Skip to content

Commit c7fcda9

Browse files
committed
More updates
1 parent 686b628 commit c7fcda9

File tree

8 files changed

+75
-125
lines changed

8 files changed

+75
-125
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,10 @@ class MCContext {
619619
GOFF::SDAttr SDAttributes, StringRef EDName,
620620
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
621621
GOFF::PRAttr PRAttributes);
622-
// Create a section with root-SD/ED/LD symbols, using the root-SD name for LD.
622+
// Create a section with root-SD/ED/LD symbols.
623623
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
624624
GOFF::EDAttr EDAttributes,
625+
StringRef LDorPRName,
625626
GOFF::LDAttr LDAttributes);
626627
// Create a section with root-SD/ED/PR symbols.
627628
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,

llvm/include/llvm/MC/MCGOFFAttributes.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,24 @@ struct PRAttr {
8989
};
9090

9191
// Class names and other values depending on AMODE64 or AMODE31, and other
92-
// environment properties.
93-
template <bool Is64Bit>
94-
constexpr StringLiteral CODE =
95-
Is64Bit ? StringLiteral("C_CODE64") : StringLiteral("C_CODE");
92+
// environment properties. For now, only the 64 bit XPLINK case is defined.
9693

97-
template <bool Is64Bit>
98-
constexpr StringLiteral WSA =
99-
Is64Bit ? StringLiteral("C_WSA64") : StringLiteral("C_WSA");
94+
// GOFF classes.
95+
constexpr StringLiteral CLASS_CODE = "C_CODE64";
96+
constexpr StringLiteral CLASS_WSA = "C_WSA64";
97+
constexpr StringLiteral CLASS_DATA = "C_DATA64";
98+
constexpr StringLiteral CLASS_PPA2 = "C_@@QPPA2";
10099

101-
template <bool Is64Bit>
102-
constexpr StringLiteral DATA =
103-
Is64Bit ? StringLiteral("C_DATA64") : StringLiteral("C_DATA");
100+
// Addres and residency mode.
101+
constexpr GOFF::ESDAmode AMODE = GOFF::ESD_AMODE_64;
102+
constexpr GOFF::ESDRmode RMODE = GOFF::ESD_RMODE_64;
104103

105-
template <bool Is64Bit>
106-
constexpr StringLiteral PPA2 =
107-
Is64Bit ? StringLiteral("C_@@QPPA2") : StringLiteral("C_@@PPA2");
104+
// Linkage.
105+
constexpr GOFF::ESDLinkageType LINKAGE = GOFF::ESD_LT_XPLink;
108106

109-
template <bool Is64Bit>
110-
constexpr GOFF::ESDAmode AMODE =
111-
Is64Bit ? GOFF::ESD_AMODE_64 : GOFF::ESD_AMODE_ANY;
107+
// Loadding behavior.
108+
constexpr GOFF::ESDLoadingBehavior LOADBEHAVIOR = GOFF::ESD_LB_Initial;
112109

