Skip to content

Commit 565a1fb

Browse files
committed
[AArch64] Unconditionally use DW_EH_PE_indirect|DW_EH_PE_pcrel personality/lsda/ttype encodings
For -fno-pic, without DW_EH_PE_indirect, the personality routine pointer in a CIE needs an R_AARCH64_ABS64 relocation. In common configurations that `__gcc_personality_v0` is defined in a shared object, this will lead to a discouraged canonical PLT entry, or, if `ld.lld -z notext` (betwen D122459 and D143136), a dynamic R_AARCH64_ABS64 relocation with an incorrect offset: #60392 Since GCC uses DW_EH_PE_indirect for -fno-pic code (the behavior hasn't changed since the initial port in 2012), let's follow suit by simplifying the code. ( For tiny and small code models, we use DW_EH_PE_sdata8 instead of GCC's DW_EH_PE_sdata4. This is a deliberate choice to support personality-.eh_frame offset > 2GiB. This is necessary for small code model since "Max text segment size < 2GiB" but it is unnecessary to make `-fno-pic -mcmodel={tiny,small}` different: The scenarios that uses both -fno-pic and C++ exceptions have been increasingly rare now, so there is little advantage optimizing for the little size saving with code complexity. ) Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D143039
1 parent 08c915f commit 565a1fb

File tree

5 files changed

+14
-24
lines changed

5 files changed

+14
-24
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,14 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
182182
// The small model guarantees static code/data size < 4GB, but not where it
183183
// will be in memory. Most of these could end up >2GB away so even a signed
184184
// pc-relative 32-bit address is insufficient, theoretically.
185-
if (isPositionIndependent()) {
186-
// ILP32 uses sdata4 instead of sdata8
187-
if (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32) {
188-
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
189-
dwarf::DW_EH_PE_sdata4;
190-
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
191-
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
192-
dwarf::DW_EH_PE_sdata4;
193-
} else {
194-
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
195-
dwarf::DW_EH_PE_sdata8;
196-
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
197-
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
198-
dwarf::DW_EH_PE_sdata8;
199-
}
200-
} else {
201-
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
202-
LSDAEncoding = dwarf::DW_EH_PE_absptr;
203-
TTypeEncoding = dwarf::DW_EH_PE_absptr;
204-
}
185+
//
186+
// Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
187+
LSDAEncoding = dwarf::DW_EH_PE_pcrel |
188+
(TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32
189+
? dwarf::DW_EH_PE_sdata4
190+
: dwarf::DW_EH_PE_sdata8);
191+
PersonalityEncoding = LSDAEncoding | dwarf::DW_EH_PE_indirect;
192+
TTypeEncoding = LSDAEncoding | dwarf::DW_EH_PE_indirect;
205193
break;
206194
case Triple::lanai:
207195
LSDAEncoding = dwarf::DW_EH_PE_absptr;

llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ declare void @_ZSt9terminatev()
7171
; CHECK-LABEL: Contents of section .eh_frame:
7272
; CHECK-NEXT: {{^ 0000}}
7373
; CHECK-NEXT: {{^ 0010}}
74-
; CHECK-NEXT: 0000 0000001c
74+
; CHECK-NEXT: 0020 0000000c 00440e10 9e040000 0000001c .....D..........
75+
; CHECK-NEXT: 0030 00000000 017a504c 5200017c 1e0b9c00 .....zPLR..|....
7576

llvm/test/CodeGen/AArch64/pic-eh-stubs.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; RUN: llc -mtriple=aarch64-none-linux-gnu -relocation-model=static -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
12
; RUN: llc -mtriple=aarch64-none-linux-gnu -relocation-model=pic -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
23
; RUN: llc -mtriple=aarch64_be-none-linux-gnu -relocation-model=pic -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
34

llvm/test/DebugInfo/AArch64/eh_frame_personality.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ clean:
1717

1818
; CHECK: Contents of section .eh_frame:
1919
; CHECK: 0000 1c000000 00000000 017a504c 5200017c .........zPLR..|
20-
; CHECK: 0010 1e0b0000 00000000 00000000 1b0c1f00 ................
20+
; CHECK: 0010 1e0b9c00 00000000 0000001c 1b0c1f00 ................
2121

2222
; Don't really care about the rest:
2323

llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ define void @test4(i32 %n) uwtable personality ptr @__FrameHandler {
138138
; CHECK-LABEL: test4:
139139
; CHECK: .Lfunc_begin0:
140140
; CHECK-NEXT: .cfi_startproc
141-
; CHECK-NEXT: .cfi_personality 0, __FrameHandler
142-
; CHECK-NEXT: .cfi_lsda 0, .Lexception0
141+
; CHECK-NEXT: .cfi_personality 156, DW.ref.__FrameHandler
142+
; CHECK-NEXT: .cfi_lsda 28, .Lexception0
143143
; CHECK-NEXT: // %bb.0: // %entry
144144
; CHECK-NEXT: stp x30, x21, [sp, #-32]! // 16-byte Folded Spill
145145
; CHECK-NEXT: .cfi_def_cfa_offset 32

0 commit comments

Comments
 (0)