This is the mail archive of the binutils@sources.redhat.com 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]

[FR-V, installed] fix crash on missing TLS section


A program containing object files that contained TLS relocations
referencing (ABS+addend) could crash at link time if no TLS symbols
were defined in the executable or shared lib being linked.  Since such
relocations only make sense to access module-local TLS symbols, I
figured it was perfectly legitimate to issue an error message if no
TLS symbols were defined (i.e., no TLS section is present).

This required tweaking a little bit the error handling of another
invalid condition that used to be the only error condition in
_frvfdpic_elf_emit_got_relocs_plt_entries().

While at that, I found out I no longer needed the tests in
FRVFDPIC_SYM_LOCAL to get *ABS*+offset relocations to bind locally in
e.g. #tlsmoff relocations, so I took it out.

Here's the patch I'm checking in.  Tested building a working glibc for
frv-linux-gnu on x86_64-linux-gnu.

Index: bfd/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elf32-frv.c (FRVFDPIC_SYM_LOCAL): Remove special handling for
	*ABS*/*UND* sections.
	(elf32_frv_relocate_section): Move zero-addend-required error...
	(_frv_emit_got_relocs_plt_entries): ... here.  Report error for
	missing needed TLS section.

Index: bfd/elf32-frv.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-frv.c,v
retrieving revision 1.34
diff -u -p -r1.34 elf32-frv.c
--- bfd/elf32-frv.c 31 Jan 2005 23:13:19 -0000 1.34
+++ bfd/elf32-frv.c 7 Feb 2005 07:50:33 -0000
@@ -1,5 +1,5 @@
 /* FRV-specific support for 32-bit ELF.
-   Copyright 2002, 2003, 2004  Free Software Foundation, Inc.
+   Copyright 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -1019,15 +1019,7 @@ frvfdpic_elf_link_hash_table_create (bfd
    its function descriptor must be assigned by the dynamic linker.  */
 #define FRVFDPIC_SYM_LOCAL(INFO, H) \
   (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
-   || ! elf_hash_table (INFO)->dynamic_sections_created \
-   /* These two additional alternatives are needed for TLS
-      relocations, that use *ABS*+offset relocations to refer to the
-      TLS section of the local module.  FIXME: At some point during
-      linking, the definition section ceases to be regarded as the
-      absolute section, and starts being regarded as the undefined
-      section.  */ \
-   || bfd_is_abs_section ((H)->root.u.def.section) \
-   || bfd_is_und_section ((H)->root.u.def.section))
+   || ! elf_hash_table (INFO)->dynamic_sections_created)
 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
   ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
 
@@ -1525,7 +1517,14 @@ _frvfdpic_emit_got_relocs_plt_entries (s
 	      idx = dynindx;
 	      ad = addend;
 	      if (ad)
-		return FALSE;
+		{
+		  (*info->callbacks->reloc_dangerous)
+		    (info, _("relocation requires zero addend"),
+		     elf_hash_table (info)->dynobj,
+		     frvfdpic_got_section (info),
+		     entry->fdgot_entry);
+		  return FALSE;
+		}
 	    }
 	  else
 	    {
@@ -1667,7 +1666,14 @@ _frvfdpic_emit_got_relocs_plt_entries (s
       else if (entry->lazyplt)
 	{
 	  if (ad)
-	    return FALSE;
+	    {
+	      (*info->callbacks->reloc_dangerous)
+		(info, _("relocation requires zero addend"),
+		 elf_hash_table (info)->dynobj,
+		 frvfdpic_got_section (info),
+		 entry->fd_entry);
+	      return FALSE;
+	    }
 
 	  fd_lazy_rel_offset = ofst;
 
@@ -1844,6 +1850,13 @@ _frvfdpic_emit_got_relocs_plt_entries (s
 	      && (bfd_is_abs_section (sec)
 		  || bfd_is_und_section (sec)))
 	    {
+	      if (! elf_hash_table (info)->tls_sec)
+		{
+		  (*info->callbacks->undefined_symbol)
+		    (info, "TLS section", elf_hash_table (info)->dynobj,
+		     frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
+		  return FALSE;
+		}
 	      idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
 	      ad += FRVFDPIC_TLS_BIAS;
 	    }
@@ -1951,6 +1964,13 @@ _frvfdpic_emit_got_relocs_plt_entries (s
 	      && (bfd_is_abs_section (sec)
 		  || bfd_is_und_section (sec)))
 	    {
+	      if (! elf_hash_table (info)->tls_sec)
+		{
+		  (*info->callbacks->undefined_symbol)
+		    (info, "TLS section", elf_hash_table (info)->dynobj,
+		     frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
+		  return FALSE;
+		}
 	      idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
 	      ad += FRVFDPIC_TLS_BIAS;
 	    }
@@ -2878,10 +2898,9 @@ elf32_frv_relocate_section (output_bfd, 
 						      rel->r_addend))
 	    {
 	      (*_bfd_error_handler)
-		(_("%B: relocation at `%A+0x%x' references symbol `%s' with nonzero addend"),
-		 input_bfd, input_section, rel->r_offset, name);
+		(_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
+		 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
 	      return FALSE;
-
 	    }
 
 	  break;
Index: ld/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* ld-frv/fdpic-shared-8-fail.d: Tweak error messages.

Index: ld/testsuite/ld-frv/fdpic-shared-8-fail.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-frv/fdpic-shared-8-fail.d,v
retrieving revision 1.1
diff -u -p -r1.1 fdpic-shared-8-fail.d
--- ld/testsuite/ld-frv/fdpic-shared-8-fail.d 6 Jan 2004 19:19:31 -0000 1.1
+++ ld/testsuite/ld-frv/fdpic-shared-8-fail.d 7 Feb 2005 07:50:34 -0000
@@ -3,4 +3,4 @@
 #objdump: -DR -j .text -j .data -j .got -j .plt
 #as: -mfdpic
 #ld: -shared
-#error: nonzero addend
+#error: (nonzero addend|may have caused)
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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