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]

[PATCH] Fix Alpha with gcc 3.1


Hi!

With quite recent gcc and binutils, it is often not possible to build C++
binaries on Alpha due to errors like
termios.o(.eh_frame+0x538): relocation truncated to fit: SREL32 gnu.linkonce.t._ZNSo5flushEv
termios.o(.eh_frame+0x558): relocation truncated to fit: SREL32 gnu.linkonce.t._ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
(doesn't matter here whether --eh-frame-hdr patch is in or not).
The reason is that eelf64_alpha_relocate_section tries to relocate a SREL32
against either r_symndx 0 (without --eh-frame-hdr patch) or STT_SECTION
symbol of discarded section.
This patch has 2 parts, one is a cleanup + bug fix
(elf_reloc_symbol_deleted_p was not taking into account SHF_MERGE sections),
the other is actual Alpha patch.
There I'm not exactly sure what should be done.
In .eh_frame case, --eh-frame-hdr patch ensures what exactly is written into
memory during _bfd_final_link_relocate doesn't matter as the memory is not
output anyway.
The options include:
1) the elf64-alpha.c hunk below
2) similarly, just with elf_section_ignore_discarded_relocs function
   exported out of elflink.h and add it to the test in elf64-alpha.c
3) add new special return value for _bfd_elf_section_offset
   ((bfd_vma) -2) and assign them meaning:
   -1: skip dynamic reloc if any, the memory against which the reloc
   won't be in the final object
   -2: skip dynamic reloc only, reloc must be done (without overflow)
   -2 would be returned just for the make_relative/make_lsda_relative
   optimizations ATM.
   If -1 was returned, _bfd_final_link_relocate could be skipped in the
   targets and in case of relocs for which no dynamic reloc is created,
   _bfd_elf_section_offset could be called when overflow happened
   and just see if it was (bfd_vma) -1, in which case just pretend
   no overflow
4) in elflink.h, move the elf_section_ignore_discarded_relocs
   test just around the actual warnings and clear relocs always.
   In addition to this, elf64-alpha.c either would need to skip
   _bfd_final_link_relocate if r_symndx == 0 (is this safe?) or
   just kill the overflow warning if r_symndx == 0.

Ok to commit the non-alpha hunks?
What do you prefer for alpha (several other backends will need similar
treatment (especially 64-bit))?

2001-12-17  Jakub Jelinek  <jakub@redhat.com>

	* elf-bfd.h (elf_discarded_section): Define.
	* elflink.h (elf_link_input_bfd): Use it.
	(elf_reloc_symbol_deleted_p): Likewise.

	* elf64-alpha.c (elf64_alpha_relocate_section): Don't warn about
	overflows for pc relative relocs against discarded sections.

--- bfd/elf-bfd.h.jj	Mon Dec 17 12:29:14 2001
+++ bfd/elf-bfd.h	Mon Dec 17 17:57:44 2001
@@ -883,6 +883,12 @@ struct bfd_elf_section_data
 #define elf_group_name(sec)    (elf_section_data(sec)->group_name)
 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
 
+/* Return true if section has been discarded.  */
+#define elf_discarded_section(sec)					\
+  (!bfd_is_abs_section(sec)						\
+   && bfd_is_abs_section((sec)->output_section)				\
+   && elf_section_data (sec)->sec_info_type != ELF_INFO_TYPE_MERGE)
+
 #define get_elf_backend_data(abfd) \
   ((struct elf_backend_data *) (abfd)->xvec->backend_data)
 
--- bfd/elflink.h.jj	Mon Dec 17 12:29:48 2001
+++ bfd/elflink.h	Mon Dec 17 18:00:58 2001
@@ -6551,11 +6551,7 @@ elf_link_input_bfd (finfo, input_bfd)
 			 discarded section.  */
 		      if ((h->root.type == bfd_link_hash_defined
 			   || h->root.type == bfd_link_hash_defweak)
-			  && ! bfd_is_abs_section (h->root.u.def.section)
-			  && bfd_is_abs_section (h->root.u.def.section
-						 ->output_section)
-			  && (elf_section_data (h->root.u.def.section)
-			      ->sec_info_type != ELF_INFO_TYPE_MERGE))
+			  && elf_discarded_section (h->root.u.def.section))
 			{
 #if BFD_VERSION_DATE < 20031005
 			  if ((o->flags & SEC_DEBUGGING) != 0)
@@ -6584,11 +6580,7 @@ elf_link_input_bfd (finfo, input_bfd)
 		    {
 		      asection *sec = finfo->sections[r_symndx];
 
-		      if (sec != NULL
-			  && ! bfd_is_abs_section (sec)
-			  && bfd_is_abs_section (sec->output_section)
-			  && (elf_section_data (sec)->sec_info_type
-			      != ELF_INFO_TYPE_MERGE))
+		      if (sec != NULL && elf_discarded_section (sec))
 			{
 #if BFD_VERSION_DATE < 20031005
 			  if ((o->flags & SEC_DEBUGGING) != 0
@@ -8085,9 +8077,7 @@ elf_reloc_symbol_deleted_p (offset, cook
 
 	  if ((h->root.type == bfd_link_hash_defined
 	       || h->root.type == bfd_link_hash_defweak)
-	      && ! bfd_is_abs_section (h->root.u.def.section)
-	      && bfd_is_abs_section (h->root.u.def.section
-				     ->output_section))
+	      && elf_discarded_section (h->root.u.def.section))
 	    return true;
 	  else
 	    return false;
@@ -8103,9 +8093,7 @@ elf_reloc_symbol_deleted_p (offset, cook
 	  if (isym.st_shndx < SHN_LORESERVE || isym.st_shndx > SHN_HIRESERVE)
 	    {
 	      isec = section_from_elf_index (rcookie->abfd, isym.st_shndx);
-	      if (isec != NULL
-		  && ! bfd_is_abs_section (isec)
-		  && bfd_is_abs_section (isec->output_section))
+	      if (isec != NULL && elf_discarded_section (isec))
 		return true;
 	    }
 	}
--- bfd/elf64-alpha.c.jj	Mon Dec 17 12:29:15 2001
+++ bfd/elf64-alpha.c	Mon Dec 17 18:02:07 2001
@@ -3628,6 +3628,15 @@ elf64_alpha_relocate_section (output_bfd
 	  {
 	    const char *name;
 
+	    /* Don't warn if the overflow is due to pc relative reloc
+	       against discarded section.  Section optimization code should
+	       handle it.  */
+
+	    if (r_symndx < symtab_hdr->sh_info
+		&& sec != NULL && howto->pc_relative
+		&& elf_discarded_section (sec))
+	      break;
+
 	    if (h != NULL)
 	      name = h->root.root.root.string;
 	    else

	Jakub


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