This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
--emit-reloc and SEC_MERGE
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Tue, 4 May 2004 00:20:57 +0930
- Subject: --emit-reloc and SEC_MERGE
Some of the folks at http://www.haifa.il.ibm.com/projects/systems/cot/fdpr/
found that --emit-relocs was producing bogus relocs in some cases. The
relocs in question were those against symbols in SEC_MERGE sections.
This patch should fix a similar problem with --emit-relocs and link-once
sections too.
* elf.c (_bfd_elf_rela_local_sym): Set kept_section for excluded
SEC_MERGE sections.
* elflink.c (elf_link_input_bfd): Adjust output reloc index for
those against discarded link-once and SEC_MERGE section symbols.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.224
diff -u -p -r1.224 elf.c
--- bfd/elf.c 30 Apr 2004 15:04:30 -0000 1.224
+++ bfd/elf.c 3 May 2004 13:34:33 -0000
@@ -7478,7 +7478,17 @@ _bfd_elf_rela_local_sym (bfd *abfd,
elf_section_data (sec)->sec_info,
sym->st_value + rel->r_addend,
0);
- sec = *psec;
+ if (sec != *psec)
+ {
+ /* If we have changed the section, and our original section is
+ marked with SEC_EXCLUDE, it means that the original
+ SEC_MERGE section has been completely subsumed in some
+ other SEC_MERGE section. In this case, we need to leave
+ some info around for --emit-relocs. */
+ if ((sec->flags & SEC_EXCLUDE) != 0)
+ sec->kept_section = *psec;
+ sec = *psec;
+ }
rel->r_addend -= relocation;
rel->r_addend += sec->output_section->vma + sec->output_offset;
}
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.67
diff -u -p -r1.67 elflink.c
--- bfd/elflink.c 30 Apr 2004 08:48:55 -0000 1.67
+++ bfd/elflink.c 3 May 2004 14:46:05 -0000
@@ -6763,13 +6763,10 @@ elf_link_input_bfd (struct elf_final_lin
{
/* I suppose the backend ought to fill in the
section of any STT_SECTION symbol against a
- processor specific section. If we have
- discarded a section, the output_section will
- be the absolute section. */
- if (bfd_is_abs_section (sec)
- || (sec != NULL
- && bfd_is_abs_section (sec->output_section)))
- r_symndx = 0;
+ processor specific section. */
+ r_symndx = 0;
+ if (bfd_is_abs_section (sec))
+ ;
else if (sec == NULL || sec->owner == NULL)
{
bfd_set_error (bfd_error_bad_value);
@@ -6777,8 +6774,25 @@ elf_link_input_bfd (struct elf_final_lin
}
else
{
- r_symndx = sec->output_section->target_index;
- BFD_ASSERT (r_symndx != 0);
+ asection *osec = sec->output_section;
+
+ /* If we have discarded a section, the output
+ section will be the absolute section. In
+ case of discarded link-once and discarded
+ SEC_MERGE sections, use the kept section. */
+ if (bfd_is_abs_section (osec)
+ && sec->kept_section != NULL
+ && sec->kept_section->output_section != NULL)
+ {
+ osec = sec->kept_section->output_section;
+ irela->r_addend -= osec->vma;
+ }
+
+ if (!bfd_is_abs_section (osec))
+ {
+ r_symndx = osec->target_index;
+ BFD_ASSERT (r_symndx != 0);
+ }
}
/* Adjust the addend according to where the
--
Alan Modra
IBM OzLabs - Linux Technology Centre