gcbenison
gcbenison

Reputation: 11963

Map a literal address to a section

Given a literal address, how can I determine which section that address falls in? Here is an example. From a disassembly of a program, made with 'objdump', I obtain a literal address 0x8048520:

80483ea: c7 45 f4 20 85 04 08 movl $0x8048520,-0xc(%ebp) ...

On my platform (Linux 2.6.39, Gentoo) I can obtain a listing of sections simply by running 'less' on the ELF file, and see that this address falls within the .rodata section:

[15] .rodata           PROGBITS        08048518 000518 000016 00   A  0   0  4
...

However, I'm looking for a convenient way to do the same thing that does not require visually scanning through and comparing addresses. Suggestions?

Upvotes: 1

Views: 191

Answers (1)

80x25
80x25

Reputation: 751

Using your example address of 0x8048520:

objdump -s --start-address=0x8048520 --stop-address=0x8048521 elf_file | grep section | awk '{ print $4 }' | cut -d':' -f 1

In your example, the output of this command would be:

.rodata

Upvotes: 4

Related Questions