aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2020-10-13[WebAssembly] Added .tabletype to asm and multiple table support in obj filesPaulo Matos1-6/+46
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-07-16[WebAssembly] 64-bit (function) pointer fixes.Wouter van Oortmerssen1-1/+4
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-16[WebAssembly] Triple::wasm64 related cleanupWouter van Oortmerssen1-3/+12
Differential Revision: https://reviews.llvm.org/D83713
2020-07-06[WebAssembly] 64-bit memory limitsWouter van Oortmerssen1-2/+2
2020-06-22[WebAssembly] Add support for externalref to MC and wasm-ldSam Clegg1-0/+8
This allows code for handling externref values to be processed by the assembler and linker. Differential Revision: https://reviews.llvm.org/D81977
2020-06-15[WebAssembly] Adding 64-bit version of R_WASM_MEMORY_ADDR_* relocsWouter van Oortmerssen1-5/+29
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-28SymbolicFile.h - removed unused FileSystem.h include. NFC.Simon Pilgrim1-0/+1
Exposes a number of implicit dependencies that needs fixing in source files and XCOFFObjectFile.h.
2020-04-18[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> ↵vgxbj1-1/+1
getSymbolFlags(). This change enables getSymbolFlags() to return errors which benefit error reporting in clients. Differential Revision: https://reviews.llvm.org/D77860
2020-04-16[WebAssembly] Add int32 DW_OP_WASM_location variantWouter van Oortmerssen1-1/+7
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-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