[BOLT][AArch64] Account for hugify alignment in AArch64 long jump layout (#195272)
When --hugify is used for a PIE, the final section allocation in
RewriteInstance::mapCodeSections aligns the address after the last
non-cold text section before laying out the following sections:
for (BinarySection *Section : CodeSections) {
Address = alignTo(Address, Section->getAlignment());
Section->setOutputAddress(Address);
Address += Section->getOutputSize();
if (opts::Hugify && !BC->HasFixedLoadAddress &&
Section->getName() == LastNonColdSectionName)
Address = alignTo(Address, Section->getAlignment());
}
The AArch64 long-jump pass doesn't model that gap in its tentative
layout, so a CBZ could be considered in range during stub insertion and
later become out of range when JITLink applied the final layout.
This patch mirrors the hugify alignment before assigning cold fragment
addresses so that range checks see the same hot-to-cold distance as the
final layout.
Assisted-by: Codex
This commit is contained in:
parent
a2098f2339
commit
b80e53d7a6
2 changed files with 26 additions and 6 deletions
|
|
@ -367,6 +367,11 @@ LongJmpPass::tentativeLayoutRelocMode(const BinaryContext &BC,
|
|||
CurrentIndex = 0;
|
||||
bool ColdLayoutDone = false;
|
||||
auto runColdLayout = [&]() {
|
||||
// Mirror the extra hugify alignment inserted by final section allocation
|
||||
// after the last non-cold section. Account for it before assigning cold
|
||||
// fragment addresses so range checks see the hot-to-cold gap.
|
||||
if (opts::Hugify && !BC.HasFixedLoadAddress && !opts::HotFunctionsAtEnd)
|
||||
DotAddress = alignTo(DotAddress, opts::AlignText);
|
||||
DotAddress = tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
|
||||
ColdLayoutDone = true;
|
||||
if (opts::HotFunctionsAtEnd)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
# Check that branches considered in-range during longjump
|
||||
# may go out of range at JITLink if hugify moves hot code.
|
||||
# The longjump pass may consider branch targets in range during tentative
|
||||
# layout and decide not to insert stubs for them. Later, final section
|
||||
# allocation may insert alignment padding after the last non-cold text section
|
||||
# when hugify is enabled. This moves the following cold section farther away,
|
||||
# resulting in relocation fixups going out of range at JITLink. Check that the
|
||||
# longjump pass accounts for this padding and inserts stubs when needed.
|
||||
|
||||
# REQUIRES: system-linux, asserts
|
||||
# REQUIRES: system-linux, asserts, bolt-runtime, target=aarch64{{.*}}
|
||||
|
||||
# RUN: %clang %cflags -Wl,-q %s -o %t
|
||||
# RUN: link_fdata --no-lbr %s %t %t.fdata
|
||||
# RUN: llvm-strip --strip-unneeded %t
|
||||
# RUN: not llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions --hugify 2>&1 \
|
||||
# RUN: | FileCheck %s
|
||||
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions --hugify
|
||||
# RUN: llvm-objdump -d %t.bolt | FileCheck %s
|
||||
|
||||
.globl foo
|
||||
.type foo, %function
|
||||
|
|
@ -34,4 +38,15 @@ _start:
|
|||
## Force relocation mode.
|
||||
.reloc 0, R_AARCH64_NONE
|
||||
|
||||
# CHECK: BOLT-ERROR: JITLink failed: In graph in-memory object file, section .text: relocation target {{0x[0-9a-f]+}} {{.*}} is out of range of CondBranch19PCRel fixup at address {{0x[0-9a-f]+}} {{.*}}
|
||||
# CHECK: Disassembly of section .text:
|
||||
|
||||
# CHECK: <foo>:
|
||||
# CHECK-NEXT: {{.*}} cbnz x0, 0x[[ADDR0:[0-9a-f]+]] <{{.*}}>
|
||||
# CHECK-NEXT: {{.*}} b 0x[[ADDR1:[0-9a-f]+]] <{{.*}}>
|
||||
# CHECK-NEXT: [[ADDR0]]: {{.*}} b 0x[[ADDR2:[0-9a-f]+]] <{{.*}}>
|
||||
|
||||
# CHECK: Disassembly of section .text.cold:
|
||||
|
||||
# CHECK: <foo.cold.0>:
|
||||
# CHECK-NEXT: [[ADDR2]]: {{.*}} mov x0, #0x1 // =1
|
||||
# CHECK-NEXT: [[ADDR1]]: {{.*}} ret
|
||||
|
|
|
|||
Loading…
Reference in a new issue