This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: Warning relocs against discarded functions
- To: Keith Owens <kaos at melbourne dot sgi dot com>
- Subject: Re: PATCH: Warning relocs against discarded functions
- From: "H . J . Lu" <hjl at lucon dot org>
- Date: Fri, 2 Nov 2001 00:37:06 -0800
- Cc: Daniel Jacobowitz <dan at debian dot org>, gdb at sources dot redhat dot com,binutils at sourceware dot cygnus dot com
- References: <20011101142835.A24773@lucon.org> <2849.1004661814@kao2.melbourne.sgi.com>
On Fri, Nov 02, 2001 at 11:43:34AM +1100, Keith Owens wrote:
> On Thu, 1 Nov 2001 14:28:35 -0800,
> "H . J . Lu" <hjl@lucon.org> wrote:
> >On Thu, Nov 01, 2001 at 11:43:10PM +1100, Keith Owens wrote:
> >> The problem is worse than stabs. If a function is marked __exit _and_
> >> some code in another section refers to that function then :-
> >How about this patch?
>
> No go. I patched ld from cygnus CVS, about 2 hours old.
>
Try this one. I didn't bother with weak references. I am not sure if
it will work with stabs.
H.J.
----
2001-11-02 H.J. Lu (hjl@gnu.org)
* elflink.h (elf_link_input_bfd): Complain relocs against
discarded sections.
Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.88
diff -u -p -r1.88 elflink.h
--- elflink.h 2001/10/31 21:30:43 1.88
+++ elflink.h 2001/11/02 08:26:38
@@ -6079,6 +6079,7 @@ elf_link_input_bfd (finfo, input_bfd)
asection *o;
struct elf_backend_data *bed;
boolean emit_relocs;
+ struct elf_link_hash_entry **sym_hashes;
output_bfd = finfo->output_bfd;
bed = get_elf_backend_data (output_bfd);
@@ -6251,6 +6252,7 @@ elf_link_input_bfd (finfo, input_bfd)
}
/* Relocate the contents of each section. */
+ sym_hashes = elf_sym_hashes (input_bfd);
for (o = input_bfd->sections; o != NULL; o = o->next)
{
bfd_byte *contents;
@@ -6298,50 +6300,113 @@ elf_link_input_bfd (finfo, input_bfd)
&& o->reloc_count > 0)
return false;
-#if BFD_VERSION_DATE < 20031005
{
Elf_Internal_Rela *rel, *relend;
- /* Run through the relocs looking for any against section
- symbols from removed link-once sections. Zero any such
- relocs. We should really complain if anything in the
- final link tries to use it, but DWARF-based exception
- handling might have an entry in .eh_frame to describe a
- routine in the linkonce section, and it turns out to be
- hard to remove the .eh_frame entry too. FIXME. */
+ /* Run through the relocs looking for any against symbols
+ from discarded sections and section symbols from
+ removed link-once sections. Complain about relocs
+ against discarded sections. Zero relocs against removed
+ link-once sections. We should really complain if
+ anything in the final link tries to use it, but
+ DWARF-based exception handling might have an entry in
+ .eh_frame to describe a routine in the linkonce section,
+ and it turns out to be hard to remove the .eh_frame
+ entry too. FIXME. */
rel = internal_relocs;
relend = rel + o->reloc_count * bed->s->int_rels_per_ext_rel;
for ( ; rel < relend; rel++)
{
unsigned long r_symndx = ELF_R_SYM (rel->r_info);
- if (r_symndx < locsymcount
- && (!elf_bad_symtab (input_bfd)
- || finfo->sections[r_symndx] != NULL))
+ if (r_symndx >= locsymcount
+ || (elf_bad_symtab (input_bfd)
+ && finfo->sections[r_symndx] == NULL))
{
+ struct elf_link_hash_entry *h;
+
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ /* Complain if the definition comes from a
+ discarded section. */
+ if ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && h->root.u.def.section->output_section
+ == bfd_abs_section_ptr)
+ {
+#if BFD_VERSION_DATE < 20031005
+ if ((o->flags & SEC_DEBUGGING) != 0)
+ {
+#if BFD_VERSION_DATE > 20021005
+ (*finfo->info->callbacks->warning)
+ (finfo->info,
+ _("warning: relocation against removed section; zeroing"),
+ NULL, input_bfd, o, rel->r_offset);
+#endif
+ memset (rel, 0, sizeof (*rel));
+ }
+ else
+#endif
+ {
+ if (! ((*finfo->info->callbacks->undefined_symbol)
+ (finfo->info, h->root.root.string,
+ input_bfd, o, rel->r_offset,
+ true)))
+ return false;
+ }
+ }
+ }
+ else
+ {
isym = finfo->internal_syms + r_symndx;
if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
{
asection *sec = finfo->sections[r_symndx];
if (sec != NULL
- && (sec->flags & SEC_LINK_ONCE) != 0
&& bfd_is_abs_section (sec->output_section))
{
+#if BFD_VERSION_DATE < 20031005
+ if ((o->flags & SEC_DEBUGGING) != 0
+ || (sec->flags & SEC_LINK_ONCE) != 0)
+ {
#if BFD_VERSION_DATE > 20021005
- (*finfo->info->callbacks->warning)
- (finfo->info,
- _("warning: relocation against removed section; zeroing"),
- NULL, input_bfd, o, rel->r_offset);
+ (*finfo->info->callbacks->warning)
+ (finfo->info,
+ _("warning: relocation against removed section; zeroing"),
+ NULL, input_bfd, o, rel->r_offset);
#endif
- memset (rel, 0, sizeof (*rel));
+ memset (rel, 0, sizeof (*rel));
+ }
+ else
+#endif
+ {
+#define SECTION_MESSAGE "symbols in discarded section"
+ boolean ok;
+ char *buf
+ = (char *) bfd_malloc
+ (strlen (sec->name) + 3
+ + sizeof ( SECTION_MESSAGE));
+ if (buf != NULL)
+ sprintf (buf, "%s: %s",
+ SECTION_MESSAGE, sec->name);
+ else
+ buf = (char *) sec->name;
+ ok = (*finfo->info->callbacks->undefined_symbol)
+ (finfo->info, buf,
+ input_bfd, o, rel->r_offset,
+ true);
+ if (buf != sec->name)
+ free (buf);
+ if (!ok)
+ return false;
+ }
}
}
}
}
}
-#else
-#error "gcc should be fixed by now, and this kludge no longer needed"
-#endif
/* Relocate the section by invoking a back end routine.