Skip to content

Commit 72d36e3

Browse files
committed
[GOFF] Emit symbols for functions.
A function entry is mapped to a LD symbol with an offset to the begin of the section.
1 parent 232c292 commit 72d36e3

File tree

7 files changed

+142
-18
lines changed

7 files changed

+142
-18
lines changed

llvm/include/llvm/MC/MCGOFFStreamer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class MCGOFFStreamer : public MCObjectStreamer {
3030

3131
GOFFObjectWriter &getWriter();
3232

33-
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
34-
return false;
35-
}
33+
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
34+
35+
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
36+
3637
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3738
Align ByteAlignment) override {}
3839
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override {}

llvm/include/llvm/MC/MCSymbolGOFF.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ class MCSymbolGOFF : public MCSymbol {
2828
GOFF::LDAttr LDAttributes;
2929

3030
enum SymbolFlags : uint16_t {
31-
SF_LD = 0x01, // LD attributes are set.
31+
SF_LD = 0x01, // LD attributes are set.
32+
// Leave place for EX attributes.
33+
SF_Hidden = 0x04, // Symbol is hidden, aka not exported.
34+
SF_Weak = 0x08, // Symbol is weak.
3235
};
3336

3437
public:
@@ -39,7 +42,8 @@ class MCSymbolGOFF : public MCSymbol {
3942
modifyFlags(SF_LD, SF_LD);
4043
LDAttributes = Attr;
4144
}
42-
GOFF::LDAttr getLDAttributes() const { return LDAttributes; }
45+
const GOFF::LDAttr &getLDAttributes() const { return LDAttributes; }
46+
GOFF::LDAttr &getLDAttributes() { return LDAttributes; }
4347
bool hasLDAttributes() const { return getFlags() & SF_LD; }
4448

4549
void setADA(MCSectionGOFF *AssociatedDataArea) {
@@ -48,6 +52,17 @@ class MCSymbolGOFF : public MCSymbol {
4852
}
4953
MCSectionGOFF *getADA() const { return ADA; }
5054

55+
void setHidden(bool Value = true) {
56+
modifyFlags(Value ? SF_Hidden : 0, SF_Hidden);
57+
}
58+
bool isHidden() const { return getFlags() & SF_Hidden; }
59+
bool isExported() const { return !isHidden(); }
60+
61+
void setWeak(bool Value = true) { modifyFlags(Value ? SF_Weak : 0, SF_Weak); }
62+
bool isWeak() const { return getFlags() & SF_Weak; }
63+
64+
void initAttributes();
65+
5166
static bool classof(const MCSymbol *S) { return S->isGOFF(); }
5267
};
5368
} // end namespace llvm

llvm/lib/MC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ add_llvm_component_library(LLVMMC
5555
MCSubtargetInfo.cpp
5656
MCSymbol.cpp
5757
MCSymbolELF.cpp
58+
MCSymbolGOFF.cpp
5859
MCSymbolXCOFF.cpp
5960
MCTargetOptions.cpp
6061
MCTargetOptionsCommandFlags.cpp

llvm/lib/MC/GOFFObjectWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void GOFFWriter::defineLabel(const MCSymbolGOFF &Symbol) {
329329
Section.getEDAttributes().NameSpace, Symbol.getLDAttributes());
330330
if (Symbol.getADA())
331331
LD.ADAEsdId = Symbol.getADA()->getOrdinal();
332+
LD.Offset = Asm.getSymbolOffset(Symbol);
332333
writeSymbol(LD);
333334
}
334335

llvm/lib/MC/MCGOFFStreamer.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
#include "llvm/MC/MCAssembler.h"
1616
#include "llvm/MC/MCCodeEmitter.h"
1717
#include "llvm/MC/MCContext.h"
18+
#include "llvm/MC/MCDirectives.h"
1819
#include "llvm/MC/MCGOFFObjectWriter.h"
20+
#include "llvm/MC/MCSymbolGOFF.h"
1921
#include "llvm/MC/TargetRegistry.h"
22+
#include "llvm/Support/Casting.h"
2023

