# Codegen-units=1 not being propagated during rustc bootstrap?

**URL:** <https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183>\
**Category:** compiler\
**Created:** [January 11, 2019, 10:04am UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183 "2019-01-11T10:04:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![happz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/happz/32/5074_2.png) [@happz](https://internals.rust-lang.org/u/happz)\
**Post date:** [January 11, 2019, 10:04am UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183/1 "2019-01-11T10:04:38Z")

</div>

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](https://github.com/rust-lang/rust)
- mkdir ~/build/rustc
- in this directory, I prepared a `config.toml`, using `configure` and few manual tweaks: [https://gist.github.com/happz/f451cd2e4dae128ae13a4fe2a32d1c2d](https://gist.github.com/happz/f451cd2e4dae128ae13a4fe2a32d1c2d)
- I experimented with running `make` but, in the end, I ended up with using `x.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](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](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:

```rust
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:

```rust
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:

```rust
[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?

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [January 12, 2019, 12:28am UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183/2 "2019-01-12T00:28:39Z")

</div>

FWIW, I’m also getting undefined anon references in my attempt to [rebase to the monorepo](https://github.com/rust-lang/llvm-project/pull/1), like:

```nohighlight
  = note: /usr/bin/ld: /home/jistone/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-1f0ebc3792162593.std.dym06td0-cgu.1.rcgu.o: in function `std::sys::unix::process::process_common::Command::capture_env':
          std.dym06td0-cgu.1:(.text._ZN3std3sys4unix7process14process_common7Command11capture_env17haf57b2f2cb9d01efE+0x7cc): undefined reference to `anon.804fe6414c481b186b5bfc2ac6fab39c.2.llvm.12458726759724057866'
          /usr/bin/ld: /home/jistone/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-1f0ebc3792162593.std.dym06td0-cgu.1.rcgu.o: relocation R_X86_64_PC32 against undefined hidden symbol `anon.804fe6414c481b186b5bfc2ac6fab39c.2.llvm.12458726759724057866' can not be used when making a shared object
          /usr/bin/ld: final link failed: bad value
          collect2: error: ld returned 1 exit status

```

… so there’s probably some change on LLVM trunk that we need to figure out.

I don’t know about your codegen-units question though.

edit: I bisected my issue to this commit, which does appear to fit the symptom:

> <https://github.com/rust-lang/llvm-project/commit/bf46e7410c8a1d26c4a434261baaae28a904d657>

---

<div class="post-metadata">

**Author:** ![happz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/happz/32/5074_2.png) [@happz](https://internals.rust-lang.org/u/happz)\
**Post date:** [January 14, 2019, 8:58am UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183/3 "2019-01-14T08:58:11Z")

</div>

Thanks for the pointer! I’ll try to revert the commit, rebase my local patches & try again. The error you got definitely looks like the same issue.

FWIW, me enforcing `codegen-units` - what worked, in the end, was adding `codegen-units = 1` entry into the top-level `Cargo.toml` in my local `rust-lang/rust` repo clone. Every other attempt, including `RUSTFLAGS` and `~/.cargo/config`, were ignored, some `rustc` invocations were missing enforced `codegen-units=1`. I have no idea whether that’s expected - I guess it’s not - but I know very little about Rust build systems…

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [January 14, 2019, 10:10pm UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183/4 "2019-01-14T22:10:11Z")

</div>

It seems to be working after mimicking [this change](https://github.com/rust-lang/llvm-project/commit/bf46e7410c8a1d26c4a434261baaae28a904d657#diff-5bec42d325ce9c44bfafcf4e1cc78465L649) in `rustllvm/PassWrapper.cpp`. I’m going to scan for other ThinLTO changes we might want too, since a lot of this code is copied from LLVM.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [April 14, 2019, 10:10pm UTC](https://internals.rust-lang.org/t/codegen-units-1-not-being-propagated-during-rustc-bootstrap/9183/5 "2019-04-14T22:10:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
