0

There's data I'm trying to access in the dynamic section. I see headers like the below but doing a search online doesn't show me any code.

#define SHT_NULL        0
#define SHT_PROGBITS    1
#define SHT_SYMTAB      2
#define SHT_STRTAB      3
#define SHT_RELA        4
#define SHT_HASH        5
#define SHT_DYNAMIC     6
#define SHT_NOTE        7
#define SHT_NOBITS      8
#define SHT_REL         9
#define SHT_SHLIB       10
#define SHT_DYNSYM      11
#define SHT_INIT_ARRAY  14
#define SHT_FINI_ARRAY  15
#define SHT_PREINIT_ARRAY       16
  • Have you looked at the source code to `readelf`? Also, `libelf` has tons of code to read/manipulate ELF files. Where did you find this `.h` as the linux one (e.g. `/usr/include/elf.h`) has comments on each of those lines? You should be able to install the development package for `libelf` from your linux distro. – Craig Estey Jul 05 '23 at 22:52

1 Answers1

0

This answer shows how to iterate over the entire .dynamic section (actually the PT_DYNAMIC segment) at runtime, looking for a particular entry in it.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thank you. What the heck is that!? Where is that magic documented!?! Hmm, it doesn't appear available when I write asm. I did find a solution in another question –  Jul 06 '23 at 14:07
  • Jesters comment with the magic linker symbol is what I ended up using (in a test app, I may not need it) https://stackoverflow.com/questions/76625010/get-binary-dt-init-array-at-runtime?noredirect=1#comment135097634_76625010 –  Jul 06 '23 at 14:16