X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FELFWriter.cpp;h=27f23f45cc0677af6a4466367e17eee8cb30e127;hb=5ac319ac7125b009adddcc49294d2e040c4a91e5;hp=3b9653740cc02d47419f3b286f5342569902fc83;hpb=58092e35a3368e130438cbc793c8f9dce2e4fe0f;p=oota-llvm.git diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 3b9653740cc..27f23f45cc0 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Chris Lattner and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -31,17 +31,33 @@ // //===----------------------------------------------------------------------===// -#include "llvm/CodeGen/ELFWriter.h" +#include "ELFWriter.h" #include "llvm/Module.h" +#include "llvm/PassManager.h" +#include "llvm/CodeGen/FileWriters.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/MachineConstantPool.h" +#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetELFWriterInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/OutputBuffer.h" #include "llvm/Support/Streams.h" +#include using namespace llvm; +char ELFWriter::ID = 0; +/// AddELFWriter - Concrete function to add the ELF writer to the function pass +/// manager. +MachineCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM, + std::ostream &O, + TargetMachine &TM) { + ELFWriter *EW = new ELFWriter(O, TM); + PM.add(EW); + return &EW->getMachineCodeEmitter(); +} + //===----------------------------------------------------------------------===// // ELFCodeEmitter Implementation //===----------------------------------------------------------------------===// @@ -56,7 +72,7 @@ namespace llvm { std::vector *OutBuffer; size_t FnStart; public: - ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM), OutBuffer(0) {} + explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM), OutBuffer(0) {} void startFunction(MachineFunction &F); bool finishFunction(MachineFunction &F); @@ -82,12 +98,28 @@ namespace llvm { return 0; } + virtual intptr_t getLabelAddress(uint64_t Label) const { + assert(0 && "Label address not implementated yet!"); + abort(); + return 0; + } + + virtual void emitLabel(uint64_t LabelID) { + assert(0 && "emit Label not implementated yet!"); + abort(); + } + + + virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { } + + /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! - void startFunctionStub(unsigned StubSize, unsigned Alignment = 1) { + void startFunctionStub(const GlobalValue* F, unsigned StubSize, + unsigned Alignment = 1) { assert(0 && "JIT specific function called!"); abort(); } - void *finishFunctionStub(const Function *F) { + void *finishFunctionStub(const GlobalValue *F) { assert(0 && "JIT specific function called!"); abort(); return 0; @@ -161,8 +193,8 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) { // ELFWriter Implementation //===----------------------------------------------------------------------===// -ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) { - e_machine = 0; // e_machine defaults to 'No Machine' +ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) + : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) { e_flags = 0; // e_flags defaults to 0, no flags. is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; @@ -197,7 +229,7 @@ bool ELFWriter::doInitialization(Module &M) { // This should change for shared objects. FHOut.outhalf(1); // e_type = ET_REL - FHOut.outhalf(e_machine); // e_machine = whatever the target wants + FHOut.outhalf(TM.getELFWriterInfo()->getEMachine()); // target-defined FHOut.outword(1); // e_version = 1 FHOut.outaddr(0); // e_entry = 0 -> no entry point in .o file FHOut.outaddr(0); // e_phoff = 0 -> no program header for .o @@ -241,8 +273,8 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) { } const Type *GVType = (const Type*)GV->getType(); - unsigned Align = TM.getTargetData()->getTypeAlignmentPref(GVType); - unsigned Size = TM.getTargetData()->getTypeSize(GVType); + unsigned Align = TM.getTargetData()->getPreferredAlignment(GV); + unsigned Size = TM.getTargetData()->getABITypeSize(GVType); // If this global has a zero initializer, it is part of the .bss or common // section. @@ -250,7 +282,8 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) { // If this global is part of the common block, add it now. Variables are // part of the common block if they are zero initialized and allowed to be // merged with other symbols. - if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage()) { + if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() || + GV->hasCommonLinkage()) { ELFSym CommonSym(GV); // Value for common symbols is the alignment required. CommonSym.Value = Align; @@ -281,7 +314,7 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) { BSSSym.SetType(ELFSym::STT_OBJECT); switch (GV->getLinkage()) { - default: // weak/linkonce handled above + default: // weak/linkonce/common handled above assert(0 && "Unexpected linkage type!"); case GlobalValue::AppendingLinkage: // FIXME: This should be improved! case GlobalValue::ExternalLinkage: