Search code examples
elfreadelf

How to list up variables assigned to a specific section in an elf file?


How can I list up variables allocated in a specific section in an elf file?
For example, if I do readelf -t vmlinux, I can see the section informations (start offset and the size, of course in virtual address) so I can see where the .data..percpu section starts and for how long.

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  ....
  [18] .data..percpu     PROGBITS         ffffffc0105cb000  0054b000
       0000000000011948  0000000000000000  WA       0     0     64

Also I can list up all the symbols using -s option which shows the address and size of all the symbols. I could combine those info with the section info to list up all the variables in .data..percpu section. But this will take some effort and I thought there should be a simple command that lists up variables in a specific section. Can I do that?


Solution

  • Every symbol has the section index to which it belongs in the Ndx column.

    To find all symbols matching section 18, do this:

    readelf -Ws vmlinux | cut -c60- | grep ' 18 '