llvm-project/llvm/test/CodeGen/M68k/gcc_except_table.ll
Peter Lafreniere ebbc5de7db
[M68k] Correctly emit non-pic relocations (#89863)
The m68k backend will always emit external calls (including libcalls)
with
PC-relative PLT relocations, even when in non-pic mode or -fno-plt is
used.

This is unexpected, as other function calls are emitted with absolute
addressing, and a static code modes suggests that there is no PLT. It
also
leads to a miscompilation where the call instruction emitted expects an
immediate address, while the relocation emitted for that instruction is
PC-relative.

This miscompilation can even be seen in the default C function in
godbolt:
https://godbolt.org/z/zEoazovzo

Fix the issue by classifying external function references based upon the
pic
mode. This triggers a change in the static code model, making it more in
line
with the expected behaviour and allowing use of this backend in more
bare-metal
situations where a PLT does not exist.

The change avoids the issue where we emit a PLT32 relocation for an
absolute
call, and makes libcalls and other external calls use absolute
addressing modes
when a static code model is desired.

Further work should be done in instruction lowering and validation to
ensure
that miscompilations of the same type don't occur.
2024-05-03 23:14:56 +08:00

49 lines
1.3 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=m68k < %s | FileCheck %s
; (Copied from test/CodeGen/X86/gcc_except_table.ll)
; Testing whether exception pointer register (d0) and exception selector
; register (d1) are correctly used by landing and EH pad, respectively.
@_ZTIi = external constant ptr
define i32 @foo() uwtable ssp personality ptr @__gxx_personality_v0 {
; CHECK-LABEL: foo:
; CHECK: .Lfunc_begin0:
; CHECK-NEXT: .cfi_startproc
; CHECK-NEXT: .cfi_personality 0, __gxx_personality_v0
; CHECK-NEXT: .cfi_lsda 0, .Lexception0
; CHECK-NEXT: ; %bb.0: ; %entry
; CHECK-NEXT: suba.l #4, %sp
; CHECK-NEXT: .cfi_def_cfa_offset -8
; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: jsr _Z1fv
; CHECK-NEXT: .Ltmp1:
; CHECK-NEXT: ; %bb.1: ; %try.cont
; CHECK-NEXT: moveq #0, %d0
; CHECK-NEXT: adda.l #4, %sp
; CHECK-NEXT: rts
; CHECK-NEXT: .LBB0_2: ; %lpad
; CHECK-NEXT: .Ltmp2:
; CHECK-NEXT: move.l %d0, (%sp)
; CHECK-NEXT: jsr _Unwind_Resume
entry:
invoke void @_Z1fv() optsize
to label %try.cont unwind label %lpad
lpad:
%0 = landingpad { ptr, i32 }
cleanup
catch ptr @_ZTIi
br label %eh.resume
try.cont:
ret i32 0
eh.resume:
resume { ptr, i32 } %0
}
declare void @_Z1fv() optsize
declare i32 @__gxx_personality_v0(...)