[llvm] 84161f1 - [AIX] Avoid unset csect assert for functions defined after their use in TOC

David Tenty via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 13:59:29 PST 2019


Author: David Tenty
Date: 2019-12-17T16:59:22-05:00
New Revision: 84161f18ccdc8f8f5a8fc16ca16d402ddc2b9ed4

URL: https://github.com/llvm/llvm-project/commit/84161f18ccdc8f8f5a8fc16ca16d402ddc2b9ed4
DIFF: https://github.com/llvm/llvm-project/commit/84161f18ccdc8f8f5a8fc16ca16d402ddc2b9ed4.diff

LOG: [AIX] Avoid unset csect assert for functions defined after their use in TOC

Summary:
If a function is defined after it appears in a TOC expression, we may
try to access an unset containing csect when returning a symbol for the
expression.

Reviewers: Xiangling_L, DiggerLin, jasonliu, hubert.reinterpretcast

Reviewed By: hubert.reinterpretcast

Subscribers: hubert.reinterpretcast, wuzish, nemanjai, hiraditya, kbarton, jsji, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71125

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
    llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index db2352b74e16..13096aab416c 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -1899,25 +1899,26 @@ PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO(const MachineOperand &MO) {
     return XSym->getContainingCsect()->getQualNameSymbol();
   }
 
-  // Handle initialized global variables.
-  if (GV) {
-    SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
-
+  // Handle initialized global variables and defined functions.
+  SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
+
+  if (GOKind.isText()) {
+    // If the MO is a function, we want to make sure to refer to the function
+    // descriptor csect.
+    return OutStreamer->getContext()
+        .getXCOFFSection(XSym->getName(), XCOFF::XMC_DS, XCOFF::XTY_SD,
+                         XCOFF::C_HIDEXT, SectionKind::getData())
+        ->getQualNameSymbol();
+  } else if (GOKind.isCommon() || GOKind.isBSSLocal()) {
     // If the operand is a common then we should refer to the csect symbol.
-    if (GVKind.isCommon() || GVKind.isBSSLocal()) {
-      MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
-          getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
-      return Csect->getQualNameSymbol();
-    }
-
-    // Other global variables are refered to by labels inside of a single csect,
-    // so refer to the label directly.
-    return getSymbol(GV);
+    return cast<MCSectionXCOFF>(
+               getObjFileLowering().SectionForGlobal(GO, GOKind, TM))
+        ->getQualNameSymbol();
   }
 
-  // If the MO is a function, we want to make sure to refer to the function
-  // descriptor csect.
-  return XSym->getContainingCsect()->getQualNameSymbol();
+  // Other global variables are refered to by labels inside of a single csect,
+  // so refer to the label directly.
+  return getSymbol(GV);
 }
 
 /// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code

diff  --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll
index 89498833b4e4..784a259e2b49 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll
@@ -19,12 +19,14 @@ declare void @foo()
 
 define void @bar() {
   %1 = alloca i8*, align 8
+  %2 = alloca i8*, align 8
   store i32 0, i32* @a, align 4
   store i64 0, i64* @b, align 8
   store i16 0, i16* @c, align 2
   store i32 0, i32* @globa, align 4
   store void (...)* bitcast (void ()* @bar to void (...)*), void (...)** @ptr, align 4
   store i8* bitcast (void ()* @foo to i8*), i8** %1, align 8
+  store i8* bitcast (void ()* @foobar to i8*), i8** %2, align 8
   ret void
 }
 
@@ -36,6 +38,10 @@ define void @bar2() {
   ret void
 }
 
+define void @foobar() {
+  ret void
+}
+
 ; CHECK-NOT: .comm a
 ; CHECK-NOT: .lcomm a
 ; CHECK-NOT: .comm b
