Does gcc enable -fPIC by default?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have the following trace.c file compiled with the following command
with clang.

$ clang -Wall -pedantic -c -o trace.o trace.c
$ ar cr  libtrace.a trace.o
$ ranlib libtrace.a

Then, I run configure from a GNU package, which gives the following
error. It asks to recompile the .a with -fPIC.

Is it because gcc enables -fPIC by default, but clang does not? I
don't see this documented. Or it is due to some other reasons. On what
systems gcc enables -fPIC by default?

Thanks.

       -fPIC
           If supported for the target machine, emit
position-independent code, suitable for dynamic linking and avoiding
any limit on the
           size of the global offset table.  This option makes a
difference on the m68k, PowerPC and SPARC.

           Position-independent code requires special support, and
therefore works only on certain machines.

           When this flag is set, the macros "__pic__" and "__PIC__"
are defined to 2.

configure:3772: gcc -g -finstrument-functions
-L/root/linux/bin/wrappercomposite/src/xplat/llvmxplat/src/mkvar/bin/Linux
conftest.c -ltrace >&5
/usr/bin/ld: /root/linux/bin/wrappercomposite/src/xplat/llvmxplat/src/mkvar/bin/Linux/libtrace.a(trace.o):
relocation R_X86_64_32S against `.bss' can not be used when making a
PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

//trace.c
#include <stdio.h>
#include <stdlib.h>
//#include <time.h>

static FILE *fp_trace;

void __attribute__ ((constructor)) trace_begin (void) {
    const char *s=getenv("TRACE_OUTFILE");
    if(s) {
        fp_trace = fopen(s, "w");
    } else {
        fputs(
                "\x1b[31;1mThe environment variable TRACE_OUTFILE must
be set.\x1b[m\n"
                , stderr
                );
        exit(1);
    }
}

void __attribute__ ((destructor)) trace_end (void) {
    if(fp_trace != NULL) {
        fclose(fp_trace);
    }
}

void __cyg_profile_func_enter (void *func,  void *caller) {
    if(fp_trace != NULL) {
        //fprintf(fp_trace, "e %p %p %lu\n", func, caller, time(NULL) );
        fprintf(fp_trace, "%p\t%p\n", func, caller);
    }
}

void __cyg_profile_func_exit (void *func, void *caller) { }


--
Regards,
Peng


-- 
Regards,
Peng



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux