Skip to content

Commit 8f6f5ec

Browse files
authored
[PowerPC] Move __ehinfo TOC entries to the end of the TOC section (llvm#73586)
On AIX, the __ehinfo toc-entry is never referenced directly using instructions, therefore we can allocate them with the TE storage mapping class to move them to the end of TOC.
1 parent e8dbed0 commit 8f6f5ec

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

llvm/include/llvm/MC/MCSymbolXCOFF.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace llvm {
1717
class MCSectionXCOFF;
1818

1919
class MCSymbolXCOFF : public MCSymbol {
20+
21+
enum XCOFFSymbolFlags : uint16_t { SF_EHInfo = 0x0001 };
22+
2023
public:
2124
MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
2225
: MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
@@ -65,6 +68,10 @@ class MCSymbolXCOFF : public MCSymbol {
6568
return getUnqualifiedName();
6669
}
6770

71+
bool isEHInfo() const { return getFlags() & SF_EHInfo; }
72+
73+
void setEHInfo() const { modifyFlags(SF_EHInfo, SF_EHInfo); }
74+
6875
private:
6976
std::optional<XCOFF::StorageClass> StorageClass;
7077
MCSectionXCOFF *RepresentedCsect = nullptr;

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,8 +2310,10 @@ bool TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB(
23102310

23112311
MCSymbol *
23122312
TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(const MachineFunction *MF) {
2313-
return MF->getMMI().getContext().getOrCreateSymbol(
2313+
MCSymbol *EHInfoSym = MF->getMMI().getContext().getOrCreateSymbol(
23142314
"__ehinfo." + Twine(MF->getFunctionNumber()));
2315+
cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
2316+
return EHInfoSym;
23152317
}
23162318

23172319
MCSymbol *
@@ -2644,12 +2646,16 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
26442646
MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
26452647
const MCSymbol *Sym, const TargetMachine &TM) const {
26462648
// Use TE storage-mapping class when large code model is enabled so that
2647-
// the chance of needing -bbigtoc is decreased.
2649+
// the chance of needing -bbigtoc is decreased. Also, the toc-entry for
2650+
// EH info is never referenced directly using instructions so it can be
2651+
// allocated with TE storage-mapping class.
26482652
return getContext().getXCOFFSection(
26492653
cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
2650-
XCOFF::CsectProperties(
2651-
TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
2652-
XCOFF::XTY_SD));
2654+
XCOFF::CsectProperties((TM.getCodeModel() == CodeModel::Large ||
2655+
cast<MCSymbolXCOFF>(Sym)->isEHInfo())
2656+
? XCOFF::XMC_TE
2657+
: XCOFF::XMC_TC,
2658+
XCOFF::XTY_SD));
26532659
}
26542660

26552661
MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(

llvm/test/CodeGen/PowerPC/aix-ehinfo-sym.ll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
; RUN: llc -mtriple powerpc64-ibm-aix -fast-isel -verify-machineinstrs < %s | \
55
; RUN: FileCheck %s
66

7+
; RUN: llc -mtriple powerpc64-ibm-aix -verify-machineinstrs -filetype=obj \
8+
; RUN: -o %t.o < %s
9+
; RUN: llvm-readobj --syms %t.o | FileCheck --check-prefix=SYM %s
10+
711
; Function Attrs: nounwind
812
declare i32 @func1() #0
913

@@ -47,4 +51,11 @@ attributes #0 = { nounwind }
4751
attributes #1 = { mustprogress noinline optnone }
4852

4953
; CHECK: __ehinfo.0:
50-
; CHECK: .tc __ehinfo.0[TC],__ehinfo.0
54+
; CHECK: .tc __ehinfo.0[TE],__ehinfo.0
55+
56+
; SYM: Symbol {
57+
; SYM: Name: __ehinfo.0
58+
; SYM: CSECT Auxiliary Entry {
59+
; SYM: StorageMappingClass: XMC_TE (0x16)
60+
; SYM: }
61+
; SYM: }

llvm/test/CodeGen/PowerPC/aix-emit-tracebacktable-clobber-register.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ entry:
104104
; COMMON-NEXT: # -- End function
105105
; COMMON: .toc
106106
; COMMON: L..C2:
107-
; COMMON-NEXT: .tc __ehinfo.1[TC],__ehinfo.1
107+
; COMMON-NEXT: .tc __ehinfo.1[TE],__ehinfo.1
108108

109109

110110
; OBJ-DIS: 9c: 00 00 00 00 # Traceback table start

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ eh.resume: ; preds = %catch.dispatch
180180
; ASM: L..C0:
181181
; ASM: .tc _ZTIi[TC],_ZTIi[UA]
182182
; ASM: L..C1:
183-
; ASM: .tc __ehinfo.1[TC],__ehinfo.1
183+
; ASM: .tc __ehinfo.1[TE],__ehinfo.1
184184

185185
declare ptr @__cxa_allocate_exception(i32)
186186
declare void @__cxa_throw(ptr, ptr, ptr)

0 commit comments

Comments
 (0)