Duplicating a section in a link
William A. Gatliff
Thu May 23 08:42:00 GMT 2002
If you don't mind if the code is always copied to RAM at startup,
i.e. you have enough RAM to have the code there whether you're using
it or not, then put the contents of single.c into your initialized
data section along with all your other initdata. Your startup code
would then copy it to RAM just like it's doing now for your
initialized globals, and the linker would resolve addresses to their
See gcc's __attribute__((section())) extension, and the linker's AT
directive (which you won't need to worry about if initdata already
works in your system). I talk about these in my gcc article at
Put another way, the linker is already doing the duplication you want,
but only for your initdata because traditionally that's all we ask it
for. So call your single.c functions initdata, and capitalize on that.
To get the section name gcc emits for initdata, create a file that
just has this in it:
int x = 10;
... and compile it to asm. Don't test with an initial value of zero,
however, because gcc will usually optimize that by placing x into the
.bss section, which isn't what you want.
On Thu, May 23, 2002 at 09:21:16AM -0600, Steve Pye wrote:
> My application runs mainly out of flash memory, but a part of
> the code has to run out of RAM. All
> the code that is to run from RAM is contained in a single .c
> source file. I'd like the linker to resolve all code addresses
> for this module to be in RAM, however I also need the linked
> object for this module to be included in the ROM image so that
> it can be programmed into flash and then later copied into
> RAM at run-time.
> I think this can be done by
> 1) assigning a section name to the code/strings contained in the .c file
> 2) telling the linker that this section should be linked in RAM
> 3) telling the linker that a copy of this section should also be placed in ROM
> Do you know how I can do 1,2,3? Or whom I should ask?
> BTW the target is StrongARM1110.
> Thanks very much.
> Best regards,
> Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to email@example.com
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to firstname.lastname@example.org
More information about the crossgcc