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/3958: ELF linker failed to handle relocation against ABS section


On Sat, Feb 03, 2007 at 08:45:18AM -0800, H. J. Lu wrote:
> This patch should fix PR ld/3958. We shouldn't remove remove the
> symbol reference from relocations against symbols from removed input
> section.  Someone should fix elf32-arm.c and elf32-score.c. They
> require adding section where r_symndx comes from.
> 
> I will try to add 2 testcases: one for PR ld/3958 and one for zeroing
> relocations against symbols from removed input section.
> 

Here is an updated patch with a testcase. There are already testcases
in ld-discard for relocations against symbols from removed input
sections.


H.J.
----
bfd/

2076-02-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3958
	* elf32-d10v.c (elf32_d10v_relocate_section): Use
	elf_discarded_section to check if a relocation is against a
	symbol from removed input section.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_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.
	* elfxx-mips.c (mips_elf_calculate_relocation): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.

	* elflink.c (elf_link_input_bfd): Don't remove the symbol
	reference from relocations against symbols from removed input
	section.

ld/testsuite/

2076-02-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3958
	* ld-i386/i386.exp: Run "pcrel16abs".

	* ld-i386/pcrel16abs.d: New file.
	* ld-i386/pcrel16abs.s: Likewise.

--- binutils/bfd/elf32-d10v.c.abs	2006-11-02 19:36:06.000000000 -0800
+++ binutils/bfd/elf32-d10v.c	2007-02-03 11:52:45.000000000 -0800
@@ -469,12 +469,11 @@ elf32_d10v_relocate_section (bfd *output
 				   unresolved_reloc, warned);
 	}
 
-      if (r_symndx == 0)
+      if (sec && elf_discarded_section (sec))
 	{
-	  /* r_symndx will be zero only for relocs against symbols from
-	     removed linkonce sections, or sections discarded by a linker
-	     script.  For these relocs, we just want the section contents
-	     zeroed.  Avoid any special processing.  */
+	  /* For relocs against symbols from removed linkonce sections,
+	     or sections discarded by a linker script, we just want the
+	     section contents zeroed.  Avoid any special processing.  */
 	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	  continue;
 	}
