Hello,
In gcc 4.1.0 something changed so when the -O2 option is present
addresses of static functions can not be assigned to pointer variables
when compiling position independent code (-fPIC). Check the example
below and tell me if this behavior is a feature or a bug.
So the code below generates no error when built into dynamic library
when the "static" specifier is commented.
With the "static" specifier uncommented there is no error only when the
-O2 option is not present.
#include <stdio.h>
/*static*/ void dummy_func(void)
{
printf("dummy_func\n");
}
void (*my_func_ptr)(void)=NULL;
int main(int argc, char** argv)
{
my_func_ptr = dummy_func;
my_func_ptr();
return 0;
}
Simplified command line used for the test:
#compile
gcc -c -O2 -fPIC dummy.c
#link
gcc -shared -o dummy.so -fPIC dummy.o
#output if the above conditions are not met
/usr/bin/ld: dummy.o: relocation R_X86_64_PC32 against `dummy_func' can
not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
Thanks,
Vladimir Vassilev