robert
robert

Reputation: 3726

.text section address range of position independent executable

I want the address of the .text section of a position independent executable. Using readelf -S:

Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
.text             PROGBITS         0000000000002700  00002700
       0000000000001672  0000000000000000  AX       0     0     16

I learn that it will begin 0x2700 bytes past where library was loaded into memory. But how can I get the load address of the executable? Is there any other way to get the .text section address range during runtime (from the running program)?

Upvotes: 2

Views: 299

Answers (1)

Employed Russian
Employed Russian

Reputation: 213955

Is there any other way to get the .text section address range during runtime (from the running program)?

Yes: you need to use dl_iterate_phdr and use info->dlpi_addr to locate the PIE binary in memory at runtime. The very first call to your callback will be for the main executable.

Upvotes: 2

Related Questions