This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/3958: ELF linker failed to handle relocation against ABS section
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Sat, 3 Feb 2007 08:45:18 -0800
- Subject: PATCH: PR ld/3958: ELF linker failed to handle relocation against ABS section
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.
H.J.
----
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.
--- bfd/elf32-d10v.c.abs 2006-11-02 19:36:06.000000000 -0800
+++ bfd/elf32-d10v.c 2007-02-03 08:06:08.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;
}
--- bfd/elf32-hppa.c.abs 2007-02-03 08:00:58.000000000 -0800
+++ bfd/elf32-hppa.c 2007-02-03 08:07:40.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;
--- bfd/elf32-i386.c.abs 2007-02-03 08:00:59.000000000 -0800
+++ bfd/elf32-i386.c 2007-02-03 08:01:21.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;
}
--- bfd/elf32-ppc.c.abs 2007-02-01 12:42:10.000000000 -0800
+++ bfd/elf32-ppc.c 2007-02-03 08:10:50.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;
}
--- bfd/elf32-s390.c.abs 2006-11-02 19:36:07.000000000 -0800
+++ bfd/elf32-s390.c 2007-02-03 08:11:41.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;
}
--- bfd/elf32-sh.c.abs 2006-11-02 19:36:07.000000000 -0800
+++ bfd/elf32-sh.c 2007-02-03 08:14:46.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;
}
--- bfd/elf32-xtensa.c.abs 2007-02-03 08:00:52.000000000 -0800
+++ bfd/elf32-xtensa.c 2007-02-03 08:15:29.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;
}
--- bfd/elf64-ppc.c.abs 2007-02-01 12:42:10.000000000 -0800
+++ bfd/elf64-ppc.c 2007-02-03 08:16:34.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;
--- bfd/elf64-s390.c.abs 2006-11-02 19:36:09.000000000 -0800
+++ bfd/elf64-s390.c 2007-02-03 08:19:22.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;
}
--- bfd/elf64-x86-64.c.abs 2007-02-03 08:00:59.000000000 -0800
+++ bfd/elf64-x86-64.c 2007-02-03 08:20:27.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;
}
--- bfd/elflink.c.abs 2007-02-03 08:00:59.000000000 -0800
+++ bfd/elflink.c 2007-02-03 08:01:21.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;
}
}
--- bfd/elfxx-ia64.c.abs 2007-02-03 08:00:59.000000000 -0800
+++ bfd/elfxx-ia64.c 2007-02-03 08:26:47.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);
--- bfd/elfxx-mips.c.abs 2007-01-30 07:59:53.000000000 -0800
+++ bfd/elfxx-mips.c 2007-02-03 08:31:00.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)
--- bfd/elfxx-sparc.c.abs 2006-11-02 19:36:09.000000000 -0800
+++ bfd/elfxx-sparc.c 2007-02-03 08:24:39.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;
}