113-
template <bool Is64Bit>
114-
constexpr GOFF::ESDRmode RMODE =
115-
Is64Bit ? GOFF::ESD_RMODE_64 : GOFF::ESD_RMODE_31;
116-
117-
template <bool IsXPLINK>
118-
constexpr GOFF::ESDLinkageType LINKAGE =
119-
IsXPLINK ? GOFF::ESD_LT_XPLink : GOFF::ESD_LT_OS;
120-
121-
template <bool IsXPLINK>
122-
constexpr GOFF::ESDLoadingBehavior LOADBEHAVIOR =
123-
IsXPLINK ? GOFF::ESD_LB_Initial : GOFF::ESD_LB_Deferred;
124110
} // namespace GOFF
125111
} // namespace llvm
126112

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class MCSectionGOFF final : public MCSection {
4949

5050
private:
5151
SectionFlags Flags;
52-
bool IsADA;
5352

5453
friend class MCContext;
5554
MCSectionGOFF(StringRef SynName, SectionKind K, SectionFlags Flags,
@@ -78,7 +77,10 @@ class MCSectionGOFF final : public MCSection {
7877
};
7978

8079
// Setters for the SD and LD/PR symbol names.
81-
void setSDName(StringRef Name) { SDName = Name; }
80+
void setSDName(StringRef Name) {
81+
assert(!(Flags & UsesRootSD) && "Uses root SD");
82+
SDName = Name;
83+
}
8284
void setLDorPRName(StringRef Name) { LDorPRName = Name; }
8385

8486
// Accessors to the various attributes.
@@ -99,9 +101,6 @@ class MCSectionGOFF final : public MCSection {
99101
bool hasPR() const { return Flags & HasPR; }
100102
bool isLDorPRNameTheSD() const { return Flags & LDorPRNameIsSD; }
101103

102-
bool isADA() const { return IsADA; }
103-
void setADA() { IsADA = true; }
104-
105104
static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; }
106105
};
107106
} // end namespace llvm

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,27 +2774,21 @@ MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
27742774
MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
27752775
const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
27762776
std::string Name = ".gcc_exception_table." + F.getName().str();
2777-
constexpr bool Is64Bit = true;
2778-
constexpr bool UsesXPLINK = true;
27792777
return getContext().getGOFFSection(
2780-
SectionKind::getData(), GOFF::WSA<true>,
2781-
GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE<Is64Bit>,
2782-
GOFF::RMODE<Is64Bit>, GOFF::ESD_NS_Parts,
2783-
GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
2784-
GOFF::LOADBEHAVIOR<UsesXPLINK>, GOFF::ESD_RQ_0,
2778+
SectionKind::getData(), GOFF::CLASS_WSA,
2779+
GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE, GOFF::RMODE,
2780+
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented,
2781+
GOFF::ESD_BA_Merge, GOFF::LOADBEHAVIOR, GOFF::ESD_RQ_0,
27852782
GOFF::ESD_ALIGN_Doubleword},
27862783
Name,
27872784
GOFF::PRAttr{true, false, GOFF::ESD_EXE_Unspecified, GOFF::ESD_NS_Parts,
2788-
GOFF::LINKAGE<UsesXPLINK>, GOFF::AMODE<Is64Bit>,
2789-
GOFF::ESD_BSC_Section, GOFF::ESD_DSS_NoWarning,
2790-
GOFF::ESD_ALIGN_Fullword, 0});
2785+
GOFF::LINKAGE, GOFF::AMODE, GOFF::ESD_BSC_Section,
2786+
GOFF::ESD_DSS_NoWarning, GOFF::ESD_ALIGN_Fullword, 0});
27912787
}
27922788

27932789
MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
27942790
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
27952791
auto *Symbol = TM.getSymbol(GO);
2796-
constexpr bool Is64Bit = true;
2797-
constexpr bool UsesXPLINK = true;
27982792

27992793
if (Kind.isBSS() || Kind.isData()) {
28002794
GOFF::ESDBindingScope PRBindingScope =
@@ -2807,19 +2801,17 @@ MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
28072801
: GOFF::ESD_BSC_Unspecified;
28082802
return getContext().getGOFFSection(
28092803
Kind, Symbol->getName(),
2810-
GOFF::SDAttr{GOFF::ESD_TA_Unspecified, SDBindingScope},
2811-
GOFF::WSA<Is64Bit>,
2812-
GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE<Is64Bit>,
2813-
GOFF::RMODE<Is64Bit>, GOFF::ESD_NS_Parts,
2814-
GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
2815-
GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_0,
2804+
GOFF::SDAttr{GOFF::ESD_TA_Unspecified, SDBindingScope}, GOFF::CLASS_WSA,
2805+
GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE, GOFF::RMODE,
2806+
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented,
2807+
GOFF::ESD_BA_Merge, GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_0,
28162808
static_cast<GOFF::ESDAlignment>(GO->getAlignment())
28172809

28182810
},
28192811
Symbol->getName(),
28202812
GOFF::PRAttr{false, false, GOFF::ESD_EXE_DATA, GOFF::ESD_NS_Parts,
2821-
GOFF::LINKAGE<UsesXPLINK>, GOFF::AMODE<Is64Bit>,
2822-
PRBindingScope, GOFF::ESD_DSS_NoWarning,
2813+
GOFF::LINKAGE, GOFF::AMODE, PRBindingScope,
2814+
GOFF::ESD_DSS_NoWarning,
28232815
static_cast<GOFF::ESDAlignment>(GO->getAlignment()), 0
28242816

28252817
});

