This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Make _LIBCPP_TYPE_VIS export members
ClosedPublic

Authored by smeenai on Oct 3 2016, 12:29 PM.

Details

Summary

Most classes annotated with _LIBCPP_TYPE_VIS need to have at least some
of their members exported, otherwise we have a lot of link errors when
linking against a libc++ built with hidden visibility. This also makes
_LIBCPP_TYPE_VIS be consistent across platforms, since on Windows it
already exports members.

With this change made, any template methods of a class marked
_LIBCPP_TYPE_VIS will also get default visibility when instantiatied,
which is not desirable for clients of libc++ headers who wish to control
their visibility; this is the same issue as PR30642. Annotate all
problematic methods with an explicit visibility specifier to avoid this.

The problematic methods were found by running bad-visibility-finder [1]
against the libc++ headers after making the _LIBCPP_TYPE_VIS change. The
small methods were marked for inlining; the larger ones hidden.

[1] https://github.com/smeenai/bad-visibility-finder

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai updated this revision to Diff 73323.Oct 3 2016, 12:29 PM
smeenai retitled this revision from to [libc++] Make _LIBCPP_TYPE_VIS export members.
smeenai updated this object.
smeenai added reviewers: compnerd, EricWF, mclow.lists.
smeenai added a subscriber: cfe-commits.
EricWF edited edge metadata.Oct 7 2016, 2:51 PM

Why do you want to build libc++.so with hidden visibility? What's wrong with the existing way we build libc++.so?

Why do you want to build libc++.so with hidden visibility? What's wrong with the existing way we build libc++.so?

There's nothing wrong with the existing way, per se. I personally prefer hidden visibility semantics because I come from a Windows background and hidden visibility matches up well with DLL semantics, but the first section of https://gcc.gnu.org/wiki/Visibility covers the advantages of hidden visibility pretty well.

Ping.

The way I see it, this doesn't change anything for people not building with hidden visibility (which should be most people, including the buildbots), but it does make _LIBCPP_TYPE_VIS more useful (and consistent with the existing Windows behavior) for people building (or attempting to build) with hidden visibility.

Ping.

I used @EricWF's ABI list verification work to confirm that this diff doesn't change the ABI of libc++ on both Darwin and Linux, so it should be completely safe.

Building with hidden visibility on top of this patch gives the following ABI removals: P7937. I'll be going through this list over the next few days to figure out if the omissions are actually correct or if they're indicative of missing source export annotations. D26823 resulted from this effort.

I should clarify that the ABI omissions are for Linux.

D27430 should unblock this.

smeenai planned changes to this revision.Dec 12 2016, 6:04 PM

Hidden visibility also requires extern template declarations to expand to default visibility (as opposed to just default type visibility) to be feasible. Will fix annotations there and then roll that macro change into this diff.

smeenai requested a review of this revision.Dec 19 2016, 7:53 PM

Actually, I think this can stand on its own. I'll do the extern template fixes in another diff.

Also, ping :)

EricWF accepted this revision.Dec 30 2016, 2:02 AM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Dec 30 2016, 2:02 AM

Not gonna submit this till D27430 has been submitted (will address comments on that one after holidays).

Yeah, that sounds good. I want to do more investigation into this as well.

EricWF requested changes to this revision.Jan 16 2017, 5:49 PM

Actually I probably shouldn't have approved this due to http://llvm.org/PR30642. I forgot about that when I last reviewed this.

This revision now requires changes to proceed.Jan 16 2017, 5:49 PM

Actually I probably shouldn't have approved this due to http://llvm.org/PR30642. I forgot about that when I last reviewed this.

Yup. I wrote https://github.com/smeenai/bad-visibility-finder to find all problematic instances, and D27430 fixes all the issues caused by this diff (I haven't gotten around to addressing the comments on that yet).

smeenai updated this revision to Diff 85816.Jan 25 2017, 3:05 PM
smeenai edited edge metadata.
smeenai edited the summary of this revision. (Show Details)
smeenai removed a reviewer: compnerd.

Folding D27430 and addressing comments from that diff.

smeenai updated this revision to Diff 87911.Feb 9 2017, 4:26 PM

Rebase and ping

smeenai updated this revision to Diff 90109.Feb 28 2017, 5:54 PM

Rebase atop D29157 and switch to _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS

This revision was automatically updated to reflect the committed changes.