Description
Enabling -Zbranch-protection=bti
on rustc (nightly-2022-08-14) doesn't generate staticlibraries or cdylib anymore. This happens after the LLVM 14 to LLVM 15 change as bisected below cargo-bisect-rustc where LLVM-15 sets the branch-target-enforcement
flag only for the module being compiled. Even with -Z build-std
this build fails as there is a module without a name that doesn't have branch-target-enforcement
set.
Earlier in nightly-2022-08-12
BTI works even without requiring the -Z build-std
The way I'm reproducing this (patch attached to make this easier) is by:
cargo new --lib bti
- Add
#[lib] crate-type = ["staticlib"]
in Cargo.toml - Run
RUSTFLAGS="-C embed-bitcode -C lto -Z branch-protection=bti" cargo +nightly-2022-08-14 build --release --target aarch64-unknown-linux-gnu
Meta
Working in -- nightly-2022-08-12
rustc --version --verbose
:
rustc 1.65.0-nightly (20ffea693 2022-08-11)
binary: rustc
commit-hash: 20ffea6938b5839c390252e07940b99e3b6a889a
commit-date: 2022-08-11
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 14.0.6
First failing in -- nightly-2022-08-14
rustc --version --verbose
rustc 1.65.0-nightly (75b7e52e9 2022-08-13)
binary: rustc
commit-hash: 75b7e52e92c3b00fc891b47f5b2efdff0a2be55a
commit-date: 2022-08-13
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
This issue persists even in the latest build nightly-2022-09-21
rustc 1.66.0-nightly (9062b780b 2022-09-21)
binary: rustc
commit-hash: 9062b780b32d2eab060b4432863e085d9504ca5c
commit-date: 2022-09-21
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0
Error output
warning: linking module flags 'branch-target-enforcement': IDs have conflicting behaviors in '' and 'bti.d1e91840-cgu.0'
error: failed to load bitcode of module "g9v5z2qx9o25o51":
warning: `bti` (lib) generated 1 warning
error: could not compile `bti` due to previous error; 1 warning emitted
Backtrace
$ RUST_BACKTRACE=1 RUSTFLAGS="-C embed-bitcode -C lto -Z branch-protection=bti" cargo +nightly-2022-08-14 build --release --target aarch64-unknown-linux-gnu
Compiling bti v0.1.0 (/mnt/lhdd/rust/bti)
warning: linking module flags 'branch-target-enforcement': IDs have conflicting behaviors in '' and 'bti.d1e91840-cgu.0'
error: failed to load bitcode of module "g9v5z2qx9o25o51":
warning: `bti` (lib) generated 1 warning
error: could not compile `bti` due to previous error; 1 warning emitted
How to reproduce:
- Download bti.tar.gz
- Run
reproduce.sh
- There are
llvm-ir
folders generated in thenon-working
andworking
folders
LLVM-IR for working:
bti-91ac4c6007946ced.std-a054a5b1fd87a365.std.3cb045be-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.addr2line-25b6f8dd0ea2eecc.addr2line.0d6e2ec0-cgu.0.rcgu.o.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.bti.f7253899-cgu.0.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.alloc-4a3ca9ff3fbc662b.alloc.03d967e7-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.panic_unwind-c6104dcb55eef74c.panic_unwind.f83e46b6-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.1hbu099i1fb4i51x.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.gimli-fd90f4a47526f3b3.gimli.d69643a5-cgu.0.rcgu.o.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 1}
LLVM-IR regressed:
bti-91ac4c6007946ced.std-a054a5b1fd87a365.std.3cb045be-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 0}
bti-91ac4c6007946ced.addr2line-25b6f8dd0ea2eecc.addr2line.0d6e2ec0-cgu.0.rcgu.o.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 0}
bti-91ac4c6007946ced.bti.f7253899-cgu.0.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 1}
bti-91ac4c6007946ced.alloc-4a3ca9ff3fbc662b.alloc.03d967e7-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 0}
bti-91ac4c6007946ced.panic_unwind-c6104dcb55eef74c.panic_unwind.f83e46b6-cgu.0.rcgu.o.rcgu.ll:!4 = !{i32 1, !"branch-target-enforcement", i32 0}
bti-91ac4c6007946ced.1hbu099i1fb4i51x.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 0}
bti-91ac4c6007946ced.gimli-fd90f4a47526f3b3.gimli.d69643a5-cgu.0.rcgu.o.rcgu.ll:!2 = !{i32 1, !"branch-target-enforcement", i32 0}
cargo-bisect-rustc
searched nightlies: from nightly-2022-08-12 to nightly-2022-08-14
regressed nightly: nightly-2022-08-13
searched commit range: 20ffea6...f22819b
regressed commit: e2b52ff
bisected with cargo-bisect-rustc v0.6.4
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc --start=2022-08-12 --end=2022-08-14 --script=test.sh --target aarch64-unknown-linux-gnu