llvm/lib/MC/GOFFObjectWriter.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ class GOFFWriter {
284284
uint32_t RootSDEsdId = 0;
285285
uint32_t ADAEsdId = 0;
286286

287+
MCSectionGOFF *ADA = nullptr;
288+
287289
void writeHeader();
288290
void writeSymbol(const GOFFSymbol &Symbol);
289291
void writeEnd();
@@ -296,7 +298,6 @@ class GOFFWriter {
296298
GOFFSymbol createGOFFSymbol(StringRef Name, const GOFF::PRAttr &Attr,
297299
uint32_t ParentEsdId);
298300

299-
void defineRootSymbol(const MCSectionGOFF *Text);
300301
void defineSectionSymbols(const MCSectionGOFF &Section);
301302
void defineSymbols();
302303

@@ -328,22 +329,14 @@ GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::PRAttr &Attr
328329
return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
329330
}
330331

331-
void GOFFWriter::defineRootSymbol(const MCSectionGOFF *Text) {
332-
// There is always a text section except for DWARF unit tests, so be lenient.
333-
GOFFSymbol RootSD =
334-
Text ? createGOFFSymbol(Text->getSDName(), Text->getSDAttributes())
335-
: createGOFFSymbol("", GOFF::SDAttr{GOFF::ESD_TA_Unspecified,
336-
GOFF::ESD_BSC_Unspecified});
337-
writeSymbol(RootSD);
338-
RootSDEsdId = RootSD.EsdId;
339-
}
340-
341332
void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
342333
uint32_t SDEsdId = RootSDEsdId;
343334
if (!Section.usesRootSD()) {
344335
GOFFSymbol SD =
345336
createGOFFSymbol(Section.getSDName(), Section.getSDAttributes());
346337
SDEsdId = SD.EsdId;
338+
if (RootSDEsdId == 0)
339+
RootSDEsdId = SDEsdId;
347340
writeSymbol(SD);
348341
}
349342

@@ -366,7 +359,7 @@ void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
366359
GOFFSymbol PR = createGOFFSymbol(Section.getLDorPRName(),
367360
Section.getPRAttributes(), ED.EsdId);
368361
PR.SectionLength = Asm.getSectionAddressSize(Section);
369-
if (Section.getName() == ".ada") {
362+
if (&Section == ADA) {
370363
// We cannot have a zero-length section for data. If we do,
371364
// artificially inflate it. Use 2 bytes to avoid odd alignments. Note:
372365
// if this is ever changed, you will need to update the code in
@@ -381,27 +374,12 @@ void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
381374
}
382375

383376
void GOFFWriter::defineSymbols() {
384-
// Search for .text and .ada sections.
385-
MCSectionGOFF *Text = nullptr;
386-
MCSectionGOFF *ADA = nullptr;
377+
// Process all sections.
387378
for (MCSection &S : Asm) {
388379
auto &Section = cast<MCSectionGOFF>(S);
389-
if (Section.isText())
390-
Text = &Section;
391-
if (Section.isADA())
380+
if (!ADA)
392381
ADA = &Section;
393-
}
394-
defineRootSymbol(Text);
395-
if (ADA)
396-
defineSectionSymbols(*ADA);
397-
if (Text)
398-
defineSectionSymbols(*Text);
399-
400-
// Process the other sections.
401-
for (MCSection &S : Asm) {
402-
auto &Section = cast<MCSectionGOFF>(S);
403-
if (Text != &Section && ADA != &Section)
404-
defineSectionSymbols(Section);
382+
defineSectionSymbols(Section);
405383
}
406384
}
407385

llvm/lib/MC/MCContext.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,11 @@ MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef SDName,
722722

723723
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef EDName,
724724
GOFF::EDAttr EDAttributes,
725+
StringRef LDorPRName,
725726
GOFF::LDAttr LDAttributes) {
726-
return getGOFFSection(Kind, "", GOFF::SDAttr{}, EDName, EDAttributes, "",
727-
LDAttributes, GOFF::PRAttr{},
728-
MCSectionGOFF::UsesRootSD |
729-
MCSectionGOFF::LDorPRNameIsSD |
730-
MCSectionGOFF::HasLD);
727+
return getGOFFSection(Kind, "", GOFF::SDAttr{}, EDName, EDAttributes,
728+
LDorPRName, LDAttributes, GOFF::PRAttr{},
729+
MCSectionGOFF::UsesRootSD | MCSectionGOFF::HasLD);
731730
}
732731

733732
MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef EDName,
@@ -743,8 +742,7 @@ MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef EDName,
743742
GOFF::EDAttr EDAttributes) {
744743
return getGOFFSection(Kind, "", GOFF::SDAttr{}, EDName, EDAttributes, "",
745744
GOFF::LDAttr{}, GOFF::PRAttr{},
746-
MCSectionGOFF::UsesRootSD |
747-
MCSectionGOFF::LDorPRNameIsSD);
745+
MCSectionGOFF::UsesRootSD);
748746
}
749747

