Skip to content

Commit fb8f61d

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:abc405858d6d into amd-gfx:bb29769bda41
Local branch amd-gfx bb29769 Merged main:3bbed4ee2681 into amd-gfx:4f2762c1457a Remote branch main abc4058 [XCOFF] make related SD symbols as isFunction (llvm#69553)
2 parents bb29769 + abc4058 commit fb8f61d

File tree

7 files changed

+97
-25
lines changed

7 files changed

+97
-25
lines changed

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 481730
19+
#define LLVM_MAIN_REVISION 481731
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Object/XCOFFObjectFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ class xcoff_symbol_iterator : public symbol_iterator {
853853
xcoff_symbol_iterator(const basic_symbol_iterator &B)
854854
: symbol_iterator(B) {}
855855

856+
xcoff_symbol_iterator(const XCOFFSymbolRef *Symbol)
857+
: symbol_iterator(*Symbol) {}
858+
856859
const XCOFFSymbolRef *operator->() const {
857860
return static_cast<const XCOFFSymbolRef *>(symbol_iterator::operator->());
858861
}

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,21 +1242,57 @@ Expected<bool> XCOFFSymbolRef::isFunction() const {
12421242

12431243
const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get();
12441244

1245-
// A function definition should be a label definition.
1246-
// FIXME: This is not necessarily the case when -ffunction-sections is
1247-
// enabled.
1248-
if (!CsectAuxRef.isLabel())
1245+
if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR &&
1246+
CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_GL)
12491247
return false;
12501248

1251-
if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR)
1249+
// A function definition should not be a common type symbol or an external
1250+
// symbol.
1251+
if (CsectAuxRef.getSymbolType() == XCOFF::XTY_CM ||
1252+
CsectAuxRef.getSymbolType() == XCOFF::XTY_ER)
12521253
return false;
12531254

1254-
const int16_t SectNum = getSectionNumber();
1255-
Expected<DataRefImpl> SI = getObject()->getSectionByNum(SectNum);
1256-
if (!SI)
1257-
return SI.takeError();
1255+
// If the next symbol is an XTY_LD type symbol with the same address, this
1256+
// XTY_SD symbol is not a function. Otherwise this is a function symbol for
1257+
// -ffunction-sections.
1258+
if (CsectAuxRef.getSymbolType() == XCOFF::XTY_SD) {
1259+
// If this is a csect with size 0, it won't be a function definition.
1260+
// This is used to work around the fact that LLVM always generates below
1261+
// symbol for -ffunction-sections:
1262+
// m 0x00000000 .text 1 unamex **No Symbol**
1263+
// a4 0x00000000 0 0 SD PR 0 0
1264+
// FIXME: remove or replace this meaningless symbol.
1265+
if (getSize() == 0)
1266+
return false;
1267+
1268+
xcoff_symbol_iterator NextIt(this);
1269+
// If this is the last main symbol table entry, there won't be an XTY_LD
1270+
// type symbol below.
1271+
if (++NextIt == getObject()->symbol_end())
1272+
return true;
1273+
1274+
if (cantFail(getAddress()) != cantFail(NextIt->getAddress()))
1275+
return true;
1276+
1277+
// Check next symbol is XTY_LD. If so, this symbol is not a function.
1278+
Expected<XCOFFCsectAuxRef> NextCsectAuxEnt = NextIt->getXCOFFCsectAuxRef();
1279+
if (!NextCsectAuxEnt)
1280+
return NextCsectAuxEnt.takeError();
1281+
1282+
if (NextCsectAuxEnt.get().getSymbolType() == XCOFF::XTY_LD)
1283+
return false;
12581284

1259-
return (getObject()->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT);
1285+
return true;
1286+
}
1287+
1288+
if (CsectAuxRef.getSymbolType() == XCOFF::XTY_LD)
1289+
return true;
1290+
1291+
return createError(
1292+
"symbol csect aux entry with index " +
1293+
Twine(getObject()->getSymbolIndex(CsectAuxRef.getEntryAddress())) +
1294+
" has invalid symbol type " +
1295+
Twine::utohexstr(CsectAuxRef.getSymbolType()));
12601296
}
12611297

12621298
bool XCOFFSymbolRef::isCsectSymbol() const {

llvm/test/CodeGen/PowerPC/aix-text.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ entry:
1717
ret i32 2
1818
}
1919

20-
; CHECKFS32: 00000000 l .text 00000000 (idx: {{[[:digit:]]*}}) [PR]
21-
; CHECKFS32-NEXT: 00000000 g .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text[PR]
22-
; CHECKFS32-NEXT: {{([[:xdigit:]]{8})}} g .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text2[PR]
20+
; CHECKFS32: 00000000 l .text 00000000 (idx: {{[[:digit:]]*}}) [PR]
21+
; CHECKFS32-NEXT: 00000000 g F .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text[PR]
22+
; CHECKFS32-NEXT: {{([[:xdigit:]]{8})}} g F .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text2[PR]
2323

24-
; CHECKFS64: 0000000000000000 l .text 0000000000000000
25-
; CHECKFS64-NEXT: 0000000000000000 g .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text[PR]
26-
; CHECKFS64-NEXT: {{([[:xdigit:]]{16})}} g .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text2[PR]
24+
; CHECKFS64: 0000000000000000 l .text 0000000000000000
25+
; CHECKFS64-NEXT: 0000000000000000 g F .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text[PR]
26+
; CHECKFS64-NEXT: {{([[:xdigit:]]{16})}} g F .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text2[PR]
2727

