]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
i386: Add GLIBC_ABI_GNU_TLS version dependency
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 17 Aug 2025 22:22:22 +0000 (15:22 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 20 Aug 2025 20:53:32 +0000 (13:53 -0700)
commitfbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07
tree598c9896e3396c675c8bef02487ba53ec2cfbeeb
parent66e4999f343f85116cf2dda137cc0f31ac793ce6
i386: Add GLIBC_ABI_GNU_TLS version dependency

On Linux/i386, programs and shared libraries compiled with
-mtls-dialect=gnu may fail silently at run-time against glibc without
the GNU TLS run-time fix for:

https://sourceware.org/bugzilla/show_bug.cgi?id=32996

The glibc version tag, GLIBC_ABI_GNU_TLS, has been added to indicate
that glibc has the working GNU TLS run-time:

commit ed1b7a5a489ab555a27fad9c101ebe2e1c1ba881
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jul 28 12:16:11 2025 -0700

    i386: Add GLIBC_ABI_GNU_TLS version [BZ #33221]

Add the --gnu-tls-tag option to x86-64 ELF linker to add the
GLIBC_ABI_GNU_TLS version dependency in output programs and shared
libraries when linking against glibc if input relocatable object files
call ___tls_get_addr.  The output will fail to load and run at run-time
against glibc which doesn't define the GLIBC_ABI_GNU_TLS version.

Add the --enable-gnu-tls-tag configure option to enable --gnu-tls-tag
by default.  If unspecified, linker will add the GLIBC_ABI_GNU_TLS
version dependency if input call ___tls_get_addr and libc.so defines
the GLIBC_ABI_GNU2_TLS version.

bfd/

PR ld/33287
* elf-linker-x86.h (elf_linker_x86_params): Add
gnu_tls_version_tag.
* elf32-i386.c (elf_backend_add_glibc_version_dependency): Add
GLIBC_ABI_GNU_TLS support.
* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set
has_tls_get_addr_call to 1 if ___tls_get_addr is used.
* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_get_addr_call.

ld/

PR ld/33287
* Mention --gnu-tls-tag, --no-gnu-tls-tag and --enable-gnu-tls-tag.
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-gnu-tls-tag.
* ld.texi: Document --gnu-tls-tag and --enable-gnu-tls-tag.
* ldlex.h (option_values): Add OPTION_GNU_TLS_VERSION_TAG and
OPTION_NO_GNU_TLS_VERSION_TAG.
* emultempl/elf-i386-glibc.em (elf_i386_glibc_before_parse):
Initialize params.gnu_tls_version_tag.
(PARSE_AND_LIST_LONGOPTS_386): New.
(PARSE_AND_LIST_OPTIONS_386): Likewise.
(PARSE_AND_LIST_ARGS_CASES_386): Likewise.
(PARSE_AND_LIST_LONGOPTS): Append $PARSE_AND_LIST_LONGOPTS_386.
(PARSE_AND_LIST_OPTIONS): Append $PARSE_AND_LIST_OPTIONS_386.
(PARSE_AND_LIST_ARGS_CASES): Append
$PARSE_AND_LIST_ARGS_CASES_386.
* testsuite/ld-i386/gnu-tls-1.s: Likewise.
* testsuite/ld-i386/gnu-tls-1a.rd: Likewise.
* testsuite/ld-i386/gnu-tls-1b.rd: Likewise.
* testsuite/ld-i386/i386.exp: Run PR ld/33287 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
15 files changed:
bfd/elf-linker-x86.h
bfd/elf32-i386.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h
ld/NEWS
ld/config.in
ld/configure
ld/configure.ac
ld/emultempl/elf-i386-glibc.em
ld/ld.texi
ld/ldlex.h
ld/testsuite/ld-i386/gnu-tls-1.s [new file with mode: 0644]
ld/testsuite/ld-i386/gnu-tls-1a.rd [new file with mode: 0644]
ld/testsuite/ld-i386/gnu-tls-1b.rd [new file with mode: 0644]
ld/testsuite/ld-i386/i386.exp