llvm-project/llvm/test/DebugInfo/AArch64/eh_frame_personality.ll
Fangrui Song ca65969c3e [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 6747fc07d1
([ORC] Use JITLink as the default linker for LLJIT on Linux/arm64.)

Reviewed By: MatzeB

Differential Revision: https://reviews.llvm.org/D143039
2023-02-05 10:46:43 -08:00

47 lines
1.7 KiB
LLVM

; RUN: llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu %s -filetype=obj -o %t
; RUN: llvm-objdump -s %t | FileCheck %s
declare i32 @__gxx_personality_v0(...)
declare void @bar()
define i64 @foo(i64 %lhs, i64 %rhs) personality ptr @__gxx_personality_v0 {
invoke void @bar() to label %end unwind label %clean
end:
ret i64 0
clean:
%tst = landingpad { ptr, i32 } cleanup
ret i64 42
}
; CHECK: Contents of section .eh_frame:
; CHECK: 0000 1c000000 00000000 017a504c 5200017c .........zPLR..|
; CHECK: 0010 1e0b9c00 00000000 0000001c 1b0c1f00 ................
; Don't really care about the rest:
; 0020 1c000000 24000000 00000000 24000000 ....$.......$...
; 0030 08000000 00000000 00440c1f 10449e02 .........D...D..
; The key test here is that the personality routine is sanely encoded (under the
; small memory model it must be an 8-byte value for full generality: code+data <
; 4GB, but you might need both +4GB and -4GB depending on where things end
; up. However, for completeness:
; First CIE:
; ----------
; 1c000000: Length = 0x1c
; 00000000: This is a CIE
; 03: Version 3
; 7a 50 4c 52 00: Augmentation string "zPLR" (personality routine, language-specific data, pointer format)
; 01: Code alignment factor 1
; 78: Data alignment factor: -8
; 1e: Return address in x30
; 07: Augmentation data 0xb bytes (this is key!)
; 00: Personality encoding is DW_EH_PE_absptr
; 00 00 00 00 00 00 00 00: First part of aug (personality routine). Relocated, obviously
; 00: Second part of aug (language-specific data): absolute pointer format used
; 1b: pointer format: pc-relative signed 4-byte. Just like GNU.
; 0c 1f 00: Initial instructions ("DW_CFA_def_cfa x31 ofs 0" in this case)