[llvm] ca65969 - [AArch64] Unconditionally use DW_EH_PE_indirect|DW_EH_PE_pcrel personality/lsda/ttype encodings
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 5 10:46:48 PST 2023
Author: Fangrui Song
Date: 2023-02-05T10:46:43-08:00
New Revision: ca65969c3ea0ad3db31e8b3646b960c75ef5f6c8
URL: https://github.com/llvm/llvm-project/commit/ca65969c3ea0ad3db31e8b3646b960c75ef5f6c8
DIFF: https://github.com/llvm/llvm-project/commit/ca65969c3ea0ad3db31e8b3646b960c75ef5f6c8.diff
LOG: [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:
https://github.com/llvm/llvm-project/issues/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 unneeded for small code model since "Max text segment
size < 2GiB" but making `-fno-pic -mcmodel={tiny,small}` different seems
unnecessary: 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.
)
---
Two clang/test/Interpreter tests would fail without 6747fc07d1aa94e22622e278e5a02ba70675ac9b
([ORC] Use JITLink as the default linker for LLJIT on Linux/arm64.)
Reviewed By: MatzeB
Differential Revision: https://reviews.llvm.org/D143039
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll
llvm/test/CodeGen/AArch64/pic-eh-stubs.ll
llvm/test/DebugInfo/AArch64/eh_frame_personality.ll
llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 39f7ee73ec203..bdb328fcfdc25 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -182,26 +182,14 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
// The small model guarantees static code/data size < 4GB, but not where it
// will be in memory. Most of these could end up >2GB away so even a signed
// pc-relative 32-bit address is insufficient, theoretically.
- if (isPositionIndependent()) {
- // ILP32 uses sdata4 instead of sdata8
- if (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32) {
- PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- dwarf::DW_EH_PE_sdata4;
- LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
- TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- dwarf::DW_EH_PE_sdata4;
- } else {
- PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- dwarf::DW_EH_PE_sdata8;
- LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
- TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
- dwarf::DW_EH_PE_sdata8;
- }
- } else {
- PersonalityEncoding = dwarf::DW_EH_PE_absptr;
- LSDAEncoding = dwarf::DW_EH_PE_absptr;
- TTypeEncoding = dwarf::DW_EH_PE_absptr;
- }
+ //
+ // Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
+ LSDAEncoding = dwarf::DW_EH_PE_pcrel |
+ (TgtM.getTargetTriple().getEnvironment() == Triple::GNUILP32
+ ? dwarf::DW_EH_PE_sdata4
+ : dwarf::DW_EH_PE_sdata8);
+ PersonalityEncoding = LSDAEncoding | dwarf::DW_EH_PE_indirect;
+ TTypeEncoding = LSDAEncoding | dwarf::DW_EH_PE_indirect;
break;
case Triple::lanai:
LSDAEncoding = dwarf::DW_EH_PE_absptr;
diff --git a/llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll b/llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll
index c6f955f05837d..6c54cec24ac54 100644
--- a/llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-big-endian-eh.ll
@@ -71,5 +71,6 @@ declare void @_ZSt9terminatev()
; CHECK-LABEL: Contents of section .eh_frame:
; CHECK-NEXT: {{^ 0000}}
; CHECK-NEXT: {{^ 0010}}
-; CHECK-NEXT: 0000 0000001c
+; CHECK-NEXT: 0020 0000000c 00440e10 9e040000 0000001c .....D..........
+; CHECK-NEXT: 0030 00000000 017a504c 5200017c 1e0b9c00 .....zPLR..|....
diff --git a/llvm/test/CodeGen/AArch64/pic-eh-stubs.ll b/llvm/test/CodeGen/AArch64/pic-eh-stubs.ll
index 3d072bc892e97..bdb557e5cfe5c 100644
--- a/llvm/test/CodeGen/AArch64/pic-eh-stubs.ll
+++ b/llvm/test/CodeGen/AArch64/pic-eh-stubs.ll
@@ -1,3 +1,4 @@
+; RUN: llc -mtriple=aarch64-none-linux-gnu -relocation-model=static -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
; RUN: llc -mtriple=aarch64-none-linux-gnu -relocation-model=pic -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
; RUN: llc -mtriple=aarch64_be-none-linux-gnu -relocation-model=pic -simplifycfg-require-and-preserve-domtree=1 -o - %s | FileCheck %s
diff --git a/llvm/test/DebugInfo/AArch64/eh_frame_personality.ll b/llvm/test/DebugInfo/AArch64/eh_frame_personality.ll
index 912ebf176e3c7..2ee65a8450811 100644
--- a/llvm/test/DebugInfo/AArch64/eh_frame_personality.ll
+++ b/llvm/test/DebugInfo/AArch64/eh_frame_personality.ll
@@ -17,7 +17,7 @@ clean:
; CHECK: Contents of section .eh_frame:
; CHECK: 0000 1c000000 00000000 017a504c 5200017c .........zPLR..|
-; CHECK: 0010 1e0b0000 00000000 00000000 1b0c1f00 ................
+; CHECK: 0010 1e0b9c00 00000000 0000001c 1b0c1f00 ................
; Don't really care about the rest:
diff --git a/llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll b/llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
index 9d8ef90680d6c..301bf66b7ccd8 100644
--- a/llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
@@ -138,8 +138,8 @@ define void @test4(i32 %n) uwtable personality ptr @__FrameHandler {
; CHECK-LABEL: test4:
; CHECK: .Lfunc_begin0:
; CHECK-NEXT: .cfi_startproc
-; CHECK-NEXT: .cfi_personality 0, __FrameHandler
-; CHECK-NEXT: .cfi_lsda 0, .Lexception0
+; CHECK-NEXT: .cfi_personality 156, DW.ref.__FrameHandler
+; CHECK-NEXT: .cfi_lsda 28, .Lexception0
; CHECK-NEXT: // %bb.0: // %entry
; CHECK-NEXT: stp x30, x21, [sp, #-32]! // 16-byte Folded Spill
; CHECK-NEXT: .cfi_def_cfa_offset 32
More information about the llvm-commits
mailing list