Re: How to create a ROM library using GNU gcc and ld?



wyse03br@xxxxxxxxxxxx wrote:
On Mar 31, 3:35 pm, Arlet Ottens <usene...@xxxxxxxxxx> wrote:
This strategy doesn't work so well, because some symbols are
introduced twice (apparently by CRT0):
/lib/gcc-lib/ppc-elf/3.3.2/crtsavres.o(.text+0x1cc): In function
`_restgpr_31_x':
: multiple definition of `_restgpr_31_x'
a.aux(.text+0x1578): first defined here
collect2: ld returned 1 exit status
Don't use gcc for the partial link.

First use gcc to convert .c file into .o file, then call ld manually to
do partial link (without linker script). Something like this:

% ppc-elf-gcc -g -c lib.c -DROM # creates lib.o file
% ppc-elf-ld -g -r -o a.aux lib.o -lm # add library code

Then build the rest of your project, adding a.aux file to final link stage.

I would call it rom.o instead of a.aux, but that's a personal preference.

Thanks for the info, it makes sense. I did something slightly
different, but the overall result seems to be the same:

% ppc-elf-gcc -g lib.c -lm -Wl,-r -DROM -o rom.out
% ppc-elf-gcc -c lib.c -o lib.o
% ppc-elf-ld lib.o rom.out -T lib.lnk -o lib.out

I think this puts the crt code in ROM as well, including your entry point. This startup code then calls main() which resides in RAM, creating a dependency between your ROM library and the main application. Linking the same ROM code to another application may then not work as expected.

The way I suggested it, the crt code shoult end up in RAM, and can be different for each application.
.