object file symbol table generated by gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

$ cat func_globalvar.c
int globalVar;
static int globalStaticVar;
int func() {
  static int localStaticVar;
  return globalVar;
}
$ gcc -c -o func_globalvar_abs.o func_globalvar.c

I have the above object file. If I understand it correctly, the Ndx in
the following output should be the index of the string in the
.shstrtab table as shown below?

1 -> .symtab
3 -> .shstrtab
4 -> .rela.text
6 -> .bss
7 -> .comment
5 -> .data

$ readelf -s func_globalvar_abs.o
Symbol table '.symtab' contains 12 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS func_globalvar.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     5: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    4 globalStaticVar
     6: 0000000000000008     4 OBJECT  LOCAL  DEFAULT    4 localStaticVar.0
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    6
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    7
     9: 0000000000000000     0 SECTION LOCAL  DEFAULT    5
    10: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    4 globalVar
    11: 0000000000000000    12 FUNC    GLOBAL DEFAULT    1 func
$ readelf -p .shstrtab func_globalvar_abs.o
String dump of section '.shstrtab':
  [     1]  .symtab
  [     9]  .strtab
  [    11]  .shstrtab
  [    1b]  .rela.text
  [    26]  .data
  [    2c]  .bss
  [    31]  .comment
  [    3a]  .note.GNU-stack
  [    4a]  .rela.eh_frame

Why these sections are in the symbol table, given that they are
already in the section headers?

$ readelf -SW func_globalvar_abs.o
There are 12 section headers, starting at offset 0x2a8:

Section Headers:
  [Nr] Name              Type            Address          Off    Size
 ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000
000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040
00000c 00  AX  0   0  1
  [ 2] .rela.text        RELA            0000000000000000 000218
000018 18   I  9   1  8
  [ 3] .data             PROGBITS        0000000000000000 00004c
000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          0000000000000000 00004c
00000c 00  WA  0   0  4
  [ 5] .comment          PROGBITS        0000000000000000 00004c
000028 01  MS  0   0  1
  [ 6] .note.GNU-stack   PROGBITS        0000000000000000 000074
000000 00      0   0  1
  [ 7] .eh_frame         PROGBITS        0000000000000000 000078
000038 00   A  0   0  8
  [ 8] .rela.eh_frame    RELA            0000000000000000 000230
000018 18   I  9   7  8
  [ 9] .symtab           SYMTAB          0000000000000000 0000b0
000120 18     10  10  8
  [10] .strtab           STRTAB          0000000000000000 0001d0
000042 00      0   0  1
  [11] .shstrtab         STRTAB          0000000000000000 000248
000059 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)

-- 
Regards,
Peng



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux