This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Weak Link to library function does not keep library in final out/map file

Tool/software: TI C/C++ Compiler

I am trying to separate a library's bindings at linker time to have a weak bond between the application and the library. 

I have a function in the library called "GoMain".  If I call it, then the library is brought into the final binary, and it works...but the link feels strong between them in that if GoMain moves around, the application will have to know where it is. 

So, 1) GNU _attributes("section...") would work to put "GoMain" at a fixed location (let's say 0x80_0000, SRAM for C64+x). 

2) a function pointer could be implemented, such as

void* MyFunc = (void*) 0x800000; 

MyFunc();    // does not need to know GoMain's address, just calls the function at 0x80000.

Is this possible to do while ensuring GoMain's library is built into the final out file, but removing the direct call to "GoMain()"?

If not, is dynamic linking the answer?  (I have follow on questions on how this would work that I'm not sure  answers) 

Thanks,

Will

C6457

CCS 5.1.0900

CGT 7.3.23

  • How is it that GoMain moves around? Does it move around at run time, or is is loaded at a fixed, unknown at link time, address?
  • Sorry, that seems to cloud the original issue and question; I meant to say that GoMain() could move around without the gnu attributes (section). Also, the connection to the library call, "GoMain()", must be there for the entire out file to include the library code...otherwise, its dumped.  I'd like to include the text,data, etc sections even though "GoMain()" is no longer referenced directly with a GoMain() call from the Application.
     
    How can I "auto"-include the library code, without having a direct call to one of its members? Can it be done with a build setting? The compiler/linker see there is no link when I create a function pointer to a fixed-address, and seem to throw away all of the information contained in the library when generating my *.out file.

    My application's main reason to have a separate library is for a multi-stage boot approach, where GoMain's() library lives in ROM until I want to load it, then call "GoMain()" (i.e. the fixed-location function pointer that points to GoMain()'s address).

  • I'm still confused about the function GoMain.  Once the link is complete, is it at a fixed address that never changes?  Or, can the address of GoMain be different from run to run?  

    ixworks said:
    How can I "auto"-include the library code, without having a direct call to one of its members?

    Try the linker option --undef_sym.  Read about it in the C6000 assembly tools manual.

    Thanks and regards,

    -George

  • Hi George,

    In my solution, with using the --undef_sym, I would place GoMain() at a fixed location using the GNU attribute section functionality.

    Will