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]

Re: ld --emit-relocs fixes


I'll apply this one in the morning if no one finds fault.  It cures
the --emit-relocs problem on rela targets and gets rid of quite a
bit of duplicated code.  mips is the fly in the ointment here, and
the reason for elf_backend_rela_normal.

bfd/ChangeLog
	* elf-bfd.h (struct elf_backend_data): Add rela_normal.
	* elfxx-target.h (elf_backend_rela_normal): Define.
	(elfNN_bed): Init rela_normal.
	* elflink.h (elf_link_input_bfd <emit_relocs>): Handle adjustment
	for section symbols here if rela_normal.  Simplify abs section test.
	* elf-m10200.c (mn10200_elf_relocate_section): If relocatable,
	return immediately.  Remove code handling relocatable linking.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-i370.c (i370_elf_relocate_section): Likewise.
	* elf32-i860.c (elf32_i860_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-openrisc.c (openrisc_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
	* elfxx-ia64.c (elfNN_ia64_relocate_section): Likewise.
	* elf32-arm.h (elf32_arm_relocate_section): Likewise #ifndef USE_REL.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf-m10200.c (elf_backend_rela_normal): Define.
	* elf-m10300.c (elf_backend_rela_normal): Define.
	* elf32-fr30.c (elf_backend_rela_normal): Define.
	* elf32-i370.c (elf_backend_rela_normal): Define.
	* elf32-i860.c (elf_backend_rela_normal): Define.
	* elf32-m68k.c (elf_backend_rela_normal): Define.
	* elf32-mcore.c (elf_backend_rela_normal): Define.
	* elf32-openrisc.c (elf_backend_rela_normal): Define.
	* elf32-ppc.c (elf_backend_rela_normal): Define.
	* elf32-s390.c (elf_backend_rela_normal): Define.
	* elf32-xstormy16.c (elf_backend_rela_normal): Define.
	* elf64-ppc.c (elf_backend_rela_normal): Define.
	* elf64-s390.c (elf_backend_rela_normal): Define.
	* elf64-x86-64.c (elf_backend_rela_normal): Define.
	* elfxx-ia64.c (elf_backend_rela_normal): Define.
	* elf32-arm.h (elf_backend_rela_normal): Define #ifndef USE_REL.
	* elf32-m32r.c (elf_backend_rela_normal): Likewise.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.68
diff -u -p -r1.68 elf-bfd.h
--- bfd/elf-bfd.h	4 Apr 2002 07:01:19 -0000	1.68
+++ bfd/elf-bfd.h	6 May 2002 12:47:53 -0000
@@ -804,6 +804,11 @@ struct elf_backend_data
      section.  */
   unsigned default_use_rela_p : 1;
 
+  /* Set if RELA relocations for a relocatable link can be handled by
+     generic code.  Backends that set this flag need do nothing in the
+     backend relocate_section routine for relocatable linking.  */
+  unsigned rela_normal : 1;
+
   /* True if addresses "naturally" sign extend.  This is used when
      swapping in from Elf32 when BFD64.  */
   unsigned sign_extend_vma : 1;
Index: bfd/elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.39
diff -u -p -r1.39 elfxx-target.h
--- bfd/elfxx-target.h	4 Apr 2002 19:53:37 -0000	1.39
+++ bfd/elfxx-target.h	6 May 2002 12:48:30 -0000
@@ -400,6 +400,10 @@ Foundation, Inc., 59 Temple Place - Suit
 #define elf_backend_default_use_rela_p !USE_REL
 #endif
 
+#ifndef elf_backend_rela_normal
+#define elf_backend_rela_normal 0
+#endif
+
 #ifndef ELF_MACHINE_ALT1
 #define ELF_MACHINE_ALT1 0
 #endif
@@ -482,6 +486,7 @@ static const struct elf_backend_data elf
   elf_backend_may_use_rel_p,
   elf_backend_may_use_rela_p,
   elf_backend_default_use_rela_p,
+  elf_backend_rela_normal,
   elf_backend_sign_extend_vma,
   elf_backend_want_got_plt,
   elf_backend_plt_readonly,
Index: bfd/elf-m10200.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10200.c,v
retrieving revision 1.13
diff -u -p -r1.13 elf-m10200.c
--- bfd/elf-m10200.c	17 Dec 2001 00:52:34 -0000	1.13
+++ bfd/elf-m10200.c	6 May 2002 12:47:55 -0000
@@ -1,5 +1,5 @@
 /* Matsushita 10200 specific support for 32-bit ELF
-   Copyright 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -347,6 +347,9 @@ mn10200_elf_relocate_section (output_bfd
   struct elf_link_hash_entry **sym_hashes;
   Elf_Internal_Rela *rel, *relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
 
@@ -367,26 +370,6 @@ mn10200_elf_relocate_section (output_bfd
       r_type = ELF32_R_TYPE (rel->r_info);
       howto = elf_mn10200_howto_table + r_type;
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -1572,6 +1555,7 @@ mn10200_elf_get_relocated_section_conten
 #define ELF_MACHINE_ALT1	EM_CYGNUS_MN10200
 #define ELF_MAXPAGESIZE		0x1000
 
+#define elf_backend_rela_normal 1
 #define elf_info_to_howto	mn10200_info_to_howto
 #define elf_info_to_howto_rel	0
 #define elf_backend_relocate_section mn10200_elf_relocate_section
Index: bfd/elf-m10300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10300.c,v
retrieving revision 1.23
diff -u -p -r1.23 elf-m10300.c
--- bfd/elf-m10300.c	4 Apr 2002 19:53:35 -0000	1.23
+++ bfd/elf-m10300.c	6 May 2002 12:47:57 -0000
@@ -553,6 +553,9 @@ mn10300_elf_relocate_section (output_bfd
   struct elf32_mn10300_link_hash_entry **sym_hashes;
   Elf_Internal_Rela *rel, *relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = (struct elf32_mn10300_link_hash_entry **)
 		 (elf_sym_hashes (input_bfd));
@@ -579,26 +582,6 @@ mn10300_elf_relocate_section (output_bfd
 	  || r_type == R_MN10300_GNU_VTENTRY)
 	continue;
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -3101,6 +3084,7 @@ _bfd_mn10300_elf_merge_private_bfd_data 
 #define elf_info_to_howto		mn10300_info_to_howto
 #define elf_info_to_howto_rel		0
 #define elf_backend_can_gc_sections	1
+#define elf_backend_rela_normal		1
 #define elf_backend_check_relocs	mn10300_elf_check_relocs
 #define elf_backend_gc_mark_hook	mn10300_elf_gc_mark_hook
 #define elf_backend_relocate_section	mn10300_elf_relocate_section
Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.h,v
retrieving revision 1.79
diff -u -p -r1.79 elf32-arm.h
--- bfd/elf32-arm.h	4 Apr 2002 19:53:36 -0000	1.79
+++ bfd/elf32-arm.h	6 May 2002 12:48:00 -0000
@@ -1830,6 +1830,11 @@ elf32_arm_relocate_section (output_bfd, 
   Elf_Internal_Rela *           relend;
   const char *                  name;
 
+#ifndef USE_REL
+  if (info->relocateable)
+    return true;
+#endif
+
   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
 
@@ -1862,6 +1867,7 @@ elf32_arm_relocate_section (output_bfd, 
 #endif
       howto = bfd_reloc.howto;
 
+#ifdef USE_REL
       if (info->relocateable)
 	{
 	  /* This is a relocateable link.  We don't have to change
@@ -1874,19 +1880,16 @@ elf32_arm_relocate_section (output_bfd, 
 	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
 		{
 		  sec = local_sections[r_symndx];
-#ifdef USE_REL
 		  arm_add_to_rel (input_bfd, contents + rel->r_offset,
 				  howto,
 				  (bfd_signed_vma) (sec->output_offset
 						    + sym->st_value));
-#else
-		  rel->r_addend += (sec->output_offset + sym->st_value);
-#endif
 		}
 	    }
 
 	  continue;
 	}
+#endif
 
       /* This is a final link.  */
       h = NULL;
@@ -3637,6 +3640,9 @@ elf32_arm_reloc_type_class (rela)
 #define elf_backend_plt_readonly    1
 #define elf_backend_want_got_plt    1
 #define elf_backend_want_plt_sym    0
+#ifndef USE_REL
+#define elf_backend_rela_normal     1
+#endif
 
 #define elf_backend_got_header_size	12
 #define elf_backend_plt_header_size	PLT_ENTRY_SIZE
Index: bfd/elf32-fr30.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-fr30.c,v
retrieving revision 1.14
diff -u -p -r1.14 elf32-fr30.c
--- bfd/elf32-fr30.c	17 Dec 2001 00:52:35 -0000	1.14
+++ bfd/elf32-fr30.c	6 May 2002 12:48:01 -0000
@@ -1,5 +1,5 @@
 /* FR30-specific support for 32-bit ELF.
-   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -517,6 +517,9 @@ fr30_elf_relocate_section (output_bfd, i
   Elf_Internal_Rela *           rel;
   Elf_Internal_Rela *           relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend     = relocs + input_section->reloc_count;
@@ -541,27 +544,6 @@ fr30_elf_relocate_section (output_bfd, i
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections [r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       howto  = fr30_elf_howto_table + ELF32_R_TYPE (rel->r_info);
       h      = NULL;
       sym    = NULL;
@@ -806,6 +788,7 @@ fr30_elf_check_relocs (abfd, info, sec, 
 #define elf_backend_check_relocs                fr30_elf_check_relocs
 
 #define elf_backend_can_gc_sections		1
+#define elf_backend_rela_normal			1
 
 #define bfd_elf32_bfd_reloc_type_lookup		fr30_reloc_type_lookup
 
Index: bfd/elf32-i370.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i370.c,v
retrieving revision 1.20
diff -u -p -r1.20 elf32-i370.c
--- bfd/elf32-i370.c	28 Mar 2002 03:27:43 -0000	1.20
+++ bfd/elf32-i370.c	6 May 2002 12:48:02 -0000
@@ -1277,6 +1277,9 @@ i370_elf_relocate_section (output_bfd, i
   bfd_vma *local_got_offsets;
   boolean ret				  = true;
 
+  if (info->relocateable)
+    return true;
+
 #ifdef DEBUG
   fprintf (stderr, "i370_elf_relocate_section called for %s section %s, %ld relocations%s\n",
 	   bfd_archive_filename (input_bfd),
@@ -1320,34 +1323,6 @@ i370_elf_relocate_section (output_bfd, i
       howto = i370_elf_howto_table[(int)r_type];
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  addend = rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-#ifdef DEBUG
-	  fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
-		   howto->name,
-		   (int)r_type,
-		   r_symndx,
-		   (long)offset,
-		   (long)addend);
-#endif
-	  continue;
-	}
-
-      /* This is a final link.  */
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  sym = local_syms + r_symndx;
@@ -1661,6 +1636,7 @@ i370_elf_post_process_headers (abfd, lin
 
 #define elf_backend_plt_not_loaded 1
 #define elf_backend_got_symbol_offset 4
+#define elf_backend_rela_normal 1
 
 #define bfd_elf32_bfd_reloc_type_lookup		i370_elf_reloc_type_lookup
 #define bfd_elf32_bfd_set_private_flags		i370_elf_set_private_flags
Index: bfd/elf32-i860.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i860.c,v
retrieving revision 1.15
diff -u -p -r1.15 elf32-i860.c
--- bfd/elf32-i860.c	23 Nov 2001 12:17:16 -0000	1.15
+++ bfd/elf32-i860.c	6 May 2002 12:48:03 -0000
@@ -1,5 +1,6 @@
 /* Intel i860 specific support for 32-bit ELF.
-   Copyright 1993, 1995, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1993, 1995, 1999, 2000, 2001, 2002
+   Free Software Foundation, Inc.
 
    Full i860 support contributed by Jason Eckhardt <jle@cygnus.com>.
 
@@ -878,6 +879,9 @@ elf32_i860_relocate_section (output_bfd,
   Elf_Internal_Rela *           rel;
   Elf_Internal_Rela *           relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend     = relocs + input_section->reloc_count;
@@ -904,27 +908,6 @@ elf32_i860_relocate_section (output_bfd,
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections [r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       howto = lookup_howto ((unsigned) ELF32_R_TYPE (rel->r_info));
       h     = NULL;
       sym   = NULL;
@@ -1097,6 +1080,7 @@ elf32_i860_is_local_label_name (abfd, na
 #define ELF_MACHINE_CODE	EM_860
 #define ELF_MAXPAGESIZE		4096
 
+#define elf_backend_rela_normal			1
 #define elf_info_to_howto_rel                   NULL
 #define elf_info_to_howto			elf32_i860_info_to_howto_rela
 #define elf_backend_relocate_section		elf32_i860_relocate_section
Index: bfd/elf32-m32r.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32r.c,v
retrieving revision 1.22
diff -u -p -r1.22 elf32-m32r.c
--- bfd/elf32-m32r.c	16 Apr 2002 04:58:12 -0000	1.22
+++ bfd/elf32-m32r.c	6 May 2002 12:48:04 -0000
@@ -981,6 +981,11 @@ m32r_elf_relocate_section (output_bfd, i
   /* Assume success.  */
   boolean ret = true;
 
+#ifndef USE_REL
+  if (info->relocateable)
+    return true;
+#endif
+
   rel = relocs;
   relend = relocs + input_section->reloc_count;
   for (; rel < relend; rel++)
@@ -1020,6 +1025,7 @@ m32r_elf_relocate_section (output_bfd, i
       howto = m32r_elf_howto_table + r_type;
       r_symndx = ELF32_R_SYM (rel->r_info);
 
+#ifdef USE_REL
       if (info->relocateable)
 	{
 	  /* This is a relocateable link.  We don't have to change
@@ -1045,16 +1051,7 @@ m32r_elf_relocate_section (output_bfd, i
 
 	  sec = local_sections[r_symndx];
 	  addend += sec->output_offset + sym->st_value;
-#ifndef USE_REL
-	  /* This can't be done for USE_REL because it doesn't mean anything
-	     and elf_link_input_bfd asserts this stays zero.  */
-	  rel->r_addend = addend;
-#endif
 
-#ifndef USE_REL
-	  /* Addends are stored with relocs.  We're done.  */
-	  continue;
-#else /* USE_REL */
 	  /* If partial_inplace, we need to store any additional addend
 	     back in the section.  */
 	  if (! howto->partial_inplace)
@@ -1088,9 +1085,9 @@ m32r_elf_relocate_section (output_bfd, i
 		r = _bfd_relocate_contents (howto, input_bfd,
 					    addend, contents + offset);
 	    }
-#endif /* USE_REL */
 	}
       else
+#endif /* USE_REL */
 	{
 	  bfd_vma relocation;
 
@@ -2161,6 +2158,9 @@ m32r_elf_check_relocs (abfd, info, sec, 
 #define elf_backend_check_relocs                m32r_elf_check_relocs
 
 #define elf_backend_can_gc_sections             1
+#ifndef USE_REL
+#define elf_backend_rela_normal			1
+#endif
 #if 0 /* not yet */
 /* relax support */
 #define bfd_elf32_bfd_relax_section		m32r_elf_relax_section
Index: bfd/elf32-m68k.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68k.c,v
retrieving revision 1.39
diff -u -p -r1.39 elf32-m68k.c
--- bfd/elf32-m68k.c	4 Apr 2002 19:53:36 -0000	1.39
+++ bfd/elf32-m68k.c	6 May 2002 12:48:07 -0000
@@ -1308,6 +1308,9 @@ elf_m68k_relocate_section (output_bfd, i
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   dynobj = elf_hash_table (info)->dynobj;
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1340,26 +1343,6 @@ elf_m68k_relocate_section (output_bfd, i
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -2325,5 +2308,6 @@ elf32_m68k_reloc_type_class (rela)
 #define elf_backend_plt_readonly 1
 #define elf_backend_want_plt_sym 0
 #define elf_backend_got_header_size	12
+#define elf_backend_rela_normal		1
 
 #include "elf32-target.h"
Index: bfd/elf32-mcore.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-mcore.c,v
retrieving revision 1.20
diff -u -p -r1.20 elf32-mcore.c
--- bfd/elf32-mcore.c	18 Dec 2001 17:59:58 -0000	1.20
+++ bfd/elf32-mcore.c	6 May 2002 12:48:07 -0000
@@ -1,5 +1,6 @@
 /* Motorola MCore specific support for 32-bit ELF
-   Copyright 1994, 1995, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1999, 2000, 2001, 2002
+   Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -414,6 +415,9 @@ mcore_elf_relocate_section (output_bfd, 
 	   (info->relocateable) ? " (relocatable)" : "");
 #endif
 
+  if (info->relocateable)
+    return true;
+
   if (! mcore_elf_howto_table [R_MCORE_PCRELIMM8BY4])	/* Initialize howto table if needed */
     mcore_elf_howto_init ();
 
@@ -447,32 +451,6 @@ mcore_elf_relocate_section (output_bfd, 
       howto = mcore_elf_howto_table [(int) r_type];
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-
-	      if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  addend = rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-#ifdef DEBUG
-	  fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
-		   howto->name, (int) r_type, r_symndx, (long) offset, (long) addend);
-#endif
-	  continue;
-	}
-
-      /* This is a final link.  */
-
       /* Complain about known relocation that are not yet supported.  */
       if (howto->special_function == mcore_elf_unsupported_reloc)
 	{
@@ -726,5 +704,6 @@ mcore_elf_check_relocs (abfd, info, sec,
 #define elf_backend_check_relocs                mcore_elf_check_relocs
 
 #define elf_backend_can_gc_sections		1
+#define elf_backend_rela_normal			1
 
 #include "elf32-target.h"
Index: bfd/elf32-openrisc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-openrisc.c,v
retrieving revision 1.7
diff -u -p -r1.7 elf32-openrisc.c
--- bfd/elf32-openrisc.c	17 Dec 2001 00:52:35 -0000	1.7
+++ bfd/elf32-openrisc.c	6 May 2002 12:48:07 -0000
@@ -1,5 +1,5 @@
 /* OpenRISC-specific support for 32-bit ELF.
-   Copyright 2001 Free Software Foundation, Inc.
+   Copyright 2001, 2002 Free Software Foundation, Inc.
    Contributed by Johan Rydberg, jrydberg@opencores.org
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -338,6 +338,9 @@ openrisc_elf_relocate_section (output_bf
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend = relocs + input_section->reloc_count;
@@ -361,25 +364,6 @@ openrisc_elf_relocate_section (output_bf
 	  || r_type == R_OPENRISC_GNU_VTENTRY)
 	continue;
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-	  continue;
-	}
-
       if ((unsigned int) r_type >
 	  (sizeof openrisc_elf_howto_table / sizeof (reloc_howto_type)))
 	abort ();
@@ -645,6 +629,7 @@ openrisc_elf_final_write_processing (abf
 #define elf_backend_check_relocs	openrisc_elf_check_relocs
 
 #define elf_backend_can_gc_sections	1
+#define elf_backend_rela_normal		1
 
 #define bfd_elf32_bfd_reloc_type_lookup openrisc_reloc_type_lookup
 
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.42
diff -u -p -r1.42 elf32-ppc.c
--- bfd/elf32-ppc.c	2 May 2002 12:35:25 -0000	1.42
+++ bfd/elf32-ppc.c	6 May 2002 12:48:10 -0000
@@ -1,5 +1,5 @@
 /* PowerPC-specific support for 32-bit ELF
-   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
@@ -2896,6 +2896,9 @@ ppc_elf_relocate_section (output_bfd, in
 	   (info->relocateable) ? " (relocatable)" : "");
 #endif
 
+  if (info->relocateable)
+    return true;
+
   if (!ppc_elf_howto_table[R_PPC_ADDR32])
     /* Initialize howto table if needed.  */
     ppc_elf_howto_init ();
@@ -2940,34 +2943,6 @@ ppc_elf_relocate_section (output_bfd, in
       howto = ppc_elf_howto_table[(int) r_type];
       r_symndx = ELF32_R_SYM (rel->r_info);
 
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  addend = rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-#ifdef DEBUG
-	  fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
-		   howto->name,
-		   (int) r_type,
-		   r_symndx,
-		   (long) offset,
-		   (long) addend);
-#endif
-	  continue;
-	}
-
-      /* This is a final link.  */
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  sym = local_syms + r_symndx;
@@ -3781,6 +3756,7 @@ ppc_elf_grok_psinfo (abfd, note)
 #define elf_backend_can_refcount	1
 #define elf_backend_got_header_size	12
 #define elf_backend_plt_header_size	PLT_INITIAL_ENTRY_SIZE
+#define elf_backend_rela_normal		1
 
 #define bfd_elf32_bfd_merge_private_bfd_data	ppc_elf_merge_private_bfd_data
 #define bfd_elf32_bfd_relax_section             ppc_elf_relax_section
Index: bfd/elf32-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-s390.c,v
retrieving revision 1.24
diff -u -p -r1.24 elf32-s390.c
--- bfd/elf32-s390.c	4 Apr 2002 19:53:36 -0000	1.24
+++ bfd/elf32-s390.c	6 May 2002 12:48:12 -0000
@@ -1632,6 +1632,9 @@ elf_s390_relocate_section (output_bfd, i
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   htab = elf_s390_hash_table (info);
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1661,30 +1664,9 @@ elf_s390_relocate_section (output_bfd, i
 	  bfd_set_error (bfd_error_bad_value);
 	  return false;
 	}
-      howto = elf_howto_table + r_type;
 
+      howto = elf_howto_table + r_type;
       r_symndx = ELF32_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -2467,6 +2449,7 @@ elf_s390_grok_prstatus (abfd, note)
 #define elf_backend_want_plt_sym	0
 #define elf_backend_got_header_size	12
 #define elf_backend_plt_header_size	PLT_ENTRY_SIZE
+#define elf_backend_rela_normal		1
 
 #define elf_info_to_howto                     elf_s390_info_to_howto
 
Index: bfd/elf32-xstormy16.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xstormy16.c,v
retrieving revision 1.4
diff -u -p -r1.4 elf32-xstormy16.c
--- bfd/elf32-xstormy16.c	28 Mar 2002 03:27:44 -0000	1.4
+++ bfd/elf32-xstormy16.c	6 May 2002 12:48:14 -0000
@@ -790,6 +790,9 @@ xstormy16_elf_relocate_section (output_b
   bfd *dynobj;
   asection *splt;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend     = relocs + input_section->reloc_count;
@@ -818,28 +821,6 @@ xstormy16_elf_relocate_section (output_b
 	continue;
       
       r_symndx = ELF32_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections [r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       howto  = xstormy16_elf_howto_table + ELF32_R_TYPE (rel->r_info);
       h      = NULL;
       sym    = NULL;
@@ -1108,6 +1089,7 @@ xstormy16_elf_gc_sweep_hook (abfd, info,
   xstormy16_elf_finish_dynamic_sections
 
 #define elf_backend_can_gc_sections		1
+#define elf_backend_rela_normal			1
 
 #define bfd_elf32_bfd_reloc_type_lookup		xstormy16_reloc_type_lookup
 #define bfd_elf32_bfd_relax_section		xstormy16_elf_relax_section
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.37
diff -u -p -r1.37 elf64-ppc.c
--- bfd/elf64-ppc.c	4 May 2002 12:01:01 -0000	1.37
+++ bfd/elf64-ppc.c	6 May 2002 12:48:17 -0000
@@ -5051,6 +5051,9 @@ ppc64_elf_relocate_section (output_bfd, 
   /* Disabled until we sort out how ld should choose 'y' vs 'at'.  */
   boolean is_power4 = false;
 
+  if (info->relocateable)
+    return true;
+
   /* Initialize howto table if needed.  */
   if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
     ppc_howto_init ();
@@ -5085,27 +5088,6 @@ ppc64_elf_relocate_section (output_bfd, 
 
       r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
       r_symndx = ELF64_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocatable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-	  continue;
-	}
-
-      /* This is a final link.  */
-
       offset = rel->r_offset;
       addend = rel->r_addend;
       r = bfd_reloc_other;
@@ -6053,6 +6035,7 @@ ppc64_elf_finish_dynamic_sections (outpu
 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
 #define elf_backend_can_gc_sections 1
 #define elf_backend_can_refcount 1
+#define elf_backend_rela_normal 1
 
 #define bfd_elf64_bfd_reloc_type_lookup	      ppc64_elf_reloc_type_lookup
 #define bfd_elf64_bfd_set_private_flags	      ppc64_elf_set_private_flags
Index: bfd/elf64-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-s390.c,v
retrieving revision 1.23
diff -u -p -r1.23 elf64-s390.c
--- bfd/elf64-s390.c	4 Apr 2002 19:53:37 -0000	1.23
+++ bfd/elf64-s390.c	6 May 2002 12:48:18 -0000
@@ -1587,6 +1587,9 @@ elf_s390_relocate_section (output_bfd, i
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   htab = elf_s390_hash_table (info);
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1616,30 +1619,9 @@ elf_s390_relocate_section (output_bfd, i
 	  bfd_set_error (bfd_error_bad_value);
 	  return false;
 	}
-      howto = elf_howto_table + r_type;
 
+      howto = elf_howto_table + r_type;
       r_symndx = ELF64_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -2384,6 +2366,7 @@ const struct elf_size_info s390_elf64_si
 #define elf_backend_want_plt_sym	0
 #define elf_backend_got_header_size	24
 #define elf_backend_plt_header_size	PLT_ENTRY_SIZE
+#define elf_backend_rela_normal		1
 
 #define elf_info_to_howto		elf_s390_info_to_howto
 
Index: bfd/elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.40
diff -u -p -r1.40 elf64-x86-64.c
--- bfd/elf64-x86-64.c	28 Apr 2002 12:29:46 -0000	1.40
+++ bfd/elf64-x86-64.c	6 May 2002 12:48:22 -0000
@@ -1494,6 +1494,9 @@ elf64_x86_64_relocate_section (output_bf
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   htab = elf64_x86_64_hash_table (info);
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1524,30 +1527,9 @@ elf64_x86_64_relocate_section (output_bf
 	  bfd_set_error (bfd_error_bad_value);
 	  return false;
 	}
-      howto = x86_64_elf_howto_table + r_type;
 
+      howto = x86_64_elf_howto_table + r_type;
       r_symndx = ELF64_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sec = local_sections[r_symndx];
-		  rel->r_addend += sec->output_offset + sym->st_value;
-		}
-	    }
-
-	  continue;
-	}
-
-      /* This is a final link.	*/
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -2230,6 +2212,7 @@ elf64_x86_64_finish_dynamic_sections (ou
 #define elf_backend_want_plt_sym	    0
 #define elf_backend_got_header_size	    (GOT_ENTRY_SIZE*3)
 #define elf_backend_plt_header_size	    PLT_ENTRY_SIZE
+#define elf_backend_rela_normal		    1
 
 #define elf_info_to_howto		    elf64_x86_64_info_to_howto
 
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.158
diff -u -p -r1.158 elflink.h
--- bfd/elflink.h	6 May 2002 08:54:44 -0000	1.158
+++ bfd/elflink.h	6 May 2002 12:48:27 -0000
@@ -6754,6 +6754,12 @@ elf_link_input_bfd (finfo, input_bfd)
 	      void (*reloc_emitter) PARAMS ((bfd *, asection *,
 					     Elf_Internal_Shdr *,
 					     Elf_Internal_Rela *));
+	      boolean rela_normal;
+
+	      input_rel_hdr = &elf_section_data (o)->rel_hdr;
+	      rela_normal = (bed->rela_normal
+			     && (input_rel_hdr->sh_entsize
+				 == sizeof (Elf_External_Rela)));
 
 	      /* Adjust the reloc addresses and symbol indices.  */
 
@@ -6827,10 +6833,9 @@ elf_link_input_bfd (finfo, input_bfd)
 			 processor specific section.  If we have
 			 discarded a section, the output_section will
 			 be the absolute section.  */
-		      if (sec != NULL
-			  && (bfd_is_abs_section (sec)
-			      || (sec->output_section != NULL
-				  && bfd_is_abs_section (sec->output_section))))
+		      if (bfd_is_abs_section (sec)
+			  || (sec != NULL
+			      && bfd_is_abs_section (sec->output_section)))
 			r_symndx = 0;
 		      else if (sec == NULL || sec->owner == NULL)
 			{
@@ -6842,6 +6847,11 @@ elf_link_input_bfd (finfo, input_bfd)
 			  r_symndx = sec->output_section->target_index;
 			  BFD_ASSERT (r_symndx != 0);
 			}
+
+		      /* Adjust the addend according to where the
+			 section winds up in the output section.  */ 
+		      if (rela_normal)
+			irela->r_addend += sec->output_offset;
 		    }
 		  else
 		    {
@@ -6900,7 +6910,6 @@ elf_link_input_bfd (finfo, input_bfd)
 	      else
 		reloc_emitter = elf_link_output_relocs;
 
-	      input_rel_hdr = &elf_section_data (o)->rel_hdr;
 	      (*reloc_emitter) (output_bfd, o, input_rel_hdr, internal_relocs);
 
 	      input_rel_hdr = elf_section_data (o)->rel_hdr2;
Index: bfd/elfxx-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-ia64.c,v
retrieving revision 1.46
diff -u -p -r1.46 elfxx-ia64.c
--- bfd/elfxx-ia64.c	28 Mar 2002 03:27:45 -0000	1.46
+++ bfd/elfxx-ia64.c	6 May 2002 12:48:30 -0000
@@ -3502,6 +3502,7 @@ elfNN_ia64_relocate_section (output_bfd,
 
       elf_section_data(input_section->output_section)
 	->this_hdr.sh_flags |= flags;
+      return true;
     }
 
   gp_val = _bfd_get_gp_value (output_bfd);
@@ -3534,29 +3535,9 @@ elfNN_ia64_relocate_section (output_bfd,
 	  ret_val = false;
 	  continue;
 	}
+
       howto = lookup_howto (r_type);
       r_symndx = ELFNN_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-	{
-	  /* This is a relocateable link.  We don't have to change
-	     anything, unless the reloc is against a section symbol,
-	     in which case we have to adjust according to where the
-	     section symbol winds up in the output section.  */
-	  if (r_symndx < symtab_hdr->sh_info)
-	    {
-	      sym = local_syms + r_symndx;
-	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-		{
-		  sym_sec = local_sections[r_symndx];
-		  rel->r_addend += sym_sec->output_offset;
-		}
-	    }
-	  continue;
-	}
-
-      /* This is a final link.  */
-
       h = NULL;
       sym = NULL;
       sym_sec = NULL;
@@ -4561,6 +4542,7 @@ elfNN_hpux_backend_section_from_bfd_sect
 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
 #define elf_backend_hide_symbol		elfNN_ia64_hash_hide_symbol
 #define elf_backend_reloc_type_class	elfNN_ia64_reloc_type_class
+#define elf_backend_rela_normal		1
 
 #include "elfNN-target.h"
 

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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