mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-25 10:27:04 +00:00
Create a MCSymbolELF.
This create a MCSymbolELF class and moves SymbolSize since only ELF needs a size expression. This reduces the size of MCSymbol from 56 to 48 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "llvm/MC/MCFixupKindInfo.h"
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
#include "llvm/MC/MCSectionELF.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
#include "llvm/MC/StringTableBuilder.h"
|
||||
#include "llvm/Support/Compression.h"
|
||||
@@ -79,7 +80,7 @@ class ELFObjectWriter : public MCObjectWriter {
|
||||
|
||||
/// Helper struct for containing some precomputed information on symbols.
|
||||
struct ELFSymbolData {
|
||||
const MCSymbol *Symbol;
|
||||
const MCSymbolELF *Symbol;
|
||||
uint32_t SectionIndex;
|
||||
StringRef Name;
|
||||
|
||||
@@ -451,7 +452,8 @@ void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer,
|
||||
assert((!Symbol.getFragment() ||
|
||||
(Symbol.getFragment()->getParent() == &Symbol.getSection())) &&
|
||||
"The symbol's section doesn't match the fragment's symbol");
|
||||
const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
|
||||
const MCSymbolELF *Base =
|
||||
cast_or_null<MCSymbolELF>(Layout.getBaseSymbol(Symbol));
|
||||
|
||||
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
|
||||
// SHN_COMMON.
|
||||
@@ -810,7 +812,7 @@ void ELFObjectWriter::computeSymbolTable(
|
||||
continue;
|
||||
|
||||
ELFSymbolData MSD;
|
||||
MSD.Symbol = &Symbol;
|
||||
MSD.Symbol = cast<MCSymbolELF>(&Symbol);
|
||||
|
||||
// Undefined symbols are global, but this is the first place we
|
||||
// are able to set it.
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "llvm/MC/MCRegisterInfo.h"
|
||||
#include "llvm/MC/MCSectionCOFF.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
|
||||
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
|
||||
void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
|
||||
void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
|
||||
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
|
||||
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment) override;
|
||||
|
||||
@@ -502,7 +502,7 @@ void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
||||
EmitEOL();
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
|
||||
assert(MAI->hasDotTypeDotSizeDirective());
|
||||
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "llvm/MC/MCSectionELF.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/Support/ELF.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
@@ -119,8 +119,8 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
|
||||
return Sym;
|
||||
}
|
||||
|
||||
MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
|
||||
MCSymbol *&Sym = SectionSymbols[&Section];
|
||||
MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
|
||||
MCSymbolELF *&Sym = SectionSymbols[&Section];
|
||||
if (Sym)
|
||||
return Sym;
|
||||
|
||||
@@ -128,12 +128,12 @@ MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
|
||||
|
||||
MCSymbol *&OldSym = Symbols[Name];
|
||||
if (OldSym && OldSym->isUndefined()) {
|
||||
Sym = OldSym;
|
||||
return OldSym;
|
||||
Sym = cast<MCSymbolELF>(OldSym);
|
||||
return Sym;
|
||||
}
|
||||
|
||||
auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first;
|
||||
Sym = new (*this) MCSymbol(&*NameIter, /*isTemporary*/ false);
|
||||
Sym = new (*this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
|
||||
|
||||
if (!OldSym)
|
||||
OldSym = Sym;
|
||||
@@ -157,6 +157,14 @@ MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
|
||||
FuncName);
|
||||
}
|
||||
|
||||
MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
|
||||
bool IsTemporary) {
|
||||
bool IsELF = MOFI && MOFI->getObjectFileType() == MCObjectFileInfo::IsELF;
|
||||
if (IsELF)
|
||||
return new (*this) MCSymbolELF(Name, IsTemporary);
|
||||
return new (*this) MCSymbol(false, Name, IsTemporary);
|
||||
}
|
||||
|
||||
MCSymbol *MCContext::CreateSymbol(StringRef Name, bool AlwaysAddSuffix) {
|
||||
// Determine whether this is an assembler temporary or normal label, if used.
|
||||
bool IsTemporary = false;
|
||||
@@ -164,7 +172,7 @@ MCSymbol *MCContext::CreateSymbol(StringRef Name, bool AlwaysAddSuffix) {
|
||||
IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
|
||||
|
||||
if (IsTemporary && AlwaysAddSuffix && !UseNamesOnTempLabels)
|
||||
return new (*this) MCSymbol(nullptr, true);
|
||||
return createSymbolImpl(nullptr, true);
|
||||
|
||||
SmallString<128> NewName = Name;
|
||||
bool AddSuffix = AlwaysAddSuffix;
|
||||
@@ -178,8 +186,7 @@ MCSymbol *MCContext::CreateSymbol(StringRef Name, bool AlwaysAddSuffix) {
|
||||
if (NameEntry.second) {
|
||||
// Ok, we found a name. Have the MCSymbol object itself refer to the copy
|
||||
// of the string that is embedded in the UsedNames entry.
|
||||
MCSymbol *Result = new (*this) MCSymbol(&*NameEntry.first, IsTemporary);
|
||||
return Result;
|
||||
return createSymbolImpl(&*NameEntry.first, IsTemporary);
|
||||
}
|
||||
assert(IsTemporary && "Cannot rename non-temporary symbols");
|
||||
AddSuffix = true;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "llvm/MC/MCObjectStreamer.h"
|
||||
#include "llvm/MC/MCSection.h"
|
||||
#include "llvm/MC/MCSectionELF.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCValue.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
@@ -333,10 +334,11 @@ void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
Symbol->setCommon(Size, ByteAlignment);
|
||||
}
|
||||
|
||||
Symbol->setSize(MCConstantExpr::create(Size, getContext()));
|
||||
cast<MCSymbolELF>(Symbol)
|
||||
->setSize(MCConstantExpr::create(Size, getContext()));
|
||||
}
|
||||
|
||||
void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
void MCELFStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
|
||||
Symbol->setSize(Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,9 +93,6 @@ public:
|
||||
void EndCOFFSymbolDef() override {
|
||||
llvm_unreachable("macho doesn't support this directive");
|
||||
}
|
||||
void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override {
|
||||
llvm_unreachable("macho doesn't support this directive");
|
||||
}
|
||||
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment) override;
|
||||
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "llvm/MC/MCParser/MCAsmLexer.h"
|
||||
#include "llvm/MC/MCSectionELF.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/Support/ELF.h"
|
||||
using namespace llvm;
|
||||
|
||||
@@ -209,7 +209,7 @@ bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
|
||||
StringRef Name;
|
||||
if (getParser().parseIdentifier(Name))
|
||||
return TokError("expected identifier in directive");
|
||||
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
|
||||
MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
|
||||
|
||||
if (getLexer().isNot(AsmToken::Comma))
|
||||
return TokError("unexpected token in directive");
|
||||
@@ -222,7 +222,7 @@ bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in directive");
|
||||
|
||||
getStreamer().EmitELFSize(Sym, Expr);
|
||||
getStreamer().emitELFSize(Sym, Expr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ void MCStreamer::EndCOFFSymbolDef() {}
|
||||
void MCStreamer::EmitFileDirective(StringRef Filename) {}
|
||||
void MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {}
|
||||
void MCStreamer::EmitCOFFSymbolType(int Type) {}
|
||||
void MCStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
|
||||
void MCStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {}
|
||||
void MCStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment) {}
|
||||
void MCStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
|
||||
|
||||
@@ -195,10 +195,6 @@ void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
||||
DF->getContents().resize(DF->getContents().size() + 4, 0);
|
||||
}
|
||||
|
||||
void MCWinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
llvm_unreachable("not supported");
|
||||
}
|
||||
|
||||
void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment) {
|
||||
assert((!Symbol->isInSection() ||
|
||||
|
||||
Reference in New Issue
Block a user