Why clang may not be compatible with gcc for .a file generation?


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 and
clang has different default on whether -fPIC is enabled? Could anybody
help explain why there is such a difference? Thanks.

configure:3772: gcc -g -finstrument-functions
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

#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 {
                "\x1b[31;1mThe environment variable TRACE_OUTFILE must
be set.\x1b[m\n"
                , stderr

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

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) { }


clang works fine.

On some platforms GCC will create PIE by default. If clang doesn't match
that, it would certainly explain what you see. Try to compile your code
with -fPIE.