Skip to content
Permalink
Branch: master
Commits on Aug 16, 2019
  1. [WebAssembly] Forbid use of EM_ASM with setjmp/longjmp

    quantum5 committed Aug 16, 2019
    Summary:
    We tried to support EM_ASM with setjmp/longjmp in binaryen. But with dynamic
    linking thrown into the mix, the code is no longer understandable and cannot
    be maintained. We also discovered more bugs in the EM_ASM handling code.
    
    To ensure maintainability and correctness of the binaryen code, EM_ASM will
    no longer be supported with setjmp/longjmp. This is probably fine since the
    support was added recently and haven't be published.
    
    Reviewers: tlively, sbc100, jgravelle-google, kripken
    
    Reviewed By: tlively, kripken
    
    Subscribers: dschuff, hiraditya, aheejin, sunfish, llvm-commits
    
    Tags: #llvm
    
    Differential Revision: https://reviews.llvm.org/D66356
    
    llvm-svn: 369137
Commits on Aug 15, 2019
  1. [WebAssembly] Correctly handle va_arg of zero-sized structures

    quantum5 committed Aug 15, 2019
    Summary:
    D66168 passes size 0 structs indirectly, while the wasm backend expects it to
    be passed directly. This causes subsequent variadic arguments to be read
    incorrectly.
    
    This diff changes it so that size 0 structs are passed directly.
    
    Reviewers: dschuff, tlively, sbc100
    
    Reviewed By: dschuff
    
    Subscribers: jgravelle-google, aheejin, sunfish, cfe-commits
    
    Tags: #clang
    
    Differential Revision: https://reviews.llvm.org/D66255
    
    llvm-svn: 369042
Commits on Aug 13, 2019
  1. [WebAssembly] Make clang emit correct va_arg code for structs

    quantum5 committed Aug 13, 2019
    Summary:
    In the WebAssembly backend, when lowering variadic function calls, non-single
    member aggregate type arguments are always passed by pointer.
    
    However, when emitting va_arg code in clang, the arguments are instead read as
    if they are passed directly. This results in the pointer being read as the
    actual structure.
    
    Fixes emscripten-core/emscripten#9042.
    
    Reviewers: tlively, sbc100, kripken, aheejin, dschuff
    
    Reviewed By: dschuff
    
    Subscribers: dschuff, jgravelle-google, sunfish, cfe-commits
    
    Tags: #clang
    
    Differential Revision: https://reviews.llvm.org/D66168
    
    llvm-svn: 368750
Commits on Aug 8, 2019
  1. [WebAssembly][lld] control __data_end export with config->shared

    quantum5 committed Aug 8, 2019
    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
Commits on Aug 6, 2019
  1. [WebAssembly] Lower ASan constructor priority on Emscripten

    quantum5 committed Aug 6, 2019
    Summary:
    This change gives Emscripten the ability to use more than one constructor
    priorities that runs before ASan. By convention, constructor priorites 0-100
    are reserved for use by the system. ASan on Emscripten now uses priority 50,
    leaving plenty of room for use by Emscripten before and after ASan.
    
    This change is done in response to:
    emscripten-core/emscripten#9076 (comment)
    
    Reviewers: kripken, tlively, aheejin
    
    Reviewed By: tlively
    
    Subscribers: cfe-commits, dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits
    
    Tags: #llvm, #clang
    
    Differential Revision: https://reviews.llvm.org/D65684
    
    llvm-svn: 368101
  2. [WebAssembly] Fix null pointer in createInitTLSFunction

    quantum5 committed Aug 6, 2019
    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 emscripten-core/emscripten#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
Commits on Jul 24, 2019
  1. [WebAssembly] Set __tls_align to 1 when there is no TLS

    quantum5 committed Jul 24, 2019
    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
Commits on Jul 19, 2019
  1. [WebAssembly] Compute and export TLS block alignment

    quantum5 committed Jul 19, 2019
    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
