[llvm-commits] [llvm] r111728 - in /llvm/trunk: include/llvm/MC/MCObjectWriter.h include/llvm/Support/COFF.h lib/MC/WinCOFFObjectWriter.cpp lib/Target/X86/X86AsmBackend.cpp lib/Target/X86/X86MCAsmInfo.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Fri Aug 20 22:58:13 PDT 2010
Author: mspencer
Date: Sat Aug 21 00:58:13 2010
New Revision: 111728
URL: http://llvm.org/viewvc/llvm-project?rev=111728&view=rev
Log:
MC: Add partial x86-64 support to COFF.
Modified:
llvm/trunk/include/llvm/MC/MCObjectWriter.h
llvm/trunk/include/llvm/Support/COFF.h
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=111728&r1=111727&r2=111728&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Sat Aug 21 00:58:13 2010
@@ -162,7 +162,7 @@
/// @}
};
-MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS);
+MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);
} // End llvm namespace
Modified: llvm/trunk/include/llvm/Support/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/COFF.h?rev=111728&r1=111727&r2=111728&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/COFF.h (original)
+++ llvm/trunk/include/llvm/Support/COFF.h Sat Aug 21 00:58:13 2010
@@ -50,7 +50,7 @@
enum MachineTypes {
IMAGE_FILE_MACHINE_I386 = 0x14C,
- IMAGINE_FILE_MACHINE_AMD64 = 0x8664
+ IMAGE_FILE_MACHINE_AMD64 = 0x8664
};
struct symbol {
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=111728&r1=111727&r2=111728&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Sat Aug 21 00:58:13 2010
@@ -33,6 +33,8 @@
#include "llvm/System/TimeValue.h"
+#include "../Target/X86/X86FixupKinds.h"
+
#include <cstdio>
using namespace llvm;
@@ -132,7 +134,7 @@
section_map SectionMap;
symbol_map SymbolMap;
- WinCOFFObjectWriter(raw_ostream &OS);
+ WinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);
~WinCOFFObjectWriter();
COFFSymbol *createSymbol(llvm::StringRef Name);
@@ -271,11 +273,12 @@
//------------------------------------------------------------------------------
// WinCOFFObjectWriter class implementation
-WinCOFFObjectWriter::WinCOFFObjectWriter(raw_ostream &OS)
+WinCOFFObjectWriter::WinCOFFObjectWriter(raw_ostream &OS, bool is64Bit)
: MCObjectWriter(OS, true) {
memset(&Header, 0, sizeof(Header));
- // TODO: Move magic constant out to COFF.h
- Header.Machine = 0x14C; // x86
+
+ is64Bit ? Header.Machine = COFF::IMAGE_FILE_MACHINE_AMD64
+ : Header.Machine = COFF::IMAGE_FILE_MACHINE_I386;
}
WinCOFFObjectWriter::~WinCOFFObjectWriter() {
@@ -587,17 +590,40 @@
Reloc.Data.VirtualAddress += Fixup.getOffset();
- switch (Fixup.getKind()) {
- case FirstTargetFixupKind: // reloc_pcrel_4byte
- Reloc.Data.Type = COFF::IMAGE_REL_I386_REL32;
- FixedValue += 4;
- break;
- case FK_Data_4:
- Reloc.Data.Type = COFF::IMAGE_REL_I386_DIR32;
- break;
- default:
- llvm_unreachable("unsupported relocation type");
- }
+ COFF::RelocationTypeX86 Type;
+
+ if (Header.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
+ switch (Fixup.getKind()) {
+ case X86::reloc_pcrel_4byte:
+ Type = COFF::IMAGE_REL_I386_REL32;
+ FixedValue += 4;
+ break;
+ case FK_Data_4:
+ Type = COFF::IMAGE_REL_I386_DIR32;
+ break;
+ default:
+ llvm_unreachable("unsupported relocation type");
+ }
+ } else if (Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
+ switch (Fixup.getKind()) {
+ case FK_Data_8:
+ Type = COFF::IMAGE_REL_AMD64_ADDR64;
+ break;
+ case X86::reloc_pcrel_4byte:
+ case X86::reloc_riprel_4byte:
+ Type = COFF::IMAGE_REL_AMD64_REL32;
+ FixedValue += 4;
+ break;
+ case FK_Data_4:
+ Type = COFF::IMAGE_REL_AMD64_ADDR32;
+ break;
+ default:
+ llvm_unreachable("unsupported relocation type");
+ }
+ } else
+ llvm_unreachable("unknown target architecture");
+
+ Reloc.Data.Type = Type;
coff_section->Relocations.push_back(Reloc);
}
@@ -739,7 +765,7 @@
// WinCOFFObjectWriter factory function
namespace llvm {
- MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS) {
- return new WinCOFFObjectWriter(OS);
+ MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit) {
+ return new WinCOFFObjectWriter(OS, is64Bit);
}
}
Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=111728&r1=111727&r2=111728&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Sat Aug 21 00:58:13 2010
@@ -223,14 +223,16 @@
};
class WindowsX86AsmBackend : public X86AsmBackend {
+ bool Is64Bit;
public:
- WindowsX86AsmBackend(const Target &T)
- : X86AsmBackend(T) {
+ WindowsX86AsmBackend(const Target &T, bool is64Bit)
+ : X86AsmBackend(T)
+ , Is64Bit(is64Bit) {
HasScatteredSymbols = true;
}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
- return createWinCOFFObjectWriter (OS);
+ return createWinCOFFObjectWriter(OS, Is64Bit);
}
bool isVirtualSection(const MCSection &Section) const {
@@ -320,7 +322,7 @@
case Triple::MinGW32:
case Triple::Cygwin:
case Triple::Win32:
- return new WindowsX86AsmBackend(T);
+ return new WindowsX86AsmBackend(T, false);
default:
return new ELFX86_32AsmBackend(T);
}
@@ -331,6 +333,10 @@
switch (Triple(TT).getOS()) {
case Triple::Darwin:
return new DarwinX86_64AsmBackend(T);
+ case Triple::MinGW64:
+ case Triple::Cygwin:
+ case Triple::Win32:
+ return new WindowsX86AsmBackend(T, true);
default:
return new ELFX86_64AsmBackend(T);
}
Modified: llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp?rev=111728&r1=111727&r2=111728&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp Sat Aug 21 00:58:13 2010
@@ -103,6 +103,9 @@
}
X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
+ if (Triple.getArch() == Triple::x86_64)
+ GlobalPrefix = "";
+
AsmTransCBE = x86_asm_table;
AssemblerDialect = AsmWriterFlavor;
More information about the llvm-commits
mailing list