aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/WasmObjectWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-11-13[WebAssembly] Added R_WASM_FUNCTION_OFFSET_I64 for use with DWARF DW_AT_low_pcWouter van Oortmerssen1-0/+3
Needed for wasm64, see discussion in https://reviews.llvm.org/D91203 Differential Revision: https://reviews.llvm.org/D91395
2020-11-13[WebAssembly] Add new relocation type for TLS data symbolsSam Clegg1-1/+3
These relocations represent offsets from the __tls_base symbol. Previously we were just using normal MEMORY_ADDR relocations and relying on the linker to select a segment-offset rather and absolute value in Symbol::getVirtualAddress(). Using an explicit relocation type allows allow us to clearly distinguish absolute from relative relocations based on the relocation information alone. One place this is useful is being able to reject absolute relocation in the PIC case, but still accept TLS relocations. Differential Revision: https://reviews.llvm.org/D91276
2020-10-28 [WebAssembly] Add support for DWARF type unitsDerek Schuff1-3/+0
Since Wasm comdat sections work similarly to ELF, we can use that mechanism to eliminate duplicate dwarf type information in the same way. Differential Revision: https://reviews.llvm.org/D88603
2020-10-27Revert "[WebAssembly] Add support for DWARF type units"Derek Schuff1-0/+3
This reverts commit bcb8a119df210753c5f1a3ac346d49597fef0f51.
2020-10-27[WebAssembly] Add support for DWARF type unitsDerek Schuff1-3/+0
Since Wasm comdat sections work similarly to ELF, we can use that mechanism to eliminate duplicate dwarf type information in the same way. Differential Revision: https://reviews.llvm.org/D88603
2020-10-23[WebAssembly] Implementation of (most) table instructionsPaulo Matos1-0/+2
Implementation of instructions table.get, table.set, table.grow, table.size, table.fill, table.copy. Missing instructions are table.init and elem.drop as they deal with element sections which are not yet implemented. Added more tests to tables.s Differential Revision: https://reviews.llvm.org/D89797
2020-10-13[WebAssembly] Added .tabletype to asm and multiple table support in obj filesPaulo Matos1-3/+42
Adds more testing in basic-assembly.s and a new test tables.s. Adds support to yaml reading and writing of tables as well. Differential Revision: https://reviews.llvm.org/D88815
2020-09-28[wasm] Move WasmTraits.h to BinaryFormatBenjamin Kramer1-1/+1
There's no dependency on Object in there and this avoids a cyclic dependency between libMC and libObject.
2020-09-28[WebAssembly] Use wasm::Signature for in ObjectWriter (NFC)Heejin Ahn1-51/+9
There are two `WasmSignature` structs, one in include/llvm/BinaryFormat/Wasm.h and the other in lib/MC/WasmObjectWriter.cpp. I don't know why they got separated in this way in the first place, but it seems we can unify them to use the one in Wasm.h for all cases. Reviewed By: dschuff, sbc100 Differential Revision: https://reviews.llvm.org/D88428
2020-09-22[WebAssembly][MC] Fix computation of relative symbol offsetDominic Chen1-7/+15
For relative symbols, add its offset when computing relocation value. Also, warn on unsupported absolute symbols. Differential Revision: https://reviews.llvm.org/D87407
2020-09-17Support dwarf fission for wasm object filesDerek Schuff1-139/+206
Initial support for dwarf fission sections (-gsplit-dwarf) on wasm. The most interesting change is support for writing 2 files (.o and .dwo) in the wasm object writer. My approach moves object-writing logic into its own function and calls it twice, swapping out the endian::Writer (W) in between calls. It also splits the import-preparation step into its own function (and skips it when writing a dwo). Differential Revision: https://reviews.llvm.org/D85685
2020-09-11[NFC] Fix compiler warnings due to integer comparison of different signednessSimon Pilgrim1-3/+2
Fix by directly using INT_MAX and INT32_MAX. Patch by: @nullptr.cpp (Yang Fan) Differential Revision: https://reviews.llvm.org/D87347
2020-07-16[WebAssembly] 64-bit (function) pointer fixes.Wouter van Oortmerssen1-1/+7
Accounting for the fact that Wasm function indices are 32-bit, but in wasm64 we want uniform 64-bit pointers. Includes reloc types for 64-bit table indices. Differential Revision: https://reviews.llvm.org/D83729
2020-07-07[WebAssembly] fix gcc 10 warningWouter van Oortmerssen1-1/+2
2020-07-06[WebAssembly] 64-bit memory limitsWouter van Oortmerssen1-8/+11
2020-06-23[WebAssembly] Fix for use of uninitialized member in WasmObjectWriter.cppSam Clegg1-16/+13
Currently, section indices may be passed uninitialized by value if writing the section fails. Removes section indices form class initialization and returns them from the write{Code,Data}Section function calls instead. Patch by Gui Andrade! Differential Revision: https://reviews.llvm.org/D81702
2020-06-22[WebAssembly] Add support for externalref to MC and wasm-ldSam Clegg1-0/+6
This allows code for handling externref values to be processed by the assembler and linker. Differential Revision: https://reviews.llvm.org/D81977
2020-06-17[WebAssembly] MC: Fix for data aliases with offsets (getelementptr)Sam Clegg1-50/+62
For some reason we hadn't seen such cases in the wild which makes me think that clang and rustc don't generate these. In the bug which reproduces it only occurs with LTO so my guess is that some LTO pass is creating this alias + gep. See: https://github.com/emscripten-core/emscripten/issues/8731 Differential Revision: https://reviews.llvm.org/D79462
2020-06-15[WebAssembly] Adding 64-bit version of R_WASM_MEMORY_ADDR_* relocsWouter van Oortmerssen1-22/+41
This adds 4 new reloc types. A lot of code that previously assumed any memory or offset values could be contained in a uint32_t (and often truncated results from functions returning 64-bit values) have been upgraded to uint64_t. This is not comprehensive: it is only the values that come in contact with the new relocation values and their dependents. A new tablegen mapping was added to automatically upgrade loads/stores in the assembler, which otherwise has no way to select for these instructions (since they are indentical other than for the offset immediate). It follows a similar technique to https://reviews.llvm.org/D53307 Differential Revision: https://reviews.llvm.org/D81704
2020-05-29[WebAssembly] Add placeholders for R_WASM_TABLE_INDEX_REL_SLEB relocationsSam Clegg1-2/+6
Previously in the object format we punted on this and simply wrote zeros (and didn't include the function in the elem segment). With this change we write a meaningful value which is the segment relative table index of the associated function. This matches the that wasm-ld produces in `-r` mode. This inconsistency between the output the MC object writer and the wasm-ld object writer could cause warnings to be emitted when reading back in the output of `wasm-ld -r`. See: https://github.com/emscripten-core/emscripten/issues/11217 This only applies to this one relocation type which is only generated when compiling in PIC mode. Differential Revision: https://reviews.llvm.org/D80774
2020-04-30[WebAssmebly] Add support for defined wasm globals in MC and lldSam Clegg1-10/+80
This change add support for defined wasm globals in the .s format, the MC layer, and wasm-ld Currently there is no support custom initialization and all wasm globals are initialized to zero. Fixes: PR45742 Differential Revision: https://reviews.llvm.org/D79137
2020-04-17MCObjectWriter.h - remove Endian.h/EndianStream.h/raw_ostream.h includes. NFCSimon Pilgrim1-0/+1
Push these includes down to the the writers that actually need them, a number of which were implicitly relying on the MCObjectWriter.h.
2020-04-16[WebAssembly] Add int32 DW_OP_WASM_location variantWouter van Oortmerssen1-1/+5
This to allow us to add reloctable global indices as a symbol. Also adds R_WASM_GLOBAL_INDEX_I32 relocation type to support it. See discussion in https://github.com/WebAssembly/debugging/issues/12
2020-04-15[MC] Rename MCSection*::getSectionName() to getName(). NFCFangrui Song1-12/+10
A pending change will merge MCSection*::getName() to MCSection::getName().
2020-04-14[WebAssembly] Emit .llvmcmd and .llvmbc as custom sectionsSam Clegg1-10/+9
Fixes: https://bugs.llvm.org/show_bug.cgi?id=45362 Differential Revision: https://reviews.llvm.org/D77115
2019-12-11[WebAssembly] Add new `export_name` clang attribute for controlling wasm ↵Sam Clegg1-0/+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-12-06[WebAssebmly][MC] Support .import_name/.import_field asm directivesSam Clegg1-1/+1
Convert the MC test to use asm rather than bitcode. This is a precursor to https://reviews.llvm.org/D70520. Differential Revision: https://reviews.llvm.org/D70877
2019-09-25[MC][WebAssembly] Error on data symbols in the text section.Sam Clegg1-1/+3
Previously we had an assert but this can actually occur in valid user code so we need to handle this in release builds too. Differential Revision: https://reviews.llvm.org/D67997 llvm-svn: 372934
2019-08-29[WebAssembly] Make __attribute__((used)) not imply export.Dan Gohman1-2/+7
Add an WASM_SYMBOL_NO_STRIP flag, so that __attribute__((used)) doesn't need to imply exporting. When targeting Emscripten, have WASM_SYMBOL_NO_STRIP imply exporting. Differential Revision: https://reviews.llvm.org/D62542 llvm-svn: 370415
2019-08-20[WebAssembly][MC] Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off ↵Fangrui Song1-3/+1
builds after r369317 llvm-svn: 369318
2019-08-20[WebAssembly][MC] Simplify WasmObjectWriter::recordRelocation. NFC.Sam Clegg1-43/+15
WebAssembly doesn't support PC relative relocation or relocation expressions that can't be reduced to single symbol. The only support for we have for fixups involving two symbols are when both symbols are defined and withing the same section. In this case evaluateFixup will already have evaluated to the expression before calling recordRelocation. llvm-svn: 369317
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-3/+3
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-07-12Delete dead storesFangrui Song1-1/+0
llvm-svn: 365903
2019-06-26[WebAssembly] Fix list of relocations with addends in lldKeno Fischer1-13/+1
Summary: The list of relocations with addend in lld was missing `R_WASM_MEMORY_ADDR_REL_SLEB`, causing `wasm-ld` to generate corrupted output. This fixes that problem and while we're at it pulls the list of such relocations into the Wasm.h header, to avoid duplicating it in multiple places. Reviewers: sbc100 Differential Revision: https://reviews.llvm.org/D63696 llvm-svn: 364367
2019-04-23Use llvm::stable_sortFangrui Song1-3/+2
While touching the code, simplify if feasible. llvm-svn: 358996
2019-04-12[WebAssembly] Add DataCount section to object filesThomas Lively1-0/+12
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-04[WebAssembly] Add new explicit relocation types for PIC relocationsSam Clegg1-0/+5
See https://github.com/WebAssembly/tool-conventions/pull/106 Differential Revision: https://reviews.llvm.org/D59907 llvm-svn: 357710
2019-03-28[WebAssembly] Rename wasm fixup kindsSam Clegg1-4/+1
These fixup kinds are not explicitly related to the code section. They are there to signal how to apply the fixup. Also, a couple of other minor wasm cleanups. Differential Revision: https://reviews.llvm.org/D59908 llvm-svn: 357145
2019-03-26[WebAssembly] Initial implementation of PIC code generationSam Clegg1-28/+36
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/+10
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-04[WebAssembly] Add support for data sections in the assembler.Wouter van Oortmerssen1-1/+1
Summary: This is quite minimal so far, introduce them with .section, fill them with .int8 or .asciz, end with .size Reviewers: dschuff, sbc100, aheejin Subscribers: jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58660 llvm-svn: 355321
2019-02-24Fix "enumeral and non-enumeral type in conditional expression" gcc7 warning. ↵Simon Pilgrim1-1/+2
NFCI. llvm-svn: 354745
2019-02-22[WebAssembly] Remove unneeded MCSymbolRefExpr variantsSam Clegg1-6/+7
We record the type of the symbol (event/function/data/global) in the MCWasmSymbol and so it should always be clear how to handle a relocation based on the symbol itself. The exception is a function which still needs the special @TYPEINDEX then the relocation contains the signature rather than the address of the functions. Differential Revision: https://reviews.llvm.org/D58472 llvm-svn: 354697
2019-02-22[WebAssembly] MC: Handle aliases of aliasesSam Clegg1-6/+7
Differential Revision: https://reviews.llvm.org/D58417 llvm-svn: 354694
2019-02-21[WebAssembly] Don't create MSSymbolWasm object for non-symbolsSam Clegg1-9/+4
`__linear_memory` and `__indirect_function_table` are both generated as imports in wasm object files but are actually symbols and don't appear in any symbols table or relocation entry. Indeed we don't have any symbol type to meaningfully represent either of them. Differential Revision: https://reviews.llvm.org/D58487 llvm-svn: 354599
2019-02-19[WebAssembly] Update MC for bulk memoryThomas Lively1-7/+13
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-1/+4
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-07[WebAssembly] Add symbol flag to the binary format llvm.usedSam Clegg1-0/+2
Summary: Rather than add a new attribute See https://github.com/WebAssembly/tool-conventions/issues/64 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57864 llvm-svn: 353360
2019-02-04[WebAssembly] clang-tidy (NFC)Heejin Ahn1-34/+28
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-34/+34
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