bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25694] R_RISCV_TPREL_HI20 relocations cause riscv64 to add TEXTR


From: nelsonc1225 at sourceware dot org
Subject: [Bug ld/25694] R_RISCV_TPREL_HI20 relocations cause riscv64 to add TEXTREL bit on executables
Date: Wed, 03 May 2023 10:57:24 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25694

Nelson Chu <nelsonc1225 at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nelsonc1225 at sourceware dot 
org

--- Comment #4 from Nelson Chu <nelsonc1225 at sourceware dot org> ---
Haven't test these changes for the riscv-gnu-toolchain regressions, and not yet
test for other project.  However, at least TLS LE testcase mentioned here, and
the pr22263-1 testcase looks good after applying the following changes.

For the R_RISCV_TPREL_HI20 in check_reloc, not really sure why we used to goto
static_reloc when pie/pde.  Refer to spare and loongarch, it's just pass and
won't reserve local dynamic reloc for TLS LE in pie/pde, and similar for other
targets.  So we probably too conservative before.

As for the TLS GD/IE in riscv_elf_relocate_section, I refer to what Maciej did
for pr22570, commits 9143e72c6d4d and 1cb83cac9a89, seems also the right way to
do the same thing for risc-v.


diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 77a732b6a08..bbb5d0cd5ff 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -824,7 +824,7 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info
*info,
          break;

        case R_RISCV_TLS_GOT_HI20:
-         if (bfd_link_pic (info))
+         if (bfd_link_dll (info))
            info->flags |= DF_STATIC_TLS;
          if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
              || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_IE))
@@ -920,11 +920,12 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info
*info,
          goto static_reloc;

        case R_RISCV_TPREL_HI20:
+         /* This is not allowed in the pic, but okay in pie.  */
          if (!bfd_link_executable (info))
            return bad_static_reloc (abfd, r_type, h);
          if (h != NULL)
            riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_LE);
-         goto static_reloc;
+         break;

        case R_RISCV_HI20:
          if (bfd_link_pic (info))
@@ -2797,24 +2798,20 @@ riscv_elf_relocate_section (bfd *output_bfd,
              if (htab->elf.srelgot == NULL)
                abort ();

-             if (h != NULL)
-               {
-                 bool dyn, pic;
-                 dyn = htab->elf.dynamic_sections_created;
-                 pic = bfd_link_pic (info);
-
-                 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
-                     && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
-                   indx = h->dynindx;
-               }
+             bool dyn = elf_hash_table (info)->dynamic_sections_created;
+             if (h != NULL
+                 && h->dynindx != -1
+                 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info),
h)
+                 && (bfd_link_dll (info) || !SYMBOL_REFERENCES_LOCAL (info,
h)))
+               indx = h->dynindx;

              /* The GOT entries have not been initialized yet.  Do it
                 now, and emit any relocations.  */
-             if ((bfd_link_pic (info) || indx != 0)
+             if ((bfd_link_dll (info) || indx != 0)
                  && (h == NULL
                      || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
                      || h->root.type != bfd_link_hash_undefweak))
-                   need_relocs = true;
+               need_relocs = true;

              if (tls_type & GOT_TLS_GD)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]