750748
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,

llvm/lib/MC/MCGOFFStreamer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/MC/MCContext.h"
1818
#include "llvm/MC/MCGOFFObjectWriter.h"
1919
#include "llvm/MC/TargetRegistry.h"
20+
#include "llvm/Support/Path.h"
2021

2122
using namespace llvm;
2223

@@ -31,18 +32,19 @@ void MCGOFFStreamer::initSections(bool NoExecStack,
3132
MCContext &Ctx = getContext();
3233

3334
// Initialize the special names for the code and ada section.
34-
StringRef FileName = Ctx.getMainFileName();
35+
StringRef FileName = sys::path::stem(Ctx.getMainFileName());
3536
RootSDName = Twine(FileName).concat("#C").str();
3637
ADAPRName = Twine(FileName).concat("#S").str();
3738
MCSectionGOFF *TextSection =
3839
static_cast<MCSectionGOFF *>(Ctx.getObjectFileInfo()->getTextSection());
3940
MCSectionGOFF *ADASection =
4041
static_cast<MCSectionGOFF *>(Ctx.getObjectFileInfo()->getADASection());
41-
TextSection->setSDName(RootSDName);
42+
ADASection->setSDName(RootSDName);
4243
ADASection->setLDorPRName(ADAPRName);
43-
ADASection->setADA();
44+
TextSection->setLDorPRName(RootSDName);
4445

45-
// Switch to the code section.
46+
// Switch to the ADA section first, then code section.
47+
switchSection(ADASection);
4648
switchSection(TextSection);
4749
}
4850

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -547,51 +547,45 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
547547
}
548548

549549
void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
550-
// Some values depend on AMODE31 or AMODE64, or other properties.
551-
constexpr bool Is64Bit = true;
552-
constexpr bool UsesXPLINK = true;
553-
554550
TextSection = Ctx->getGOFFSection(
555-
SectionKind::getText(), GOFF::CODE<Is64Bit>,
556-
GOFF::EDAttr{true, GOFF::ESD_EXE_CODE, GOFF::AMODE<Is64Bit>,
557-
GOFF::RMODE<Is64Bit>, GOFF::ESD_NS_NormalName,
558-
GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Concatenate,
559-
GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
560-
GOFF::ESD_ALIGN_Doubleword},
551+
SectionKind::getText(), GOFF::CLASS_CODE,
552+
GOFF::EDAttr{true, GOFF::ESD_EXE_CODE, GOFF::AMODE, GOFF::RMODE,
553+
GOFF::ESD_NS_NormalName, GOFF::ESD_TS_ByteOriented,
554+
GOFF::ESD_BA_Concatenate, GOFF::ESD_LB_Initial,
555+
GOFF::ESD_RQ_0, GOFF::ESD_ALIGN_Doubleword}, "",
561556
GOFF::LDAttr{false, GOFF::ESD_EXE_CODE, GOFF::ESD_NS_NormalName,
562-
GOFF::ESD_BST_Strong, GOFF::LINKAGE<UsesXPLINK>,
563-
GOFF::AMODE<Is64Bit>, GOFF::ESD_BSC_Section});
557+
GOFF::ESD_BST_Strong, GOFF::LINKAGE, GOFF::AMODE,
558+
GOFF::ESD_BSC_Section});
564559

