mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 04:33:05 +00:00
Add back the MC bits of 126425. Original patch by Nathan Jeffords. I added the
asm parsing and testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8b99c1e42c
commit
8f7d12ccfd
@ -334,6 +334,11 @@ namespace llvm {
|
||||
/// EndCOFFSymbolDef - Marks the end of the symbol definition.
|
||||
virtual void EndCOFFSymbolDef() = 0;
|
||||
|
||||
/// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
|
||||
///
|
||||
/// @param Symbol - Symbol the section relative realocation should point to.
|
||||
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
|
||||
|
||||
/// EmitELFSize - Emit an ELF .size directive.
|
||||
///
|
||||
/// This corresponds to an assembler statement such as:
|
||||
|
@ -144,9 +144,8 @@ void AsmPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{
|
||||
void AsmPrinter::EmitSectionOffset(const MCSymbol *Label,
|
||||
const MCSymbol *SectionLabel) const {
|
||||
// On COFF targets, we have to emit the special .secrel32 directive.
|
||||
if (const char *SecOffDir = MAI->getDwarfSectionOffsetDirective()) {
|
||||
// FIXME: MCize.
|
||||
OutStreamer.EmitRawText(SecOffDir + Twine(Label->getName()));
|
||||
if (MAI->getDwarfSectionOffsetDirective()) {
|
||||
OutStreamer.EmitCOFFSecRel32(Label);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,7 @@ public:
|
||||
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
|
||||
virtual void EmitCOFFSymbolType(int Type);
|
||||
virtual void EndCOFFSymbolDef();
|
||||
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
|
||||
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment);
|
||||
@ -470,6 +471,11 @@ void MCAsmStreamer::EndCOFFSymbolDef() {
|
||||
EmitEOL();
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
||||
OS << "\t.secrel32\t" << *Symbol << '\n';
|
||||
EmitEOL();
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
assert(MAI.hasDotTypeDotSizeDirective());
|
||||
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
|
||||
|
@ -122,6 +122,11 @@ public:
|
||||
return Child->EndCOFFSymbolDef();
|
||||
}
|
||||
|
||||
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
||||
LogCall("EmitCOFFSecRel32");
|
||||
return Child->EmitCOFFSecRel32(Symbol);
|
||||
}
|
||||
|
||||
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
LogCall("EmitELFSize");
|
||||
return Child->EmitELFSize(Symbol, Value);
|
||||
|
@ -55,6 +55,7 @@ namespace {
|
||||
virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
|
||||
virtual void EmitCOFFSymbolType(int Type) {}
|
||||
virtual void EndCOFFSymbolDef() {}
|
||||
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {}
|
||||
|
||||
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
|
@ -45,6 +45,7 @@ class COFFAsmParser : public MCAsmParserExtension {
|
||||
AddDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(".scl");
|
||||
AddDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(".type");
|
||||
AddDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(".endef");
|
||||
AddDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(".secrel32");
|
||||
|
||||
// Win64 EH directives.
|
||||
AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
|
||||
@ -102,6 +103,7 @@ class COFFAsmParser : public MCAsmParserExtension {
|
||||
bool ParseDirectiveScl(StringRef, SMLoc);
|
||||
bool ParseDirectiveType(StringRef, SMLoc);
|
||||
bool ParseDirectiveEndef(StringRef, SMLoc);
|
||||
bool ParseDirectiveSecRel32(StringRef, SMLoc);
|
||||
|
||||
// Win64 EH directives.
|
||||
bool ParseSEHDirectiveStartProc(StringRef, SMLoc);
|
||||
@ -217,6 +219,21 @@ bool COFFAsmParser::ParseDirectiveEndef(StringRef, SMLoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool COFFAsmParser::ParseDirectiveSecRel32(StringRef, SMLoc) {
|
||||
StringRef SymbolID;
|
||||
if (getParser().ParseIdentifier(SymbolID))
|
||||
return true;
|
||||
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in directive");
|
||||
|
||||
MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID);
|
||||
|
||||
Lex();
|
||||
getStreamer().EmitCOFFSecRel32(Symbol);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool COFFAsmParser::ParseSEHDirectiveStartProc(StringRef, SMLoc) {
|
||||
StringRef SymbolID;
|
||||
if (getParser().ParseIdentifier(SymbolID))
|
||||
|
@ -558,6 +558,10 @@ void MCStreamer::EmitWin64EHEndProlog() {
|
||||
EmitLabel(CurFrame->PrologEnd);
|
||||
}
|
||||
|
||||
void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
|
||||
assert(0 && "This file format doesn't support this directive");
|
||||
}
|
||||
|
||||
void MCStreamer::EmitFnStart() {
|
||||
errs() << "Not implemented yet\n";
|
||||
abort();
|
||||
|
@ -716,6 +716,10 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
else
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
break;
|
||||
case X86::reloc_coff_secrel32:
|
||||
Reloc.Data.Type = Is64Bit ? COFF::IMAGE_REL_AMD64_SREL32
|
||||
: COFF::IMAGE_REL_I386_SECREL;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
#include "../Target/X86/MCTargetDesc/X86FixupKinds.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
@ -60,6 +63,7 @@ public:
|
||||
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
|
||||
virtual void EmitCOFFSymbolType(int Type);
|
||||
virtual void EndCOFFSymbolDef();
|
||||
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
|
||||
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
|
||||
unsigned ByteAlignment);
|
||||
@ -293,6 +297,16 @@ void WinCOFFStreamer::EndCOFFSymbolDef() {
|
||||
CurSymbol = NULL;
|
||||
}
|
||||
|
||||
void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
|
||||
{
|
||||
MCDataFragment *DF = getOrCreateDataFragment();
|
||||
|
||||
DF->addFixup(MCFixup::Create(DF->getContents().size(),
|
||||
MCSymbolRefExpr::Create (Symbol, getContext ()),
|
||||
(MCFixupKind)X86::reloc_coff_secrel32));
|
||||
DF->getContents().resize(DF->getContents().size() + 4, 0);
|
||||
}
|
||||
|
||||
void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
|
||||
llvm_unreachable("not implemented");
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
case X86::reloc_signed_4byte:
|
||||
case X86::reloc_global_offset_table:
|
||||
case X86::reloc_coff_secrel32:
|
||||
case FK_Data_4: return 2;
|
||||
case FK_PCRel_8:
|
||||
case FK_Data_8: return 3;
|
||||
@ -76,7 +77,8 @@ public:
|
||||
{ "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel},
|
||||
{ "reloc_signed_4byte", 0, 4 * 8, 0},
|
||||
{ "reloc_global_offset_table", 0, 4 * 8, 0}
|
||||
{ "reloc_global_offset_table", 0, 4 * 8, 0},
|
||||
{ "reloc_coff_secrel32", 0, 4 * 8, 0}
|
||||
};
|
||||
|
||||
if (Kind < FirstTargetFixupKind)
|
||||
|
@ -23,6 +23,8 @@ enum Fixups {
|
||||
reloc_global_offset_table, // 32-bit, relative to the start
|
||||
// of the instruction. Used only
|
||||
// for _GLOBAL_OFFSET_TABLE_.
|
||||
reloc_coff_secrel32, // PE-COFF section relative 32
|
||||
// (only valid for win32 COFF)
|
||||
// Marker
|
||||
LastTargetFixupKind,
|
||||
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind
|
||||
|
14
test/MC/COFF/secrel32.s
Normal file
14
test/MC/COFF/secrel32.s
Normal file
@ -0,0 +1,14 @@
|
||||
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s | coff-dump.py | FileCheck %s
|
||||
|
||||
// check that we produce the correct relocation for .secrel32
|
||||
|
||||
Lfoo:
|
||||
.secrel32 Lfoo
|
||||
|
||||
// CHECK: Relocations = [
|
||||
// CHECK-NEXT: 0 = {
|
||||
// CHECK-NEXT: VirtualAddress = 0x0
|
||||
// CHECK-NEXT: SymbolTableIndex = 0
|
||||
// CHECK-NEXT: Type = IMAGE_REL_I386_SECREL (11)
|
||||
// CHECK-NEXT: SymbolName = .text
|
||||
// CHECK-NEXT: }
|
Loading…
Reference in New Issue
Block a user