Reserving a large address region using the MEMORY directive

Nick Clifton nickc@redhat.com
Tue Jan 27 17:53:00 GMT 2004


Hi Mike,

> Reading the ld manual, it seems the best way to do this is to use the
> MEMORY directive, however I simply get segfaults when a minimal test app
> int main() { return 0; } is run. This is the linker script I'm starting
> with:
>
> MEMORY {
> 	before (rwxai) : ORIGIN = 0x000000, LENGTH = 0x400000 
> 	loadarea       : ORIGIN = 0x400000, LENGTH = 256M
> }
>
> I'm sure this doesn't look right, but am I vaguely on the right track?
> Does anybody know what the script I need would look like?

That script does look basically correct, but I think that you have
attributes slightly mixed up.

 	before (rwxai)

This says that the "before" region is read-only ("r") and read/write
("w").  Presumably you just want "r".

Also specifying an attribute for a region means that only sections
whose attributes exactly match the attributes of the region will be
allocated to it.  Any other sections will be assigned to the nearest
region with no attributes - ie the "loadarea" in the case of your map.

I think that you probably want a map like this:

 MEMORY {
 	before (rxai) : ORIGIN =   0x000000, LENGTH = 0x400000 
 	loadarea (wx) : ORIGIN =   0x400000, LENGTH = 256M
        after         : ORIGIN = 0x10400000, LENGTH = 0xe0c00000
 }

Assuming that you do not have any writable/executable input
sections...

Cheers
        Nick



More information about the Binutils mailing list