2828
; CHECK32: 00000000 l .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) [PR]
2929
; CHECK32-NEXT: {{([[:xdigit:]]{8})}} g F .text (csect: (idx: {{[[:digit:]]*}}) [PR]) 00000000 (idx: {{[[:digit:]]*}}) .text

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ entry:
117117
; XCOFF32-NEXT: 00000000 l .text 00000000 (idx: 5) [PR]
118118
; XCOFF32-NEXT: 00000000 g .text 00000019 (idx: 7) .foo[PR]
119119
; XCOFF32-NEXT: 00000000 g F .text (csect: (idx: 7) .foo[PR]) 00000000 (idx: 9) .alias_foo
120-
; XCOFF32-NEXT: 00000020 g .text 00000020 .hidden (idx: 11) .hidden_foo[PR]
121-
; XCOFF32-NEXT: 00000040 g .text 00000059 (idx: 13) .bar[PR]
122-
; XCOFF32-NEXT: 000000c0 l .text 0000002a (idx: 15) .static_overalign_foo[PR]
120+
; XCOFF32-NEXT: 00000020 g F .text 00000020 .hidden (idx: 11) .hidden_foo[PR]
121+
; XCOFF32-NEXT: 00000040 g F .text 00000059 (idx: 13) .bar[PR]
122+
; XCOFF32-NEXT: 000000c0 l F .text 0000002a (idx: 15) .static_overalign_foo[PR]
123123
; XCOFF32-NEXT: 000000ec g O .data 0000000c (idx: 17) foo[DS]
124124
; XCOFF32-NEXT: 000000ec g O .data (csect: (idx: 17) foo[DS]) 00000000 (idx: 19) alias_foo
125125
; XCOFF32-NEXT: 000000f8 g O .data 0000000c .hidden (idx: 21) hidden_foo[DS]
@@ -152,9 +152,9 @@ entry:
152152
; XCOFF64-NEXT: 0000000000000000 l .text 0000000000000000 (idx: 5) [PR]
153153
; XCOFF64-NEXT: 0000000000000000 g .text 0000000000000019 (idx: 7) .foo[PR]
154154
; XCOFF64-NEXT: 0000000000000000 g F .text (csect: (idx: 7) .foo[PR]) 0000000000000000 (idx: 9) .alias_foo
155-
; XCOFF64-NEXT: 0000000000000020 g .text 0000000000000020 .hidden (idx: 11) .hidden_foo[PR]
156-
; XCOFF64-NEXT: 0000000000000040 g .text 0000000000000059 (idx: 13) .bar[PR]
157-
; XCOFF64-NEXT: 00000000000000c0 l .text 000000000000002a (idx: 15) .static_overalign_foo[PR]
155+
; XCOFF64-NEXT: 0000000000000020 g F .text 0000000000000020 .hidden (idx: 11) .hidden_foo[PR]
156+
; XCOFF64-NEXT: 0000000000000040 g F .text 0000000000000059 (idx: 13) .bar[PR]
157+
; XCOFF64-NEXT: 00000000000000c0 l F .text 000000000000002a (idx: 15) .static_overalign_foo[PR]
158158
; XCOFF64-NEXT: 00000000000000f0 g O .data 0000000000000018 (idx: 17) foo[DS]
159159
; XCOFF64-NEXT: 00000000000000f0 g O .data (csect: (idx: 17) foo[DS]) 0000000000000000 (idx: 19) alias_foo
160160
; XCOFF64-NEXT: 0000000000000108 g O .data 0000000000000018 .hidden (idx: 21) hidden_foo[DS]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Check that llvm-objdump --syms reports an error when
2+
## the symbol type in the csect aux entry of a symbol is not valid.
3+
4+
## Check XCOFF32
5+
# RUN: yaml2obj -DMAGICNUMBER=0x1DF %s -o %t1
6+
# RUN: not llvm-objdump --syms %t1 2>&1 | FileCheck %s -DOBJ=%t1
7+
8+
## Check XCOFF64
9+
# RUN: yaml2obj -DMAGICNUMBER=0x1F7 %s -o %t2
10+
# RUN: not llvm-objdump --syms %t2 2>&1 | FileCheck %s -DOBJ=%t2
11+
12+
# CHECK: error: '[[OBJ]]': symbol csect aux entry with index 2 has invalid symbol type 5
13+
14+
--- !XCOFF
15+
FileHeader:
16+
MagicNumber: [[MAGICNUMBER]]
17+
Sections:
18+
- Name: .text
19+
Flags: [ STYP_TEXT ]
20+
Symbols:
21+
- Name: .file
22+
Section: N_DEBUG
23+
NumberOfAuxEntries: 0
24+
Type: 0x0
25+
StorageClass: C_FILE
26+
- Name: test
27+
Section: .text
28+
NumberOfAuxEntries: 1
29+
StorageClass: C_EXT
30+
AuxEntries:
31+
- Type: AUX_CSECT
32+
SymbolAlignmentAndType: 5
33+
StorageMappingClass: XMC_PR

llvm/test/tools/llvm-symbolizer/xcoff-sd-symbol.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ entry:
1616
ret void
1717
}
1818

19-
; CHECK: ??
19+
; CHECK: .foo
2020
; CHECK: ??:0:0
2121
; CHECK-EMPTY:
2222

23-
; CHECK: ??
23+
; CHECK: .foo1
2424
; CHECK: ??:0:0
2525
; CHECK-EMPTY:

0 commit comments

Comments
 (0)