summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2020-12-29 23:37:55 -0800
committerFangrui Song <i@maskray.me>2020-12-29 23:37:55 -0800
commit2820a2ca3a0e69c3f301845420e0067ffff2251b (patch)
tree8b64848e1d29f8bcc27054738be2417d1f7ee020 /clang/lib/CodeGen/CodeGenModule.cpp
parent30feb93036ebb8ffc5233a9ab3960836c2407d95 (diff)
Move -fno-semantic-interposition dso_local logic from TargetMachine to Clang CodeGenModule
This simplifies TargetMachine::shouldAssumeDSOLocal and and gives frontend the decision to use dso_local. For LLVM synthesized functions/globals, they may lose inferred dso_local but such optimizations are probably not very useful. Note: the hasComdat() condition in canBenefitFromLocalAlias (D77429) may be dead now. (llvm/CodeGen/X86/semantic-interposition-comdat.ll) (Investigate whether we need test coverage when Fuchsia C++ ABI is clearer)
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 93916e85a461..6d14298d9f5f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -954,8 +954,17 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
const auto &CGOpts = CGM.getCodeGenOpts();
llvm::Reloc::Model RM = CGOpts.RelocationModel;
const auto &LOpts = CGM.getLangOpts();
- if (RM != llvm::Reloc::Static && !LOpts.PIE)
- return false;
+ if (RM != llvm::Reloc::Static && !LOpts.PIE) {
+ // On ELF, if -fno-semantic-interposition is specified, we can set dso_local
+ // if using a local alias is preferable (can avoid GOT indirection).
+ // Currently only x86 supports local alias.
+ if (!TT.isOSBinFormatELF() ||
+ !CGM.getLangOpts().ExplicitNoSemanticInterposition ||
+ !GV->canBenefitFromLocalAlias())
+ return false;
+ // The allowed targets need to match AsmPrinter::getSymbolPreferLocal.
+ return TT.isX86();
+ }
// A definition cannot be preempted from an executable.
if (!GV->isDeclarationForLinker())