MCELFObjectWriter.h revision 69bbda03918a18bd4477bb254d51346ee3033567
1//===-- llvm/MC/MCELFObjectWriter.h - ELF Object Writer ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_MC_MCELFOBJECTWRITER_H 11#define LLVM_MC_MCELFOBJECTWRITER_H 12 13#include "llvm/MC/MCObjectWriter.h" 14#include "llvm/Support/DataTypes.h" 15#include "llvm/Support/ELF.h" 16 17namespace llvm { 18class MCELFObjectTargetWriter { 19 const uint8_t OSABI; 20 const uint16_t EMachine; 21 const unsigned HasRelocationAddend : 1; 22 const unsigned Is64Bit : 1; 23 24protected: 25 26 MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_, 27 uint16_t EMachine_, bool HasRelocationAddend_); 28 29public: 30 static uint8_t getOSABI(Triple::OSType OSType) { 31 switch (OSType) { 32 case Triple::FreeBSD: 33 return ELF::ELFOSABI_FREEBSD; 34 case Triple::Linux: 35 return ELF::ELFOSABI_LINUX; 36 default: 37 return ELF::ELFOSABI_NONE; 38 } 39 } 40 41 virtual ~MCELFObjectTargetWriter(); 42 43 virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, 44 bool IsPCRel, bool IsRelocWithSymbol, 45 int64_t Addend) const; // FIXME: add = 0 46 virtual unsigned getEFlags() const; 47 virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, 48 const MCValue &Target, 49 const MCFragment &F, 50 const MCFixup &Fixup, 51 bool IsPCRel) const; 52 53 /// @name Accessors 54 /// @{ 55 uint8_t getOSABI() { return OSABI; } 56 uint16_t getEMachine() { return EMachine; } 57 bool hasRelocationAddend() { return HasRelocationAddend; } 58 bool is64Bit() const { return Is64Bit; } 59 /// @} 60}; 61 62/// \brief Construct a new ELF writer instance. 63/// 64/// \param MOTW - The target specific ELF writer subclass. 65/// \param OS - The stream to write to. 66/// \returns The constructed object writer. 67MCObjectWriter *createELFObjectWriter(MCELFObjectTargetWriter *MOTW, 68 raw_ostream &OS, bool IsLittleEndian); 69} // End llvm namespace 70 71#endif 72