x86: Don't define _TLS_MODULE_BASE_ for ld -r
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 22 Nov 2022 21:58:47 +0000 (13:58 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 22 Nov 2022 22:03:16 +0000 (14:03 -0800)
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.

bfd/elfxx-x86.c
ld/testsuite/ld-x86-64/pr29820.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr29820.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index c48d0385485ceaf731a9a3c17326225c6d86c084..bbf868826e5f273475216163d9e5752a30a84a8a 100644 (file)
@@ -2932,7 +2932,7 @@ _bfd_x86_elf_always_size_sections (bfd *output_bfd,
 {
   asection *tls_sec = elf_hash_table (info)->tls_sec;
 
-  if (tls_sec)
+  if (tls_sec && !bfd_link_relocatable (info))
     {
       struct elf_link_hash_entry *tlsbase;
 
diff --git a/ld/testsuite/ld-x86-64/pr29820.d b/ld/testsuite/ld-x86-64/pr29820.d
new file mode 100644 (file)
index 0000000..8dc5d61
--- /dev/null
@@ -0,0 +1,6 @@
+#ld: -r
+#readelf: -s -W
+
+#...
+ +[0-9]+: +0+ +0 +TLS +GLOBAL +DEFAULT +UND +_TLS_MODULE_BASE_
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr29820.s b/ld/testsuite/ld-x86-64/pr29820.s
new file mode 100644 (file)
index 0000000..7a4815f
--- /dev/null
@@ -0,0 +1,12 @@
+       .text
+       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
index 1782e8e5defa2f0a47f79fdd821b434b6671612b..136371bd5a22f0b4fa81d5dd2bb61f1548b2c548 100644 (file)
@@ -728,6 +728,7 @@ run_dump_test "pr27016a"
 run_dump_test "pr27016b"
 run_dump_test "report-reloc-1"
 run_dump_test "report-reloc-1-x32"
+run_dump_test "pr29820"
 
 proc undefined_weak {cflags ldflags} {
     set testname "Undefined weak symbol"