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

dong jianqiang via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 23:11:37 PDT 2026


dongjianqiang2 wrote:

> This is entirely well-specified and easily produced:
> 
> ```
> [[gnu::weak, gnu::visibility("hidden")]] extern int foo;
> int* bar() { return &foo; }
> ```
> 
> The only correct way to emit that reference is via the GOT, because the compiler doesn't know whether it will be defined or undefined at link time. If it's undefined, it has to materialize as 0, and there is no way for REL32 to produce that outcome.

Thanks for the correction - you're right. extern_weak hidden is reachable from C/C++, and it's not a "doesn't matter" difference: an undefined weak has to materialize as 0, and only the GOT can do that (R_ARM_REL32 can't). That's exactly why isDSOLocal() is the right condition here over || !hasDefaultVisibility() - it keeps undefined weaks on the GOT. Appreciate the catch.

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


More information about the llvm-commits mailing list