summaryrefslogtreecommitdiffstats
path: root/lld/wasm/Symbols.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [lld][WebAssembly] Add libcall symbols to the link when LTO is being used.Sam Clegg2020-01-101-0/+11
| | | | | | | | | | | | | | | This code is copied almost verbatim from the equivalent change to the ELF linker: - https://reviews.llvm.org/D50017 - https://reviews.llvm.org/D50475 The upshot is that libraries containing libcall (such as compiler-rt and libc) can be compiled with LTO. Fixes PR41384 Differential Revision: https://reviews.llvm.org/D71738
* [WebAssembly] Wrap definitions in namespace lld { namespace wasm {. NFCFangrui Song2019-10-101-43/+45
| | | | | | | | | | Similar to D68323, but for wasm. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68759 llvm-svn: 374279
* [LLD] Simplify the demangleItanium function. NFC.Martin Storsjo2019-09-271-2/+1
| | | | | | | | | Instead of returning an optional, just return the input string if demangling fails, as that's what all callers use anyway. Differential Revision: https://reviews.llvm.org/D68015 llvm-svn: 373077
* [WebAssembly] Initialize memory in start functionThomas Lively2019-09-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: - `__wasm_init_memory` is now the WebAssembly start function instead of being called from `__wasm_call_ctors` or called directly by the runtime. - Adds a new synthetic data symbol `__wasm_init_memory_flag` that is atomically incremented from zero to one by the thread responsible for initializing memory. - All threads now unconditionally perform data.drop on all passive segments. - Removes --passive-segments and --active-segments flags and controls segment type based on --shared-memory instead. The deleted flags were only present to ameliorate the upgrade path in Emscripten. Reviewers: sbc100, aheejin Subscribers: dschuff, jgravelle-google, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65783 llvm-svn: 370965
* [WebAssembly] Implement NO_STRIPDan Gohman2019-08-291-0/+4
| | | | | | | | | | | | | This patch implements support for the NO_STRIP flag, which will allow __attribute__((used)) to be implemented. This accompanies https://reviews.llvm.org/D62542, which moves to setting the NO_STRIP flag, and will continue to set EXPORTED for Emscripten targets for compatibility. Differential Revision: https://reviews.llvm.org/D66968 llvm-svn: 370416
* [lld][WebAssembly] Allow linking of pic code into static binariesSam Clegg2019-08-131-3/+7
| | | | | | | | | | | | Summary: See https://github.com/emscripten-core/emscripten/issues/9013 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65922 llvm-svn: 368719
* [WebAssembly] Compute and export TLS block alignmentGuanzhong Chen2019-07-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add immutable WASM global `__tls_align` which stores the alignment requirements of the TLS segment. Add `__builtin_wasm_tls_align()` intrinsic to get this alignment in Clang. The expected usage has now changed to: __wasm_init_tls(memalign(__builtin_wasm_tls_align(), __builtin_wasm_tls_size())); Reviewers: tlively, aheejin, sbc100, sunfish, alexcrichton Reviewed By: tlively Subscribers: dschuff, jgravelle-google, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D65028 llvm-svn: 366624
* [WebAssembly] Implement thread-local storage (local-exec model)Guanzhong Chen2019-07-161-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Thread local variables are placed inside a `.tdata` segment. Their symbols are offsets from the start of the segment. The address of a thread local variable is computed as `__tls_base` + the offset from the start of the segment. `.tdata` segment is a passive segment and `memory.init` is used once per thread to initialize the thread local storage. `__tls_base` is a wasm global. Since each thread has its own wasm instance, it is effectively thread local. Currently, `__tls_base` must be initialized at thread startup, and so cannot be used with dynamic libraries. `__tls_base` is to be initialized with a new linker-synthesized function, `__wasm_init_tls`, which takes as an argument a block of memory to use as the storage for thread locals. It then initializes the block of memory and sets `__tls_base`. As `__wasm_init_tls` will handle the memory initialization, the memory does not have to be zeroed. To help allocating memory for thread-local storage, a new compiler intrinsic is introduced: `__builtin_wasm_tls_size()`. This instrinsic function returns the size of the thread-local storage for the current function. The expected usage is to run something like the following upon thread startup: __wasm_init_tls(malloc(__builtin_wasm_tls_size())); Reviewers: tlively, aheejin, kripken, sbc100 Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D64537 llvm-svn: 366272
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-151/+151
| | | | | | | | | | | This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
* [WebAssembly] Add option to emit passive segmentsThomas Lively2019-07-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: Adds `--passive-segments` and `--active-segments` flags to control what kind of segments are emitted. For now the default is always to emit active segments so this is not a breaking change, but in the future the default will be changed to passive segments when shared memory is requested and active segments otherwise. When passive segments are emitted, corresponding memory.init and data.drop instructions are emitted in a `__wasm_init_memory` function that is automatically called at the beginning of `__wasm_call_ctors`. Reviewers: sbc100, aheejin, dschuff Subscribers: azakai, dschuff, jgravelle-google, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59343 llvm-svn: 365088
* [wasm-ld] Add __global_base symbol to mark the value of --global-baseGuanzhong Chen2019-06-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: This is needed for address sanitizer on Emscripten. As everything in memory starts at the value passed to --global-base, everything before that can be used as shadow memory. This symbol is added so that the library for the ASan runtime can know where the shadow memory ends and real memory begins. This is split from D63742. Reviewers: tlively, aheejin, sbc100 Subscribers: sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63833 llvm-svn: 364467
* [WebAssembly] Fix for discarded init functionsSam Clegg2019-06-071-0/+7
| | | | | | | | | When a function is excluded via comdat we shouldn't add it to the final list of init functions. Differential Revision: https://reviews.llvm.org/D62983 llvm-svn: 362769
* [lld] Trace all references with lld --trace-symbolSam Clegg2019-05-241-3/+10
| | | | | | | | | | | Previously undefined symbol references were only traced if they were seen before that definition. Fixes https://bugs.llvm.org/show_bug.cgi?id=41878 Differential Revision: https://reviews.llvm.org/D61929 llvm-svn: 361636
* [WebAssembly] Refactor synthetic sections and relocation processing. NFC.Sam Clegg2019-05-211-12/+10
| | | | | | | | | | | Major refactor to better match the structure of the ELF linker. - Split out relocation processing into scanRelocations - Split out synthetic sections into their own classes. Differential Revision: https://reviews.llvm.org/D61811 llvm-svn: 361233
* [WebAssembly] Always take into account added when applying runtime relocationsSam Clegg2019-04-251-0/+3
| | | | | | | | | | | The code we generate for applying data relocations at runtime omitted the symbols with GOT entries. Also refactor the code to reduce duplication. Differential Revision: https://reviews.llvm.org/D61111 llvm-svn: 359207
* [WebAssembly] Apply data relocations at runtime in shared objectsSam Clegg2019-04-041-0/+1
| | | | | | | | | | | | | See: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md Data section relocations in wasm shared libraries are applied by the library itself at static constructor time. This change adds a new synthetic function that applies relocations to relevant memory locations on startup. Differential Revision: https://reviews.llvm.org/D59278 llvm-svn: 357715
* [WebAssembly] Initial implementation of PIC code generationSam Clegg2019-03-261-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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
* [WebAssembly] Don't generate invalid modules when function signatures mismatchSam Clegg2019-02-201-0/+8
| | | | | | | | | | | | Previously we could emit a warning and generate a potentially invalid wasm module (due to call sites and functions having conflicting signatures). Now, rather than create invalid binaries we handle such cases by creating stub functions containing unreachable, effectively turning these into runtime errors rather than validation failures. Differential Revision: https://reviews.llvm.org/D57909 llvm-svn: 354528
* [WebAssembly] Honor WASM_SYMBOL_EXPORT symbol flagSam Clegg2019-02-071-1/+1
| | | | | | | | | | | | This flag means that symbol should be exported in the final binary. The reason for this change is to allow source level annotations to trigger a given symbol to be exported: https://github.com/emscripten-core/emscripten/issues/7702 Differential Revision: https://reviews.llvm.org/D57869 llvm-svn: 353364
* [WebAssembly] Implement --trace and --trace-symbolSam Clegg2019-02-061-0/+13
| | | | | | Differential Revision: https://reviews.llvm.org/D57725 llvm-svn: 353264
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-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
* [WebAssembly] Add support for the event sectionHeejin Ahn2018-12-081-0/+35
| | | | | | | | | | | | | | | | | Summary: This adds support for the 'event section' specified in the exception handling proposal. Wasm exception handling binary model spec: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model Reviewers: sbc100, ruiu Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54875 llvm-svn: 348703
* [WebAssembly] Import the stack pointer when building shared librariesSam Clegg2018-11-151-3/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D54558 llvm-svn: 346974
* [WebAssembly] Initial support for shared objects (-shared)Sam Clegg2018-11-151-0/+2
| | | | | | | | | | | | Based on the initial spec proposal: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md The llvm/codegen side of this is still missing but I believe this change is still worth landing as an incremental step Differential Revision: https://reviews.llvm.org/D54249 llvm-svn: 346918
* [WebAssembly] Respect `--no-mangle` in more locationsSam Clegg2018-11-091-2/+6
| | | | | | | | | | | | | `--no-demangle` now also applies to the name section. This change was motivated by the rust team that have a slightly different name mangling scheme to the standard C++ itanium one and prefer to do their de-mangling as a post-link setp. Patch by Alex Crichton! Differential Revision: https://reviews.llvm.org/D54279 llvm-svn: 346516
* [WebAssembly] Add --[no]-export-dynamic to replace --export-defaultSam Clegg2018-09-271-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | In a very recent change I introduced a --no-export-default flag but after conferring with others it seems that this feature already exists in gnu GNU ld and lld in the form the --export-dynamic flag which is off by default. This change replaces export-default with export-dynamic and also changes the default to match the traditional linker behaviour. Now, by default, only the entry point is exported. If other symbols are required by the embedder then --export-dynamic or --export can be used to export all visibility hidden symbols or individual symbols respectively. This change touches a lot of tests that were relying on symbols being exported by default. I imagine it will also effect many users but do think the change is worth it match of the traditional behaviour and flag names. Differential Revision: https://reviews.llvm.org/D52587 llvm-svn: 343265
* [WebAssembly] Add --export-default/--no-export-default optionsSam Clegg2018-09-251-0/+3
| | | | | | | | | | | | | These option control weather or not symbols marked as visibility default are exported in the output binary. By default this is true, but emscripten prefers to control the exported symbol list explicitly at link time and ignore the symbol attributes. Differential Revision: https://reviews.llvm.org/D52003 llvm-svn: 343034
* [WebAssembly] Fix --export of LTO symbolsSam Clegg2018-06-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D48697 llvm-svn: 335881
* [WebAssembly] Add support for bitcode archive membersSam Clegg2018-06-281-0/+10
| | | | | | | | | | This change effects the behavior of --export-all. Previously --export-all would only effect symbols that survived GC. Now --export-all will prevent any non-local symbols from being GCed. Differential Revision: https://reviews.llvm.org/D48673 llvm-svn: 335878
* [lld] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-151-12/+13
| | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Differential Revision: https://reviews.llvm.org/D44977 llvm-svn: 332351
* [WebAssembly] Update to match llvm changesSam Clegg2018-05-141-18/+4
| | | | | | | | Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D46849 llvm-svn: 332306
* [WebAssembly] Add support for debug (DWARF) sectionsSam Clegg2018-05-041-0/+17
| | | | | | | | | | | | | | Specifically add support for custom sections that contain relocations, and for the two new relocation types needed by DWARF sections. See: https://reviews.llvm.org/D44184 Patch by Yury Delendik! Differential Revision: https://reviews.llvm.org/D44184 llvm-svn: 331566
* [LLD][WASM] Handle WASM_SYMBOL_TYPE_SECTION in toString().Roman Lebedev2018-04-261-0/+2
| | | | | | | Fixes build. If this is not the desired solution, please revert. WasmSymbolType was changed in rL330982 / D44184 llvm-svn: 330984
* [WebAssembly] Implement GC for importsNicholas Wilson2018-04-201-2/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D44313 llvm-svn: 330454
* [WebAssembly] Refactor to avoid conflating global and fucntion index space. NFCSam Clegg2018-03-121-29/+38
| | | | | | Differential Revision: https://reviews.llvm.org/D44358 llvm-svn: 327326
* [WebAssembly] Remove a second parameter from toString().Rui Ueyama2018-03-091-2/+2
| | | | | | | | | | | | toString(T) is a stringize function for an object of type T. Each type that has that function defined should know how to stringize itself, and there should be one string representation of an object. Passing a "supplemental" argument to toString() breaks that princple. We shouldn't add a second parameter to that function. Differential Revision: https://reviews.llvm.org/D44323 llvm-svn: 327182
* [WebAssembly] Handle weak undefined functions with a synthetic stubNicholas Wilson2018-03-091-2/+2
| | | | | | | | | This error case is described in Linking.md. The operand for call requires generation of a synthetic stub. Differential Revision: https://reviews.llvm.org/D44028 llvm-svn: 327151
* [WebAssembly] Reduce code repetition. NFC.Rui Ueyama2018-02-281-0/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D43910 llvm-svn: 326379
* [WebAssembly] Simplify Symbol::getWasmType. NFC.Rui Ueyama2018-02-281-10/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D43717 llvm-svn: 326293
* [WebAssembly] Inline translateVA as it's trivial.Rui Ueyama2018-02-281-1/+3
| | | | | | | | | | | The problem I want to address now is that chunks have too many data members for "offsets", and their origins are not well defined. For example, InputSegment has OutputSegmentOffset, but it's base class also has OutputOffset. That's very confusing. Differential Revision: https://reviews.llvm.org/D43726 llvm-svn: 326291
* [WebAssembly] Remove trivial accessors.Rui Ueyama2018-02-281-1/+1
| | | | | | | | {set,get}OutputSegment don't hide anything, so remove them. Differential Revision: https://reviews.llvm.org/D43724 llvm-svn: 326276
* [WebAssembly] Add explicit symbol tableSam Clegg2018-02-231-6/+85
| | | | | | | | | | | | | | | | | | This change modified lld to in response the llvm change which moved to a more explicit symbol table in the object format. Based on patches by Nicholas Wilson: 1. https://reviews.llvm.org/D41955 2. https://reviews.llvm.org/D42585 The primary difference that we see in the test output is that for relocatable (-r) output we now have symbol table which replaces exports/imports and globals. See: https://github.com/WebAssembly/tool-conventions/issues/38 Differential Revision: https://reviews.llvm.org/D43264 llvm-svn: 325861
* [WebAssembly] Rename GlobalSymbol types. NFC.Sam Clegg2018-02-201-11/+11
| | | | | | | | | | | | | | | Purely a rename in preparation for adding new global symbol type. We want to use GlobalSymbol to represent real wasm globals and DataSymbol for pointers to things in linear memory (what ELF would call STT_OBJECT). This reduces the size the patch to add the explicit symbol table which is coming soon! Differential Revision: https://reviews.llvm.org/D43476 llvm-svn: 325645
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-201-1/+0
| | | | | | | | | The profailing style in lld seem to be to not include such empty lines. Clang-tidy/clang-format seem to handle this just fine. Differential Revision: https://reviews.llvm.org/D43528 llvm-svn: 325629
* [WebAssembly] Remove InputChunk from Symbol baseclassSam Clegg2018-02-201-17/+27
| | | | | | | | | | Instead include InputFuction and InputSegment directly in the subclasses that use them (DefinedFunction and DefinedGlobal). Differential Revision: https://reviews.llvm.org/D43493 llvm-svn: 325603
* [WebAssembly] Remove unneeded classifer methods from Symbol class. NFC.Sam Clegg2018-02-171-2/+0
| | | | | | | | | We already have isa<> for this, and these methods were simply duplicating those redundantly. Differential Revision: https://reviews.llvm.org/D43422 llvm-svn: 325418
* [WebAssembly] Simplify FunctionSymbol::get/set/hasFunctionType. NFC.Sam Clegg2018-02-161-13/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D43416 llvm-svn: 325415
* [WebAssebmly] Remove use of Optional to fix assertion in gccSam Clegg2018-02-141-6/+8
| | | | | | | | | | | | | | This was causing GCC builds with fail with: Symbols.h:240:3: error: static assertion failed: Symbol types must be trivially destructible static_assert(std::is_trivially_destructible<T>( The reason this is a gcc-only failure is that OptionalStorage has as specialization for POD types that isn't built under GCC. Differential Revision: https://reviews.llvm.org/D43317 llvm-svn: 325185
* [WebAssembly] Use a Symbol class heirarchy. NFC.Sam Clegg2018-02-141-62/+52
| | | | | | | | | This brings wasm into line with ELF and COFF in terms of symbol types are represented. Differential Revision: https://reviews.llvm.org/D43112 llvm-svn: 325150
* [WebAssembly] Add __data_end link-sythentic symbol.Sam Clegg2018-02-071-0/+1
| | | | | | | | | | | | | | This is similar to _end (See https://linux.die.net/man/3/edata for more) but using our own unique name since our use cases will most likely be different and we want to keep our options open WRT to memory layout. This change will allow is to remove the DataSize from the linking metadata section which is currently being used by emscripten to derive the end of the data. Differential Revision: https://reviews.llvm.org/D42867 llvm-svn: 324443
OpenPOWER on IntegriCloud