[PATCH] D147832: [libcxx] Introduce clang::lto_visibility_public attribute

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 7 18:29:34 PDT 2023


leonardchan created this revision.
leonardchan added reviewers: pcc, ldionne, phosek, mcgrathr.
leonardchan added a project: libc++.
Herald added subscribers: inglorion, Prazek.
Herald added a project: All.
leonardchan requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

In fuchsia, we build our shared libs with `-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` and -fvisibility=hidden` to ensure all symbols manifested from classes in libc++ headers are hidden. But if we build with LTO, then then each of the classes included from libc++ headers have hidden LTO visibility <https://clang.llvm.org/docs/LTOVisibility.html> (which is unique to LTO and separate from ELF visibility). This is an issue if we ship a libc++.so that was not built with LTO because those same libc++ classes will have default LTO visibility. This can lead to incorrect behavior because LTO will only work if classes used across multiple linkage units have default LTO visibility, which can be achieved by either compiling everything with LTO and default visibility, or explicitly adding `[[clang::lto_visibility_public]]` to those classes. To ensure that we can still use `-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` and -fvisibility=hidden` to make sure libc++ symbols have hidden visibility, we can apply `[[clang::lto_visibility_public]]` to libc++ classes which effectively prevents whole program devirtualization from operating on them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147832

Files:
  libcxx/include/__config
  libcxx/include/__hash_table
  libcxx/include/__iterator/wrap_iter.h
  libcxx/include/__memory/shared_ptr.h
  libcxx/include/__threading_support
  libcxx/include/__tree
  libcxx/include/deque
  libcxx/include/ext/hash_map
  libcxx/include/forward_list
  libcxx/include/map
  libcxx/include/set
  libcxx/include/unordered_map
  libcxx/include/unordered_set
  libcxx/include/valarray
  libcxx/include/vector

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147832.511832.patch
Type: text/x-patch
Size: 24401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230408/79f37633/attachment-0001.bin>


More information about the llvm-commits mailing list