public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86: Don't define _TLS_MODULE_BASE_ for ld -r
@ 2022-11-22 22:02 H.J. Lu
  2022-11-22 22:35 ` Fangrui Song
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2022-11-22 22:02 UTC (permalink / raw)
  To: binutils

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                   |  2 +-
 ld/testsuite/ld-x86-64/pr29820.d  |  6 ++++++
 ld/testsuite/ld-x86-64/pr29820.s  | 12 ++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp |  1 +
 4 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-x86-64/pr29820.d
 create mode 100644 ld/testsuite/ld-x86-64/pr29820.s

diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index c48d0385485..bbf868826e5 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -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
index 00000000000..8dc5d6151c3
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr29820.d
@@ -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
index 00000000000..7a4815ff7c5
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr29820.s
@@ -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
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 1782e8e5def..136371bd5a2 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -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"
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86: Don't define _TLS_MODULE_BASE_ for ld -r
  2022-11-22 22:02 [PATCH] x86: Don't define _TLS_MODULE_BASE_ for ld -r H.J. Lu
@ 2022-11-22 22:35 ` Fangrui Song
  0 siblings, 0 replies; 2+ messages in thread
From: Fangrui Song @ 2022-11-22 22:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On 2022-11-22, H.J. Lu via Binutils wrote:
>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                   |  2 +-
> ld/testsuite/ld-x86-64/pr29820.d  |  6 ++++++
> ld/testsuite/ld-x86-64/pr29820.s  | 12 ++++++++++++
> ld/testsuite/ld-x86-64/x86-64.exp |  1 +
> 4 files changed, 20 insertions(+), 1 deletion(-)
> create mode 100644 ld/testsuite/ld-x86-64/pr29820.d
> create mode 100644 ld/testsuite/ld-x86-64/pr29820.s
>
>diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
>index c48d0385485..bbf868826e5 100644
>--- a/bfd/elfxx-x86.c
>+++ b/bfd/elfxx-x86.c
>@@ -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
>index 00000000000..8dc5d6151c3
>--- /dev/null
>+++ b/ld/testsuite/ld-x86-64/pr29820.d
>@@ -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
>index 00000000000..7a4815ff7c5
>--- /dev/null
>+++ b/ld/testsuite/ld-x86-64/pr29820.s
>@@ -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
>diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
>index 1782e8e5def..136371bd5a2 100644
>--- a/ld/testsuite/ld-x86-64/x86-64.exp
>+++ b/ld/testsuite/ld-x86-64/x86-64.exp
>@@ -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"
>-- 
>2.38.1
>

Thanks for the rapid fix!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-22 22:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 22:02 [PATCH] x86: Don't define _TLS_MODULE_BASE_ for ld -r H.J. Lu
2022-11-22 22:35 ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).