Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Import LLD for linking wasm objects #48125

Merged
merged 2 commits into from
Mar 4, 2018
Merged

Commits on Mar 4, 2018

  1. rust: Import LLD for linking wasm objects

    This commit imports the LLD project from LLVM to serve as the default linker for
    the `wasm32-unknown-unknown` target. The `binaryen` submoule is consequently
    removed along with "binaryen linker" support in rustc.
    
    Moving to LLD brings with it a number of benefits for wasm code:
    
    * LLD is itself an actual linker, so there's no need to compile all wasm code
      with LTO any more. As a result builds should be *much* speedier as LTO is no
      longer forcibly enabled for all builds of the wasm target.
    * LLD is quickly becoming an "official solution" for linking wasm code together.
      This, I believe at least, is intended to be the main supported linker for
      native code and wasm moving forward. Picking up support early on should help
      ensure that we can help LLD identify bugs and otherwise prove that it works
      great for all our use cases!
    * Improvements to the wasm toolchain are currently primarily focused around LLVM
      and LLD (from what I can tell at least), so it's in general much better to be
      on this bandwagon for bugfixes and new features.
    * Historical "hacks" like `wasm-gc` will soon no longer be necessary, LLD
      will [natively implement][gc] `--gc-sections` (better than `wasm-gc`!) which
      means a postprocessor is no longer needed to show off Rust's "small wasm
      binary size".
    
    LLD is added in a pretty standard way to rustc right now. A new rustbuild target
    was defined for building LLD, and this is executed when a compiler's sysroot is
    being assembled. LLD is compiled against the LLVM that we've got in tree, which
    means we're currently on the `release_60` branch, but this may get upgraded in
    the near future!
    
    LLD is placed into rustc's sysroot in a `bin` directory. This is similar to
    where `gcc.exe` can be found on Windows. This directory is automatically added
    to `PATH` whenever rustc executes the linker, allowing us to define a `WasmLd`
    linker which implements the interface that `wasm-ld`, LLD's frontend, expects.
    
    Like Emscripten the LLD target is currently only enabled for Tier 1 platforms,
    notably OSX/Windows/Linux, and will need to be installed manually for compiling
    to wasm on other platforms. LLD is by default turned off in rustbuild, and
    requires a `config.toml` option to be enabled to turn it on.
    
    Finally the unstable `#![wasm_import_memory]` attribute was also removed as LLD
    has a native option for controlling this.
    
    [gc]: https://reviews.llvm.org/D42511
    alexcrichton committed Mar 4, 2018
    Configuration menu
    Copy the full SHA
    d69b248 View commit details
    Browse the repository at this point in the history
  2. rustc: Tweak default linker selection

    This commit refactors how the path to the linker that we're going to invoke is
    selected. Previously all targets listed *both* a `LinkerFlavor` and a `linker`
    (path) option, but this meant that whenever you changed one you had to change
    the other. The purpose of this commit is to avoid coupling these where possible.
    
    Target specifications now only unconditionally define the *flavor* of the linker
    that they're using by default. If not otherwise specified each flavor now
    implies a particular default linker to run. As a result, this means that if
    you'd like to test out `ld` for example you should be able to do:
    
        rustc -Z linker-flavor=ld foo.rs
    
    whereas previously you had to do
    
        rustc -Z linker-flavor=ld -C linker=ld foo.rs
    
    This will hopefully make it a bit easier to tinker around with variants that
    should otherwise be well known to work, for example with LLD, `ld` on OSX, etc.
    alexcrichton committed Mar 4, 2018
    Configuration menu
    Copy the full SHA
    0129b01 View commit details
    Browse the repository at this point in the history