I am using different linker script. In some, a value is defined, in others, it is not defined:
DIRECTORY_ADDRESS = 0x80100000;
DIRECTORY_SIZE = 32M;
At execution, I want a default behavior when this value is not defined, and a special behavior when it is defined.
Classically, I get the values like this:
extern void * DIRECTORY_ADDRESS;
extern void * DIRECTORY_SIZE;
void f() {
void *dir_addr = &DIRECTORY_ADDRESS;
int dir_size = (int)&DIRECTORY_SIZE;
}
My first lead to conditionnaly execute code according to the existence of this value in linker script is the weak atttribute:
extern void * DIRECTORY_ADDRESS __attribute__ ((weak)) = 0x0;
extern void * DIRECTORY_SIZE __attribute__ ((weak)) = 0x0;
void f() {
if ( DIRECTORY_ADDRESS )
// special code
else
// default code
}
But it can't work, as I am initializing the pointer value, and not its address: even an undifined weak symbol has an address. So directory address is always != NULL.
I am pretty sure this problem has already been solved, but I can't find any related problem on the web.