Skip to content

Commit 57f9c9e

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 1d8d8dc commit 57f9c9e

File tree

7 files changed

+143
-18
lines changed

7 files changed

+143
-18
lines changed

llvm/include/llvm/MC/MCGOFFStreamer.h

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

2929
GOFFObjectWriter &getWriter();
3030

31-
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
32-
return false;
33-
}
31+
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
32+
33+
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
34+
3435
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3536
Align ByteAlignment) override {}
3637
};

llvm/include/llvm/MC/MCSymbolGOFF.h

Lines changed: 20 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,14 +42,29 @@ 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) {
4650
ADA = AssociatedDataArea;
4751
AssociatedDataArea->RequiresNonZeroLength = true;
4852
}
4953
MCSectionGOFF *getADA() const { return ADA; }
54+
55+
bool isExternal() const { return IsExternal; }
56+
void setExternal(bool Value) const { IsExternal = Value; }
57+
58+
void setHidden(bool Value = true) {
59+
modifyFlags(Value ? SF_Hidden : 0, SF_Hidden);
60+
}
61+
bool isHidden() const { return getFlags() & SF_Hidden; }
62+
bool isExported() const { return !isHidden(); }
63+
64+
void setWeak(bool Value = true) { modifyFlags(Value ? SF_Weak : 0, SF_Weak); }
65+
bool isWeak() const { return getFlags() & SF_Weak; }
66+
67+
void initAttributes();
5068
};
5169
} // end namespace llvm
5270

llvm/lib/MC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_llvm_component_library(LLVMMC
5050
MCSubtargetInfo.cpp
5151
MCSymbol.cpp
5252
MCSymbolELF.cpp
53+
MCSymbolGOFF.cpp
5354
MCSymbolXCOFF.cpp
5455
MCTargetOptions.cpp
5556
MCTargetOptionsCommandFlags.cpp

llvm/lib/MC/GOFFObjectWriter.cpp

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

llvm/lib/MC/MCGOFFStreamer.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
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"
2022

2123
using namespace llvm;
@@ -37,6 +39,61 @@ void MCGOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
3739
}
3840
}
3941

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

llvm/lib/MC/MCSymbolGOFF.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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/ErrorHandling.h"
12+
13+
using namespace llvm;
14+
15+
void MCSymbolGOFF::initAttributes() {
16+
if (hasLDAttributes())
17+
return;
18+
19+
if (isDefined()) {
20+
MCSectionGOFF &Section = static_cast<MCSectionGOFF &>(getSection());
21+
GOFF::ESDBindingScope BindingScope =
22+
isExternal() ? (isExported() ? GOFF::ESD_BSC_ImportExport
23+
: GOFF::ESD_BSC_Library)
24+
: GOFF::ESD_BSC_Section;
25+
GOFF::ESDBindingStrength BindingStrength =
26+
isWeak() ? GOFF::ESDBindingStrength::ESD_BST_Weak
27+
: GOFF::ESDBindingStrength::ESD_BST_Strong;
28+
if (Section.isED()) {
29+
setLDAttributes(GOFF::LDAttr{false, GOFF::ESD_EXE_CODE, BindingStrength,
30+
GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64,
31+
BindingScope});
32+
} else if (Section.isPR()) {
33+
// For data symbols, the attributes are already determind in TLOFI.
34+
// TODO Does it make sense to it to here?
35+
} else
36+
llvm_unreachable("Unexpected section type for label");
37+
}
38+
// TODO Handle external symbol.
39+
}

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)