This is an archive of the discontinued LLVM Phabricator instance.

Use __attribute__((internal_linkage)) when available.
ClosedPublic

Authored by EricWF on Sep 15 2016, 5:43 PM.

Details

Summary

This patch has been a long time coming (Thanks @eugenis). It changes _LIBCPP_INLINE_VISIBILITY to use __attribute__((internal_linkage)) instead of __attribute__((visibility("hidden"), always_inline)).

The point of _LIBCPP_INLINE_VISIBILITY is to prevent inline functions from being exported from both the libc++ library and from user libraries. This helps libc++ better manage it's ABI.
Previously this was done by forcing inlining and modifying the symbols visibility. However inlining isn't guaranteed and symbol visibility only affects shared libraries making this an imperfect solution. internal_linkage improves this situation by making all symbols local to the TU they are emitted in, regardless of inlining or visibility. IIRC the effect of applying __attribute__((internal_linkage)) to an inline function is the same as applying static.

For more information about the attribute see: http://lists.llvm.org/pipermail/cfe-dev/2015-October/045580.html

Most of the work for this patch was done by @eugenis.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 71578.Sep 15 2016, 5:43 PM
EricWF updated this revision to Diff 71579.
EricWF retitled this revision from to Use __attribute__((internal_linkage)) when available..
EricWF updated this object.
EricWF added reviewers: mclow.lists, eugenis.
EricWF added subscribers: cfe-commits, eugenis.

Revert accidental change.

EricWF updated this object.Sep 15 2016, 6:30 PM
eugenis accepted this revision.Sep 15 2016, 6:34 PM
eugenis edited edge metadata.

Looks great.
Thank you for seeing it through!

This revision is now accepted and ready to land.Sep 15 2016, 6:34 PM
EricWF updated this revision to Diff 71590.Sep 15 2016, 7:30 PM
EricWF edited edge metadata.
  • Add always_inline to _LIBCPP_INLINE_VISIBILITY. In future I think only _LIBCPP_ALWAYS_INLINE should actually apply always_inline, but I'll make that change separately.
  • Change _LIBCPP_ALWAYS_INLINE to use internal_linkage as well.

I'll commit this change tomorrow barring any objections.

EricWF closed this revision.Sep 24 2016, 8:22 PM