LLVM API Documentation
00001 //===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the TargetELFWriterInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H 00015 #define LLVM_TARGET_TARGETELFWRITERINFO_H 00016 00017 namespace llvm { 00018 class Function; 00019 class TargetData; 00020 class TargetMachine; 00021 00022 //===--------------------------------------------------------------------===// 00023 // TargetELFWriterInfo 00024 //===--------------------------------------------------------------------===// 00025 00026 class TargetELFWriterInfo { 00027 protected: 00028 // EMachine - This field is the target specific value to emit as the 00029 // e_machine member of the ELF header. 00030 unsigned short EMachine; 00031 TargetMachine &TM; 00032 bool is64Bit, isLittleEndian; 00033 public: 00034 00035 // Machine architectures 00036 enum MachineType { 00037 EM_NONE = 0, // No machine 00038 EM_M32 = 1, // AT&T WE 32100 00039 EM_SPARC = 2, // SPARC 00040 EM_386 = 3, // Intel 386 00041 EM_68K = 4, // Motorola 68000 00042 EM_88K = 5, // Motorola 88000 00043 EM_486 = 6, // Intel 486 (deprecated) 00044 EM_860 = 7, // Intel 80860 00045 EM_MIPS = 8, // MIPS R3000 00046 EM_PPC = 20, // PowerPC 00047 EM_ARM = 40, // ARM 00048 EM_ALPHA = 41, // DEC Alpha 00049 EM_SPARCV9 = 43, // SPARC V9 00050 EM_X86_64 = 62 // AMD64 00051 }; 00052 00053 // ELF File classes 00054 enum { 00055 ELFCLASS32 = 1, // 32-bit object file 00056 ELFCLASS64 = 2 // 64-bit object file 00057 }; 00058 00059 // ELF Endianess 00060 enum { 00061 ELFDATA2LSB = 1, // Little-endian object file 00062 ELFDATA2MSB = 2 // Big-endian object file 00063 }; 00064 00065 explicit TargetELFWriterInfo(TargetMachine &tm); 00066 virtual ~TargetELFWriterInfo(); 00067 00068 unsigned short getEMachine() const { return EMachine; } 00069 unsigned getEFlags() const { return 0; } 00070 unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; } 00071 unsigned getEIData() const { 00072 return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB; 00073 } 00074 00075 /// ELF Header and ELF Section Header Info 00076 unsigned getHdrSize() const { return is64Bit ? 64 : 52; } 00077 unsigned getSHdrSize() const { return is64Bit ? 64 : 40; } 00078 00079 /// Symbol Table Info 00080 unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; } 00081 00082 /// getPrefELFAlignment - Returns the preferred alignment for ELF. This 00083 /// is used to align some sections. 00084 unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; } 00085 00086 /// getRelocationEntrySize - Entry size used in the relocation section 00087 unsigned getRelocationEntrySize() const { 00088 return is64Bit ? (hasRelocationAddend() ? 24 : 16) 00089 : (hasRelocationAddend() ? 12 : 8); 00090 } 00091 00092 /// getRelocationType - Returns the target specific ELF Relocation type. 00093 /// 'MachineRelTy' contains the object code independent relocation type 00094 virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0; 00095 00096 /// hasRelocationAddend - True if the target uses an addend in the 00097 /// ELF relocation entry. 00098 virtual bool hasRelocationAddend() const = 0; 00099 00100 /// getDefaultAddendForRelTy - Gets the default addend value for a 00101 /// relocation entry based on the target ELF relocation type. 00102 virtual long int getDefaultAddendForRelTy(unsigned RelTy, 00103 long int Modifier = 0) const = 0; 00104 00105 /// getRelTySize - Returns the size of relocatable field in bits 00106 virtual unsigned getRelocationTySize(unsigned RelTy) const = 0; 00107 00108 /// isPCRelativeRel - True if the relocation type is pc relative 00109 virtual bool isPCRelativeRel(unsigned RelTy) const = 0; 00110 00111 /// getJumpTableRelocationTy - Returns the machine relocation type used 00112 /// to reference a jumptable. 00113 virtual unsigned getAbsoluteLabelMachineRelTy() const = 0; 00114 00115 /// computeRelocation - Some relocatable fields could be relocated 00116 /// directly, avoiding the relocation symbol emission, compute the 00117 /// final relocation value for this symbol. 00118 virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset, 00119 unsigned RelTy) const = 0; 00120 }; 00121 00122 } // end llvm namespace 00123 00124 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H