summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/WasmObjectFile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [WebAssembly] Add new `export_name` clang attribute for controlling wasm ↵Sam Clegg2019-12-111-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
* [WebAssembly] Allow multivalue signatures in object filesThomas Lively2019-10-181-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
* [llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-151-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
* [NFC] Test commit, corrected some spelling in commentDavid Candler2019-08-021-1/+1
| | | | | | | | Test commit, corrected some spelling in comment. Differential Revision: https://reviews.llvm.org/D65516 llvm-svn: 367685
* [Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song2019-05-141-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
* [Object] Change getSectionName() to return Expected<StringRef>Fangrui Song2019-05-021-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
* [WebAssembly] Object: Improve error messages on invalid sectionSam Clegg2019-04-201-3/+3
| | | | | | | | Also add a test. Differential Revision: https://reviews.llvm.org/D60836 llvm-svn: 358801
* [WebAssembly] Add DataCount section to object filesThomas Lively2019-04-121-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
* Change some StringRef::data() reinterpret_cast to bytes_begin() or ↵Fangrui Song2019-04-071-1/+1
| | | | | | arrayRefFromStringRef() llvm-svn: 357852
* [WebAssembly] Add new explicit relocation types for PIC relocationsSam Clegg2019-04-041-0/+2
| | | | | | | | See https://github.com/WebAssembly/tool-conventions/pull/106 Differential Revision: https://reviews.llvm.org/D59907 llvm-svn: 357710
* [WebAssembly] Initial implementation of PIC code generationSam Clegg2019-03-261-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
* [WebAssembly] Target features sectionThomas Lively2019-03-201-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
* [WebAssembly] Improve support for "needed" list in dylink sectionSam Clegg2019-03-131-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
* [WebAssembly] Generalize section ordering constraintsThomas Lively2019-02-201-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
* [WebAssembly] Update MC for bulk memoryThomas Lively2019-02-191-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
* [WebAssembly] Fix imported function symbol names that differ from their ↵Dan Gohman2019-02-071-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
* [WebAssembly] Object: Remove redundant method. NFC.Sam Clegg2019-02-051-5/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D57719 llvm-svn: 353183
* [WebAssembly] clang-tidy (NFC)Heejin Ahn2019-02-041-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
* [WebAssembly] Rename relocations from R_WEBASSEMBLY_ to R_WASM_Sam Clegg2019-02-041-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
* [WebAssembly] Add missing SymbolRef update from rL352551Sam Clegg2019-01-301-2/+2
| | | | | | | | This change broke some MC tests which are now fixed. Differential Revision: https://reviews.llvm.org/D57424 llvm-svn: 352573
* [WebAssembly] Ensure BasicSymbolRef.getRawDataRefImpl().p is non-nullSam Clegg2019-01-291-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
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-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
* [WebAssembly] Fixed objdump not parsing function headers.Wouter van Oortmerssen2019-01-171-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
* [WebAssembly] Parse llvm.ident into producers sectionThomas Lively2019-01-171-0/+45
| | | | llvm-svn: 351413
* Revert "[WebAssembly] Parse llvm.ident into producers section"Thomas Lively2019-01-171-45/+0
| | | | | | This reverts commit eccdbba3a02a33e13b5262e92200a33e2ead873d. llvm-svn: 351410
* [WebAssembly] Parse llvm.ident into producers sectionThomas Lively2019-01-161-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
* [WebAssembly] Massive instruction renamingThomas Lively2019-01-081-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
* [WebAssembly] Check if the section order is correctHeejin Ahn2018-12-151-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
* [WebAssembly] Update dylink section parsingSam Clegg2018-12-121-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
* [WebAssembly] Make WasmSymbol's signature usable for events (NFC)Heejin Ahn2018-12-081-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
* [WebAssembly] Add support for dylink section in object formatSam Clegg2018-11-141-1/+16
| | | | | | | | See https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md. Differential Revision: https://reviews.llvm.org/D54490 llvm-svn: 346880
* [WebAssembly] Add support for the event sectionHeejin Ahn2018-11-141-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
* [WebAssembly] Add shared memory support to limits fieldDerek Schuff2018-11-061-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
* [WebAssembly] Refactor WasmSignature and use it for MCSymbolWasmDerek Schuff2018-10-031-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
* [WebAssembly] clang-format (NFC)Heejin Ahn2018-09-051-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
* [Wasm] Add missing EOF checks for floatsJonas Devlieghere2018-08-311-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
* [WebAssembly] Ensure relocation entries are ordered by offsetSam Clegg2018-08-221-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
* [WASM] Fix overflow when reading custom sectionJonas Devlieghere2018-08-081-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
* Fix MSVC "signed/unsigned mismatch" warning. NFCI.Simon Pilgrim2018-06-261-1/+1
| | | | llvm-svn: 335587
* MC: Remove redundant substr() callSam Clegg2018-05-301-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D47047 llvm-svn: 333496
* Fix build error introduced in rL333459Sam Clegg2018-05-291-2/+3
| | | | | | The DEBUG macro was renamed LLVM_DEBUG. llvm-svn: 333462
* [WebAssembly] Add more error checking to object file parsingSam Clegg2018-05-291-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
* [WebAssembly] Object: Add more error checking for object file readingSam Clegg2018-05-181-3/+9
| | | | | | | | | | This should address some 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/D47046 llvm-svn: 332769
* [NFC] WebAssembly build break #2JF Bastien2018-05-161-0/+4
| | | | | | | | | | | | | | | | | Summary: Same as r332530, move WasmSymbol::dump to an implementation file to avoid linker issues when the dump function is seen in the header, doesn't get eliminated, and then linking fails because of the missing dependency. <rdar://problem/40258137> Reviewers: sbc100, ncw, paquette, vsk, dschuff Subscribers: jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D46985 llvm-svn: 332542
* [NFC] WebAssembly build fixJF Bastien2018-05-161-0/+13
| | | | | | | | | | | | | | | | | | | | | | Summary: r332305 added a use of llvm::wasm::toString in llvm::object::WasmSymbol::print, which is in a header file. It also moves toString to BinaryFormat. This has the unintended side-effect that any inclusion of Object/Wasm.h now relies on toString, and needs to required_libraries = BinaryFormat. Thankfully most builds don't fail with this because print just isn't used and gets eliminated, dropping the required dependency in the process. Not all builds are so lucky. Fix this issue by moving print to the corresponding .cpp file. <rdar://problem/40258137> Reviewers: sbc100, ncw, paquette Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D46977 llvm-svn: 332530
* [WebAssembly] Provide WasmFunction content offset information.Sam Clegg2018-05-151-0/+1
| | | | | | | | | | | | | WasmObjectWriter mostly operates with function segments offsets that do not include their size fields. WasmObjectFile needs to have and provide this information to the lld to maintain proper R_WEBASSEMBLY_FUNCTION_OFFSET_I32 relocations entries. Patch by Yury Delendik Differential Revision: https://reviews.llvm.org/D46763 llvm-svn: 332406
* Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-141-2/+2
| | | | | | | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
* typoSam Clegg2018-04-271-2/+3
| | | | llvm-svn: 331006
* [WebAssembly] Section symbols must have local bindingSam Clegg2018-04-271-0/+4
| | | | | | | | | | Summary: Also test for symbols information in test/MC/WebAssembly/debug-info.ll. Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, JDevlieghere, llvm-commits Differential Revision: https://reviews.llvm.org/D46160 llvm-svn: 331005
* [WebAssembly] Write DWARF data into wasm object fileSam Clegg2018-04-261-1/+35
| | | | | | | | | | | - Writes ".debug_XXX" into corresponding custom sections. - Writes relocation records into "reloc.debug_XXX" sections. Patch by Yury Delendik! Differential Revision: https://reviews.llvm.org/D44184 llvm-svn: 330982
OpenPOWER on IntegriCloud