0

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?

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
Chan Kim
  • 5,177
  • 12
  • 57
  • 112

1 Answers1

1

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 '
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Wow thanks again! (Then 'readelf -Ws vmlinux | awk '$7==18{print}' also works). I didn't know there are so many percpu variables. – Chan Kim Feb 05 '22 at 14:15