aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-02-27[lld][WebAssembly] Fix handling of mixed strong and weak referencesSam Clegg1-1/+12
When adding a undefined symbols to the symbol table, if the existing reference is weak replace the symbol flags with (potentially) non-weak binding. Fixes: https://github.com/llvm/llvm-project/issues/60829 Differential Revision: https://reviews.llvm.org/D144747
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-16[llvm-objdump][RISCV] Use new common method to parse ARCH RISCV attributeElena Lepilkina1-1/+1
Differential Revision: https://reviews.llvm.org/D139553
2022-12-09Revert D139098 "[Alignment] Use Align for ObjectFile::getSectionAlignment"Guillaume Chatelet1-2/+2
This breaks lld. This reverts commit 10c47465e2505ddfee4e62a2ab2e535abea3ec56.
2022-12-09[Alignment] Use Align for ObjectFile::getSectionAlignmentGuillaume Chatelet1-2/+2
Differential Revision: https://reviews.llvm.org/D139098
2022-08-31[lld][WebAssemby] Allow import module names to be empty strings.Dan Gohman1-12/+4
The component-model [canonical ABI] is currently using import names with empty strings. Remove the special cases for empty strings from WasmObjectFile.cpp so that they can pass through as-is. [canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md Differential Revision: https://reviews.llvm.org/D133037
2022-07-17[llvm] Modernize bool literals (NFC)Kazu Hirata1-1/+1
Identified with modernize-use-bool-literals.
2022-06-23[WebAssembly][Object] Remove requirement that objects must have code sectionsDerek Schuff1-13/+3
When parsing name and linking sections, we currently require that the object must have a code section (it seems that this was intended to verify section ordering). However it can be useful for binaries to have their code sections stripped out (e.g. if we just want the debug info). In that case we need the rest of the known sections (so e.g. we know how many functions there are, to verify the name section) but not the actual code. I've removed the restriction completely. I think this is OK because the section-parsing code already checks function and global indices in many places for validity and will return appropriate errors if the relevant sections are missing. Also we can't just replace the requirement of seeing a code section with a requirement that we see a function or global section, because a binary may just not have any functions or globals. But there's only an problem if the name or linking section tries to name a nonexistent function. Part of a fix for https://github.com/emscripten-core/emscripten/issues/13084 Differential Revision: https://reviews.llvm.org/D128094
2022-06-20[llvm] Don't use Optional::getValue (NFC)Kazu Hirata1-1/+1
2022-06-07[WebAssembly] Add WASM_SEC_LAST_KNOWN to BinaryFormat section types list [NFC]Derek Schuff1-1/+1
There are 3 places where we were using WASM_SEC_TAG as the "last" known section type, which requires updating (or leaves a bug) when a new known section type is added. Instead add a "last type" to the enum for this purpose. Differential Revision: https://reviews.llvm.org/D127164
2022-05-27[WebAssembly] Consolidate sectionTypeToString in BinaryFormat [NFC]Derek Schuff1-21/+3
Currently there are 2 duplicate implementation, and I want to add a use in a 3rd place. Combine them in lib/BinaryFormat so they can be shared. Also update toString for symbol and reloc types to use StringRef Differential Revision: https://reviews.llvm.org/D126553
2022-03-15[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349Sam Clegg1-0/+1
2022-03-14[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349Sam Clegg1-0/+1
2022-03-14[WebAssembly] Second phase of implemented extended const proposalSam Clegg1-21/+56
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-10Cleanup LLVMObject headersserge-sans-paille1-2/+0
Most notably, llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h llvm-project preprocessed size: before: 1068185081 after: 1068324320 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119457
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-15[WebAssembly] Add import info to `dylink` section of shared librariesSam Clegg1-0/+8
See https://github.com/WebAssembly/tool-conventions/pull/175 Differential Revision: https://reviews.llvm.org/D111345
2021-10-12[WebAssembly] Make EH work with dynamic linkingHeejin Ahn1-2/+4
This makes Wasm EH work with dynamic linking. So far we were only able to handle destructors, which do not use any tags or LSDA info. 1. This uses `TargetExternalSymbol` for `GCC_except_tableN` symbols, which points to the address of per-function LSDA info. It is more convenient to use than `MCSymbol` because it can take additional target flags. 2. When lowering `wasm_lsda` intrinsic, if PIC is enabled, make the symbol relative to `__memory_base` and generate the `add` node. If PIC is disabled, continue to use the absolute address. 3. Make tag symbols (`__cpp_exception` and `__c_longjmp`) undefined in the backend, because it is hard to make it work with dynamic linking's loading order. Instead, we make all tag symbols undefined in the LLVM backend and import it from JS. 4. Add support for undefined tags to the linker. Companion patches: - https://github.com/WebAssembly/binaryen/pull/4223 - https://github.com/emscripten-core/emscripten/pull/15266 Reviewed By: sbc100 Differential Revision: https://reviews.llvm.org/D111388
2021-10-05[WebAssembly] Remove WasmTagTypeHeejin Ahn1-10/+21
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-10-04[Object][WebAssemlby] Report function types (signatures). NFCSam Clegg1-8/+9
This simplifies the code in a number of ways and avoids having to track functions and their types separately. Differential Revision: https://reviews.llvm.org/D111104
2021-09-29[WebAssemlby][Object] Fix dead code in WasmObjectFile.cppSam Clegg1-2/+1
I introduced this by mistake in https://reviews.llvm.org/D109595. Differential Revision: https://reviews.llvm.org/D110717
2021-09-14[WebAssembly] Allow import and export of TLS symbols between DSOsSam Clegg1-0/+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-12[WebAssembly] Convert to new "dylink.0" section formatSam Clegg1-1/+52
This format is based on sub-sections (like the "linking" and "name" sections) and is therefore easier to extend going forward. spec change: https://github.com/WebAssembly/tool-conventions/pull/170 binaryen change: https://github.com/WebAssembly/binaryen/pull/4141 wabt change: https://github.com/WebAssembly/wabt/pull/1707 emscripten change: https://github.com/emscripten-core/emscripten/pull/15019 Differential Revision: https://reviews.llvm.org/D109595
2021-09-10[WebAssembly][libObject] Avoid re-use of Section object during parsingSam Clegg1-1/+1
The re-use of this struct across iterations of the loop was causing fields (specifically Name) to be incorrectly shared between multiple sections. Differential Revision: https://reviews.llvm.org/D108984
2021-07-19[WebAssembly] Support R_WASM_MEMORY_ADDR_TLS_SLEB64 for wasm64Wouter van Oortmerssen1-0/+1
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-59/+59
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-0/+1
__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-12[lld][WebAssembly] Allow data symbols to extend past end of segmentSam Clegg1-3/+6
This fixes a bug with string merging with string symbols that contain NULLs, as is the case in the `merge-string.s` test. The bug only showed when we run with `--relocatable` and then try read the resulting object back in. In this case we would end up with string symbols that extend past the end of the segment in which they live. The problem comes from the fact that sections which are flagged as string mergable assume that all strings are NULL terminated. The merging algorithm will drop trailing chars that follow a NULL since they are essentially unreachable. However, the "size" attribute (in the symbol table) of such a truncated symbol is not updated resulting a symbol size that can overlap the end of the segment. I verified that this can happen in ELF too given the right conditions and the its harmless enough. In practice Strings that contain embedded null should not be part of a mergable section. Differential Revision: https://reviews.llvm.org/D102281
2021-05-10Reland: "[lld][WebAssembly] Initial support merging string data"Sam Clegg1-2/+2
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-2/+2
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-2/+2
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-03[lld][WebAssembly] Do not merge comdat data segmentsSam Clegg1-2/+2
When running in relocatable mode any input data segments that are part of a comdat group should not be merged with other segments of the same name. This is because the final linker needs to keep the separate so they can be included/excluded individually. Often this is not a problem since normally only one section with a given name `foo` ends up in the output object file. However, the problem occurs when one input contains `foo` which part of a comdat and another object contains a local symbol `foo` we were attempting to merge them. This behaviour matches (I believe) that of the ELF linker. See `LinkerScript.cpp:addInputSec`. Fixes: https://github.com/emscripten-core/emscripten/issues/9726 Differential Revision: https://reviews.llvm.org/D101703
2021-03-30[WebAssembly] Encode numbers in ULEB128 in event sectionHeejin Ahn1-2/+2
The number of events and the type index should be encoded in ULEB128, but they were incorrctly encoded in LEB128. The smallest number with which its LEB128 and ULEB128 encodings are different is 64. There's no way we can generate 64 events in the C++ toolchain implementation so we can't test that, but the attached test tests when the type index is 64. Reviewed By: dschuff Differential Revision: https://reviews.llvm.org/D99627
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-0/+2
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-12/+53
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-01-25[Object][WebAssembly] Update format of error messagesSam Clegg1-90/+92
Error message should start with lowercase in accordance with https://llvm.org/docs/CodingStandards.html#error-and-warning-messages Differential Revision: https://reviews.llvm.org/D95239
2021-01-21[WebAssembly] Test that invalid symbol/relocation types generate errorsSam Clegg1-6/+7
See https://bugs.llvm.org/show_bug.cgi?id=48827 Differential Revision: https://reviews.llvm.org/D95163
2021-01-19[WebAssembly] Change prefix on data segment flags to WASM_DATA_SEGMENTAndy Wingo1-3/+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-14[lld][WebAssembly] Add support for handling table symbolsAndy Wingo1-4/+3
This commit adds table symbol support in a partial way, while still including some special cases for the __indirect_function_table symbol. No change in tests. Differential Revision: https://reviews.llvm.org/D94075
2020-12-09[WebAssembly] Add support for named data sections in wasm binariesSam Clegg1-6/+15
Followup to https://reviews.llvm.org/D91769 which added support for names globals. Differential Revision: https://reviews.llvm.org/D92909
2020-12-07[WebAssembly] Add Object and ObjectWriter support for wasm COMDAT sectionsDerek Schuff1-0/+9
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-11-25[MC][WebAssembly] Only emit indirect function table import if neededAndy Wingo1-2/+22
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-11/+12
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
2020-11-19[WebAssembly] Add support for named globals in the object format.Sam Clegg1-11/+26
Differential Revision: https://reviews.llvm.org/D91769
2020-11-17[WebAssembly] Fix parsing of linking section for named global importsAndy Wingo1-1/+0
Differential Revision: https://reviews.llvm.org/D91635
2020-11-13[WebAssembly] Added R_WASM_FUNCTION_OFFSET_I64 for use with DWARF DW_AT_low_pcWouter van Oortmerssen1-1/+8
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-0/+1
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-23[WebAssembly] Implementation of (most) table instructionsPaulo Matos1-0/+9
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