binutils/binutils-link-following.patch

460 lines
17 KiB
Diff
Raw Normal View History

diff -rup binutils.orig/binutils/dwarf.c binutils-2.37/binutils/dwarf.c
--- binutils.orig/binutils/dwarf.c 2022-05-21 13:12:31.851174169 +0100
+++ binutils-2.37/binutils/dwarf.c 2022-05-21 13:12:58.798988551 +0100
@@ -11533,7 +11533,11 @@ free_debug_memory (void)
free_dwo_info ();
}
-void
+/* Enable display of specific DWARF sections as determined by the comma
+ separated strings in NAMES. Returns non-zero if any displaying was
+ enabled. */
+
+int
dwarf_select_sections_by_names (const char *names)
{
typedef struct
@@ -11586,6 +11590,7 @@ dwarf_select_sections_by_names (const ch
};
const char *p;
+ int result = 0;
p = names;
while (*p)
@@ -11600,6 +11605,7 @@ dwarf_select_sections_by_names (const ch
&& (p[len] == ',' || p[len] == '\0'))
{
* entry->variable = entry->val;
+ result |= entry->val;
/* The --debug-dump=frames-interp option also
enables the --debug-dump=frames option. */
@@ -11622,48 +11628,82 @@ dwarf_select_sections_by_names (const ch
if (*p == ',')
p++;
}
+
+ return result;
}
-void
+/* Enable display of specific DWARF sections as determined by the characters
+ in LETTERS. Returns non-zero if any displaying was enabled. */
+
+int
dwarf_select_sections_by_letters (const char *letters)
{
- unsigned int lindex = 0;
+ typedef struct
+ {
+ const char letter;
+ int * variable;
+ int val;
+ bool cont;
+ }
+ debug_dump_letter_opts;
- while (letters[lindex])
- switch (letters[lindex++])
- {
- case 'A': do_debug_addr = 1; break;
- case 'a': do_debug_abbrevs = 1; break;
- case 'c': do_debug_cu_index = 1; break;
+ static const debug_dump_letter_opts letter_table [] =
+ {
+ { 'A', & do_debug_addr, 1, false},
+ { 'a', & do_debug_abbrevs, 1, false },
+ { 'c', & do_debug_cu_index, 1, false },
#ifdef HAVE_LIBDEBUGINFOD
- case 'D': use_debuginfod = 1; break;
- case 'E': use_debuginfod = 0; break;
+ { 'D', & use_debuginfod, 1, false },
+ { 'E', & use_debuginfod, 0, false },
#endif
- case 'F': do_debug_frames_interp = 1; /* Fall through. */
- case 'f': do_debug_frames = 1; break;
- case 'g': do_gdb_index = 1; break;
- case 'i': do_debug_info = 1; break;
- case 'K': do_follow_links = 1; break;
- case 'N': do_follow_links = 0; break;
- case 'k': do_debug_links = 1; break;
- case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
- case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
- case 'm': do_debug_macinfo = 1; break;
- case 'O': do_debug_str_offsets = 1; break;
- case 'o': do_debug_loc = 1; break;
- case 'p': do_debug_pubnames = 1; break;
- case 'R': do_debug_ranges = 1; break;
- case 'r': do_debug_aranges = 1; break;
- case 's': do_debug_str = 1; break;
- case 'T': do_trace_aranges = 1; break;
- case 't': do_debug_pubtypes = 1; break;
- case 'U': do_trace_info = 1; break;
- case 'u': do_trace_abbrevs = 1; break;
-
- default:
- warn (_("Unrecognized debug option '%s'\n"), letters);
- break;
- }
+ { 'F', & do_debug_frames_interp, 1, true }, /* Note the fall through. */
+ { 'f', & do_debug_frames, 1, false },
+ { 'g', & do_gdb_index, 1, false },
+ { 'i', & do_debug_info, 1, false },
+ { 'K', & do_follow_links, 1, false },
+ { 'k', & do_debug_links, 1, false },
+ { 'L', & do_debug_lines, FLAG_DEBUG_LINES_DECODED, false },
+ { 'l', & do_debug_lines, FLAG_DEBUG_LINES_RAW, false },
+ { 'm', & do_debug_macinfo, 1, false },
+ { 'N', & do_follow_links, 0, false },
+ { 'O', & do_debug_str_offsets, 1, false },
+ { 'o', & do_debug_loc, 1, false },
+ { 'p', & do_debug_pubnames, 1, false },
+ { 'R', & do_debug_ranges, 1, false },
+ { 'r', & do_debug_aranges, 1, false },
+ { 's', & do_debug_str, 1, false },
+ { 'T', & do_trace_aranges, 1, false },
+ { 't', & do_debug_pubtypes, 1, false },
+ { 'U', & do_trace_info, 1, false },
+ { 'u', & do_trace_abbrevs, 1, false },
+ { 0, NULL, 0, false }
+ };
+
+ int result = 0;
+
+ while (* letters)
+ {
+ const debug_dump_letter_opts * entry;
+
+ for (entry = letter_table; entry->letter; entry++)
+ {
+ if (entry->letter == * letters)
+ {
+ * entry->variable |= entry->val;
+ result |= entry->val;
+
+ if (! entry->cont)
+ break;
+ }
+ }
+
+ if (entry->letter == 0)
+ warn (_("Unrecognized debug letter option '%c'\n"), * letters);
+
+ letters ++;
+ }
+
+ return result;
}
void
Only in binutils-2.37/binutils/: dwarf.c.orig
diff -rup binutils.orig/binutils/dwarf.h binutils-2.37/binutils/dwarf.h
--- binutils.orig/binutils/dwarf.h 2022-05-21 13:12:31.854174148 +0100
+++ binutils-2.37/binutils/dwarf.h 2022-05-21 13:12:58.799988544 +0100
@@ -243,8 +243,8 @@ extern void *open_debug_file (const char
extern void free_debug_memory (void);
-extern void dwarf_select_sections_by_names (const char *);
-extern void dwarf_select_sections_by_letters (const char *);
+extern int dwarf_select_sections_by_names (const char *);
+extern int dwarf_select_sections_by_letters (const char *);
extern void dwarf_select_sections_all (void);
extern unsigned int * find_cu_tu_set (void *, unsigned int);
Only in binutils-2.37/binutils/: dwarf.h.orig
diff -rup binutils.orig/binutils/objdump.c binutils-2.37/binutils/objdump.c
--- binutils.orig/binutils/objdump.c 2022-05-21 13:12:31.855174141 +0100
+++ binutils-2.37/binutils/objdump.c 2022-05-21 13:14:42.740372795 +0100
@@ -5010,6 +5010,26 @@ sign_extend_address (bfd *abfd ATTRIBUTE
return (((vma & ((mask << 1) - 1)) ^ mask) - mask);
}
+static bool
+might_need_separate_debug_info (bool is_mainfile)
+{
+ /* We do not follow links from debug info files. */
+ if (! is_mainfile)
+ return false;
+
+ /* Since do_follow_links might be enabled by default, only treat it as an
+ indication that separate files should be loaded if setting it was a
+ deliberate user action. */
+ if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links)
+ return true;
+
+ if (process_links || dump_symtab || dump_debugging
+ || dump_dwarf_section_info)
+ return true;
+
+ return false;
+}
+
/* Dump selected contents of ABFD. */
static void
@@ -5024,16 +5044,8 @@ dump_bfd (bfd *abfd, bool is_mainfile)
else
byte_get = NULL;
- /* Load any separate debug information files.
- We do this now and without checking do_follow_links because separate
- debug info files may contain symbol tables that we will need when
- displaying information about the main file. Any memory allocated by
- load_separate_debug_files will be released when we call
- free_debug_memory below.
-
- The test on is_mainfile is there because the chain of separate debug
- info files is a global variable shared by all invocations of dump_bfd. */
- if (is_mainfile)
+ /* Load any separate debug information files. */
+ if (byte_get != NULL && might_need_separate_debug_info (is_mainfile))
{
load_separate_debug_files (abfd, bfd_get_filename (abfd));
@@ -5588,20 +5600,30 @@ main (int argc, char **argv)
do_follow_links = true;
break;
case 'W':
- dump_dwarf_section_info = true;
seenflag = true;
if (optarg)
- dwarf_select_sections_by_letters (optarg);
+ {
+ if (dwarf_select_sections_by_letters (optarg))
+ dump_dwarf_section_info = true;
+ }
else
- dwarf_select_sections_all ();
+ {
+ dump_dwarf_section_info = true;
+ dwarf_select_sections_all ();
+ }
break;
case OPTION_DWARF:
- dump_dwarf_section_info = true;
seenflag = true;
if (optarg)
- dwarf_select_sections_by_names (optarg);
+ {
+ if (dwarf_select_sections_by_names (optarg))
+ dump_dwarf_section_info = true;
+ }
else
- dwarf_select_sections_all ();
+ {
+ dwarf_select_sections_all ();
+ dump_dwarf_section_info = true;
+ }
break;
case OPTION_DWARF_DEPTH:
{
diff -rup binutils.orig/binutils/objdump.c.orig binutils-2.37/binutils/objdump.c.orig
--- binutils.orig/binutils/objdump.c.orig 2022-05-21 13:12:31.872174024 +0100
+++ binutils-2.37/binutils/objdump.c.orig 2022-05-21 13:12:22.066241569 +0100
@@ -280,6 +280,14 @@ usage (FILE *stream, int status)
Do not follow links to separate debug info files\n\
(default)\n"));
#endif
+#if HAVE_LIBDEBUGINFOD
+ fprintf (stream, _("\
+ -WD --dwarf=use-debuginfod\n\
+ When following links, also query debuginfod servers (default)\n"));
+ fprintf (stream, _("\
+ -WE --dwarf=do-not-use-debuginfod\n\
+ When following links, do not query debuginfod servers\n"));
+#endif
fprintf (stream, _("\
-L, --process-links Display the contents of non-debug sections in\n\
separate debuginfo files. (Implies -WK)\n"));
diff -rup binutils.orig/binutils/objdump.c.rej binutils-2.37/binutils/objdump.c.rej
--- binutils.orig/binutils/objdump.c.rej 2022-05-21 13:12:31.872174024 +0100
+++ binutils-2.37/binutils/objdump.c.rej 2022-05-21 13:12:58.800988538 +0100
@@ -1,43 +1,21 @@
---- binutils/objdump.c
-+++ binutils/objdump.c
-@@ -487,28 +517,16 @@ static struct option long_options[]=
- {"source", no_argument, NULL, 'S'},
- {"source-comment", optional_argument, NULL, OPTION_SOURCE_COMMENT},
- {"special-syms", no_argument, &dump_special_syms, 1},
-- {"include", required_argument, NULL, 'I'},
-- {"dwarf", optional_argument, NULL, OPTION_DWARF},
--#ifdef ENABLE_LIBCTF
-- {"ctf", optional_argument, NULL, OPTION_CTF},
-- {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
--#endif
- {"stabs", no_argument, NULL, 'G'},
- {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
- {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
- {"syms", no_argument, NULL, 't'},
- {"target", required_argument, NULL, 'b'},
-+ {"unicode", required_argument, NULL, 'U'},
- {"version", no_argument, NULL, 'V'},
-- {"wide", no_argument, NULL, 'w'},
-- {"prefix", required_argument, NULL, OPTION_PREFIX},
-- {"prefix-strip", required_argument, NULL, OPTION_PREFIX_STRIP},
-- {"insn-width", required_argument, NULL, OPTION_INSN_WIDTH},
-- {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
-- {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
-- {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
-- {"inlines", no_argument, 0, OPTION_INLINES},
- {"visualize-jumps", optional_argument, 0, OPTION_VISUALIZE_JUMPS},
-- {0, no_argument, 0, 0}
-+ {"wide", no_argument, NULL, 'w'},
-+ {NULL, no_argument, NULL, 0}
- };
-
- static void
-@@ -5375,7 +5533,7 @@ main (int argc, char **argv)
- set_default_bfd_target ();
+--- binutils/objdump.c 2022-05-20 16:57:16.566961359 +0100
++++ binutils/objdump.c 2022-05-20 16:57:32.881853688 +0100
+@@ -5042,16 +5062,8 @@ dump_bfd (bfd *abfd, bool is_mainfile)
+ else
+ byte_get = NULL;
- while ((c = getopt_long (argc, argv,
-- "CDE:FGHI:LM:P:RSTVW::ab:defghij:lm:prstvwxz",
-+ "CDE:FGHI:LM:P:RSTU:VW::ab:defghij:lm:prstvwxz",
- long_options, (int *) 0))
- != EOF)
+- /* Load any separate debug information files.
+- We do this now and without checking do_follow_links because separate
+- debug info files may contain symbol tables that we will need when
+- displaying information about the main file. Any memory allocated by
+- load_separate_debug_files will be released when we call
+- free_debug_memory below.
+-
+- The test on is_mainfile is there because the chain of separate debug
+- info files is a global variable shared by all invocations of dump_bfd. */
+- if (byte_get != NULL && is_mainfile)
++ /* Load any separate debug information files. */
++ if (byte_get != NULL && might_need_separate_debug_info (is_mainfile))
{
+ load_separate_debug_files (abfd, bfd_get_filename (abfd));
+
diff -rup binutils.orig/binutils/readelf.c binutils-2.37/binutils/readelf.c
--- binutils.orig/binutils/readelf.c 2022-05-21 13:12:31.853174155 +0100
+++ binutils-2.37/binutils/readelf.c 2022-05-21 13:12:58.802988523 +0100
@@ -21632,6 +21632,26 @@ initialise_dump_sects (Filedata * fileda
}
}
+static bool
+might_need_separate_debug_info (Filedata * filedata)
+{
+ /* Debuginfo files do not need further separate file loading. */
+ if (filedata->file_header.e_shstrndx == SHN_UNDEF)
+ return false;
+
+ /* Since do_follow_links might be enabled by default, only treat it as an
+ indication that separate files should be loaded if setting it was a
+ deliberate user action. */
+ if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links)
+ return true;
+
+ if (process_links || do_syms || do_unwind
+ || do_dump || do_debugging)
+ return true;
+
+ return false;
+}
+
/* Process one ELF object file according to the command line options.
This file may actually be stored in an archive. The file is
positioned at the start of the ELF object. Returns TRUE if no
@@ -21715,7 +21735,7 @@ process_object (Filedata * filedata)
if (! process_version_sections (filedata))
res = false;
- if (filedata->file_header.e_shstrndx != SHN_UNDEF)
+ if (might_need_separate_debug_info (filedata))
have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
else
have_separate_files = false;
diff -rup binutils.orig/binutils/readelf.c.orig binutils-2.37/binutils/readelf.c.orig
--- binutils.orig/binutils/readelf.c.orig 2022-05-21 13:12:31.854174148 +0100
+++ binutils-2.37/binutils/readelf.c.orig 2022-05-21 13:12:22.077241494 +0100
@@ -4955,6 +4955,14 @@ usage (FILE * stream)
Do not follow links to separate debug info files\n\
(default)\n"));
#endif
+#if HAVE_LIBDEBUGINFOD
+ fprintf (stream, _("\
+ -wD --debug-dump=use-debuginfod\n\
+ When following links, also query debuginfod servers (default)\n"));
+ fprintf (stream, _("\
+ -wE --debug-dump=do-not-use-debuginfod\n\
+ When following links, do not query debuginfod servers\n"));
+#endif
fprintf (stream, _("\
--dwarf-depth=N Do not display DIEs at depth N or greater\n"));
fprintf (stream, _("\
diff -rup binutils.orig/binutils/testsuite/binutils-all/debuginfod.exp binutils-2.37/binutils/testsuite/binutils-all/debuginfod.exp
--- binutils.orig/binutils/testsuite/binutils-all/debuginfod.exp 2022-05-21 13:12:31.872174024 +0100
+++ binutils-2.37/binutils/testsuite/binutils-all/debuginfod.exp 2022-05-21 13:12:58.803988517 +0100
@@ -188,7 +188,7 @@ if { [regexp ".*DEBUGINFOD.*" $conf_objd
test_fetch_debugaltlink $OBJDUMP "-Wk"
set test "disabling debuginfod access"
- setup_xfail *-*-*
+ # setup_xfail *-*-*
test_fetch_debuglink $OBJDUMP "-W -WE"
set test "debuginfod"
@@ -201,7 +201,7 @@ if { [regexp ".*DEBUGINFOD.*" $conf_read
test_fetch_debugaltlink $READELF "-wk"
set test "disabling debuginfod access"
- setup_xfail *-*-*
+ # setup_xfail *-*-*
test_fetch_debuglink $READELF "-w -wE"
set test "debuginfod"
Only in binutils-2.37/binutils/testsuite/binutils-all: debuginfod.exp.orig
diff -rup binutils.orig/binutils/testsuite/binutils-all/objdump.Wk binutils-2.37/binutils/testsuite/binutils-all/objdump.Wk
--- binutils.orig/binutils/testsuite/binutils-all/objdump.Wk 2022-05-21 13:12:31.862174093 +0100
+++ binutils-2.37/binutils/testsuite/binutils-all/objdump.Wk 2022-05-21 13:12:58.803988517 +0100
@@ -1,8 +1,9 @@
+#...
tmpdir/debuglink\.o: file format .*
-Contents of the \.gnu_debuglink section:
+Contents of the \.gnu_debuglink section.*
Separate debug info file: this_is_a_debuglink\.debug
CRC value: 0x12345678
-Contents of the \.gnu_debugaltlink section:
+Contents of the \.gnu_debugaltlink section.*
Separate debug info file: linkdebug\.debug
Build-ID \(0x18 bytes\):
00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 01 23 45 67 89 ab cd ef
diff -rup binutils.orig/binutils/testsuite/binutils-all/readelf.k binutils-2.37/binutils/testsuite/binutils-all/readelf.k
--- binutils.orig/binutils/testsuite/binutils-all/readelf.k 2022-05-21 13:12:31.863174086 +0100
+++ binutils-2.37/binutils/testsuite/binutils-all/readelf.k 2022-05-21 13:12:58.812988455 +0100
@@ -1,7 +1,8 @@
-Contents of the \.gnu_debuglink section:
+#...
+Contents of the \.gnu_debuglink section.*
Separate debug info file: this_is_a_debuglink\.debug
CRC value: 0x12345678
-Contents of the \.gnu_debugaltlink section:
+Contents of the \.gnu_debugaltlink section.*
Separate debug info file: linkdebug\.debug
Build-ID \(0x18 bytes\):
00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 01 23 45 67 89 ab cd ef
Only in binutils-2.37/binutils/testsuite/binutils-all: debuginfod.exp.orig
--- binutils.orig/binutils/dwarf.c 2022-06-30 15:28:53.484593360 +0100
+++ binutils-2.37/binutils/dwarf.c 2022-06-30 15:32:22.112213811 +0100
@@ -11689,7 +11689,10 @@ dwarf_select_sections_by_letters (const
{
if (entry->letter == * letters)
{
- * entry->variable |= entry->val;
+ if (entry->val == 0)
+ * entry->variable = 0;
+ else
+ * entry->variable |= entry->val;
result |= entry->val;
if (! entry->cont)