[cfe-dev] clang trunk: extern "C"/static problem

Richtarsky, Martin martin.richtarsky at sap.com
Thu Mar 14 08:14:56 PDT 2013


> -----Original Message-----
> From: Rafael Espíndola [mailto:rafael.espindola at gmail.com]
> Sent: Donnerstag, 14. März 2013 15:42
> To: Richtarsky, Martin
> Cc: cfe-dev at cs.uiuc.edu Developers; John McCall; Richard Smith
> Subject: Re: [cfe-dev] clang trunk: extern "C"/static problem
> 
> On 14 March 2013 09:34, Richtarsky, Martin <martin.richtarsky at sap.com> wrote:
> > Hi,
> >
> > it seems there is a bug in current trunk with regards to the symbols that
> are generated. At least clang 3.1, gcc 4.3.4 and gcc 4.8 behave differently
> here.
> >
> > test.cpp:
> >
> > extern "C"
> > {
> >
> > static void __attribute__((__used__)) func(char *a, char b)
> > {
> > }
> >
> > }
> >
> > clang++ test.cpp
> >
> > nm -C test*.o shows these generated symbols for the different compilers:
> >
> > test_clang31.o:
> > 0000000000000000 t func
> >
> > test_clang33.o:
> > 0000000000000000 t func(char*, char)
> >
> > test_gcc43.o:
> >                  U __gxx_personality_v0
> > 0000000000000000 t func
> >
> > test_gcc48.o:
> > 0000000000000000 t func
> >
> >
> > It looks like the static in conjunction with the extern "C" is causing a
> problem here. Should I file a bug?
> 
> The c++ standard
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.pdf)
> says
> 
> ------------------
> All function types, function names with external linkage, and variable
> names with external linkage have a language linkage.
> ------------------
> 
> Since static functions have internal linkage, they don't have a
> language linkage. That is, the extern "C" doesn't apply.
> 
> This was recently implemented in clang, and there was some discussion
> about maybe trying to change the standard instead. What problems is
> this causing?

Hi Rafael,

in this case the affected function is called from another function which is implemented in inline assembler, within the extern "C" scope. These symbols are emitted:

                 U func
0000000000000110 t func(long*, long)

Afterwards the link will fail because "func" is missing. The exact error is:

"relocation R_X86_64_PC32 against undefined symbol `func' can not be used when making a shared object; recompile with -fPIC"

(I compiled with -fPIC)

Best regards,
Martin




More information about the cfe-dev mailing list