This is the mail archive of the binutils@sourceware.org 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: allocating starting at top of memory with ld?


Nick Clifton wrote:
Hi Galen,

When linking I would like to allocate input sections starting from the highest memory address of an output section and working downwards. For example, given a memory area that starts at 0 and is 64KB in size, and an input section that is 4KB in size, I would like to have the input section located at 0xf000. Additional input sections would be located below this.

Sorry - this is not something that is currently supported by the linker. It always allocates from lower addresses towards higher addresses.


What benefit do you gain from allocating sections downwards ? Perhaps there is another way to solve the problem that you are handling.

Thanks for the response. The reason for wanting to allocate downwards is that the bottom portion of memory is occupied by data of varying size that is not part of the link process. The situation is somewhat similar to having a heap that grows up and a stack that grows down. I'm trying to pack my stuff at the top of memory in order to maximize the space available for the data that lives at the bottom.


The only idea I've come up with so far is to link twice. The first link would be a 'normal' link with input sections being assigned upwards. objdump would then be used to extract the resulting size of the output section. Then a second link would be performed, passing an org of a bogus output section on the command line that acts as a negative offset from the top of memory. Note that the files I'm linking are strictly data. I'm assuming the output section size will be the same on each link. Is there a simpler way to achieve a top down packing of data files?

Here's what the linker script might look like.

SECTIONS
{
    neg_offset (NOLOAD):
     { neg_offset = .;
       *(bogus) }

    . = 0x1000000 - neg_offset;
    real  :
     { *(data) }
}

thanks,
galen
--
Galen Seitz
galens@seitzassoc.com


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