--gc-sections ignored warning patch
Grant Edwards
grante@visi.com
Tue Dec 30 17:58:00 GMT 2003
On Tue, Dec 30, 2003 at 11:47:16AM -0500, Ian Lance Taylor wrote:
> Grant Edwards <grante@visi.com> writes:
>
> > I know the docs say the option is simply ignored if it's not
> > supported, but a warning from the linker sure would have saved
> > me a lot of hours trying to figure out what I was doing wrong.
>
> Probably a good idea. The place to patch is elf_gc_sections() in
> bfd/elflink.h.
Here's my first pass at adding warnings when gc-sections is
ignored. I may have gotten a bit carried away. Would people
prefer a single more generic warning message?
--
Grant Edwards
grante@visi.com
-------------- next part --------------
Index: elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.250
diff -U8 -r1.250 elflink.h
--- elflink.h 8 Dec 2003 13:05:10 -0000 1.250
+++ elflink.h 30 Dec 2003 17:31:43 -0000
@@ -5791,22 +5791,36 @@
elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
{
bfd_boolean ok = TRUE;
bfd *sub;
asection * (*gc_mark_hook)
(asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *h, Elf_Internal_Sym *);
- if (!get_elf_backend_data (abfd)->can_gc_sections
- || info->relocatable
- || info->emitrelocations
- || !is_elf_hash_table (info->hash)
- || elf_hash_table (info)->dynamic_sections_created)
- return TRUE;
+ if (!get_elf_backend_data (abfd)->can_gc_sections)
+ {
+ (*_bfd_error_handler)(_("Warning: gc-sections option ignored (not supported by target architecture)."));
+ return TRUE;
+ }
+ if (info->relocatable || info->emitrelocations)
+ {
+ (*_bfd_error_handler)(_("Warning: gc-sections option ignored (only supported for static output)."));
+ return TRUE;
+ }
+ if (!is_elf_hash_table (info->hash))
+ {
+ (*_bfd_error_handler)(_("Warning: gc-sections option ignored (only supported for ELF targets)."));
+ return TRUE;
+ }
+ if (elf_hash_table (info)->dynamic_sections_created)
+ {
+ (*_bfd_error_handler)(_("Warning: gc-sections option ignored (not supported with dynamic libs)."));
+ 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,
&ok);
if (!ok)
return FALSE;
More information about the Binutils
mailing list