This is an archive of the discontinued LLVM Phabricator instance.

lib/CodeGen: Compile with -fvisibility=hidden when possible
Needs ReviewPublic

Authored by tstellar on Nov 4 2022, 12:43 AM.

Details

Reviewers
MaskRay
compnerd
Summary

I don't think there is any code there that is meant to be part of the
public LLVM API. This helps reduce the number of exported symbols in
the library:

Before:
$ nm -D libLLVM-16git.so | wc -l
33240

After:
$ nm -D libLLVM-16git.so | wc -l
26987

Diff Detail

Event Timeline

tstellar created this revision.Nov 4 2022, 12:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 12:43 AM
tstellar requested review of this revision.Nov 4 2022, 12:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 12:43 AM

I just realized my test build was not using LLVM_LINK_LLVM_DYLIB, so I missed some symbols that are actually used, so I need to add some export annotations for some functions.

The motivation looks good but a bunch of llvm/include/CodeGen APIs are used outside of llvm/ (note, clang/ flang/ bolt/ uses also count): https://sourcegraph.com/search?q=context:global+include+%22llvm/CodeGen/+-file:llvm/lib/+-file:llvm/include/llvm/+-file:llvm/unittests/&patternType=standard

I do like the idea in concept less in practice. The problem is that this is specific to the ELFish targets. I would prefer to handle this like my previously suggested approach of annotations (see D109192).

I do like the idea in concept less in practice. The problem is that this is specific to the ELFish targets. I would prefer to handle this like my previously suggested approach of annotations (see D109192).

Well they're not mutually exclusive either. The existing approach with visibility works for some configurations, and can be extended to cover more areas of the libraries, without blocking D109192 when that is ready in a mergeable shape, right?

(FWIW, hidden visibility is usable on mingw targets these days too, so it's not only ELF.)

tstellar updated this revision to Diff 475297.Nov 14 2022, 3:29 PM

Export functions needs for other sub-projects. Still not enough to run
unittests.

Is this version working with various llvm dependent projects? You as a distributor shall know:)

Is this version working with various llvm dependent projects? You as a distributor shall know:)

No, so far I'm testing with a build of clang;lld;lldb;compiler-rt and there are still unittests that won't compile. I wanted to get the patch update in Phabricator to get feedback on how the API annotations are done, before I go through and update everything.

I do like the idea in concept less in practice. The problem is that this is specific to the ELFish targets. I would prefer to handle this like my previously suggested approach of annotations (see D109192).

I've updated my patch with some annotations now. Is this more what you had in mind?

compnerd added inline comments.Jul 2 2023, 8:16 PM
llvm/CMakeLists.txt
1183

This condition is pretty unmanageable IMO. Can we perhaps split it up into a set of named conditions?