Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprust: Import LLD for linking wasm objects #48125
Conversation
This comment has been minimized.
This comment has been minimized.
|
cc @yurydelendik I think this may regress the source map support for wasm32-unknown-unknown as I'm not sure if lld has that implemented like binaryen does, but I could be wrong! |
mzji
reviewed
Feb 10, 2018
| // rethought from the ground up once a linker (lld) is available, so this is all | ||
| // temporary and should improve in the future. | ||
| // There's some trickery below on crate types supported and various defaults | ||
| // (aka panic=abort by default), but otherwise this is ing eneral a relatively |
This comment has been minimized.
This comment has been minimized.
kennytm
added
T-compiler
S-waiting-on-review
labels
Feb 10, 2018
This comment has been minimized.
This comment has been minimized.
Correct, it will regress the rust source maps support. I was planing to look into exporting source maps from LLVM next. |
alexcrichton
force-pushed the
alexcrichton:lld
branch
3 times, most recently
from
ddf7169
to
8b11f93
Feb 10, 2018
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
Mark-Simulacrum
Feb 10, 2018
This comment has been minimized.
This comment has been minimized.
Is that the case for all the targets or only for the wasm32-unknown-unknown target? Because I think it would be great to be able to link ARM Cortex-M binaries using the lld shipped with rustc; that way we don't need to install arm-none-eabi-ld on the host. |
This comment has been minimized.
This comment has been minimized.
|
@japaric it is indeed true for all targets! I haven't added support for LLD for other targets yet in this PR but I'm hopefully structuring it in such a way that it should be fairly easy. That I'm hoping can be a quick followup :) |
japaric
referenced this pull request
Feb 10, 2018
Closed
LLD support (AKA LLD *almost* works out of the box) #53
This comment has been minimized.
This comment has been minimized.
|
It's also important to note that this PR actually regresses the apparent hello size of "hello world" in wasm. Fear not, though, this is intended and not as bad as it seems! Today this program: #![crate_type = "cdylib"]
#[no_mangle]
pub extern fn foo(a: u32) -> u32 {
a + 1
} generates a 17k hello world with With this PR, however, the size of the first compilation is 633k (!) and with wasm-gc it only reduces to 209k (!). Not to fear, though, this is expected! This "bug" is due to the fact that the To recap, here's the size of the program above in various stages:
As always for the smallest binaries it's recommended to compile with |
This comment has been minimized.
This comment has been minimized.
|
@japaric hm actually I've been meaning to refactor this for quite some time now, so f359356 should do the trick. In theory, once this lands, you can simply specify (this will likely be buggy when it first starts out as it's never been used before!) |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton awesome! I've also confirmed that the version of LLD that ihis PR will ship can link ARM Cortex-M applications (older versions of LLD had problems with the linker scripts we use) |
This comment has been minimized.
This comment has been minimized.
With this PR, how is memory imported then? |
alexcrichton
force-pushed the
alexcrichton:lld
branch
from
f359356
to
5adcd97
Feb 10, 2018
This comment has been minimized.
This comment has been minimized.
|
@badboy with LLD you've now got a whole slew of options for configuring memory and how everything gets linked, but I think you'd at least start with |
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Feb 10, 2018
alexcrichton
force-pushed the
alexcrichton:lld
branch
from
5adcd97
to
c0c4ab1
Feb 10, 2018
Mark-Simulacrum
approved these changes
Feb 11, 2018
|
So this in general looks good to me but I'm not familiar with the linker bits in |
| @@ -81,7 +81,7 @@ matrix: | |||
| # OSX 10.7 and `xcode7` is the latest Xcode able to compile LLVM for 10.7. | |||
| - env: > | |||
| RUST_CHECK_TARGET=dist | |||
| RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-extended --enable-profiler --enable-emscripten" | |||
| RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-tier1-tools --enable-profiler" | |||
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Feb 11, 2018
Member
tier1-tools is probably not quite the best name for this -- since you can enable it (presumably) on non-tier1 platforms, and the platforms being "tier1" really has nothing to do with it -- I'd prefer something like full-tools or similar.
| lld_install_root: &Path) { | ||
| let target = target_compiler.host; | ||
|
|
||
| let dst = builder.sysroot_libdir(target_compiler, target) |
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Feb 11, 2018
Member
Hm, so I feel like I'd sort of expect this to be in a non-target specific place -- that is, lld would presumably work for both x86_64-unknown-linux-gnu as much as wasm32-unknown-unknown... I don't think we have a good place to put it (since the sysroot/bin directory is probably a bad idea)... but something to think about. We may want to change this down the road to avoid duplicating it across the various platforms that will probably want to default to lld down the road.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Feb 11, 2018
Author
Member
Ah so this isn't necessarily target-specific, it's also where we put the codegen backends for example. The target in the directory name is basically "things in here are only relevant for this target", which for the case of binaries just means that platform the binaries run on. We'll use the lld executable here (by placing it in PATH) regardless of the actual target of the compiler.
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Feb 11, 2018
Member
Hm, okay. Seems slightly odd, since presumably that means that we'd have to have the rustlib for, say, x86_64-unknown-linux-gnu installed if that's where we ship lld even if you want to use lld for some windows target. But maybe I'm creating problems where none exist.
| fn finalize(&mut self) -> Command { | ||
| self.cmd.arg("--threads"); | ||
|
|
||
| // FIXME we probably shouldn't pass this but instead pass an explicit |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I find this somewhat suspicious. Did LLD tip regress? It looks like it gc's less out of the wasm files... |
alexcrichton
referenced this pull request
Feb 11, 2018
Closed
Use the linker directly on darwin,ios #46255
This comment has been minimized.
This comment has been minimized.
|
@Mark-Simulacrum heh I had to double check as well. LLD didn't regress per se but it did emit a few more annotations/exports for things I didn't quite recognize (but seemed injected in LLVM/LLD/etc). In general LLD-for-wasm I believe is still early-days, so I suspect that this'll get smoothed out over time! |
alexcrichton
force-pushed the
alexcrichton:lld
branch
from
9615abc
to
ce52e0e
Feb 11, 2018
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 4, 2018
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 0129b01
into
rust-lang:master
Mar 4, 2018
This was referenced Mar 4, 2018
alexcrichton
deleted the
alexcrichton:lld
branch
Mar 4, 2018
This was referenced Mar 6, 2018
This was referenced Mar 6, 2018
Arnavion
referenced this pull request
Mar 6, 2018
Closed
WASM module base address is always 0, prevents multiple modules with single imported memory #46645
alexcrichton
referenced this pull request
Mar 7, 2018
Closed
Spurious timeout in the asmjs builder #48826
kennytm
referenced this pull request
Mar 23, 2018
Closed
binaryen is being built with inappropriate compiler flags for i586-unknown-linux-gnu host #49267
cuviper
referenced this pull request
Mar 24, 2018
Open
Armv6 builds of rust appear to be armv7 contaminated. #49280
ngg
referenced this pull request
May 15, 2018
Closed
Wrong codegen for wasm32 with opt-level >= 2 #50754
comex
referenced this pull request
May 30, 2018
Closed
Pass -lfoo to linker rather than -l foo. #51197
frol
added a commit
to frol/yew-actix-protobuf-sample
that referenced
this pull request
Jul 3, 2018
frol
referenced this pull request
Jul 3, 2018
Merged
Enable LTO for the client to cut the WASM output size by 10x (2.6MB -> 260KB) #1
This comment has been minimized.
This comment has been minimized.
oooutlk
commented
Aug 23, 2018
|
Any schedule to turn on lld by default on Tier-2 platform? |
alexcrichton commentedFeb 10, 2018
This commit imports the LLD project from LLVM to serve as the default linker for
the
wasm32-unknown-unknowntarget. Thebinaryensubmoule is consequentlyremoved along with "binaryen linker" support in rustc.
Moving to LLD brings with it a number of benefits for 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.
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!
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.
wasm-gcwill soon no longer be necessary, LLDwill natively implement
--gc-sections(better thanwasm-gc!) whichmeans 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_60branch, but this may get upgraded inthe near future!
LLD is placed into rustc's sysroot in a
bindirectory. This is similar towhere
gcc.execan be found on Windows. This directory is automatically addedto
PATHwhenever rustc executes the linker, allowing us to define aWasmLdlinker 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.tomloption to be enabled to turn it on.Finally the unstable
#![wasm_import_memory]attribute was also removed as LLDhas a native option for controlling this.