aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2020-12-31 13:59:45 -0800
committerFangrui Song <i@maskray.me>2020-12-31 13:59:45 -0800
commitd1fd72343c6ff58a3b66bc0df56fed9ac21e4056 (patch)
tree1c6f42eeb37d5aac8f00f8cf15b1c6c348a7b4bd /clang/lib/CodeGen/CodeGenModule.cpp
parent219d00e0d90941d3e54fc711ea1e7b5e4b5b4335 (diff)
downloadllvm-d1fd72343c6ff58a3b66bc0df56fed9ac21e4056.zip
llvm-d1fd72343c6ff58a3b66bc0df56fed9ac21e4056.tar.gz
llvm-d1fd72343c6ff58a3b66bc0df56fed9ac21e4056.tar.bz2
Refactor how -fno-semantic-interposition sets dso_local on default visibility external linkage definitions
The idea is that the CC1 default for ELF should set dso_local on default visibility external linkage definitions in the default -mrelocation-model pic mode (-fpic/-fPIC) to match COFF/Mach-O and make output IR similar. The refactoring is made available by 2820a2ca3a0e69c3f301845420e0067ffff2251b. Currently only x86 supports local aliases. We move the decision to the driver. There are three CC1 states: * -fsemantic-interposition: make some linkages interposable and make default visibility external linkage definitions dso_preemptable. * (default): selected if the target supports .Lfoo$local: make default visibility external linkage definitions dso_local * -fhalf-no-semantic-interposition: if neither option is set or the target does not support .Lfoo$local: like -fno-semantic-interposition but local aliases are not used. So references can be interposed if not optimized out. Add -fhalf-no-semantic-interposition to a few tests using the half-based semantic interposition behavior.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index bf0a38b..cfc0f73 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -534,9 +534,6 @@ void CodeGenModule::Release() {
if (Context.getLangOpts().SemanticInterposition)
// Require various optimization to respect semantic interposition.
getModule().setSemanticInterposition(1);
- else if (Context.getLangOpts().ExplicitNoSemanticInterposition)
- // Allow dso_local on applicable targets.
- getModule().setSemanticInterposition(0);
if (CodeGenOpts.EmitCodeView) {
// Indicate that we want CodeView in the metadata.
@@ -961,15 +958,15 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
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())
+ // On ELF, if -fno-semantic-interposition is specified and the target
+ // supports local aliases, there will be neither CC1
+ // -fsemantic-interposition nor -fhalf-no-semantic-interposition. Set
+ // dso_local if using a local alias is preferable (can avoid GOT
+ // indirection).
+ if (!GV->canBenefitFromLocalAlias())
return false;
- // The allowed targets need to match AsmPrinter::getSymbolPreferLocal.
- return TT.isX86();
+ return !(CGM.getLangOpts().SemanticInterposition ||
+ CGM.getLangOpts().HalfNoSemanticInterposition);
}
// A definition cannot be preempted from an executable.