Bug 21133 - Readelf doesn't warn about malformed ELF
Summary: Readelf doesn't warn about malformed ELF
Status: RESOLVED WORKSFORME
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-12 23:41 UTC by Peter Johnson
Modified: 2017-02-13 11:48 UTC (History)
2 users (show)

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


Attachments
Testcase elf (229 bytes, application/x-object)
2017-02-12 23:41 UTC, Peter Johnson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Johnson 2017-02-12 23:41:43 UTC
Created attachment 9799 [details]
Testcase elf

It's possible to create an ELF file that readelf will perfectly read, but isn't valid according to the spec, this later caused some confusion when ld tried to link it against something.

I spoke with Alan Modra to figure out what was going on with the attached testcase I was given, and he informed me the ELF has a local after a global in the symtab, which is not allowed.

Would it be possible to get a warning added to readelf for this? I had assumed if readelf could understand it that the ELF was proper. It along with nm slightly misleadingly suggest that _start is a valid global symbol, when ld will silently ignore it.
Comment 1 Nick Clifton 2017-02-13 11:48:23 UTC
Hi Peter,

> Would it be possible to get a warning added to readelf for this?

We added a warning for this last year. :-)  It will be in the 2.28 release, or you could download the latest development sources and try for yourself.  You should see:

  $ readelf --syms basm.o

Symbol table '.symtab' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS file.asm
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    2 
     4: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 message
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    2 _start
     6: 000000000000000a     0 NOTYPE  LOCAL  DEFAULT    2 bar
readelf: Warning: local symbol 6 found at index >= .symtab's sh_info value of 6

Cheers
  Nick