forked from OSchip/llvm-project
Centralize the information about which object format we are using.
Other than some places that were handling unknown as ELF, this should have no change. The test updates are because we were detecting arm-coff or x86_64-win64-coff as ELF targets before. It is not clear if the enum should live on the Triple. At least now it lives in a single location and should be easier to move somewhere else. llvm-svn: 245047
This commit is contained in:
parent
078ab134ea
commit
90eb70c8a7
|
@ -331,13 +331,9 @@ public:
|
||||||
return EHFrameSection;
|
return EHFrameSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Environment { IsMachO, IsELF, IsCOFF };
|
|
||||||
Environment getObjectFileType() const { return Env; }
|
|
||||||
|
|
||||||
Reloc::Model getRelocM() const { return RelocM; }
|
Reloc::Model getRelocM() const { return RelocM; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Environment Env;
|
|
||||||
Reloc::Model RelocM;
|
Reloc::Model RelocM;
|
||||||
CodeModel::Model CMModel;
|
CodeModel::Model CMModel;
|
||||||
MCContext *Ctx;
|
MCContext *Ctx;
|
||||||
|
|
|
@ -162,13 +162,15 @@ MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
|
||||||
MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
|
MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
|
||||||
bool IsTemporary) {
|
bool IsTemporary) {
|
||||||
if (MOFI) {
|
if (MOFI) {
|
||||||
switch (MOFI->getObjectFileType()) {
|
switch (MOFI->getTargetTriple().getObjectFormat()) {
|
||||||
case MCObjectFileInfo::IsCOFF:
|
case Triple::COFF:
|
||||||
return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
|
return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
|
||||||
case MCObjectFileInfo::IsELF:
|
case Triple::ELF:
|
||||||
return new (Name, *this) MCSymbolELF(Name, IsTemporary);
|
return new (Name, *this) MCSymbolELF(Name, IsTemporary);
|
||||||
case MCObjectFileInfo::IsMachO:
|
case Triple::MachO:
|
||||||
return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
|
return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
|
||||||
|
case Triple::UnknownObjectFormat:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
|
return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
|
||||||
|
|
|
@ -767,25 +767,19 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
|
||||||
|
|
||||||
TT = TheTriple;
|
TT = TheTriple;
|
||||||
|
|
||||||
Triple::ArchType Arch = TT.getArch();
|
Triple::ObjectFormatType Format = TT.getObjectFormat();
|
||||||
// FIXME: Checking for Arch here to filter out bogus triples such as
|
switch (Format) {
|
||||||
// cellspu-apple-darwin. Perhaps we should fix in Triple?
|
case Triple::MachO:
|
||||||
if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
|
||||||
Arch == Triple::arm || Arch == Triple::thumb ||
|
|
||||||
Arch == Triple::aarch64 ||
|
|
||||||
Arch == Triple::ppc || Arch == Triple::ppc64 ||
|
|
||||||
Arch == Triple::UnknownArch) &&
|
|
||||||
TT.isOSBinFormatMachO()) {
|
|
||||||
Env = IsMachO;
|
|
||||||
initMachOMCObjectFileInfo(TT);
|
initMachOMCObjectFileInfo(TT);
|
||||||
} else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
|
break;
|
||||||
Arch == Triple::arm || Arch == Triple::thumb) &&
|
case Triple::COFF:
|
||||||
(TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
|
|
||||||
Env = IsCOFF;
|
|
||||||
initCOFFMCObjectFileInfo(TT);
|
initCOFFMCObjectFileInfo(TT);
|
||||||
} else {
|
break;
|
||||||
Env = IsELF;
|
case Triple::ELF:
|
||||||
initELFMCObjectFileInfo(TT);
|
initELFMCObjectFileInfo(TT);
|
||||||
|
break;
|
||||||
|
case Triple::UnknownObjectFormat:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -801,7 +795,9 @@ MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCObjectFileInfo::InitEHFrameSection() {
|
void MCObjectFileInfo::InitEHFrameSection() {
|
||||||
if (Env == IsMachO)
|
Triple::ObjectFormatType Format = TT.getObjectFormat();
|
||||||
|
switch (Format) {
|
||||||
|
case Triple::MachO:
|
||||||
EHFrameSection =
|
EHFrameSection =
|
||||||
Ctx->getMachOSection("__TEXT", "__eh_frame",
|
Ctx->getMachOSection("__TEXT", "__eh_frame",
|
||||||
MachO::S_COALESCED |
|
MachO::S_COALESCED |
|
||||||
|
@ -809,14 +805,20 @@ void MCObjectFileInfo::InitEHFrameSection() {
|
||||||
MachO::S_ATTR_STRIP_STATIC_SYMS |
|
MachO::S_ATTR_STRIP_STATIC_SYMS |
|
||||||
MachO::S_ATTR_LIVE_SUPPORT,
|
MachO::S_ATTR_LIVE_SUPPORT,
|
||||||
SectionKind::getReadOnly());
|
SectionKind::getReadOnly());
|
||||||
else if (Env == IsELF)
|
break;
|
||||||
|
case Triple::ELF:
|
||||||
EHFrameSection =
|
EHFrameSection =
|
||||||
Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
|
Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
|
||||||
else
|
break;
|
||||||
|
case Triple::COFF:
|
||||||
EHFrameSection =
|
EHFrameSection =
|
||||||
Ctx->getCOFFSection(".eh_frame",
|
Ctx->getCOFFSection(".eh_frame",
|
||||||
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
|
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
|
||||||
COFF::IMAGE_SCN_MEM_READ |
|
COFF::IMAGE_SCN_MEM_READ |
|
||||||
COFF::IMAGE_SCN_MEM_WRITE,
|
COFF::IMAGE_SCN_MEM_WRITE,
|
||||||
SectionKind::getDataRel());
|
SectionKind::getDataRel());
|
||||||
|
break;
|
||||||
|
case Triple::UnknownObjectFormat:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -513,17 +513,19 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
|
||||||
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
|
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
|
||||||
|
|
||||||
// Initialize the platform / file format parser.
|
// Initialize the platform / file format parser.
|
||||||
switch (Ctx.getObjectFileInfo()->getObjectFileType()) {
|
switch (Ctx.getObjectFileInfo()->getTargetTriple().getObjectFormat()) {
|
||||||
case MCObjectFileInfo::IsCOFF:
|
case Triple::COFF:
|
||||||
PlatformParser.reset(createCOFFAsmParser());
|
PlatformParser.reset(createCOFFAsmParser());
|
||||||
break;
|
break;
|
||||||
case MCObjectFileInfo::IsMachO:
|
case Triple::MachO:
|
||||||
PlatformParser.reset(createDarwinAsmParser());
|
PlatformParser.reset(createDarwinAsmParser());
|
||||||
IsDarwin = true;
|
IsDarwin = true;
|
||||||
break;
|
break;
|
||||||
case MCObjectFileInfo::IsELF:
|
case Triple::ELF:
|
||||||
PlatformParser.reset(createELFAsmParser());
|
PlatformParser.reset(createELFAsmParser());
|
||||||
break;
|
break;
|
||||||
|
case Triple::UnknownObjectFormat:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformParser->Initialize(*this);
|
PlatformParser->Initialize(*this);
|
||||||
|
|
|
@ -4055,10 +4055,10 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
||||||
|
|
||||||
/// ParseDirective parses the arm specific directives
|
/// ParseDirective parses the arm specific directives
|
||||||
bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
|
bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
|
||||||
const MCObjectFileInfo::Environment Format =
|
Triple::ObjectFormatType Format =
|
||||||
getContext().getObjectFileInfo()->getObjectFileType();
|
getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
|
||||||
bool IsMachO = Format == MCObjectFileInfo::IsMachO;
|
bool IsMachO = Format == Triple::MachO;
|
||||||
bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
|
bool IsCOFF = Format == Triple::COFF;
|
||||||
|
|
||||||
StringRef IDVal = DirectiveID.getIdentifier();
|
StringRef IDVal = DirectiveID.getIdentifier();
|
||||||
SMLoc Loc = DirectiveID.getLoc();
|
SMLoc Loc = DirectiveID.getLoc();
|
||||||
|
|
|
@ -5173,18 +5173,11 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
|
||||||
COFF = (1 << MCObjectFileInfo::IsCOFF),
|
|
||||||
ELF = (1 << MCObjectFileInfo::IsELF),
|
|
||||||
MACHO = (1 << MCObjectFileInfo::IsMachO)
|
|
||||||
};
|
|
||||||
static const struct PrefixEntry {
|
static const struct PrefixEntry {
|
||||||
const char *Spelling;
|
const char *Spelling;
|
||||||
ARMMCExpr::VariantKind VariantKind;
|
ARMMCExpr::VariantKind VariantKind;
|
||||||
uint8_t SupportedFormats;
|
|
||||||
} PrefixEntries[] = {
|
} PrefixEntries[] = {
|
||||||
{ "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
|
{"lower16", ARMMCExpr::VK_ARM_LO16}, {"upper16", ARMMCExpr::VK_ARM_HI16},
|
||||||
{ "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
StringRef IDVal = Parser.getTok().getIdentifier();
|
StringRef IDVal = Parser.getTok().getIdentifier();
|
||||||
|
@ -5199,25 +5192,6 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CurrentFormat;
|
|
||||||
switch (getContext().getObjectFileInfo()->getObjectFileType()) {
|
|
||||||
case MCObjectFileInfo::IsMachO:
|
|
||||||
CurrentFormat = MACHO;
|
|
||||||
break;
|
|
||||||
case MCObjectFileInfo::IsELF:
|
|
||||||
CurrentFormat = ELF;
|
|
||||||
break;
|
|
||||||
case MCObjectFileInfo::IsCOFF:
|
|
||||||
CurrentFormat = COFF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (~Prefix->SupportedFormats & CurrentFormat) {
|
|
||||||
Error(Parser.getTok().getLoc(),
|
|
||||||
"cannot represent relocation in the current file format");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RefKind = Prefix->VariantKind;
|
RefKind = Prefix->VariantKind;
|
||||||
Parser.Lex();
|
Parser.Lex();
|
||||||
|
|
||||||
|
@ -8691,10 +8665,10 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
||||||
|
|
||||||
/// parseDirective parses the arm specific directives
|
/// parseDirective parses the arm specific directives
|
||||||
bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
|
bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
|
||||||
const MCObjectFileInfo::Environment Format =
|
Triple::ObjectFormatType Format =
|
||||||
getContext().getObjectFileInfo()->getObjectFileType();
|
getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
|
||||||
bool IsMachO = Format == MCObjectFileInfo::IsMachO;
|
bool IsMachO = Format == Triple::MachO;
|
||||||
bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
|
bool IsCOFF = Format == Triple::COFF;
|
||||||
|
|
||||||
StringRef IDVal = DirectiveID.getIdentifier();
|
StringRef IDVal = DirectiveID.getIdentifier();
|
||||||
if (IDVal == ".word")
|
if (IDVal == ".word")
|
||||||
|
@ -8859,8 +8833,9 @@ void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
|
||||||
/// ::= .thumbfunc symbol_name
|
/// ::= .thumbfunc symbol_name
|
||||||
bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
|
bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
|
||||||
MCAsmParser &Parser = getParser();
|
MCAsmParser &Parser = getParser();
|
||||||
const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
|
Triple::ObjectFormatType Format =
|
||||||
bool IsMachO = Format == MCObjectFileInfo::IsMachO;
|
getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
|
||||||
|
bool IsMachO = Format == Triple::MachO;
|
||||||
|
|
||||||
// Darwin asm has (optionally) function name after .thumb_func direction
|
// Darwin asm has (optionally) function name after .thumb_func direction
|
||||||
// ELF doesn't
|
// ELF doesn't
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
; RUN: llc < %s -mtriple="x86_64-pc-linux-gnu" | FileCheck %s
|
; RUN: llc < %s -mtriple="x86_64-pc-linux-gnu" | FileCheck %s
|
||||||
; RUN: llc < %s -mtriple="x86_64-pc-win64-coff" | FileCheck %s
|
; RUN: llc < %s -mtriple="x86_64-pc-unknown-elf" | FileCheck %s
|
||||||
|
|
||||||
; This test is a sanity check to ensure statepoints are generating StackMap
|
; This test is a sanity check to ensure statepoints are generating StackMap
|
||||||
; sections correctly. This is not intended to be a rigorous test of the
|
; sections correctly. This is not intended to be a rigorous test of the
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
// RUN: not llvm-mc -triple arm-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
|
|
||||||
// RUN: not llvm-mc -triple armeb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
|
|
||||||
// RUN: not llvm-mc -triple thumb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
|
|
||||||
// RUN: not llvm-mc -triple thumbeb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
|
|
||||||
|
|
||||||
.type symbol 32
|
|
||||||
// CHECK: error: expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '%<type>' or "<type>"
|
|
||||||
// CHECK: .type symbol 32
|
|
||||||
// CHECK: ^
|
|
||||||
|
|
Loading…
Reference in New Issue