MCELFObjectWriter.h revision edae8e1e4d5bd9b59f18ecef04a248be95d8ca46
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 47 /// @name Accessors 48 /// @{ 49 uint8_t getOSABI() { return OSABI; } 50 uint16_t getEMachine() { return EMachine; } 51 bool hasRelocationAddend() { return HasRelocationAddend; } 52 bool is64Bit() const { return Is64Bit; } 53 /// @} 54}; 55 56/// \brief Construct a new ELF writer instance. 57/// 58/// \param MOTW - The target specific ELF writer subclass. 59/// \param OS - The stream to write to. 60/// \returns The constructed object writer. 61MCObjectWriter *createELFObjectWriter(MCELFObjectTargetWriter *MOTW, 62 raw_ostream &OS, bool IsLittleEndian); 63} // End llvm namespace 64 65#endif 66