mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 02:33:33 +00:00
Move x86 specific bits of the COFF writer to lib/Target/X86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147231 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
84070ffbe6
commit
df09270ae8
@ -192,8 +192,6 @@ public:
|
||||
unsigned Padding = 0);
|
||||
};
|
||||
|
||||
MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
|
36
include/llvm/MC/MCWinCOFFObjectWriter.h
Normal file
36
include/llvm/MC/MCWinCOFFObjectWriter.h
Normal file
@ -0,0 +1,36 @@
|
||||
//===-- llvm/MC/MCWinCOFFObjectWriter.h - Win COFF Object Writer *- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_MC_MCWINCOFFOBJECTWRITER_H
|
||||
#define LLVM_MC_MCWINCOFFOBJECTWRITER_H
|
||||
|
||||
namespace llvm {
|
||||
class MCWinCOFFObjectTargetWriter {
|
||||
const unsigned Machine;
|
||||
|
||||
protected:
|
||||
MCWinCOFFObjectTargetWriter(unsigned Machine_);
|
||||
|
||||
public:
|
||||
virtual ~MCWinCOFFObjectTargetWriter() {}
|
||||
|
||||
unsigned getMachine() const { return Machine; }
|
||||
virtual unsigned getRelocType(unsigned FixupKind) const = 0;
|
||||
};
|
||||
|
||||
/// \brief Construct a new Win COFF writer instance.
|
||||
///
|
||||
/// \param MOTW - The target specific WinCOFF writer subclass.
|
||||
/// \param OS - The stream to write to.
|
||||
/// \returns The constructed object writer.
|
||||
MCObjectWriter *createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
|
||||
raw_ostream &OS);
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
@ -22,8 +22,10 @@
|
||||
#include "llvm/MC/MCAssembler.h"
|
||||
#include "llvm/MC/MCAsmLayout.h"
|
||||
#include "llvm/MC/MCSectionCOFF.h"
|
||||
#include "llvm/MC/MCWinCOFFObjectWriter.h"
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
@ -33,8 +35,6 @@
|
||||
|
||||
#include "llvm/Support/TimeValue.h"
|
||||
|
||||
#include "../Target/X86/MCTargetDesc/X86FixupKinds.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
using namespace llvm;
|
||||
@ -120,8 +120,6 @@ public:
|
||||
};
|
||||
|
||||
class WinCOFFObjectWriter : public MCObjectWriter {
|
||||
unsigned getRelocType(unsigned FixupKind) const;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector<COFFSymbol*> symbols;
|
||||
@ -130,8 +128,9 @@ public:
|
||||
typedef DenseMap<MCSymbol const *, COFFSymbol *> symbol_map;
|
||||
typedef DenseMap<MCSection const *, COFFSection *> section_map;
|
||||
|
||||
llvm::OwningPtr<MCWinCOFFObjectTargetWriter> TargetObjectWriter;
|
||||
|
||||
// Root level file contents.
|
||||
bool Is64Bit;
|
||||
COFF::header Header;
|
||||
sections Sections;
|
||||
symbols Symbols;
|
||||
@ -141,7 +140,7 @@ public:
|
||||
section_map SectionMap;
|
||||
symbol_map SymbolMap;
|
||||
|
||||
WinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);
|
||||
WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_ostream &OS);
|
||||
~WinCOFFObjectWriter();
|
||||
|
||||
COFFSymbol *createSymbol(StringRef Name);
|
||||
@ -316,13 +315,13 @@ size_t StringTable::insert(llvm::StringRef String) {
|
||||
//------------------------------------------------------------------------------
|
||||
// WinCOFFObjectWriter class implementation
|
||||
|
||||
WinCOFFObjectWriter::WinCOFFObjectWriter(raw_ostream &OS, bool is64Bit)
|
||||
WinCOFFObjectWriter::WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
|
||||
raw_ostream &OS)
|
||||
: MCObjectWriter(OS, true)
|
||||
, Is64Bit(is64Bit) {
|
||||
, TargetObjectWriter(MOTW) {
|
||||
memset(&Header, 0, sizeof(Header));
|
||||
|
||||
Is64Bit ? Header.Machine = COFF::IMAGE_FILE_MACHINE_AMD64
|
||||
: Header.Machine = COFF::IMAGE_FILE_MACHINE_I386;
|
||||
Header.Machine = TargetObjectWriter->getMachine();
|
||||
}
|
||||
|
||||
WinCOFFObjectWriter::~WinCOFFObjectWriter() {
|
||||
@ -629,32 +628,6 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
||||
}
|
||||
}
|
||||
|
||||
unsigned WinCOFFObjectWriter::getRelocType(unsigned FixupKind) const {
|
||||
switch (FixupKind) {
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_REL32 : COFF::IMAGE_REL_I386_REL32;
|
||||
break;
|
||||
case FK_Data_4:
|
||||
case X86::reloc_signed_4byte:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_ADDR32 : COFF::IMAGE_REL_I386_DIR32;
|
||||
break;
|
||||
case FK_Data_8:
|
||||
if (Is64Bit)
|
||||
return COFF::IMAGE_REL_AMD64_ADDR64;
|
||||
else
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
break;
|
||||
case X86::reloc_coff_secrel32:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_SREL32 : COFF::IMAGE_REL_I386_SECREL;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
const MCAsmLayout &Layout,
|
||||
const MCFragment *Fragment,
|
||||
@ -723,7 +696,7 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
if (CrossSection)
|
||||
FixupKind = FK_PCRel_4;
|
||||
|
||||
Reloc.Data.Type = getRelocType(FixupKind);
|
||||
Reloc.Data.Type = TargetObjectWriter->getRelocType(FixupKind);
|
||||
|
||||
// FIXME: Can anyone explain what this does other than adjust for the size
|
||||
// of the offset?
|
||||
@ -889,11 +862,16 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
OS.write((char const *)&Strings.Data.front(), Strings.Data.size());
|
||||
}
|
||||
|
||||
MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_) :
|
||||
Machine(Machine_) {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WinCOFFObjectWriter factory function
|
||||
|
||||
namespace llvm {
|
||||
MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit) {
|
||||
return new WinCOFFObjectWriter(OS, is64Bit);
|
||||
MCObjectWriter *createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
|
||||
raw_ostream &OS) {
|
||||
return new WinCOFFObjectWriter(MOTW, OS);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ add_llvm_library(LLVMX86Desc
|
||||
X86MCCodeEmitter.cpp
|
||||
X86MachObjectWriter.cpp
|
||||
X86ELFObjectWriter.cpp
|
||||
X86WinCOFFObjectWriter.cpp
|
||||
)
|
||||
|
||||
add_dependencies(LLVMX86Desc X86CommonTableGen)
|
||||
|
@ -367,7 +367,7 @@ public:
|
||||
}
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createWinCOFFObjectWriter(OS, Is64Bit);
|
||||
return createX86WinCOFFObjectWriter(OS, Is64Bit);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -92,6 +92,8 @@ MCObjectWriter *createX86MachObjectWriter(raw_ostream &OS,
|
||||
MCObjectWriter *createX86ELFObjectWriter(raw_ostream &OS,
|
||||
bool Is64Bit,
|
||||
uint8_t OSABI);
|
||||
/// createX86WinCOFFObjectWriter - Construct an X86 Win COFF object writer.
|
||||
MCObjectWriter *createX86WinCOFFObjectWriter(raw_ostream &OS, bool Is64Bit);
|
||||
} // End llvm namespace
|
||||
|
||||
|
||||
|
70
lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
Normal file
70
lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//===-- X86WinCOFFObjectWriter.cpp - X86 Win COFF Writer ------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MCTargetDesc/X86FixupKinds.h"
|
||||
#include "MCTargetDesc/X86MCTargetDesc.h"
|
||||
#include "llvm/MC/MCWinCOFFObjectWriter.h"
|
||||
#include "llvm/Support/COFF.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
class MCObjectWriter;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class X86WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
|
||||
const bool Is64Bit;
|
||||
|
||||
public:
|
||||
X86WinCOFFObjectWriter(bool Is64Bit_);
|
||||
~X86WinCOFFObjectWriter();
|
||||
|
||||
virtual unsigned getRelocType(unsigned FixupKind) const;
|
||||
};
|
||||
}
|
||||
|
||||
X86WinCOFFObjectWriter::X86WinCOFFObjectWriter(bool Is64Bit_)
|
||||
: MCWinCOFFObjectTargetWriter(Is64Bit_ ? COFF::IMAGE_FILE_MACHINE_AMD64 :
|
||||
COFF::IMAGE_FILE_MACHINE_I386),
|
||||
Is64Bit(Is64Bit_) {}
|
||||
|
||||
X86WinCOFFObjectWriter::~X86WinCOFFObjectWriter() {}
|
||||
|
||||
unsigned X86WinCOFFObjectWriter::getRelocType(unsigned FixupKind) const {
|
||||
switch (FixupKind) {
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_REL32 : COFF::IMAGE_REL_I386_REL32;
|
||||
break;
|
||||
case FK_Data_4:
|
||||
case X86::reloc_signed_4byte:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_ADDR32 : COFF::IMAGE_REL_I386_DIR32;
|
||||
break;
|
||||
case FK_Data_8:
|
||||
if (Is64Bit)
|
||||
return COFF::IMAGE_REL_AMD64_ADDR64;
|
||||
else
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
break;
|
||||
case X86::reloc_coff_secrel32:
|
||||
return Is64Bit ? COFF::IMAGE_REL_AMD64_SREL32 : COFF::IMAGE_REL_I386_SECREL;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("unsupported relocation type");
|
||||
}
|
||||
}
|
||||
|
||||
MCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_ostream &OS,
|
||||
bool Is64Bit) {
|
||||
MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit);
|
||||
return createWinCOFFObjectWriter(MOTW, OS);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user