--- binutils/bfd/elf32-hppa.c.abs	2007-02-03 09:11:04.000000000 -0800
+++ binutils/bfd/elf32-hppa.c	2007-02-03 11:52:45.000000000 -0800
@@ -3939,11 +3939,12 @@ elf32_hppa_relocate_section (bfd *output
 	case R_PARISC_DPREL14R:
 	case R_PARISC_DPREL21L:
 	case R_PARISC_DIR32:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sym_sec && elf_discarded_section (sym_sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script,
+		 we just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (elf_hppa_howto_table + r_type, input_bfd,
 				   contents + rela->r_offset);
 	      break;
--- binutils/bfd/elf32-i386.c.abs	2007-02-03 09:11:04.000000000 -0800
+++ binutils/bfd/elf32-i386.c	2007-02-03 11:52:45.000000000 -0800
@@ -2414,12 +2414,11 @@ elf_i386_relocate_section (bfd *output_b
 				   unresolved_reloc, warned);
 	}
 
-      if (r_symndx == 0)
+      if (sec && elf_discarded_section (sec))
 	{
-	  /* r_symndx will be zero only for relocs against symbols from
-	     removed linkonce sections, or sections discarded by a linker
-	     script.  For these relocs, we just want the section contents
-	     zeroed.  Avoid any special processing.  */
+	  /* For relocs against symbols from removed linkonce sections,
+	     or sections discarded by a linker script, we just want the
+	     section contents zeroed.  Avoid any special processing.  */
 	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	  continue;
 	}
--- binutils/bfd/elf32-ppc.c.abs	2007-02-01 12:42:10.000000000 -0800
+++ binutils/bfd/elf32-ppc.c	2007-02-03 11:52:45.000000000 -0800
@@ -6225,12 +6225,13 @@ ppc_elf_relocate_section (bfd *output_bf
 	case R_PPC_ADDR14_BRNTAKEN:
 	case R_PPC_UADDR32:
 	case R_PPC_UADDR16:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
 	dodyn:
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script, we
+		 just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      break;
 	    }
--- binutils/bfd/elf32-s390.c.abs	2006-11-02 19:36:07.000000000 -0800
+++ binutils/bfd/elf32-s390.c	2007-02-03 11:52:45.000000000 -0800
@@ -2540,11 +2540,12 @@ elf_s390_relocate_section (output_bfd, i
 	case R_390_PC16DBL:
 	case R_390_PC32DBL:
 	case R_390_PC32:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script,
+		 we just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      break;
 	    }
--- binutils/bfd/elf32-sh.c.abs	2006-11-02 19:36:07.000000000 -0800
+++ binutils/bfd/elf32-sh.c	2007-02-03 11:52:45.000000000 -0800
@@ -3557,11 +3557,12 @@ sh_elf_relocate_section (bfd *output_bfd
 	case R_SH_IMM_MEDHI16_PCREL:
 	case R_SH_IMM_HI16_PCREL:
 #endif
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script, we
+		 just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      continue;
 	    }
--- binutils/bfd/elf32-xtensa.c.abs	2007-02-03 08:00:52.000000000 -0800
+++ binutils/bfd/elf32-xtensa.c	2007-02-03 11:52:45.000000000 -0800
@@ -2313,12 +2313,11 @@ elf_xtensa_relocate_section (bfd *output
 	  return FALSE;
 	}
 
-      if (r_symndx == 0)
+      if (sec && elf_discarded_section (sec))
 	{
-	  /* r_symndx will be zero only for relocs against symbols from
-	     removed linkonce sections, or sections discarded by a linker
-	     script.  For these relocs, we just want the section contents
-	     zeroed.  Avoid any special processing.  */
+	  /* For relocs against symbols from removed linkonce sections,
+	     or sections discarded by a linker script, we just want the
+	     section contents zeroed.  Avoid any special processing.  */
 	  _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	  continue;
 	}
--- binutils/bfd/elf64-ppc.c.abs	2007-02-01 12:42:10.000000000 -0800
+++ binutils/bfd/elf64-ppc.c	2007-02-03 11:52:45.000000000 -0800
@@ -10818,12 +10818,13 @@ ppc64_elf_relocate_section (bfd *output_
 	case R_PPC64_UADDR16:
 	case R_PPC64_UADDR32:
 	case R_PPC64_UADDR64:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
 	dodyn:
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script,
+		 we just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (ppc64_elf_howto_table[r_type], input_bfd,
 				   contents + rel->r_offset);
 	      break;
--- binutils/bfd/elf64-s390.c.abs	2006-11-02 19:36:09.000000000 -0800
+++ binutils/bfd/elf64-s390.c	2007-02-03 11:52:45.000000000 -0800
@@ -2519,11 +2519,12 @@ elf_s390_relocate_section (output_bfd, i
 	case R_390_PC32:
 	case R_390_PC32DBL:
 	case R_390_PC64:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script, we
+		 just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      break;
 	    }
--- binutils/bfd/elf64-x86-64.c.abs	2007-02-03 09:11:04.000000000 -0800
+++ binutils/bfd/elf64-x86-64.c	2007-02-03 11:52:45.000000000 -0800
@@ -2388,11 +2388,12 @@ elf64_x86_64_relocate_section (bfd *outp
 	  /* FIXME: The ABI says the linker should make sure the value is
 	     the same when it's zeroextended to 64 bit.	 */
 
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script, we
+		 just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      break;
 	    }
--- binutils/bfd/elflink.c.abs	2007-02-03 09:11:04.000000000 -0800
+++ binutils/bfd/elflink.c	2007-02-03 11:52:45.000000000 -0800
@@ -7754,14 +7754,17 @@ elf_link_input_bfd (struct elf_final_lin
 			    }
 			}
 
-		      /* Remove the symbol reference from the reloc, but
-			 don't kill the reloc completely.  This is so that
-			 a zero value will be written into the section,
-			 which may have non-zero contents put there by the
-			 assembler.  Zero in things like an eh_frame fde
-			 pc_begin allows stack unwinders to recognize the
-			 fde as bogus.  */
-		      rel->r_info &= r_type_mask;
+		      /* We can't use relocation against STN_UNDEF to
+			 indicate that a relocation entry is against a
+			 symbol from a removed input section since it is
+			 used for relocation against constant.  See
+			 PR 3958.  We need to use elf_discarded_section
+			 to check if a zero value should be be written
+			 into the section, which may have non-zero
+			 contents put there by the assembler.  Zero
+			 in things like an eh_frame fde pc_begin
+			 allows stack unwinders to recognize the fde as
+			 bogus.  */
 		      rel->r_addend = 0;
 		    }
 		}
