Using linker script assignments in shared object

Max Dmitrichenko dmitrmax@gmail.com
Wed May 28 13:29:00 GMT 2014


Hi!

I'm trying to define a value in linker script to be used in the shared object.

Suppose the following linker script:

PROVIDE_HIDDEN(test_ls_value = 5);


I have a test program with the following function:

extern int test_ls_value;

void show_test_value()
{
    printf("test value %p\n", &test_ls_value);
}

When this function is defined in the program object everything is OK.
The output is "test value 5".

But when I paste this code into shared object then I got some address
in the middle of memory address space. Though readelf outputs
following for this symbol:

552: 0000000000000005     0 NOTYPE  LOCAL  HIDDEN  ABS test_ls_value

I guess this is somehow connected with -fPIC but I'm not sure. Also I
don't understand if it possible to overcome this behavior. Any ideas?

With best regards,
  Max Dmitrichenko



More information about the Binutils mailing list