2124
using namespace llvm;
2225

@@ -41,6 +44,61 @@ void MCGOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
4144
MCObjectStreamer::changeSection(Section, Subsection);
4245
}
4346

47+
void MCGOFFStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
48+
MCObjectStreamer::emitLabel(Symbol, Loc);
49+
cast<MCSymbolGOFF>(Symbol)->initAttributes();
50+
}
51+
52+
bool MCGOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
53+
MCSymbolAttr Attribute) {
54+
auto *Symbol = cast<MCSymbolGOFF>(Sym);
55+
switch (Attribute) {
56+
case MCSA_Invalid:
57+
case MCSA_Cold:
58+
case MCSA_ELF_TypeFunction:
59+
case MCSA_ELF_TypeIndFunction:
60+
case MCSA_ELF_TypeObject:
61+
case MCSA_ELF_TypeTLS:
62+
case MCSA_ELF_TypeCommon:
63+
case MCSA_ELF_TypeNoType:
64+
case MCSA_ELF_TypeGnuUniqueObject:
65+
case MCSA_LGlobal:
66+
case MCSA_Extern:
67+
case MCSA_Exported:
68+
case MCSA_IndirectSymbol:
69+
case MCSA_Internal:
70+
case MCSA_LazyReference:
71+
case MCSA_NoDeadStrip:
72+
case MCSA_SymbolResolver:
73+
case MCSA_AltEntry:
74+
case MCSA_PrivateExtern:
75+
case MCSA_Protected:
76+
case MCSA_Reference:
77+
case MCSA_WeakDefinition:
78+
case MCSA_WeakDefAutoPrivate:
79+
case MCSA_WeakAntiDep:
80+
case MCSA_Memtag:
81+
return false;
82+
83+
case MCSA_Global:
84+
Symbol->setExternal(true);
85+
break;
86+
case MCSA_Local:
87+
Symbol->setExternal(false);
88+
break;
89+
case MCSA_Weak:
90+
case MCSA_WeakReference:
91+
Symbol->setExternal(true);
92+
Symbol->setWeak();
93+
break;
94+
case MCSA_Hidden:
95+
Symbol->setHidden(true);
96+
break;
97+
}
98+
99+
return true;
100+
}
101+
44102
MCStreamer *llvm::createGOFFStreamer(MCContext &Context,
45103
std::unique_ptr<MCAsmBackend> &&MAB,
46104
std::unique_ptr<MCObjectWriter> &&OW,

llvm/lib/MC/MCSymbolGOFF.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- MCSymbolGOFF.cpp - GOFF Symbol Representation ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/MC/MCSymbolGOFF.h"
10+
#include "llvm/BinaryFormat/GOFF.h"
11+
#include "llvm/Support/Casting.h"
12+
#include "llvm/Support/ErrorHandling.h"
13+
14+
using namespace llvm;
15+
16+
void MCSymbolGOFF::initAttributes() {
17+
if (hasLDAttributes())
18+
return;
19+
20+
if (isDefined()) {
21+
MCSectionGOFF &Section = cast<MCSectionGOFF>(getSection());
22+
GOFF::ESDBindingScope BindingScope =
23+
isExternal() ? (isExported() ? GOFF::ESD_BSC_ImportExport
24+
: GOFF::ESD_BSC_Library)
25+
: GOFF::ESD_BSC_Section;
26+
GOFF::ESDBindingStrength BindingStrength =
27+
isWeak() ? GOFF::ESDBindingStrength::ESD_BST_Weak
28+
: GOFF::ESDBindingStrength::ESD_BST_Strong;
29+
if (Section.isED()) {
30+
setLDAttributes(GOFF::LDAttr{false, GOFF::ESD_EXE_CODE, BindingStrength,
31+
GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64,
32+
BindingScope});
33+
} else if (Section.isPR()) {
34+
// For data symbols, the attributes are already determind in TLOFI.
35+
// TODO Does it make sense to it to here?
36+
} else
37+
llvm_unreachable("Unexpected section type for label");
38+
}
39+
// TODO Handle external symbol.
40+
}

llvm/test/CodeGen/SystemZ/zos-section-1.ll

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,34 @@ entry:
104104
; CHECK-NEXT: 000300 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 02
105105
; CHECK-NEXT: 000310 00 01 20 00 00 00 00 06 a3 85 a2 a3 7b c3 00 00
106106

107+
; ESD record, type LD.
108+
; The name is me.
109+
; CHECK-NEXT: 000320 03 00 00 02 [[ME:00 00 00 09]] [[C_CODE64]] 00 00 00 00
110+
; CHECK-NEXT: 000330 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00
111+
; CHECK-NEXT: 000340 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
112+
; CHECK-NEXT: 000350 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 02
113+
; CHECK-NEXT: 000360 00 04 20 00 00 00 00 02 94 85 00 00 00 00 00 00
114+
107115
; Text record for the code section C_CODE64.
108116
; The regular expression matches the lower byte of the length.
109-
; CHECK-NEXT: 000320 03 11 00 00 [[C_CODE64]] 00 00 00 00 00 00 00 00
110-
; CHECK-NEXT: 000330 00 00 00 00 00 00 00 {{..}} 00 c3 00 c5 00 c5 00 f1
117+
; CHECK-NEXT: 000370 03 11 00 00 [[C_CODE64]] 00 00 00 00 00 00 00 00
118+
; CHECK-NEXT: 000380 00 00 00 00 00 00 00 {{..}} 00 c3 00 c5 00 c5 00 f1
111119

112120
; Text record for the section .&ppa2.
113-
; CHECK: 0003c0 03 10 00 00 [[PPA2]] 00 00 00 00 00 00 00 00
114-
; CHECK-NEXT: 0003d0 00 00 00 00 00 00 00 {{..}} {{.*}}
121+
; CHECK: 000410 03 10 00 00 [[PPA2]] 00 00 00 00 00 00 00 00
122+
; CHECK-NEXT: 000420 00 00 00 00 00 00 00 {{..}} {{.*}}
115123

116124
; Text record for the ADA section test#S.
117-
; CHECK: 000410 03 10 00 00 [[TESTS]] 00 00 00 00 00 00 00 00
118-
; CHECK-NEXT: 000420 00 00 00 00 00 00 00 {{..}} {{.*}}
125+
; CHECK: 000460 03 10 00 00 [[TESTS]] 00 00 00 00 00 00 00 00
126+
; CHECK-NEXT: 000470 00 00 00 00 00 00 00 {{..}} {{.*}}
119127

120128
; Text record for the section B_IDRL.
121-
; CHECK: 000460 03 10 00 01 [[BIDRL]] 00 00 00 00 00 00 00 00
122-
; CHECK-NEXT: 000470 00 00 00 00 00 00 00 {{..}} {{.*}}
129+
; CHECK: 0004b0 03 10 00 01 [[BIDRL]] 00 00 00 00 00 00 00 00
130+
; CHECK-NEXT: 0004c0 00 00 00 00 00 00 00 {{..}} {{.*}}
123131

124132
; End record.
125-
; CHECK: 0004b0 03 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00
126-
; CHECK-NEXT: 0004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
127-
; CHECK-NEXT: 0004d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
128-
; CHECK-NEXT: 0004e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
129-
; CHECK-NEXT: 0004f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
133+
; CHECK: 000500 03 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00
134+
; CHECK-NEXT: 000510 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
135+
; CHECK-NEXT: 000520 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
136+
; CHECK-NEXT: 000530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
137+
; CHECK-NEXT: 000540 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

0 commit comments

Comments
 (0)