Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to group objects from static library in a section?

310 views
Skip to first unread message

wyse...@yahoo.com.br

unread,
Mar 25, 2008, 2:22:59 PM3/25/08
to
Hi all,

Using GNU linker ld, I'd like to create a section ROM_LIB grouping
some routines and all its dependencies, including the implicit called
ones such as math routines provided by libm.a. Going down in more
details, my intention is creating a stand-alone ROM image containing
several utility routines that will be used by programs loaded in RAM.
The C code is something like:

void rom_routine() __attribute__((section("ROM_LIB")))
void rom_routine() {
...
c = a / b; // Will call stuff from libm.a that I want be placed
in ROM_LIB
...
}

I tried unsucessfully a linker script similar to:

SECTIONS {
.text : { .text .text.* } > RAM
ROM_LIB : { *(ROM_LIB) libm.a(*) } > ROM
...
}

Even if this solution were working, it would require one
independent compilation for the ROM library and other for the main()
code because this link script is adding all math routines to ROM_LIB
(even called by main()) instead of only those called by ROM routines.

Any ideas?

Thanks in advance

Walter

Andy Sinclair

unread,
Mar 26, 2008, 4:48:45 AM3/26/08
to
wyse...@yahoo.com.br wrote:
>Hi all,
>
> Using GNU linker ld, I'd like to create a section ROM_LIB grouping
>some routines and all its dependencies, including the implicit called
>ones such as math routines provided by libm.a. Going down in more
>details, my intention is creating a stand-alone ROM image containing
>several utility routines that will be used by programs loaded in RAM.


I have done this, an example follows:

Declaration:

__attribute__((section(".rom_code"))) void rom_function();


Linker script entries:

MEMORY
{
ROM_CODE: o = 0x0000 , l = 0xF800
}
SECTIONS
\n\
{
\n\
.rom_code: {*(.rom_code)} > ROM_CODE
}


You will probably also need to put the explicitly located functions in
their own source file.

Andy

wyse...@yahoo.com.br

unread,
Mar 26, 2008, 12:52:24 PM3/26/08
to
Hi Andy,

Your solution works for placing the rom_function() into ROM_CODE
memory but according to my tests, it doesn' t place the library-
supplied routines called by rom_function() into ROM_CODE too, as I am
looking for. These are the test inputs I used:

% cat test.c <<HERE
#include <stdio.h>
#include <math.h>

void _start() { main(); }

extern int main();

volatile float a, b, c;
volatile float res;

__attribute__((section(".rom_code"))) void rom_function();

void rom_function() {
c = a / b; // Use implicitely libm.a routine
res = sin(c); // Use explictly libm.a routine
}

int main() {
rom_function();
return 0;
}
HERE

% gcc -g test.c -lm -Wl,-T lib.lnk

These are the references to .rom_code section. Only the
rom_function() routine is there:

% objdump -x a.out | grep rom_code
7 .rom_code 00000070 00008000 00008000 00018000 2**2
00008000 l d .rom_code 00000000
00008000 g F .rom_code 00000070 rom_function

The sin() was placed in .text and not in .rom_code:

% objdump -x a.out | grep sin
00000000 l df *ABS* 00000000 s_sin.c
00000000 l df *ABS* 00000000 k_sin.c
00001438 g F .text 000000f8 __kernel_sin
00000514 g F .text 000000ec sin

The linker script is:

MEMORY
{
RAM_CODE : o = 0x0000 , l = 0x8000
ROM_CODE : o = 0x8000 , l = 0x8000
}

SECTIONS
{
.bss : { *(.bss) } > RAM_CODE
.sbss : { *(.sbss) } > RAM_CODE
.rodata : { *(.rodata*) } > RAM_CODE
.got2 : { *(.got*) } > RAM_CODE
.data : { *(.data) } > RAM_CODE
.sdata : { *(.sdata*) } > RAM_CODE

.text : { *(.text .text.*) } > RAM_CODE

.rom_code : { *(.rom_code) } > ROM_CODE
}

Any comments?

Tks

0 new messages