Linux - process killed when linking section into lowest 2 MB of memory?

103 views Asked by At

I'm learning about LD linker scripts, and I noticed that if I link the .text section (or any section) at an address lower than than 2 MB, my process gets instantly killed by Linux as soon as I run it. Here's an example script I'm using:

SECTIONS
{
    . = 0x200000;    /* base for text section */
    .text : { *(.text) }
    . = 0x800000;
    .rodata : { *(.rodata) }
    .data : { *(.data) }
    .bss : { *(.bss) }
}

If I set the text base to 0x1FFFFF or below, the program immediately gets killed by Linux when I run it:

$ ./main
Killed

0x200000 works fine. Does Linux have some type of protection or something in place for the lowest 2 MB of virtual memory?

As a more general question, are there any rules about where sections should be linked in virtual memory, or is anywhere generally OK as long as I don't step on any reserved ranges?

(Obviously for a "real" program I'd just use the default LD script, but I'm just asking for learning purposes).

1

There are 1 answers

1
AudioBubble On BEST ANSWER

Does Linux have some type of protection or something in place for the lowest 2 MB of virtual memory?

Yes; the mmap_min_addr sysctl value prevents processes from mapping low memory pages to protect against certain types of kernel exploits.