Skip to content

Commit 84161f1

Browse files
committed
[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
1 parent c3bc805 commit 84161f1

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,25 +1899,26 @@ PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO(const MachineOperand &MO) {
18991899
return XSym->getContainingCsect()->getQualNameSymbol();
19001900
}
19011901

1902-
// Handle initialized global variables.
1903-
if (GV) {
1904-
SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
1905-
1902+
// Handle initialized global variables and defined functions.
1903+
SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
1904+
1905+
if (GOKind.isText()) {
1906+
// If the MO is a function, we want to make sure to refer to the function
1907+
// descriptor csect.
1908+
return OutStreamer->getContext()
1909+
.getXCOFFSection(XSym->getName(), XCOFF::XMC_DS, XCOFF::XTY_SD,
1910+
XCOFF::C_HIDEXT, SectionKind::getData())
1911+
->getQualNameSymbol();
1912+
} else if (GOKind.isCommon() || GOKind.isBSSLocal()) {
19061913
// If the operand is a common then we should refer to the csect symbol.
1907-
if (GVKind.isCommon() || GVKind.isBSSLocal()) {
1908-
MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
1909-
getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
1910-
return Csect->getQualNameSymbol();
1911-
}
1912-
1913-
// Other global variables are refered to by labels inside of a single csect,
1914-
// so refer to the label directly.
1915-
return getSymbol(GV);
1914+
return cast<MCSectionXCOFF>(
1915+
getObjFileLowering().SectionForGlobal(GO, GOKind, TM))
1916+
->getQualNameSymbol();
19161917
}
19171918

1918-
// If the MO is a function, we want to make sure to refer to the function
1919-
// descriptor csect.
1920-
return XSym->getContainingCsect()->getQualNameSymbol();
1919+
// Other global variables are refered to by labels inside of a single csect,
1920+
// so refer to the label directly.
1921+
return getSymbol(GV);
19211922
}
19221923

19231924
/// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code

llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ declare void @foo()
1919

2020
define void @bar() {
2121
%1 = alloca i8*, align 8
22+
%2 = alloca i8*, align 8
2223
store i32 0, i32* @a, align 4
2324
store i64 0, i64* @b, align 8
2425
store i16 0, i16* @c, align 2
2526
store i32 0, i32* @globa, align 4
2627
store void (...)* bitcast (void ()* @bar to void (...)*), void (...)** @ptr, align 4
2728
store i8* bitcast (void ()* @foo to i8*), i8** %1, align 8
29+
store i8* bitcast (void ()* @foobar to i8*), i8** %2, align 8
2830
ret void
2931
}
3032

@@ -36,6 +38,10 @@ define void @bar2() {
3638
ret void
3739
}
3840

41+
define void @foobar() {
42+
ret void
43+
}
44+
3945
; CHECK-NOT: .comm a
4046
; CHECK-NOT: .lcomm a
4147
; CHECK-NOT: .comm b
@@ -60,10 +66,12 @@ define void @bar2() {
6066
; CHECK-NEXT: .tc bar[TC],bar[DS]
6167
; CHECK-NEXT: LC6:
6268
; CHECK-NEXT: .tc foo[TC],foo[DS]
69+
; CHECK-NEXT: LC7:
70+
; CHECK-NEXT: .tc foobar[TC],foobar[DS]
6371

6472
; SYM: File: {{.*}}aix-xcoff-toc.ll.tmp.o
6573
; SYM: Symbol {{[{][[:space:]] *}}Index: [[#INDX:]]{{[[:space:]] *}}Name: TOC
66-
; SYM-NEXT: Value (RelocatableAddress): 0x8C
74+
; SYM-NEXT: Value (RelocatableAddress): 0xA8
6775
; SYM-NEXT: Section: .data
6876
; SYM-NEXT: Type: 0x0
6977
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -83,7 +91,7 @@ define void @bar2() {
8391
; SYM-NEXT: Symbol {
8492
; SYM-NEXT: Index: [[#INDX+2]]
8593
; SYM-NEXT: Name: a
86-
; SYM-NEXT: Value (RelocatableAddress): 0x8C
94+
; SYM-NEXT: Value (RelocatableAddress): 0xA8
8795
; SYM-NEXT: Section: .data
8896
; SYM-NEXT: Type: 0x0
8997
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -103,7 +111,7 @@ define void @bar2() {
103111
; SYM-NEXT: Symbol {
104112
; SYM-NEXT: Index: [[#INDX+4]]
105113
; SYM-NEXT: Name: b
106-
; SYM-NEXT: Value (RelocatableAddress): 0x90
114+
; SYM-NEXT: Value (RelocatableAddress): 0xAC
107115
; SYM-NEXT: Section: .data
108116
; SYM-NEXT: Type: 0x0
109117
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -123,7 +131,7 @@ define void @bar2() {
123131
; SYM-NEXT: Symbol {
124132
; SYM-NEXT: Index: [[#INDX+6]]
125133
; SYM-NEXT: Name: c
126-
; SYM-NEXT: Value (RelocatableAddress): 0x94
134+
; SYM-NEXT: Value (RelocatableAddress): 0xB0
127135
; SYM-NEXT: Section: .data
128136
; SYM-NEXT: Type: 0x0
129137
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -143,7 +151,7 @@ define void @bar2() {
143151
; SYM-NEXT: Symbol {
144152
; SYM-NEXT: Index: [[#INDX+8]]
145153
; SYM-NEXT: Name: globa
146-
; SYM-NEXT: Value (RelocatableAddress): 0x98
154+
; SYM-NEXT: Value (RelocatableAddress): 0xB4
147155
; SYM-NEXT: Section: .data
148156
; SYM-NEXT: Type: 0x0
149157
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -163,7 +171,7 @@ define void @bar2() {
163171
; SYM-NEXT: Symbol {
164172
; SYM-NEXT: Index: [[#INDX+10]]
165173
; SYM-NEXT: Name: ptr
166-
; SYM-NEXT: Value (RelocatableAddress): 0x9C
174+
; SYM-NEXT: Value (RelocatableAddress): 0xB8
167175
; SYM-NEXT: Section: .data
168176
; SYM-NEXT: Type: 0x0
169177
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -183,7 +191,7 @@ define void @bar2() {
183191
; SYM-NEXT: Symbol {
184192
; SYM-NEXT: Index: [[#INDX+12]]
185193
; SYM-NEXT: Name: bar
186-
; SYM-NEXT: Value (RelocatableAddress): 0xA0
194+
; SYM-NEXT: Value (RelocatableAddress): 0xBC
187195
; SYM-NEXT: Section: .data
188196
; SYM-NEXT: Type: 0x0
189197
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -203,7 +211,7 @@ define void @bar2() {
203211
; SYM-NEXT: Symbol {
204212
; SYM-NEXT: Index: [[#INDX+14]]
205213
; SYM-NEXT: Name: foo
206-
; SYM-NEXT: Value (RelocatableAddress): 0xA4
214+
; SYM-NEXT: Value (RelocatableAddress): 0xC0
207215
; SYM-NEXT: Section: .data
208216
; SYM-NEXT: Type: 0x0
209217
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
@@ -220,3 +228,23 @@ define void @bar2() {
220228
; SYM-NEXT: StabSectNum: 0x0
221229
; SYM-NEXT: }
222230
; SYM-NEXT: }
231+
; SYM-NEXT: Symbol {
232+
; SYM-NEXT: Index: [[#INDX+16]]
233+
; SYM-NEXT: Name: foobar
234+
; SYM-NEXT: Value (RelocatableAddress): 0xC4
235+
; SYM-NEXT: Section: .data
236+
; SYM-NEXT: Type: 0x0
237+
; SYM-NEXT: StorageClass: C_HIDEXT (0x6B)
238+
; SYM-NEXT: NumberOfAuxEntries: 1
239+
; SYM-NEXT: CSECT Auxiliary Entry {
240+
; SYM-NEXT: Index: [[#INDX+17]]
241+
; SYM-NEXT: SectionLen: 4
242+
; SYM-NEXT: ParameterHashIndex: 0x0
243+
; SYM-NEXT: TypeChkSectNum: 0x0
244+
; SYM-NEXT: SymbolAlignmentLog2: 2
245+
; SYM-NEXT: SymbolType: XTY_SD (0x1)
246+
; SYM-NEXT: StorageMappingClass: XMC_TC (0x3)
247+
; SYM-NEXT: StabInfoIndex: 0x0
248+
; SYM-NEXT: StabSectNum: 0x0
249+
; SYM-NEXT: }
250+
; SYM-NEXT: }

0 commit comments

Comments
 (0)