Skip to content

Prologue of function missing in FatLTO but present in ThinLTO #103619

Closed
@MasterAwesome

Description

@MasterAwesome

Compiling with branch-target-enforcement = 1(-Zbranch-protection=bti) on aarch64-unknown-linux-gnu causes different code to emitted in the prologue of the function for fat LTO and thin LTO in debug mode.

Baseline assembly for function add defined as follows:

#[no_mangle]
pub extern "C" fn add(left: usize, right: usize) -> usize {
    left.wrapping_add(right)
}

compiled into a cdylib.

[DEBUG] llvm-objdump on ThinLTO

0000000000010408 <add>:
   10408: d503245f     	bti	c ; not present in FatLTO
   1040c: d10043ff     	sub	sp, sp, #16
   10410: 8b010008     	add	x8, x0, x1
   10414: f90007e8     	str	x8, [sp, #8]
   10418: 14000001     	b	0x1041c <add+0x14>
   1041c: f94007e0     	ldr	x0, [sp, #8]
   10420: 910043ff     	add	sp, sp, #16
   10424: d65f03c0     	ret

[DEBUG] llvm-objdump on FatLTO

0000000000010408 <add>:
   10408: d10043ff     	sub	sp, sp, #16
   1040c: 8b010008     	add	x8, x0, x1
   10410: f90007e8     	str	x8, [sp, #8]
   10414: 14000001     	b	0x10418 <add+0x10>
   10418: f94007e0     	ldr	x0, [sp, #8]
   1041c: 910043ff     	add	sp, sp, #16
   10420: d65f03c0     	ret

[RELEASE] llvm-objdump on both FatLTO and ThinLTO

0000000000010238 <add>:
   10238: d503245f     	bti	c
   1023c: 8b000020     	add	x0, x1, x0
   10240: d65f03c0     	ret

rustc version with failure first occuring:

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

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

Might be related to: #102162 as reverting the same patches in that issue solves the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions