diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-08-17 15:22:22 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-08-20 13:53:32 -0700 |
commit | fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07 (patch) | |
tree | 598c9896e3396c675c8bef02487ba53ec2cfbeeb /ld/testsuite | |
parent | 66e4999f343f85116cf2dda137cc0f31ac793ce6 (diff) | |
download | binutils-fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07.zip binutils-fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07.tar.gz binutils-fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07.tar.bz2 |
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>
Diffstat (limited to 'ld/testsuite')
-rw-r--r-- | ld/testsuite/ld-i386/gnu-tls-1.s | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/gnu-tls-1a.rd | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/gnu-tls-1b.rd | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/i386.exp | 18 |
4 files changed, 37 insertions, 1 deletions
diff --git a/ld/testsuite/ld-i386/gnu-tls-1.s b/ld/testsuite/ld-i386/gnu-tls-1.s new file mode 100644 index 0000000..02ae207 --- /dev/null +++ b/ld/testsuite/ld-i386/gnu-tls-1.s @@ -0,0 +1,9 @@ + .text + .p2align 4 + .globl func + .type func, @function +func: + leal foo@tlsgd(,%ebx,1), %eax + call ___tls_get_addr@PLT + ret + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-i386/gnu-tls-1a.rd b/ld/testsuite/ld-i386/gnu-tls-1a.rd new file mode 100644 index 0000000..65d889d --- /dev/null +++ b/ld/testsuite/ld-i386/gnu-tls-1a.rd @@ -0,0 +1,7 @@ +#... +Version needs section '.gnu.version_r' contains [0-9]+ entries: + Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\) + +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+ +#... + 0x[a-f0-9]+: Name: GLIBC_ABI_GNU_TLS Flags: none Version: [0-9]+ +#pass diff --git a/ld/testsuite/ld-i386/gnu-tls-1b.rd b/ld/testsuite/ld-i386/gnu-tls-1b.rd new file mode 100644 index 0000000..02006e4 --- /dev/null +++ b/ld/testsuite/ld-i386/gnu-tls-1b.rd @@ -0,0 +1,4 @@ +#failif +#... + 0x[a-f0-9]+: Name: GLIBC_ABI_GNU_TLS Flags: none Version: [0-9]+ +#... diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 622c06e..5b189ec 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -1519,11 +1519,27 @@ run_ld_link_tests [list \ ] \ ] -# The musl C library does not support --gnu2-tls-tag. +# The musl C library does not support --gnu-tls-tag nor --gnu2-tls-tag. if { ![istarget *-*-musl] && [check_compiler_available] } { run_cc_link_tests [list \ [list \ + "Build gnu-tls-1a.so" \ + "-shared -Wl,--no-as-needed,--gnu-tls-tag" \ + "-fPIC" \ + { gnu-tls-1.s } \ + {{readelf {-W --version-info} gnu-tls-1a.rd}} \ + "gnu-tls-1a.so" \ + ] \ + [list \ + "Build gnu-tls-1b.so" \ + "-shared -Wl,--no-as-needed,--no-gnu-tls-tag" \ + "-fPIC" \ + { gnu-tls-1.s } \ + {{readelf {-W --version-info} gnu-tls-1b.rd}} \ + "gnu-tls-1b.so" \ + ] \ + [list \ "Build gnu2-tls-1a.so" \ "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \ "-fPIC" \ |