public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] don't strip symbols involved in relocations
@ 2007-04-23 15:31 Nathan Froyd
  2007-04-23 16:11 ` H. J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Froyd @ 2007-04-23 15:31 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

The attached patch adds a safety check when stripping a symbol specified
on the command line: if the symbol is involved in a relocation, it
should not be stripped.

Tested on i586-none-vxworks.

OK?

-Nathan

binutils/
2007-04-23  Nathan Froyd  <froydnj@codesourcery.com>
	    Phil Edwards  <phil@codesourcery.com>

	* objcopy.c (filter_symbols): Explicitly stripping a symbol
	used in relocations is an error.

binutils/testsuite/
2007-04-23  Nathan Froyd  <froydnj@codesourcery.com>
	    Phil Edwards  <phil@codesourcery.com>

	* binutils-all/objcopy.exp: Add test for stripping a symbol
	used in a relocation.

[-- Attachment #2: dont-strip.patch --]
[-- Type: text/plain, Size: 3386 bytes --]

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.107
diff -u -p -r1.107 objcopy.c
--- binutils/objcopy.c	12 Apr 2007 19:20:46 -0000	1.107
+++ binutils/objcopy.c	23 Apr 2007 15:03:08 -0000
@@ -910,6 +910,7 @@ filter_symbols (bfd *abfd, bfd *obfd, as
       flagword flags = sym->flags;
       char *name = (char *) bfd_asymbol_name (sym);
       int keep;
+      int used_in_reloc = 0;
       bfd_boolean undefined;
       bfd_boolean rem_leading_char;
       bfd_boolean add_leading_char;
@@ -982,7 +983,10 @@ filter_symbols (bfd *abfd, bfd *obfd, as
 	       || ((flags & BSF_SECTION_SYM) != 0
 		   && ((*bfd_get_section (sym)->symbol_ptr_ptr)->flags
 		       & BSF_KEEP) != 0))
-	keep = 1;
+	{
+	  keep = 1;
+	  used_in_reloc = 1;
+	}
       else if (relocatable			/* Relocatable file.  */
 	       && (flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
 	keep = 1;
@@ -1012,7 +1016,18 @@ filter_symbols (bfd *abfd, bfd *obfd, as
 			|| ! bfd_is_local_label (abfd, sym))));
 
       if (keep && is_specified_symbol (name, strip_specific_list))
-	keep = 0;
+	{
+	  /* There are multiple ways to set 'keep' above, but if it was
+	     the relocatable symbol case, then that's an error.  */
+	  if (used_in_reloc)
+	    {
+	      non_fatal (_("not stripping symbol `%s' because it is named in a relocation"), name);
+	      status = 1;
+	      keep = 1;
+	    }
+	  else
+	    keep = 0;
+	}
       if (keep
 	  && !(flags & BSF_KEEP)
 	  && is_specified_symbol (name, strip_unneeded_list))
Index: binutils/testsuite/binutils-all/needed-reloc.s
===================================================================
RCS file: binutils/testsuite/binutils-all/needed-reloc.s
diff -N binutils/testsuite/binutils-all/needed-reloc.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ binutils/testsuite/binutils-all/needed-reloc.s	23 Apr 2007 15:03:08 -0000
@@ -0,0 +1,7 @@
+        .globl foo
+
+	.data
+	.4byte	foo
+        .text
+foo:
+        .long 1
Index: binutils/testsuite/binutils-all/objcopy.exp
===================================================================
RCS file: /cvs/src/src/binutils/testsuite/binutils-all/objcopy.exp,v
retrieving revision 1.41
diff -u -p -r1.41 objcopy.exp
--- binutils/testsuite/binutils-all/objcopy.exp	12 Apr 2007 19:20:46 -0000	1.41
+++ binutils/testsuite/binutils-all/objcopy.exp	23 Apr 2007 15:03:08 -0000
@@ -723,6 +723,27 @@ if { ([istarget "ia64-*-elf*"]
     objcopy_test "ia64 link order" link-order.s
 }
 
+# This test is really only valid on platforms that have the right relocation
+# types for this to matter.  We choose i*86-*-vxworks arbitrarily.
+if { [istarget "i*86-*-vxworks"] } {
+    # Check to make sure we don't strip a symbol named in relocations.
+    set test "objcopy doesn't strip needed symbols"
+
+    set srcfile $srcdir/$subdir/needed-reloc.s
+
+    if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
+        unresolved $test
+    } else {
+        set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -N foo tmpdir/bintest.o ${copyfile}.o"]
+
+        if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
+            pass $test
+        } else {
+            fail $test
+        }
+    }
+}
+
 # ELF specific tests
 if [is_elf_format] {
     objcopy_test "ELF unknown section type" unknown.s

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-24 10:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-23 15:31 [PATCH] don't strip symbols involved in relocations Nathan Froyd
2007-04-23 16:11 ` H. J. Lu
2007-04-23 18:57   ` Nathan Froyd
2007-04-23 23:07     ` H. J. Lu
2007-04-24 13:35     ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).