I am running some C code, compiled to 32bit x86 on Linux. And I am trying to access some memory. Apperently I can write to .bss and .data and to the stack. Some time ago, the .ctors and .dtors segments used to be writable, but it seems they are gone.
Without trial-and-error, how can I found out to which sections in memory the segments are mapped? How can I find out which addresses are mapped to writable memory and which are executable?
Sections and segments have specific meaning when you talk about
ELFexecutables, and your usage above doesn’t agree with that meaning.ELF sections don’t matter at load time, only (loadable) segments do.
The
readelf -l a.outcommand provides exactly the mapping from ELF sections to segments. E.g.This tells you that
.ctorsis mapped to segment 3, which is writable (this output is from ancientUnitedLinux 1.0distribution).Nowadays,
.ctorsis put into a segment different from.data, and protected from writing after relocation via specialGNU_RELROsegment.