Last updated: 2016-08-06
Summary: We'll modify the rustc-builtins crate to make all the intrinsics "undefined", then
we'll proceed to bootstrap rustc normally. This will cause a linker error while linking rustc
because the intrinsics are "undefined". The linker error message will list the intrinsics that are
required to link rustc but the linker couldn't "find".
- First, we avoid building
.soversions ofstd,rustcet al. because those will also fail to link but the linker error message will list all the intrinsics instead of only the ones that are actually needed to build a Rust program (binary). We do this by removing"dylib"from thecrate-typelist (if it's there) for every Cargo.toml.
[package]
(..)
-crate-type = ["dylib", "rlib"]
+crate-type = ["rlib"]
(..)- Stop building the C version of compiler-rt intrinsics. Simply remove the
buildfield fromrustc-builtins'sCargo.toml:
[package]
(..)
-build = "build.rs"
(..)- "Undefine" each and every compiler-rt intrinsic. Modify
rustc-builtins'slib.rslike this:
+#[no_mangle]
+pub extern fn __addsf3() {
+ extern {
+ fn __addsf3_is_undefined();
+ }
+
+ unsafe {
+ __addsf3_is_undefined();
+ }
+}For each intrinsic. In the previous example addsf3 is the name of the intrinsic. How many of these
intrinsics needs to be "undefined"? Each and every intrinsics defined in libcompiler-rt.a. Use
nm to get list of intrinsics from stage0's libcompiler-rt.a:
$ nm libcompiler-rt.a | grep 'T __' | cut -d' ' -f3 | sort -u'
__absvdi2
__absvsi2
__absvti2
(..)
- Bootstrap
rustcusing rustbuild, and observe the linker error
NOTE The example output below is for a compiler with host:
arm-unknown-linux-gnueabi.
$ configure --enable-rustbuild && make
(..)
error: linking with `arm-linux-gnueabi-gcc` failed: exit code: 1
note: "arm-linux-gnueabi-gcc" (..)
note: /home/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/arm-unknown-linux-gnueabi/lib/librustc_builtins-e6891dc09c662475.rlib(rustc_builtins-e6891dc09c662475.0.o): In function `__absvdi2':
rustc_builtins.cgu-0.rs:(.text.__absvdi2+0x0): undefined reference to `__absvdi2_is_undefined'
/home/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/arm-unknown-linux-gnueabi/lib/librustc_builtins-e6891dc09c662475.rlib(rustc_builtins-e6891dc09c662475.0.o): In function `__absvsi2':
rustc_builtins.cgu-0.rs:(.text.__absvsi2+0x0): undefined reference to `__absvsi2_is_undefined'
/home/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/arm-unknown-linux-gnueabi/lib/librustc_builtins-e6891dc09c662475.rlib(rustc_builtins-e6891dc09c662475.0.o): In function `__adddf3':
rustc_builtins.cgu-0.rs:(.text.__adddf3+0x0): undefined reference to `__adddf3_is_undefined'
(..)
The "undefined reference to __absvdi2_is_undefined" lines indicate which intrinsics are required
to link rustc. In this last example, the required intrinsics are: absvdi2, absvsi2, adddf3,
etc.