[RFA:] Ignore --gc-sections if non-ELF objects are involved
Hans-Peter Nilsson
hans-peter.nilsson@axis.com
Tue Mar 26 02:53:00 GMT 2002
> Date: Tue, 26 Mar 2002 11:15:12 +1030
> From: Alan Modra <amodra@bigpond.net.au>
(I hope this answers Catherine's concerns too.)
> On Tue, Mar 26, 2002 at 12:15:50AM +0100, Hans-Peter Nilsson wrote:
> > The test currently SEGV:s.
>
> Why?
Sorry, I thought that was obvious, at least from the test-case.
I see my report was too terse. The test-case links an a.out
object with an ELF object, producing ELF. This works when GC
isn't involved. Right, it's a "don't do that then" but SEGV is
inappropriate anyway. The SEGV:s happens in
elflink.h:elf_gc_mark, on:
group_sec = elf_section_data (sec)->next_in_group;
That's not an ELF section, that's an a.out section. Adding a
bfd_target_elf_flavour test and return true for others would
work, but I thought that wouldn't be a proper solution, since
all-ELF assumptions would probably sneak in elsewhere in GC
eventually. (Actually more bfd_target_elf_flavour tests are
needed for that.)
> > It's better if GC just isn't
> > performed, as happens if !get_elf_backend_data (abfd)->can_gc_sections
> > or info->dynamic_sections_created.
>
> Seems a wee bit heavy-handed. Can't you just stop gc on the non-elf
> object?
You can, but I thought it wasn't worth the trouble. It would
mean adding more bfd_target_elf_flavour checks (at least one for
each elf_link_hash_traverse call). I fear those would rot to
just handle this test-case. Right now ld SEGVs for non-ELF
sections with referred symbols (if you're lucky, produce invalid
output if you're not). So this is an improvement, not a general
setback to suit a corner case AFAICT. Perhaps if there's a
warning for all non-ELF objects? Here's a patch to do that.
(I'll tweak the test-case accordingly.) Making it an error
_would_ be too heavy-handed. It's also a little more involved
than just returning false, and it's not what's done for other
cases anyway:
if (!get_elf_backend_data (abfd)->can_gc_sections
|| info->relocateable || info->emitrelocations
|| elf_hash_table (info)->dynamic_sections_created)
return true;
Is this better, perhaps ok?
2002-03-26 Hans-Peter Nilsson <hp@axis.com>
* elflink.h (elf_gc_sections): Check that all input objects are
ELF, warn and return if not.
Index: elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.152
diff -c -p -r1.152 elflink.h
*** elflink.h 2002/03/19 20:21:54 1.152
--- elflink.h 2002/03/26 10:52:17
*************** elf_gc_sections (abfd, info)
*** 7809,7814 ****
--- 7809,7835 ----
|| elf_hash_table (info)->dynamic_sections_created)
return true;
+ /* Check that we're dealing only with ELF files, so we don't have to
+ remember to check for that everywhere else, and to accommodate not
+ sweeping them. */
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+ if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
+ {
+ if (ok)
+ (*_bfd_error_handler)
+ (_("%s: warning: garbage collection not performed due to\
+ non-ELF input:"),
+ bfd_archive_filename (abfd));
+
+ (*_bfd_error_handler)
+ (_("object format of %s is %s"),
+ bfd_archive_filename (sub), bfd_get_target (sub));
+
+ ok = false;
+ }
+ if (!ok)
+ return true;
+
/* Apply transitive closure to the vtable entry usage info. */
elf_link_hash_traverse (elf_hash_table (info),
elf_gc_propagate_vtable_entries_used,
brgds, H-P
More information about the Binutils
mailing list