Disclaimer - all the work is based on the very recent content of git repositories of rust and LLVM. I am working on a custom target (called “Ducky”) for LLVM - which works well enough for my use case, including clang and lld - and this target is lives in my own fork of LLVM repos and is based on its trunk, which seems to be future LLVM 8.
My idea was to bootstrap a rustc for Ducky - I have a working C/C++ compiler, why not add Rust into the portfolio? Should be a nice excuse for diving into Rust as well. So,
- git clone https://github.com/rust-lang/rust
- mkdir ~/build/rustc
- in this directory, I prepared a
config.toml
, usingconfigure
and few manual tweaks: https://gist.github.com/happz/f451cd2e4dae128ae13a4fe2a32d1c2d - I experimented with running
make
but, in the end, I ended up with usingx.py
directly - stage 0 :
~/git/happz/rust/x.py build --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu --stage 0 --jobs 1
=> https://gist.github.com/happz/fcf8220c63015ae272ecf5430f6f87f2- went fine, no sign of error
- stage 1:
~/git/happz/rust/x.py build --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu --stage 1 --jobs 1
=> https://gist.github.com/happz/ea4e632d31d43cf13966ec375ebf1dff
And here I ran into the issue, stage 1 - still just plain x86_64, no sign of my target at all - failed with a bunch of linker errors:
Building stage1 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Compiling nodrop v0.1.12
Compiling libc v0.2.46
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.0.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.1.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.10.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.11.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.12.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.13.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.2.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.3.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.4.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.5.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.7.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.8.rcgu.o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.9.rcgu.o" "-o" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.568kce49yq92h71g.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps" "-L" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-1f0ebc3792162593.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-d8aa3c70b29301f9.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-2778927fd2b43ec3.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-2e6d898a4c812bcc.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-7bff917400793732.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-b8c4a7dca2ec29d6.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-24bee12b598d36c9.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-511cb181395e536b.rlib" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-852c25e755af0d0c.rlib" "-Wl,--end-group" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0b2f682f2372a9ca.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
= note: /home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.4.rcgu.o: In function `<alloc::collections::btree::map::BTreeMap<K, V> as core::ops::drop::Drop>::drop':
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x54f): undefined reference to `anon.5f91f8358dafbd9c120104ca0cc788cf.2.llvm.6229199703593566319'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x55e): undefined reference to `anon.5f91f8358dafbd9c120104ca0cc788cf.11.llvm.6229199703593566319'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x56d): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x57c): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x58b): undefined reference to `anon.5f91f8358dafbd9c120104ca0cc788cf.5.llvm.6229199703593566319'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x59a): undefined reference to `anon.5f91f8358dafbd9c120104ca0cc788cf.3.llvm.6229199703593566319'
build_script_build.dfqinty8-cgu.4:(.text._ZN100_$LT$alloc..collections..btree..map..BTreeMap$LT$K$C$$u20$V$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h9e90b425bf3ad6c0E+0x5b8): undefined reference to `anon.5f91f8358dafbd9c120104ca0cc788cf.5.llvm.6229199703593566319'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.4.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.4:(.text._ZN4core3ptr18real_drop_in_place17h15f941b7feb28716E+0x3c): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.4.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.4:(.text._ZN4core3ptr18real_drop_in_place17h1f978df61cf6c9b4E+0x37): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.4.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.4:(.text._ZN4core3ptr18real_drop_in_place17h3c372103021132a9E+0x60): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.4:(.text._ZN4core3ptr18real_drop_in_place17h3c372103021132a9E+0x73): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h5a29463afa2493e6E+0x4a): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h5a29463afa2493e6E+0x59): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.4.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h68ebccb7c1466bfcE+0x56): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h68ebccb7c1466bfcE+0x65): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h6ded10369cd928c5E+0x1d0): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h6ded10369cd928c5E+0x1df): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h6ded10369cd928c5E+0x1ee): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.4.llvm.135868953261897967'
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17h6ded10369cd928c5E+0x1fd): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.4.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `core::ptr::real_drop_in_place':
build_script_build.dfqinty8-cgu.6:(.text._ZN4core3ptr18real_drop_in_place17hd0fe08247abd8fedE+0x37): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `build_script_build::main':
build_script_build.dfqinty8-cgu.6:(.text._ZN18build_script_build4main17h680a7ed38e2afc2eE+0x2fa): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.3.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.6.rcgu.o: In function `main':
build_script_build.dfqinty8-cgu.6:(.text.main+0x15): undefined reference to `anon.cd2daae0a671f4c96e8862be1f8faa22.0.llvm.16476670150362609511'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.9.rcgu.o: In function `std::process::Command::new':
build_script_build.dfqinty8-cgu.9:(.text._ZN3std7process7Command3new17h7cf45bc8b56bc5f2E+0x65): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592.build_script_build.dfqinty8-cgu.9.rcgu.o: In function `_ZN4core3ptr18real_drop_in_place17h65b84cc504bb8bf5E.llvm.17482924789063804846':
build_script_build.dfqinty8-cgu.9:(.text._ZN4core3ptr18real_drop_in_place17h65b84cc504bb8bf5E.llvm.17482924789063804846+0x37): undefined reference to `anon.690e140c0b7ee15f9f6c39f33ebd1ad3.5.llvm.135868953261897967'
/usr/bin/ld: /home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592/build_script_build-e75d1a98062c0592: hidden symbol `anon.5f91f8358dafbd9c120104ca0cc788cf.5.llvm.6229199703593566319' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: Could not compile `libc`.
To learn more, run the command again with --verbose.
command did not execute successfully: "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "1" "--release" "--features" "" "--manifest-path" "/home/mprchlik/git/happz/rust/src/rustc/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
failed to run: /home/mprchlik/build/rustc/build/bootstrap/debug/bootstrap build --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu --stage 1 --jobs 1
Build completed unsuccessfully in 0:12:24
So I ran the stage 1 with verbose = 2
, to see the actual command, got to this one:
rustc command: "LD_LIBRARY_PATH"="/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib:/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps:/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib:/home/mprchlik/build/llvm/lib:" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "--crate-name" "build_script_build" "/home/mprchlik/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.46/build.rs" "--color" "never" "--crate-type" "bin" "--emit=dep-info,link" "-C" "opt-level=2" "--cfg" "feature=\"default\"" "--cfg" "feature=\"use_std\"" "-C" "metadata=e75d1a98062c0592-rustc" "-C" "extra-filename=-e75d1a98062c0592" "--out-dir" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592" "-L" "dependency=/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps" "--cap-lints" "allow" "--cfg" "stage1" "-Dwarnings" "-Dbare_trait_objects"
I ran it manually, got the same error. Not very nice, why would it result in so many linker errors?? After some experimenting guided by Google I’ve found out that adding -Ccodegen-unit=1
changes the result:
[pts-7:0]: mprchlik@multivac [master] ~/build/rustc $ LD_LIBRARY_PATH="/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib:/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps:/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/lib:/home/mprchlik/build/llvm/lib:" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "--crate-name" "build_script_build" "/home/mprchlik/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.46/build.rs" "--color" "never" "--crate-type" "bin" "--emit=dep-info,link" "-C" "opt-level=2" "--cfg" "feature=\"default\"" "--cfg" "feature=\"use_std\"" "-C" "metadata=e75d1a98062c0592-rustc" "-C" "extra-filename=-e75d1a98062c0592" "--out-dir" "/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/libc-e75d1a98062c0592" "-L" "dependency=/home/mprchlik/build/rustc/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps" "--cap-lints" "allow" "--cfg" "stage1" "-Dwarnings" "-Dbare_trait_objects" -Ccodegen-units=1
[pts-7:0]: mprchlik@multivac [master] ~/build/rustc $ $?
bash: 0: command not found...
[pts-7:0]: mprchlik@multivac [master] ~/build/rustc $
But apparently the rust.codegen-units
(and rust.codegen-units-std
) setting from my config.toml
does not affect the command above - despite me setting both to 1
, there’s no such option given to the command.
Of course, the problem with linker errors when codegen-units != 1
is another issue, which I was hoping to investigate, unfortunately at this moment, I’m kind of lost in ways rustc bootstrap consumes and applies settings from config.toml
, and I think I’ve made some wrong assumptions about how the bootstrap works. What am I doing wrong, why is the command above ignoring my codegen-units
settings?