Commits on Jul 18, 2019
  1. [WebAssembly] fix bug in finding .tdata segment

    quantum5 committed Jul 18, 2019
    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
  2. [WebAssembly] Fix __builtin_wasm_tls_base intrinsic

    quantum5 committed Jul 18, 2019
    Summary:
    Properly generate the outchain for the `__builtin_wasm_tls_base` intrinsic.
    
    Also marked the intrinsic pure, per @sunfish's suggestion.
    
    Reviewers: tlively, aheejin, sbc100, sunfish
    
    Reviewed By: tlively
    
    Subscribers: dschuff, jgravelle-google, hiraditya, cfe-commits, llvm-commits, sunfish
    
    Tags: #clang, #llvm
    
    Differential Revision: https://reviews.llvm.org/D64949
    
    llvm-svn: 366499
  3. [WebAssembly] Implement __builtin_wasm_tls_base intrinsic

    quantum5 committed Jul 18, 2019
    Summary:
    Add `__builtin_wasm_tls_base` so that LeakSanitizer can find the thread-local
    block and scan through it for memory leaks.
    
    Reviewers: tlively, aheejin, sbc100
    
    Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits
    
    Tags: #clang, #llvm
    
    Differential Revision: https://reviews.llvm.org/D64900
    
    llvm-svn: 366475
Commits on Jul 16, 2019
  1. [WebAssembly] Compile all TLS on Emscripten as local-exec

    quantum5 committed Jul 16, 2019
    Summary:
    Currently, on Emscripten, dynamic linking is not supported with threads.
    This means that if thread-local storage is used, it must be used in a
    statically-linked executable. Hence, local-exec is the only possible model.
    
    This diff compiles all TLS variables to use local-exec on Emscripten as a
    temporary measure until dynamic linking is supported with threads.
    
    The goal for this is to allow C++ types with constructors to be thread-local.
    
    Currently, when `clang` compiles a `thread_local` variable with a constructor,
    it generates `__tls_guard` variable:
    
        @__tls_guard = internal thread_local global i8 0, align 1
    
    As no TLS model is specified, this is treated as general-dynamic, which we do
    not support (and cannot support without implementing dynamic linking support
    with threads in Emscripten). As a result, any C++ constructor in `thread_local`
    variables would not compile.
    
    By compiling all `thread_local` as local-exec, `__tls_guard` will compile and
    we can support C++ constructors with TLS without implementing dynamic linking
    with threads.
    
    Depends on D64537
    
    Reviewers: tlively, aheejin, sbc100
    
    Reviewed By: aheejin
    
    Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, llvm-commits
    
    Tags: #llvm
    
    Differential Revision: https://reviews.llvm.org/D64776
    
    llvm-svn: 366275
  2. [WebAssembly] Implement thread-local storage (local-exec model)

    quantum5 committed Jul 16, 2019
    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
Commits on Jul 3, 2019
  1. [WebAssembly][NFC] simplify SjLj inline assembly test

    quantum5 committed Jul 3, 2019
    Summary:
    Per feedback in D64115, simplify the test.
    
    `hidden` is left in though, because every test in the file has it.
    
    Reviewers: aheejin, tlively
    
    Subscribers: dschuff, sbc100, jgravelle-google, sunfish, llvm-commits
    
    Tags: #llvm
    
    Differential Revision: https://reviews.llvm.org/D64117
    
    llvm-svn: 365089
  2. [WebAssembly] Prevent inline assembly from being mangled by SjLj

    quantum5 committed Jul 3, 2019
    Summary:
    Before, inline assembly gets mangled by the SjLj transformation.
    
    For example, in a function with setjmp/longjmp, this LLVM IR code
    
        call void asm sideeffect "", ""()
    
    would be transformed into
    
        call void @__invoke_void(void ()* asm sideeffect "", "")
    
    This is invalid, and results in the error:
    
        Cannot take the address of an inline asm!
    
    In this diff, we skip the transformation for inline assembly.
    
    Reviewers: aheejin, tlively
    
    Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits
    
    Tags: #llvm
    
    Differential Revision: https://reviews.llvm.org/D64115
    
    llvm-svn: 364985
Commits on Jun 26, 2019
  1. [WebAssembly] Implement Address Sanitizer for Emscripten

    quantum5 committed Jun 26, 2019
    Summary:
    This diff enables address sanitizer on Emscripten.
    
    On Emscripten, real memory starts at the value passed to --global-base.
    
    All memory before this is used as shadow memory, and thus the shadow mapping
    function is simply dividing by 8.
    
    Reviewers: tlively, aheejin, sbc100
    
    Reviewed By: sbc100
    
    Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits
    
    Tags: #clang, #llvm
    
    Differential Revision: https://reviews.llvm.org/D63742
    
    llvm-svn: 364468
  2. [wasm-ld] Add __global_base symbol to mark the value of --global-base

    quantum5 committed Jun 26, 2019
    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
You can’t perform that action at this time.