Skip to content

Commit 0dbcb36

Browse files
committed
CMake: Make most target symbols hidden by default
Summary: For builds with LLVM_BUILD_LLVM_DYLIB=ON and BUILD_SHARED_LIBS=OFF this change makes all symbols in the target specific libraries hidden by default. A new macro called LLVM_EXTERNAL_VISIBILITY has been added to mark symbols in these libraries public, which is mainly needed for the definitions of the LLVMInitialize* functions. This patch reduces the number of public symbols in libLLVM.so by about 25%. This should improve load times for the dynamic library and also make abi checker tools, like abidiff require less memory when analyzing libLLVM.so One side-effect of this change is that for builds with LLVM_BUILD_LLVM_DYLIB=ON and LLVM_LINK_LLVM_DYLIB=ON some unittests that access symbols that are no longer public will need to be statically linked. Before and after public symbol counts (using gcc 8.2.1, ld.bfd 2.31.1): nm before/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l 36221 nm after/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l 26278 Reviewers: chandlerc, beanz, mgorny, rnk, hans Reviewed By: rnk, hans Subscribers: merge_guards_bot, luismarques, smeenai, ldionne, lenary, s.egerton, pzheng, sameer.abuasal, MaskRay, wuzish, echristo, Jim, hiraditya, michaelplatings, chapuni, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, mgrang, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, kristina, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D54439
1 parent 1b5404a commit 0dbcb36

File tree

116 files changed

+154
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+154
-113
lines changed

llvm/include/llvm/Support/Compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@
117117
/// not accessible from outside it. Can also be used to mark variables and
118118
/// functions, making them private to any shared library they are linked into.
119119
/// On PE/COFF targets, library visibility is the default, so this isn't needed.
120+
///
121+
/// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with
122+
/// this attribute will be made public and visible outside of any shared library
123+
/// they are linked in to.
120124
#if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
121125
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)
122126
#define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
127+
#define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default")))
123128
#else
124129
#define LLVM_LIBRARY_VISIBILITY
130+
#define LLVM_EXTERNAL_VISIBILITY
125131
#endif
126132

127133
#if defined(__GNUC__)

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ void AArch64AsmPrinter::EmitInstruction(const MachineInstr *MI) {
12981298
}
12991299

13001300
// Force static initialization.
1301-
extern "C" void LLVMInitializeAArch64AsmPrinter() {
1301+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64AsmPrinter() {
13021302
RegisterAsmPrinter<AArch64AsmPrinter> X(getTheAArch64leTarget());
13031303
RegisterAsmPrinter<AArch64AsmPrinter> Y(getTheAArch64beTarget());
13041304
RegisterAsmPrinter<AArch64AsmPrinter> Z(getTheARM64Target());

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static cl::opt<bool>
154154
cl::desc("Enable the AAcrh64 branch target pass"),
155155
cl::init(true));
156156

157-
extern "C" void LLVMInitializeAArch64Target() {
157+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Target() {
158158
// Register the target.
159159
RegisterTargetMachine<AArch64leTargetMachine> X(getTheAArch64leTarget());
160160
RegisterTargetMachine<AArch64beTargetMachine> Y(getTheAArch64beTarget());

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5515,7 +5515,7 @@ AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
55155515
}
55165516

55175517
/// Force static initialization.
5518-
extern "C" void LLVMInitializeAArch64AsmParser() {
5518+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64AsmParser() {
55195519
RegisterMCAsmParser<AArch64AsmParser> X(getTheAArch64leTarget());
55205520
RegisterMCAsmParser<AArch64AsmParser> Y(getTheAArch64beTarget());
55215521
RegisterMCAsmParser<AArch64AsmParser> Z(getTheARM64Target());

llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ createAArch64ExternalSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
277277
SymbolLookUp, DisInfo);
278278
}
279279

280-
extern "C" void LLVMInitializeAArch64Disassembler() {
280+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Disassembler() {
281281
TargetRegistry::RegisterMCDisassembler(getTheAArch64leTarget(),
282282
createAArch64Disassembler);
283283
TargetRegistry::RegisterMCDisassembler(getTheAArch64beTarget(),

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static MCInstrAnalysis *createAArch64InstrAnalysis(const MCInstrInfo *Info) {
366366
}
367367

368368
// Force static initialization.
369-
extern "C" void LLVMInitializeAArch64TargetMC() {
369+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64TargetMC() {
370370
for (Target *T : {&getTheAArch64leTarget(), &getTheAArch64beTarget(),
371371
&getTheAArch64_32Target(), &getTheARM64Target(),
372372
&getTheARM64_32Target()}) {

llvm/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Target &llvm::getTheARM64_32Target() {
3131
return TheARM64_32Target;
3232
}
3333

34-
extern "C" void LLVMInitializeAArch64TargetInfo() {
34+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64TargetInfo() {
3535
// Now register the "arm64" name for use with "-march". We don't want it to
3636
// take possession of the Triple::aarch64 tags though.
3737
TargetRegistry::RegisterTarget(getTheARM64Target(), "arm64",

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ createAMDGPUAsmPrinterPass(TargetMachine &tm,
9090
return new AMDGPUAsmPrinter(tm, std::move(Streamer));
9191
}
9292

93-
extern "C" void LLVMInitializeAMDGPUAsmPrinter() {
93+
extern "C" void LLVM_EXTERNAL_VISIBILITY LLVMInitializeAMDGPUAsmPrinter() {
9494
TargetRegistry::RegisterAsmPrinter(getTheAMDGPUTarget(),
9595
llvm::createR600AsmPrinterPass);
9696
TargetRegistry::RegisterAsmPrinter(getTheGCNTarget(),

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static cl::opt<bool> EnableScalarIRPasses(
183183
cl::init(true),
184184
cl::Hidden);
185185

186-
extern "C" void LLVMInitializeAMDGPUTarget() {
186+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
187187
// Register the target
188188
RegisterTargetMachine<R600TargetMachine> X(getTheAMDGPUTarget());
189189
RegisterTargetMachine<GCNTargetMachine> Y(getTheGCNTarget());

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6980,7 +6980,7 @@ AMDGPUOperand::Ptr AMDGPUAsmParser::defaultABID() const {
69806980
}
69816981

69826982
/// Force static initialization.
6983-
extern "C" void LLVMInitializeAMDGPUAsmParser() {
6983+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUAsmParser() {
69846984
RegisterMCAsmParser<AMDGPUAsmParser> A(getTheAMDGPUTarget());
69856985
RegisterMCAsmParser<AMDGPUAsmParser> B(getTheGCNTarget());
69866986
}

0 commit comments

Comments
 (0)