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.

CCS 3.3 - priority linker option

 Hi

This is with respect to the  -priority linker option available in code composer studio.  Need help in understanding the same.

 

Customer is  using ccs version 3.3.38

 

As per the help doc –priority option details is as below.

 

 

The -priority option is used to provide an alternate search mechanism for libraries. –priority causes each unresolved reference to be satisfied by the first library that contains a definition for that symbol.

For example:

 

objfile   references A

lib1      defines B

lib2      defines A, B; obj defining A references B

 

% cl2000 -v28 -z objfile lib1 lib2

Under the existing model, objfile resolves its reference to A in lib2, pulling in a reference to B, which resolves to the B in lib2.

Under -priority, objfile resolves its reference to A in lib2, pulling in a reference to B, but now B is resolved by searching the libraries in order and resolves B to the first definition it finds, namely the one in lib1.

 

This option is useful for libraries that want to provide overriding definitions for related sets of functions in other libraries without having to provide a complete version of the whole library.

For example, suppose you want to override versions of malloc and free defined in the rts6200.lib without providing a full replacement for rts6200.lib. Using -priority and linking your new library before linking rts6200.lib guarantees that all references to malloc and free resolve to the new library.

 

This option is intended to support linking programs with DSP/BIOS where situations like the one illustrated above occur.

 

I am trying to implement the same but it is not working for me.

 

Please find the example files attached to this mail and the detailed steps followed as below.

 

1)      Example files are as below -

 

                MultipleTest.cpp –

                Main test driver calling the functions defined in other files –

                #include "testharness.h"

                #include "MultipleDef.h"

 

                void run_test()

                {

                                function(1,2);

                                function1(3, 4);

                                function2(6, 7);

                }

 

                MultipleTest1.cpp –

                Has 3 functions defined in it namely,

                int function(int a, int b) {  return a+b+1; }

                int function1(int x, int y) {  return x/y; }

               int function2(int s, int d) {  return s/d; }

 

                MultipleTest2.cpp –

                Has 1 overridden functions defined

                int function(int g, int u){               return g+u+15;}  // overriding the function defined in MultipleTest1.

 

2)      Created lib files of MultipleTest1.lib and MultipleTest2.lib using command

             ar2000.exe -a  MultipleTest1.lib  MultipleTest1.o

             ar2000.exe -a  MultipleTest2.lib  MultipleTest2.o

 

3)      Linking files in the below sequence to create executable.

                 LINK_FLAGS_HEAD = -z -c -priority -heap 0x400 -stack0x160 -w -x -I$(CCS_HOME)\C2000\cgtools\lib

                 LINK_FLAGS_TAIL = -lrts2800_ml_eh.lib $(SIM_TEST_PATH)\F2812_Sim.cmd

 

             cl2000.exe $( LINK_FLAGS_HEAD) $( LINK_FLAGS_TAIL) MultipleTest.o    MultipleTest1.lib   MultipleTest2.lib   -m" MultipleTest.map" -o MultipleTest.out                                                                

- With this sequence final executable will be having all the defination from the MultipleTest1.lib

 

             cl2000.exe $( LINK_FLAGS_HEAD) $( LINK_FLAGS_TAIL) MultipleTest.o    MultipleTest2.lib   MultipleTest1.lib   -m" MultipleTest.map" -o MultipleTest.out                                                                                             

                         - Changing the sequence to get the overriding function defination in executable.

                         - but instead I am getting multiple defination error here.

 

Some observation I found during the experiment –

 

Priority option works only if below condition satisfies.

- Both MultipleTest1.lib and MultipleTest2.lib should have same number of the function

- function signature in both file should be same.

- If we have different number of function defination in MultipleTest1.lib and MultipleTest2.lib file.

It works only if I link the file having all defination linked first.

If I link file having only the overriden function definition first it throw error message saying multiple defination.

 

Please let me know If I am missing something or lack in understanding –priority purpose.

  • Hi,

    Usually the linkers are not able to partially link-in a single segment. When you link-in an obj, you link in ALL the symbols defined in it.

    So, if function(), function1() and function2() are in the same compilation unit, and you reference function1, also function and function2 will be linked in even if You don't use them.

    If, during the linking process, due to your priority directive, the linker has already link function() from MultipleTest2.obj, it give multiple definition when trying to link in the obj from MultipleTest1.obj, since it cannot simple extract function1() and function2() only.

    You have to break MultipleTest1.cpp in two file, one for the overridable function, one for the other, so to obtain two .obj.

  • The post by Alberto Chessa is correct.  This whole thing is easier to understand if every object file in the library is limited to one function.

    Further, you are linking with the options -priority and -x.  These options work at cross-purposes.  I'm not sure what happens when you use both.  To keep things simple, remove the -x.

    Thanks and regards,

    -George 

  • Hi

     

    user document mentions like below, can you please provide some direction.

     

    This option is useful for libraries that want to provide overriding definitions for related sets of functions in other libraries without having to provide a complete version of the whole library.

    For example, suppose you want to override versions of malloc and free defined in the rts6200.lib without providing a full replacement for rts6200.lib. Using -priority and linking your new library before linking rts6200.lib guarantees that all references to malloc and free resolve to the new library.

  • Venkatadri Shantaram84961 said:
    user document mentions like below, can you please provide some direction.

    I'm not sure that I can.  This documentation is correct, as far as it goes.  It is silent on the issues you encountered.  It does not talk about what happens when a library module supplies the definition of more than one function.  And it does not mention that you should not use -priority in combination with -x.  

    Thanks and regards,

    -George