forked from OSchip/llvm-project
parent
d1154860a4
commit
2a562ba47b
|
@ -14,6 +14,7 @@
|
||||||
#ifndef LLVM_CODEGEN_MACHOWRITER_H
|
#ifndef LLVM_CODEGEN_MACHOWRITER_H
|
||||||
#define LLVM_CODEGEN_MACHOWRITER_H
|
#define LLVM_CODEGEN_MACHOWRITER_H
|
||||||
|
|
||||||
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/CodeGen/MachineRelocation.h"
|
#include "llvm/CodeGen/MachineRelocation.h"
|
||||||
|
@ -486,8 +487,13 @@ namespace llvm {
|
||||||
MachOSection *getDataSection() {
|
MachOSection *getDataSection() {
|
||||||
return getSection("__DATA", "__data");
|
return getSection("__DATA", "__data");
|
||||||
}
|
}
|
||||||
MachOSection *getConstSection(const Type *Ty) {
|
MachOSection *getConstSection(Constant *C) {
|
||||||
// FIXME: support cstring literals and pointer literal
|
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
||||||
|
if (CVA && CVA->isCString())
|
||||||
|
return getSection("__TEXT", "__cstring",
|
||||||
|
MachOSection::S_CSTRING_LITERALS);
|
||||||
|
|
||||||
|
const Type *Ty = C->getType();
|
||||||
if (Ty->isPrimitiveType() || Ty->isInteger()) {
|
if (Ty->isPrimitiveType() || Ty->isInteger()) {
|
||||||
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
||||||
switch(Size) {
|
switch(Size) {
|
||||||
|
|
|
@ -245,7 +245,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
||||||
const Type *Ty = CP[i].getType();
|
const Type *Ty = CP[i].getType();
|
||||||
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
unsigned Size = TM.getTargetData()->getTypeSize(Ty);
|
||||||
|
|
||||||
MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty);
|
MachOWriter::MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal);
|
||||||
OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
|
OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
|
||||||
|
|
||||||
CPLocations.push_back(Sec->SectionData.size());
|
CPLocations.push_back(Sec->SectionData.size());
|
||||||
|
@ -390,7 +390,8 @@ void MachOWriter::EmitGlobal(GlobalVariable *GV) {
|
||||||
// Scalar read-only data goes in a literal section if the scalar is 4, 8, or
|
// Scalar read-only data goes in a literal section if the scalar is 4, 8, or
|
||||||
// 16 bytes, or a cstring. Other read only data goes into a regular const
|
// 16 bytes, or a cstring. Other read only data goes into a regular const
|
||||||
// section. Read-write data goes in the data section.
|
// section. Read-write data goes in the data section.
|
||||||
MachOSection *Sec = GV->isConstant() ? getConstSection(Ty) : getDataSection();
|
MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) :
|
||||||
|
getDataSection();
|
||||||
AddSymbolToSection(Sec, GV);
|
AddSymbolToSection(Sec, GV);
|
||||||
InitMem(GV->getInitializer(), &Sec->SectionData[0], GVOffset[GV],
|
InitMem(GV->getInitializer(), &Sec->SectionData[0], GVOffset[GV],
|
||||||
TM.getTargetData(), Sec->Relocations);
|
TM.getTargetData(), Sec->Relocations);
|
||||||
|
@ -716,7 +717,11 @@ void MachOWriter::CalculateRelocations(MachOSection &MOS) {
|
||||||
intptr_t Offset = GVOffset[GV];
|
intptr_t Offset = GVOffset[GV];
|
||||||
Scattered = TargetSection != 0;
|
Scattered = TargetSection != 0;
|
||||||
|
|
||||||
assert(MOSPtr && "Trying to relocate unknown global!");
|
if (!MOSPtr) {
|
||||||
|
cerr << "Trying to relocate unknown global " << *GV << '\n';
|
||||||
|
continue;
|
||||||
|
//abort();
|
||||||
|
}
|
||||||
|
|
||||||
TargetSection = MOSPtr->Index;
|
TargetSection = MOSPtr->Index;
|
||||||
MR.setResultPointer((void*)Offset);
|
MR.setResultPointer((void*)Offset);
|
||||||
|
|
Loading…
Reference in New Issue