Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicitly set starting stack pointer with linker script

I'd like to create a program with a special section at the end of Virtual Memory. So I wanted to do a linker script something like this:

 /* ... */
 .section_x 0xffff0000 : {
     _start_section_x = .;
     . = . + 0xffff;
     _end_section_x = .;
 }

The problem is that gcc/ld/glibc seem to load the stack at this location by default for a 32 bit application, even if it overlaps a known section. The above code zero's out the stack causing an exception. Is there any way to tell the linker to use another VM memory location for the stack? (As well, I'd like to ensure the heap doesn't span this section of virtual memory...).

like image 222
HardcoreHenry Avatar asked Nov 16 '17 22:11

HardcoreHenry


1 Answers

I hate answers that presume or even ask if the question is wrong but, if you need a 64k segment, why can't you just allocate one on startup?

Why could you possibly need a fixed address within your process address space? I've been doing a lot of different kinds of coding for almost 30 years, and I haven't seen the need for a fixed address since the advent of protected memory.

like image 128
Eliot Gillum Avatar answered Oct 16 '22 04:10

Eliot Gillum