This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR ld/5913: IA64 linker crashes on supported relocations


On Wed, Mar 12, 2008 at 10:16:37PM -0700, Jim Wilson wrote:
> H.J. Lu wrote:
>> IA64 Linker crashes on bad input in
>
> It looks like every port with TLS support has this problem, except maybe 
> the FRV port.  A bit more than half of them have
>>                 }
> So it looks like the FRV port is the only one that currently handles this 
> correctly.
>
> Should we be trying to fix every target here, instead of just the IA-64 
> port?

I tried to fix the linker crash when I saw one

>
> I tried to create my own testcase for x86 to see what happens there, but 
> neither the assembler nor objcopy will let me create a broken .o file, 
http://sourceware.org/ml/binutils/2007-08/msg00359.html

> which make me wonder how you created your testcase.  If this situation is 
> very hard to get, maybe we don't need to worry about fixing other targets.

I fixed the x86 linker crash:

http://sourceware.org/ml/binutils/2007-08/msg00359.html

I don't know if other targets need similar fix.

>
> As for the patch, it seems reasonable.  We could maybe eliminate the code 
> duplication by making elfNN_ia64_tprel_base and elfNN_ia64_dtprel_base into 

We may remove a few lines. But the current code is easier to
understand than goto in macros.

> macros.  Maybe the error message should say something about the missing tls 
> section like the FRV port does?  The error message says that the relocation 
> is unsupported, but doesn't give any clue as to why.
>

I added "missing TLS section" in this updated patch. OK to install?

Thanks.


H.J.
----
2008-03-11  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/5913
	* elfxx-ia64.c (elfNN_ia64_tprel_base): Remove BFD_ASSERT.
	(elfNN_ia64_dtprel_base): Likewise.
	(elfNN_ia64_relocate_section): Go to missing_tls_sec if
	tls_sec is NULL before calling elfNN_ia64_tprel_base or
	elfNN_ia64_dtprel_base.  Report unsupported TLS relocations.

--- bfd/elfxx-ia64.c.check	2008-03-12 12:32:54.000000000 -0700
+++ bfd/elfxx-ia64.c	2008-03-13 06:21:38.000000000 -0700
@@ -4189,8 +4189,6 @@ static bfd_vma
 elfNN_ia64_tprel_base (struct bfd_link_info *info)
 {
   asection *tls_sec = elf_hash_table (info)->tls_sec;
-
-  BFD_ASSERT (tls_sec != NULL);
   return tls_sec->vma - align_power ((bfd_vma) ARCH_SIZE / 4,
 				     tls_sec->alignment_power);
 }
@@ -4202,7 +4200,6 @@ elfNN_ia64_tprel_base (struct bfd_link_i
 static bfd_vma
 elfNN_ia64_dtprel_base (struct bfd_link_info *info)
 {
-  BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
   return elf_hash_table (info)->tls_sec->vma;
 }
 
@@ -4972,6 +4969,8 @@ elfNN_ia64_relocate_section (bfd *output
 	case R_IA64_TPREL14:
 	case R_IA64_TPREL22:
 	case R_IA64_TPREL64I:
+	  if (elf_hash_table (info)->tls_sec == NULL)
+	    goto missing_tls_sec;
 	  value -= elfNN_ia64_tprel_base (info);
 	  r = elfNN_ia64_install_value (hit_addr, value, r_type);
 	  break;
@@ -4983,6 +4982,8 @@ elfNN_ia64_relocate_section (bfd *output
 	case R_IA64_DTPREL32MSB:
 	case R_IA64_DTPREL64LSB:
 	case R_IA64_DTPREL64MSB:
+	  if (elf_hash_table (info)->tls_sec == NULL)
+	    goto missing_tls_sec;
 	  value -= elfNN_ia64_dtprel_base (info);
 	  r = elfNN_ia64_install_value (hit_addr, value, r_type);
 	  break;
@@ -5001,6 +5002,8 @@ elfNN_ia64_relocate_section (bfd *output
 	      case R_IA64_LTOFF_TPREL22:
 		if (!dynamic_symbol_p)
 		  {
+		    if (elf_hash_table (info)->tls_sec == NULL)
+		      goto missing_tls_sec;
 		    if (!info->shared)
 		      value -= elfNN_ia64_tprel_base (info);
 		    else
@@ -5018,7 +5021,11 @@ elfNN_ia64_relocate_section (bfd *output
 		break;
 	      case R_IA64_LTOFF_DTPREL22:
 		if (!dynamic_symbol_p)
-		  value -= elfNN_ia64_dtprel_base (info);
+		  {
+		    if (elf_hash_table (info)->tls_sec == NULL)
+		      goto missing_tls_sec;
+		    value -= elfNN_ia64_dtprel_base (info);
+		  }
 		got_r_type = R_IA64_DTPRELNNLSB;
 		break;
 	      }
@@ -5069,6 +5076,7 @@ elfNN_ia64_relocate_section (bfd *output
 	case bfd_reloc_outofrange:
 	case bfd_reloc_overflow:
 	default:
+missing_tls_sec:
 	  {
 	    const char *name;
 
@@ -5080,6 +5088,25 @@ elfNN_ia64_relocate_section (bfd *output
 
 	    switch (r_type)
 	      {
+	      case R_IA64_TPREL14:
+	      case R_IA64_TPREL22:
+	      case R_IA64_TPREL64I:
+	      case R_IA64_DTPREL14:
+	      case R_IA64_DTPREL22:
+	      case R_IA64_DTPREL64I:
+	      case R_IA64_DTPREL32LSB:
+	      case R_IA64_DTPREL32MSB:
+	      case R_IA64_DTPREL64LSB:
+	      case R_IA64_DTPREL64MSB:
+	      case R_IA64_LTOFF_TPREL22:
+	      case R_IA64_LTOFF_DTPMOD22:
+	      case R_IA64_LTOFF_DTPREL22:
+		(*_bfd_error_handler)
+		  (_("%B: missing TLS section for relocation %s against `%s' at 0x%lx in section `%A'."),
+		   input_bfd, input_section, howto->name, name,
+		   rel->r_offset);
+		break;
+
 	      case R_IA64_PCREL21B:
 	      case R_IA64_PCREL21BI:
 	      case R_IA64_PCREL21M:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]