Explicitly set starting stack pointer with linker script
Asked Answered
B

1

7

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...).

Bettor answered 16/11, 2017 at 22:27 Comment(2)
You need to provide more information about your target. The initial register contents (which determines the stack location) is target-dependent.Yea
This is an arm-8 system (compiling in 32 bit mode). I am using a linux 3.10 kernel with a gcc 4.7.0 toolchain.Bettor
D
1

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.

Darrickdarrill answered 27/11, 2017 at 9:48 Comment(2)
No unfortunately the question is not incorrect. I'm modifying an existing system with the capability to assign special meaning to various bits in a pointer. As such, I need to reserve the 0xffff0000 address range for a special purpose.Bettor
@Bettor I'm sure whoever created this system described it as "elegant" however I think 99% of the world, hopefully including you, sees this as evil. That said, why do these goofy pointers have to resolve to valid addresses? Can't some layer of abstraction provide the additional functionality while not requiring fixed memory addresses? They could point to a struct with those bits set, or dereferencing the pointer could be done by a routine which knows how to do a lookaside?Darrickdarrill

© 2022 - 2024 — McMap. All rights reserved.