565560
PPA2ListSection = Ctx->getGOFFSection(
566-
SectionKind::getData(), GOFF::PPA2<Is64Bit>,
567-
GOFF::EDAttr{
568-
true, GOFF::ESD_EXE_DATA, GOFF::AMODE<Is64Bit>, GOFF::RMODE<Is64Bit>,
569-
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
570-
GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0, GOFF::ESD_ALIGN_Doubleword},
561+
SectionKind::getData(), GOFF::CLASS_PPA2,
562+
GOFF::EDAttr{true, GOFF::ESD_EXE_DATA, GOFF::AMODE, GOFF::RMODE,
563+
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented,
564+
GOFF::ESD_BA_Merge, GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
565+
GOFF::ESD_ALIGN_Doubleword},
571566
".&ppa2",
572567
GOFF::PRAttr{true, false, GOFF::ESD_EXE_Unspecified, GOFF::ESD_NS_Parts,
573-
GOFF::ESD_LT_OS, GOFF::AMODE<Is64Bit>, GOFF::ESD_BSC_Section,
568+
GOFF::ESD_LT_OS, GOFF::AMODE, GOFF::ESD_BSC_Section,
574569
GOFF::ESD_DSS_NoWarning, GOFF::ESD_ALIGN_Doubleword, 0});
575570

576571
ADASection = Ctx->getGOFFSection(
577-
SectionKind::getData(), GOFF::WSA<Is64Bit>,
578-
GOFF::EDAttr{
579-
false, GOFF::ESD_EXE_DATA, GOFF::AMODE<Is64Bit>, GOFF::RMODE<Is64Bit>,
580-
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
581-
GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_1, GOFF::ESD_ALIGN_Quadword},
572+
SectionKind::getData(), "",
573+
GOFF::SDAttr{GOFF::ESD_TA_Rent, GOFF::ESD_BSC_Section}, GOFF::CLASS_WSA,
574+
GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE, GOFF::RMODE,
575+
GOFF::ESD_NS_Parts, GOFF::ESD_TS_ByteOriented,
576+
GOFF::ESD_BA_Merge, GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_1,
577+
GOFF::ESD_ALIGN_Quadword},
582578
"",
583579
GOFF::PRAttr{false, false, GOFF::ESD_EXE_DATA, GOFF::ESD_NS_Parts,
584-
GOFF::ESD_LT_XPLink, GOFF::AMODE<Is64Bit>,
585-
GOFF::ESD_BSC_Section, GOFF::ESD_DSS_NoWarning,
586-
GOFF::ESD_ALIGN_Quadword, 0});
580+
GOFF::ESD_LT_XPLink, GOFF::AMODE, GOFF::ESD_BSC_Section,
581+
GOFF::ESD_DSS_NoWarning, GOFF::ESD_ALIGN_Quadword, 0});
587582

588583
IDRLSection = Ctx->getGOFFSection(
589584
SectionKind::getData(), "B_IDRL",
590-
GOFF::EDAttr{true, GOFF::ESD_EXE_Unspecified, GOFF::AMODE<Is64Bit>,
591-
GOFF::RMODE<Is64Bit>, GOFF::ESD_NS_NormalName,
592-
GOFF::ESD_TS_Structured, GOFF::ESD_BA_Concatenate,
593-
GOFF::ESD_LB_NoLoad, GOFF::ESD_RQ_0,
594-
GOFF::ESD_ALIGN_Doubleword});
585+
GOFF::EDAttr{true, GOFF::ESD_EXE_Unspecified, GOFF::AMODE, GOFF::RMODE,
586+
GOFF::ESD_NS_NormalName, GOFF::ESD_TS_Structured,
587+
GOFF::ESD_BA_Concatenate, GOFF::ESD_LB_NoLoad,
588+
GOFF::ESD_RQ_0, GOFF::ESD_ALIGN_Doubleword});
595589
}
596590

597591
void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {

0 commit comments

Comments
 (0)