cat > a.s <<eof leaq _TLS_MODULE_BASE_@tlsdesc(%rip), %rax call *_TLS_MODULE_BASE_@tlscall(%rax) movl %fs:a@dtpoff(%rax), %edx addl %fs:b@dtpoff(%rax), %edx .section .tbss .zero 8 a: .zero 4 b: .zero 4 eof cc -c a.s ld.bfd -r a.o a.o -o a.ro ld.bfd a.ro The -r link should not define _TLS_MODULE_BASE_. % readelf -Ws a.ro 12: 0000000000000000 0 TLS LOCAL DEFAULT 3 _TLS_MODULE_BASE_ Since ld currently does define _TLS_MODULE_BASE_, the final output has two local _TLS_MODULE_BASE_ and the relaxation result is incorrect. % objdump -d a.out ... 0000000000401000 <.text>: 401000: 48 c7 c0 e0 ff ff ff movq $-0x20, %rax ##### should be $0x0 401007: 66 90 nop 401009: 64 8b 90 e8 ff ff ff movl %fs:-0x18(%rax), %edx 401010: 64 03 90 ec ff ff ff addl %fs:-0x14(%rax), %edx 401017: 48 c7 c0 e0 ff ff ff movq $-0x20, %rax ##### should be $0x0 40101e: 66 90 nop 401020: 64 8b 90 f8 ff ff ff movl %fs:-0x8(%rax), %edx 401027: 64 03 90 fc ff ff ff addl %fs:-0x4(%rax), %edx
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=04ad71937f28561ad5a2bbbc7e8f0af21e1019f8 commit 04ad71937f28561ad5a2bbbc7e8f0af21e1019f8 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Nov 22 13:58:47 2022 -0800 x86: Don't define _TLS_MODULE_BASE_ for ld -r bfd/ PR ld/29820 * elfxx-x86.c (_bfd_x86_elf_always_size_sections): Don't define _TLS_MODULE_BASE_ for ld -r. ld/ PR ld/29820 * testsuite/ld-x86-64/pr29820.d: New file. * testsuite/ld-x86-64/pr29820.s: Likewise. * testsuite/ld-x86-64/x86-64.ex: Run pr29820.
Fixed for 2.40