[PATCH] D117190: [GlobalValue] Make dso_local function work with comdat nodeduplicate

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 13 16:37:24 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc56097817be: [GlobalValue] Make dso_local function work with comdat nodeduplicate (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D117190?vs=399834&id=399836#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117190/new/

https://reviews.llvm.org/D117190

Files:
  llvm/lib/IR/Globals.cpp
  llvm/test/CodeGen/X86/linux-preemption.ll


Index: llvm/test/CodeGen/X86/linux-preemption.ll
===================================================================
--- llvm/test/CodeGen/X86/linux-preemption.ll
+++ llvm/test/CodeGen/X86/linux-preemption.ll
@@ -252,6 +252,32 @@
 ; STATIC: movq external_preemptable_function at GOTPCREL(%rip), %rax
 ; CHECK32: movl external_preemptable_function at GOT(%eax), %eax
 
+$comdat_nodeduplicate_local = comdat nodeduplicate
+$comdat_nodeduplicate_preemptable = comdat nodeduplicate
+$comdat_any_local = comdat any
+
+;; -fpic -fno-semantic-interposition may add dso_local. Some instrumentation
+;; may add comdat nodeduplicate. We should use local aliases to make the symbol
+;; non-preemptible in the linker.
+define dso_local i8* @comdat_nodeduplicate_local() comdat {
+  ret i8* bitcast (i8* ()* @comdat_nodeduplicate_local to i8*)
+}
+; CHECK: leaq .Lcomdat_nodeduplicate_local$local(%rip), %rax
+; STATIC: movl $comdat_nodeduplicate_local, %eax
+
+define dso_preemptable i8* @comdat_nodeduplicate_preemptable() comdat {
+  ret i8* bitcast (i8* ()* @comdat_nodeduplicate_preemptable to i8*)
+}
+; CHECK: movq comdat_nodeduplicate_preemptable at GOTPCREL(%rip), %rax
+; STATIC: movq comdat_nodeduplicate_preemptable at GOTPCREL(%rip), %rax
+
+;; Check the behavior for the invalid construct.
+define dso_local i8* @comdat_any_local() comdat {
+  ret i8* bitcast (i8* ()* @comdat_any_local to i8*)
+}
+; CHECK: leaq comdat_any_local(%rip), %rax
+; STATIC: movl $comdat_any_local, %eax
+
 !llvm.module.flags = !{!0}
 !0 = !{i32 7, !"PIC Level", i32 2}
 
Index: llvm/lib/IR/Globals.cpp
===================================================================
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -105,10 +105,15 @@
 }
 
 bool GlobalValue::canBenefitFromLocalAlias() const {
-  // See AsmPrinter::getSymbolPreferLocal().
+  // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
+  // references to a discarded local symbol from outside the group are not
+  // allowed, so avoid the local alias.
+  auto isDeduplicateComdat = [](const Comdat *C) {
+    return C && C->getSelectionKind() != Comdat::NoDeduplicate;
+  };
   return hasDefaultVisibility() &&
          GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
-         !isa<GlobalIFunc>(this) && !hasComdat();
+         !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
 }
 
 unsigned GlobalValue::getAddressSpace() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117190.399836.patch
Type: text/x-patch
Size: 2430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220114/5dd5daac/attachment.bin>


More information about the llvm-commits mailing list