From 1ea1e053f6a10955a5aa8f5a8007544a846766e5 Mon Sep 17 00:00:00 2001 From: David Tenty Date: Thu, 5 Dec 2019 15:21:53 -0500 Subject: [PATCH] [AIX] Make sure to use QualNames for external global objects Summary: Previously we only handled the case where the csect hadn't been set up yet, so we'd hit an assert later on. Reviewers: jasonliu, DiggerLin, stevewan Reviewed By: jasonliu Subscribers: hubert.reinterpretcast, wuzish, nemanjai, hiraditya, kbarton, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71032 --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 26 ++++++++++++++------------ llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll | 24 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 9b8fb4d..db2352b 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1883,18 +1883,20 @@ PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO(const MachineOperand &MO) { // declaration of a function, then XSym is an external referenced symbol. // Hence we may need to explictly create a MCSectionXCOFF for it so that we // can return its symbol later. - if (GO->isDeclaration() && !XSym->hasContainingCsect()) { - // Make sure the storage class is set. - const XCOFF::StorageClass SC = - TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GO); - XSym->setStorageClass(SC); - - MCSectionXCOFF *Csect = OutStreamer->getContext().getXCOFFSection( - XSym->getName(), isa(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA, - XCOFF::XTY_ER, SC, SectionKind::getMetadata()); - XSym->setContainingCsect(Csect); - - return Csect->getQualNameSymbol(); + if (GO->isDeclaration()) { + if (!XSym->hasContainingCsect()) { + // Make sure the storage class is set. + const XCOFF::StorageClass SC = + TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GO); + XSym->setStorageClass(SC); + + MCSectionXCOFF *Csect = OutStreamer->getContext().getXCOFFSection( + XSym->getName(), isa(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA, + XCOFF::XTY_ER, SC, SectionKind::getMetadata()); + XSym->setContainingCsect(Csect); + } + + return XSym->getContainingCsect()->getQualNameSymbol(); } // Handle initialized global variables. diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll index 57f9706..8949883 100644 --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll @@ -28,6 +28,14 @@ define void @bar() { ret void } +; We initialize a csect when we first reference an external global, so make sure we don't run into problems when we see it again. +define void @bar2() { + store i32 0, i32* @a, align 4 + store i64 0, i64* @b, align 8 + store i16 0, i16* @c, align 2 + ret void +} + ; CHECK-NOT: .comm a ; CHECK-NOT: .lcomm a ; CHECK-NOT: .comm b @@ -55,7 +63,7 @@ define void @bar() { ; SYM: File: {{.*}}aix-xcoff-toc.ll.tmp.o ; SYM: Symbol {{[{][[:space:]] *}}Index: [[#INDX:]]{{[[:space:]] *}}Name: TOC -; SYM-NEXT: Value (RelocatableAddress): 0x54 +; SYM-NEXT: Value (RelocatableAddress): 0x8C ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -75,7 +83,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+2]] ; SYM-NEXT: Name: a -; SYM-NEXT: Value (RelocatableAddress): 0x54 +; SYM-NEXT: Value (RelocatableAddress): 0x8C ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -95,7 +103,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+4]] ; SYM-NEXT: Name: b -; SYM-NEXT: Value (RelocatableAddress): 0x58 +; SYM-NEXT: Value (RelocatableAddress): 0x90 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -115,7 +123,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+6]] ; SYM-NEXT: Name: c -; SYM-NEXT: Value (RelocatableAddress): 0x5C +; SYM-NEXT: Value (RelocatableAddress): 0x94 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -135,7 +143,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+8]] ; SYM-NEXT: Name: globa -; SYM-NEXT: Value (RelocatableAddress): 0x60 +; SYM-NEXT: Value (RelocatableAddress): 0x98 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -155,7 +163,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+10]] ; SYM-NEXT: Name: ptr -; SYM-NEXT: Value (RelocatableAddress): 0x64 +; SYM-NEXT: Value (RelocatableAddress): 0x9C ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -175,7 +183,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+12]] ; SYM-NEXT: Name: bar -; SYM-NEXT: Value (RelocatableAddress): 0x68 +; SYM-NEXT: Value (RelocatableAddress): 0xA0 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) @@ -195,7 +203,7 @@ define void @bar() { ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: [[#INDX+14]] ; SYM-NEXT: Name: foo -; SYM-NEXT: Value (RelocatableAddress): 0x6C +; SYM-NEXT: Value (RelocatableAddress): 0xA4 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) -- 2.7.4