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

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Mar 14 07:41:31 PDT 2013


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?

> Best regards,
> Martin
>

Cheers,
Rafael



More information about the cfe-dev mailing list