]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Report expected register for elf_x86_tls_error_indirect_call
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 28 Aug 2024 12:03:04 +0000 (05:03 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 28 Aug 2024 12:56:25 +0000 (05:56 -0700)
Since R_386_TLS_DESC_CALL can only be used with

call *variable@TLSCALL(%eax)

and R_X86_64_TLSDESC_CALL can only be used with

call *variable@TLSCALL(%rax)

update TLS transition error report to display the expected register in
indirect CALL.

bfd/

PR ld/32017
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
the ax_register field.
(_bfd_x86_elf_link_report_tls_transition_error): Report the
expected register in elf_x86_tls_error_indirect_call error.
* elfxx-x86.h (elf_x86_link_hash_table): Add ax_register.

ld/

PR ld/32017
* testsuite/ld-i386/tlsgdesc2.d: Updated.
* testsuite/ld-i386/tlsgdesc2.s: Change jmp to call via ECX.
* testsuite/ld-x86-64/tlsdesc4.d: Updated.
* testsuite/ld-x86-64/tlsdesc4.s: Change jmp to call via RCX.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elfxx-x86.c
bfd/elfxx-x86.h
ld/testsuite/ld-i386/tlsgdesc2.d
ld/testsuite/ld-i386/tlsgdesc2.s
ld/testsuite/ld-x86-64/tlsdesc4.d
ld/testsuite/ld-x86-64/tlsdesc4.s

index 85737fc18b77666276db4def1635922b37724243..dd951b91f50281cd4db32a5bd554f42bfea055ef 100644 (file)
@@ -745,6 +745,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
       ret->tls_get_addr = "__tls_get_addr";
       ret->relative_r_type = R_X86_64_RELATIVE;
       ret->relative_r_name = "R_X86_64_RELATIVE";
+      ret->ax_register = "RAX";
       ret->elf_append_reloc = elf_append_rela;
       ret->elf_write_addend_in_got = _bfd_elf64_write_addend;
     }
@@ -776,6 +777,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
          ret->pointer_r_type = R_386_32;
          ret->relative_r_type = R_386_RELATIVE;
          ret->relative_r_name = "R_386_RELATIVE";
+         ret->ax_register = "EAX";
          ret->elf_append_reloc = elf_append_rel;
          ret->elf_write_addend = _bfd_elf32_write_addend;
          ret->elf_write_addend_in_got = _bfd_elf32_write_addend;
@@ -3211,15 +3213,14 @@ _bfd_x86_elf_link_report_tls_transition_error
    enum elf_x86_tls_error_type tls_error)
 {
   const char *name;
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  struct elf_x86_link_hash_table *htab
+    = elf_x86_hash_table (info, bed->target_id);
 
   if (h)
     name = h->root.root.string;
   else
     {
-      const struct elf_backend_data *bed
-       = get_elf_backend_data (abfd);
-      struct elf_x86_link_hash_table *htab
-       = elf_x86_hash_table (info, bed->target_id);
       if (htab == NULL)
        name = "*unknown*";
       else
@@ -3265,8 +3266,9 @@ _bfd_x86_elf_link_report_tls_transition_error
       info->callbacks->einfo
        /* xgettext:c-format */
        (_("%pB(%pA+0x%v): relocation %s against `%s' must be used "
-          "in indirect CALL only\n"),
-        abfd, asect, rel->r_offset, from_reloc_name, name);
+          "in indirect CALL with %s register only\n"),
+        abfd, asect, rel->r_offset, from_reloc_name, name,
+        htab->ax_register);
       break;
 
     case elf_x86_tls_error_lea:
index 5eef7b09152b07302b725f1a770846574ccd9689..b042d45c28280312fd0ef96f20ab67663a12a800 100644 (file)
@@ -687,6 +687,7 @@ struct elf_x86_link_hash_table
   const char *dynamic_interpreter;
   const char *tls_get_addr;
   const char *relative_r_name;
+  const char *ax_register;
   void (*elf_append_reloc) (bfd *, asection *, Elf_Internal_Rela *);
   void (*elf_write_addend) (bfd *, uint64_t, void *);
   void (*elf_write_addend_in_got) (bfd *, uint64_t, void *);
index 2e6a66d372c8669dff7ead4ed41e670c4b31f514..bbf93bef7674ec2f5a8768ad79d50b576938b9b9 100644 (file)
@@ -1,4 +1,4 @@
 #name: TLS GDesc->LE transition check (indirect CALL)
 #as: --32
 #ld: -melf_i386
-#error: .*: relocation R_386_TLS_DESC_CALL against `foo' must be used in indirect CALL only
+#error: .*: relocation R_386_TLS_DESC_CALL against `foo' must be used in indirect CALL with EAX register only
index 7d9d556e2ab14e52214b187cf76391c5b1685896..5d3d0b8068d857728f596e50c3da475dfb4d070a 100644 (file)
@@ -1,8 +1,8 @@
        .text
        .globl _start
 _start:
-       leal    foo@tlsdesc(%ebx), %eax
-       jmp     *foo@tlscall(%eax)
+       leal    foo@tlsdesc(%ebx), %ecx
+       call    *foo@tlscall(%ecx)
        .section        .tdata,"awT",@progbits
        .align 4
        .type   foo, @object
index b50115c7178a1e4bb3b4bd24297a3935a6c0f6f7..c882c877ae392621596bac378deb0551eb516df4 100644 (file)
@@ -1,4 +1,4 @@
 #name: TLS GDesc->LE transition check (indirect CALL)
 #as: --64
 #ld: -melf_x86_64
-#error: .*: relocation R_X86_64_TLSDESC_CALL against `foo' must be used in indirect CALL only
+#error: .*: relocation R_X86_64_TLSDESC_CALL against `foo' must be used in indirect CALL with RAX register only
index b3d6c12d4fc1fb79900d624c4af64a45e352371a..1f3febc281574ece8c59dfaacb92429c28e46cb5 100644 (file)
@@ -2,8 +2,8 @@
        .globl  _start
        .type   _start,@function
 _start:
-       leaq    foo@tlsdesc(%rip), %rax
-       jmp     *foo@tlscall(%rax)
+       leaq    foo@tlsdesc(%rip), %rcx
+       call    *foo@tlscall(%rcx)
        .globl foo
        .section        .tdata,"awT",@progbits
        .align 8