[cfe-dev] clang symbol visibility question

Jean-Daniel Dupas devlists at shadowlab.org
Mon Oct 25 06:37:10 PDT 2010


Hello,

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

==============================================
clang++ --version
clang version 2.9 (trunk 117252)
Target: x86_64-apple-darwin10

clang++ -S -emit-llvm  -fvisibility=hidden Foo.cpp
cat Foo.s | grep hidden
	define hidden void @Foo(..…)


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.

Thanks


-- Jean-Daniel








More information about the cfe-dev mailing list