Hello,
The problem is still a valid issue. After looking around I figured out
-fno-unit-at-a-time is needed to solve some problem with building linux
modules. But this flag is only used for the gcc versions which support
the option, but not for (and newer) version than gcc 4.0.0 although they
also support it.
The excerpt below is from ./arch/i386/Makefile:
CFLAGS += $(shell if [ $(call cc-version) -lt
0400 ] ;
then echo $(call cc-option,-fno-unit-at-a-time); fi ;)
So I guess there has to be a related cause for linux maintainers to stop
using this option since 4.0.0 ... and probably it is the same with my
case ? ... Can you give me some clues?
Regards,
Vladimir
Vladimir Vassilev wrote:
Andrew Haley wrote:
Vladimir Vassilev writes:
> 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
WORKSFORME gcc version 4.1.1 x86_64-redhat-linux.
Try a more recent version; if that doesn't work, tell us more about
your setup.
Andrew.
zorro:~ $ cat dummy.c
#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;
}
zorro:~ $ /usr/bin/gcc -c -O2 -fPIC dummy.c
zorro:~ $ /usr/bin/gcc -shared -o dummy.so -fPIC dummy.o
zorro:~ $ /usr/bin/gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
Hello Andrew,
My bad. I have been too fast in my conclusion and overlooked some
parameters. Actually the problem requires three command line
parameters '-O2', '-fno-unit-at-a-time' and '-finline-functions'. If
either of those is not added everything works fine.:
gcc -c -O2 -fno-unit-at-a-time -finline-functions -fPIC dummy.c
Then linking fails with:
gcc -O2 -shared -o dummy.so -fPIC dummy.o
I am looking into why '-fno-unit-at-a-time' was needed and if I can
remove its use in case this option is no longer needed.
Regards,
Vladimir