[03/12] objdump, readelf: Report errors from CTF archive iteration

Message ID 20201025141413.363381-4-nick.alcock@oracle.com
State New
Headers show
Series
  • CTF symbol functionality
Related show

Commit Message

Alan Modra via Binutils Oct. 25, 2020, 2:14 p.m.
We were failing to report errors from ctf_archive_iter, which results in
silent early termination if (for example) one CTF archive member in a
.ctf section is corrupted and cannot be opened.  Report the error in the
usual fashion instead.

binutils/ChangeLog
2020-10-23  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (dump_ctf): Report errors from ctf_archive_iter.
	* readelf.c (dump_section_as_ctf): Likewise.
---
 binutils/objdump.c | 7 ++++++-
 binutils/readelf.c | 8 ++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

-- 
2.29.0.249.g249b51256f

Comments

Alan Modra via Binutils Nov. 17, 2020, 10:28 p.m. | #1
On Sun, Oct 25, 2020 at 02:14:04PM +0000, Nick Alcock via Binutils wrote:
> We were failing to report errors from ctf_archive_iter, which results in

> silent early termination if (for example) one CTF archive member in a

> .ctf section is corrupted and cannot be opened.  Report the error in the

> usual fashion instead.

> 

> binutils/ChangeLog

> 2020-10-23  Nick Alcock  <nick.alcock@oracle.com>

> 

> 	* objdump.c (dump_ctf): Report errors from ctf_archive_iter.

> 	* readelf.c (dump_section_as_ctf): Likewise.


OK, with one minor fix.

> --- a/binutils/objdump.c

> +++ b/binutils/objdump.c

> @@ -4203,7 +4203,12 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)

>  

>    printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));

>  

> -  ctf_archive_iter (ctfa, dump_ctf_archive_member, parent);

> +  if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)

> +    {

> +      dump_ctf_errs (NULL);

> +      fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));

> +      bfd_fatal (bfd_get_filename (abfd));


fatal calls xexit, which makes bfd_fatal here dead code.

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra via Binutils Nov. 18, 2020, 4:20 p.m. | #2
On 17 Nov 2020, Alan Modra spake thusly:

> On Sun, Oct 25, 2020 at 02:14:04PM +0000, Nick Alcock via Binutils wrote:

>> -  ctf_archive_iter (ctfa, dump_ctf_archive_member, parent);

>> +  if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)

>> +    {

>> +      dump_ctf_errs (NULL);

>> +      fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));

>> +      bfd_fatal (bfd_get_filename (abfd));

>

> fatal calls xexit, which makes bfd_fatal here dead code.


Oops! That should be a non_fatal, obviously, like the calls above.
Fixed.

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index bf8234987f0..d8b194d56cb 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4203,7 +4203,12 @@  dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
 
   printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
 
-  ctf_archive_iter (ctfa, dump_ctf_archive_member, parent);
+  if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)
+    {
+      dump_ctf_errs (NULL);
+      fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err));
+      bfd_fatal (bfd_get_filename (abfd));
+    }
   ctf_dict_close (parent);
   ctf_close (ctfa);
   ctf_close (parenta);
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 8577d0d2212..9a682c3ab19 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -14746,8 +14746,12 @@  dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   printf (_("\nDump of CTF section '%s':\n"),
 	  printable_section_name (filedata, section));
 
-  if (ctf_archive_iter (ctfa, dump_ctf_archive_member, parent) != 0)
-    ret = FALSE;
+  if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0)
+    {
+      dump_ctf_errs (NULL);
+      error (_("CTF member  open failure: %s\n"), ctf_errmsg (err));
+      ret = FALSE;
+    }
 
  fail:
   ctf_dict_close (parent);