I'm learning about elf binaries. I want to manually verify that the code written in the program is in an executable region of memory (same for code for shared library that will be linked).
I have a simple program:
int main() { return 0; }
When I do:
readelf -a myprog
I get the following:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048154 000154 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048168 000168 000020 00 A 0 0 4
[ 3] .note.gnu.build-i NOTE 08048188 000188 000024 00 A 0 0 4
[ 4] .gnu.hash GNU_HASH 080481ac 0001ac 000020 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481cc 0001cc 000040 10 A 6 1 4
[ 6] .dynstr STRTAB 0804820c 00020c 000045 00 A 0 0 1
[ 7] .gnu.version VERSYM 08048252 000252 000008 02 A 5 0 2
[ 8] .gnu.version_r VERNEED 0804825c 00025c 000020 00 A 6 1 4
[ 9] .rel.dyn REL 0804827c 00027c 000008 08 A 5 0 4
[10] .rel.plt REL 08048284 000284 000010 08 A 5 12 4
[11] .init PROGBITS 08048294 000294 00002e 00 AX 0 0 4
[12] .plt PROGBITS 080482d0 0002d0 000030 04 AX 0 0 16
[13] .text PROGBITS 08048300 000300 00016c 00 AX 0 0 16
[14] .fini PROGBITS 0804846c 00046c 00001a 00 AX 0 0 4
[15] .rodata PROGBITS 08048488 000488 000008 00 A 0 0 4
[16] .eh_frame_hdr PROGBITS 08048490 000490 000034 00 A 0 0 4
[17] .eh_frame PROGBITS 080484c4 0004c4 0000c4 00 A 0 0 4
[18] .ctors PROGBITS 08049f14 000f14 000008 00 WA 0 0 4
[19] .dtors PROGBITS 08049f1c 000f1c 000008 00 WA 0 0 4
[20] .jcr PROGBITS 08049f24 000f24 000004 00 WA 0 0 4
[21] .dynamic DYNAMIC 08049f28 000f28 0000c8 08 WA 6 0 4
[22] .got PROGBITS 08049ff0 000ff0 000004 04 WA 0 0 4
[23] .got.plt PROGBITS 08049ff4 000ff4 000014 04 WA 0 0 4
[24] .data PROGBITS 0804a008 001008 000008 00 WA 0 0 4
[25] .bss NOBITS 0804a010 001010 000008 00 WA 0 0 4
[26] .comment PROGBITS 00000000 001010 00002a 01 MS 0 0 1
[27] .shstrtab STRTAB 00000000 00103a 0000fc 00 0 0 1
[28] .symtab SYMTAB 00000000 0015e8 000400 10 29 45 4
[29] .strtab STRTAB 00000000 0019e8 0001ea 00 0 0 1
To check whether the code of the program is executable, I can see the .text section with the flags AX. Is the X here for making the code inside my main() function is executable ?
Which section will the shared library (e.g. glibc) be loaded into when the program is dynamically linked at run time ? I found explanation online which discussed use of GOT,PLT in context of dynamic linking. The only sections with the mark X are init, plt and fini (in addition to text). Are shared libraries linked into one of these sections to make sure their code is executable when program starts execution ?
(It would be great if some reference(s) could be pointed at when answering the above)