--- binutils/bfd/elfxx-ia64.c.abs	2007-02-03 09:11:04.000000000 -0800
+++ binutils/bfd/elfxx-ia64.c	2007-02-03 11:52:45.000000000 -0800
@@ -4752,10 +4752,10 @@ elfNN_ia64_relocate_section (output_bfd,
 	case R_IA64_LTV32LSB:
 	case R_IA64_LTV64MSB:
 	case R_IA64_LTV64LSB:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  /* For relocs against symbols from removed linkonce sections,
+	     or sections discarded by a linker script, we just want the
+	     section contents zeroed.  Avoid any special processing.  */
+	  if (sym_sec && elf_discarded_section (sym_sec))
 	    value = 0;
 
 	  r = elfNN_ia64_install_value (hit_addr, value, r_type);
--- binutils/bfd/elfxx-mips.c.abs	2007-01-30 07:59:53.000000000 -0800
+++ binutils/bfd/elfxx-mips.c	2007-02-03 11:52:45.000000000 -0800
@@ -4323,11 +4323,13 @@ mips_elf_calculate_relocation (bfd *abfd
 						   input_section))
 	    return bfd_reloc_undefined;
 	}
-      else if (r_symndx == 0)
-	/* r_symndx will be zero only for relocs against symbols
-	   from removed linkonce sections, or sections discarded by
-	   a linker script.  */
-	value = 0;
+      else if (sec && elf_discarded_section (sec))
+	{
+	  /* For relocs against symbols from removed linkonce sections,
+	     or sections discarded by a linker script, we just want the
+	     section contents zeroed.  Avoid any special processing.  */
+	  value = 0;
+	}
       else
 	{
 	  if (r_type != R_MIPS_REL32)
--- binutils/bfd/elfxx-sparc.c.abs	2006-11-02 19:36:09.000000000 -0800
+++ binutils/bfd/elfxx-sparc.c	2007-02-03 11:52:45.000000000 -0800
@@ -2752,11 +2752,12 @@ _bfd_sparc_elf_relocate_section (bfd *ou
 	case R_SPARC_L44:
 	case R_SPARC_UA64:
 	r_sparc_plt32:
-	  /* r_symndx will be zero only for relocs against symbols
-	     from removed linkonce sections, or sections discarded by
-	     a linker script.  */
-	  if (r_symndx == 0)
+	  if (sec && elf_discarded_section (sec))
 	    {
+	      /* For relocs against symbols from removed linkonce
+		 sections, or sections discarded by a linker script, we
+		 just want the section contents zeroed.  Avoid any
+		 special processing.  */
 	      _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
 	      break;
 	    }
--- binutils/ld/testsuite/ld-i386/i386.exp.abs	2006-03-03 01:32:01.000000000 -0800
+++ binutils/ld/testsuite/ld-i386/i386.exp	2007-02-03 11:49:33.000000000 -0800
@@ -113,3 +113,4 @@ run_ld_link_tests $i386tests
 run_dump_test "abs"
 run_dump_test "pcrel8"
 run_dump_test "pcrel16"
+run_dump_test "pcrel16abs"
--- binutils/ld/testsuite/ld-i386/pcrel16abs.d.abs	2007-02-03 11:51:08.000000000 -0800
+++ binutils/ld/testsuite/ld-i386/pcrel16abs.d	2007-02-03 11:49:55.000000000 -0800
@@ -0,0 +1,12 @@
+#name: PCREL16 absolute reloc
+#as: --32
+#ld: -melf_i386 -Ttext 0xfffffff0
+#objdump: -drj.text -m i8086
+
+.*: +file format elf32-i386
+
+Disassembly of section .text:
+
+f+0 <_start>:
+f+0:	e9 0d e0[ 	]+jmp[ 	]+ffffe000 <SEGMENT_SIZE\+0xfffee000>
+#pass
--- binutils/ld/testsuite/ld-i386/pcrel16abs.s.abs	2007-02-03 11:51:11.000000000 -0800
+++ binutils/ld/testsuite/ld-i386/pcrel16abs.s	2007-02-03 10:13:24.000000000 -0800
@@ -0,0 +1,6 @@
+SEGMENT_SIZE = 0x10000
+RVECTOR = 0x00010
+.code16
+ .globl _start
+_start:
+ jmp SEGMENT_SIZE-(0x1f00 +0xf0 +RVECTOR)


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