Skip to content
Advertisement

Understanding ELF64 text/data segment layout/padding

I’m trying to brush up on UNIX viruses and one text I’m reading mentions that parasitic code can be inserted in the padding between the text and the data segment, supposedly up to 2MB in size on x86-64 systems. But when I compile a simple hello world program with gcc -no-pie

JavaScript

…and inspect its segment headers with readelf -W -l I get:

JavaScript

I assume the segment starting at virtual address 0x401000 is the text segment and the one starting at 0x430e00 is the data segment. But what are the other two read-only LOAD segment? And how precisely does padding work here? There’s no padding to 2MB boundaries to be seen and even assuming padding to 4KB boundaries, why does the data segment not start at address 0x403000?

Advertisement

Answer

But what are the other two read-only LOAD segment?

See this answer.

There’s no padding to 2MB boundaries

The BFD linker used to align segments on 2MiB boundary because that’s the maximum page size an x86_64 system can be configured with.

It no longer does this (not sure when the change was made).
The text you are reading is probably out of date.

Advertisement