Bug 21820 - [2.29 Regression] readelf now exits with error reading an empty section
Summary: [2.29 Regression] readelf now exits with error reading an empty section
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-24 00:58 UTC by Michael Hudson-Doyle
Modified: 2017-09-05 14:33 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
the file from the diffoscope test suite that exhibits the problem (754 bytes, application/x-object)
2017-07-24 11:10 UTC, Michael Hudson-Doyle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Hudson-Doyle 2017-07-24 00:58:53 UTC
As of https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=32ec889602502348b704cfb16e65c83dc3eec095 ("Tidy up readelf's use of boolean values.") readelf errors on reading an empty section from an object file:

((32ec889...))mwhudson@aeglos:/opt/opensource/binutils/binutils/binutils$ ./readelf  --hex-dump=.data alloc_system-d16b8f0e.0.o 
Section '.data' has no data to dump.
((32ec889...))mwhudson@aeglos:/opt/opensource/binutils/binutils/binutils$ echo $?
1

It's unclear if this is a desired consequence of this commit. It seems wrong to me.

(This breaks diffoscope's tests, which is how I found this)
Comment 1 Michael Hudson-Doyle 2017-07-24 11:10:24 UTC
Created attachment 10284 [details]
the file from the diffoscope test suite that exhibits the problem

Here's the file I mentioned in the summary.

I also noticed that readelf -x exits with code 0 for a section that does not exist at all so exiting with code 1 for a present, empty section seems even more likely to be a bug.
Comment 2 cvs-commit@gcc.gnu.org 2017-07-25 08:38:32 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c6b78c965a96fb152fbd58926edccb5dee2707a5

commit c6b78c965a96fb152fbd58926edccb5dee2707a5
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Jul 25 09:35:36 2017 +0100

    Stop readelf from returning an error status if asked to dump an emoty section.
    
    	PR 21820
    	* readelf.c (dump_section_as_strings): Do not fail if the section
    	was empty.
    	(dump_section_as_bytes): Likewise.
Comment 3 Nick Clifton 2017-07-25 08:43:31 UTC
Hi Michael,

  Thanks for reporting this problem.  I guess it could be argued that if the
  section is empty, why is the user trying to dump it ?  But I do not see this
  as a big issue, so I have gone ahead and applied a patch to restore the old
  behaviour of reporting, but not complaining about, empty sections.

Cheers
  Nick
Comment 4 cvs-commit@gcc.gnu.org 2017-09-05 14:33:26 UTC
The binutils-2_29-branch branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=64aa1246572306b72dc479b46d13ff749b0c3236

commit 64aa1246572306b72dc479b46d13ff749b0c3236
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Sep 5 15:32:04 2017 +0100

    Import patches from mainline to fix minor binutils bugs:
    
    	PR 21861
    	* winduni.c (codepages): Use cp1252 for codepage 0.
    
    	PR 21813
    	* rddbg.c (read_symbol_stabs_debugging_info): Check for an empty
    	string whilst concatenating symbol names.
    
    	PR 21909
    	* prdbg.c (pr_int_type): Increase size of local string buffer.
    	(pr_float_type): Likewise.
    	(pr_bool_type): Likewise.
    
    	PR 21820
    	* readelf.c (dump_section_as_strings): Do not fail if the section
    	was empty.
    	(dump_section_as_bytes): Likewise.
    
    	PR 21990
    	* readelf.c (process_version_sections <SHT_GNU_verneed>): Check
    	for invalid vn_next field before adding to idx.  Use unsigned
    	long for index vars.  Move index checks.
    	<SHT_GNU_verdef>: Likewise for vd_next.
    
    	PR 21994
    	* readelf.c (process_version_sections <SHT_GNU_verdef>): Check
    	vd_aux and vda_next for sanity.  Delete "end".  Correct overflow
    	checks.
    	(process_version_sections <SHT_GNU_verneed>): Correct overflow
    	check.  Don't report invalid vna_next on overflow.  Do report
    	invalid vna_next on size less than aux info.