aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/WasmObjectWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-08-31[WebAssembly][MC] Avoid the need for .size directives for functionsSam Clegg1-13/+6
Warn if `.size` is specified for a function symbol. The size of a function symbol is determined solely by its content. I noticed this simplification was possible while debugging #57427, but this change doesn't fix that specific issue. Differential Revision: https://reviews.llvm.org/D132929
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata1-4/+4
2022-06-15[NFC][Alignment] Use Align in MCAlignFragmentGuillaume Chatelet1-1/+2
2022-03-14[WebAssembly] Second phase of implemented extended const proposalSam Clegg1-24/+29
This change continues to lay the ground work for supporting extended const expressions in the linker. The included test covers object file reading and writing and the YAML representation. Differential Revision: https://reviews.llvm.org/D121349
2022-02-25[MC][WebAssembly] Fix crash when relocation addend underlows U32Sam Clegg1-20/+42
For the object file writer we need to allow the underflow (ar write zero), but for the final linker output we should probably generate an error (I've left that as a TODO for now). Fixes: https://github.com/llvm/llvm-project/issues/54012 Differential Revision: https://reviews.llvm.org/D120522
2022-02-09Cleanup LLVMMC headersserge-sans-paille1-2/+0
There's a few relevant forward declarations in there that may require downstream adding explicit includes: llvm/MC/MCContext.h no longer includes llvm/BinaryFormat/ELF.h, llvm/MC/MCSubtargetInfo.h, llvm/MC/MCTargetOptions.h llvm/MC/MCObjectStreamer.h no longer include llvm/MC/MCAssembler.h llvm/MC/MCAssembler.h no longer includes llvm/MC/MCFixup.h, llvm/MC/MCFragment.h Counting preprocessed lines required to rebuild llvm-project on my setup: before: 1052436830 after: 1049293745 Which is significant and backs up the change in addition to the usual benefits of decreasing coupling between headers and compilation units. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119244
2022-02-05[MC] Use default member initialization in WasmCustomSection (NFC)Kazu Hirata1-4/+3
2021-11-05[NFC] Inclusive language: Remove instances of master in URLsQuinn Pham1-1/+1
[NFC] This patch fixes URLs containing "master". Old URLs were either broken or redirecting to the new URL. Reviewed By: #libc, ldionne, mehdi_amini Differential Revision: https://reviews.llvm.org/D113186
2021-10-19[WebAssembly] Emit clangast in custom section aligned by 4 bytesYuta Saito1-1/+30
Emit __clangast in custom section instead of named data segment to find it while iterating sections. This could be avoided if all data segements (the wasm sense) were represented as their own sections (in the llvm sense). This can be resolved by https://github.com/WebAssembly/tool-conventions/issues/138 And the on-disk hashtable in clangast needs to be aligned by 4 bytes, so add paddings in name length field in custom section header. The length of clangast section name can be represented in 1 byte by leb128, and possible maximum pads are 3 bytes, so the section name length won't be invalid in theory. Fixes https://bugs.llvm.org/show_bug.cgi?id=35928 Differential Revision: https://reviews.llvm.org/D74531
2021-10-05[WebAssembly] Remove WasmTagTypeHeejin Ahn1-18/+15
This removes `WasmTagType`. `WasmTagType` contained an attribute and a signature index: ``` struct WasmTagType { uint8_t Attribute; uint32_t SigIndex; }; ``` Currently the attribute field is not used and reserved for future use, and always 0. And that this class contains `SigIndex` as its property is a little weird in the place, because the tag type's signature index is not an inherent property of a tag but rather a reference to another section that changes after linking. This makes tag handling in the linker also weird that tag-related methods are taking both `WasmTagType` and `WasmSignature` even though `WasmTagType` contains a signature index. This is because the signature index changes in linking so it doesn't have any info at this point. This instead moves `SigIndex` to `struct WasmTag` itself, as we did for `struct WasmFunction` in D111104. In this CL, in lib/MC and lib/Object, this now treats tag types in the same way as function types. Also in YAML, this removes `struct Tag`, because now it only contains the tag index. Also tags set `SigIndex` in `WasmImport` union, as functions do. I think this makes things simpler and makes tag handling more in line with function handling. These two shares similar properties in that both of them have signatures, but they are kind of nominal so having the same signature doesn't mean they are the same element. Also a drive-by fix: the reserved 'attirubute' part's encoding changed from uleb32 to uint8 a while ago. This was fixed in lib/MC and lib/Object but not in YAML. This doesn't change object files because the field's value is always 0 and its encoding is the same for the both encoding. This is effectively NFC; I didn't mark it as such just because it changed YAML test results. Reviewed By: sbc100, tlively Differential Revision: https://reviews.llvm.org/D111086
2021-09-14[WebAssembly] Allow import and export of TLS symbols between DSOsSam Clegg1-1/+7
We previously had a limitation that TLS variables could not be exported (and therefore could also not be imported). This change removed that limitation. Differential Revision: https://reviews.llvm.org/D108877
2021-09-09[WebAssembly] Add explict TLS symbol flagSam Clegg1-0/+2
As before we maintain backwards compat with older object files by also infering the TLS flag based on the name of the segment. This change is was split out from https://reviews.llvm.org/D108877. Differential Revision: https://reviews.llvm.org/D109426
2021-09-02[WebAssembly] Add Wasm SjLj supportHeejin Ahn1-1/+2
This add support for SjLj using Wasm exception handling instructions: https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md This does not yet support the mixed use of EH and SjLj within a function. It will be added in a follow-up CL. This currently passes all SjLj Emscripten tests for wasm0/1/2/3/s, except for the below: - `test_longjmp_standalone`: Uses Node - `test_dlfcn_longjmp`: Uses NodeRAWFS - `test_longjmp_throw`: Mixes EH and SjLj - `test_exceptions_longjmp1`: Mixes EH and SjLj - `test_exceptions_longjmp2`: Mixes EH and SjLj - `test_exceptions_longjmp3`: Mixes EH and SjLj Reviewed By: dschuff, tlively Differential Revision: https://reviews.llvm.org/D108960
2021-07-19[WebAssembly] Generate R_WASM_FUNCTION_OFFSET relocs in debuginfo sectionsDerek Schuff1-4/+13
Debug info sections need R_WASM_FUNCTION_OFFSET_I32 relocs (with FK_Data_4 fixup kinds) to refer to functions (instead of R_WASM_TABLE_INDEX as is used in data sections). Usually this is done in a convoluted way, with unnamed temp data symbols which target the start of the function, in which case WasmObjectWriter::recordRelocation converts it to use the section symbol instead. However in some cases the function can actually be undefined; in this case the dwarf generator uses the function symbol (a named undefined function symbol) instead. In that case the section-symbol transform doesn't work and we need to generate the correct reloc type a different way. In this change WebAssemblyWasmObjectWriter::getRelocType takes the fixup section type into account to choose the correct reloc type. Fixes PR50408 Differential Revision: https://reviews.llvm.org/D103557
2021-07-19[WebAssembly] Support R_WASM_MEMORY_ADDR_TLS_SLEB64 for wasm64Wouter van Oortmerssen1-0/+2
Also fixed TLS tests swapping addr & value in store op Differential Revision: https://reviews.llvm.org/D106096
2021-06-21[WebAssembly] Make tag attribute's encoding uint8Heejin Ahn1-2/+2
This changes the encoding of the `attribute` field, which currently only contains the value `0` denoting this tag is for an exception, from `varuint32` to `uint8`. This field is effectively unused at the moment and reserved for future use, and it is not likely to need `varuint32` even in future. See https://github.com/WebAssembly/exception-handling/pull/162. This does not change any encoded binaries because `0` is encoded in the same way both in `varuint32` and `uint8`. Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D104571
2021-06-17[WebAssembly] Rename event to tagHeejin Ahn1-43/+43
We recently decided to change 'event' to 'tag', and 'event section' to 'tag section', out of the rationale that the section contains a generalized tag that references a type, which may be used for something other than exceptions, and the name 'event' can be confusing in the web context. See - https://github.com/WebAssembly/exception-handling/issues/159#issuecomment-857910130 - https://github.com/WebAssembly/exception-handling/pull/161 Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D104423
2021-05-20[WebAssembly] Fix PIC/GOT codegen for wasm64Wouter van Oortmerssen1-2/+7
__table_base is know 64-bit, since in LLVM it represents a function pointer offset __table_base32 is a copy in wasm32 for use in elem init expr, since no truncation may be used there. New reloc R_WASM_TABLE_INDEX_REL_SLEB64 added Differential Revision: https://reviews.llvm.org/D101784
2021-05-10Reland: "[lld][WebAssembly] Initial support merging string data"Sam Clegg1-3/+3
This change was originally landed in: 5000a1b4b9edeb9e994f2a5b36da8d48599bea49 It was reverted in: 061e071d8c9b98526f35cad55a918a4f1615afd4 This change adds support for a new WASM_SEG_FLAG_STRINGS flag in the object format which works in a similar fashion to SHF_STRINGS in the ELF world. Unlike the ELF linker this support is currently limited: - No support for SHF_MERGE (non-string merging) - Always do full tail merging ("lo" can be merged with "hello") - Only support single byte strings (p2align 0) Like the ELF linker merging is only performed at `-O1` and above. This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828, although crucially it doesn't not currently support debug sections because they are not represented by data segments (they are custom sections) Differential Revision: https://reviews.llvm.org/D97657
2021-05-10Revert "[lld][WebAssembly] Initial support merging string data"Nico Weber1-3/+3
This reverts commit 5000a1b4b9edeb9e994f2a5b36da8d48599bea49. Breaks tests, see https://reviews.llvm.org/D97657#2749151 Easily repros locally with `ninja check-llvm-mc-webassembly`.
2021-05-10[lld][WebAssembly] Initial support merging string dataSam Clegg1-3/+3
This change adds support for a new WASM_SEG_FLAG_STRINGS flag in the object format which works in a similar fashion to SHF_STRINGS in the ELF world. Unlike the ELF linker this support is currently limited: - No support for SHF_MERGE (non-string merging) - Always do full tail merging ("lo" can be merged with "hello") - Only support single byte strings (p2align 0) Like the ELF linker merging is only performed at `-O1` and above. This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828, although crucially it doesn't not currently support debug sections because they are not represented by data segments (they are custom sections) Differential Revision: https://reviews.llvm.org/D97657
2021-04-07[WebAssembly] Improve error messages regarding missing indirect function ↵Sam Clegg1-4/+4
table. NFC Use report_fatal_error here since this is an internal error, and not something the user can/should be trying to fix. Also distinguish between the symbol being missing and the symbol having the wrong type. We have a failure internally where the symbol is missing. Currently trying to reduce the test case to something we can attach to an llvm bug. Differential Revision: https://reviews.llvm.org/D99960
2021-03-24[WebAssembly][MC] Record limit constraints for table sizesAndy Wingo1-9/+2
This commit adds a full WasmTableType to MCSymbolWasm, differing from the current situation (just an ElemType) in that it additionally records a WasmLimits. We add support for specifying the limits in .S files also, via the following syntax variations: .tabletype SYM, ELEMTYPE .tabletype SYM, ELEMTYPE, MINSIZE .tabletype SYM, ELEMTYPE, MINSIZE, MAXSIZE Depends on D99186. Differential Revision: https://reviews.llvm.org/D99191
2021-03-24[WebAssembly] Rename WasmLimits::Initial to ::Minimum. NFC.Andy Wingo1-1/+1
This patch renames the "Initial" member of WasmLimits to the name used in the spec, "Minimum". In the core WebAssembly specification, the Limits data type has one required "min" member and one optional "max" member, indicating the minimum required size of the corresponding table or memory, and the maximum size, if any. Although the WebAssembly spec does instantiate locally-defined tables and memories with the initial size being equal to the minimum size, it can't impose such a requirement for imports. It doesn't make sense to require an initial size for a memory import, for example. The compiler can only sensibly express the minimum and maximum sizes. See https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md#naming-of-size-limits for a related discussion that agrees that the right name of "initial" is "minimum" when querying the type of a table or memory from JavaScript. (Of course it still makes sense for JS to speak in terms of an initial size when it explicitly instantiates memories and tables.) Differential Revision: https://reviews.llvm.org/D99186
2021-03-08[WebAssembly] Add new relocation for location relative dataYuta Saito1-10/+30
This `R_WASM_MEMORY_ADDR_SELFREL_I32` relocation represents an offset between its relocating address and the symbol address. It's very similar to `R_X86_64_PC32` but restricted to be used for only data segments. ``` S + A - P ``` A: Represents the addend used to compute the value of the relocatable field. P: Represents the place of the storage unit being relocated. S: Represents the value of the symbol whose index resides in the relocation entry. Proposal: https://github.com/WebAssembly/tool-conventions/issues/162 Differential Revision: https://reviews.llvm.org/D96659
2021-03-05[WebAssembly][yaml2obj][obj2yaml] Elem sections for nonzero tablesAndy Wingo1-4/+26
With reference types, tables can have non-zero table numbers. This commit adds support for element sections against these tables. Differential Revision: https://reviews.llvm.org/D97923
2021-03-01[WebAssembly] call_indirect issues table number relocsAndy Wingo1-21/+22
If the reference-types feature is enabled, call_indirect will explicitly reference its corresponding function table via TABLE_NUMBER relocations against a table symbol. Also, as before, address-taken functions can also cause the function table to be created, only with reference-types they additionally cause a symbol table entry to be emitted. Differential Revision: https://reviews.llvm.org/D90948
2021-02-23Revert "[WebAssembly] call_indirect issues table number relocs"Andy Wingo1-22/+21
This reverts commit 861dbe1a021e6439af837b72b219fb9c449a57ae. It broke emscripten -- see https://reviews.llvm.org/D90948#2578843.
2021-02-22[WebAssembly] call_indirect issues table number relocsAndy Wingo1-21/+22
If the reference-types feature is enabled, call_indirect will explicitly reference its corresponding function table via `TABLE_NUMBER` relocations against a table symbol. Also, as before, address-taken functions can also cause the function table to be created, only with reference-types they additionally cause a symbol table entry to be emitted. We abuse the used-in-reloc flag on symbols to indicate which tables should end up in the symbol table. We do this because unfortunately older wasm-ld will carp if it see a table symbol. Differential Revision: https://reviews.llvm.org/D90948
2021-02-08[MC][WebAssembly] Fix provisional values for data alias relocationsSam Clegg1-7/+4
When calculating the symbol offsets to write as provisitonal values in object files we are only interested in the offset of the symbol itself. For aliases this offset already includes the offset of the base symbol. The testin question was added back in https://reviews.llvm.org/D87407 but I believe the expectations here were incorrect. sym_a lives at offset 4 and sym_b lives 4 bytes into that (should be 8). The addresses of the 3 symbosl in this object file are: foo : 0 sym_a: 4 sym_b: 8 Differential Revision: https://reviews.llvm.org/D96234
2021-02-05[WebAssembly] Prevent data inside text sections in assemblyWouter van Oortmerssen1-6/+12
This is not supported in Wasm, unless the data was encoded instructions, but that wouldn't work with the assembler's other functionality (enforcing nesting etc.). Fixes: https://bugs.llvm.org/show_bug.cgi?id=48971 Differential Revision: https://reviews.llvm.org/D95838
2021-02-01[WebAssembly] fixed wasm64 data segment init exp not 64-bitWouter van Oortmerssen1-2/+2
As defined in the spec: https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md Differential Revision: https://reviews.llvm.org/D95651
2021-01-25Revert "[WebAssembly] MC layer writes table symbols to object files"Sam Clegg1-7/+4
This reverts commit d806618636f8a82bfc3f620e1fad83af4d2a2575. Review: https://reviews.llvm.org/D92215 We had issues where older versions of wasm-ld were crashing on object files containing a table symbol. We decided that the best strategy going forward is to only generate these symbol if refernece types is enabled. Without reference types enabled we should never geneate a table symbol or a TABLE_NUMBER relocation. This revert is in addition to the one already reverted in https://reviews.llvm.org/D95005. The plan is to re-land these in updated form after the llvm 12 branch. Differential Revision: https://reviews.llvm.org/D95420
2021-01-19Revert "[WebAssembly] call_indirect issues table number relocs"Sam Clegg1-0/+7
This reverts commit 418df4a6ab35d343cc0f2608c90a73dd9b8d0ab1. This change broke emscripten tests, I believe because it started generating 5-byte a wide table index in the call_indirect instruction. Neither v8 nor wabt seem to be able to handle that. The spec currently says that this is single 0x0 byte and: "In future versions of WebAssembly, the zero byte occurring in the encoding of the call_indirectcall_indirect instruction may be used to index additional tables." So we need to revisit this change. For backwards compat I guess we need to guarantee that __indirect_function_table is always at address zero. We could also consider making this a single-byte relocation with and assert if have more than 127 tables (for now). Differential Revision: https://reviews.llvm.org/D95005
2021-01-19[WebAssembly] Change prefix on data segment flags to WASM_DATA_SEGMENTAndy Wingo1-4/+5
Element sections will also need flags, so we shouldn't squat the WASM_SEGMENT namespace. Depends on D90948. Differential Revision: https://reviews.llvm.org/D92315
2021-01-19[WebAssembly] call_indirect issues table number relocsAndy Wingo1-7/+0
This patch changes to make call_indirect explicitly refer to the corresponding function table, residualizing TABLE_NUMBER relocs against it. With this change, wasm-ld now sees all references to tables, and can link multiple tables. Differential Revision: https://reviews.llvm.org/D90948
2021-01-18[WebAssembly] MC layer writes table symbols to object filesAndy Wingo1-4/+7
Now that the linker handles table symbols, we can allow the frontend to produce them. Depends on D91870. Differential Revision: https://reviews.llvm.org/D92215
2021-01-15Revert "[WebAssembly] MC layer writes table symbols to object files"Derek Schuff1-7/+4
This reverts commit e9f1ed2306b1b3aedcb1acef2b50e252a77a04b9. Reverting because it depends on 38dfce706f
2021-01-15[WebAssembly] MC layer writes table symbols to object filesAndy Wingo1-4/+7
Now that the linker handles table symbols, we can allow the frontend to produce them. Depends on D91870. Differential Revision: https://reviews.llvm.org/D92215
2021-01-06[llvm] Use llvm::append_range (NFC)Kazu Hirata1-2/+2
2021-01-06[MC][WebAssembly] Avoid recalculating indexes in -gsplit-dwarf modeSam Clegg1-190/+197
Be consistent about asserting before setting WasmIndices. Adding these assertions revealed that we were duplicating a lot of work and setting these indexed twice when running in DWO mode. Differential Revision: https://reviews.llvm.org/D93650
2021-01-05[WebAssembly] call_indirect causes indirect function table importAndy Wingo1-0/+7
For wasm-ld table linking work to proceed, object files should indicate if they use an indirect function table. In the future this will be done by the usual symbols and relocations mechanism, but until that support lands in the linker, the presence of an `__indirect_function_table` in the object file's import section shows that the object file needs an indirect function table. Prior to https://reviews.llvm.org/D91637, this condition was met by all object files residualizing an `__indirect_function_table` import. Since https://reviews.llvm.org/D91637, the intention has been that only those object files needing an indirect function table would have the `__indirect_function_table` import. However, we missed the case of object files which use the table via `call_indirect` but which themselves do not declare any indirect functions. This changeset makes it so that when we lower a call to `call_indirect`, that we ensure that a `__indirect_function_table` symbol is present and that it will be propagated to the linker. A followup patch will revise this mechanism to make an explicit link between `call_indirect` and its associated indirect function table; see https://reviews.llvm.org/D90948. Differential Revision: https://reviews.llvm.org/D92840
2020-12-10[WebAssembly] Support COMDAT sections in assembly syntaxDerek Schuff1-0/+3
This CL changes the asm syntax for section flags, making them more like ELF (previously "passive" was the only option). Now we also allow "G" to designate COMDAT group sections. In these sections we set the appropriate comdat flag on function symbols, and also avoid auto-creating a new section for them. This also adds asm-based tests for the changes D92691 to go along with the direct-to-object tests. Differential Revision: https://reviews.llvm.org/D92952 This is a reland of rG4564553b8d8a with a fix to the lit pipeline in llvm/test/MC/WebAssembly/comdat.ll
2020-12-10Revert "[WebAssembly] Support COMDAT sections in assembly syntax"Derek Schuff1-3/+0
This reverts commit 4564553b8d8ab81dc21431a35275581cb42329c8. It broke several buildbots.
2020-12-10[WebAssembly] Support COMDAT sections in assembly syntaxDerek Schuff1-0/+3
This CL changes the asm syntax for section flags, making them more like ELF (previously "passive" was the only option). Now we also allow "G" to designate COMDAT group sections. In these sections we set the appropriate comdat flag on function symbols, and also avoid auto-creating a new section for them. This also adds asm-based tests for the changes D92691 to go along with the direct-to-object tests. Differential Revision: https://reviews.llvm.org/D92952
2020-12-07[WebAssembly] Add Object and ObjectWriter support for wasm COMDAT sectionsDerek Schuff1-2/+20
Allow sections to be placed into COMDAT groups, in addtion to functions and data segments. Also make section symbols unnamed, which allows sections with identical names (section names are independent of their section symbols, but previously we gave the symbols the same name as their sections, which results in collisions when sections are identically-named). Differential Revision: https://reviews.llvm.org/D92691
2020-12-07[WebAssembly][MC] Fix placement of table sectionAndy Wingo1-1/+1
The table section goes after functions. Differential Revision: https://reviews.llvm.org/D92323
2020-12-06[MC] Delete unused declarationsFangrui Song1-3/+0
Notes: * llvm::createAsmStreamer: it has been moved to TargetRegistry.h * (anon ns)::WasmObjectWriter::updateCustomSectionRelocations: remnant of D46335 * COFFAsmParser::ParseSEHRegisterNumber: remnant of D66625 * llvm::CodeViewContext::isValidCVFileNumber: accidentally added by r279847
2020-11-25[MC][WebAssembly] Only emit indirect function table import if neededAndy Wingo1-16/+48
The indirect function table, synthesized by the linker, is needed if and only if there are TABLE_INDEX relocs. Differential Revision: https://reviews.llvm.org/D91637
2020-11-25[WebAssembly] Factor out WasmTableType in binary formatAndy Wingo1-7/+7
This commit factors out a WasmTableType definition from WasmTable, as is the case for WasmGlobal and other data types. Also add support for extracting the SymbolName for a table from the linking section's symbol table. Differential Revision: https://reviews.llvm.org/D91849