Revert patch.
llvm-svn: 33298
This commit is contained in:
@@ -22,7 +22,6 @@ namespace llvm {
|
|||||||
class Mangler;
|
class Mangler;
|
||||||
class MachineCodeEmitter;
|
class MachineCodeEmitter;
|
||||||
class ELFCodeEmitter;
|
class ELFCodeEmitter;
|
||||||
class TargetObjInfo;
|
|
||||||
|
|
||||||
/// ELFWriter - This class implements the common target-independent code for
|
/// ELFWriter - This class implements the common target-independent code for
|
||||||
/// writing ELF files. Targets should derive a class from this to
|
/// writing ELF files. Targets should derive a class from this to
|
||||||
@@ -50,10 +49,6 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
TargetMachine &TM;
|
TargetMachine &TM;
|
||||||
|
|
||||||
/// Target object writer info.
|
|
||||||
///
|
|
||||||
const TargetObjInfo *TOI;
|
|
||||||
|
|
||||||
/// Mang - The object used to perform name mangling for this module.
|
/// Mang - The object used to perform name mangling for this module.
|
||||||
///
|
///
|
||||||
Mangler *Mang;
|
Mangler *Mang;
|
||||||
@@ -219,6 +214,102 @@ namespace llvm {
|
|||||||
unsigned ELFHeader_e_shoff_Offset; // e_shoff in ELF header.
|
unsigned ELFHeader_e_shoff_Offset; // e_shoff in ELF header.
|
||||||
unsigned ELFHeader_e_shstrndx_Offset; // e_shstrndx in ELF header.
|
unsigned ELFHeader_e_shstrndx_Offset; // e_shstrndx in ELF header.
|
||||||
unsigned ELFHeader_e_shnum_Offset; // e_shnum in ELF header.
|
unsigned ELFHeader_e_shnum_Offset; // e_shnum in ELF header.
|
||||||
|
|
||||||
|
|
||||||
|
// align - Emit padding into the file until the current output position is
|
||||||
|
// aligned to the specified power of two boundary.
|
||||||
|
static void align(DataBuffer &Output, unsigned Boundary) {
|
||||||
|
assert(Boundary && (Boundary & (Boundary-1)) == 0 &&
|
||||||
|
"Must align to 2^k boundary");
|
||||||
|
size_t Size = Output.size();
|
||||||
|
if (Size & (Boundary-1)) {
|
||||||
|
// Add padding to get alignment to the correct place.
|
||||||
|
size_t Pad = Boundary-(Size & (Boundary-1));
|
||||||
|
Output.resize(Size+Pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void outbyte(DataBuffer &Output, unsigned char X) {
|
||||||
|
Output.push_back(X);
|
||||||
|
}
|
||||||
|
void outhalf(DataBuffer &Output, unsigned short X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back(X&255);
|
||||||
|
Output.push_back(X >> 8);
|
||||||
|
} else {
|
||||||
|
Output.push_back(X >> 8);
|
||||||
|
Output.push_back(X&255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outword(DataBuffer &Output, unsigned X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back((X >> 0) & 255);
|
||||||
|
Output.push_back((X >> 8) & 255);
|
||||||
|
Output.push_back((X >> 16) & 255);
|
||||||
|
Output.push_back((X >> 24) & 255);
|
||||||
|
} else {
|
||||||
|
Output.push_back((X >> 24) & 255);
|
||||||
|
Output.push_back((X >> 16) & 255);
|
||||||
|
Output.push_back((X >> 8) & 255);
|
||||||
|
Output.push_back((X >> 0) & 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outxword(DataBuffer &Output, uint64_t X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back(unsigned(X >> 0) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 8) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 16) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 24) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 32) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 40) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 48) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 56) & 255);
|
||||||
|
} else {
|
||||||
|
Output.push_back(unsigned(X >> 56) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 48) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 40) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 32) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 24) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 16) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 8) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 0) & 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outaddr32(DataBuffer &Output, unsigned X) {
|
||||||
|
outword(Output, X);
|
||||||
|
}
|
||||||
|
void outaddr64(DataBuffer &Output, uint64_t X) {
|
||||||
|
outxword(Output, X);
|
||||||
|
}
|
||||||
|
void outaddr(DataBuffer &Output, uint64_t X) {
|
||||||
|
if (!is64Bit)
|
||||||
|
outword(Output, (unsigned)X);
|
||||||
|
else
|
||||||
|
outxword(Output, X);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix functions - Replace an existing entry at an offset.
|
||||||
|
void fixhalf(DataBuffer &Output, unsigned short X, unsigned Offset) {
|
||||||
|
unsigned char *P = &Output[Offset];
|
||||||
|
P[0] = (X >> (isLittleEndian ? 0 : 8)) & 255;
|
||||||
|
P[1] = (X >> (isLittleEndian ? 8 : 0)) & 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fixword(DataBuffer &Output, unsigned X, unsigned Offset) {
|
||||||
|
unsigned char *P = &Output[Offset];
|
||||||
|
P[0] = (X >> (isLittleEndian ? 0 : 24)) & 255;
|
||||||
|
P[1] = (X >> (isLittleEndian ? 8 : 16)) & 255;
|
||||||
|
P[2] = (X >> (isLittleEndian ? 16 : 8)) & 255;
|
||||||
|
P[3] = (X >> (isLittleEndian ? 24 : 0)) & 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fixaddr(DataBuffer &Output, uint64_t X, unsigned Offset) {
|
||||||
|
if (!is64Bit)
|
||||||
|
fixword(Output, (unsigned)X, Offset);
|
||||||
|
else
|
||||||
|
assert(0 && "Emission of 64-bit data not implemented yet!");
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EmitGlobal(GlobalVariable *GV);
|
void EmitGlobal(GlobalVariable *GV);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ namespace llvm {
|
|||||||
class Mangler;
|
class Mangler;
|
||||||
class MachineCodeEmitter;
|
class MachineCodeEmitter;
|
||||||
class MachOCodeEmitter;
|
class MachOCodeEmitter;
|
||||||
class TargetObjInfo;
|
|
||||||
|
|
||||||
/// MachOSym - This struct contains information about each symbol that is
|
/// MachOSym - This struct contains information about each symbol that is
|
||||||
/// added to logical symbol table for the module. This is eventually
|
/// added to logical symbol table for the module. This is eventually
|
||||||
@@ -101,10 +100,6 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
TargetMachine &TM;
|
TargetMachine &TM;
|
||||||
|
|
||||||
/// Target object writer info.
|
|
||||||
///
|
|
||||||
const TargetObjInfo *TOI;
|
|
||||||
|
|
||||||
/// Mang - The object used to perform name mangling for this module.
|
/// Mang - The object used to perform name mangling for this module.
|
||||||
///
|
///
|
||||||
Mangler *Mang;
|
Mangler *Mang;
|
||||||
@@ -664,6 +659,101 @@ namespace llvm {
|
|||||||
/// SymbolTable to aid in emitting the DYSYMTAB load command.
|
/// SymbolTable to aid in emitting the DYSYMTAB load command.
|
||||||
std::vector<unsigned> DynamicSymbolTable;
|
std::vector<unsigned> DynamicSymbolTable;
|
||||||
|
|
||||||
|
// align - Emit padding into the file until the current output position is
|
||||||
|
// aligned to the specified power of two boundary.
|
||||||
|
static void align(DataBuffer &Output, unsigned Boundary) {
|
||||||
|
assert(Boundary && (Boundary & (Boundary-1)) == 0 &&
|
||||||
|
"Must align to 2^k boundary");
|
||||||
|
size_t Size = Output.size();
|
||||||
|
if (Size & (Boundary-1)) {
|
||||||
|
// Add padding to get alignment to the correct place.
|
||||||
|
size_t Pad = Boundary-(Size & (Boundary-1));
|
||||||
|
Output.resize(Size+Pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void outbyte(DataBuffer &Output, unsigned char X) {
|
||||||
|
Output.push_back(X);
|
||||||
|
}
|
||||||
|
void outhalf(DataBuffer &Output, unsigned short X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back(X&255);
|
||||||
|
Output.push_back(X >> 8);
|
||||||
|
} else {
|
||||||
|
Output.push_back(X >> 8);
|
||||||
|
Output.push_back(X&255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outword(DataBuffer &Output, unsigned X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back((X >> 0) & 255);
|
||||||
|
Output.push_back((X >> 8) & 255);
|
||||||
|
Output.push_back((X >> 16) & 255);
|
||||||
|
Output.push_back((X >> 24) & 255);
|
||||||
|
} else {
|
||||||
|
Output.push_back((X >> 24) & 255);
|
||||||
|
Output.push_back((X >> 16) & 255);
|
||||||
|
Output.push_back((X >> 8) & 255);
|
||||||
|
Output.push_back((X >> 0) & 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outxword(DataBuffer &Output, uint64_t X) {
|
||||||
|
if (isLittleEndian) {
|
||||||
|
Output.push_back(unsigned(X >> 0) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 8) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 16) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 24) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 32) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 40) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 48) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 56) & 255);
|
||||||
|
} else {
|
||||||
|
Output.push_back(unsigned(X >> 56) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 48) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 40) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 32) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 24) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 16) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 8) & 255);
|
||||||
|
Output.push_back(unsigned(X >> 0) & 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void outaddr32(DataBuffer &Output, unsigned X) {
|
||||||
|
outword(Output, X);
|
||||||
|
}
|
||||||
|
void outaddr64(DataBuffer &Output, uint64_t X) {
|
||||||
|
outxword(Output, X);
|
||||||
|
}
|
||||||
|
void outaddr(DataBuffer &Output, uint64_t X) {
|
||||||
|
if (!is64Bit)
|
||||||
|
outword(Output, (unsigned)X);
|
||||||
|
else
|
||||||
|
outxword(Output, X);
|
||||||
|
}
|
||||||
|
void outstring(DataBuffer &Output, std::string &S, unsigned Length) {
|
||||||
|
unsigned len_to_copy = S.length() < Length ? S.length() : Length;
|
||||||
|
unsigned len_to_fill = S.length() < Length ? Length-S.length() : 0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < len_to_copy; ++i)
|
||||||
|
outbyte(Output, S[i]);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < len_to_fill; ++i)
|
||||||
|
outbyte(Output, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
void fixhalf(DataBuffer &Output, unsigned short X, unsigned Offset) {
|
||||||
|
unsigned char *P = &Output[Offset];
|
||||||
|
P[0] = (X >> (isLittleEndian ? 0 : 8)) & 255;
|
||||||
|
P[1] = (X >> (isLittleEndian ? 8 : 0)) & 255;
|
||||||
|
}
|
||||||
|
void fixword(DataBuffer &Output, unsigned X, unsigned Offset) {
|
||||||
|
unsigned char *P = &Output[Offset];
|
||||||
|
P[0] = (X >> (isLittleEndian ? 0 : 24)) & 255;
|
||||||
|
P[1] = (X >> (isLittleEndian ? 8 : 16)) & 255;
|
||||||
|
P[2] = (X >> (isLittleEndian ? 16 : 8)) & 255;
|
||||||
|
P[3] = (X >> (isLittleEndian ? 24 : 0)) & 255;
|
||||||
|
}
|
||||||
|
|
||||||
static void InitMem(const Constant *C, void *Addr, intptr_t Offset,
|
static void InitMem(const Constant *C, void *Addr, intptr_t Offset,
|
||||||
const TargetData *TD,
|
const TargetData *TD,
|
||||||
std::vector<MachineRelocation> &MRs);
|
std::vector<MachineRelocation> &MRs);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class TargetAsmInfo;
|
class TargetAsmInfo;
|
||||||
class TargetObjInfo;
|
|
||||||
class TargetData;
|
class TargetData;
|
||||||
class TargetSubtarget;
|
class TargetSubtarget;
|
||||||
class TargetInstrInfo;
|
class TargetInstrInfo;
|
||||||
@@ -67,7 +66,7 @@ class TargetMachine {
|
|||||||
TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
|
TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
|
||||||
void operator=(const TargetMachine &); // DO NOT IMPLEMENT
|
void operator=(const TargetMachine &); // DO NOT IMPLEMENT
|
||||||
protected: // Can only create subclasses.
|
protected: // Can only create subclasses.
|
||||||
TargetMachine() : AsmInfo(NULL), ObjInfo(NULL) { }
|
TargetMachine() : AsmInfo(NULL) { }
|
||||||
|
|
||||||
/// getSubtargetImpl - virtual method implemented by subclasses that returns
|
/// getSubtargetImpl - virtual method implemented by subclasses that returns
|
||||||
/// a reference to that target's TargetSubtarget-derived member variable.
|
/// a reference to that target's TargetSubtarget-derived member variable.
|
||||||
@@ -81,14 +80,6 @@ protected: // Can only create subclasses.
|
|||||||
/// information.
|
/// information.
|
||||||
virtual const TargetAsmInfo *createTargetAsmInfo() const { return NULL; }
|
virtual const TargetAsmInfo *createTargetAsmInfo() const { return NULL; }
|
||||||
|
|
||||||
/// ObjInfo - Contains target specific object file information.
|
|
||||||
///
|
|
||||||
mutable const TargetObjInfo *ObjInfo;
|
|
||||||
|
|
||||||
/// createTargetObjInfo - Create a new instance of target specific object
|
|
||||||
/// information.
|
|
||||||
virtual const TargetObjInfo *createTargetObjInfo() const { return NULL; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~TargetMachine();
|
virtual ~TargetMachine();
|
||||||
|
|
||||||
@@ -116,6 +107,7 @@ public:
|
|||||||
virtual TargetLowering *getTargetLowering() const { return 0; }
|
virtual TargetLowering *getTargetLowering() const { return 0; }
|
||||||
virtual const TargetData *getTargetData() const { return 0; }
|
virtual const TargetData *getTargetData() const { return 0; }
|
||||||
|
|
||||||
|
|
||||||
/// getTargetAsmInfo - Return target specific asm information.
|
/// getTargetAsmInfo - Return target specific asm information.
|
||||||
///
|
///
|
||||||
const TargetAsmInfo *getTargetAsmInfo() const {
|
const TargetAsmInfo *getTargetAsmInfo() const {
|
||||||
@@ -123,13 +115,6 @@ public:
|
|||||||
return AsmInfo;
|
return AsmInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getTargetObjInfo - Return target specific object information.
|
|
||||||
///
|
|
||||||
const TargetObjInfo *getTargetObjInfo() const {
|
|
||||||
if (!ObjInfo) ObjInfo = createTargetObjInfo();
|
|
||||||
return ObjInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getSubtarget - This method returns a pointer to the specified type of
|
/// getSubtarget - This method returns a pointer to the specified type of
|
||||||
/// TargetSubtarget. In debug builds, it verifies that the object being
|
/// TargetSubtarget. In debug builds, it verifies that the object being
|
||||||
/// returned is of the correct type.
|
/// returned is of the correct type.
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
//===-- llvm/Target/TargetObjInfo.h - Object File Info ----------*- C++ -*-===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file was developed by Bill Wendling and is distributed under the
|
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file contains a class to be used as the basis for target specific object
|
|
||||||
// writers.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#ifndef LLVM_TARGET_OBJ_INFO_H
|
|
||||||
#define LLVM_TARGET_OBJ_INFO_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
struct TargetObjInfo {
|
|
||||||
TargetObjInfo() {}
|
|
||||||
virtual ~TargetObjInfo() {}
|
|
||||||
|
|
||||||
typedef std::vector<unsigned char> DataBuffer;
|
|
||||||
|
|
||||||
virtual void align(DataBuffer &Output, unsigned Boundary) const = 0;
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Out Functions - Output the specified value to the data buffer.
|
|
||||||
|
|
||||||
virtual void outbyte(DataBuffer &Output, unsigned char X) const = 0;
|
|
||||||
virtual void outhalf(DataBuffer &Output, unsigned short X) const = 0;
|
|
||||||
virtual void outword(DataBuffer &Output, unsigned X) const = 0;
|
|
||||||
virtual void outxword(DataBuffer &Output, uint64_t X) const = 0;
|
|
||||||
virtual void outaddr32(DataBuffer &Output, unsigned X) const = 0;
|
|
||||||
virtual void outaddr64(DataBuffer &Output, uint64_t X) const = 0;
|
|
||||||
virtual void outaddr(DataBuffer &Output, uint64_t X) const = 0;
|
|
||||||
virtual void outstring(DataBuffer &Output, std::string &S,
|
|
||||||
unsigned Length) const = 0;
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Fix Functions - Replace an existing entry at an offset.
|
|
||||||
|
|
||||||
virtual void fixhalf(DataBuffer &Output, unsigned short X,
|
|
||||||
unsigned Offset) const = 0;
|
|
||||||
virtual void fixword(DataBuffer &Output, unsigned X,
|
|
||||||
unsigned Offset) const = 0;
|
|
||||||
virtual void fixaddr(DataBuffer &Output, uint64_t X,
|
|
||||||
unsigned Offset) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end llvm namespace
|
|
||||||
|
|
||||||
#endif // LLVM_TARGET_OBJ_INFO_H
|
|
||||||
@@ -37,7 +37,6 @@
|
|||||||
#include "llvm/CodeGen/MachineConstantPool.h"
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "llvm/Support/Streams.h"
|
#include "llvm/Support/Streams.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -54,20 +53,8 @@ namespace llvm {
|
|||||||
ELFWriter::ELFSection *ES; // Section to write to.
|
ELFWriter::ELFSection *ES; // Section to write to.
|
||||||
std::vector<unsigned char> *OutBuffer;
|
std::vector<unsigned char> *OutBuffer;
|
||||||
size_t FnStart;
|
size_t FnStart;
|
||||||
|
|
||||||
/// Target machine description.
|
|
||||||
///
|
|
||||||
TargetMachine &TM;
|
|
||||||
|
|
||||||
/// Target object writer info.
|
|
||||||
///
|
|
||||||
const TargetObjInfo *TOI;
|
|
||||||
public:
|
public:
|
||||||
ELFCodeEmitter(ELFWriter &ew, TargetMachine &tm)
|
ELFCodeEmitter(ELFWriter &ew) : EW(ew), OutBuffer(0) {}
|
||||||
: EW(ew), OutBuffer(0), TM(tm) {
|
|
||||||
// Create the target object info object for this target.
|
|
||||||
TOI = TM.getTargetObjInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void startFunction(MachineFunction &F);
|
void startFunction(MachineFunction &F);
|
||||||
bool finishFunction(MachineFunction &F);
|
bool finishFunction(MachineFunction &F);
|
||||||
@@ -126,7 +113,7 @@ void ELFCodeEmitter::startFunction(MachineFunction &F) {
|
|||||||
|
|
||||||
// Add padding zeros to the end of the buffer to make sure that the
|
// Add padding zeros to the end of the buffer to make sure that the
|
||||||
// function will start on the correct byte alignment within the section.
|
// function will start on the correct byte alignment within the section.
|
||||||
TOI->align(*OutBuffer, Align);
|
ELFWriter::align(*OutBuffer, Align);
|
||||||
|
|
||||||
FnStart = OutBuffer->size();
|
FnStart = OutBuffer->size();
|
||||||
}
|
}
|
||||||
@@ -178,11 +165,8 @@ ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
|
|||||||
isLittleEndian = TM.getTargetData()->isLittleEndian();
|
isLittleEndian = TM.getTargetData()->isLittleEndian();
|
||||||
|
|
||||||
// Create the machine code emitter object for this target.
|
// Create the machine code emitter object for this target.
|
||||||
MCE = new ELFCodeEmitter(*this, TM);
|
MCE = new ELFCodeEmitter(*this);
|
||||||
NumSections = 0;
|
NumSections = 0;
|
||||||
|
|
||||||
// Create the target object info object for this target.
|
|
||||||
TOI = TM.getTargetObjInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFWriter::~ELFWriter() {
|
ELFWriter::~ELFWriter() {
|
||||||
@@ -197,36 +181,36 @@ bool ELFWriter::doInitialization(Module &M) {
|
|||||||
// Local alias to shortenify coming code.
|
// Local alias to shortenify coming code.
|
||||||
std::vector<unsigned char> &FH = FileHeader;
|
std::vector<unsigned char> &FH = FileHeader;
|
||||||
|
|
||||||
TOI->outbyte(FH, 0x7F); // EI_MAG0
|
outbyte(FH, 0x7F); // EI_MAG0
|
||||||
TOI->outbyte(FH, 'E'); // EI_MAG1
|
outbyte(FH, 'E'); // EI_MAG1
|
||||||
TOI->outbyte(FH, 'L'); // EI_MAG2
|
outbyte(FH, 'L'); // EI_MAG2
|
||||||
TOI->outbyte(FH, 'F'); // EI_MAG3
|
outbyte(FH, 'F'); // EI_MAG3
|
||||||
TOI->outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS
|
outbyte(FH, is64Bit ? 2 : 1); // EI_CLASS
|
||||||
TOI->outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA
|
outbyte(FH, isLittleEndian ? 1 : 2); // EI_DATA
|
||||||
TOI->outbyte(FH, 1); // EI_VERSION
|
outbyte(FH, 1); // EI_VERSION
|
||||||
FH.resize(16); // EI_PAD up to 16 bytes.
|
FH.resize(16); // EI_PAD up to 16 bytes.
|
||||||
|
|
||||||
// This should change for shared objects.
|
// This should change for shared objects.
|
||||||
TOI->outhalf(FH, 1); // e_type = ET_REL
|
outhalf(FH, 1); // e_type = ET_REL
|
||||||
TOI->outhalf(FH, e_machine); // e_machine = whatever the target wants
|
outhalf(FH, e_machine); // e_machine = whatever the target wants
|
||||||
TOI->outword(FH, 1); // e_version = 1
|
outword(FH, 1); // e_version = 1
|
||||||
TOI->outaddr(FH, 0); // e_entry = 0 -> no entry point in .o file
|
outaddr(FH, 0); // e_entry = 0 -> no entry point in .o file
|
||||||
TOI->outaddr(FH, 0); // e_phoff = 0 -> no program header for .o
|
outaddr(FH, 0); // e_phoff = 0 -> no program header for .o
|
||||||
|
|
||||||
ELFHeader_e_shoff_Offset = FH.size();
|
ELFHeader_e_shoff_Offset = FH.size();
|
||||||
TOI->outaddr(FH, 0); // e_shoff
|
outaddr(FH, 0); // e_shoff
|
||||||
TOI->outword(FH, e_flags); // e_flags = whatever the target wants
|
outword(FH, e_flags); // e_flags = whatever the target wants
|
||||||
|
|
||||||
TOI->outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size
|
outhalf(FH, is64Bit ? 64 : 52); // e_ehsize = ELF header size
|
||||||
TOI->outhalf(FH, 0); // e_phentsize = prog header entry size
|
outhalf(FH, 0); // e_phentsize = prog header entry size
|
||||||
TOI->outhalf(FH, 0); // e_phnum = # prog header entries=0
|
outhalf(FH, 0); // e_phnum = # prog header entries = 0
|
||||||
TOI->outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size
|
outhalf(FH, is64Bit ? 64 : 40); // e_shentsize = sect hdr entry size
|
||||||
|
|
||||||
|
|
||||||
ELFHeader_e_shnum_Offset = FH.size();
|
ELFHeader_e_shnum_Offset = FH.size();
|
||||||
TOI->outhalf(FH, 0); // e_shnum = # of section header ents
|
outhalf(FH, 0); // e_shnum = # of section header ents
|
||||||
ELFHeader_e_shstrndx_Offset = FH.size();
|
ELFHeader_e_shstrndx_Offset = FH.size();
|
||||||
TOI->outhalf(FH, 0); // e_shstrndx = Section # of '.shstrtab'
|
outhalf(FH, 0); // e_shstrndx = Section # of '.shstrtab'
|
||||||
|
|
||||||
// Add the null section, which is required to be first in the file.
|
// Add the null section, which is required to be first in the file.
|
||||||
getSection("", 0, 0);
|
getSection("", 0, 0);
|
||||||
@@ -368,7 +352,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
DataBuffer &StrTabBuf = StrTab.SectionData;
|
DataBuffer &StrTabBuf = StrTab.SectionData;
|
||||||
|
|
||||||
// Set the zero'th symbol to a null byte, as required.
|
// Set the zero'th symbol to a null byte, as required.
|
||||||
TOI->outbyte(StrTabBuf, 0);
|
outbyte(StrTabBuf, 0);
|
||||||
SymbolTable[0].NameIdx = 0;
|
SymbolTable[0].NameIdx = 0;
|
||||||
unsigned Index = 1;
|
unsigned Index = 1;
|
||||||
for (unsigned i = 1, e = SymbolTable.size(); i != e; ++i) {
|
for (unsigned i = 1, e = SymbolTable.size(); i != e; ++i) {
|
||||||
@@ -405,22 +389,22 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
if (!is64Bit) { // 32-bit and 64-bit formats are shuffled a bit.
|
if (!is64Bit) { // 32-bit and 64-bit formats are shuffled a bit.
|
||||||
for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
|
for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
|
||||||
ELFSym &Sym = SymbolTable[i];
|
ELFSym &Sym = SymbolTable[i];
|
||||||
TOI->outword(SymTabBuf, Sym.NameIdx);
|
outword(SymTabBuf, Sym.NameIdx);
|
||||||
TOI->outaddr32(SymTabBuf, Sym.Value);
|
outaddr32(SymTabBuf, Sym.Value);
|
||||||
TOI->outword(SymTabBuf, Sym.Size);
|
outword(SymTabBuf, Sym.Size);
|
||||||
TOI->outbyte(SymTabBuf, Sym.Info);
|
outbyte(SymTabBuf, Sym.Info);
|
||||||
TOI->outbyte(SymTabBuf, Sym.Other);
|
outbyte(SymTabBuf, Sym.Other);
|
||||||
TOI->outhalf(SymTabBuf, Sym.SectionIdx);
|
outhalf(SymTabBuf, Sym.SectionIdx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
|
for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
|
||||||
ELFSym &Sym = SymbolTable[i];
|
ELFSym &Sym = SymbolTable[i];
|
||||||
TOI->outword(SymTabBuf, Sym.NameIdx);
|
outword(SymTabBuf, Sym.NameIdx);
|
||||||
TOI->outbyte(SymTabBuf, Sym.Info);
|
outbyte(SymTabBuf, Sym.Info);
|
||||||
TOI->outbyte(SymTabBuf, Sym.Other);
|
outbyte(SymTabBuf, Sym.Other);
|
||||||
TOI->outhalf(SymTabBuf, Sym.SectionIdx);
|
outhalf(SymTabBuf, Sym.SectionIdx);
|
||||||
TOI->outaddr64(SymTabBuf, Sym.Value);
|
outaddr64(SymTabBuf, Sym.Value);
|
||||||
TOI->outxword(SymTabBuf, Sym.Size);
|
outxword(SymTabBuf, Sym.Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,7 +420,7 @@ void ELFWriter::EmitSectionTableStringTable() {
|
|||||||
|
|
||||||
// Now that we know which section number is the .shstrtab section, update the
|
// Now that we know which section number is the .shstrtab section, update the
|
||||||
// e_shstrndx entry in the ELF header.
|
// e_shstrndx entry in the ELF header.
|
||||||
TOI->fixhalf(FileHeader, SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset);
|
fixhalf(FileHeader, SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset);
|
||||||
|
|
||||||
// Set the NameIdx of each section in the string table and emit the bytes for
|
// Set the NameIdx of each section in the string table and emit the bytes for
|
||||||
// the string table.
|
// the string table.
|
||||||
@@ -487,11 +471,11 @@ void ELFWriter::OutputSectionsAndSectionTable() {
|
|||||||
|
|
||||||
// Now that we know where all of the sections will be emitted, set the e_shnum
|
// Now that we know where all of the sections will be emitted, set the e_shnum
|
||||||
// entry in the ELF header.
|
// entry in the ELF header.
|
||||||
TOI->fixhalf(FileHeader, NumSections, ELFHeader_e_shnum_Offset);
|
fixhalf(FileHeader, NumSections, ELFHeader_e_shnum_Offset);
|
||||||
|
|
||||||
// Now that we know the offset in the file of the section table, update the
|
// Now that we know the offset in the file of the section table, update the
|
||||||
// e_shoff address in the ELF header.
|
// e_shoff address in the ELF header.
|
||||||
TOI->fixaddr(FileHeader, FileOff, ELFHeader_e_shoff_Offset);
|
fixaddr(FileHeader, FileOff, ELFHeader_e_shoff_Offset);
|
||||||
|
|
||||||
// Now that we know all of the data in the file header, emit it and all of the
|
// Now that we know all of the data in the file header, emit it and all of the
|
||||||
// sections!
|
// sections!
|
||||||
@@ -513,16 +497,16 @@ void ELFWriter::OutputSectionsAndSectionTable() {
|
|||||||
O.write((char*)&S.SectionData[0], S.SectionData.size());
|
O.write((char*)&S.SectionData[0], S.SectionData.size());
|
||||||
FileOff += S.SectionData.size();
|
FileOff += S.SectionData.size();
|
||||||
|
|
||||||
TOI->outword(Table, S.NameIdx); // sh_name - Symbol table name idx
|
outword(Table, S.NameIdx); // sh_name - Symbol table name idx
|
||||||
TOI->outword(Table, S.Type); // sh_type - Section contents & semantics
|
outword(Table, S.Type); // sh_type - Section contents & semantics
|
||||||
TOI->outword(Table, S.Flags); // sh_flags - Section flags
|
outword(Table, S.Flags); // sh_flags - Section flags.
|
||||||
TOI->outaddr(Table, S.Addr); // sh_addr - The mem addr this section is in
|
outaddr(Table, S.Addr); // sh_addr - The mem addr this section is in.
|
||||||
TOI->outaddr(Table, S.Offset); // sh_offset - Offset from the file start
|
outaddr(Table, S.Offset); // sh_offset - Offset from the file start.
|
||||||
TOI->outword(Table, S.Size); // sh_size - The section size
|
outword(Table, S.Size); // sh_size - The section size.
|
||||||
TOI->outword(Table, S.Link); // sh_link - Section header table index link
|
outword(Table, S.Link); // sh_link - Section header table index link.
|
||||||
TOI->outword(Table, S.Info); // sh_info - Auxillary information
|
outword(Table, S.Info); // sh_info - Auxillary information.
|
||||||
TOI->outword(Table, S.Align); // sh_addralign - Alignment of section
|
outword(Table, S.Align); // sh_addralign - Alignment of section.
|
||||||
TOI->outword(Table, S.EntSize); // sh_entsize - Size of entries in the sect
|
outword(Table, S.EntSize); // sh_entsize - Size of entries in the section.
|
||||||
|
|
||||||
SectionList.pop_front();
|
SectionList.pop_front();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@
|
|||||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||||
#include "llvm/Target/TargetAsmInfo.h"
|
#include "llvm/Target/TargetAsmInfo.h"
|
||||||
#include "llvm/Target/TargetJITInfo.h"
|
#include "llvm/Target/TargetJITInfo.h"
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/Streams.h"
|
#include "llvm/Support/Streams.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@@ -49,14 +49,6 @@ namespace llvm {
|
|||||||
class MachOCodeEmitter : public MachineCodeEmitter {
|
class MachOCodeEmitter : public MachineCodeEmitter {
|
||||||
MachOWriter &MOW;
|
MachOWriter &MOW;
|
||||||
|
|
||||||
/// Target machine description.
|
|
||||||
///
|
|
||||||
TargetMachine &TM;
|
|
||||||
|
|
||||||
/// Target object writer info.
|
|
||||||
///
|
|
||||||
const TargetObjInfo *TOI;
|
|
||||||
|
|
||||||
/// Relocations - These are the relocations that the function needs, as
|
/// Relocations - These are the relocations that the function needs, as
|
||||||
/// emitted.
|
/// emitted.
|
||||||
std::vector<MachineRelocation> Relocations;
|
std::vector<MachineRelocation> Relocations;
|
||||||
@@ -79,10 +71,7 @@ namespace llvm {
|
|||||||
std::vector<intptr_t> MBBLocations;
|
std::vector<intptr_t> MBBLocations;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MachOCodeEmitter(MachOWriter &mow, TargetMachine &tm) : MOW(mow), TM(tm) {
|
MachOCodeEmitter(MachOWriter &mow) : MOW(mow) {}
|
||||||
// Create the target object info object for this target.
|
|
||||||
TOI = TM.getTargetObjInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void startFunction(MachineFunction &F);
|
virtual void startFunction(MachineFunction &F);
|
||||||
virtual bool finishFunction(MachineFunction &F);
|
virtual bool finishFunction(MachineFunction &F);
|
||||||
@@ -174,7 +163,7 @@ bool MachOCodeEmitter::finishFunction(MachineFunction &F) {
|
|||||||
|
|
||||||
// Get a symbol for the function to add to the symbol table
|
// Get a symbol for the function to add to the symbol table
|
||||||
const GlobalValue *FuncV = F.getFunction();
|
const GlobalValue *FuncV = F.getFunction();
|
||||||
MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TM);
|
MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, MOW.TM);
|
||||||
|
|
||||||
// Emit constant pool to appropriate section(s)
|
// Emit constant pool to appropriate section(s)
|
||||||
emitConstantPool(F.getConstantPool());
|
emitConstantPool(F.getConstantPool());
|
||||||
@@ -222,7 +211,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
|||||||
if (CP.empty()) return;
|
if (CP.empty()) return;
|
||||||
|
|
||||||
// FIXME: handle PIC codegen
|
// FIXME: handle PIC codegen
|
||||||
bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
|
bool isPIC = MOW.TM.getRelocationModel() == Reloc::PIC_;
|
||||||
assert(!isPIC && "PIC codegen not yet handled for mach-o jump tables!");
|
assert(!isPIC && "PIC codegen not yet handled for mach-o jump tables!");
|
||||||
|
|
||||||
// Although there is no strict necessity that I am aware of, we will do what
|
// Although there is no strict necessity that I am aware of, we will do what
|
||||||
@@ -234,7 +223,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
|||||||
// "giant object for PIC" optimization.
|
// "giant object for PIC" optimization.
|
||||||
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
||||||
const Type *Ty = CP[i].getType();
|
const Type *Ty = CP[i].getType();
|
||||||
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
unsigned Size = MOW.TM.getTargetData()->getTypeSize(Ty);
|
||||||
|
|
||||||
MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
|
MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
|
||||||
CPLocations.push_back(Sec->SectionData.size());
|
CPLocations.push_back(Sec->SectionData.size());
|
||||||
@@ -247,10 +236,10 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
|||||||
// FIXME: need alignment?
|
// FIXME: need alignment?
|
||||||
// FIXME: share between here and AddSymbolToSection?
|
// FIXME: share between here and AddSymbolToSection?
|
||||||
for (unsigned j = 0; j < Size; ++j)
|
for (unsigned j = 0; j < Size; ++j)
|
||||||
TOI->outbyte(Sec->SectionData, 0);
|
MOW.outbyte(Sec->SectionData, 0);
|
||||||
|
|
||||||
MOW.InitMem(CP[i].Val.ConstVal, &Sec->SectionData[0], CPLocations[i],
|
MOW.InitMem(CP[i].Val.ConstVal, &Sec->SectionData[0], CPLocations[i],
|
||||||
TM.getTargetData(), Sec->Relocations);
|
MOW.TM.getTargetData(), Sec->Relocations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +250,7 @@ void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) {
|
|||||||
if (JT.empty()) return;
|
if (JT.empty()) return;
|
||||||
|
|
||||||
// FIXME: handle PIC codegen
|
// FIXME: handle PIC codegen
|
||||||
bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
|
bool isPIC = MOW.TM.getRelocationModel() == Reloc::PIC_;
|
||||||
assert(!isPIC && "PIC codegen not yet handled for mach-o jump tables!");
|
assert(!isPIC && "PIC codegen not yet handled for mach-o jump tables!");
|
||||||
|
|
||||||
MachOWriter::MachOSection *Sec = MOW.getJumpTableSection();
|
MachOWriter::MachOSection *Sec = MOW.getJumpTableSection();
|
||||||
@@ -278,7 +267,7 @@ void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) {
|
|||||||
MR.setResultPointer((void *)JTLocations[i]);
|
MR.setResultPointer((void *)JTLocations[i]);
|
||||||
MR.setConstantVal(TextSecIndex);
|
MR.setConstantVal(TextSecIndex);
|
||||||
Sec->Relocations.push_back(MR);
|
Sec->Relocations.push_back(MR);
|
||||||
TOI->outaddr(Sec->SectionData, 0);
|
MOW.outaddr(Sec->SectionData, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: remove when we have unified size + output buffer
|
// FIXME: remove when we have unified size + output buffer
|
||||||
@@ -294,10 +283,7 @@ MachOWriter::MachOWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
|
|||||||
isLittleEndian = TM.getTargetData()->isLittleEndian();
|
isLittleEndian = TM.getTargetData()->isLittleEndian();
|
||||||
|
|
||||||
// Create the machine code emitter object for this target.
|
// Create the machine code emitter object for this target.
|
||||||
MCE = new MachOCodeEmitter(*this, tm);
|
MCE = new MachOCodeEmitter(*this);
|
||||||
|
|
||||||
// Create the target object info object for this target.
|
|
||||||
TOI = TM.getTargetObjInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MachOWriter::~MachOWriter() {
|
MachOWriter::~MachOWriter() {
|
||||||
@@ -326,7 +312,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
|
|||||||
// FIXME: remove when we have unified size + output buffer
|
// FIXME: remove when we have unified size + output buffer
|
||||||
unsigned AlignedSize = Sec->size - OrigSize;
|
unsigned AlignedSize = Sec->size - OrigSize;
|
||||||
for (unsigned i = 0; i < AlignedSize; ++i)
|
for (unsigned i = 0; i < AlignedSize; ++i)
|
||||||
TOI->outbyte(Sec->SectionData, 0);
|
outbyte(Sec->SectionData, 0);
|
||||||
}
|
}
|
||||||
// Record the offset of the symbol, and then allocate space for it.
|
// Record the offset of the symbol, and then allocate space for it.
|
||||||
// FIXME: remove when we have unified size + output buffer
|
// FIXME: remove when we have unified size + output buffer
|
||||||
@@ -343,7 +329,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
|
|||||||
|
|
||||||
// Allocate space in the section for the global.
|
// Allocate space in the section for the global.
|
||||||
for (unsigned i = 0; i < Size; ++i)
|
for (unsigned i = 0; i < Size; ++i)
|
||||||
TOI->outbyte(Sec->SectionData, 0);
|
outbyte(Sec->SectionData, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachOWriter::EmitGlobal(GlobalVariable *GV) {
|
void MachOWriter::EmitGlobal(GlobalVariable *GV) {
|
||||||
@@ -456,15 +442,15 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
|
|||||||
// Step #3: write the header to the file
|
// Step #3: write the header to the file
|
||||||
// Local alias to shortenify coming code.
|
// Local alias to shortenify coming code.
|
||||||
DataBuffer &FH = Header.HeaderData;
|
DataBuffer &FH = Header.HeaderData;
|
||||||
TOI->outword(FH, Header.magic);
|
outword(FH, Header.magic);
|
||||||
TOI->outword(FH, Header.cputype);
|
outword(FH, Header.cputype);
|
||||||
TOI->outword(FH, Header.cpusubtype);
|
outword(FH, Header.cpusubtype);
|
||||||
TOI->outword(FH, Header.filetype);
|
outword(FH, Header.filetype);
|
||||||
TOI->outword(FH, Header.ncmds);
|
outword(FH, Header.ncmds);
|
||||||
TOI->outword(FH, Header.sizeofcmds);
|
outword(FH, Header.sizeofcmds);
|
||||||
TOI->outword(FH, Header.flags);
|
outword(FH, Header.flags);
|
||||||
if (is64Bit)
|
if (is64Bit)
|
||||||
TOI->outword(FH, Header.reserved);
|
outword(FH, Header.reserved);
|
||||||
|
|
||||||
// Step #4: Finish filling in the segment load command and write it out
|
// Step #4: Finish filling in the segment load command and write it out
|
||||||
for (std::vector<MachOSection*>::iterator I = SectionList.begin(),
|
for (std::vector<MachOSection*>::iterator I = SectionList.begin(),
|
||||||
@@ -474,17 +460,17 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
|
|||||||
SEG.vmsize = SEG.filesize;
|
SEG.vmsize = SEG.filesize;
|
||||||
SEG.fileoff = Header.cmdSize(is64Bit) + Header.sizeofcmds;
|
SEG.fileoff = Header.cmdSize(is64Bit) + Header.sizeofcmds;
|
||||||
|
|
||||||
TOI->outword(FH, SEG.cmd);
|
outword(FH, SEG.cmd);
|
||||||
TOI->outword(FH, SEG.cmdsize);
|
outword(FH, SEG.cmdsize);
|
||||||
TOI->outstring(FH, SEG.segname, 16);
|
outstring(FH, SEG.segname, 16);
|
||||||
TOI->outaddr(FH, SEG.vmaddr);
|
outaddr(FH, SEG.vmaddr);
|
||||||
TOI->outaddr(FH, SEG.vmsize);
|
outaddr(FH, SEG.vmsize);
|
||||||
TOI->outaddr(FH, SEG.fileoff);
|
outaddr(FH, SEG.fileoff);
|
||||||
TOI->outaddr(FH, SEG.filesize);
|
outaddr(FH, SEG.filesize);
|
||||||
TOI->outword(FH, SEG.maxprot);
|
outword(FH, SEG.maxprot);
|
||||||
TOI->outword(FH, SEG.initprot);
|
outword(FH, SEG.initprot);
|
||||||
TOI->outword(FH, SEG.nsects);
|
outword(FH, SEG.nsects);
|
||||||
TOI->outword(FH, SEG.flags);
|
outword(FH, SEG.flags);
|
||||||
|
|
||||||
// Step #5: Finish filling in the fields of the MachOSections
|
// Step #5: Finish filling in the fields of the MachOSections
|
||||||
uint64_t currentAddr = 0;
|
uint64_t currentAddr = 0;
|
||||||
@@ -511,19 +497,19 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
|
|||||||
currentAddr += MOS->nreloc * 8;
|
currentAddr += MOS->nreloc * 8;
|
||||||
|
|
||||||
// write the finalized section command to the output buffer
|
// write the finalized section command to the output buffer
|
||||||
TOI->outstring(FH, MOS->sectname, 16);
|
outstring(FH, MOS->sectname, 16);
|
||||||
TOI->outstring(FH, MOS->segname, 16);
|
outstring(FH, MOS->segname, 16);
|
||||||
TOI->outaddr(FH, MOS->addr);
|
outaddr(FH, MOS->addr);
|
||||||
TOI->outaddr(FH, MOS->size);
|
outaddr(FH, MOS->size);
|
||||||
TOI->outword(FH, MOS->offset);
|
outword(FH, MOS->offset);
|
||||||
TOI->outword(FH, MOS->align);
|
outword(FH, MOS->align);
|
||||||
TOI->outword(FH, MOS->reloff);
|
outword(FH, MOS->reloff);
|
||||||
TOI->outword(FH, MOS->nreloc);
|
outword(FH, MOS->nreloc);
|
||||||
TOI->outword(FH, MOS->flags);
|
outword(FH, MOS->flags);
|
||||||
TOI->outword(FH, MOS->reserved1);
|
outword(FH, MOS->reserved1);
|
||||||
TOI->outword(FH, MOS->reserved2);
|
outword(FH, MOS->reserved2);
|
||||||
if (is64Bit)
|
if (is64Bit)
|
||||||
TOI->outword(FH, MOS->reserved3);
|
outword(FH, MOS->reserved3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step #7: Emit the symbol table to temporary buffers, so that we know the
|
// Step #7: Emit the symbol table to temporary buffers, so that we know the
|
||||||
@@ -535,36 +521,36 @@ void MachOWriter::EmitHeaderAndLoadCommands() {
|
|||||||
SymTab.nsyms = SymbolTable.size();
|
SymTab.nsyms = SymbolTable.size();
|
||||||
SymTab.stroff = SymTab.symoff + SymT.size();
|
SymTab.stroff = SymTab.symoff + SymT.size();
|
||||||
SymTab.strsize = StrT.size();
|
SymTab.strsize = StrT.size();
|
||||||
TOI->outword(FH, SymTab.cmd);
|
outword(FH, SymTab.cmd);
|
||||||
TOI->outword(FH, SymTab.cmdsize);
|
outword(FH, SymTab.cmdsize);
|
||||||
TOI->outword(FH, SymTab.symoff);
|
outword(FH, SymTab.symoff);
|
||||||
TOI->outword(FH, SymTab.nsyms);
|
outword(FH, SymTab.nsyms);
|
||||||
TOI->outword(FH, SymTab.stroff);
|
outword(FH, SymTab.stroff);
|
||||||
TOI->outword(FH, SymTab.strsize);
|
outword(FH, SymTab.strsize);
|
||||||
|
|
||||||
// FIXME: set DySymTab fields appropriately
|
// FIXME: set DySymTab fields appropriately
|
||||||
// We should probably just update these in BufferSymbolAndStringTable since
|
// We should probably just update these in BufferSymbolAndStringTable since
|
||||||
// thats where we're partitioning up the different kinds of symbols.
|
// thats where we're partitioning up the different kinds of symbols.
|
||||||
TOI->outword(FH, DySymTab.cmd);
|
outword(FH, DySymTab.cmd);
|
||||||
TOI->outword(FH, DySymTab.cmdsize);
|
outword(FH, DySymTab.cmdsize);
|
||||||
TOI->outword(FH, DySymTab.ilocalsym);
|
outword(FH, DySymTab.ilocalsym);
|
||||||
TOI->outword(FH, DySymTab.nlocalsym);
|
outword(FH, DySymTab.nlocalsym);
|
||||||
TOI->outword(FH, DySymTab.iextdefsym);
|
outword(FH, DySymTab.iextdefsym);
|
||||||
TOI->outword(FH, DySymTab.nextdefsym);
|
outword(FH, DySymTab.nextdefsym);
|
||||||
TOI->outword(FH, DySymTab.iundefsym);
|
outword(FH, DySymTab.iundefsym);
|
||||||
TOI->outword(FH, DySymTab.nundefsym);
|
outword(FH, DySymTab.nundefsym);
|
||||||
TOI->outword(FH, DySymTab.tocoff);
|
outword(FH, DySymTab.tocoff);
|
||||||
TOI->outword(FH, DySymTab.ntoc);
|
outword(FH, DySymTab.ntoc);
|
||||||
TOI->outword(FH, DySymTab.modtaboff);
|
outword(FH, DySymTab.modtaboff);
|
||||||
TOI->outword(FH, DySymTab.nmodtab);
|
outword(FH, DySymTab.nmodtab);
|
||||||
TOI->outword(FH, DySymTab.extrefsymoff);
|
outword(FH, DySymTab.extrefsymoff);
|
||||||
TOI->outword(FH, DySymTab.nextrefsyms);
|
outword(FH, DySymTab.nextrefsyms);
|
||||||
TOI->outword(FH, DySymTab.indirectsymoff);
|
outword(FH, DySymTab.indirectsymoff);
|
||||||
TOI->outword(FH, DySymTab.nindirectsyms);
|
outword(FH, DySymTab.nindirectsyms);
|
||||||
TOI->outword(FH, DySymTab.extreloff);
|
outword(FH, DySymTab.extreloff);
|
||||||
TOI->outword(FH, DySymTab.nextrel);
|
outword(FH, DySymTab.nextrel);
|
||||||
TOI->outword(FH, DySymTab.locreloff);
|
outword(FH, DySymTab.locreloff);
|
||||||
TOI->outword(FH, DySymTab.nlocrel);
|
outword(FH, DySymTab.nlocrel);
|
||||||
|
|
||||||
O.write((char*)&FH[0], FH.size());
|
O.write((char*)&FH[0], FH.size());
|
||||||
}
|
}
|
||||||
@@ -641,7 +627,7 @@ void MachOWriter::BufferSymbolAndStringTable() {
|
|||||||
|
|
||||||
// Write out a leading zero byte when emitting string table, for n_strx == 0
|
// Write out a leading zero byte when emitting string table, for n_strx == 0
|
||||||
// which means an empty string.
|
// which means an empty string.
|
||||||
TOI->outbyte(StrT, 0);
|
outbyte(StrT, 0);
|
||||||
|
|
||||||
// The order of the string table is:
|
// The order of the string table is:
|
||||||
// 1. strings for external symbols
|
// 1. strings for external symbols
|
||||||
@@ -654,7 +640,7 @@ void MachOWriter::BufferSymbolAndStringTable() {
|
|||||||
I->n_strx = 0;
|
I->n_strx = 0;
|
||||||
} else {
|
} else {
|
||||||
I->n_strx = StrT.size();
|
I->n_strx = StrT.size();
|
||||||
TOI->outstring(StrT, I->GVName, I->GVName.length()+1);
|
outstring(StrT, I->GVName, I->GVName.length()+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,11 +654,11 @@ void MachOWriter::BufferSymbolAndStringTable() {
|
|||||||
I->n_value += GVSection[GV]->addr;
|
I->n_value += GVSection[GV]->addr;
|
||||||
|
|
||||||
// Emit nlist to buffer
|
// Emit nlist to buffer
|
||||||
TOI->outword(SymT, I->n_strx);
|
outword(SymT, I->n_strx);
|
||||||
TOI->outbyte(SymT, I->n_type);
|
outbyte(SymT, I->n_type);
|
||||||
TOI->outbyte(SymT, I->n_sect);
|
outbyte(SymT, I->n_sect);
|
||||||
TOI->outhalf(SymT, I->n_desc);
|
outhalf(SymT, I->n_desc);
|
||||||
TOI->outaddr(SymT, I->n_value);
|
outaddr(SymT, I->n_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
// This file was developed by Nate Begeman and is distributed under the
|
// This file was developed by Nate Begeman and is distributed under
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
#include "llvm/PassManager.h"
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/CodeGen/MachOWriter.h"
|
#include "llvm/CodeGen/MachOWriter.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -92,10 +91,10 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
MachORelocation VANILLA(MR.getMachineCodeOffset(), To.Index, false, 2,
|
MachORelocation VANILLA(MR.getMachineCodeOffset(), To.Index, false, 2,
|
||||||
isExtern, PPC_RELOC_VANILLA);
|
isExtern, PPC_RELOC_VANILLA);
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
TOI->outword(From.RelocBuffer, VANILLA.r_address);
|
outword(From.RelocBuffer, VANILLA.r_address);
|
||||||
TOI->outword(From.RelocBuffer, VANILLA.getPackedFields());
|
outword(From.RelocBuffer, VANILLA.getPackedFields());
|
||||||
}
|
}
|
||||||
TOI->fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
|
fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
|
||||||
break;
|
break;
|
||||||
case PPC::reloc_pcrel_bx:
|
case PPC::reloc_pcrel_bx:
|
||||||
Addr -= MR.getMachineCodeOffset();
|
Addr -= MR.getMachineCodeOffset();
|
||||||
@@ -103,12 +102,12 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
Addr &= 0xFFFFFF;
|
Addr &= 0xFFFFFF;
|
||||||
Addr <<= 2;
|
Addr <<= 2;
|
||||||
Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
|
Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
|
||||||
TOI->fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
|
fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
|
||||||
break;
|
break;
|
||||||
case PPC::reloc_pcrel_bcx:
|
case PPC::reloc_pcrel_bcx:
|
||||||
Addr -= MR.getMachineCodeOffset();
|
Addr -= MR.getMachineCodeOffset();
|
||||||
Addr &= 0xFFFC;
|
Addr &= 0xFFFC;
|
||||||
TOI->fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
|
fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
case PPC::reloc_absolute_high:
|
case PPC::reloc_absolute_high:
|
||||||
{
|
{
|
||||||
@@ -118,14 +117,14 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
PPC_RELOC_PAIR);
|
PPC_RELOC_PAIR);
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
TOI->outword(From.RelocBuffer, HA16.r_address);
|
outword(From.RelocBuffer, HA16.r_address);
|
||||||
TOI->outword(From.RelocBuffer, HA16.getPackedFields());
|
outword(From.RelocBuffer, HA16.getPackedFields());
|
||||||
TOI->outword(From.RelocBuffer, PAIR.r_address);
|
outword(From.RelocBuffer, PAIR.r_address);
|
||||||
TOI->outword(From.RelocBuffer, PAIR.getPackedFields());
|
outword(From.RelocBuffer, PAIR.getPackedFields());
|
||||||
}
|
}
|
||||||
printf("ha16: %x\n", (unsigned)Addr);
|
printf("ha16: %x\n", (unsigned)Addr);
|
||||||
Addr += 0x8000;
|
Addr += 0x8000;
|
||||||
TOI->fixhalf(From.SectionData, Addr >> 16, MR.getMachineCodeOffset() + 2);
|
fixhalf(From.SectionData, Addr >> 16, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
case PPC::reloc_absolute_low:
|
case PPC::reloc_absolute_low:
|
||||||
{
|
{
|
||||||
@@ -135,13 +134,13 @@ void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
|
|||||||
PPC_RELOC_PAIR);
|
PPC_RELOC_PAIR);
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
++From.nreloc;
|
++From.nreloc;
|
||||||
TOI->outword(From.RelocBuffer, LO16.r_address);
|
outword(From.RelocBuffer, LO16.r_address);
|
||||||
TOI->outword(From.RelocBuffer, LO16.getPackedFields());
|
outword(From.RelocBuffer, LO16.getPackedFields());
|
||||||
TOI->outword(From.RelocBuffer, PAIR.r_address);
|
outword(From.RelocBuffer, PAIR.r_address);
|
||||||
TOI->outword(From.RelocBuffer, PAIR.getPackedFields());
|
outword(From.RelocBuffer, PAIR.getPackedFields());
|
||||||
}
|
}
|
||||||
printf("lo16: %x\n", (unsigned)Addr);
|
printf("lo16: %x\n", (unsigned)Addr);
|
||||||
TOI->fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
|
fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,3 +150,4 @@ MachineRelocation PPCMachOWriter::GetJTRelocation(unsigned Offset,
|
|||||||
// FIXME: do something about PIC
|
// FIXME: do something about PIC
|
||||||
return MachineRelocation::getBB(Offset, PPC::reloc_vanilla, MBB);
|
return MachineRelocation::getBB(Offset, PPC::reloc_vanilla, MBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "PPC.h"
|
#include "PPC.h"
|
||||||
#include "PPCTargetAsmInfo.h"
|
#include "PPCTargetAsmInfo.h"
|
||||||
#include "PPCTargetObjInfo.h"
|
|
||||||
#include "PPCTargetMachine.h"
|
#include "PPCTargetMachine.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/PassManager.h"
|
#include "llvm/PassManager.h"
|
||||||
@@ -35,10 +34,6 @@ const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
|
|||||||
return new LinuxTargetAsmInfo(*this);
|
return new LinuxTargetAsmInfo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TargetObjInfo *PPCTargetMachine::createTargetObjInfo() const {
|
|
||||||
return new MachOTargetObjInfo(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned PPC32TargetMachine::getJITMatchQuality() {
|
unsigned PPC32TargetMachine::getJITMatchQuality() {
|
||||||
#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
|
#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
|
||||||
if (sizeof(void*) == 4)
|
if (sizeof(void*) == 4)
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ class PPCTargetMachine : public LLVMTargetMachine {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const TargetAsmInfo *createTargetAsmInfo() const;
|
virtual const TargetAsmInfo *createTargetAsmInfo() const;
|
||||||
virtual const TargetObjInfo *createTargetObjInfo() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PPCTargetMachine(const Module &M, const std::string &FS, bool is64Bit);
|
PPCTargetMachine(const Module &M, const std::string &FS, bool is64Bit);
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
//===-- PPCTargetObjInfo.cpp - Object File Info ----------------------------==//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file was developed by Bill Wendling and is distributed under the
|
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file defines target object file properties for PowerPC.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "PPCTargetObjInfo.h"
|
|
||||||
#include "llvm/Target/TargetData.h"
|
|
||||||
#include "llvm/Target/TargetMachine.h"
|
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
MachOTargetObjInfo::MachOTargetObjInfo(const TargetMachine &tm)
|
|
||||||
: TM(tm),
|
|
||||||
is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64),
|
|
||||||
isLittleEndian(TM.getTargetData()->isLittleEndian()) {}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
//===-- PPCTargetObjInfo.h - Object File Info --------------------*- C++ -*-==//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file was developed by Bill Wendling and is distributed under the
|
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file defines target object file properties for PowerPC.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#ifndef PPCTARGETOBJINFO_H
|
|
||||||
#define PPCTARGETOBJINFO_H
|
|
||||||
|
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
class TargetMachine;
|
|
||||||
|
|
||||||
struct MachOTargetObjInfo : public TargetObjInfo {
|
|
||||||
MachOTargetObjInfo(const TargetMachine &PPC_TM);
|
|
||||||
|
|
||||||
// align - Emit padding into the file until the current output position is
|
|
||||||
// aligned to the specified power of two boundary.
|
|
||||||
virtual void align(DataBuffer &Output, unsigned Boundary) const {
|
|
||||||
assert(Boundary && (Boundary & (Boundary-1)) == 0 &&
|
|
||||||
"Must align to 2^k boundary");
|
|
||||||
size_t Size = Output.size();
|
|
||||||
|
|
||||||
if (Size & (Boundary-1)) {
|
|
||||||
// Add padding to get alignment to the correct place.
|
|
||||||
size_t Pad = Boundary - (Size & (Boundary - 1));
|
|
||||||
Output.resize(Size + Pad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Out Functions - Output the specified value to the data buffer.
|
|
||||||
|
|
||||||
virtual void outbyte(DataBuffer &Output, unsigned char X) const {
|
|
||||||
Output.push_back(X);
|
|
||||||
}
|
|
||||||
virtual void outhalf(DataBuffer &Output, unsigned short X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back(X & 255);
|
|
||||||
Output.push_back(X >> 8);
|
|
||||||
} else {
|
|
||||||
Output.push_back(X >> 8);
|
|
||||||
Output.push_back(X & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outword(DataBuffer &Output, unsigned X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back((X >> 0) & 255);
|
|
||||||
Output.push_back((X >> 8) & 255);
|
|
||||||
Output.push_back((X >> 16) & 255);
|
|
||||||
Output.push_back((X >> 24) & 255);
|
|
||||||
} else {
|
|
||||||
Output.push_back((X >> 24) & 255);
|
|
||||||
Output.push_back((X >> 16) & 255);
|
|
||||||
Output.push_back((X >> 8) & 255);
|
|
||||||
Output.push_back((X >> 0) & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outxword(DataBuffer &Output, uint64_t X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back(unsigned(X >> 0) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 8) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 16) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 24) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 32) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 40) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 48) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 56) & 255);
|
|
||||||
} else {
|
|
||||||
Output.push_back(unsigned(X >> 56) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 48) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 40) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 32) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 24) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 16) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 8) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 0) & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outaddr32(DataBuffer &Output, unsigned X) const {
|
|
||||||
outword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outaddr64(DataBuffer &Output, uint64_t X) const {
|
|
||||||
outxword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outaddr(DataBuffer &Output, uint64_t X) const {
|
|
||||||
if (!is64Bit)
|
|
||||||
outword(Output, (unsigned)X);
|
|
||||||
else
|
|
||||||
outxword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outstring(DataBuffer &Output, std::string &S,
|
|
||||||
unsigned Length) const {
|
|
||||||
unsigned len_to_copy = S.length() < Length ? S.length() : Length;
|
|
||||||
unsigned len_to_fill = S.length() < Length ? Length-S.length() : 0;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < len_to_copy; ++i)
|
|
||||||
outbyte(Output, S[i]);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < len_to_fill; ++i)
|
|
||||||
outbyte(Output, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Fix Functions - Replace an existing entry at an offset.
|
|
||||||
|
|
||||||
virtual void fixhalf(DataBuffer &Output, unsigned short X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
unsigned char *P = &Output[Offset];
|
|
||||||
P[0] = (X >> (isLittleEndian ? 0 : 8)) & 255;
|
|
||||||
P[1] = (X >> (isLittleEndian ? 8 : 0)) & 255;
|
|
||||||
}
|
|
||||||
virtual void fixword(DataBuffer &Output, unsigned X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
unsigned char *P = &Output[Offset];
|
|
||||||
P[0] = (X >> (isLittleEndian ? 0 : 24)) & 255;
|
|
||||||
P[1] = (X >> (isLittleEndian ? 8 : 16)) & 255;
|
|
||||||
P[2] = (X >> (isLittleEndian ? 16 : 8)) & 255;
|
|
||||||
P[3] = (X >> (isLittleEndian ? 24 : 0)) & 255;
|
|
||||||
}
|
|
||||||
virtual void fixaddr(DataBuffer &Output, uint64_t X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
// Not implemented
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
/// Target machine description.
|
|
||||||
const TargetMachine &TM;
|
|
||||||
|
|
||||||
/// is64Bit/isLittleEndian - This information is inferred from the target
|
|
||||||
/// machine directly, indicating what header values and flags to set.
|
|
||||||
bool is64Bit, isLittleEndian;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end llvm namespace
|
|
||||||
|
|
||||||
#endif // PPCTARGETOBJINFO_H
|
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "llvm/Target/TargetAsmInfo.h"
|
#include "llvm/Target/TargetAsmInfo.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -105,7 +104,6 @@ namespace {
|
|||||||
|
|
||||||
TargetMachine::~TargetMachine() {
|
TargetMachine::~TargetMachine() {
|
||||||
delete AsmInfo;
|
delete AsmInfo;
|
||||||
delete ObjInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getRelocationModel - Returns the code generation relocation model. The
|
/// getRelocationModel - Returns the code generation relocation model. The
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "X86TargetAsmInfo.h"
|
#include "X86TargetAsmInfo.h"
|
||||||
#include "X86TargetObjInfo.h"
|
|
||||||
#include "X86TargetMachine.h"
|
#include "X86TargetMachine.h"
|
||||||
#include "X86.h"
|
#include "X86.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
@@ -43,10 +42,6 @@ const TargetAsmInfo *X86TargetMachine::createTargetAsmInfo() const {
|
|||||||
return new X86TargetAsmInfo(*this);
|
return new X86TargetAsmInfo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TargetObjInfo *X86TargetMachine::createTargetObjInfo() const {
|
|
||||||
return new ELFTargetObjInfo(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned X86_32TargetMachine::getJITMatchQuality() {
|
unsigned X86_32TargetMachine::getJITMatchQuality() {
|
||||||
#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
|
#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
|
||||||
return 10;
|
return 10;
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class X86TargetMachine : public LLVMTargetMachine {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const TargetAsmInfo *createTargetAsmInfo() const;
|
virtual const TargetAsmInfo *createTargetAsmInfo() const;
|
||||||
virtual const TargetObjInfo *createTargetObjInfo() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
X86TargetMachine(const Module &M, const std::string &FS, bool is64Bit);
|
X86TargetMachine(const Module &M, const std::string &FS, bool is64Bit);
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
//===-- X86TargetObjInfo.cpp - Object File Info ----------------------------==//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file was developed by Bill Wendling and is distributed under the
|
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file defines target object file properties for X86
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#include "X86TargetObjInfo.h"
|
|
||||||
#include "llvm/Target/TargetData.h"
|
|
||||||
#include "llvm/Target/TargetMachine.h"
|
|
||||||
using namespace llvm;
|
|
||||||
|
|
||||||
ELFTargetObjInfo::ELFTargetObjInfo(const TargetMachine &tm)
|
|
||||||
: TM(tm),
|
|
||||||
is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64),
|
|
||||||
isLittleEndian(TM.getTargetData()->isLittleEndian()) {}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
//===-- X86TargetObjInfo.h - Object File Info --------------------*- C++ -*-==//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file was developed by Bill Wendling and is distributed under the
|
|
||||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This file defines target object file properties for X86
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#ifndef X86TARGETOBJINFO_H
|
|
||||||
#define X86TARGETOBJINFO_H
|
|
||||||
|
|
||||||
#include "llvm/Target/TargetObjInfo.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
class TargetMachine;
|
|
||||||
|
|
||||||
struct ELFTargetObjInfo : public TargetObjInfo {
|
|
||||||
ELFTargetObjInfo(const TargetMachine &tm);
|
|
||||||
|
|
||||||
// align - Emit padding into the file until the current output position is
|
|
||||||
// aligned to the specified power of two boundary.
|
|
||||||
virtual void align(DataBuffer &Output, unsigned Boundary) const {
|
|
||||||
assert(Boundary && (Boundary & (Boundary - 1)) == 0 &&
|
|
||||||
"Must align to 2^k boundary");
|
|
||||||
size_t Size = Output.size();
|
|
||||||
|
|
||||||
if (Size & (Boundary - 1)) {
|
|
||||||
// Add padding to get alignment to the correct place.
|
|
||||||
size_t Pad = Boundary - (Size & (Boundary - 1));
|
|
||||||
Output.resize(Size + Pad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Out Functions - Output the specified value to the data buffer.
|
|
||||||
|
|
||||||
virtual void outbyte(DataBuffer &Output, unsigned char X) const {
|
|
||||||
Output.push_back(X);
|
|
||||||
}
|
|
||||||
virtual void outhalf(DataBuffer &Output, unsigned short X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back(X & 255);
|
|
||||||
Output.push_back(X >> 8);
|
|
||||||
} else {
|
|
||||||
Output.push_back(X >> 8);
|
|
||||||
Output.push_back(X & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outword(DataBuffer &Output, unsigned X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back((X >> 0) & 255);
|
|
||||||
Output.push_back((X >> 8) & 255);
|
|
||||||
Output.push_back((X >> 16) & 255);
|
|
||||||
Output.push_back((X >> 24) & 255);
|
|
||||||
} else {
|
|
||||||
Output.push_back((X >> 24) & 255);
|
|
||||||
Output.push_back((X >> 16) & 255);
|
|
||||||
Output.push_back((X >> 8) & 255);
|
|
||||||
Output.push_back((X >> 0) & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outxword(DataBuffer &Output, uint64_t X) const {
|
|
||||||
if (isLittleEndian) {
|
|
||||||
Output.push_back(unsigned(X >> 0) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 8) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 16) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 24) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 32) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 40) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 48) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 56) & 255);
|
|
||||||
} else {
|
|
||||||
Output.push_back(unsigned(X >> 56) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 48) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 40) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 32) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 24) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 16) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 8) & 255);
|
|
||||||
Output.push_back(unsigned(X >> 0) & 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void outaddr32(DataBuffer &Output, unsigned X) const {
|
|
||||||
outword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outaddr64(DataBuffer &Output, uint64_t X) const {
|
|
||||||
outxword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outaddr(DataBuffer &Output, uint64_t X) const {
|
|
||||||
if (!is64Bit)
|
|
||||||
outword(Output, (unsigned)X);
|
|
||||||
else
|
|
||||||
outxword(Output, X);
|
|
||||||
}
|
|
||||||
virtual void outstring(DataBuffer &Output, std::string &S,
|
|
||||||
unsigned Length) const {
|
|
||||||
// Not implemented
|
|
||||||
}
|
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
// Fix Functions - Replace an existing entry at an offset.
|
|
||||||
|
|
||||||
virtual void fixhalf(DataBuffer &Output, unsigned short X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
unsigned char *P = &Output[Offset];
|
|
||||||
P[0] = (X >> (isLittleEndian ? 0 : 8)) & 255;
|
|
||||||
P[1] = (X >> (isLittleEndian ? 8 : 0)) & 255;
|
|
||||||
}
|
|
||||||
virtual void fixword(DataBuffer &Output, unsigned X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
unsigned char *P = &Output[Offset];
|
|
||||||
P[0] = (X >> (isLittleEndian ? 0 : 24)) & 255;
|
|
||||||
P[1] = (X >> (isLittleEndian ? 8 : 16)) & 255;
|
|
||||||
P[2] = (X >> (isLittleEndian ? 16 : 8)) & 255;
|
|
||||||
P[3] = (X >> (isLittleEndian ? 24 : 0)) & 255;
|
|
||||||
}
|
|
||||||
virtual void fixaddr(DataBuffer &Output, uint64_t X,
|
|
||||||
unsigned Offset) const {
|
|
||||||
if (!is64Bit)
|
|
||||||
fixword(Output, (unsigned)X, Offset);
|
|
||||||
else
|
|
||||||
assert(0 && "Emission of 64-bit data not implemented yet!");
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
/// Target machine description.
|
|
||||||
const TargetMachine &TM;
|
|
||||||
|
|
||||||
/// is64Bit/isLittleEndian - This information is inferred from the target
|
|
||||||
/// machine directly, indicating what header values and flags to set.
|
|
||||||
bool is64Bit, isLittleEndian;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end llvm namespace
|
|
||||||
|
|
||||||
#endif // X86TARGETOBJINFO_H
|
|
||||||
Reference in New Issue
Block a user