* RFC: strip --strip-nondebug
@ 2003-06-05 15:57 Nick Clifton
2003-06-05 16:06 ` Ian Lance Taylor
` (3 more replies)
0 siblings, 4 replies; 20+ messages in thread
From: Nick Clifton @ 2003-06-05 15:57 UTC (permalink / raw)
To: gdb-patches; +Cc: binutils
Hi Guys,
I am seeking comments and criticisms on the attached patch. It adds
a new switch to strip:
--strip-nondebug
This can be used to create an output file which only contains the
debug information from an executable. This would allow stripped
binaries to be shipped with separate debug info files, and provided
that the debugger supported it, they could still be debugged.
The patch is incomplete - it needs a ChangeLog entry as well as
modifications to NEWS and binutils.texi to document the new
functionality, but I will write all of these once/if the patch is
in acceptable state.
Cheers
Nick
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.48
diff -c -3 -p -r1.48 objcopy.c
*** binutils/objcopy.c 2 Jun 2003 14:45:12 -0000 1.48
--- binutils/objcopy.c 5 Jun 2003 15:50:15 -0000
*************** enum strip_action
*** 130,136 ****
STRIP_NONE, /* don't strip */
STRIP_DEBUG, /* strip all debugger symbols */
STRIP_UNNEEDED, /* strip unnecessary symbols */
! STRIP_ALL /* strip all symbols */
};
/* Which symbols to remove. */
--- 130,137 ----
STRIP_NONE, /* don't strip */
STRIP_DEBUG, /* strip all debugger symbols */
STRIP_UNNEEDED, /* strip unnecessary symbols */
! STRIP_ALL, /* strip all symbols */
! STRIP_NONDEBUG /* Strip everything but debug info. */
};
/* Which symbols to remove. */
*************** static char *prefix_alloc_sections_strin
*** 277,282 ****
--- 278,284 ----
#define OPTION_PREFIX_SECTIONS (OPTION_PREFIX_SYMBOLS + 1)
#define OPTION_PREFIX_ALLOC_SECTIONS (OPTION_PREFIX_SECTIONS + 1)
#define OPTION_FORMATS_INFO (OPTION_PREFIX_ALLOC_SECTIONS + 1)
+ #define OPTION_STRIP_NONDEBUG (OPTION_FORMATS_INFO + 1)
/* Options to handle if running as "strip". */
*************** static struct option strip_options[] =
*** 297,302 ****
--- 299,305 ----
{"remove-section", required_argument, 0, 'R'},
{"strip-all", no_argument, 0, 's'},
{"strip-debug", no_argument, 0, 'S'},
+ {"strip-nondebug", no_argument, 0, OPTION_STRIP_NONDEBUG},
{"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED},
{"strip-symbol", required_argument, 0, 'N'},
{"target", required_argument, 0, 'F'},
*************** strip_usage (stream, exit_status)
*** 490,495 ****
--- 493,499 ----
-g -S -d --strip-debug Remove all debugging symbols\n\
--strip-unneeded Remove all symbols not needed by relocations\n\
-N --strip-symbol=<name> Do not copy symbol <name>\n\
+ --strip-nondebug Remove all but the debug info\n\
-K --keep-symbol=<name> Only copy symbol <name>\n\
-x --discard-all Remove all non-global symbols\n\
-X --discard-locals Remove any compiler-generated symbols\n\
*************** is_strip_section (abfd, sec)
*** 752,776 ****
bfd *abfd ATTRIBUTE_UNUSED;
asection *sec;
{
! struct section_list *p;
! if ((bfd_get_section_flags (abfd, sec) & SEC_DEBUGGING) != 0
! && (strip_symbols == STRIP_DEBUG
|| strip_symbols == STRIP_UNNEEDED
|| strip_symbols == STRIP_ALL
|| discard_locals == LOCALS_ALL
! || convert_debugging))
! return TRUE;
! if (! sections_removed && ! sections_copied)
! return FALSE;
! p = find_section_list (bfd_get_section_name (abfd, sec), FALSE);
! if (sections_removed && p != NULL && p->remove)
! return TRUE;
! if (sections_copied && (p == NULL || ! p->copy))
! return TRUE;
! return FALSE;
}
/* Choose which symbol entries to copy; put the result in OSYMS.
--- 756,787 ----
bfd *abfd ATTRIBUTE_UNUSED;
asection *sec;
{
! if (sections_removed || sections_copied)
! {
! struct section_list *p;
!
! p = find_section_list (bfd_get_section_name (abfd, sec), FALSE);
!
! if (sections_removed && p != NULL && p->remove)
! return TRUE;
! if (sections_copied && (p == NULL || ! p->copy))
! return TRUE;
! }
! if ((bfd_get_section_flags (abfd, sec) & SEC_DEBUGGING) != 0)
! {
! if (strip_symbols == STRIP_DEBUG
|| strip_symbols == STRIP_UNNEEDED
|| strip_symbols == STRIP_ALL
|| 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.
*************** filter_symbols (abfd, obfd, osyms, isyms
*** 882,890 ****
|| bfd_is_com_section (bfd_get_section (sym)))
keep = strip_symbols != STRIP_UNNEEDED;
else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
! keep = (strip_symbols != STRIP_DEBUG
! && strip_symbols != STRIP_UNNEEDED
! && ! convert_debugging);
else if (bfd_get_section (sym)->comdat)
/* COMDAT sections store special information in local
symbols, so we cannot risk stripping any of them. */
--- 893,903 ----
|| bfd_is_com_section (bfd_get_section (sym)))
keep = strip_symbols != STRIP_UNNEEDED;
else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
! {
! keep = (strip_symbols != STRIP_DEBUG
! && strip_symbols != STRIP_UNNEEDED
! && ! convert_debugging);
! }
else if (bfd_get_section (sym)->comdat)
/* COMDAT sections store special information in local
symbols, so we cannot risk stripping any of them. */
*************** copy_object (ibfd, obfd)
*** 1329,1334 ****
--- 1342,1348 ----
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)
*** 1434,1440 ****
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),
--- 1448,1459 ----
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),
*************** copy_object (ibfd, obfd)
*** 1442,1448 ****
status = 1;
return;
}
!
/* Switch to the alternate machine code. We have to do this at the
very end, because we only initialize the header when we create
the first section. */
--- 1461,1467 ----
status = 1;
return;
}
!
/* Switch to the alternate machine code. We have to do this at the
very end, because we only initialize the header when we create
the first section. */
*************** setup_section (ibfd, isection, obfdarg)
*** 1761,1783 ****
const char * name;
char *prefix = NULL;
! if ((bfd_get_section_flags (ibfd, isection) & SEC_DEBUGGING) != 0
! && (strip_symbols == STRIP_DEBUG
! || strip_symbols == STRIP_UNNEEDED
! || strip_symbols == STRIP_ALL
! || discard_locals == LOCALS_ALL
! || convert_debugging))
return;
p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
if (p != NULL)
p->used = TRUE;
- if (sections_removed && p != NULL && p->remove)
- return;
- if (sections_copied && (p == NULL || ! p->copy))
- return;
-
/* Get the, possibly new, name of the output section. */
name = find_section_rename (ibfd, isection, & flags);
--- 1780,1792 ----
const char * name;
char *prefix = NULL;
! if (is_strip_section (ibfd, isection))
return;
p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
if (p != NULL)
p->used = TRUE;
/* Get the, possibly new, name of the output section. */
name = find_section_rename (ibfd, isection, & flags);
*************** setup_section (ibfd, isection, obfdarg)
*** 1872,1878 ****
/* 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;
--- 1881,1892 ----
/* 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;
*************** copy_section (ibfd, isection, obfdarg)
*** 1913,1943 ****
if (status != 0)
return;
! flags = bfd_get_section_flags (ibfd, isection);
! if ((flags & SEC_DEBUGGING) != 0
! && (strip_symbols == STRIP_DEBUG
! || strip_symbols == STRIP_UNNEEDED
! || strip_symbols == STRIP_ALL
! || discard_locals == LOCALS_ALL
! || convert_debugging))
return;
if ((flags & SEC_GROUP) != 0)
return;
- p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
-
- if (sections_removed && p != NULL && p->remove)
- return;
- if (sections_copied && (p == NULL || ! p->copy))
- return;
-
osection = isection->output_section;
size = bfd_get_section_size_before_reloc (isection);
if (size == 0 || osection == 0)
return;
/* Core files do not need to be relocated. */
if (bfd_get_format (obfd) == bfd_core)
relsize = 0;
--- 1927,1947 ----
if (status != 0)
return;
! if (is_strip_section (ibfd, isection))
return;
+ flags = bfd_get_section_flags (ibfd, isection);
if ((flags & SEC_GROUP) != 0)
return;
osection = isection->output_section;
size = bfd_get_section_size_before_reloc (isection);
if (size == 0 || osection == 0)
return;
+ p = find_section_list (bfd_get_section_name (ibfd, isection), FALSE);
+
/* Core files do not need to be relocated. */
if (bfd_get_format (obfd) == bfd_core)
relsize = 0;
*************** strip_main (argc, argv)
*** 2265,2270 ****
--- 2269,2277 ----
case OPTION_FORMATS_INFO:
formats_info = TRUE;
break;
+ case OPTION_STRIP_NONDEBUG:
+ strip_symbols = STRIP_NONDEBUG;
+ break;
case 0:
/* We've been given a long option. */
break;
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 15:57 RFC: strip --strip-nondebug Nick Clifton
@ 2003-06-05 16:06 ` Ian Lance Taylor
2003-06-05 16:24 ` Daniel Jacobowitz
2003-06-05 16:14 ` Andrew Cagney
` (2 subsequent siblings)
3 siblings, 1 reply; 20+ messages in thread
From: Ian Lance Taylor @ 2003-06-05 16:06 UTC (permalink / raw)
To: Nick Clifton; +Cc: gdb-patches, binutils
Nick Clifton <nickc@redhat.com> writes:
> I am seeking comments and criticisms on the attached patch. It adds
> a new switch to strip:
>
> --strip-nondebug
>
> This can be used to create an output file which only contains the
> debug information from an executable. This would allow stripped
> binaries to be shipped with separate debug info files, and provided
> that the debugger supported it, they could still be debugged.
I recommend a different option name. The other --strip* options
affect only the symbol table and the debugging information. This new
option also affects the sections. Maybe something like
strip --nondebug
or
strip --keep-debug
and don't forget
objcopy --keep-debug
Ian
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 15:57 RFC: strip --strip-nondebug Nick Clifton
2003-06-05 16:06 ` Ian Lance Taylor
@ 2003-06-05 16:14 ` Andrew Cagney
2003-06-05 16:24 ` Elena Zannoni
2003-06-05 18:29 ` Michael Snyder
3 siblings, 0 replies; 20+ messages in thread
From: Andrew Cagney @ 2003-06-05 16:14 UTC (permalink / raw)
To: Nick Clifton; +Cc: gdb-patches, binutils
Ya!!!!
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 16:06 ` Ian Lance Taylor
@ 2003-06-05 16:24 ` Daniel Jacobowitz
0 siblings, 0 replies; 20+ messages in thread
From: Daniel Jacobowitz @ 2003-06-05 16:24 UTC (permalink / raw)
To: gdb-patches, binutils, nickc
On Thu, Jun 05, 2003 at 09:06:04AM -0700, Ian Lance Taylor wrote:
> Nick Clifton <nickc@redhat.com> writes:
>
> > I am seeking comments and criticisms on the attached patch. It adds
> > a new switch to strip:
> >
> > --strip-nondebug
> >
> > This can be used to create an output file which only contains the
> > debug information from an executable. This would allow stripped
> > binaries to be shipped with separate debug info files, and provided
> > that the debugger supported it, they could still be debugged.
>
> I recommend a different option name. The other --strip* options
> affect only the symbol table and the debugging information. This new
> option also affects the sections. Maybe something like
> strip --nondebug
> or
> strip --keep-debug
> and don't forget
> objcopy --keep-debug
How about:
strip --keep-debug-only
objcopy --keep-debug-only
?
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 15:57 RFC: strip --strip-nondebug Nick Clifton
2003-06-05 16:06 ` Ian Lance Taylor
2003-06-05 16:14 ` Andrew Cagney
@ 2003-06-05 16:24 ` Elena Zannoni
2003-06-05 17:08 ` Nick Clifton
2003-06-05 18:29 ` Michael Snyder
3 siblings, 1 reply; 20+ messages in thread
From: Elena Zannoni @ 2003-06-05 16:24 UTC (permalink / raw)
To: Nick Clifton; +Cc: gdb-patches, binutils
Nick Clifton writes:
> Hi Guys,
>
> I am seeking comments and criticisms on the attached patch. It adds
> a new switch to strip:
>
> --strip-nondebug
>
> This can be used to create an output file which only contains the
> debug information from an executable. This would allow stripped
> binaries to be shipped with separate debug info files, and provided
> that the debugger supported it, they could still be debugged.
>
> The patch is incomplete - it needs a ChangeLog entry as well as
> modifications to NEWS and binutils.texi to document the new
> functionality, but I will write all of these once/if the patch is
> in acceptable state.
Nick, cool. Have you tried using gdb with the separate debug info
resulting from your command? It should work transparently, once you
set the debug directory, if needed.
(gdb) help set debug-file-directory
Set the directory where separate debug symbols are searched for.
Separate debug symbols are first searched for in the same
directory as the binary, then in the `.debug' subdirectory,
and lastly at the path of the directory of the binary with
the global debug-file directory prepended
elena
>
> Cheers
> Nick
>
> Index: binutils/objcopy.c
> ===================================================================
> RCS file: /cvs/src/src/binutils/objcopy.c,v
> retrieving revision 1.48
> diff -c -3 -p -r1.48 objcopy.c
> *** binutils/objcopy.c 2 Jun 2003 14:45:12 -0000 1.48
> --- binutils/objcopy.c 5 Jun 2003 15:50:15 -0000
> *************** enum strip_action
> *** 130,136 ****
> STRIP_NONE, /* don't strip */
> STRIP_DEBUG, /* strip all debugger symbols */
> STRIP_UNNEEDED, /* strip unnecessary symbols */
> ! STRIP_ALL /* strip all symbols */
> };
>
> /* Which symbols to remove. */
> --- 130,137 ----
> STRIP_NONE, /* don't strip */
> STRIP_DEBUG, /* strip all debugger symbols */
> STRIP_UNNEEDED, /* strip unnecessary symbols */
> ! STRIP_ALL, /* strip all symbols */
> ! STRIP_NONDEBUG /* Strip everything but debug info. */
> };
>
> /* Which symbols to remove. */
> *************** static char *prefix_alloc_sections_strin
> *** 277,282 ****
> --- 278,284 ----
> #define OPTION_PREFIX_SECTIONS (OPTION_PREFIX_SYMBOLS + 1)
> #define OPTION_PREFIX_ALLOC_SECTIONS (OPTION_PREFIX_SECTIONS + 1)
> #define OPTION_FORMATS_INFO (OPTION_PREFIX_ALLOC_SECTIONS + 1)
> + #define OPTION_STRIP_NONDEBUG (OPTION_FORMATS_INFO + 1)
>
> /* Options to handle if running as "strip". */
>
> *************** static struct option strip_options[] =
> *** 297,302 ****
> --- 299,305 ----
> {"remove-section", required_argument, 0, 'R'},
> {"strip-all", no_argument, 0, 's'},
> {"strip-debug", no_argument, 0, 'S'},
> + {"strip-nondebug", no_argument, 0, OPTION_STRIP_NONDEBUG},
> {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED},
> {"strip-symbol", required_argument, 0, 'N'},
> {"target", required_argument, 0, 'F'},
> *************** strip_usage (stream, exit_status)
> *** 490,495 ****
> --- 493,499 ----
> -g -S -d --strip-debug Remove all debugging symbols\n\
> --strip-unneeded Remove all symbols not needed by relocations\n\
> -N --strip-symbol=<name> Do not copy symbol <name>\n\
> + --strip-nondebug Remove all but the debug info\n\
> -K --keep-symbol=<name> Only copy symbol <name>\n\
> -x --discard-all Remove all non-global symbols\n\
> -X --discard-locals Remove any compiler-generated symbols\n\
> *************** is_strip_section (abfd, sec)
> *** 752,776 ****
> bfd *abfd ATTRIBUTE_UNUSED;
> asection *sec;
> {
> ! struct section_list *p;
>
> ! if ((bfd_get_section_flags (abfd, sec) & SEC_DEBUGGING) != 0
> ! && (strip_symbols == STRIP_DEBUG
> || strip_symbols == STRIP_UNNEEDED
> || strip_symbols == STRIP_ALL
> || discard_locals == LOCALS_ALL
> ! || convert_debugging))
> ! return TRUE;
>
> ! if (! sections_removed && ! sections_copied)
> ! return FALSE;
>
> ! p = find_section_list (bfd_get_section_name (abfd, sec), FALSE);
> ! if (sections_removed && p != NULL && p->remove)
> ! return TRUE;
> ! if (sections_copied && (p == NULL || ! p->copy))
> ! return TRUE;
> ! return FALSE;
> }
>
> /* Choose which symbol entries to copy; put the result in OSYMS.
> --- 756,787 ----
> bfd *abfd ATTRIBUTE_UNUSED;
> asection *sec;
> {
> ! if (sections_removed || sections_copied)
> ! {
> ! struct section_list *p;
> !
> ! p = find_section_list (bfd_get_section_name (abfd, sec), FALSE);
> !
> ! if (sections_removed && p != NULL && p->remove)
> ! return TRUE;
> ! if (sections_copied && (p == NULL || ! p->copy))
> ! return TRUE;
> ! }
>
> ! if ((bfd_get_section_flags (abfd, sec) & SEC_DEBUGGING) != 0)
> ! {
> ! if (strip_symbols == STRIP_DEBUG
> || strip_symbols == STRIP_UNNEEDED
> || strip_symbols == STRIP_ALL
> || 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.
> *************** filter_symbols (abfd, obfd, osyms, isyms
> *** 882,890 ****
> || bfd_is_com_section (bfd_get_section (sym)))
> keep = strip_symbols != STRIP_UNNEEDED;
> else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
> ! keep = (strip_symbols != STRIP_DEBUG
> ! && strip_symbols != STRIP_UNNEEDED
> ! && ! convert_debugging);
> else if (bfd_get_section (sym)->comdat)
> /* COMDAT sections store special information in local
> symbols, so we cannot risk stripping any of them. */
> --- 893,903 ----
> || bfd_is_com_section (bfd_get_section (sym)))
> keep = strip_symbols != STRIP_UNNEEDED;
> else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
> ! {
> ! keep = (strip_symbols != STRIP_DEBUG
> ! && strip_symbols != STRIP_UNNEEDED
> ! && ! convert_debugging);
> ! }
> else if (bfd_get_section (sym)->comdat)
> /* COMDAT sections store special information in local
> symbols, so we cannot risk stripping any of them. */
> *************** copy_object (ibfd, obfd)
> *** 1329,1334 ****
> --- 1342,1348 ----
> 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)
> *** 1434,1440 ****
> 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),
> --- 1448,1459 ----
> 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),
> *************** copy_object (ibfd, obfd)
> *** 1442,1448 ****
> status = 1;
> return;
> }
> !
> /* Switch to the alternate machine code. We have to do this at the
> very end, because we only initialize the header when we create
> the first section. */
> --- 1461,1467 ----
> status = 1;
> return;
> }
> !
> /* Switch to the alternate machine code. We have to do this at the
> very end, because we only initialize the header when we create
> the first section. */
> *************** setup_section (ibfd, isection, obfdarg)
> *** 1761,1783 ****
> const char * name;
> char *prefix = NULL;
>
> ! if ((bfd_get_section_flags (ibfd, isection) & SEC_DEBUGGING) != 0
> ! && (strip_symbols == STRIP_DEBUG
> ! || strip_symbols == STRIP_UNNEEDED
> ! || strip_symbols == STRIP_ALL
> ! || discard_locals == LOCALS_ALL
> ! || convert_debugging))
> return;
>
> p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
> if (p != NULL)
> p->used = TRUE;
>
> - if (sections_removed && p != NULL && p->remove)
> - return;
> - if (sections_copied && (p == NULL || ! p->copy))
> - return;
> -
> /* Get the, possibly new, name of the output section. */
> name = find_section_rename (ibfd, isection, & flags);
>
> --- 1780,1792 ----
> const char * name;
> char *prefix = NULL;
>
> ! if (is_strip_section (ibfd, isection))
> return;
>
> p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
> if (p != NULL)
> p->used = TRUE;
>
> /* Get the, possibly new, name of the output section. */
> name = find_section_rename (ibfd, isection, & flags);
>
> *************** setup_section (ibfd, isection, obfdarg)
> *** 1872,1878 ****
>
> /* 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;
> --- 1881,1892 ----
>
> /* 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;
> *************** copy_section (ibfd, isection, obfdarg)
> *** 1913,1943 ****
> if (status != 0)
> return;
>
> ! flags = bfd_get_section_flags (ibfd, isection);
> ! if ((flags & SEC_DEBUGGING) != 0
> ! && (strip_symbols == STRIP_DEBUG
> ! || strip_symbols == STRIP_UNNEEDED
> ! || strip_symbols == STRIP_ALL
> ! || discard_locals == LOCALS_ALL
> ! || convert_debugging))
> return;
>
> if ((flags & SEC_GROUP) != 0)
> return;
>
> - p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
> -
> - if (sections_removed && p != NULL && p->remove)
> - return;
> - if (sections_copied && (p == NULL || ! p->copy))
> - return;
> -
> osection = isection->output_section;
> size = bfd_get_section_size_before_reloc (isection);
>
> if (size == 0 || osection == 0)
> return;
>
> /* Core files do not need to be relocated. */
> if (bfd_get_format (obfd) == bfd_core)
> relsize = 0;
> --- 1927,1947 ----
> if (status != 0)
> return;
>
> ! if (is_strip_section (ibfd, isection))
> return;
>
> + flags = bfd_get_section_flags (ibfd, isection);
> if ((flags & SEC_GROUP) != 0)
> return;
>
> osection = isection->output_section;
> size = bfd_get_section_size_before_reloc (isection);
>
> if (size == 0 || osection == 0)
> return;
>
> + p = find_section_list (bfd_get_section_name (ibfd, isection), FALSE);
> +
> /* Core files do not need to be relocated. */
> if (bfd_get_format (obfd) == bfd_core)
> relsize = 0;
> *************** strip_main (argc, argv)
> *** 2265,2270 ****
> --- 2269,2277 ----
> case OPTION_FORMATS_INFO:
> formats_info = TRUE;
> break;
> + case OPTION_STRIP_NONDEBUG:
> + strip_symbols = STRIP_NONDEBUG;
> + break;
> case 0:
> /* We've been given a long option. */
> break;
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 16:24 ` Elena Zannoni
@ 2003-06-05 17:08 ` Nick Clifton
2003-06-05 19:19 ` Elena Zannoni
0 siblings, 1 reply; 20+ messages in thread
From: Nick Clifton @ 2003-06-05 17:08 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
Hi Elena,
> Nick, cool. Have you tried using gdb with the separate debug info
> resulting from your command? It should work transparently, once you
> set the debug directory, if needed.
>
> (gdb) help set debug-file-directory
> Set the directory where separate debug symbols are searched for.
> Separate debug symbols are first searched for in the same
> directory as the binary, then in the `.debug' subdirectory,
> and lastly at the path of the directory of the binary with
> the global debug-file directory prepended
Apparently not :-( Is there a good way to watch gdb try to find debug
information and find out what is wrong ?
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 15:57 RFC: strip --strip-nondebug Nick Clifton
` (2 preceding siblings ...)
2003-06-05 16:24 ` Elena Zannoni
@ 2003-06-05 18:29 ` Michael Snyder
2003-06-05 18:48 ` Daniel Jacobowitz
2003-06-05 19:47 ` Nick Clifton
3 siblings, 2 replies; 20+ messages in thread
From: Michael Snyder @ 2003-06-05 18:29 UTC (permalink / raw)
To: Nick Clifton; +Cc: gdb-patches, binutils
Nick Clifton wrote:
>
> Hi Guys,
>
> I am seeking comments and criticisms on the attached patch. It adds
> a new switch to strip:
>
> --strip-nondebug
>
> This can be used to create an output file which only contains the
> debug information from an executable. This would allow stripped
> binaries to be shipped with separate debug info files, and provided
> that the debugger supported it, they could still be debugged.
>
> The patch is incomplete - it needs a ChangeLog entry as well as
> modifications to NEWS and binutils.texi to document the new
> functionality, but I will write all of these once/if the patch is
> in acceptable state.
How big a reduction in size would you expect, typically?
I'm a little ignorant, but what strippable info is in there
that gdb doesn't need?
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 18:29 ` Michael Snyder
@ 2003-06-05 18:48 ` Daniel Jacobowitz
2003-06-05 19:06 ` Michael Snyder
2003-06-05 19:47 ` Nick Clifton
1 sibling, 1 reply; 20+ messages in thread
From: Daniel Jacobowitz @ 2003-06-05 18:48 UTC (permalink / raw)
To: Michael Snyder; +Cc: Nick Clifton, gdb-patches, binutils
On Thu, Jun 05, 2003 at 11:29:48AM -0700, Michael Snyder wrote:
> Nick Clifton wrote:
> >
> > Hi Guys,
> >
> > I am seeking comments and criticisms on the attached patch. It adds
> > a new switch to strip:
> >
> > --strip-nondebug
> >
> > This can be used to create an output file which only contains the
> > debug information from an executable. This would allow stripped
> > binaries to be shipped with separate debug info files, and provided
> > that the debugger supported it, they could still be debugged.
> >
> > The patch is incomplete - it needs a ChangeLog entry as well as
> > modifications to NEWS and binutils.texi to document the new
> > functionality, but I will write all of these once/if the patch is
> > in acceptable state.
>
> How big a reduction in size would you expect, typically?
> I'm a little ignorant, but what strippable info is in there
> that gdb doesn't need?
The trick is that the output file doesn't contain the code or data
segments. Just the debug info.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 18:48 ` Daniel Jacobowitz
@ 2003-06-05 19:06 ` Michael Snyder
2003-06-05 19:13 ` Elena Zannoni
0 siblings, 1 reply; 20+ messages in thread
From: Michael Snyder @ 2003-06-05 19:06 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Nick Clifton, gdb-patches, binutils
Daniel Jacobowitz wrote:
>
> On Thu, Jun 05, 2003 at 11:29:48AM -0700, Michael Snyder wrote:
> > Nick Clifton wrote:
> > >
> > > Hi Guys,
> > >
> > > I am seeking comments and criticisms on the attached patch. It adds
> > > a new switch to strip:
> > >
> > > --strip-nondebug
> > >
> > > This can be used to create an output file which only contains the
> > > debug information from an executable. This would allow stripped
> > > binaries to be shipped with separate debug info files, and provided
> > > that the debugger supported it, they could still be debugged.
> > >
> > > The patch is incomplete - it needs a ChangeLog entry as well as
> > > modifications to NEWS and binutils.texi to document the new
> > > functionality, but I will write all of these once/if the patch is
> > > in acceptable state.
> >
> > How big a reduction in size would you expect, typically?
> > I'm a little ignorant, but what strippable info is in there
> > that gdb doesn't need?
>
> The trick is that the output file doesn't contain the code or data
> segments. Just the debug info.
I thought separate-debug-info was an orthogonal issue (mentioned
by Elena in her own reply). My interpretation of Nick's patch
was that it would strip the binary of anything not needed by the
debugger, but leave the code and data. I wanted to know what that
subset consists of, and how big it typically is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 19:06 ` Michael Snyder
@ 2003-06-05 19:13 ` Elena Zannoni
0 siblings, 0 replies; 20+ messages in thread
From: Elena Zannoni @ 2003-06-05 19:13 UTC (permalink / raw)
To: Michael Snyder; +Cc: Daniel Jacobowitz, Nick Clifton, gdb-patches, binutils
Michael Snyder writes:
> Daniel Jacobowitz wrote:
> >
> > On Thu, Jun 05, 2003 at 11:29:48AM -0700, Michael Snyder wrote:
> > > Nick Clifton wrote:
> > > >
> > > > Hi Guys,
> > > >
> > > > I am seeking comments and criticisms on the attached patch. It adds
> > > > a new switch to strip:
> > > >
> > > > --strip-nondebug
> > > >
> > > > This can be used to create an output file which only contains the
> > > > debug information from an executable. This would allow stripped
> > > > binaries to be shipped with separate debug info files, and provided
> > > > that the debugger supported it, they could still be debugged.
> > > >
> > > > The patch is incomplete - it needs a ChangeLog entry as well as
> > > > modifications to NEWS and binutils.texi to document the new
> > > > functionality, but I will write all of these once/if the patch is
> > > > in acceptable state.
> > >
> > > How big a reduction in size would you expect, typically?
> > > I'm a little ignorant, but what strippable info is in there
> > > that gdb doesn't need?
> >
> > The trick is that the output file doesn't contain the code or data
> > segments. Just the debug info.
>
> I thought separate-debug-info was an orthogonal issue (mentioned
> by Elena in her own reply). My interpretation of Nick's patch
> was that it would strip the binary of anything not needed by the
> debugger, but leave the code and data. I wanted to know what that
> subset consists of, and how big it typically is.
The intent is to separate the debug info from the other stuff, and to
have gdb do:
gdb <executable-file>
and have this still work as expected (as if the debug info was in the
executable). If the debug info only file is not in special locations
that gdb looks in, the user can tell it where it is, and then
(re)issue a file command on the executable.
elena
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 17:08 ` Nick Clifton
@ 2003-06-05 19:19 ` Elena Zannoni
2003-06-06 11:17 ` Nick Clifton
0 siblings, 1 reply; 20+ messages in thread
From: Elena Zannoni @ 2003-06-05 19:19 UTC (permalink / raw)
To: Nick Clifton; +Cc: Elena Zannoni, gdb-patches
Nick Clifton writes:
> Hi Elena,
>
> > Nick, cool. Have you tried using gdb with the separate debug info
> > resulting from your command? It should work transparently, once you
> > set the debug directory, if needed.
> >
> > (gdb) help set debug-file-directory
> > Set the directory where separate debug symbols are searched for.
> > Separate debug symbols are first searched for in the same
> > directory as the binary, then in the `.debug' subdirectory,
> > and lastly at the path of the directory of the binary with
> > the global debug-file directory prepended
>
> Apparently not :-( Is there a good way to watch gdb try to find debug
> information and find out what is wrong ?
>
> Cheers
> Nick
>
Hmm, step through symfile.c:find_separate_debug_file, if the problem
seems to be locating the file. If the problem is that the file is
found, but the format is not ok, you should see symbol_file_add
getting called, with that file as one of the arguments. The you can
step through symbol_file_add. Is this Elf/dwarf2 you are testing or
something else? I think the gdb stuff was only tested on such a
combination, even though it should be generic.
elena
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 18:29 ` Michael Snyder
2003-06-05 18:48 ` Daniel Jacobowitz
@ 2003-06-05 19:47 ` Nick Clifton
2003-06-05 19:54 ` Kris Warkentin
1 sibling, 1 reply; 20+ messages in thread
From: Nick Clifton @ 2003-06-05 19:47 UTC (permalink / raw)
To: Michael Snyder; +Cc: gdb-patches, binutils
Hi Michael,
> How big a reduction in size would you expect, typically?
> I'm a little ignorant, but what strippable info is in there
> that gdb doesn't need?
Quite a lot it would seem. I have not done any rigorous studies but I
did try out a simple hello world program:
compiled hello executable: 11999 bytes
after strip --strip-debug: 4350 bytes
after strip --strip-all: 2772 bytes
after strip --strip-nondebug 6725 bytes
So even taking a debug stripped executable and its associated debug
file, the combined size is 4350 + 6725 = 11075 which is less than the
original.
Of course the patch does not work properly yet. (GDB does not seem to
find/understand the debug info file) so the sizes will probably
change). But in the normal case of running an program, having an
executable that is significantly smaller must surely result in some
performance benefits.
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 19:47 ` Nick Clifton
@ 2003-06-05 19:54 ` Kris Warkentin
0 siblings, 0 replies; 20+ messages in thread
From: Kris Warkentin @ 2003-06-05 19:54 UTC (permalink / raw)
To: Michael Snyder, Nick Clifton; +Cc: gdb-patches, binutils
> > How big a reduction in size would you expect, typically?
> > I'm a little ignorant, but what strippable info is in there
> > that gdb doesn't need?
>
> Quite a lot it would seem. I have not done any rigorous studies but I
> did try out a simple hello world program:
>
> compiled hello executable: 11999 bytes
> after strip --strip-debug: 4350 bytes
> after strip --strip-all: 2772 bytes
> after strip --strip-nondebug 6725 bytes
>
> So even taking a debug stripped executable and its associated debug
> file, the combined size is 4350 + 6725 = 11075 which is less than the
> original.
We do something like this for remote debugging. The target doesn't need the
debug info so we strip it before we send it off. GDB on the host reads the
original binary and the target runs the stripped one.
> Of course the patch does not work properly yet. (GDB does not seem to
> find/understand the debug info file) so the sizes will probably
> change). But in the normal case of running an program, having an
> executable that is significantly smaller must surely result in some
> performance benefits.
Actually, I wouldn't expect so. None of the debug stuff is loadable anyway.
But that's okay: space is an adequate optimization even if time is the more
fashionable one these days. Hard drives and ram are practically free but
embedded boards are almost always short on resources and flash isn't quite
as cheap.
cheers,
Kris
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-05 19:19 ` Elena Zannoni
@ 2003-06-06 11:17 ` Nick Clifton
2003-06-06 13:11 ` Elena Zannoni
0 siblings, 1 reply; 20+ messages in thread
From: Nick Clifton @ 2003-06-06 11:17 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
Hi Elena,
> Hmm, step through symfile.c:find_separate_debug_file, if the problem
> seems to be locating the file.
The problem is find_separate_debug_file() calls get_debug_link_info()
which looks for a section called ".gnu_debuglink" which is not present
in the stripped executable.
What is this section and how is it supposed to get into the stripped
executable ?
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-06 11:17 ` Nick Clifton
@ 2003-06-06 13:11 ` Elena Zannoni
2003-06-06 14:32 ` Nick Clifton
2003-06-06 14:51 ` Nick Clifton
0 siblings, 2 replies; 20+ messages in thread
From: Elena Zannoni @ 2003-06-06 13:11 UTC (permalink / raw)
To: Nick Clifton; +Cc: Elena Zannoni, gdb-patches
Nick Clifton writes:
> Hi Elena,
>
> > Hmm, step through symfile.c:find_separate_debug_file, if the problem
> > seems to be locating the file.
>
> The problem is find_separate_debug_file() calls get_debug_link_info()
> which looks for a section called ".gnu_debuglink" which is not present
> in the stripped executable.
>
> What is this section and how is it supposed to get into the stripped
> executable ?
The strip utility does it. BTW, I find it a bit silly that a non-gnu
utility decided to use the .gnu_debuglink name. Maybe you should call
it somethign different, and gdb can look for both names?
elena
>
> Cheers
> Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-06 13:11 ` Elena Zannoni
@ 2003-06-06 14:32 ` Nick Clifton
2003-06-06 14:51 ` Nick Clifton
1 sibling, 0 replies; 20+ messages in thread
From: Nick Clifton @ 2003-06-06 14:32 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
Hi Elena,
> > What is this section and how is it supposed to get into the stripped
> > executable ?
>
> The strip utility does it.
Ah - I was afraid of that. You see what I had hoped was that the GNU
strip program would only ever have to produce *one* output file at a
time. So you could use one command to strip an executable and a
second command to create a debug-info file for that executable, rather
than trying to do both things at once. (Which would mean a lot more
changes to the internals of strip, something I was trying to avoid).
If "--only-keep-debug" (my suggested new name for the --strip-nondebug
switch) has to produce a debug-info file *and* a stripped executable
with an extra .gnu_debuglink section in it, then it gets rather
complicated...
Of course we could have a five stage process:
1. strip --strip-debug foo.exe -o foo.exe.stripped
2. strip --only-keep-debug foo.exe -o foo.dbg
4. echo foo.dbg > debug_link
3. objcopy --add-section .gnu_debuglink=debug_link foo.stripped
5. rm debug_link
I'll give it a go and see what happens.
> BTW, I find it a bit silly that a non-gnu utility decided to use the
> .gnu_debuglink name. Maybe you should call it somethign different,
> and gdb can look for both names?
I have no problem with the name. In fact I am very happy to keep
calling it .gnu_debuglink. This assumes of course that there is some
documentation as to the exact format of the contents of this
section...
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-06 13:11 ` Elena Zannoni
2003-06-06 14:32 ` Nick Clifton
@ 2003-06-06 14:51 ` Nick Clifton
2003-06-06 21:34 ` Andrew Cagney
1 sibling, 1 reply; 20+ messages in thread
From: Nick Clifton @ 2003-06-06 14:51 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
Hi Elena,
> The strip utility does it.
Well addign a .gnu_debuglink section with --add-section does not work,
because the section needs to contain a file name and CRC. *sigh*. It
looks like we are going to have to add another new option to objcopy:
--add-gnu_debuglink-section=<name_of_debug_info_file>
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-06 14:51 ` Nick Clifton
@ 2003-06-06 21:34 ` Andrew Cagney
2003-06-07 10:39 ` Nick Clifton
0 siblings, 1 reply; 20+ messages in thread
From: Andrew Cagney @ 2003-06-06 21:34 UTC (permalink / raw)
To: Nick Clifton; +Cc: Elena Zannoni, gdb-patches
> Hi Elena,
>
>
>> The strip utility does it.
>
>
>
> Well addign a .gnu_debuglink section with --add-section does not work,
> because the section needs to contain a file name and CRC. *sigh*. It
> looks like we are going to have to add another new option to objcopy:
>
> --add-gnu_debuglink-section=<name_of_debug_info_file>
>
> Cheers
BTW, which CRC? GDB appears to have more CRC checkers than one can poke
a stick at :-/
Andrew
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-06 21:34 ` Andrew Cagney
@ 2003-06-07 10:39 ` Nick Clifton
2003-06-07 15:37 ` Andrew Cagney
0 siblings, 1 reply; 20+ messages in thread
From: Nick Clifton @ 2003-06-07 10:39 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Elena Zannoni, gdb-patches
Hi Andrew,
> BTW, which CRC? GDB appears to have more CRC checkers than one can
> poke a stick at :-/
gnu_debuglink_crc32() defined in gdb/utils.c
Cheers
Nick
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: RFC: strip --strip-nondebug
2003-06-07 10:39 ` Nick Clifton
@ 2003-06-07 15:37 ` Andrew Cagney
0 siblings, 0 replies; 20+ messages in thread
From: Andrew Cagney @ 2003-06-07 15:37 UTC (permalink / raw)
To: Nick Clifton; +Cc: Elena Zannoni, gdb-patches
> Hi Andrew,
>
>
>> BTW, which CRC? GDB appears to have more CRC checkers than one can
>> poke a stick at :-/
>
>
>
> gnu_debuglink_crc32() defined in gdb/utils.c
[rude noise]
Feel free to move it to BFD (or liberty?).
Andrew
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2003-06-07 15:37 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-05 15:57 RFC: strip --strip-nondebug Nick Clifton
2003-06-05 16:06 ` Ian Lance Taylor
2003-06-05 16:24 ` Daniel Jacobowitz
2003-06-05 16:14 ` Andrew Cagney
2003-06-05 16:24 ` Elena Zannoni
2003-06-05 17:08 ` Nick Clifton
2003-06-05 19:19 ` Elena Zannoni
2003-06-06 11:17 ` Nick Clifton
2003-06-06 13:11 ` Elena Zannoni
2003-06-06 14:32 ` Nick Clifton
2003-06-06 14:51 ` Nick Clifton
2003-06-06 21:34 ` Andrew Cagney
2003-06-07 10:39 ` Nick Clifton
2003-06-07 15:37 ` Andrew Cagney
2003-06-05 18:29 ` Michael Snyder
2003-06-05 18:48 ` Daniel Jacobowitz
2003-06-05 19:06 ` Michael Snyder
2003-06-05 19:13 ` Elena Zannoni
2003-06-05 19:47 ` Nick Clifton
2003-06-05 19:54 ` Kris Warkentin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox