Skip to content

Commit 3cf7324

Browse files
committed
Remove the class GOFFSymbolMapper
1 parent f2be856 commit 3cf7324

File tree

16 files changed

+362
-347
lines changed

16 files changed

+362
-347
lines changed

llvm/include/llvm/BinaryFormat/GOFF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class Flags {
204204
};
205205

206206
// Structure for the flag field of a symbol. See
207-
// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record ,
208-
// offset 41, for the definition.
207+
// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record
208+
// at offset 41 for the definition.
209209
struct SymbolFlags {
210210
Flags SymFlags;
211211

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ class TargetLoweringObjectFileGOFF : public TargetLoweringObjectFile {
320320
TargetLoweringObjectFileGOFF();
321321
~TargetLoweringObjectFileGOFF() override = default;
322322

323+
void getModuleMetadata(Module &M) override;
324+
323325
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
324326
const TargetMachine &TM) const override;
325327
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,

llvm/include/llvm/MC/MCContext.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#include "llvm/BinaryFormat/XCOFF.h"
2020
#include "llvm/MC/MCAsmMacro.h"
2121
#include "llvm/MC/MCDwarf.h"
22+
#include "llvm/MC/MCGOFFAttributes.h"
2223
#include "llvm/MC/MCPseudoProbe.h"
2324
#include "llvm/MC/MCSection.h"
25+
#include "llvm/MC/MCSectionGOFF.h"
2426
#include "llvm/MC/MCSymbolTableEntry.h"
2527
#include "llvm/MC/SectionKind.h"
2628
#include "llvm/Support/Allocator.h"
@@ -54,7 +56,6 @@ class MCSection;
5456
class MCSectionCOFF;
5557
class MCSectionDXContainer;
5658
class MCSectionELF;
57-
class MCSectionGOFF;
5859
class MCSectionMachO;
5960
class MCSectionSPIRV;
6061
class MCSectionWasm;
@@ -599,8 +600,36 @@ class MCContext {
599600
unsigned Flags,
600601
unsigned EntrySize);
601602

602-
MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind,
603-
MCSection *Parent, uint32_t Subsection = 0);
603+
private:
604+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
605+
GOFF::SDAttr SDAttributes, StringRef EDName,
606+
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
607+
GOFF::LDAttr LDAttributes,
608+
GOFF::PRAttr PRAttributes,
609+
MCSectionGOFF::SectionFlags Flags);
610+
611+
public:
612+
// Create a section with SD/ED/LD symbols.
613+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
614+
GOFF::SDAttr SDAttributes, StringRef EDName,
615+
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
616+
GOFF::LDAttr LDAttributes);
617+
// Create a section with SD/ED/PR symbols.
618+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
619+
GOFF::SDAttr SDAttributes, StringRef EDName,
620+
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
621+
GOFF::PRAttr PRAttributes);
622+
// Create a section with root-SD/ED/LD symbols, using the root-SD name for LD.
623+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
624+
GOFF::EDAttr EDAttributes,
625+
GOFF::LDAttr LDAttributes);
626+
// Create a section with root-SD/ED/PR symbols.
627+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
628+
GOFF::EDAttr EDAttributes, StringRef PRName,
629+
GOFF::PRAttr PRAttributes);
630+
// Create a section with root-SD/ED symbols.
631+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
632+
GOFF::EDAttr EDAttributes);
604633

605634
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
606635
StringRef COMDATSymName, int Selection,
Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
//===- MCGOFFSymbolMapper.h - Maps MC section/symbol to GOFF symbols ------===//
1+
//===- MCGOFFAttributes.h - Attributes of GOFF symbols --------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// Maps a section or a symbol to the GOFF symbols it is composed of, and their
10-
// attributes.
9+
// Defines the various attribute collections defining GOFF symbols.
1110
//
1211
//===----------------------------------------------------------------------===//
1312

14-
#ifndef LLVM_MC_MCGOFFSYMBOLMAPPER_H
15-
#define LLVM_MC_MCGOFFSYMBOLMAPPER_H
13+
#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
14+
#define LLVM_MC_MCGOFFATTRIBUTES_H
1615

1716
#include "llvm/ADT/StringRef.h"
1817
#include "llvm/BinaryFormat/GOFF.h"
19-
#include "llvm/Support/Alignment.h"
20-
#include <string>
21-
#include <utility>
2218

