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.

How to replace functions in runtime libraries ?



Hi, everyone,

I'm working with CCS5.3 and sys/bios. Now we want to replace malloc/free functions with our private version.

We're using ELF for DSP executable, and from the result of nm utility, seems like malloc and free are not weak functions.

Is there any way we can do this ?

Thanks in advance !

  • There are two ways you may supply your private implementation of malloc and free.  

    If they are C files that are built just like other C files in your application ... Then there is nothing further you need to do.  The linker will resolve references to malloc and free to your versions, and will not use malloc and free from the BIOS or RTS libraries.

    If your implementation of malloc and free is supplied in a custom library ... Do not use the linker option --reread_libs (AKA -x).  Use --priority and insure the linker sees your library before any others.

    Thanks and regards,

    -George

  • Hi, George, thanks for your kindly info !

    Besides the malloc/free, we also want to replace abort function.
    Do those 2 methods work for abort ? (abort is called by System_Abort(), we actually want to redirect System_abort to our private implementation)

    And, is there any detailed document or user manual for the 2 methods described by you ?

    Thanks.

  • PENG HUANG said:
    Do those 2 methods work for abort ?

    Yes.  The technique is general, and not specific to any symbol.  It works the same for both functions and data.

    PENG HUANG said:
    is there any detailed document or user manual for the 2 methods described by you ?

    Please see the section titled Exhaustively Read and Search Libraries in the C6000 assembly tools book.  (This book is specific to the C6000 processor family.  However, this particular section applies to any TI linker.)  

    This section does not mention that any symbols already provided in the user's code, prior to any library being considered, always take precedence.

    Another wrinkle that needs to be described ... The granularity of control is an input section, not a symbol.  An input section can define more than one symbol.  Suppose, for instance, that abort and System_Abort are both defined in the same .text section of the same file.  If the linker brings in that input section, then both of those symbols will be defined.  This could cause a symbol redefinition error if you supply your own definition of abort.  Note this scenario is just an example.  I don't know whether the BIOS library supplies the functions abort and System_Abort in the same input section.  If I had to guess, I would say they are not in the same input section.

    Thanks and regards,

    -George

  • Thanks for your help, George ! This is really helpful to us !