This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Add --only-keep-debug switch to strip/objcopy
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Thu, 26 Jun 2003 08:59:38 +0100
- Subject: Add --only-keep-debug switch to strip/objcopy
Hi Guys,
I am checking in my patch to add the --only-keep-debug switch. The
debug info sections that it creates are mostly working with gdb
now, although these does appear to be an issue with minisymbols
which we are currently investigating. I did not want the patch to
go stale however, so here it is.
Cheers
Nick
2003-06-26 Nick Clifton <nickc@redhat.com>
* objcopy (enum strip_action): Add STRIP_NONDEBUG.
(OPTION_ONLY_KEEP_DEBUG): New.
(strip_options): Add --only-keep-debug.
(copy_options): Likewise.
(is_strip_section): Invert return value if STRIP_NONDEBUG is
active.
(copy_object): Do not copy private data when STRIP_NONDEBUG is
active.
(setup_section): Likewise.
(strip_main): Handle --only-keep-debug.
(copy_main): Likewise.
* NEWS: Mention new switch
* doc/binutils.texi: Document new switch.
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.49
diff -c -3 -p -r1.49 objcopy.c
*** binutils/objcopy.c 12 Jun 2003 07:23:31 -0000 1.49
--- binutils/objcopy.c 26 Jun 2003 07:54:17 -0000
*************** enum strip_action
*** 132,137 ****
--- 132,138 ----
STRIP_NONE, /* don't strip */
STRIP_DEBUG, /* strip all debugger symbols */
STRIP_UNNEEDED, /* strip unnecessary symbols */
+ STRIP_NONDEBUG, /* Strip everything but debug info. */
STRIP_ALL /* strip all symbols */
};
*************** static char *prefix_alloc_sections_strin
*** 284,289 ****
--- 285,291 ----
#define OPTION_PREFIX_ALLOC_SECTIONS (OPTION_PREFIX_SECTIONS + 1)
#define OPTION_FORMATS_INFO (OPTION_PREFIX_ALLOC_SECTIONS + 1)
#define OPTION_ADD_GNU_DEBUGLINK (OPTION_FORMATS_INFO + 1)
+ #define OPTION_ONLY_KEEP_DEBUG (OPTION_ADD_GNU_DEBUGLINK + 1)
/* Options to handle if running as "strip". */
*************** static struct option strip_options[] =
*** 297,302 ****
--- 299,305 ----
{"input-format", required_argument, 0, 'I'}, /* Obsolete */
{"input-target", required_argument, 0, 'I'},
{"keep-symbol", required_argument, 0, 'K'},
+ {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG},
{"output-format", required_argument, 0, 'O'}, /* Obsolete */
{"output-target", required_argument, 0, 'O'},
{"output-file", required_argument, 0, 'o'},
*************** static struct option copy_options[] =
*** 350,355 ****
--- 353,359 ----
{"localize-symbols", required_argument, 0, OPTION_LOCALIZE_SYMBOLS},
{"no-adjust-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS},
{"no-change-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS},
+ {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG},
{"only-section", required_argument, 0, 'j'},
{"output-format", required_argument, 0, 'O'}, /* Obsolete */
{"output-target", required_argument, 0, 'O'},
*************** is_strip_section (abfd, sec)
*** 781,789 ****
|| discard_locals == LOCALS_ALL
|| convert_debugging)
return TRUE;
}
! return FALSE;
}
/* Choose which symbol entries to copy; put the result in OSYMS.
--- 785,796 ----
|| discard_locals == LOCALS_ALL
|| convert_debugging)
return TRUE;
+
+ if (strip_symbols == STRIP_NONDEBUG)
+ return FALSE;
}
! return strip_symbols == STRIP_NONDEBUG ? TRUE : FALSE;
}
/* Choose which symbol entries to copy; put the result in OSYMS.
*************** copy_object (ibfd, obfd)
*** 1346,1351 ****
--- 1353,1359 ----
if (strip_symbols == STRIP_DEBUG
|| strip_symbols == STRIP_ALL
|| strip_symbols == STRIP_UNNEEDED
+ || strip_symbols == STRIP_NONDEBUG
|| discard_locals != LOCALS_UNDEF
|| strip_specific_list != NULL
|| keep_specific_list != NULL
*************** copy_object (ibfd, obfd)
*** 1451,1457 ****
from the input BFD to the output BFD. This is done last to
permit the routine to look at the filtered symbol table, which is
important for the ECOFF code at least. */
! if (! bfd_copy_private_bfd_data (ibfd, obfd))
{
non_fatal (_("%s: error copying private BFD data: %s"),
bfd_get_filename (obfd),
--- 1459,1470 ----
from the input BFD to the output BFD. This is done last to
permit the routine to look at the filtered symbol table, which is
important for the ECOFF code at least. */
! if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour
! && strip_symbols == STRIP_NONDEBUG)
! /* Do not copy the private data when creating an ELF format
! debug info file. We do not want the program headers. */
! ;
! else if (! bfd_copy_private_bfd_data (ibfd, obfd))
{
non_fatal (_("%s: error copying private BFD data: %s"),
bfd_get_filename (obfd),
*************** setup_section (ibfd, isection, obfdarg)
*** 1879,1885 ****
/* Allow the BFD backend to copy any private data it understands
from the input section to the output section. */
! if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
{
err = _("private data");
goto loser;
--- 1892,1903 ----
/* Allow the BFD backend to copy any private data it understands
from the input section to the output section. */
! if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour
! && strip_symbols == STRIP_NONDEBUG)
! /* Do not copy the private data when creating an ELF format
! debug info file. We do not want the program headers. */
! ;
! else if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
{
err = _("private data");
goto loser;
*************** strip_main (argc, argv)
*** 2262,2267 ****
--- 2280,2288 ----
case OPTION_FORMATS_INFO:
formats_info = TRUE;
break;
+ case OPTION_ONLY_KEEP_DEBUG:
+ strip_symbols = STRIP_NONDEBUG;
+ break;
case 0:
/* We've been given a long option. */
break;
*************** copy_main (argc, argv)
*** 2413,2418 ****
--- 2434,2443 ----
case OPTION_STRIP_UNNEEDED:
strip_symbols = STRIP_UNNEEDED;
+ break;
+
+ case OPTION_ONLY_KEEP_DEBUG:
+ strip_symbols = STRIP_NONDEBUG;
break;
case OPTION_ADD_GNU_DEBUGLINK:
Index: binutils/NEWS
===================================================================
RCS file: /cvs/src/src/binutils/NEWS,v
retrieving revision 1.36
diff -c -3 -p -r1.36 NEWS
*** binutils/NEWS 25 Jun 2003 06:40:25 -0000 1.36
--- binutils/NEWS 26 Jun 2003 07:54:14 -0000
***************
*** 1,5 ****
--- 1,11 ----
-*- text -*-
+ * objcopy and strip now accept --only-keep-debug to create a file containing
+ those sections that would be stripped out by --strip-debug. The idea is that
+ this can be used in conjunction with the --add-gnu-debuglink switch to create
+ a two part program distribution - one a stripped executable and the other the
+ debugging info.
+
* objcopy now accepts --add-gnu-debuglink=<file> to insert a .gnu_debuglink
section into a (presumably stripped) executable. This allows the debug
information for the file to be held in a seperate file.
Index: binutils/doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.41
diff -c -3 -p -r1.41 binutils.texi
*** binutils/doc/binutils.texi 12 Jun 2003 07:23:31 -0000 1.41
--- binutils/doc/binutils.texi 26 Jun 2003 07:54:21 -0000
*************** objcopy [@option{-F} @var{bfdname}|@opti
*** 934,940 ****
[@option{-B} @var{bfdarch}|@option{--binary-architecture=}@var{bfdarch}]
[@option{-S}|@option{--strip-all}]
[@option{-g}|@option{--strip-debug}]
- [@option{--add-gnu-debuglink=}@var{path-to-file}]
[@option{-K} @var{symbolname}|@option{--keep-symbol=}@var{symbolname}]
[@option{-N} @var{symbolname}|@option{--strip-symbol=}@var{symbolname}]
[@option{-G} @var{symbolname}|@option{--keep-global-symbol=}@var{symbolname}]
--- 934,939 ----
*************** objcopy [@option{-F} @var{bfdname}|@opti
*** 974,979 ****
--- 973,980 ----
[@option{--prefix-symbols=}@var{string}]
[@option{--prefix-sections=}@var{string}]
[@option{--prefix-alloc-sections=}@var{string}]
+ [@option{--add-gnu-debuglink=}@var{path-to-file}]
+ [@option{--only-keep-debug}]
[@option{-v}|@option{--verbose}]
[@option{-V}|@option{--version}]
[@option{--help}] [@option{--info}]
*************** Do not copy debugging symbols or section
*** 1079,1088 ****
@item --strip-unneeded
Strip all symbols that are not needed for relocation processing.
- @item --add-gnu-debuglink=@var{path-to-file}
- Creates a .gnu_debuglink section which contains a reference to @var{path-to-file}
- and adds it to the output file.
-
@item -K @var{symbolname}
@itemx --keep-symbol=@var{symbolname}
Copy only symbol @var{symbolname} from the source file. This option may
--- 1080,1085 ----
*************** Prefix all section names in the output f
*** 1353,1358 ****
--- 1350,1396 ----
Prefix all the names of all allocated sections in the output file with
@var{string}.
+ @item --add-gnu-debuglink=@var{path-to-file}
+ Creates a .gnu_debuglink section which contains a reference to @var{path-to-file}
+ and adds it to the output file.
+
+ @item --only-keep-debug
+ Strip a file, removing any sections that would be stripped by
+ @option{--strip-debug} and leaving the debugging sections.
+
+ The intention is that this option will be used in conjunction with
+ @option{--add-gnu-debuglink} to create a two part executable. One a
+ stripped binary which will occupy less space in RAM and in a
+ distribution and the second a debugging information file which is only
+ needed if debugging abilities are required. The suggested procedure
+ to create these files is as follows:
+
+ @enumerate
+ @item Link the executable as normal. Assuming that is is called
+ @code{foo} then...
+ @item Run @code{objcopy --only-keep-debug foo foo.dbg} to
+ create a file containing the debugging info.
+ @item Run @code{objcopy --strip-debug foo} to create a
+ stripped executable.
+ @item Run @code{objcopy --add-gnu-debuglink=foo.dbg foo}
+ to add a link to the debugging info into the stripped executable.
+ @end enumerate
+
+ Note - the choice of @code{.dbg} as an extension for the debug info
+ file is arbitrary. Also the @code{--only-keep-debug} step is
+ optional. You could instead do this:
+
+ @enumerate
+ @item Link the executable as normal.
+ @item Copy @code{foo} to @code{foo.full}
+ @item Run @code{objcopy --strip-debug foo}
+ @item Run @code{objcopy --add-gnu-debuglink=foo.full foo}
+ @end enumerate
+
+ ie the file pointed to by the @option{--add-gnu-debuglink} can be the
+ full executable. It does not have to be a file created by the
+ @option{--only-keep-debug} switch.
+
@item -V
@itemx --version
Show the version number of @command{objcopy}.
*************** strip [@option{-F} @var{bfdname} |@optio
*** 2073,2078 ****
--- 2111,2117 ----
[@option{-x}|@option{--discard-all}] [@option{-X} |@option{--discard-locals}]
[@option{-R} @var{sectionname} |@option{--remove-section=}@var{sectionname}]
[@option{-o} @var{file}] [@option{-p}|@option{--preserve-dates}]
+ [@option{--only-keep-debug}]
[@option{-v} |@option{--verbose}] [@option{-V}|@option{--version}]
[@option{--help}] [@option{--info}]
@var{objfile}@dots{}
*************** Remove non-global symbols.
*** 2163,2168 ****
--- 2202,2244 ----
@itemx --discard-locals
Remove compiler-generated local symbols.
(These usually start with @samp{L} or @samp{.}.)
+
+ @item --only-keep-debug
+ Strip a file, removing any sections that would be stripped by
+ @option{--strip-debug} and leaving the debugging sections.
+
+ The intention is that this option will be used in conjunction with
+ @option{--add-gnu-debuglink} to create a two part executable. One a
+ stripped binary which will occupy less space in RAM and in a
+ distribution and the second a debugging information file which is only
+ needed if debugging abilities are required. The suggested procedure
+ to create these files is as follows:
+
+ @enumerate
+ @item Link the executable as normal. Assuming that is is called
+ @code{foo} then...
+ @item Run @code{objcopy --only-keep-debug foo foo.dbg} to
+ create a file containing the debugging info.
+ @item Run @code{objcopy --strip-debug foo} to create a
+ stripped executable.
+ @item Run @code{objcopy --add-gnu-debuglink=foo.dbg foo}
+ to add a link to the debugging info into the stripped executable.
+ @end enumerate
+
+ Note - the choice of @code{.dbg} as an extension for the debug info
+ file is arbitrary. Also the @code{--only-keep-debug} step is
+ optional. You could instead do this:
+
+ @enumerate
+ @item Link the executable as normal.
+ @item Copy @code{foo} to @code{foo.full}
+ @item Run @code{strip --strip-debug foo}
+ @item Run @code{objcopy --add-gnu-debuglink=foo.full foo}
+ @end enumerate
+
+ ie the file pointed to by the @option{--add-gnu-debuglink} can be the
+ full executable. It does not have to be a file created by the
+ @option{--only-keep-debug} switch.
@item -V
@itemx --version