[PATCH] D77429: [AsmPrinter] Do not define local aliases for global objects in a comdat

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 13:34:03 PDT 2020


leonardchan created this revision.
leonardchan added reviewers: MaskRay, sfertile, rnk, peter.smith.
leonardchan added a project: LLVM.
Herald added a subscriber: hiraditya.
leonardchan added a parent revision: D72959: Relative VTables ABI on Fuchsia.

A global symbol that is defined in a comdat should not generate an alias since call sites that would've referred to that symbol will refer to their own independent local aliases rather than the surviving global comdat one. This could result in something that looks like:

  ld.lld: error: relocation refers to a discarded section: .text._ZN3fbl8internal18NullFunctionTargetIvJjjPjEED1Ev.stub
  >>> defined in user-x64-clang/obj/system/ulib/minfs/libminfs.a(minfs._sources.file.cc.o)
  >>> section group signature: _ZN3fbl8internal18NullFunctionTargetIvJjjPjEED1Ev.stub
  >>> prevailing definition is in user-x64-clang/obj/system/ulib/minfs/libminfs.a(minfs._sources.vnode.cc.o)
  >>> referenced by function.h:169 (../../zircon/system/ulib/fbl/include/fbl/function.h:169)
  >>>               minfs._sources.file.cc.o:(minfs::File::AllocateAndCommitData(std::__2::unique_ptr<minfs::Transaction, std::__2::default_delete<minfs::Transaction> >)) in archive user-x64-clang/obj/system/ulib/minfs/libminfs.a

We ran into this when experimenting with a new C++ ABI for fuchsia (refer to D72959 <https://reviews.llvm.org/D72959>) which takes relative offsets between comdat'd functions which is why the normal C++ user wouldn't run into this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77429

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/X86/reject-local-symbol-for-comdat.ll


Index: llvm/test/CodeGen/X86/reject-local-symbol-for-comdat.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/reject-local-symbol-for-comdat.ll
@@ -0,0 +1,23 @@
+; RUN: llc -mtriple x86_64-unknown-linux-gnu %s -o - | FileCheck %s
+
+$comdat_func = comdat any
+
+; CHECK-LABEL: func2:
+; CHECK-NEXT: .Lfunc2$local
+
+declare void @func()
+
+define hidden void @func2() {
+entry:
+  call void @func()
+  ret void
+}
+
+; CHECK: comdat_func:
+; CHECK-NOT: .Lcomdat_func$local
+
+define hidden void @comdat_func() comdat {
+entry:
+  call void @func()
+  ret void
+}
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -460,7 +460,7 @@
   // assumed it.
   if (TM.getTargetTriple().isOSBinFormatELF() &&
       GlobalObject::isExternalLinkage(GV.getLinkage()) && GV.isDSOLocal() &&
-      !GV.isDeclaration() && !isa<GlobalIFunc>(GV))
+      !GV.isDeclaration() && !isa<GlobalIFunc>(GV) && !GV.hasComdat())
     return getSymbolWithGlobalValueBase(&GV, "$local");
   return TM.getSymbol(&GV);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77429.254897.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200403/58accce2/attachment.bin>


More information about the llvm-commits mailing list