From ca0e11aa4ba877e180f7d40dcc5a89540740c501 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Thu, 4 Mar 2021 10:41:22 +0000 Subject: Gate the displaying of non-debug sections in separate debuginfo files. PR 27478 * objdump.c (process_links): New variable. (usage): Add --process-links. (long_options): Likewise. (dump_bfd): Stop processing once the bfd has been loaded unless this is the main file or process_links has been enabled. (main): Handle the process-links option. * readelf.c (process_links): New variable. (struct filedata): Add is_separate field. (options): Add --process-links. (usage): Likewise. (parse_args): Likewise. (process_file_header): Include the filename when dumping information for separate debuginfo files. (process_program_headers): Likewise. (process_section_headers): Likewise. (process_section_groups): Likewise. (process_relocs): Likewise. (process_dynamic_section): Likewise. (process_version_sections): Likewise. (display_lto_symtab): Likewise. (process_symbol_table): Likewise. (process_syminfo): Likewise. (initialise_dumps_by_name): Likewise. (process_section_contents): Likewise. (process_notes_at): Likewise. (process_notes): Likewise. (open_file): Add is_separate parameter. Use to initialise the is_separate field in the filedata structure. (open_deug): Update call to open_file. (process_object): Add processing of the contents of separate debuginfo files, gated by the process_links variable. (process_archive): Update call to open_file. (process_file): Initialise the is_separate field in the filedata structure. * dwarf.c (load_separate_debug_info_file): Only report the loading of a separate file if debug links are being dumped. * objcopy.c (keep_section_symbols): New variable. (enum command_line_switch): Add OPTION_KEEP_SYMBOLS. (strip_options): Add keep-section-symbols. (copy_options): Likewise. (copy_usage): Likewise. (strip_usage): Likewise. (copy_object): Keep section symbols if requested by command line option. (strip_main): Handle --keep-section-symbols. (copy_main): Likewise. * doc/binutils.texi: Document the new options. * NEWS: Mention the new features. * testsuite/binutils-all/compress.exp (test_gnu_debuglink): Update options passed to objdump. Use diff rather than cmp to compare the dumped data. * testsuite/binutils-all/objdump.WK2: Update regexp. * testsuite/binutils-all/objdump.WK3: Update regexp. * testsuite/binutils-all/objdump.exp: Use --process-links instead of --dwarf=follow-links. * testsuite/binutils-all/readelf.exp (readelf_test): Include readelf's output in the log when the test fails. Add the -P option to the -wKis test. * testsuite/binutils-all/readelf.wKis: Update expected output. --- binutils/objcopy.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'binutils/objcopy.c') diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 99e6cad..d58f910 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -91,6 +91,7 @@ static int copy_byte = -1; static int interleave = 0; /* Initialised to 4 in copy_main(). */ static int copy_width = 1; +static bfd_boolean keep_section_symbols = FALSE ;/* True if section symbols should be retained. */ static bfd_boolean verbose; /* Print file and target names. */ static bfd_boolean preserve_dates; /* Preserve input file timestamp. */ static int deterministic = -1; /* Enable deterministic archives. */ @@ -335,6 +336,7 @@ enum command_line_switch OPTION_KEEP_FILE_SYMBOLS, OPTION_KEEP_SECTION, OPTION_KEEP_SYMBOLS, + OPTION_KEEP_SECTION_SYMBOLS, OPTION_LOCALIZE_HIDDEN, OPTION_LOCALIZE_SYMBOLS, OPTION_LONG_SECTION_NAMES, @@ -387,6 +389,7 @@ static struct option strip_options[] = {"info", no_argument, 0, OPTION_FORMATS_INFO}, {"input-format", required_argument, 0, 'I'}, /* Obsolete */ {"input-target", required_argument, 0, 'I'}, + {"keep-section-symbols", no_argument, 0, OPTION_KEEP_SECTION_SYMBOLS}, {"keep-file-symbols", no_argument, 0, OPTION_KEEP_FILE_SYMBOLS}, {"keep-section", required_argument, 0, OPTION_KEEP_SECTION}, {"keep-symbol", required_argument, 0, 'K'}, @@ -463,6 +466,7 @@ static struct option copy_options[] = {"keep-section", required_argument, 0, OPTION_KEEP_SECTION}, {"keep-symbol", required_argument, 0, 'K'}, {"keep-symbols", required_argument, 0, OPTION_KEEP_SYMBOLS}, + {"keep-section-symbols", required_argument, 0, OPTION_KEEP_SECTION_SYMBOLS}, {"localize-hidden", no_argument, 0, OPTION_LOCALIZE_HIDDEN}, {"localize-symbol", required_argument, 0, 'L'}, {"localize-symbols", required_argument, 0, OPTION_LOCALIZE_SYMBOLS}, @@ -595,6 +599,7 @@ copy_usage (FILE *stream, int exit_status) --extract-symbol Remove section contents but keep symbols\n\ --keep-section Do not strip section \n\ -K --keep-symbol Do not strip symbol \n\ + --keep-section-symbols Do not strip section symbols\n\ --keep-file-symbols Do not strip file symbol(s)\n\ --localize-hidden Turn all ELF hidden symbols into locals\n\ -L --localize-symbol Force symbol to be marked as a local\n\ @@ -729,6 +734,7 @@ strip_usage (FILE *stream, int exit_status) -N --strip-symbol= Do not copy symbol \n\ --keep-section= Do not strip section \n\ -K --keep-symbol= Do not strip symbol \n\ + --keep-section-symbols Do not strip section symbols\n\ --keep-file-symbols Do not strip file symbol(s)\n\ -w --wildcard Permit wildcard in symbol comparison\n\ -x --discard-all Remove all non-global symbols\n\ @@ -3196,7 +3202,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) if ((obfd->flags & (EXEC_P | DYNAMIC)) != 0 && (obfd->flags & HAS_RELOC) == 0) { - if (bfd_keep_unused_section_symbols (obfd)) + if (bfd_keep_unused_section_symbols (obfd) || keep_section_symbols) { /* Non-relocatable inputs may not have the unused section symbols. Mark all section symbols as used to generate @@ -4768,6 +4774,9 @@ strip_main (int argc, char *argv[]) case OPTION_KEEP_FILE_SYMBOLS: keep_file_symbols = 1; break; + case OPTION_KEEP_SECTION_SYMBOLS: + keep_section_symbols = TRUE; + break; case 0: /* We've been given a long option. */ break; @@ -5653,6 +5662,10 @@ copy_main (int argc, char *argv[]) &keep_specific_buffer); break; + case OPTION_KEEP_SECTION_SYMBOLS: + keep_section_symbols = TRUE; + break; + case OPTION_LOCALIZE_HIDDEN: localize_hidden = TRUE; break; -- cgit v1.1