clang symbol visibility question


I'm playing with clang++ and try to compile some C++ project but I have a problem with symbol visibility (that I don't have with GCC).

First, I'm use to compile all my projects using the -fvisibility=hidden to make sure I'm only exporting public symbols.

I'm including a system header (<CoreAudio/CoreAudioTypes.h>) which define structs inside an extern "C" block.

extern "C" {
  struct AudioTimeStamp {
    // misc fields
  typedef struct AudioTimeStamp AudioTimeStamp;

As I'm using -fvisibility=hidden, the structs are marked as private_extern (maybe they shouldn't as we are in an extern "C" block).

Now, in my header, I declare a function that take a pointer on AudioTimeStamp:

extern "C" __attribute__((visibility("default"))) void Foo(AudioTimeStamp *ts);

As the argument is of a type marked 'private extern', clang++ ignores the visibility attribute of the function and marks it as private_extern which result in a non-exported symbol.

Here is a reduced test case:
======================= Foo.cpp ======================
extern "C" {
  struct AudioTimeStamp { int field; };
  typedef struct AudioTimeStamp AudioTimeStamp;

extern "C" __attribute__((visibility("default"))) void Foo(AudioTimeStamp *timeStamp);

void Foo(AudioTimeStamp *timeStamp) {}

And so the question:

Is this a bug in clang++, or am I doing something wrong with visibility. And if I'm doing something wrong, what should I do instead.

It looks like you found an interesting bug in clang's handling of
visibility in C++. I reduce the test a bit:

struct AudioTimeStamp { int field; };
void __attribute__((visibility("default"))) Foo (struct
AudioTimeStamp *timeStamp) { }

Compile it as C++ code and you get a hidden function. Compile it as C
and you get one with default visibility. Both gcc and g++ will produce
a function with default visibility.

Would you mind adding this to bugzilla?


-- Jean-Daniel



-- Jean-Daniel