summaryrefslogtreecommitdiffstats
path: root/lld/wasm
Commit message (Collapse)AuthorAgeFilesLines
* [lld][WebAssembly] Add libcall symbols to the link when LTO is being used.Sam Clegg2020-01-104-0/+43
| | | | | | | | | | | | | | | 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
* [ThinLTO] Pass CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLPWei Mi2020-01-091-0/+1
| | | | | | | | | | | | | down to pass builder in ltobackend. Currently CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLP in clang are not passed down to pass builder in ltobackend when new pass manager is used. This is inconsistent with the behavior when new pass manager is used and thinlto is not used. Such inconsistency causes slp vectorization pass not being enabled in ltobackend for O3 + thinlto right now. This patch fixes that. Differential Revision: https://reviews.llvm.org/D72386
* [lld] Fix trivial typos in commentsKazuaki Ishizaki2020-01-065-12/+12
| | | | | | Reviewed By: ruiu, MaskRay Differential Revision: https://reviews.llvm.org/D72196
* [lld] Fix -Wrange-loop-analysis warningsFangrui Song2020-01-011-4/+1
| | | | | | | | | | One instance looks like a false positive: lld/ELF/Relocations.cpp:1622:14: note: use reference type 'const std::pair<ThunkSection *, uint32_t> &' (aka 'cons t pair<lld::elf::ThunkSection *, unsigned int> &') to prevent copying for (const std::pair<ThunkSection *, uint32_t> ts : isd->thunkSections) It is not changed in this commit.
* [WebAssembly] Add new `export_name` clang attribute for controlling wasm ↵Sam Clegg2019-12-112-0/+7
| | | | | | | | | | | | | | | | | | | | 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
* LLD: Don't use the stderrOS stream in link before it's reassigned.James Y Knight2019-11-211-8/+8
| | | | | | | | | | | | | | | | Remove the lld::enableColors function, as it just obscures which stream it's affecting, and replace with explicit calls to the stream's enable_colors. Also, assign the stderrOS and stdoutOS globals first in link function, just to ensure nothing might use them. (Either change individually fixes the issue of using the old stream, but both together seems best.) Follow-up to b11386f9be9b2dc7276a758d64f66833da10bdea. Differential Revision: https://reviews.llvm.org/D70492
* Make it possible to redirect not only errs() but also outs()Rui Ueyama2019-11-181-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change is for those who use lld as a library. Context: https://reviews.llvm.org/D70287 This patch adds a new parmeter to lld::*::link() so that we can pass an raw_ostream object representing stdout. Previously, lld::*::link() took only an stderr object. Justification for making stdoutOS and stderrOS mandatory: I wanted to make link() functions to take stdout and stderr in that order. However, if we change the function signature from bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stderrOS = llvm::errs()); to bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS = llvm::outs(), raw_ostream &stderrOS = llvm::errs()); , then the meaning of existing code that passes stderrOS silently changes (stderrOS would be interpreted as stdoutOS). So, I chose to make existing code not to compile, so that developers can fix their code. Differential Revision: https://reviews.llvm.org/D70292
* [WebAssembly][lld] Fix for static linking of PIC codeSam Clegg2019-10-291-2/+0
| | | | | | | | | | | When statically linking PIC code we create an internalized __memory_base so that memory-base-relative relocation work correctly. The value of this global should be zero, and not the globalBase since the globalBase offset is already taken into account by getVirtualAddress. Fixes: https://github.com/emscripten-core/emscripten/issues/9013 Differential Revision: https://reviews.llvm.org/D69600
* [lld][WebAssebmly] Preserve custom import attributes with LTOSam Clegg2019-10-173-6/+37
| | | | | | | | | | | | | | | | | | | Undefined symbols in WebAssembly can come with custom `import-module` and `import-field` attributes. However when reading symbols from bitcode object files during LTO those curtom attributes are not available. Once we compile the LTO object and read in the symbol table from the object file we have access to these custom attributes. In this case, when undefined symbols are added and a symbol already exists in the SymbolTable we can't simple return it, we may need to update the symbol's attributes. Fixes: PR43211 Differential Revision: https://reviews.llvm.org/D68959 llvm-svn: 375081
* [lld][WebAssembly] Fix for weak references to data symbols in archivesSam Clegg2019-10-171-1/+1
| | | | | | | | | | | | | Fix a bug where were not handling relocations against weakly undefined data symbol. Add a test for this case. Also ensure that the weak references to data symbols are not pulled in from archive files by default (but are if `-u <name>` is added to the command line). Fixes: PR43696 Differential Revision: https://reviews.llvm.org/D69073 llvm-svn: 375077
* [WebAssembly] Elide data segments for .bss sectionsThomas Lively2019-10-156-6/+32
| | | | | | | | | | | | | | | | | | | Summary: WebAssembly memories are zero-initialized, so when module does not import its memory initializing .bss sections is guaranteed to be a no-op. To reduce binary size and initialization time, .bss sections are simply not emitted into the final binary unless the memory is imported. Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68965 llvm-svn: 374940
* [lld][WebAssembly] Fix static linking of -fPIC code with external undefined dataJames Clarke2019-10-151-1/+5
| | | | | | | | | | | | | | Reviewers: ruiu, sbc100 Reviewed By: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68991 llvm-svn: 374913
* [WebAssembly] Wrap definitions in namespace lld { namespace wasm {. NFCFangrui Song2019-10-1011-158/+187
| | | | | | | | | | Similar to D68323, but for wasm. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68759 llvm-svn: 374279
* [lld][WebAssembly] Refactor markLive.cpp. NFCSam Clegg2019-10-101-30/+61
| | | | | | | | | This pattern matches the ELF implementation add if also useful as part of a planned change where running `mark` more than once is needed. Differential Revision: https://reviews.llvm.org/D68749 llvm-svn: 374275
* [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
* [lld][WebAssembly] Fix static linking of -fPIC code with external undefined ↵Sam Clegg2019-09-246-29/+50
| | | | | | | | functions Differential Revision: https://reviews.llvm.org/D66784 llvm-svn: 372779
* [lld][WebAssembly] Preserve symbol flags in --relocatable outputSam Clegg2019-09-234-27/+10
| | | | | | | | Fixes https://github.com/emscripten-core/emscripten/issues/8879 Differential Revision: https://reviews.llvm.org/D67729 llvm-svn: 372660
* [WebAssembly][NFC] Remove unnecessary bracesThomas Lively2019-09-191-2/+1
| | | | llvm-svn: 372358
* [WebAssembly] Sort output data sections to place .bss lastThomas Lively2019-09-192-4/+21
| | | | | | | | | | | | | | | | | | | | Summary: This was always the intended behavior, but had not been implemented. This ordering is important for Emscripten when generating .mem files while compiling to JS, since only zeros at the end of initialized memory can be dropped. Fixes https://github.com/emscripten-core/emscripten/issues/8999 Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67736 llvm-svn: 372284
* [lld][WebAssembly] Fix use after free of archive pathSam Clegg2019-09-181-1/+1
| | | | | | | | This was fixed in the ELF backend in https://reviews.llvm.org/D34554. Differential Revision: https://reviews.llvm.org/D67676 llvm-svn: 372266
* [WebAssembly] Initialize memory in start functionThomas Lively2019-09-0411-78/+209
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* [lld][WebAssembly] Fix spurious signature mismatch warningsSam Clegg2019-08-301-2/+9
| | | | | | | | | | | | | | | | | | | Summary: This a follow up on: https://reviews.llvm.org/D62153 Handle the case where there are multiple object files that contain undefined references to the same function. We only generate a function variant if the existing symbol is directly called. See: https://github.com/emscripten-core/emscripten/issues/8995 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67015 llvm-svn: 370509
* [WebAssembly] Implement NO_STRIPDan Gohman2019-08-294-2/+11
| | | | | | | | | | | | | 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] Support for growable tablesJacob Gravelle2019-08-274-1/+10
| | | | | | | | | | | | | | | Adds --growable-table flag to handle building wasm modules with tables that can grow. Wasm tables that we use to store function pointers. In order to add functions to that table at runtime, we need to either preallocate space, or grow the table. In order to specify a table with no maximum size, we need some flag to handle that case, separately from a potential --max-table-size= flag. Note that the number of elements in the table isn't knowable until link-time, so it's unclear if we will want a --max-table-size= flag in the future. llvm-svn: 370127
* [lld][WebAssembly] Create optional symbols after handling --export/--undefinedSam Clegg2019-08-271-2/+2
| | | | | | | | | | | Handling of --export/--undefined can pull in lazy symbols which in turn can pull in referenced to optional symbols. We need to delay the creation of optional symbols until all possible references to them have been created. Differential Revision: https://reviews.llvm.org/D66768 llvm-svn: 370012
* [lld][WebAssembly] Store table base in config rather than passing it around. ↵Sam Clegg2019-08-274-12/+16
| | | | | | | | | | | NFC. I've got another change that makes more use of this value in other places. Differential Revision: https://reviews.llvm.org/D66777 llvm-svn: 370010
* [WebAssembly][lld] Fix crash when applying relocations to debug sectionsSam Clegg2019-08-202-2/+2
| | | | | | | | | | | | | | Debug sections are special in that they can contain relocations against symbols that are not present in the final output (i.e. not live). However it is also possible to have R_WASM_TABLE_INDEX relocations against symbols that don't have a table index assigned (since they are not address taken by actual code. Fixes: https://github.com/emscripten-core/emscripten/issues/9023 Differential Revision: https://reviews.llvm.org/D66435 llvm-svn: 369423
* [lld][WebAssembly] Honor --no-export-dynamic even with -sharedSam Clegg2019-08-191-3/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D66359 llvm-svn: 369276
* [LLD] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-3/+3
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368936
* [lld][WebAssembly] Allow linking of pic code into static binariesSam Clegg2019-08-137-14/+70
| | | | | | | | | | | | 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
* [lld][WebAssembly] Don't create optional symbols when outputing an object fileSam Clegg2019-08-081-25/+27
| | | | | | | | Summary: This was a bug in rL368310. I'm working on a test case now. Differential Revision: https://reviews.llvm.org/D65985 llvm-svn: 368369
* [WebAssembly][lld] control __data_end export with config->sharedGuanzhong Chen2019-08-081-1/+3
| | | | | | | | | | | | | | | | | | | | | Summary: Emscripten expects `__data_end` to show up in PIC code as long as it's not linked with `--shared`. Currently, Emscripten breaks with latest LLVM because `__data_end` is controlled by `config->isPic` instead of `config->shared`.` Reviewers: tlively, sbc100 Reviewed By: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65980 llvm-svn: 368361
* [lld][WebAssembly] Use createGlobalVariable helper function. NFC.Sam Clegg2019-08-081-12/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D65911 llvm-svn: 368325
* [lld][WebAssembly] Add optional symbols after input file handlingSam Clegg2019-08-083-11/+16
| | | | | | | | | | | | | | This allows undefined references in input files be resolved by the optional symbols. Previously we were doing this before input file reading which means it was working only for command line symbols references (i.e. -u or --export). Also use addOptionalDataSymbol for __dso_handle and make all optional symbols hidden by default. Differential Revision: https://reviews.llvm.org/D65920 llvm-svn: 368310
* Re-submit r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-071-5/+5
| | | | | | | | | operator<< The original patch broke buildbots, perhaps because it changed the default setting whether colors are enabled or not. llvm-svn: 368131
* [WebAssembly] Fix null pointer in createInitTLSFunctionGuanzhong Chen2019-08-061-1/+1
| | | | | | | | | | | | | | | | | | | | | Summary: `createSyntheticSymbols`, which creates `WasmSym::InitTLS`, is only called when `!config->relocatable`, but this condition is not checked when calling `createInitTLSFunction`. This diff checks `!config->relocatable` before calling `createInitTLSFunction`. Fixes https://github.com/emscripten-core/emscripten/issues/9155. Reviewers: tlively, aheejin, kripken, sbc100 Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65785 llvm-svn: 368078
* Revert r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-021-5/+5
| | | | | | | | operator<< This reverts commit r367649 in an attempt to unbreak Windows bots. llvm-svn: 367658
* Improve raw_ostream so that you can "write" colors using operator<<Rui Ueyama2019-08-021-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. raw_ostream supports ANSI colors so that you can write messages to the termina with colors. Previously, in order to change and reset color, you had to call `changeColor` and `resetColor` functions, respectively. So, if you print out "error: " in red, for example, you had to do something like this: OS.changeColor(raw_ostream::RED); OS << "error: "; OS.resetColor(); With this patch, you can write the same code as follows: OS << raw_ostream::RED << "error: " << raw_ostream::RESET; 2. Add a boolean flag to raw_ostream so that you can disable colored output. If you disable colors, changeColor, operator<<(Color), resetColor and other color-related functions have no effect. Most LLVM tools automatically prints out messages using colors, and you can disable it by passing a flag such as `--disable-colors`. This new flag makes it easy to write code that works that way. Differential Revision: https://reviews.llvm.org/D65564 llvm-svn: 367649
* [WebAssembly] Set __tls_align to 1 when there is no TLSGuanzhong Chen2019-07-241-5/+6
| | | | | | | | | | | | | | | | | | Summary: We want the tool conventions to state that `__tls_align` will be a power of 2. It makes sense to not have an exception for when there is no TLS. Reviewers: tlively, sunfish Reviewed By: tlively Subscribers: dschuff, sbc100, jgravelle-google, aheejin, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65177 llvm-svn: 366948
* [WebAssembly] Compute and export TLS block alignmentGuanzhong Chen2019-07-194-18/+21
| | | | | | | | | | | | | | | | | | | | | | | | | 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] Use passive segments by default when memory is sharedThomas Lively2019-07-182-5/+4
| | | | | | | | | | | | | | | | | | Summary: This change makes it so that passing --shared-memory is all a user needs to do to get proper multithreaded code. This default can still be explicitly overridden for any reason using --passive-segments and --active-segments. Reviewers: sbc100, quantum Subscribers: dschuff, jgravelle-google, aheejin, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64950 llvm-svn: 366504
* [WebAssembly] fix bug in finding .tdata segmentGuanzhong Chen2019-07-181-2/+3
| | | | | | | | | | | | | | | | Summary: Fix bug in `wasm-ld`'s `Writer::createInitTLSFunction` that only finds `.tdata` if it's the first section. Reviewers: tlively, aheejin, sbc100 Reviewed By: sbc100 Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64947 llvm-svn: 366500
* [lld][WebAssembly] Fix handling of comdat functions in init array.Sam Clegg2019-07-172-6/+5
| | | | | | | | | | | | | | | | | When hidden symbols are discarded by comdat rules we still want to create a local defined symbol, otherwise `Symbol::isDiscarded()` relies on begin able to check `getChunk->discarded`. This is a followup on rL362769. The comdat.ll test was previously GC'ing the `__wasm_call_ctors` functions so `do_init` was not actually being included in the link. Once that function was included in triggered the crash bug that this change addresses. Fixes: https://github.com/emscripten-core/emscripten/issues/8981 Differential Revision: https://reviews.llvm.org/D64872 llvm-svn: 366358
* [WebAssembly] Implement thread-local storage (local-exec model)Guanzhong Chen2019-07-164-5/+125
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [WebAssembly] Rename variale references in comments after VariableName -> ↵Fangrui Song2019-07-165-7/+7
| | | | | | variableName change llvm-svn: 366192
* [WebAssembly] Rename except_ref type to exnrefHeejin Ahn2019-07-151-2/+2
| | | | | | | | | | | | | | | | | | | Summary: We agreed to rename `except_ref` to `exnref` for consistency with other reference types in https://github.com/WebAssembly/exception-handling/issues/79. This also renames WebAssemblyInstrExceptRef.td to WebAssemblyInstrRef.td in order to use the file for other reference types in future. Reviewers: dschuff Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64703 llvm-svn: 366145
* [WebAssembly] i32.const operands should be signedThomas Lively2019-07-121-3/+3
| | | | | | | | | | | | | | | | Summary: This was causing large addresses to be emitted as negative numbers, which rightfully caused crashes in binaryen. Reviewers: aheejin, dschuff Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64612 llvm-svn: 365930
* [WebAssembly] Import __stack_pointer when building -pie binariesSam Clegg2019-07-112-18/+15
| | | | | | | | | | | | | The -pie binary doesn't know that layout ahead of time so needs to import the stack pointer from the embedder, just like we do already for shared libraries. This change is needed in order to address: https://github.com/emscripten-core/emscripten/issues/8915 Differential Revision: https://reviews.llvm.org/D64516 llvm-svn: 365771
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-1125-3043/+3043
| | | | | | | | | | | 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
* Make functions and member variables distinguishable even after the name ↵Rui Ueyama2019-07-107-53/+55
| | | | | | style change. NFC. llvm-svn: 365605
OpenPOWER on IntegriCloud