[PATCH] D84363: [XCOFF][AIX] Handle llvm.used and llvm.compiler.used global array

Jason Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 14:24:32 PDT 2020


jasonliu created this revision.
jasonliu added reviewers: daltenty, DiggerLin, Xiangling_L, hubert.reinterpretcast.
Herald added subscribers: llvm-commits, kbarton, hiraditya, nemanjai.
Herald added a project: LLVM.

For now, just return and do nothing when we see llvm.used and llvm.compiler.used global array.
Hopefully, we could come up with a good solution later to prevent linker from eliminating symbols in llvm.used array.


https://reviews.llvm.org/D84363

Files:
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll


Index: llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
@@ -0,0 +1,20 @@
+;; This test verifies llc on AIX would not crash when llvm.used and 
+;; llvm.compiler.used is presented in the IR.
+
+; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc-ibm-aix-xcoff < %s | \
+; RUN:   FileCheck %s
+
+; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff < %s | \
+; RUN:   FileCheck %s
+
+ at keep_this = internal global i32 2, align 4
+ at keep_this2 = internal global i32 3, align 4
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @keep_this to i8*)], section "llvm.metadata"
+ at llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32* @keep_this2 to i8*)], section "llvm.metadata"
+
+; CHECK-NOT: llvm.metadata
+; CHECK:    .lglobl keep_this
+; CHECK:  keep_this:
+; CHECK:    .lglobl keep_this2
+; CHECK:  keep_this2:
+; CHECK-NOT: llvm.metadata
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -1678,22 +1678,28 @@
     report_fatal_error("COMDAT not yet supported by AIX.");
 }
 
-static bool isSpecialLLVMGlobalArrayForStaticInit(const GlobalVariable *GV) {
+static bool isSpecialLLVMGlobalArrayToSkip(const GlobalVariable *GV) {
   return StringSwitch<bool>(GV->getName())
+      // TODO: Update the handling of global arrays for static init when
+      // we support the ".ref" directive.
+      // Otherwise, we can skip these arrays, because the AIX linker collects
+      // static init functions simply based on their name.
       .Cases("llvm.global_ctors", "llvm.global_dtors", true)
+      // TODO: Linker could still eliminate the GV if we just skip handling
+      // llvm.used array. Skipping them for now until we or the AIX OS team
+      // come up with a good solution.
+      .Case("llvm.used", true)
+      // It's correct to just skip llvm.compiler.used array here.
+      .Case("llvm.compiler.used", true)
       .Default(false);
 }
 
 void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
-  ValidateGV(GV);
-
-  // TODO: Update the handling of global arrays for static init when we support
-  // the ".ref" directive.
-  // Otherwise, we can skip these arrays, because the AIX linker collects
-  // static init functions simply based on their name.
-  if (isSpecialLLVMGlobalArrayForStaticInit(GV))
+  if (isSpecialLLVMGlobalArrayToSkip(GV))
     return;
 
+  ValidateGV(GV);
+
   // Create the symbol, set its storage class.
   MCSymbolXCOFF *GVSym = cast<MCSymbolXCOFF>(getSymbol(GV));
   GVSym->setStorageClass(
@@ -1836,8 +1842,11 @@
   // We need to know, up front, the alignment of csects for the assembly path,
   // because once a .csect directive gets emitted, we could not change the
   // alignment value on it.
-  for (const auto &G : M.globals())
+  for (const auto &G : M.globals()) {
+    if (isSpecialLLVMGlobalArrayToSkip(&G))
+      continue;
     setCsectAlignment(&G);
+  }
 
   for (const auto &F : M)
     setCsectAlignment(&F);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84363.279943.patch
Type: text/x-patch
Size: 3225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200722/b25d5ca3/attachment.bin>


More information about the llvm-commits mailing list