[llvm] [ARM] Use .reloc for weak symbols in PIC mode instead of GOT indirection (PR #208372)

dong jianqiang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 19:04:56 PDT 2026


================
@@ -2,18 +2,19 @@
 ; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -relocation-model=pic | FileCheck %s
 ; RUN: llc < %s -O0 -fast-isel-abort=2 -mtriple=armv7-linux-gnueabi -relocation-model=pic | FileCheck %s
 
-; Hidden weak function with dso_local must still use GOT indirection
-; in PIC mode on ARM. The assembler eagerly resolves PC-relative
-; expressions like .long xxx-(.LPC+8) when both are in the same section,
-; which prevents the linker from overriding the weak definition with
-; a non-weak one from another object file.
+; Weak dso_local hidden functions must be overridable at link time
+; (a non-weak definition in another object should override the weak one).
+; Instead of using GOT indirection, we use a PC-relative constant pool
+; entry with a .reloc directive to force the assembler to emit a proper
+; relocation (R_ARM_REL32), preventing eager resolution when the symbol
+; and reference are in the same section.
 
 define weak dso_local hidden void @weak_hidden_func() {
   ret void
 }
 
 ; CHECK-LABEL: weak_hidden_func_addr:
-; CHECK:       .long weak_hidden_func(GOT_PREL)
+; CHECK:       .reloc .Ltmp{{[0-9]+}}, R_ARM_REL32, weak_hidden_func
----------------
dongjianqiang2 wrote:

 Thanks for the suggestion and the review! Done. I added a CHECK for the .long so the addend expression is verified, not just the .reloc.

https://github.com/llvm/llvm-project/pull/208372


More information about the llvm-commits mailing list