[PATCH v4] alpha: Properly handle local weak undefined symbols
H.J. Lu
hjl.tools@gmail.com
Sun May 24 05:06:44 GMT 2026
On Sun, May 24, 2026 at 11:55 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Sun, May 24, 2026 at 07:24:46AM +0800, H.J. Lu wrote:
> > When processing TLS relocations, elf_hash_table (info)->tls_sec can be
> > NULL if all TLS symbols are weak, hidden and undefined. Don't assert
> > elf_hash_table (info)->tls_sec != NULL. Since the undefined TLS symbol
> > address doesn't map to any TLS storage, it isn't usable. Also set
> > dtp_base and tp_base to 0 if elf_hash_table (info)->tls_sec == NULL.
> >
> > bfd/
> >
> > PR ld/34165
> > * elf64-alpha.c (elf64_alpha_relax_got_load): Set dtp_base and
> > tp_base to 0 if elf_hash_table (info)->tls_sec == NULL.
> > (elf64_alpha_relocate_section): Don't assert
> > elf_hash_table (info)->tls_sec != NULL.
> >
> > ld/
> >
> > PR ld/34165
> > * testsuite/ld-alpha/alpha.exp: Run $srcdir/$subdir/*.d.
> > * testsuite/ld-alpha/tlsbin-undef.d: New file.
> > * testsuite/ld-alpha/tlsbin-undef.s: Likewise.
> > * testsuite/ld-alpha/tlsbin-weak-undef1.d: Likewise.
> > * testsuite/ld-alpha/tlsbin-weak-undef1.s: Likewise.
> > * testsuite/ld-alpha/tlsbin-weak-undef2.d: Likewise.
> > * testsuite/ld-alpha/tlsbin-weak-undef2.s: Likewise.
> > * testsuite/ld-alpha/tlspic-undef.d: Likewise.
> > * testsuite/ld-alpha/tlspic-undef.s: Likewise.
> > * testsuite/ld-alpha/tlspic-weak-undef1.d: Likewise.
> > * testsuite/ld-alpha/tlspic-weak-undef1.s: Likewise.
> > * testsuite/ld-elf/pr34165.c: Likewise.
> > * testsuite/ld-elf/tls.exp: Run PR ld/34165 test.
>
> Thanks, this is good. aarch64-linux and ia64-linux fail the pr34165
> test, exposing similary problems in those backends.
>
It turns out that we need special handling for local weak undefined symbols.
Otherwise, we may get relocation overflow. Here is the v4 patch to set
the local undefined TLS symbol value to 0 with a new testcase.
--
H.J.
---
Since the local undefined TLS symbol address isn't mapped to any TLS
storage, it isn't usable. Set its value to 0 to avoid relocation overflow.
When processing TLS relocations, elf_hash_table (info)->tls_sec can be
NULL if all TLS symbols are weak, hidden and undefined. Don't assert
elf_hash_table (info)->tls_sec != NULL. Always set dtp_base and tp_base
to 0 if elf_hash_table (info)->tls_sec == NULL.
bfd/
PR ld/34165
* * elf-bfd.h (elf_link_local_undefweak_p): New function.
* elf64-alpha.c (elf64_alpha_relax_got_load): Set dtp_base and
tp_base to 0 if elf_hash_table (info)->tls_sec == NULL.
(elf64_alpha_relocate_section): Set the local undefined TLS
symbol value to 0. Don't assert elf_hash_table (info)->tls_sec
!= NULL.
ld/
PR ld/34165
* testsuite/ld-alpha/alpha.exp: Run $srcdir/$subdir/*.d.
* testsuite/ld-alpha/tlsbin-undef.d: New file.
* testsuite/ld-alpha/tlsbin-undef.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef1.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef1.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef2.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef2.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef3.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef3.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef4.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef4.s: Likewise.
* testsuite/ld-alpha/tlspic-undef.d: Likewise.
* testsuite/ld-alpha/tlspic-undef.s: Likewise.
* testsuite/ld-alpha/tlspic-weak-undef1.d: Likewise.
* testsuite/ld-alpha/tlspic-weak-undef1.s: Likewise.
* testsuite/ld-elf/pr34165.c: Likewise.
* testsuite/ld-elf/tls.exp: Run PR ld/34165 test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v4-0001-alpha-Properly-handle-local-weak-undefined-symbol.patch
Type: text/x-patch
Size: 15042 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20260524/d55b8abd/attachment-0001.bin>
More information about the Binutils
mailing list