aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-04-15Enable finding bitcode in wasm objectsSam Clegg1-2/+0
This commit fixes using functions in `IRObjectFile` to load bitcode from wasm objects by recognizing the file magic for wasm and also inheriting the default implementation of classifying sections as bitcode. Patch By: alexcrichton Differential Revision: https://reviews.llvm.org/D78199
2020-03-25[WebAssembly] Move event section before global sectionHeejin Ahn1-44/+64
Summary: https://github.com/WebAssembly/exception-handling/issues/98 Also this moves many parts of code to make code align with the section order, even if they don't affect the output. Reviewers: tlively Subscribers: dschuff, sbc100, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76752
2020-02-19[WebAssembly] Use llvm::Optional to store optional symbol attributes. NFC.Sam Clegg1-11/+21
The changes the in-memory representation of wasm symbols such that their optional ImportName and ImportModule use llvm::Optional. ImportName is set whenever WASM_SYMBOL_EXPLICIT_NAME flag is set. ImportModule (for imports) is currently always set since it defaults to "env". In the future we can possibly extent to binary format distingish import which have explit module names. Tags: #llvm Differential Revision: https://reviews.llvm.org/D74109
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-2/+2
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-2/+2
2020-01-29Another round of GCC5 fixes.Benjamin Kramer1-1/+1
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28[WebAssembly] Add WebAssembly support to llvm-symbolizerDerek Schuff1-11/+15
The only thing missing for basic llvm-symbolizer support is the ability on lib/Object to get a wasm symbol's section ID, which allows sorting and computation of the symbols' sizes. Also, when the WasmAsmParser switches sections on new functions, also add the section to the list of Dwarf sections if Dwarf is being generated for assembly; this allows writing of simple tests. Reviewers: sbc100, jhenderson, aardappel Differential Revision: https://reviews.llvm.org/D73246
2019-12-11[WebAssembly] Add new `export_name` clang attribute for controlling wasm ↵Sam Clegg1-7/+10
export names This is equivalent to the existing `import_name` and `import_module` attributes which control the import names in the final wasm binary produced by lld. This maps the existing This attribute currently requires a string rather than using the symbol name for a couple of reasons: 1. Avoid confusion with static and dynamic linking which is based on symbol name. Exporting a function from a wasm module using this directive is orthogonal to both static and dynamic linking. 2. Avoids name mangling. Differential Revision: https://reviews.llvm.org/D70520
2019-10-18[WebAssembly] Allow multivalue signatures in object filesThomas Lively1-6/+3
Summary: Also changes the wasm YAML format to reflect the possibility of having multiple return types and to put the returns after the params for consistency with the binary encoding. Reviewers: aheejin, sbc100 Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, arphaman, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69156 llvm-svn: 375283
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-02[NFC] Test commit, corrected some spelling in commentDavid Candler1-1/+1
Test commit, corrected some spelling in comment. Differential Revision: https://reviews.llvm.org/D65516 llvm-svn: 367685
2019-05-14[Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song1-5/+3
Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
2019-05-02[Object] Change getSectionName() to return Expected<StringRef>Fangrui Song1-8/+4
Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
2019-04-20[WebAssembly] Object: Improve error messages on invalid sectionSam Clegg1-3/+3
Also add a test. Differential Revision: https://reviews.llvm.org/D60836 llvm-svn: 358801
2019-04-12[WebAssembly] Add DataCount section to object filesThomas Lively1-0/+11
Summary: This ensures that object files will continue to validate as WebAssembly modules in the presence of bulk memory operations. Engines that don't support bulk memory operations will not recognize the DataCount section and will report validation errors, but that's ok because object files aren't supposed to be run directly anyway. Reviewers: aheejin, dschuff, sbc100 Subscribers: jgravelle-google, hiraditya, sunfish, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60623 llvm-svn: 358315
2019-04-07Change some StringRef::data() reinterpret_cast to bytes_begin() or ↵Fangrui Song1-1/+1
arrayRefFromStringRef() llvm-svn: 357852
2019-04-04[WebAssembly] Add new explicit relocation types for PIC relocationsSam Clegg1-0/+2
See https://github.com/WebAssembly/tool-conventions/pull/106 Differential Revision: https://reviews.llvm.org/D59907 llvm-svn: 357710
2019-03-26[WebAssembly] Initial implementation of PIC code generationSam Clegg1-1/+5
This change implements lowering of references global symbols in PIC mode. This change implements lowering of global references in PIC mode using a new @GOT reference type. @GOT references can be used with function or data symbol names combined with the get_global instruction. In this case the linker will insert the wasm global that stores the address of the symbol (either in memory for data symbols or in the wasm table for function symbols). For now I'm continuing to use the R_WASM_GLOBAL_INDEX_LEB relocation type for this type of reference which means that this relocation type can refer to either a global or a function or data symbol. We could choose to introduce specific relocation types for GOT entries in the future. See the current dynamic linking proposal: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md Differential Revision: https://reviews.llvm.org/D54647 llvm-svn: 357022
2019-03-20[WebAssembly] Target features sectionThomas Lively1-1/+36
Summary: Implements a new target features section in assembly and object files that records what features are used, required, and disallowed in WebAssembly objects. The linker uses this information to ensure that all objects participating in a link are feature-compatible and records the set of used features in the output binary for use by optimizers and other tools later in the toolchain. The "atomics" feature is always required or disallowed to prevent linking code with stripped atomics into multithreaded binaries. Other features are marked used if they are enabled globally or on any function in a module. Future CLs will add linker flags for ignoring feature compatibility checks and for specifying the set of allowed features, implement using the presence of the "atomics" feature to control the type of memory and segments in the linked binary, and add front-end flags for relaxing the linkage policy for atomics. Reviewers: aheejin, sbc100, dschuff Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59173 llvm-svn: 356610
2019-03-13[WebAssembly] Improve support for "needed" list in dylink sectionSam Clegg1-0/+1
This change adds basic support for shared library dependencies via the dylink section. See https://github.com/WebAssembly/tool-conventions/pull/77 Differential Revision: https://reviews.llvm.org/D59237 llvm-svn: 356102
2019-02-20[WebAssembly] Generalize section ordering constraintsThomas Lively1-8/+61
Summary: Changes from using a total ordering of known sections to using a dependency graph approach. This allows our tools to accept and process binaries that are compliant with the spec and tool conventions that would have been previously rejected. It also means our own tools can do less work to enforce an artificially imposed ordering. Using a general mechanism means fewer special cases and exceptions in the ordering logic. Reviewers: aheejin, dschuff Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58312 llvm-svn: 354426
2019-02-19[WebAssembly] Update MC for bulk memoryThomas Lively1-5/+12
Summary: Rename MemoryIndex to InitFlags and implement logic for determining data segment layout in ObjectYAML and MC. Also adds a "passive" flag for the .section assembler directive although this cannot be assembled yet because the assembler does not support data sections. Reviewers: sbc100, aardappel, aheejin, dschuff Subscribers: jgravelle-google, hiraditya, sunfish, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57938 llvm-svn: 354397
2019-02-07[WebAssembly] Fix imported function symbol names that differ from their ↵Dan Gohman1-4/+18
import names in the .o format Add a flag to allow symbols to have a wasm import name which differs from the linker symbol name, allowing the linker to link code using the import_module attribute. This is the MC/Object portion of the patch. Differential Revision: https://reviews.llvm.org/D57632 llvm-svn: 353474
2019-02-05[WebAssembly] Object: Remove redundant method. NFC.Sam Clegg1-5/+1
Differential Revision: https://reviews.llvm.org/D57719 llvm-svn: 353183
2019-02-04[WebAssembly] clang-tidy (NFC)Heejin Ahn1-18/+18
Summary: This patch fixes clang-tidy warnings on wasm-only files. The list of checks used is: `-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*` (LLVM's default .clang-tidy list is the same except it does not have `modernize-*`. But I've seen in multiple CLs in LLVM the modernize style was recommended and code was fixed based on the style, so I added it as well.) The common fixes are: - Variable names start with an uppercase letter - Function names start with a lowercase letter - Use `auto` when you use casts so the type is evident - Use inline initialization for class member variables - Use `= default` for empty constructors / destructors - Use `using` in place of `typedef` Reviewers: sbc100, tlively, aardappel Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D57500 llvm-svn: 353075
2019-02-04[WebAssembly] Rename relocations from R_WEBASSEMBLY_ to R_WASM_Sam Clegg1-16/+16
See https://github.com/WebAssembly/tool-conventions/pull/95. This is less typing and IMHO more readable, and it also fits with our naming around the binary format which tends to use the short name. e.g. include/llvm/BinaryFormat/Wasm.h tools/llvm-objdump/WasmDump.cpp etc.. Differential Revision: https://reviews.llvm.org/D57611 llvm-svn: 353062
2019-01-30[WebAssembly] Add missing SymbolRef update from rL352551Sam Clegg1-2/+2
This change broke some MC tests which are now fixed. Differential Revision: https://reviews.llvm.org/D57424 llvm-svn: 352573
2019-01-29[WebAssembly] Ensure BasicSymbolRef.getRawDataRefImpl().p is non-nullSam Clegg1-4/+6
Store a non-zero value to ref.d.a and use ref.d.b to store the symbol index. This means that ref.p is never null, which was confusing llvm-nm. Fixes PR40497 Differential Revision: https://reviews.llvm.org/D57373 llvm-svn: 352551
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-17[WebAssembly] Fixed objdump not parsing function headers.Wouter van Oortmerssen1-1/+12
Summary: objdump was interpreting the function header containing the locals declaration as instructions. To parse these without injecting target specific code in objdump, MCDisassembler::onSymbolStart was added to be implemented by the WebAssembly implemention. WasmObjectFile now returns a code offset for the "address" of a symbol, rather than the index. This is also more in-line with what other targets do. Also ensured that the AsmParser correctly puts each function in its own segment to enable this test case. Reviewers: sbc100, dschuff Subscribers: jgravelle-google, aheejin, sunfish, rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D56684 llvm-svn: 351460
2019-01-17[WebAssembly] Parse llvm.ident into producers sectionThomas Lively1-0/+45
llvm-svn: 351413
2019-01-17Revert "[WebAssembly] Parse llvm.ident into producers section"Thomas Lively1-45/+0
This reverts commit eccdbba3a02a33e13b5262e92200a33e2ead873d. llvm-svn: 351410
2019-01-16[WebAssembly] Parse llvm.ident into producers sectionThomas Lively1-0/+45
Summary: Everything before the word "version" is the tool, and everything after the word "version" is the version. Reviewers: aheejin, dschuff Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D56742 llvm-svn: 351399
2019-01-08[WebAssembly] Massive instruction renamingThomas Lively1-3/+3
Summary: An automated renaming of all the instructions listed at https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329 as well as some similarly-named identifiers. Reviewers: aheejin, dschuff, aardappel Subscribers: sbc100, jgravelle-google, eraman, sunfish, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D56338 llvm-svn: 350609
2018-12-15[WebAssembly] Check if the section order is correctHeejin Ahn1-3/+67
Summary: This patch checks if the section order is correct when reading a wasm object file in `WasmObjectFile` and converting YAML to wasm object in yaml2wasm. (It is not possible to check when reading YAML because it is handled exclusively by the YAML reader.) This checks the ordering of all known sections (core sections + known custom sections). This also adds section ID DataCount section that will be scheduled to be added in near future. Reviewers: sbc100 Subscribers: dschuff, mgorny, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54924 llvm-svn: 349221
2018-12-12[WebAssembly] Update dylink section parsingSam Clegg1-0/+6
This updates the format of the dylink section in accordance with recent "spec" change: https://github.com/WebAssembly/tool-conventions/pull/77 Differential Revision: https://reviews.llvm.org/D55609 llvm-svn: 348989
2018-12-08[WebAssembly] Make WasmSymbol's signature usable for events (NFC)Heejin Ahn1-5/+7
Summary: WasmSignature used to use its `WasmSignature` member variable only for function types, but now it also can be used for events as well. Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D55247 llvm-svn: 348702
2018-11-14[WebAssembly] Add support for dylink section in object formatSam Clegg1-1/+16
See https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md. Differential Revision: https://reviews.llvm.org/D54490 llvm-svn: 346880
2018-11-14[WebAssembly] Add support for the event sectionHeejin Ahn1-3/+92
Summary: This adds support for the 'event section' specified in the exception handling proposal. (This was named 'exception section' first, but later renamed to 'event section' to take possibilities of other kinds of events into consideration. But currently we only store exception info in this section.) The event section is added between the global section and the export section. This is for ease of validation per request of the V8 team. This patch: - Creates the event symbol type, which is a weak symbol - Makes 'throw' instruction take the event symbol '__cpp_exception' - Adds relocation support for events - Adds WasmObjectWriter / WasmObjectFile (Reader) support - Adds obj2yaml / yaml2obj support - Adds '.eventtype' printing support Reviewers: dschuff, sbc100, aardappel Subscribers: jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54096 llvm-svn: 346825
2018-11-06[WebAssembly] Add shared memory support to limits fieldDerek Schuff1-1/+1
Support the IS_SHARED bit in the memory limits flag word. The compiler does not create object files with memory definitions, but the field is used by the linker. Differential Revision: https://reviews.llvm.org/D54131 llvm-svn: 346246
2018-10-03[WebAssembly] Refactor WasmSignature and use it for MCSymbolWasmDerek Schuff1-5/+4
MCContext does not destroy MCSymbols on shutdown. So, rather than putting SmallVectors (which may heap-allocate) inside MCSymbolWasm, use unowned pointer to a WasmSignature instead. The signatures are now owned by the AsmPrinter. Also uses WasmSignature instead of param and result vectors in TargetStreamer, and leaves some TODOs for further simplification. Differential Revision: https://reviews.llvm.org/D52580 llvm-svn: 343733
2018-09-05[WebAssembly] clang-format (NFC)Heejin Ahn1-38/+35
Summary: This patch runs clang-format on all wasm-only files. Reviewers: aardappel, dschuff, sunfish, tlively Subscribers: MatzeB, sbc100, jgravelle-google, llvm-commits Differential Revision: https://reviews.llvm.org/D51447 llvm-svn: 341439
2018-08-31[Wasm] Add missing EOF checks for floatsJonas Devlieghere1-0/+4
Adds the same checks we already do for ints to floats. Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8698 llvm-svn: 341216
2018-08-22[WebAssembly] Ensure relocation entries are ordered by offsetSam Clegg1-0/+5
wasm-lld expects relocation entries to be sorted by offset. In most cases llvm produces them in order, but the CODE section (which combines many MCSections) is an exception because we order the functions in Symbol order, not in section order. What is more, its not clear weather `recordRelocation` is guaranteed to be called in offset order so this sort of most likely needed in the general case too. Differential Revision: https://reviews.llvm.org/D51065 llvm-svn: 340423
2018-08-08[WASM] Fix overflow when reading custom sectionJonas Devlieghere1-3/+10
When reading a custom WASM section, it was possible that its name extended beyond the size of the section. This resulted in a bogus value for the section size due to the size overflowing. Fixes heap buffer overflow detected by OSS-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8190 Differential revision: https://reviews.llvm.org/D50387 llvm-svn: 339269
2018-06-26Fix MSVC "signed/unsigned mismatch" warning. NFCI.Simon Pilgrim1-1/+1
llvm-svn: 335587
2018-05-30MC: Remove redundant substr() callSam Clegg1-1/+1
Differential Revision: https://reviews.llvm.org/D47047 llvm-svn: 333496
2018-05-29Fix build error introduced in rL333459Sam Clegg1-2/+3
The DEBUG macro was renamed LLVM_DEBUG. llvm-svn: 333462
2018-05-29[WebAssembly] Add more error checking to object file parsingSam Clegg1-224/+240
This should address some of the assert failures the fuzzer has been finding such as: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6719 Differential Revision: https://reviews.llvm.org/D47086 llvm-svn: 333459