2319
namespace llvm {
24-
class MCAssembler;
25-
class MCContext;
26-
class MCSectionGOFF;
27-
20+
namespace GOFF {
2821
// An "External Symbol Definition" in the GOFF file has a type, and depending on
2922
// the type a different subset of the fields is used.
3023
//
@@ -40,8 +33,8 @@ class MCSectionGOFF;
4033
// the whole data is pulled into the resulting executable, and the addresses
4134
// given by the LD symbols are resolved.
4235
//
43-
// The alternative is to use a Part Definition (PR). In this case, the data (in a
44-
// text record) is associated with the part. When binding, only the data of
36+
// The alternative is to use a Part Definition (PR). In this case, the data (in
37+
// a text record) is associated with the part. When binding, only the data of
4538
// referenced PRs is pulled into the resulting binary.
4639
//
4740
// Both approaches are used, which means that the equivalent of a section in ELF
@@ -95,54 +88,40 @@ struct PRAttr {
9588
uint32_t SortKey = 0;
9689
};
9790

98-
struct GOFFSectionData {
99-
// Name and attributes of SD symbol.
100-
StringRef SDName;
101-
SDAttr SDAttributes;
102-
103-
// Name and attributes of ED symbol.
104-
StringRef EDName;
105-
EDAttr EDAttributes;
106-
107-
// Name and attributes of LD or PR symbol.
108-
StringRef LDorPRName;
109-
LDAttr LDAttributes;
110-
PRAttr PRAttributes;
91+
// 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");
11196

112-
// Indicates if there is a LD or PR symbol.
113-
enum { None, LD, PR } Tag;
114-
115-
// Indicates if the SD symbol is to root symbol (aka the Csect Code).
116-
bool IsSDRootSD;
117-
};
97+
template <bool Is64Bit>
98+
constexpr StringLiteral WSA =
99+
Is64Bit ? StringLiteral("C_WSA64") : StringLiteral("C_WSA");
118100

119-
class GOFFSymbolMapper {
120-
MCContext &Ctx;
101+
template <bool Is64Bit>
102+
constexpr StringLiteral DATA =
103+
Is64Bit ? StringLiteral("C_DATA64") : StringLiteral("C_DATA");
121104

122-
std::string RootSDName;
123-
SDAttr RootSDAttributes;
105+
template <bool Is64Bit>
106+
constexpr StringLiteral PPA2 =
107+
Is64Bit ? StringLiteral("C_@@QPPA2") : StringLiteral("C_@@PPA2");
124108

125-
std::string ADALDName;
109+
template <bool Is64Bit>
110+
constexpr GOFF::ESDAmode AMODE =
111+
Is64Bit ? GOFF::ESD_AMODE_64 : GOFF::ESD_AMODE_ANY;
126112

127-
StringRef BaseName;
113+
template <bool Is64Bit>
114+
constexpr GOFF::ESDRmode RMODE =
115+
Is64Bit ? GOFF::ESD_RMODE_64 : GOFF::ESD_RMODE_31;
128116

129-
bool IsCsectCodeNameEmpty;
130-
bool Is64Bit;
131-
bool UsesXPLINK;
132-
133-
public:
134-
GOFFSymbolMapper(MCContext &Ctx);
135-
GOFFSymbolMapper(MCAssembler &Asm);
136-
137-
// Required order: .text first, then .ada.
138-
std::pair<GOFFSectionData, bool> getSection(const MCSectionGOFF &Section);
139-
140-
void setBaseName();
141-
void determineRootSD(StringRef CSectCodeName);
142-
llvm::StringRef getRootSDName() const;
143-
const SDAttr &getRootSD() const;
144-
};
117+
template <bool IsXPLINK>
118+
constexpr GOFF::ESDLinkageType LINKAGE =
119+
IsXPLINK ? GOFF::ESD_LT_XPLink : GOFF::ESD_LT_OS;
145120

121+
template <bool IsXPLINK>
122+
constexpr GOFF::ESDLoadingBehavior LOADBEHAVIOR =
123+
IsXPLINK ? GOFF::ESD_LB_Initial : GOFF::ESD_LB_Deferred;
124+
} // namespace GOFF
146125
} // namespace llvm
147126

148127
#endif

