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.

Referencing a linker label in C/C++

I have a linker label of a group created with the LOAD_START() operator - LOAD_START(app_vtable_start).  It happens to point to the beginning of my Cortex-M3 vector table.

What is the proper way to reference this in C/C++?

I have tried a few ways, but I keep getting too many de-references in the code that uses it, generating a fault.  I think I am not getting my de-references correct in C++.

Here is the latest iteration of how I am trying to do it (I have tried many unsuccessful ways):

extern unsigned long const * const ap_vtable_start;

if( (*app_vtable_start == 0xffffffffuL) )

{

// Do something

}

Here is the resulting assembly code:

LDR    R0, $C$CON1 - loads R0 with 0x00002000, which is the address of the vector table.

LDR    R0, [R0] - loads R0 with 0x20018000 which is the top of the stack.

LDR   R1, [R0] - attempts to load R1 from 0x20018000 which is beyond RAM and hence generates a fault.

CMP.W R1, #4294967295 - the compare that would happen if it would get here.

What am I doing wrong?

 

 

  • How about the following? Does it give you what you are looking for?

    extern unsigned long const ap_vtable_start;

    if( (app_vtable_start == 0xffffffffuL) )

    {

    // Do something

    }

  • Try:

    extern char app_vtable_start;
    
    #define APP_VTABLE_START (_symval(&app_vtable_start))
    
    if (APP_VTABLE_START == 0xffffffffuL)
  • I couldn't get this one to work (APP_VTABLE_START), kept giving me the address (0x00002000) instead of the value at the address (0x20018000).

    In addition to the extern unsigned long const app_vtable_start solution, I was also able to get the following to work:

    extern "C" void app_vtable_start( void );

    static unsigned long const * app_ptr = (unsigned long const *)app_vtable_start;

    if( (*app_ptr == 0xffffffffuL)

    I end up checking other values in the vector table so having a pointer I can use to move through the table is important.

  • Sorry, I misunderstood what you were trying to do.   Try the following:

    extern char app_vtable_start;
    
    #define APP_VTABLE_START ((unsigned long const *)_symval(&app_vtable_start))
    
    if (*APP_VTABLE_START == 0xffffffffuL)

    For anyone reading along, Aarti's version will work, but only on architectures where "long" is the same size as a data pointer, such as ARM.