Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aarch64] Regression with BTI after nightly-2022-08-14 #102162

Closed
MasterAwesome opened this issue Sep 22, 2022 · 3 comments · Fixed by #105932
Closed

[aarch64] Regression with BTI after nightly-2022-08-14 #102162

MasterAwesome opened this issue Sep 22, 2022 · 3 comments · Fixed by #105932
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MasterAwesome
Copy link
Contributor

MasterAwesome commented Sep 22, 2022

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:

  1. cargo new --lib bti
  2. Add #[lib] crate-type = ["staticlib"] in Cargo.toml
  3. 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:

  1. Download bti.tar.gz
  2. Run reproduce.sh
  3. There are llvm-ir folders generated in the non-working and working 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
@MasterAwesome MasterAwesome added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2022
@inquisitivecrystal inquisitivecrystal added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. labels Sep 23, 2022
@MasterAwesome MasterAwesome changed the title Fat LTO broken when BTI is enabled after nightly-2022-08-14 [aarch64] Regression with BTI after nightly-2022-08-14 Sep 30, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2022

Error: Label P-high can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@MasterAwesome
Copy link
Contributor Author

MasterAwesome commented Oct 15, 2022

Looks like rust-lang/llvm-project@b0343a3 commit is the start of this bug.

Bug not reproduced by running: 

git revert de1b5c91453fb9fc65b931a9afa53c8d407f8460 b3fd3a9ac3eb31bc478abeefe64c05bfbecd3233 1666f09933eefdd666be4c46887ba59ae089361c 218b5c83940d469424564ba6f1ec488c4970a5e5  b0343a38a5910e980bb031e4014655d77cd0c162

Other commits reverted for conflict reasons.

On the https://github.com/rust-lang/llvm-project project branch https://github.com/rust-lang/llvm-project/tree/rustc/15.0-2022-08-09

Commit base: rust-lang/llvm-project@9567f08

@MasterAwesome
Copy link
Contributor Author

MasterAwesome commented Dec 19, 2022

This bug only happens for release mode builds with the same RUSTFLAGS which leads me to believe this unnamed module is release mode specific or this occurs due to some llvm-ir merging/optimization that doesn't happen for debug builds.

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Dec 21, 2022
… r=nikic

Correct branch-protection ModFlagBehavior for Aarch64 on LLVM-15

When building with Fat LTO and BTI enabled on aarch64, the BTI is set to `Module::Min` for alloc shim but is set to `Module::Error` for the crate. This was fine when we were using LLVM-14 but LLVM-15 changes it's behaviour to support for compiling with different `mbranch-protection` flags.

Refer:
rust-lang/llvm-project@b0343a3

fixes rust-lang#102162
@bors bors closed this as completed in 924a1d4 Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants