llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.34k stars 11.7k forks source link

Make GNU style symbol printing invalid symbol section indexes match GNU readelf #43195

Open jh7370 opened 4 years ago

jh7370 commented 4 years ago
Bugzilla Link 43850
Version trunk
OS Windows NT
CC @jh7370

Extended Description

When a symbol's st_shndx value is invalid due to it being larger than the number of sections, GNU readelf prints "bad section index[ XX]" for the section index column (where XX is the raw value). This also applies if the value is derived from the .symtab_shndx section:

C:\Work> readelf --symbols test.o

Symbol table '.symtab' contains 3 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 NOTYPE LOCAL DEFAULT bad section index[ 67] invalid 2: 00000000 0 NOTYPE LOCAL DEFAULT bad section index[ 42] invalid_shndx

llvm-readelf prints simply the value (derived from the .symtab_shndx section if appropriate).

jh7370 commented 4 years ago

Commit ef85f47595a905475d3e7b8d1441ed69cb226d9c fixes the comment 1 issue.

jh7370 commented 4 years ago

https://reviews.llvm.org/D69671 addresses comment 1. I haven't attempted to address the other related issue from comment 0.

jh7370 commented 4 years ago

For the record, the printing where there is no SYMTAB_SHNDX section for SHN_XINDEX st_shndx values is also incorrect (llvm-readelf emits an error, GNU readelf prints "RSV[0xffff]"). I am working on a fix for that issue currently.