]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86-64: Fix misleading R_X86_64_TPOFF32 error message
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 9 Sep 2025 20:32:27 +0000 (13:32 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 10 Sep 2025 13:13:43 +0000 (06:13 -0700)
R_X86_64_TPOFF32 relocation of local-exec TLS model can only be used in
executable, not in a shared library, even if the source code is compiled
with -fPIC.  Change the linker error message from

relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; recompile with -fPIC

to

relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model

bfd/

PR ld/33408
* elf64-x86-64.c (elf_x86_64_need_pic): Suggest "replace
local-exec with initial-exec TLS model" for R_X86_64_TPOFF32.
(elf_x86_64_scan_relocs): Drop ABI_64_P check for
R_X86_64_TPOFF32.

ld/

PR ld/33408
* testsuite/ld-x86-64/tls-le-pic-1-x32.d: New file.
* testsuite/ld-x86-64/tls-le-pic-1.d: Likewise.
* testsuite/ld-x86-64/tls-le-pic-1.s: Likewise.
* testsuite/ld-x86-64/tls-le-pic-2-x32.d: Likewise.
* testsuite/ld-x86-64/tls-le-pic-2.d: Likewise.
* testsuite/ld-x86-64/tls-le-pic-2.s: Likewise.
* testsuite/ld-x86-64/tls-le-pic-3-x32.d: Likewise.
* testsuite/ld-x86-64/tls-le-pic-3.d: Likewise.
* testsuite/ld-x86-64/tls-le-pic-3.s: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elf64-x86-64.c
ld/testsuite/ld-x86-64/tls-le-pic-1-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-1.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-2-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-2.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-2.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-3-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-3.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/tls-le-pic-3.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 00586455203715a138fa06cc3a57dc24586dc64a..ad99cf6754e4ca29f4037ea6d1198dc933312b55 100644 (file)
@@ -1717,7 +1717,9 @@ elf_x86_64_need_pic (struct bfd_link_info *info,
     {
       object = _("a shared object");
       if (!pic)
-       pic = _("; recompile with -fPIC");
+       pic = (howto->type == R_X86_64_TPOFF32
+              ? _("; replace local-exec with initial-exec TLS model")
+              : _("; recompile with -fPIC"));
     }
   else
     {
@@ -2684,7 +2686,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
          goto create_got;
 
        case R_X86_64_TPOFF32:
-         if (!bfd_link_executable (info) && ABI_64_P (abfd))
+         if (!bfd_link_executable (info))
            {
              elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
                                   &x86_64_elf_howto_table[r_type]);
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-1-x32.d b/ld/testsuite/ld-x86-64/tls-le-pic-1-x32.d
new file mode 100644 (file)
index 0000000..b0824c4
--- /dev/null
@@ -0,0 +1,4 @@
+#source: tls-le-pic-1.s
+#as: --x32
+#ld: -shared -melf32_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-1.d b/ld/testsuite/ld-x86-64/tls-le-pic-1.d
new file mode 100644 (file)
index 0000000..6db5f02
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-1.s b/ld/testsuite/ld-x86-64/tls-le-pic-1.s
new file mode 100644 (file)
index 0000000..ffc8e63
--- /dev/null
@@ -0,0 +1,17 @@
+       .text
+       .p2align 4
+       .globl  func
+       .type   func, @function
+func:
+       movq    %fs:0, %rax
+       addq    $foo@tpoff, %rax
+       ret
+       .size   func, .-func
+       .section        .tbss,"awT",@nobits
+       .align 4
+       .globl  foo
+       .type   foo, @object
+       .size   foo, 4
+foo:
+       .zero   4
+       .section        .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-2-x32.d b/ld/testsuite/ld-x86-64/tls-le-pic-2-x32.d
new file mode 100644 (file)
index 0000000..e16395a
--- /dev/null
@@ -0,0 +1,4 @@
+#source: tls-le-pic-2.s
+#as: --x32
+#ld: -shared -melf32_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against undefined symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-2.d b/ld/testsuite/ld-x86-64/tls-le-pic-2.d
new file mode 100644 (file)
index 0000000..0e718e0
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against undefined symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-2.s b/ld/testsuite/ld-x86-64/tls-le-pic-2.s
new file mode 100644 (file)
index 0000000..ad930db
--- /dev/null
@@ -0,0 +1,10 @@
+       .text
+       .p2align 4
+       .globl  func
+       .type   func, @function
+func:
+       movq    %fs:0, %rax
+       addq    $foo@tpoff, %rax
+       ret
+       .size   func, .-func
+       .section        .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-3-x32.d b/ld/testsuite/ld-x86-64/tls-le-pic-3-x32.d
new file mode 100644 (file)
index 0000000..f6731da
--- /dev/null
@@ -0,0 +1,4 @@
+#source: tls-le-pic-3.s
+#as: --x32
+#ld: -shared -melf32_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-3.d b/ld/testsuite/ld-x86-64/tls-le-pic-3.d
new file mode 100644 (file)
index 0000000..987e370
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#error: .*: relocation R_X86_64_TPOFF32 against `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
diff --git a/ld/testsuite/ld-x86-64/tls-le-pic-3.s b/ld/testsuite/ld-x86-64/tls-le-pic-3.s
new file mode 100644 (file)
index 0000000..6e213fd
--- /dev/null
@@ -0,0 +1,16 @@
+       .text
+       .p2align 4
+       .globl  func
+       .type   func, @function
+func:
+       movq    %fs:0, %rax
+       addq    $foo@tpoff, %rax
+       ret
+       .size   func, .-func
+       .section        .tbss,"awT",@nobits
+       .align 4
+       .type   foo, @object
+       .size   foo, 4
+foo:
+       .zero   4
+       .section        .note.GNU-stack,"",@progbits
index 23e0a98d1cd5da0ad455d700e9da537b0d0fd602..f04ae923ebc983457cff618574954060d2066182 100644 (file)
@@ -578,6 +578,12 @@ run_dump_test "pr33292"
 run_dump_test "pr33292-x32"
 run_dump_test "pr28387"
 run_dump_test "pr28387-x32"
+run_dump_test "tls-le-pic-1"
+run_dump_test "tls-le-pic-1-x32"
+run_dump_test "tls-le-pic-2"
+run_dump_test "tls-le-pic-2-x32"
+run_dump_test "tls-le-pic-3"
+run_dump_test "tls-le-pic-3-x32"
 
 if { ![skip_sframe_tests] } {
     run_dump_test "sframe-simple-1"