This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Create internal namespace that hides all symbols.
AbandonedPublic

Authored by EricWF on Mar 26 2015, 11:23 PM.

Details

Summary

Currently functions and types that are pure implementation must be individually annotated with a DSO visibility attribute. This requires tedious repetition and is prone to errors.

As it stands there are a number of symbols within libc++ that do not have a visibility attribute. These symbols may or may be compiled into the DSO depending on the compilation flags. This leads to the DSO providing an unstable and unmanageable set of symbols.

This patch creates a nested namespace __libcpp_internal that sets the visibility to "hidden" for all symbols within it. Classes and functions that are pure implementation details should live within this namespace. This way the symbols don't have to be individually annotated.

Slowly but surely symbols should be moved to this namespace. Migrating code into this namespace will be tricky. We will have to ensure that no platform already ships a DSO that contains the candidate symbols.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 22777.Mar 26 2015, 11:23 PM
EricWF retitled this revision from to [libcxx] Create internal namespace that hides all symbols..
EricWF updated this object.
EricWF edited the test plan for this revision. (Show Details)
EricWF added a subscriber: Unknown Object (MLST).
mclow.lists edited edge metadata.Jun 23 2015, 8:33 AM

This would be more compelling if you had examples of such symbols, and moved a few of them into this namespace.

EricWF updated this revision to Diff 30069.Jul 17 2015, 9:34 PM
EricWF edited edge metadata.

Address @mclow.lists comments. Use the three symbols from D8651 as examples.

Also add tests using sym_check that ensure no symbols within the __libcpp_internal namespace are visible in the resulting dylib.

GCC 4.0 seems to have attributes on namespaces and we should require GCC >= 4.7.
I can't seem to find any documentation about when Clang supports visibility attributes on namespaces but it I think it works for all clang versions.

Confirmed working on GCC 4.6 and Clang 3.2.

danalbert added inline comments.Jul 17 2015, 10:37 PM
test/libcxx/symbols/inline_namespace.sh.cpp
2

within

test/libcxx/test/config.py
640

Why can't we check the static lib? The symbols will still be hidden either way.

643

This is always true.

670

Why sys.path (PYTHONPATH)?

EricWF marked 3 inline comments as done.Jul 18 2015, 9:19 AM

Address @danalbert's comments.

test/libcxx/test/config.py
640

We can check a static library. This branch selects libc++.a for checking if it exists. Otherwise we try libc++.dylib or libc++.so.

643

Good catch. That should be an 'else'.

670

Probably a mistake. I thought sys.path and os.environ['PATH'] were essentially the same. I'll remove it.

EricWF updated this revision to Diff 30082.Jul 18 2015, 9:26 AM
EricWF marked 3 inline comments as done.

Make changes requested by @danalbert.

EricWF abandoned this revision.Dec 15 2015, 1:32 PM

There hasn't been much interest in this approach and it won't work with the new linkage attributes.