aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML/WasmYAML.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-03-04[lld][WebAssembly] Support for the custom-page-sizes WebAssembly proposal ↵Nick Fitzgerald1-0/+3
(#128942) This commit adds support for WebAssembly's custom-page-sizes proposal to `wasm-ld`. An overview of the proposal can be found [here](https://github.com/WebAssembly/custom-page-sizes/blob/main/proposals/custom-page-sizes/Overview.md). In a sentence, it allows customizing a Wasm memory's page size, enabling Wasm to target environments with less than 64KiB of memory (the default Wasm page size) available for Wasm memories. This commit contains the following: * Adds a `--page-size=N` CLI flag to `wasm-ld` for configuring the linked Wasm binary's linear memory's page size. * When the page size is configured to a non-default value, then the final Wasm binary will use the encodings defined in the custom-page-sizes proposal to declare the linear memory's page size. * Defines a `__wasm_first_page_end` symbol, whose address points to the first page in the Wasm linear memory, a.k.a. is the Wasm memory's page size. This allows writing code that is compatible with any page size, and doesn't require re-compiling its object code. At the same time, because it just lowers to a constant rather than a memory access or something, it enables link-time optimization. * Adds tests for these new features. r? @sbc100 cc @sunfishcode
2025-02-24[object][WebAssembly] Add support for RUNTIME_PATH to yaml2obj and obj2yaml ↵Hood Chatham1-0/+1
(#126080) This is the first step of adding RPATH support for wasm. See corresponding update to the WebAssembly/tool-conventions repo on dynamic linking: https://github.com/WebAssembly/tool-conventions/pull/246
2025-01-17[WebAssembly][Object] Support more elem segment flags (#123427)Derek Schuff1-1/+1
Some tools (e.g. Rust tooling) produce element segment descriptors with neither elemkind or element type descriptors, but with init exprs instead of func indices (this is with the flags value of 4 in https://webassembly.github.io/spec/core/binary/modules.html#element-section). LLVM doesn't fully model reference types or the various ways to initialize element segments, but we do want to correctly parse and skip over all type sections, so this change updates the object parser to handle that case, and refactors for more clarity. The test file is updated to include one additional elem segment with a flags value of 4, an initializer value of (32.const 0) and an empty vector. Also support parsing files that export imported (undefined) functions.
2024-11-04[WebAssembly] Remove WASM_FEATURE_PREFIX_REQUIRED (NFC) (#113729)Heejin Ahn1-1/+0
This has not been emitted since https://github.com/llvm/llvm-project/commit/3f34e1b883351c7d98426b084386a7aa762aa366. The corresponding proposed tool-conventions change: https://github.com/WebAssembly/tool-conventions/pull/236
2024-05-28[WebAssembly] Add exnref type (#93586)Heejin Ahn1-0/+2
This adds (back) the exnref type restored in the new EH proposal adopted in Oct 2023 CG meeting: https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md:x
2024-02-21[WebAssembly] Add segment RETAIN flag to support private retained data (#81539)Yuta Saito1-0/+1
In WebAssembly, we have `WASM_SYMBOL_NO_STRIP` symbol flag to mark the referenced content as retained. However, the flag is not enough to express retained data that is not referenced by any symbol. This patch adds a new segment flag`WASM_SEG_FLAG_RETAIN` to support "private" linkage data that is retained by llvm.used. This kind of data that is not referenced but must be retained is usually used with encapsulation symbols (__start/__stop). Swift runtime uses this technique and depends on the fact "all metadata sections in live objects are retained", which was not guaranteed with `--gc-sections` before this patch. This is a revised version of https://reviews.llvm.org/D126950 (has been reverted) based on @MaskRay's comments
2024-01-25[Object][Wasm] Allow parsing of GC types in type and table sections (#79235)Derek Schuff1-3/+9
This change allows a WasmObjectFile to be created from a wasm file even if it uses typed funcrefs and GC types. It does not significantly change how lib/Object models its various internal types (e.g. WasmSignature, WasmElemSegment), so LLVM does not really "support" or understand such files, but it is sufficient to parse the type, global and element sections, discarding types that are not understood. This is useful for low-level binary tools such as nm and objcopy, which use only limited aspects of the binary (such as function definitions) or deal with sections as opaque blobs. This is done by allowing `WasmValType` to have a value of `OTHERREF` (representing any unmodeled reference type), and adding a field to `WasmSignature` indicating it's a placeholder for an unmodeled reference type (since there is a 1:1 correspondence between WasmSignature objects and types in the type section). Then the object file parsers for the type and element sections are expanded to parse encoded reference types and discard any unmodeled fields.
2023-10-03[WebAssembly] Allow absolute symbols in the linking section (symbol table) ↵Sam Clegg1-1/+4
(#67493) Fixes a crash in `-Wl,-emit-relocs` where the linker was not able to write linker-synthetic absolute symbols to the symbol table. This change adds a new symbol flag (`WASM_SYMBOL_ABS`), which means that the symbol's offset is absolute and not relative to a given segment. Such symbols include `__stack_low` and `__stack_low`. Note that wasm object files never contains such symbols, only binaries linked with `-Wl,-emit-relocs`. Fixes: #67111
2023-07-27[WebAssembly][Objcopy] Write output section headers identically to inputsDerek Schuff1-0/+1
Previously when objcopy generated section headers, it padded the LEB that encodes the section size out to 5 bytes, matching the behavior of clang. This is correct, but results in a binary that differs from the input. This can sometimes have undesirable consequences (e.g. breaking source maps). This change makes the object reader remember the size of the LEB encoding in the section header, so that llvm-objcopy can reproduce it exactly. For sections not read from an object file (e.g. that llvm-objcopy is adding itself), pad to 5 bytes. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D155535
2022-03-14[WebAssembly] Rename member in WasmYAML.h to avoid compiler warningSam Clegg1-1/+1
Followup/fix for https://reviews.llvm.org/D121349.
2022-03-14[WebAssembly] Second phase of implemented extended const proposalSam Clegg1-32/+35
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
2021-10-15[WebAssembly] Add import info to `dylink` section of shared librariesSam Clegg1-4/+12
See https://github.com/WebAssembly/tool-conventions/pull/175 Differential Revision: https://reviews.llvm.org/D111345
2021-10-05[WebAssembly] Remove WasmTagTypeHeejin Ahn1-11/+3
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-14Fix test failure created by ef8c9135efcbSam Clegg1-1/+1
Followup to https://reviews.llvm.org/D108877 to fix test failure.
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/+1
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-09[WebAssembly] Add explict TLS symbol flagSam Clegg1-0/+1
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-06-17[WebAssembly] Rename event to tagHeejin Ahn1-17/+17
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-12[WebAssembly] Add TLS data segment flag: WASM_SEG_FLAG_TLSSam Clegg1-0/+1
Previously the linker was relying solely on the name of the segment to imply TLS. Differential Revision: https://reviews.llvm.org/D102202
2021-05-10Reland: "[lld][WebAssembly] Initial support merging string data"Sam Clegg1-1/+5
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-5/+1
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-1/+5
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-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-05[WebAssembly][yaml2obj][obj2yaml] Elem sections for nonzero tablesAndy Wingo1-0/+8
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-02-02[yaml2obj][wasm] Support numeric relocation typeFangrui Song1-0/+1
Differential Revision: https://reviews.llvm.org/D95661
2021-01-19[WebAssembly] Change prefix on data segment flags to WASM_DATA_SEGMENTAndy Wingo1-2/+2
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-09[WebAssembly] Remove exnref and br_on_exnHeejin Ahn1-1/+0
This removes `exnref` type and `br_on_exn` instruction. This is effectively NFC because most uses of these were already removed in the previous CLs. Reviewed By: dschuff, tlively Differential Revision: https://reviews.llvm.org/D94041
2020-12-09[WebAssembly] Add support for named data sections in wasm binariesSam Clegg1-0/+1
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/+1
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-19[WebAssembly] Add support for named globals in the object format.Sam Clegg1-0/+1
Differential Revision: https://reviews.llvm.org/D91769
2020-10-13[WebAssembly] Added .tabletype to asm and multiple table support in obj filesPaulo Matos1-0/+5
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-06[WebAssembly] 64-bit memory limitsWouter van Oortmerssen1-0/+1
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-03-25[WebAssembly] Move event section before global sectionHeejin Ahn1-9/+9
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
2019-10-18[WebAssembly] Allow multivalue signatures in object filesThomas Lively1-2/+1
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
2019-08-29[WebAssembly] Make __attribute__((used)) not imply export.Dan Gohman1-0/+1
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-05-07[WebAssembly] Add more test coverage for reloctions against section symbolsSam Clegg1-1/+2
The only known user of this relocation type and symbol type is the debug info sections, but we were not testing the `--relocatable` output path. This change adds a minimal test case to cover relocations against section symbols includes `--relocatable` output. Differential Revision: https://reviews.llvm.org/D61623 llvm-svn: 360110
2019-04-30[WebAssembly] Support EXPLICIT_NAME symbols in llvm-readobjDan Gohman1-0/+1
Teach llvm-readobj about WASM_SYMBOL_EXPLICIT_NAME. Differential Revision: https://reviews.llvm.org/D61323 Reviewer: sbc100 llvm-svn: 359602
2019-04-12[WebAssembly] Add DataCount section to object filesThomas Lively1-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
2019-03-20[WebAssembly] Target features sectionThomas Lively1-0/+25
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-02-19[WebAssembly] Update MC for bulk memoryThomas Lively1-2/+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
2019-02-07[WebAssembly] Add symbol flag to the binary format llvm.usedSam Clegg1-0/+1
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-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-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
2019-01-17[WebAssembly] Parse llvm.ident into producers sectionThomas Lively1-0/+18
llvm-svn: 351413
2019-01-17Revert "[WebAssembly] Parse llvm.ident into producers section"Thomas Lively1-18/+0
This reverts commit eccdbba3a02a33e13b5262e92200a33e2ead873d. llvm-svn: 351410
2019-01-16[WebAssembly] Parse llvm.ident into producers sectionThomas Lively1-0/+18
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
2019-01-08[WebAssembly] Massive instruction renamingThomas Lively1-4/+4
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
2018-12-12[WebAssembly] Update dylink section parsingSam Clegg1-0/+1
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
2018-11-14[WebAssembly] Add support for dylink section in object formatSam Clegg1-1/+14
See https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md. Differential Revision: https://reviews.llvm.org/D54490 llvm-svn: 346880
2018-11-14[WebAssembly] Add support for the event sectionHeejin Ahn1-0/+24
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