This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA:] Ignore --gc-sections if non-ELF objects are involved


> Date: Tue, 26 Mar 2002 22:24:26 +1030
> From: Alan Modra <amodra@bigpond.net.au>

>  The non-ELF
> sections won't be dropped, but relocs referencing ELF sections
> from the non-ELF BFD won't stop ELF sections from being dropped.
> So that could be dangerous.

Yes.  And not worth doing GC in that situation IMHO.

>  A more typical case might be ELF
> + a binary input BFD.  That shouldn't stop GC operating correctly.

I see.  Always that dreaded binary input. 8-}

> I'm applying the following,

FWIW, your patch was my first abandoned, approach.  Then I
started thinking that it was better to stop the any-non-ELF-case
at the *top level*, because it wasn't worth doing, and too error
prone with regards to future changes.  Lot's of
bfd_target_elf_flavour tests could go too.  But I think I'm
repeating myself.

I thought I saw some all-ELF assumptions in the
elf_link_hash_traverse-functions called from elf_gc_sections,
but I see those are actually always ELF (since that's what's
produced).

> and I think a variation of your patch
> that warns on finding non-ELF input BFDs _with relocs_, but doesn't
> stop GC, is the best solution.

I'm hesitant to warn and still proceed in that situation; it's
almost certain to fail.  Would you accept warning and ignoring
GC in that case, like this?

	* elflink.h (elf_gc_sections): Check that all input objects with
	relocations 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 13:37:24
*************** elf_gc_sections (abfd, info)
*** 7807,7812 ****
--- 7811,7839 ----
    if (!get_elf_backend_data (abfd)->can_gc_sections
        || info->relocateable || info->emitrelocations
        || elf_hash_table (info)->dynamic_sections_created)
+     return true;
+ 
+   /* Check that we're dealing only with ELF files if there are
+      relocations, so we don't have to remember to check for that
+      when marking them and treat them specially to avoid sweeping
+      sections referred to by non-ELF input.  */
+   for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+     if (bfd_get_flavour (sub) != bfd_target_elf_flavour
+ 	&& (bfd_get_file_flags (sub) & HAS_RELOC) != 0)
+       {
+ 	if (ok)
+ 	  (*_bfd_error_handler)
+ 	    (_("%s: warning: garbage collection not performed due to\
+  non-ELF input with relocations:"),
+ 	     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.  */


brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]