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.

Build warning when assigning symbols at link time?

Hi (first post!)

I get a build warning, which I'd like to get rid of =), about a symbol being redefined when assigning a value to it at link time:

/common_sections.cmd", line 47: warning #10188-D: 
symbol "useCacheSize" from file
"MyFile.cpp.obj" being redefined
useCacheSize = L2_CACHE_SIZE;

Hoping someone can help me out!

In my code I've defined a global symbol useCacheSize which is then used to set the L2 cache size.
volatile uint32_t useCacheSize;
..
switch (useCacheSize)
{
case use0Kcache:
CACHE_setL2Size( CACHE_0KCACHE);
break;
case use64Kcache:
CACHE_setL2Size( CACHE_64KCACHE);
break;
..
This symbol is then assigned at link time with the linker command file (common_sections.cmd) to tell our run time code how much L2 memory is available to use as cache:
useCacheSize = L2_CACHE_SIZE;

The Assembly user guide (spru186v) section 7.5.8 states that:
"The symbol should be defined externally. If it is not, the linker defines a new symbol and enters it into the symbol table."
I have tried to do exactly that, define the symbol 'externally', but I still get the aforementioned warning. Have I misunderstood something?

Thanks!
  • When you saty "externally", do you mean you have declared it "extern"?

    Also note that the linker defines symbols address only, that is "useCacheSize=.L2_CACHE_SIZE" place a symbol ad address L2_CACHE_SIZE, it doesn't allocate memory for the symbols and assign it to L2_CACHE_SIZE. You have to take the address of the symbol and interpret it as an intergal value:

    extern far uint32_t useCacheSize;

    ...

    unsigned int required_cache_size=(unsigned int)&useCacheSize;

    switch(required_cache_size)

    ....

  • I have forgotten to say that if you don't declare it "far" (or compile with the meory model far), the compiler could assume is is near and try to use the near base pointer that generate a wrong address. Normally yhe linker should generate an error, but it doesn't!

  • Hi Alberto,

    First of all, thank you for your input! It is greatly appreciated :)

    I took a look at the symbol useCacheSize in the debugger and it seems to be of type void pointer with a value of L2_CACHE_SIZE (0x40000 in this case). Apparently the linker command files did redefine the symbol, just as the warning message states (otherwise it would be of type uint32_t).

    Maybe the possibility to assign values to symbols is a relatively new feature? 

     spru186v section 7.5.8 Assigning symbols at Link Time:

    "Linker assignment statements allow you to define external (global) symbols and assign values to them at
    link time. You can use this feature to initialize a variable or pointer to an allocation-dependent value."

    The code I posted above works just fine. It's just that I get an annoying warning message (which everyone and their bosses keep bugging me about :( ). I tried your way as well, it works and without the warning message. It's just that I need the solution to be flexible. (I.e. others should be able to use my code with their own linker command file or my linker command file but without my code.) 

    To answer your question, no I do not have useCacheSize declared 'extern' in my code (I have it declared only as volatile). I believed that the user guide sentence "The symbol should be defined externally" meant that I should have the symbol declared in code rather than linker command files?

    Thanks again!

  • Well, maybe You have to move this thread to the CGT forum.

    Anyway, I suppose the linker manual omit to say the the symbol should be declare as "weak":

    #pragma WEAK(useCacheSize)

    unsigned int useCacheSize;

    ...

    if (useCacheSize==0)

      .... apply default...

    else

       ... use it...

    In the linker file useCacheSize=.... as before but without warning.