How to group objects from static library in a section?

Discussion in 'C Programming' started by wyse03br@yahoo.com.br, Mar 27, 2008.

  1. Guest

    Hi all,

    Using GNU linker ld, I'd like to create a section .rom_code
    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 (with all its dependencies) that will be used
    by programs loaded in RAM.
    The C code is something like:


    % 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

    Compiling and linking in the usual way, only the rom_function()
    went to ROM, not its dependencies. These are the references
    to .rom_code section, only the
    rom_function() routine can be found 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 used 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 ideas on how to put also the rom_function() dependencies into
    ROM?

    Tks

    Walter
     
    , Mar 27, 2008
    #1
    1. Advertising

  2. jacob navia Guest

    wrote:
    > Hi all,
    >
    > Using GNU linker ld, I'd like to create a section .rom_code
    > 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 (with all its dependencies) that will be used
    > by programs loaded in RAM.
    > The C code is something like:
    >
    >
    > % 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
    >
    > Compiling and linking in the usual way, only the rom_function()
    > went to ROM, not its dependencies. These are the references
    > to .rom_code section, only the
    > rom_function() routine can be found 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 used 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 ideas on how to put also the rom_function() dependencies into
    > ROM?
    >
    > Tks
    >
    > Walter



    I think you have to rebuild the C library to put the
    __attribute__((section(".rom_code")))
    in each of the functions you want in ROM.

    Normally, the linker assumes certain sections from the
    attributes of the sections in the object files.
    (See my previous articles about linkers in this forum).

    To put your library functions in the rom you should
    recompile the library with the attributes in the object
    file. This is surely not an easy task!


    P.S. Why don't you put ALL code in the ROM?

    IN that case you would just modify the linker script.


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Mar 27, 2008
    #2
    1. Advertising

  3. Guest

    Hi,

    Putting all the library routines in .rom_code section has a
    important drawback - it will place in ROM also the library routines
    called by the code in RAM. It is a problem for me because the ROM
    contents shouldn't depend on the code in RAM. Answering your question,
    I can't put all the code in ROM because ROM contents behaves like a
    library for RAM code - ROM is programmed *before* the code targetted
    to RAM is compiled, which is dynamically loaded by a bootstrap code in
    ROM reading the code targetted to RAM through a special interface in
    my board.

    What I am looking for is a way to extend the section attribute
    attached to a routine to all its dependencies. There are some
    compilers/linkers that allow that (CodeWarrior, but not using
    attributes) and GNU linker seems to be equiped for that - there is a
    call graph analysis done during --gc-section optimization.

    Any help is welcome.

    Tks

    On Mar 27, 2:14 pm, jacob navia <> wrote:
    > I think you have to rebuild the C library to put the
    > __attribute__((section(".rom_code")))
    > in each of the functions you want in ROM.
    >
    > Normally, the linker assumes certain sections from the
    > attributes of the sections in the object files.
    > (See my previous articles about linkers in this forum).
    >
    > To put your library functions in the rom you should
    > recompile the library with the attributes in the object
    > file. This is surely not an easy task!
    >
    > P.S. Why don't you put ALL code in the ROM?
    >
    > IN that case you would just modify the linker script.
    >
    > --
    > jacob navia
    > jacob at jacob point remcomp point fr
    > logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
     
    , Mar 27, 2008
    #3
  4. jacob navia Guest

    wrote:
    > What I am looking for is a way to extend the section attribute
    > attached to a routine to all its dependencies. There are some
    > compilers/linkers that allow that (CodeWarrior, but not using
    > attributes) and GNU linker seems to be equiped for that - there is a
    > call graph analysis done during --gc-section optimization.


    Well, here you need an expert in your specific environment
    and the guys that wrote the port of gnu "ld" to your environment.

    I am not an expert in "ld" and I can't help you further. In
    any case, compiling the libc library with all functions
    including this attribute should work but that would be
    a significant amount of work. Maybe better options exists.

    Just ask to the gnu ld support people.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Mar 27, 2008
    #4
  5. Jack Klein Guest

    On Thu, 27 Mar 2008 10:02:17 -0700 (PDT), wrote
    in comp.lang.c:

    > Hi all,
    >
    > Using GNU linker ld, I'd like to create a section .rom_code
    > 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 (with all its dependencies) that will be used
    > by programs loaded in RAM.
    > The C code is something like:


    [snip]

    Your question has nothing at all to do with the C language, and
    everything to do with your particular tool set and target. C does not
    have ROM images or sections.

    You need to ask this question in a GNU support group, or, since you
    mention ROM, perhaps in news:comp.arch.embedded where such questions
    for embedded system development are topical. But if you ask there,
    you had better provide more information, such as the target and
    version of the tools.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Mar 27, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RnVlaG5lcg==?=
    Replies:
    2
    Views:
    6,730
    =?Utf-8?B?RnVlaG5lcg==?=
    Nov 15, 2005
  2. gorda
    Replies:
    5
    Views:
    5,068
    akhyls
    Mar 7, 2010
  3. pramod
    Replies:
    1
    Views:
    329
    Thomas Wintschel
    Nov 29, 2003
  4. Victor Bazarov
    Replies:
    11
    Views:
    759
    James Kanze
    Dec 9, 2009
  5. kampy
    Replies:
    9
    Views:
    353
    Steven D'Aprano
    Oct 19, 2012
Loading...

Share This Page