[llvm] [ARM] support -mlong-calls -fPIC on arm32 #39970 (PR #147313)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 13 16:35:08 PDT 2025
================
@@ -46,4 +49,62 @@ entry:
declare void @callee0()
+; PIC-O0-LONGCALL-LABEL: global_func:
+; PIC-O0-LONGCALL: bx lr
+
+; PIC-LONGCALL-LABEL: global_func:
+; PIC-LONGCALL: bx lr
+define void @global_func() {
+entry:
+ ret void
+}
+
+; PIC-O0-LONGCALL-LABEL: test_global:
+; PIC-O0-LONGCALL: push {r11, lr}
+; PIC-O0-LONGCALL: ldr r0, [[GOT_LABEL:.*]]
+; PIC-O0-LONGCALL: ldr r0, [pc, r0]
+; PIC-O0-LONGCALL: blx r0
+; PIC-O0-LONGCALL: pop {r11, pc}
+; PIC-O0-LONGCALL: [[GOT_LABEL]]:
+; PIC-O0-LONGCALL: .long global_func(GOT_PREL)
+
+; PIC-LONGCALL-LABEL: test_global:
+; PIC-LONGCALL: push {r11, lr}
+; PIC-LONGCALL: ldr r0, [[GOT_LABEL:.*]]
+; PIC-LONGCALL: ldr r0, [pc, r0]
+; PIC-LONGCALL: blx r0
+; PIC-LONGCALL: pop {r11, pc}
+; PIC-LONGCALL: [[GOT_LABEL]]:
+; PIC-LONGCALL: .long global_func(GOT_PREL)
+define void @test_global() {
+entry:
+ call void @global_func()
+ ret void
+}
+
+; PIC-O0-LONGCALL-LABEL: test_memset:
+; PIC-O0-LONGCALL: push {r11, lr}
+; PIC-O0-LONGCALL: ldr r3, [[GOT_LABEL:.*]]
+; PIC-O0-LONGCALL: ldr r3, [pc, r3]
+; PIC-O0-LONGCALL: blx r3
+; PIC-O0-LONGCALL: pop {r11, pc}
+; PIC-O0-LONGCALL: [[GOT_LABEL]]:
+; PIC-O0-LONGCALL: .long memset(GOT_PREL)
+
+; PIC-LONGCALL-LABEL: test_memset:
+; PIC-LONGCALL: push {r11, lr}
+; PIC-LONGCALL: ldr r3, [[MEMSET_LABEL:.*]]
+; PIC-LONGCALL: add r3, pc, r3
----------------
efriedma-quic wrote:
The -O1 code is wrong. The -O0 code is also wrong.
Look at what we do for something like `extern int x; int* f() { return &x; }`. Or look at what we do for `__attribute((visibility("hidden"))) extern int x; int* f() { return &x; }`.
https://github.com/llvm/llvm-project/pull/147313
More information about the llvm-commits
mailing list