Skip to content

Commit c1bfe45

Browse files
committed
Fix build error + some issues with section symbols
1 parent 7387343 commit c1bfe45

File tree

6 files changed

+55
-86
lines changed

6 files changed

+55
-86
lines changed

Diff for: llvm/include/llvm/MC/MCContext.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ class MCContext {
660660
GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial,
661661
GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified,
662662
bool isRooted = false,
663-
MCSymbolGOFF *TextOwner = nullptr);
663+
const MCSymbolGOFF *TextOwner = nullptr);
664664

665665
MCSectionGOFF *
666666
getGOFFSection(StringRef Section, SectionKind Kind,
@@ -671,7 +671,7 @@ class MCContext {
671671
GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate,
672672
GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial,
673673
GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified,
674-
bool isRooted = false, MCSymbolGOFF * TextOwner = nullptr);
674+
bool isRooted = false, const MCSymbolGOFF * TextOwner = nullptr);
675675

676676
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
677677
SectionKind Kind, StringRef COMDATSymName,

Diff for: llvm/include/llvm/MC/MCSectionGOFF.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ class MCSectionGOFF final : public MCSection {
5252
/// TextOwner - Valid if owned the text record containing the body of this section
5353
/// is not owned by an ED Symbol. The MCSymbol that represents the part or label that
5454
/// actually owns the TXT Record.
55-
MCSymbolGOFF *TextOwner = nullptr;
55+
const MCSymbolGOFF *TextOwner = nullptr;
5656

5757
friend class MCContext;
5858
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, const MCExpr *Sub)
5959
: MCSection(SV_GOFF, Name, K, nullptr), Parent(P), SubsectionId(Sub) {}
6060

6161
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, const MCExpr *Sub,
6262
GOFF::ESDTextStyle TextStyle, GOFF::ESDBindingAlgorithm BindAlgorithm,
63-
GOFF::ESDLoadingBehavior LoadBehavior, GOFF::ESDBindingScope BindingScope, bool IsRooted, MCSymbolGOFF *TextOwner)
63+
GOFF::ESDLoadingBehavior LoadBehavior, GOFF::ESDBindingScope BindingScope, bool IsRooted, const MCSymbolGOFF *TextOwner)
6464
: MCSection(SV_GOFF, Name, K, nullptr), Parent(P), SubsectionId(Sub),
6565
TextStyle(TextStyle), BindAlgorithm(BindAlgorithm), LoadBehavior(LoadBehavior), BindingScope(BindingScope), IsRooted(IsRooted), TextOwner(TextOwner) {}
6666