llvm/include/llvm/MC/MCGOFFStreamer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace llvm {
1616
class GOFFObjectWriter;
1717

1818
class MCGOFFStreamer : public MCObjectStreamer {
19+
std::string RootSDName;
20+
std::string ADAPRName;
21+
1922
public:
2023
MCGOFFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
2124
std::unique_ptr<MCObjectWriter> OW,
@@ -25,6 +28,8 @@ class MCGOFFStreamer : public MCObjectStreamer {
2528

2629
~MCGOFFStreamer() override;
2730

31+
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
32+
2833
GOFFObjectWriter &getWriter();
2934

3035
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {

llvm/include/llvm/MC/MCObjectFileInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ class MCObjectFileInfo {
230230
MCSection *GLJMPSection = nullptr;
231231

232232
// GOFF specific sections.
233-
MCSection *PPA1Section = nullptr;
234-
MCSection *PPA2Section = nullptr;
235233
MCSection *PPA2ListSection = nullptr;
236234
MCSection *ADASection = nullptr;
237235
MCSection *IDRLSection = nullptr;
@@ -438,8 +436,6 @@ class MCObjectFileInfo {
438436
MCSection *getGLJMPSection() const { return GLJMPSection; }
439437

440438
// GOFF specific sections.
441-
MCSection *getPPA1Section() const { return PPA1Section; }
442-
MCSection *getPPA2Section() const { return PPA2Section; }
443439
MCSection *getPPA2ListSection() const { return PPA2ListSection; }
444440
MCSection *getADASection() const { return ADASection; }
445441
MCSection *getIDRLSection() const { return IDRLSection; }

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#ifndef LLVM_MC_MCSECTIONGOFF_H
1616
#define LLVM_MC_MCSECTIONGOFF_H
1717

18+
#include "llvm/ADT/BitmaskEnum.h"
1819
#include "llvm/BinaryFormat/GOFF.h"
20+
#include "llvm/MC/MCGOFFAttributes.h"
1921
#include "llvm/MC/MCSection.h"
2022
#include "llvm/Support/raw_ostream.h"
2123

@@ -25,13 +27,38 @@ class MCExpr;
2527

2628
class MCSectionGOFF final : public MCSection {
2729
private:
28-
MCSection *Parent;
29-
uint32_t Subsection;
30+
// The names of the GOFF symbols.
31+
StringRef SDName;
32+
StringRef EDName;
33+
StringRef LDorPRName;
34+
35+
// The attributes of the GOFF symbols.
36+
GOFF::SDAttr SDAttributes;
37+
GOFF::EDAttr EDAttributes;
38+
GOFF::LDAttr LDAttributes;
39+
GOFF::PRAttr PRAttributes;
40+
41+
public:
42+
enum SectionFlags {
43+
UsesRootSD = 1, // Uses the common root SD.
44+
HasLD = 2, // Has a LD symbol.
45+
HasPR = 4, // Has a PR symbol.
46+
LDorPRNameIsSD = 8, // The LD or PR name is the same as the SD name.
47+
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ 8)
48+
};
49+
50+
private:
51+
SectionFlags Flags;
52+
bool IsADA;
3053

3154
friend class MCContext;
32-
MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub)
33-
: MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
34-
Parent(P), Subsection(Sub) {}
55+
MCSectionGOFF(StringRef SynName, SectionKind K, SectionFlags Flags,
56+
StringRef SDName, GOFF::SDAttr SDAttributes, StringRef EDName,
57+
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
58+
GOFF::LDAttr LDAttributes, GOFF::PRAttr PRAttributes)
59+
: MCSection(SV_GOFF, SynName, K.isText(), /*IsVirtual=*/false, nullptr),
60+
SDName(SDName), EDName(EDName), LDorPRName(LDorPRName),
61+
SDAttributes(SDAttributes), EDAttributes(EDAttributes), Flags(Flags) {}
3562

3663
public:
3764
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
@@ -42,8 +69,38 @@ class MCSectionGOFF final : public MCSection {
4269

4370
bool useCodeAlign() const override { return false; }
4471

45-
MCSection *getParent() const { return Parent; }
46-
uint32_t getSubsection() const { return Subsection; }
72+
// Accessors to the various symbol names.
73+
StringRef getSDName() const { return SDName; };
74+
StringRef getEDName() const { return EDName; };
75+
StringRef getLDorPRName() const {
76+
assert(Flags & (HasLD | HasPR) && "LD/PR name not available");
77+
return (Flags & LDorPRNameIsSD) ? SDName : LDorPRName;
78+
};
79+
80+
// Setters for the SD and LD/PR symbol names.
81+
void setSDName(StringRef Name) { SDName = Name; }
82+
void setLDorPRName(StringRef Name) { LDorPRName = Name; }
83+
84+
// Accessors to the various attributes.
85+
GOFF::SDAttr getSDAttributes() const { return SDAttributes; }
86+
GOFF::EDAttr getEDAttributes() const { return EDAttributes; }
87+
GOFF::LDAttr getLDAttributes() const {
88+
assert(Flags & HasLD && "LD not available");
89+
return LDAttributes;
90+
}
91+
GOFF::PRAttr getPRAttributes() const {
92+
assert(Flags & HasPR && "PR not available");
93+
return PRAttributes;
94+
}
95+
96+
// Query various flags.
97+
bool usesRootSD() const { return Flags & UsesRootSD; }
98+
bool hasLD() const { return Flags & HasLD; }
99+
bool hasPR() const { return Flags & HasPR; }
100+
bool isLDorPRNameTheSD() const { return Flags & LDorPRNameIsSD; }
101+
102+
bool isADA() const { return IsADA; }
103+
void setADA() { IsADA = true; }
47104

48105
static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; }
49106
};

0 commit comments

Comments
 (0)