public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671]
@ 2023-01-17 11:25 Rainer Orth
  2023-01-19 21:55 ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Rainer Orth @ 2023-01-17 11:25 UTC (permalink / raw)
  To: binutils; +Cc: hjl.tools

[-- Attachment #1: Type: text/plain, Size: 843 bytes --]

As detailed in PR ld/13671, gld can emit R_386_TLS_TPOFF32 relocs which
the Solaris/x86 ld.so.1 doesn't know about, so the resulting executables
won't run.

The following patch, which H.J. provided in the PR, fixes this.

Tested on i386-pc-solaris2.11 (both with the binutils testsuite and a
full gcc bootstrap) and i686-pc-linux-gnu.

Already approved by H.J. in the PR, but it's probably best if someone
double-checks the ChangeLog entry.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2023-01-17  H.J. Lu  <hongjiu.lu@intel.com>

	bfd:
	PR ld/13671
	* elf32-i386.c (elf_i386_tls_transition): Only emit R_386_TLS_LE,
	R_386_TLS_IE on Solaris.
	(elf_i386_relocate_section): Only use R_386_TLS_GD->R_386_TLS_LE
	transition on Solaris.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: local.patch6 --]
[-- Type: text/x-patch, Size: 3514 bytes --]

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1062,6 +1062,7 @@ elf_i386_tls_transition (struct bfd_link
   unsigned int from_type = *r_type;
   unsigned int to_type = from_type;
   bool check = true;
+  unsigned int to_le_type, to_ie_type;
 
   /* Skip TLS transition for functions.  */
   if (h != NULL
@@ -1069,6 +1070,18 @@ elf_i386_tls_transition (struct bfd_link
 	  || h->type == STT_GNU_IFUNC))
     return true;
 
+  if (get_elf_backend_data (abfd)->target_os == is_solaris)
+    {
+      /* NB: Solaris only supports R_386_TLS_LE and R_386_TLS_IE.  */
+      to_le_type = R_386_TLS_LE;
+      to_ie_type = R_386_TLS_IE;
+    }
+  else
+    {
+      to_le_type = R_386_TLS_LE_32;
+      to_ie_type = R_386_TLS_IE_32;
+    }
+
   switch (from_type)
     {
     case R_386_TLS_GD:
@@ -1080,10 +1093,10 @@ elf_i386_tls_transition (struct bfd_link
       if (bfd_link_executable (info))
 	{
 	  if (h == NULL)
-	    to_type = R_386_TLS_LE_32;
+	    to_type = to_le_type;
 	  else if (from_type != R_386_TLS_IE
 		   && from_type != R_386_TLS_GOTIE)
-	    to_type = R_386_TLS_IE_32;
+	    to_type = to_ie_type;
 	}
 
       /* When we are called from elf_i386_relocate_section, there may
@@ -1093,7 +1106,7 @@ elf_i386_tls_transition (struct bfd_link
 	  unsigned int new_to_type = to_type;
 
 	  if (TLS_TRANSITION_IE_TO_LE_P (info, h, tls_type))
-	    new_to_type = R_386_TLS_LE_32;
+	    new_to_type = to_le_type;
 
 	  if (to_type == R_386_TLS_GD
 	      || to_type == R_386_TLS_GOTDESC
@@ -1102,7 +1115,7 @@ elf_i386_tls_transition (struct bfd_link
 	      if (tls_type == GOT_TLS_IE_POS)
 		new_to_type = R_386_TLS_GOTIE;
 	      else if (tls_type & GOT_TLS_IE)
-		new_to_type = R_386_TLS_IE_32;
+		new_to_type = to_ie_type;
 	    }
 
 	  /* We checked the transition before when we were called from
@@ -1116,7 +1129,7 @@ elf_i386_tls_transition (struct bfd_link
 
     case R_386_TLS_LDM:
       if (bfd_link_executable (info))
-	to_type = R_386_TLS_LE_32;
+	to_type = to_le_type;
       break;
 
     default:
@@ -2024,6 +2037,7 @@ elf_i386_relocate_section (bfd *output_b
   Elf_Internal_Rela *wrel;
   Elf_Internal_Rela *relend;
   bool is_vxworks_tls;
+  unsigned expected_tls_le;
   unsigned plt_entry_size;
 
   /* Skip if check_relocs or scan_relocs failed.  */
@@ -2853,9 +2867,17 @@ elf_i386_relocate_section (bfd *output_b
 					 relend, h, r_symndx, true))
 	    return false;
 
-	  if (r_type_tls == R_386_TLS_LE_32)
+	  expected_tls_le = htab->elf.target_os == is_solaris
+	    ? R_386_TLS_LE : R_386_TLS_LE_32;
+	  if (r_type_tls == expected_tls_le)
 	    {
-	      BFD_ASSERT (! unresolved_reloc);
+	      /* NB: Solaris only supports R_386_TLS_GD->R_386_TLS_LE.  */
+	      BFD_ASSERT (! unresolved_reloc
+			  && (htab->elf.target_os != is_solaris
+			      || (htab->elf.target_os == is_solaris
+				  && (r_type == R_386_TLS_GD
+				      || r_type == R_386_TLS_IE
+				      || r_type == R_386_TLS_GOTIE))));
 	      if (r_type == R_386_TLS_GD)
 		{
 		  unsigned int type;
@@ -3352,7 +3374,9 @@ elf_i386_relocate_section (bfd *output_b
 		 into:
 			movl %gs:0, %eax
 			leal 0(%esi), %esi  */
-	      BFD_ASSERT (r_type == R_386_TLS_LE_32);
+	      expected_tls_le = htab->elf.target_os == is_solaris
+		? R_386_TLS_LE : R_386_TLS_LE_32;
+	      BFD_ASSERT (r_type == expected_tls_le);
 	      if (*(contents + rel->r_offset + 4) == 0xff
 		  || *(contents + rel->r_offset + 4) == 0x67)
 		memcpy (contents + rel->r_offset - 2,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671]
  2023-01-17 11:25 [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671] Rainer Orth
@ 2023-01-19 21:55 ` H.J. Lu
  2023-01-20  8:10   ` Rainer Orth
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2023-01-19 21:55 UTC (permalink / raw)
  To: Rainer Orth; +Cc: binutils

On Tue, Jan 17, 2023 at 3:25 AM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>
> As detailed in PR ld/13671, gld can emit R_386_TLS_TPOFF32 relocs which
> the Solaris/x86 ld.so.1 doesn't know about, so the resulting executables
> won't run.
>
> The following patch, which H.J. provided in the PR, fixes this.
>
> Tested on i386-pc-solaris2.11 (both with the binutils testsuite and a
> full gcc bootstrap) and i686-pc-linux-gnu.
>
> Already approved by H.J. in the PR, but it's probably best if someone
> double-checks the ChangeLog entry.
>
>         Rainer
>
> --
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2023-01-17  H.J. Lu  <hongjiu.lu@intel.com>
>
>         bfd:
>         PR ld/13671
>         * elf32-i386.c (elf_i386_tls_transition): Only emit R_386_TLS_LE,
>         R_386_TLS_IE on Solaris.
>         (elf_i386_relocate_section): Only use R_386_TLS_GD->R_386_TLS_LE
>         transition on Solaris.
>

I checked it in.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671]
  2023-01-19 21:55 ` H.J. Lu
@ 2023-01-20  8:10   ` Rainer Orth
  0 siblings, 0 replies; 3+ messages in thread
From: Rainer Orth @ 2023-01-20  8:10 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

Hi H.J.,

>> 2023-01-17  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>         bfd:
>>         PR ld/13671
>>         * elf32-i386.c (elf_i386_tls_transition): Only emit R_386_TLS_LE,
>>         R_386_TLS_IE on Solaris.
>>         (elf_i386_relocate_section): Only use R_386_TLS_GD->R_386_TLS_LE
>>         transition on Solaris.
>>
>
> I checked it in.

great, thanks a lot.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-20  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 11:25 [PATCH] i386: Don't emit unsupported TLS relocs on Solaris [PR13671] Rainer Orth
2023-01-19 21:55 ` H.J. Lu
2023-01-20  8:10   ` Rainer Orth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).