Bug 12639 - nm/readelf failed to detect corrupted symtab
Summary: nm/readelf failed to detect corrupted symtab
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL: http://sourceware.org/ml/binutils/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-05 16:18 UTC by H.J. Lu
Modified: 2011-04-05 17:12 UTC (History)
0 users

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


Attachments
A testcase with bad symtab (3.23 KB, application/octet-stream)
2011-04-05 16:18 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2011-04-05 16:18:27 UTC
Created attachment 5646 [details]
A testcase with bad symtab

[hjl@gnu-6 cq167859]$ readelf -sS --wide  tr70098.bad.o      
There are 13 section headers, starting at offset 0x3008:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .symtab           SYMTAB          0000000000000000 000040 000420 18      9  37  4
  [ 2] .rodata           PROGBITS        0000000000000000 000460 000240 00   A  0   0 32
  [ 3] .data             PROGBITS        0000000000000000 0006a0 000c28 00  WA  0   0  8
  [ 4] .rodata.str1.4    PROGBITS        0000000000000000 0012c8 000008 01 AMS  0   0  4
  [ 5] .text             PROGBITS        0000000000000000 0012d0 000c00 00  AX  0   0 16
  [ 6] .note.GNU-stack   NOTE            0000000000000000 001ed0 000000 00      0   0  1
  [ 7] .comment          PROGBITS        0000000000000000 001ed0 000013 00      0   0  1
  [ 8] .eh_frame         PROGBITS        0000000000000000 001ee3 000238 00   A  0   0  4
  [ 9] .strtab           STRTAB          0000000000000000 00211b 000348 00      0   0  1
  [10] .rela.data        RELA            0000000000000000 002463 0001b0 18      1   3  8
  [11] .rela.text        RELA            0000000000000000 002613 0009a8 18      1   5  8
  [12] .rela.eh_frame    RELA            0000000000000000 002fbb 000048 18      1   8  8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Symbol table '.symtab' contains 44 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS tr70098.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    9 .strtab
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 .symtab
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    2 .rodata
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 .data
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 .rodata.str1.4
     7: 0000000000000000     8 OBJECT  LOCAL  DEFAULT    4 .L_2__STRING.0
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 .text
     9: 0000000000000000    20 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.7.0.3
    10: 0000000000000018    52 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.8.0.3
    11: 0000000000000050   848 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.6.0.3
    12: 0000000000000000    73 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.8.0.3
    13: 000000000000004c    83 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.9.0.3
    14: 00000000000000a0     5 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.10.0.3
    15: 00000000000000a8     5 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.11.0.3
    16: 00000000000003a0    20 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.1.0.1
    17: 00000000000003b8    80 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.2.0.1
    18: 0000000000000408  1552 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.0.0.1
    19: 00000000000000c0    73 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.0.0.1
    20: 000000000000010c    83 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.1.0.1
    21: 0000000000000160     5 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.2.0.1
    22: 0000000000000168     4 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.3.0.1
    23: 0000000000000a18    20 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.4.0.2
    24: 0000000000000a30    36 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.5.0.2
    25: 0000000000000a58   464 OBJECT  LOCAL  DEFAULT    3 __pgo_segment_2pack.3.0.2
    26: 0000000000000180    73 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.4.0.2
    27: 00000000000001cc    83 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.5.0.2
    28: 0000000000000220     5 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.6.0.2
    29: 0000000000000228     5 OBJECT  LOCAL  DEFAULT    2 __pgopti_2inst_string.7.0.2
    30: 0000000000000000     0 SECTION LOCAL  DEFAULT    6 .note.GNU-stack
    31: 0000000000000000     0 SECTION LOCAL  DEFAULT    7 .comment
    32: 0000000000000000     0 SECTION LOCAL  DEFAULT    8 .eh_frame
    33: 0000000000000000     0 SECTION LOCAL  DEFAULT   10 .rela.data
    34: 0000000000000000     0 SECTION LOCAL  DEFAULT   11 .rela.text
    35: 0000000000000000     0 SECTION LOCAL  DEFAULT   12 .rela.eh_frame
    36: 0000000000000000  1392 FUNC    GLOBAL DEFAULT    5 main
...

The sh_info field of symtab section header should be 36, not 37.
But readelf doesn't detect it.
Comment 1 H.J. Lu 2011-04-05 17:07:47 UTC
nm has the same problem:

[hjl@gnu-6 cq167859]$ nm tr70098.bad.o
0000000000000000 r .L_2__STRING.0
                 U _GLOBAL_OFFSET_TABLE_
                 U _PGOPTI_Prof_Begin
                 U _PGOPTI_Prof_Div_64_VP
                 U __intel_new_proc_init
0000000000000408 d __pgo_segment_2pack.0.0.1
00000000000003a0 d __pgo_segment_2pack.1.0.1
00000000000003b8 d __pgo_segment_2pack.2.0.1
0000000000000a58 d __pgo_segment_2pack.3.0.2
0000000000000a18 d __pgo_segment_2pack.4.0.2
0000000000000a30 d __pgo_segment_2pack.5.0.2
0000000000000050 d __pgo_segment_2pack.6.0.3
0000000000000000 d __pgo_segment_2pack.7.0.3
0000000000000018 d __pgo_segment_2pack.8.0.3
00000000000000c0 r __pgopti_2inst_string.0.0.1
000000000000010c r __pgopti_2inst_string.1.0.1
00000000000000a0 r __pgopti_2inst_string.10.0.3
00000000000000a8 r __pgopti_2inst_string.11.0.3
0000000000000160 r __pgopti_2inst_string.2.0.1
0000000000000168 r __pgopti_2inst_string.3.0.1
0000000000000180 r __pgopti_2inst_string.4.0.2
00000000000001cc r __pgopti_2inst_string.5.0.2
0000000000000220 r __pgopti_2inst_string.6.0.2
0000000000000228 r __pgopti_2inst_string.7.0.2
0000000000000000 r __pgopti_2inst_string.8.0.3
000000000000004c r __pgopti_2inst_string.9.0.3
0000000000000ab0 T init
0000000000000000 T main
                 U printf
0000000000000570 T sum

"main" should be local.
Comment 2 H.J. Lu 2011-04-05 17:12:17 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2011-04/msg00036.html