This is the mail archive of the binutils@sourceware.cygnus.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]

Re: strip --strip-unneeded?


On Fri, May 12, 2000 at 09:20:17PM -0700, Ian Lance Taylor wrote:
> 
> I think I agree.  strip --strip-unneeded is meaningful on a
> relocateable file.  It should remove only BSF_LOCAL symbols which are
> not referenced by any relocations.
> 
> A relocateable file is one with HAS_RELOC set, and neither EXEC_P nor
> DYNAMIC set.  However, I don't know whether are all BFD backends are
> fully reliable about setting EXEC_P and DYNAMIC.
> 

How about this patch? I can restrict it to ELF objects.

Thanks.


H.J.
----
2000-05-12  H.J. Lu  (hjl@gnu.org)

	* objcopy.c (filter_symbols): Don't strip global symbols in
	relocatable object files.

Index: objcopy.c
===================================================================
RCS file: /work/cvs/gnu/binutils/binutils/objcopy.c,v
retrieving revision 1.10
diff -u -p -r1.10 objcopy.c
--- objcopy.c	2000/05/12 15:11:30	1.10
+++ objcopy.c	2000/05/13 06:31:10
@@ -556,7 +556,12 @@ filter_symbols (abfd, obfd, osyms, isyms
 {
   register asymbol **from = isyms, **to = osyms;
   long src_count = 0, dst_count = 0;
+  int relocatable;
 
+  relocatable = bfd_get_format (abfd) == bfd_object
+		&& (abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC))
+		   == HAS_RELOC;
+
   for (; src_count < symcount; src_count++)
     {
       asymbol *sym = from[src_count];
@@ -609,6 +614,9 @@ filter_symbols (abfd, obfd, osyms, isyms
 	       || ((flags & BSF_SECTION_SYM) != 0
 		   && ((*bfd_get_section (sym)->symbol_ptr_ptr)->flags
 		       & BSF_KEEP) != 0))
+	keep = 1;
+      else if (relocatable			/* Relocatable file. */
+	       && (flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
 	keep = 1;
       else if ((flags & BSF_GLOBAL) != 0	/* Global symbol.  */
 	       || (flags & BSF_WEAK) != 0

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