This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Defining a section that isn't file-backed (with an additional wrinkle)


On Mon, Feb 23, 2004 at 09:49:36AM +0000, Nick Clifton wrote:
>Hi Mike,
>
>> I'd like to use a linker script to define an ELF section that isn't
>> backed by disk space in the resulting binary, that I can place at a
>> specific absolute address in memory.
>>
>> By "not backed" I mean something a bit like the BSS where the
>> section could be (say) 256mb but only take up a few bytes on
>> disk. If the resulting section is assigned to a read-only VMA range,
>> then I think the result should be equivalent to a MAP_NORESERVE |
>> MAP_FIXED mmap before the dynamic linker runs - am I correct?
>
>Not sure about that, sorry.
>
>> If this is possible, what sort of script would I be looking for?
>> Alternatively which part of the ld manual describes how to do it, as
>> I've looked and not been able to find any info on this.
>
>What you need is a combination of a linker script and an assembler
>source file.  For example if you create an assembler file containing
>this:
>	.section .empty, "a", @nobits
>	.zero 40000
>
>and then a linker script which contains:
>
>        .empty 0x100 : { KEEP (*(.empty)) }
>
>You should get what you want.  Obviously you will need to change the
>numbers to reflect the size and location that you want.

I've had this email bookmarked for a while since I could really use
something like this in cygwin but with a probably nontrivial wrinkle.

I'd like to have a similar type of layout but have the memory reserved
but not allocated, i.e., I'd like the OS to set aside the memory addresses
automatically but not associate any physical memory with the space until
the equivalent of an 'sbrk' is called.

The distinction between reserved and allocated space is probably not a
UNIX-like concept although it is easy to do in Windows.  I can't find
any way in mmap or sbrk that would allow this, so I am probably out of
luck.

My reason for wanting this is to reserve a guaranteed section of memory
in every cygwin process but not necessarily use all of the section --
like for a heap.

So, is it possible in, ld or gas, to set aside a region of memory as
reserved but not allocated?

cgf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]