[PATCH] x86: Report expected register for elf_x86_tls_error_indirect_call
H.J. Lu
hjl.tools@gmail.com
Wed Aug 28 12:03:04 GMT 2024
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>
Fix
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
bfd/elfxx-x86.c | 14 ++++++++------
bfd/elfxx-x86.h | 1 +
ld/testsuite/ld-i386/tlsgdesc2.d | 2 +-
ld/testsuite/ld-i386/tlsgdesc2.s | 4 ++--
ld/testsuite/ld-x86-64/tlsdesc4.d | 2 +-
ld/testsuite/ld-x86-64/tlsdesc4.s | 4 ++--
6 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 85737fc18b7..dd951b91f50 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -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:
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 5eef7b09152..b042d45c282 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -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 *);
diff --git a/ld/testsuite/ld-i386/tlsgdesc2.d b/ld/testsuite/ld-i386/tlsgdesc2.d
index 2e6a66d372c..bbf93bef767 100644
--- a/ld/testsuite/ld-i386/tlsgdesc2.d
+++ b/ld/testsuite/ld-i386/tlsgdesc2.d
@@ -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
diff --git a/ld/testsuite/ld-i386/tlsgdesc2.s b/ld/testsuite/ld-i386/tlsgdesc2.s
index 7d9d556e2ab..5d3d0b8068d 100644
--- a/ld/testsuite/ld-i386/tlsgdesc2.s
+++ b/ld/testsuite/ld-i386/tlsgdesc2.s
@@ -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
diff --git a/ld/testsuite/ld-x86-64/tlsdesc4.d b/ld/testsuite/ld-x86-64/tlsdesc4.d
index b50115c7178..c882c877ae3 100644
--- a/ld/testsuite/ld-x86-64/tlsdesc4.d
+++ b/ld/testsuite/ld-x86-64/tlsdesc4.d
@@ -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
diff --git a/ld/testsuite/ld-x86-64/tlsdesc4.s b/ld/testsuite/ld-x86-64/tlsdesc4.s
index b3d6c12d4fc..1f3febc2815 100644
--- a/ld/testsuite/ld-x86-64/tlsdesc4.s
+++ b/ld/testsuite/ld-x86-64/tlsdesc4.s
@@ -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
--
2.46.0
More information about the Binutils
mailing list