.bss vs COMMON: what goes where?

// file a.c // file-scope int a = 0; // goes into BSS after compilation of a.c into object file a.o, a symbol goes into BSS section. // file b.c // file-scope int b; // goes into COMMON section after compilation of b.c into object file b.o, b symbol goes into COMMON section. After linking … Read more

How can I make GCC compile the .text section as writable in an ELF binary?

In the general sense, mprotect is the perferred choice (on POSIX conforming systems) under sys/mman.h (check http://linux.die.net/man/2/mprotect). Simply get the address and system page count of the executable section of your process and call mprotect to request permission permissions; write to it; then, call mprotect again to release write permission. However, if this is meant … Read more

Why Linux/gnu linker chose address 0x400000?

The start address is usually set by a linker script. For example, on GNU/Linux, looking at /usr/lib/ldscripts/elf_x86_64.x we see: … PROVIDE (__executable_start = SEGMENT_START(“text-segment”, 0x400000)); \ . = SEGMENT_START(“text-segment”, 0x400000) + SIZEOF_HEADERS; The value 0x400000 is the default value for the SEGMENT_START() function on this platform. You can find out more about linker scripts by … Read more