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.