[XCOFF][AIX] Check linkage on the function, and two fixes for comments
authorjasonliu <jasonliu.development@gmail.com>
Tue, 26 Nov 2019 16:05:26 +0000 (16:05 +0000)
committerjasonliu <jasonliu.development@gmail.com>
Tue, 26 Nov 2019 16:09:31 +0000 (16:09 +0000)
This is a follow up commit to address post-commit comment in D70443

Differential revision: https://reviews.llvm.org/D70443

llvm/lib/MC/XCOFFObjectWriter.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/aix-weak-undef-func-call.ll [new file with mode: 0644]

index ca96a0e..ab0d904 100644 (file)
@@ -574,7 +574,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
   // yet, so start at index 0.
   uint32_t SymbolTableIndex = 0;
 
-  // Calculate undefined symbol's indices.
+  // Calculate indices for undefined symbols.
   for (auto &Csect : UndefinedCsects) {
     Csect.Size = 0;
     Csect.Address = 0;
index f95f8be..3c59cea 100644 (file)
@@ -52,6 +52,7 @@
 #include "llvm/CodeGen/SelectionDAGNodes.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
 #include "llvm/CodeGen/TargetRegisterInfo.h"
 #include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/IR/CallSite.h"
@@ -5326,16 +5327,19 @@ SDValue PPCTargetLowering::FinishCall(
     GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee);
     auto &Context = DAG.getMachineFunction().getMMI().getContext();
 
+    const GlobalObject *GO = cast<GlobalObject>(G->getGlobal());
     MCSymbolXCOFF *S = cast<MCSymbolXCOFF>(Context.getOrCreateSymbol(
-        Twine(".") + Twine(G->getGlobal()->getName())));
-
-    const GlobalValue *GV = G->getGlobal();
-    if (GV && GV->isDeclaration() && !S->hasContainingCsect()) {
-      // On AIX, undefined symbol need to associate with a MCSectionXCOFF to
-      // get the correct storage mapping class. In this case, XCOFF::XMC_PR.
+        Twine(".") + Twine(GO->getName())));
+
+    if (GO && GO->isDeclaration() && !S->hasContainingCsect()) {
+      // On AIX, an undefined symbol needs to be associated with a
+      // MCSectionXCOFF to get the correct storage mapping class.
+      // In this case, XCOFF::XMC_PR.
+      const XCOFF::StorageClass SC =
+          TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GO);
       MCSectionXCOFF *Sec =
           Context.getXCOFFSection(S->getName(), XCOFF::XMC_PR, XCOFF::XTY_ER,
-                                  XCOFF::C_EXT, SectionKind::getMetadata());
+                                  SC, SectionKind::getMetadata());
       S->setContainingCsect(Sec);
     }
 
diff --git a/llvm/test/CodeGen/PowerPC/aix-weak-undef-func-call.ll b/llvm/test/CodeGen/PowerPC/aix-weak-undef-func-call.ll
new file mode 100644 (file)
index 0000000..9fb3dec
--- /dev/null
@@ -0,0 +1,30 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s
+; RUN: llvm-readobj  --symbols %t.o | FileCheck %s
+
+define void @bar() {
+entry:
+  call void bitcast (void (...)* @foo to void ()*)()
+  ret void
+}
+
+declare extern_weak void @foo(...) 
+
+;CHECK: Symbol {
+;CHECK:   Name: .foo
+;CHECK-NEXT:   Value (RelocatableAddress): 0x0
+;CHECK-NEXT:   Section: N_UNDEF
+;CHECK-NEXT:   Type: 0x0
+;CHECK-NEXT:   StorageClass: C_WEAKEXT (0x6F)
+;CHECK-NEXT:   NumberOfAuxEntries: 1
+;CHECK-NEXT:   CSECT Auxiliary Entry {
+;CHECK:          SectionLen: 0
+;CHECK-NEXT:     ParameterHashIndex: 0x0
+;CHECK-NEXT:     TypeChkSectNum: 0x0
+;CHECK-NEXT:     SymbolAlignmentLog2: 0
+;CHECK-NEXT:     SymbolType: XTY_ER (0x0)
+;CHECK-NEXT:     StorageMappingClass: XMC_PR (0x0)
+;CHECK-NEXT:     StabInfoIndex: 0x0
+;CHECK-NEXT:     StabSectNum: 0x0
+;CHECK-NEXT:   }
+;CHECK-NEXT: }
+