From d1fd72343c6ff58a3b66bc0df56fed9ac21e4056 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 31 Dec 2020 13:59:45 -0800 Subject: 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. --- clang/lib/CodeGen/CodeGenModule.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index bf0a38bf83ab..cfc0f732748c 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. -- cgit v1.2.3