Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/MC/MCSectionGOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace llvm {
class MCExpr;

class LLVM_ABI MCSectionGOFF final : public MCSection {
StringRef ExternalName; // Alternate external name.

// Parent of this section. Implies that the parent is emitted first.
MCSectionGOFF *Parent;

Expand Down Expand Up @@ -115,6 +117,12 @@ class LLVM_ABI MCSectionGOFF final : public MCSection {
bool requiresNonZeroLength() const { return RequiresNonZeroLength; }

void setName(StringRef SectionName) { Name = SectionName; }

bool hasExternalName() const { return !ExternalName.empty(); }
void setExternalName(StringRef Name) { ExternalName = Name; }
StringRef getExternalName() const {
return hasExternalName() ? ExternalName : getName();
}
};
} // end namespace llvm

Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/MC/MCSymbolGOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace llvm {

class MCSymbolGOFF : public MCSymbol {

StringRef ExternalName; // Alternate external name.

// Associated data area of the section. Needs to be emitted first.
MCSectionGOFF *ADA = nullptr;

Expand All @@ -48,6 +51,12 @@ class MCSymbolGOFF : public MCSymbol {
bool isExternal() const { return IsExternal; }
void setExternal(bool Value) const { IsExternal = Value; }

bool hasExternalName() const { return !ExternalName.empty(); }
void setExternalName(StringRef Name) { ExternalName = Name; }
StringRef getExternalName() const {
return hasExternalName() ? ExternalName : getName();
}

void setHidden(bool Value = true) {
modifyFlags(Value ? SF_Hidden : 0, SF_Hidden);
}
Expand Down
35 changes: 20 additions & 15 deletions llvm/lib/MC/GOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,23 @@ GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm,

void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
if (Section.isSD()) {
GOFFSymbol SD(Section.getName(), Section.getOrdinal(),
GOFFSymbol SD(Section.getExternalName(), Section.getOrdinal(),
Section.getSDAttributes());
writeSymbol(SD);
}

if (Section.isED()) {
GOFFSymbol ED(Section.getName(), Section.getOrdinal(),
GOFFSymbol ED(Section.getExternalName(), Section.getOrdinal(),
Section.getParent()->getOrdinal(), Section.getEDAttributes());
ED.SectionLength = Asm.getSectionAddressSize(Section);
writeSymbol(ED);
}

if (Section.isPR()) {
MCSectionGOFF *Parent = Section.getParent();
GOFFSymbol PR(Section.getName(), Section.getOrdinal(), Parent->getOrdinal(),
Parent->getEDAttributes(), Section.getPRAttributes());
GOFFSymbol PR(Section.getExternalName(), Section.getOrdinal(),
Parent->getOrdinal(), Parent->getEDAttributes(),
Section.getPRAttributes());
PR.SectionLength = Asm.getSectionAddressSize(Section);
if (Section.requiresNonZeroLength()) {
// We cannot have a zero-length section for data. If we do,
Expand All @@ -347,8 +348,8 @@ void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {

void GOFFWriter::defineLabel(const MCSymbolGOFF &Symbol) {
MCSectionGOFF &Section = static_cast<MCSectionGOFF &>(Symbol.getSection());
GOFFSymbol LD(Symbol.getName(), Symbol.getIndex(), Section.getOrdinal(),
Section.getEDAttributes().NameSpace,
GOFFSymbol LD(Symbol.getExternalName(), Symbol.getIndex(),
Section.getOrdinal(), Section.getEDAttributes().NameSpace,
GOFF::LDAttr{false, Symbol.getCodeData(),
Symbol.getBindingStrength(), Symbol.getLinkage(),
GOFF::ESD_AMODE_64, Symbol.getBindingScope()});
Expand All @@ -359,7 +360,8 @@ void GOFFWriter::defineLabel(const MCSymbolGOFF &Symbol) {
}

void GOFFWriter::defineExtern(const MCSymbolGOFF &Symbol) {
GOFFSymbol ER(Symbol.getName(), Symbol.getIndex(), RootSD->getOrdinal(),
GOFFSymbol ER(Symbol.getExternalName(), Symbol.getIndex(),
RootSD->getOrdinal(),
GOFF::ERAttr{Symbol.isIndirect(), Symbol.getCodeData(),
Symbol.getBindingStrength(), Symbol.getLinkage(),
GOFF::ESD_AMODE_64, Symbol.getBindingScope()});
Expand Down Expand Up @@ -695,25 +697,26 @@ void GOFFObjectWriter::recordRelocation(const MCFragment &F,
Asm->reportError(
Fixup.getLoc(),
Twine("symbol ")
.concat(A.getName())
.concat(A.getExternalName())
.concat(" must be defined for a relative immediate relocation"));
return;
}
if (&A.getSection() != PSection) {
MCSectionGOFF &GOFFSection = static_cast<MCSectionGOFF &>(A.getSection());
Asm->reportError(Fixup.getLoc(),
Twine("relative immediate relocation section mismatch: ")
.concat(A.getSection().getName())
.concat(GOFFSection.getExternalName())
.concat(" of symbol ")
.concat(A.getName())
.concat(A.getExternalName())
.concat(" <-> ")
.concat(PSection->getName()));
.concat(PSection->getExternalName()));
return;
}
if (B) {
Asm->reportError(
Fixup.getLoc(),
Twine("subtractive symbol ")
.concat(B->getName())
.concat(B->getExternalName())
.concat(" not supported for a relative immediate relocation"));
return;
}
Expand Down Expand Up @@ -767,9 +770,11 @@ void GOFFObjectWriter::recordRelocation(const MCFragment &F,
default:
Con = "(unknown)";
}
dbgs() << "Reloc " << N << ": " << Con << " Rptr: " << Sym->getName()
<< " Pptr: " << PSection->getName() << " Offset: " << FixupOffset
<< " Fixed Imm: " << FixedValue << "\n";
dbgs() << "Reloc " << N << ": " << Con
<< " Rptr: " << Sym->getExternalName()
<< " Pptr: " << PSection->getExternalName()
<< " Offset: " << FixupOffset << " Fixed Imm: " << FixedValue
<< "\n";
};
(void)DumpReloc;

Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/MC/MCAsmInfoGOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@ void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
raw_ostream &OS) const {
auto &Sec =
const_cast<MCSectionGOFF &>(static_cast<const MCSectionGOFF &>(Section));
auto EmitExternalName = [&Sec, &OS]() {
if (Sec.hasExternalName())
OS << Sec.getName() << " ALIAS C'" << Sec.getExternalName() << "'\n";
};
switch (Sec.SymbolType) {
case GOFF::ESD_ST_SectionDefinition: {
OS << Sec.getName() << " CSECT\n";
Sec.Emitted = true;
EmitExternalName();
break;
}
case GOFF::ESD_ST_ElementDefinition: {
Expand All @@ -134,6 +139,7 @@ void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
GOFF::ESD_EXE_Unspecified, Sec.EDAttributes.IsReadOnly, 0,
Sec.EDAttributes.FillByteValue, StringRef());
Sec.Emitted = true;
EmitExternalName();
} else
OS << Sec.getName() << " CATTR\n";
break;
Expand All @@ -151,6 +157,7 @@ void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
Sec.PRAttributes.Executable, Sec.PRAttributes.BindingScope);
ED->Emitted = true;
Sec.Emitted = true;
EmitExternalName();
} else
OS << ED->getName() << " CATTR PART(" << Sec.getName() << ")\n";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ void SystemZHLASMAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
emitXATTR(OS, Sym->getName(), Sym->isIndirect(), Sym->getLinkage(),
Sym->getCodeData(), Sym->getBindingScope());
EmitEOL();
if (Sym->hasExternalName())
OS << Sym->getName() << " ALIAS C'" << Sym->getExternalName() << "'\n";
}

if (EmitLabelAndEntry) {
Expand Down Expand Up @@ -368,6 +370,8 @@ void SystemZHLASMAsmStreamer::finishImpl() {
emitXATTR(OS, Sym.getName(), Sym.isIndirect(), Sym.getLinkage(),
Sym.getCodeData(), Sym.getBindingScope());
EmitEOL();
if (Sym.hasExternalName())
OS << Sym.getName() << " ALIAS C'" << Sym.getExternalName() << "'\n";
}

// Finish the assembly output.
Expand Down
17 changes: 17 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSectionGOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCSymbolGOFF.h"
#include "llvm/Support/FormattedStream.h"
#include <map>
#include <utility>
Expand Down Expand Up @@ -58,6 +60,9 @@ class SystemZTargetStreamer : public MCTargetStreamer {

virtual void emitMachine(StringRef CPUOrCommand) {};

virtual void emitExternalName(MCSymbol *Sym, StringRef Name) {}
virtual void emitExternalName(MCSection *Sec, StringRef Name) {}

virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
const MCSymbol *Lo) {
return nullptr;
Expand All @@ -69,6 +74,12 @@ class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {
SystemZTargetGOFFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
const MCSymbol *Lo) override;
virtual void emitExternalName(MCSymbol *Sym, StringRef Name) override {
static_cast<MCSymbolGOFF *>(Sym)->setExternalName(Name);
}
virtual void emitExternalName(MCSection *Sec, StringRef Name) override {
static_cast<MCSectionGOFF *>(Sec)->setExternalName(Name);
}
};

class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
Expand All @@ -80,6 +91,12 @@ class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
SystemZHLASMAsmStreamer &getHLASMStreamer();
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
const MCSymbol *Lo) override;
virtual void emitExternalName(MCSymbol *Sym, StringRef Name) override {
static_cast<MCSymbolGOFF *>(Sym)->setExternalName(Name);
}
virtual void emitExternalName(MCSection *Sec, StringRef Name) override {
static_cast<MCSectionGOFF *>(Sec)->setExternalName(Name);
}
};

class SystemZTargetELFStreamer : public SystemZTargetStreamer {
Expand Down
Loading