diff options
author | Max Filippov <jcmvbkbc@gmail.com> | 2022-08-23 05:25:55 -0700 |
---|---|---|
committer | Max Filippov <jcmvbkbc@gmail.com> | 2022-09-02 09:54:49 -0700 |
commit | 658ba81aef5e85a08d67eb211a43c6db775a36b3 (patch) | |
tree | e30b2f29188986cd78114d6ac2bc0cbf36487498 /bfd/elf32-xtensa.c | |
parent | 1a51864b467c2d65bd37c3bc9cbab2cf1ee6a039 (diff) | |
download | gdb-658ba81aef5e85a08d67eb211a43c6db775a36b3.zip gdb-658ba81aef5e85a08d67eb211a43c6db775a36b3.tar.gz gdb-658ba81aef5e85a08d67eb211a43c6db775a36b3.tar.bz2 |
xtensa: bfd: fix TLS relocations generated for PIE
When generating TLS dynamic relocations the existing xtensa BFD code
treats linking to a PIE exactly as linking to a shared object, resulting
in generation of wrong relocations for TLS entries. Fix that and add
tests.
bfd/
* elf32-xtensa.c (elf_xtensa_check_relocs): Use bfd_link_dll
instead of bfd_link_pic. Add elf_xtensa_dynamic_symbol_p test
when generating GOT entries.
(elf_xtensa_relocate_section): Use bfd_link_dll instead of
bfd_link_pic.
ld/
* testsuite/ld-xtensa/tlspie.dd: New file.
* testsuite/ld-xtensa/tlspie.rd: New file.
* testsuite/ld-xtensa/tlspie.sd: New file.
* testsuite/ld-xtensa/tlspie.td: New file.
* testsuite/ld-xtensa/xtensa-linux.exp (TLS PIE transitions):
New test.
Diffstat (limited to 'bfd/elf32-xtensa.c')
-rw-r--r-- | bfd/elf32-xtensa.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index bf72c85..31e2d74 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -1116,7 +1116,7 @@ elf_xtensa_check_relocs (bfd *abfd, switch (r_type) { case R_XTENSA_TLSDESC_FN: - if (bfd_link_pic (info)) + if (bfd_link_dll (info)) { tls_type = GOT_TLS_GD; is_got = true; @@ -1127,7 +1127,7 @@ elf_xtensa_check_relocs (bfd *abfd, break; case R_XTENSA_TLSDESC_ARG: - if (bfd_link_pic (info)) + if (bfd_link_dll (info)) { tls_type = GOT_TLS_GD; is_got = true; @@ -1135,13 +1135,14 @@ elf_xtensa_check_relocs (bfd *abfd, else { tls_type = GOT_TLS_IE; - if (h && elf_xtensa_hash_entry (h) != htab->tlsbase) + if (h && elf_xtensa_hash_entry (h) != htab->tlsbase + && elf_xtensa_dynamic_symbol_p (h, info)) is_got = true; } break; case R_XTENSA_TLS_DTPOFF: - if (bfd_link_pic (info)) + if (bfd_link_dll (info)) tls_type = GOT_TLS_GD; else tls_type = GOT_TLS_IE; @@ -1151,7 +1152,7 @@ elf_xtensa_check_relocs (bfd *abfd, tls_type = GOT_TLS_IE; if (bfd_link_pic (info)) info->flags |= DF_STATIC_TLS; - if (bfd_link_pic (info) || h) + if (bfd_link_dll (info) || elf_xtensa_dynamic_symbol_p (h, info)) is_got = true; break; @@ -2884,7 +2885,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, case R_XTENSA_TLS_TPOFF: /* Switch to LE model for local symbols in an executable. */ - if (! bfd_link_pic (info) && ! dynamic_symbol) + if (! bfd_link_dll (info) && ! dynamic_symbol) { relocation = tpoff (info, relocation); break; @@ -2896,12 +2897,12 @@ elf_xtensa_relocate_section (bfd *output_bfd, { if (r_type == R_XTENSA_TLSDESC_FN) { - if (! bfd_link_pic (info) || (tls_type & GOT_TLS_IE) != 0) + if (! bfd_link_dll (info) || (tls_type & GOT_TLS_IE) != 0) r_type = R_XTENSA_NONE; } else if (r_type == R_XTENSA_TLSDESC_ARG) { - if (bfd_link_pic (info)) + if (bfd_link_dll (info)) { if ((tls_type & GOT_TLS_IE) != 0) r_type = R_XTENSA_TLS_TPOFF; @@ -2975,7 +2976,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, break; case R_XTENSA_TLS_DTPOFF: - if (! bfd_link_pic (info)) + if (! bfd_link_dll (info)) /* Switch from LD model to LE model. */ relocation = tpoff (info, relocation); else |