summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-05-19 16:08:28 -0700
committerFangrui Song <i@maskray.me>2021-05-19 16:08:28 -0700
commit37561ba89b7de57bd8ff5ae0691d02604885d4ee (patch)
treea4a4ae38aa49e1c78c2342cff8b36e40889d281c /clang/lib/CodeGen/CodeGenModule.cpp
parent2f8ac0758bbfad72e52ef8602fbbd796e1347784 (diff)
-fno-semantic-interposition: Don't set dso_local on GlobalVariable
`clang -fpic -fno-semantic-interposition` may set dso_local on variables for -fpic. GCC folks consider there are 'address interposition' and 'semantic interposition', and 'disabling semantic interposition' can optimize function calls but cannot change variable references to use local aliases (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483). This patch removes dso_local for variables in `clang -fpic -fno-semantic-interposition` mode so that the built shared objects can work with copy relocations. Building llvm-project tiself with -fno-semantic-interposition (D102453) should now be safe with trunk Clang. Example: ``` // a.c int var; int *addr() { return var; } // old: cannot be interposed movslq .Lvar$local(%rip), %rax // new: can be interposed movq var@GOTPCREL(%rip), %rax movslq (%rax), %rax ``` The local alias lowering for `GlobalVariable`s is kept in case there is a future option allowing local aliases. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D102583
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index fa9676a1f32d..e38dee92db29 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1007,9 +1007,9 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
// 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())
+ // dso_local on the function if using a local alias is preferable (can avoid
+ // PLT indirection).
+ if (!(isa<llvm::Function>(GV) && GV->canBenefitFromLocalAlias()))
return false;
return !(CGM.getLangOpts().SemanticInterposition ||
CGM.getLangOpts().HalfNoSemanticInterposition);