@@ -124,7 +124,7 @@ class MCSectionGOFF final : public MCSection {
124124
case GOFF::GOFFSectionType::Static:
125125
return "C_WSA64";
126126
case GOFF::GOFFSectionType::PPA2Offset:
127-
return "C_QPPA2";
127+
return "C_@@QPPA2";
128128
case GOFF::GOFFSectionType::B_IDRL:
129129
return "B_IDRL";
130130
case GOFF::GOFFSectionType::Other:
@@ -133,7 +133,7 @@ class MCSectionGOFF final : public MCSection {
133133
return "";
134134
}
135135

136-
std::optional<MCSymbolGOFF *> getTextOwner() const {
136+
std::optional<const MCSymbolGOFF *> getTextOwner() const {
137137
if (TextOwnedByED)
138138
return std::nullopt;
139139
else if (TextOwner)

Diff for: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2738,20 +2738,21 @@ MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
27382738
MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
27392739
const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
27402740
std::string Name = ".gcc_exception_table." + F.getName().str();
2741+
const auto *Symbol = cast<MCSymbolGOFF>(&FnSym);
27412742
return getContext().getGOFFSection(Name, SectionKind::getData(),
27422743
GOFF::ESD_TS_ByteOriented,
27432744
GOFF::ESD_BA_Merge,
27442745
GOFF::ESD_LB_Deferred,
27452746
GOFF::ESD_BSC_Section,
2746-
true, &FnSym);
2747+
true, Symbol);
27472748
}
27482749

27492750
MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
27502751
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
2751-
auto *Symbol = cast<MCSymbolGOFF *>(TM.getSymbol(GO));
2752+
auto *Symbol = cast<MCSymbolGOFF>(TM.getSymbol(GO));
27522753
if (Kind.isData() || Kind.isBSS()) {
2753-
auto BindingScope = Symbol.isExternal()
2754-
? (Symbol.isExported() ? GOFF::ESD_BSC_ImportExport
2754+
auto BindingScope = Symbol->isExternal()
2755+
? (Symbol->isExported() ? GOFF::ESD_BSC_ImportExport
27552756
: GOFF::ESD_BSC_Library)
27562757
: GOFF::ESD_BSC_Section;
27572758
return getContext().getGOFFSection(Symbol->getName(), Kind,

Diff for: llvm/lib/MC/GOFFObjectWriter.cpp

+41-72
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ class GOFFObjectWriter : public MCObjectWriter {
326326
uint32_t EntryEDEsdId;
327327
uint32_t CodeLDEsdId;
328328

329+
std::string FileName;
330+
329331
public:
330332
GOFFObjectWriter(std::unique_ptr<MCGOFFObjectTargetWriter> MOTW,
331333
raw_pwrite_stream &OS)
@@ -339,16 +341,33 @@ class GOFFObjectWriter : public MCObjectWriter {
339341

340342
void writeSymbol(const GOFFSymbol &Symbol, const MCAsmLayout &Layout);
341343

342-
void writeADAandCodeSectionSymbols(MCAssembler &Asm,
343-
const MCAsmLayout &Layout);
344+
const MCSectionGOFF *getCodeSection(const MCAssembler &Asm) const {
345+
for (const MCSection &MCSec : Asm) {
346+
auto &GSec = cast<MCSectionGOFF>(MCSec);
347+
if (GSec.isCode())
348+
return &GSec;
349+
}
350+
llvm_unreachable("Code CSect not found!\n");
351+
return nullptr;
352+
}
353+
354+
const MCSectionGOFF *getStaticSection(const MCAssembler &Asm) const {
355+
for (const MCSection &MCSec : Asm) {
356+
auto &GSec = cast<MCSectionGOFF>(MCSec);
357+
if (GSec.isStatic())
358+
return &GSec;
359+
}
360+
llvm_unreachable("Static CSect not found!\n");
361+
return nullptr;
362+
}
344363

345364
std::pair<GOFFSymbol, GOFFSymbol> getSDEDSymbolsForSection(const MCSectionGOFF& GSection, const MCAsmLayout Layout);
346365

347-
// Write out all ESD Symbols that own a section. GOFF doesn't have
366+
// Write out all ESD Symbols that make up a section. GOFF doesn't have
348367
// "sections" in the way other object file formats like ELF do; instead
349368
// a GOFF section is defined as a triple of ESD Symbols (SD, ED, PR/LD).
350-
// The PR/LD symbol should own a TXT record that contains the actual
351-
// data of the section.
369+
// The ED or PR symbol should own a TXT Record that contains the contents
370+
// of the section itself
352371
void writeSectionSymbols(const MCSectionGOFF &GSection, MCAssembler &Asm, const MCAsmLayout &Layout);
353372

354373
void writeText(const MCSectionGOFF *MCSec, uint32_t EsdId,
@@ -528,27 +547,10 @@ GOFFSymbol GOFFObjectWriter::createWSASymbol(uint32_t ParentEsdId,
528547
return WSA;
529548
}
530549

531-
static uint32_t getADASectionLength(MCAssembler &Asm,
532-
const MCAsmLayout &Layout) {
533-
uint32_t SecLen = 0;
534-
for (const MCSection &MCSec : Asm) {
535-
auto &GSec = cast<MCSectionGOFF>(MCSec);
536-
if (GSec.isStatic()) {
537-
SecLen = Layout.getSectionAddressSize(&MCSec);
538-
}
539-
}
540-
541-
// The ADA section is not allowed to be zero-length. We also want to
542-
// avoid odd alignments, so we use 2 bytes.
543-
return std::max(SecLen, 2u);
544-
}
545-
546550
void GOFFObjectWriter::defineRootSD(MCAssembler &Asm,
547551
const MCAsmLayout &Layout) {
548-
StringRef FileName = "";
549-
if (!Asm.getFileNames().empty())
550-
FileName = sys::path::stem((*(Asm.getFileNames().begin())).first);
551-
RootSD = createSDSymbol(FileName.str().append("#C"));
552+
std::string RootName = FileName + "#C";
553+
RootSD = createSDSymbol(RootName);
552554
RootSD.BindingScope = GOFF::ESD_BSC_Section;
553555
RootSD.Executable = GOFF::ESD_EXE_CODE;
554556
}
@@ -659,8 +661,8 @@ void GOFFObjectWriter::writeSymbolDeclaredInModule(const MCSymbolGOFF &Symbol,
659661

660662
void GOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
661663
const MCAsmLayout &Layout) {
662-
LLVM_DEBUG(dbgs() << "Entering " << __FUNCTION__ << "\n");
663-
664+
if (!Asm.getFileNames().empty())
665+
FileName = sys::path::stem((*(Asm.getFileNames().begin())).first);
664666
defineRootSD(Asm, Layout);
665667
}
666668

@@ -863,50 +865,6 @@ void GOFFObjectWriter::writeSymbol(const GOFFSymbol &Symbol,
863865
OS.write(Name.data(), NameLength); // Name
864866
}
865867

866-
void GOFFObjectWriter::writeADAandCodeSectionSymbols(
867-
MCAssembler &Asm, const MCAsmLayout &Layout) {
868-
// Write ESD Records for ADA Section
869-
GOFFSymbol ADAED = createWSASymbol(RootSD.EsdId, true);
870-
StringRef FileName = "";
871-
if (!Asm.getFileNames().empty())
872-
FileName = sys::path::stem((*(Asm.getFileNames().begin())).first);
873-
874-
GOFFSymbol ADA;
875-
ADA = createPRSymbol(FileName.str().append("#S"), ADAED.EsdId,
876-
GOFF::ESD_NS_Parts, GOFF::ESD_EXE_DATA,
877-
GOFF::ESD_ALIGN_Quadword, GOFF::ESD_BSC_Section,
878-
getADASectionLength(Asm, Layout));
879-
writeSymbol(ADAED, Layout);
880-
writeSymbol(ADA, Layout);
881-
ADAPREsdId = ADA.EsdId;
882-
883-
// Write ESD Records for Code Section
884-
GOFFSymbol ED =
885-
createEDSymbol("C_CODE64", RootSD.EsdId, 0, GOFF::ESD_EXE_CODE, true);
886-
887-
for (const MCSection &MCSec : Asm) {
888-
auto &GSec = cast<MCSectionGOFF>(MCSec);
889-
if (GSec.isCode()) {
890-
if (!ED.SectionLength)
891-
ED.SectionLength = Layout.getSectionAddressSize(&MCSec);
892-
}
893-
}
894-
895-
GOFFSymbol LD = createLDSymbol(RootSD.Name, ED.EsdId);
896-
LD.Executable = GOFF::ESD_EXE_CODE;
897-
if (RootSD.BindingScope == GOFF::ESD_BSC_Section)
898-
LD.BindingScope = GOFF::ESD_BSC_Section;
899-
else
900-
LD.BindingScope = GOFF::ESD_BSC_Library;
901-
902-
LD.ADAEsdId = ADAPREsdId;
903-
904-
EntryEDEsdId = ED.EsdId;
905-
CodeLDEsdId = LD.EsdId;
906-
writeSymbol(ED, Layout);
907-
writeSymbol(LD, Layout);
908-
}
909-
910868
std::pair<GOFFSymbol, GOFFSymbol> GOFFObjectWriter::getSDEDSymbolsForSection(const MCSectionGOFF& GSection, const MCAsmLayout Layout) {
911869
GOFFSymbol SD = GSection.getRooted() ? RootSD : createSDSymbol(GSection.getName());
912870

@@ -922,7 +880,6 @@ std::pair<GOFFSymbol, GOFFSymbol> GOFFObjectWriter::getSDEDSymbolsForSection(con
922880
return std::make_pair(SD, ED);
923881
}
924882

925-
926883
void GOFFObjectWriter::writeSectionSymbols(const MCSectionGOFF &GSection,
927884
MCAssembler &Asm,
928885
const MCAsmLayout &Layout) {
@@ -936,6 +893,8 @@ void GOFFObjectWriter::writeSectionSymbols(const MCSectionGOFF &GSection,
936893
if (GSection.isCode()) {
937894
GOFFSymbol LD = createLDSymbol(RootSD.Name, SDEDSymbols.second.EsdId);
938895
LD.BindingScope = GOFF::ESD_BSC_Section;
896+
EntryEDEsdId = SDEDSymbols.second.EsdId;
897+
CodeLDEsdId = LD.EsdId;
939898
GOFFSection GoffSec = GOFFSection(LD.EsdId, SDEDSymbols.second.EsdId, SDEDSymbols.first.EsdId);
940899
writeSymbol(LD, Layout);
941900
} else if (!GSection.isTextOwnedByED()) {
@@ -946,14 +905,17 @@ void GOFFObjectWriter::writeSectionSymbols(const MCSectionGOFF &GSection,
946905
Executability = GSym.value()->getExecutable();
947906
IsOSLinkage = GSym.value()->isOSLinkage();
948907
}
949-
GOFFSymbol PR = createPRSymbol(GSection.getTextOwnerName(), SDEDSymbols.second.EsdId,
908+
std::string ADAName = FileName + "#S";
909+
GOFFSymbol PR = createPRSymbol(GSection.isStatic() ? ADAName : GSection.getTextOwnerName(),
910+
SDEDSymbols.second.EsdId,
950911
GOFF::ESD_NS_Parts,
951912
Executability,
952913
GOFFSymbol::setGOFFAlignment(GSection.getAlign()),
953914
GOFF::ESD_BSC_Section,
954915
Layout.getSectionAddressSize(&GSection),
955916
GSection.getLoadBehavior(),
956917
IsOSLinkage ? GOFF::ESD_LT_OS : GOFF::ESD_LT_XPLink);
918+
ADAPREsdId = PR.EsdId;
957919
writeSymbol(PR, Layout);
958920
GOFFSection GoffSec = GOFFSection(PR.EsdId, SDEDSymbols.second.EsdId, SDEDSymbols.first.EsdId);
959921
SectionMap.insert(std::make_pair(&GSection, GoffSec));
@@ -1061,12 +1023,18 @@ uint64_t GOFFObjectWriter::writeObject(MCAssembler &Asm,
10611023
writeHeader();
10621024
writeSymbol(RootSD, Layout);
10631025

1026+
// The static and code sections must be written first because the symbols that make up the aforementioned sections
1027+
// are referenced by several other symbols/sections.
1028+
writeSectionSymbols(*getStaticSection(Asm), Asm, Layout);
1029+
writeSectionSymbols(*getCodeSection(Asm), Asm, Layout);
1030+
10641031
for (MCSection &S : Asm) {
10651032
auto &GSection = cast<MCSectionGOFF>(S);
10661033
if (!(GSection.isCode() || GSection.isStatic()))
10671034
writeSectionSymbols(GSection, Asm, Layout);
10681035
}
10691036

1037+
/*
10701038
// Process all MCSymbols and generate the ESD Record(s) for them.
10711039
// Symbols that are aliases of other symbols need to be processed
10721040
// at the end, after the symbols they alias are processed.
@@ -1088,6 +1056,7 @@ uint64_t GOFFObjectWriter::writeObject(MCAssembler &Asm,
10881056
static_cast<GOFF::TXTRecordStyle>(MCGOFFSec.getTextStyle());
10891057
writeText(&MCGOFFSec, CurrGSec.PEsdId, TextStyle, Asm, Layout);
10901058
}
1059+
*/
10911060

10921061
writeEnd();
10931062

Diff for: llvm/lib/MC/MCContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind,
656656
GOFF::ESDBindingAlgorithm BindAlgorithm,
657657
GOFF::ESDLoadingBehavior LoadBehavior,
658658
GOFF::ESDBindingScope BindingScope,
659-
bool isRooted, MCSymbolGOFF *TextOwner) {
659+
bool isRooted, const MCSymbolGOFF *TextOwner) {
660660
return getGOFFSection(Section, Kind, nullptr, nullptr, GOFF::GOFFSectionType::Other,
661661
TextStyle, BindAlgorithm, LoadBehavior, BindingScope, isRooted, TextOwner);
662662
}
@@ -669,7 +669,7 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind,
669669
GOFF::ESDBindingAlgorithm BindAlgorithm,
670670
GOFF::ESDLoadingBehavior LoadBehavior,
671671
GOFF::ESDBindingScope BindingScope,
672-
bool isRooted, MCSymbolGOFF *TextOwner) {
672+
bool isRooted, const MCSymbolGOFF *TextOwner) {
673673
// Do the lookup. If we don't have a hit, return a new section.
674674
auto IterBool = GOFFUniquingMap.insert(std::make_pair(
675675
GOFFSectionKey{Section.str(), SectionType, (Parent != nullptr)},

Diff for: llvm/lib/MC/MCObjectFileInfo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
556556
MCConstantExpr::create(GOFF::SK_PPA1, *Ctx));
557557
PPA2Section =
558558
Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(), TextSection,
559-
MCConstantExpr::create(GOFF::SK_PPA2, *Ctx),
560-
GOFF::GOFFSectionType::PPA2Offset);
559+
MCConstantExpr::create(GOFF::SK_PPA2, *Ctx));
561560

562561
PPA2ListSection =
563562
Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr, nullptr,

0 commit comments

Comments
 (0)