public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Load debug section only when dumping debug sections
@ 2022-01-30 20:04 H.J. Lu
  2022-01-31 16:31 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-01-30 20:04 UTC (permalink / raw)
  To: binutils

Don't load debug sections if we aren't dumping any debug sections.

	PR binutils/28843
	* objdump.c (dump_any_debugging): New.
	(load_debug_section): Return false if dump_any_debugging isn't
	set.
	(main): Set dump_any_debugging when dumping any debug sections.
	* readelf (dump_any_debugging): New.
	(parse_args): Set dump_any_debugging when dumping any debug
	sections.
	(load_debug_section): Return false if dump_any_debugging isn't
	set.
---
 binutils/objdump.c | 8 ++++++++
 binutils/readelf.c | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 08a0fe521d8..24e91869bfd 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -131,6 +131,7 @@ static bool color_output = false;	/* --visualize-jumps=color.  */
 static bool extended_color_output = false; /* --visualize-jumps=extended-color.  */
 static int process_links = false;       /* --process-links.  */
 
+static int dump_any_debugging;
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 
 /* A structure to record the sections mentioned in -j switches.  */
@@ -3851,6 +3852,9 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file)
   asection *sec;
   const char *name;
 
+  if (!dump_any_debugging)
+    return false;
+
   /* If it is already loaded, do nothing.  */
   if (section->start != NULL)
     {
@@ -5688,6 +5692,10 @@ main (int argc, char **argv)
   if (!seenflag)
     usage (stderr, 2);
 
+  dump_any_debugging = (dump_debugging
+			|| dump_dwarf_section_info
+			|| process_links);
+
   if (formats_info)
     exit_status = display_info ();
   else
diff --git a/binutils/readelf.c b/binutils/readelf.c
index b45683cd571..e56e9b56393 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -239,6 +239,7 @@ static bool decompress_dumps = false;
 static bool do_not_show_symbol_truncation = false;
 static bool do_demangle = false;	/* Pretty print C++ symbol names.  */
 static bool process_links = false;
+static bool dump_any_debugging = false;
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 static int sym_base = 0;
 
@@ -5332,6 +5333,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
 	case 'P':
 	  process_links = true;
 	  do_follow_links = true;
+	  dump_any_debugging = true;
 	  break;
 	case 'x':
 	  request_dump (dumpdata, HEX_DUMP);
@@ -5347,6 +5349,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
 	  break;
 	case 'w':
 	  do_dump = true;
+	  dump_any_debugging = true;
 	  if (optarg == NULL)
 	    {
 	      do_debugging = true;
@@ -5360,6 +5363,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
 	  break;
 	case OPTION_DEBUG_DUMP:
 	  do_dump = true;
+	  dump_any_debugging = true;
 	  if (optarg == NULL)
 	    {
 	      do_debugging = true;
@@ -15913,6 +15917,9 @@ load_debug_section (enum dwarf_section_display_enum debug, void * data)
   Elf_Internal_Shdr * sec;
   Filedata * filedata = (Filedata *) data;
 
+  if (!dump_any_debugging)
+    return false;
+
   /* Without section headers we cannot find any sections.  */
   if (filedata->section_headers == NULL)
     return false;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Load debug section only when dumping debug sections
  2022-01-30 20:04 [PATCH] Load debug section only when dumping debug sections H.J. Lu
@ 2022-01-31 16:31 ` Nick Clifton
  2022-01-31 18:20   ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2022-01-31 16:31 UTC (permalink / raw)
  To: H.J. Lu, binutils

Hi H.J.

> Don't load debug sections if we aren't dumping any debug sections.
> 
> 	PR binutils/28843
> 	* objdump.c (dump_any_debugging): New.
> 	(load_debug_section): Return false if dump_any_debugging isn't
> 	set.
> 	(main): Set dump_any_debugging when dumping any debug sections.
> 	* readelf (dump_any_debugging): New.
> 	(parse_args): Set dump_any_debugging when dumping any debug
> 	sections.
> 	(load_debug_section): Return false if dump_any_debugging isn't
> 	set.

Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Load debug section only when dumping debug sections
  2022-01-31 16:31 ` Nick Clifton
@ 2022-01-31 18:20   ` H.J. Lu
  2022-02-01 10:17     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-01-31 18:20 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Binutils

On Mon, Jan 31, 2022 at 8:31 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi H.J.
>
> > Don't load debug sections if we aren't dumping any debug sections.
> >
> >       PR binutils/28843
> >       * objdump.c (dump_any_debugging): New.
> >       (load_debug_section): Return false if dump_any_debugging isn't
> >       set.
> >       (main): Set dump_any_debugging when dumping any debug sections.
> >       * readelf (dump_any_debugging): New.
> >       (parse_args): Set dump_any_debugging when dumping any debug
> >       sections.
> >       (load_debug_section): Return false if dump_any_debugging isn't
> >       set.
>
> Approved - please apply.
>

Pushed.

OK for backport?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Load debug section only when dumping debug sections
  2022-01-31 18:20   ` H.J. Lu
@ 2022-02-01 10:17     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2022-02-01 10:17 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

Hi H.J.

> OK for backport?

No.  Please keep this for mainline only for now.

I have a sneaking suspicion that their might be more cases where
we want to load the debug sections, even when the options involved
do not appear to need it.  At least not at first glance.  So lets
give the patch time to be tested in the mainline.

Cheers
   Nick



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-01 10:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 20:04 [PATCH] Load debug section only when dumping debug sections H.J. Lu
2022-01-31 16:31 ` Nick Clifton
2022-01-31 18:20   ` H.J. Lu
2022-02-01 10:17     ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).