@@ -60,10 +66,12 @@ define void @bar2() {
 ; CHECK-NEXT: .tc   bar[TC],bar[DS]
 ; CHECK-NEXT: LC6:
 ; CHECK-NEXT: .tc   foo[TC],foo[DS]
+; CHECK-NEXT: LC7:
+; CHECK-NEXT: .tc   foobar[TC],foobar[DS]
 
 ; SYM:       File: {{.*}}aix-xcoff-toc.ll.tmp.o
 ; SYM:       Symbol {{[{][[:space:]] *}}Index: [[#INDX:]]{{[[:space:]] *}}Name: TOC
-; SYM-NEXT:    Value (RelocatableAddress): 0x8C
+; SYM-NEXT:    Value (RelocatableAddress): 0xA8
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -83,7 +91,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+2]]
 ; SYM-NEXT:    Name: a
-; SYM-NEXT:    Value (RelocatableAddress): 0x8C
+; SYM-NEXT:    Value (RelocatableAddress): 0xA8
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -103,7 +111,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+4]]
 ; SYM-NEXT:    Name: b
-; SYM-NEXT:    Value (RelocatableAddress): 0x90
+; SYM-NEXT:    Value (RelocatableAddress): 0xAC
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -123,7 +131,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+6]]
 ; SYM-NEXT:    Name: c
-; SYM-NEXT:    Value (RelocatableAddress): 0x94
+; SYM-NEXT:    Value (RelocatableAddress): 0xB0
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -143,7 +151,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+8]]
 ; SYM-NEXT:    Name: globa
-; SYM-NEXT:    Value (RelocatableAddress): 0x98
+; SYM-NEXT:    Value (RelocatableAddress): 0xB4
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -163,7 +171,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+10]]
 ; SYM-NEXT:    Name: ptr
-; SYM-NEXT:    Value (RelocatableAddress): 0x9C
+; SYM-NEXT:    Value (RelocatableAddress): 0xB8
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -183,7 +191,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+12]]
 ; SYM-NEXT:    Name: bar
-; SYM-NEXT:    Value (RelocatableAddress): 0xA0
+; SYM-NEXT:    Value (RelocatableAddress): 0xBC
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -203,7 +211,7 @@ define void @bar2() {
 ; SYM-NEXT:  Symbol {
 ; SYM-NEXT:    Index: [[#INDX+14]]
 ; SYM-NEXT:    Name: foo
-; SYM-NEXT:    Value (RelocatableAddress): 0xA4
+; SYM-NEXT:    Value (RelocatableAddress): 0xC0
 ; SYM-NEXT:    Section: .data
 ; SYM-NEXT:    Type: 0x0
 ; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
@@ -220,3 +228,23 @@ define void @bar2() {
 ; SYM-NEXT:      StabSectNum: 0x0
 ; SYM-NEXT:    }
 ; SYM-NEXT:  }
+; SYM-NEXT:  Symbol {
+; SYM-NEXT:    Index: [[#INDX+16]]
+; SYM-NEXT:    Name: foobar
+; SYM-NEXT:    Value (RelocatableAddress): 0xC4
+; SYM-NEXT:    Section: .data
+; SYM-NEXT:    Type: 0x0
+; SYM-NEXT:    StorageClass: C_HIDEXT (0x6B)
+; SYM-NEXT:    NumberOfAuxEntries: 1
+; SYM-NEXT:    CSECT Auxiliary Entry {
+; SYM-NEXT:      Index: [[#INDX+17]]
+; SYM-NEXT:      SectionLen: 4
+; SYM-NEXT:      ParameterHashIndex: 0x0
+; SYM-NEXT:      TypeChkSectNum: 0x0
+; SYM-NEXT:      SymbolAlignmentLog2: 2
+; SYM-NEXT:      SymbolType: XTY_SD (0x1)
+; SYM-NEXT:      StorageMappingClass: XMC_TC (0x3)
+; SYM-NEXT:      StabInfoIndex: 0x0
+; SYM-NEXT:      StabSectNum: 0x0
+; SYM-NEXT:    }
+; SYM-NEXT:  }


        


More information about the llvm-commits mailing list