[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#219459: NPTL breaks abort()



On Sat, Jan 24, 2004 at 01:57:01PM -0500, Daniel Jacobowitz wrote:
> Whee!  With a little help from CVS binutils, I got the third option to
> work; and it works _beautifully_.  Unfortunately it does not work using
> the binutils from unstable.  James, I -think- that the patches needed
> will be confined to binutils/objcopy.c and thus not impact the
> assembler/linker; if I'm right, do you think this is doable for sarge?

I'm still testing, but here's the binutils patch.  I snuck in a fix for
another little bug that really annoys me :)

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer
#!/bin/sh -e
## 109_objcopy_keep_debug.dpatch
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Description: objcopy --only-keep-debug and readelf SHT_NOBITS fixes
## DP: Author: Jakub Jelinek, Nick Clifton, Marshall T. Vandegrift
## DP: Upstream status: Committed to trunk
## DP: Date: 2004-01-24

if [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch}"

case "$1" in
       -patch) patch $patch_opts -p1 < $0;;
       -unpatch) patch $patch_opts -p1 -R < $0;;
        *)
                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
                exit 1;;
esac

exit 0

@DPATCH@
2004-01-12  Jakub Jelinek  <jakub@redhat.com>

	* objcopy.c: Include elf-bfd.h.
	(is_strip_section): Don't strip debugging sections if
	STRIP_NONDEBUG.
	(setup_section): If STRIP_NONDEBUG make SEC_ALLOC sections
	~(SEC_LOAD | SEC_HAS_CONTENTS) and on ELF targets also SHT_NOBITS.

	* objcopy.c (copy_section): Free relpp if relcount == 0.

2003-12-11  Nick Clifton  <nickc@redhat.com>

	* objcopy.c (strip_usage): Add --only-keep-debug.
	(copy_usage): Likewise.

2003-10-30  Marshall T. Vandegrift  <llasram@wuli.nu>

	* readelf.c (dump_section): Do not dump the contents of SHT_NOBITS
	sections - they have no file space assigned to their contents.

diff -ur src/binutils.orig/objcopy.c src/binutils/objcopy.c
--- src/binutils.orig/objcopy.c	2003-10-29 12:37:48.000000000 -0500
+++ src/binutils/objcopy.c	2004-01-24 14:13:58.000000000 -0500
@@ -27,6 +27,7 @@
 #include "libiberty.h"
 #include "budbg.h"
 #include "filenames.h"
+#include "elf-bfd.h"
 #include <sys/stat.h>
 
 /* A list of symbols to explicitly strip out, or to keep.  A linked
@@ -385,6 +386,7 @@
   -g --strip-debug                 Remove all debugging symbols & sections\n\
      --strip-unneeded              Remove all symbols not needed by relocations\n\
   -N --strip-symbol <name>         Do not copy symbol <name>\n\
+     --only-keep-debug             Strip everything but the debug information\n\
   -K --keep-symbol <name>          Only copy symbol <name>\n\
   -L --localize-symbol <name>      Force symbol <name> to be marked as a local\n\
   -G --keep-global-symbol <name>   Localize all symbols except <name>\n\
@@ -457,6 +459,7 @@
   -s --strip-all                   Remove all symbol and relocation information\n\
   -g -S -d --strip-debug           Remove all debugging symbols & sections\n\
      --strip-unneeded              Remove all symbols not needed by relocations\n\
+     --only-keep-debug             Strip everything but the debug information\n\
   -N --strip-symbol=<name>         Do not copy symbol <name>\n\
   -K --keep-symbol=<name>          Only copy symbol <name>\n\
   -x --discard-all                 Remove all non-global symbols\n\
@@ -734,7 +737,7 @@
 	return FALSE;
     }
 
-  return strip_symbols == STRIP_NONDEBUG ? TRUE : FALSE;
+  return FALSE;
 }
 
 /* Choose which symbol entries to copy; put the result in OSYMS.
@@ -1806,6 +1809,13 @@
 
   if (p != NULL && p->set_flags)
     flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
+  else if (strip_symbols == STRIP_NONDEBUG && (flags & SEC_ALLOC) != 0)
+    {
+      flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD);
+      if (obfd->xvec->flavour == bfd_target_elf_flavour)
+	elf_section_type (osection) = SHT_NOBITS;
+    }
+
   if (!bfd_set_section_flags (obfd, osection, flags))
     {
       err = _("flags");
@@ -1926,6 +1936,8 @@
 	}
 
       bfd_set_reloc (obfd, osection, relcount == 0 ? NULL : relpp, relcount);
+      if (relcount == 0)
+	free (relpp);
     }
 
   isection->_cooked_size = isection->_raw_size;
diff -ur src/binutils.orig/readelf.c src/binutils/readelf.c
--- src/binutils.orig/readelf.c	2003-10-29 12:37:48.000000000 -0500
+++ src/binutils/readelf.c	2004-01-24 14:13:45.000000000 -0500
@@ -6055,7 +6055,7 @@
 
   bytes = section->sh_size;
 
-  if (bytes == 0)
+  if (bytes == 0 || section->sh_type == SHT_NOBITS)
     {
       printf (_("\nSection '%s' has no data to dump.\n"),
 	      SECTION_NAME (section));

Reply to: