1 //===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the TargetELFWriterInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H
15 #define LLVM_TARGET_TARGETELFWRITERINFO_H
22 //===--------------------------------------------------------------------===//
23 // TargetELFWriterInfo
24 //===--------------------------------------------------------------------===//
26 class TargetELFWriterInfo {
28 // EMachine - This field is the target specific value to emit as the
29 // e_machine member of the ELF header.
30 unsigned short EMachine;
31 bool is64Bit, isLittleEndian;
34 // Machine architectures
36 EM_NONE = 0, // No machine
37 EM_M32 = 1, // AT&T WE 32100
38 EM_SPARC = 2, // SPARC
39 EM_386 = 3, // Intel 386
40 EM_68K = 4, // Motorola 68000
41 EM_88K = 5, // Motorola 88000
42 EM_486 = 6, // Intel 486 (deprecated)
43 EM_860 = 7, // Intel 80860
44 EM_MIPS = 8, // MIPS R3000
45 EM_PPC = 20, // PowerPC
47 EM_ALPHA = 41, // DEC Alpha
48 EM_SPARCV9 = 43, // SPARC V9
49 EM_X86_64 = 62 // AMD64
54 ELFCLASS32 = 1, // 32-bit object file
55 ELFCLASS64 = 2 // 64-bit object file
60 ELFDATA2LSB = 1, // Little-endian object file
61 ELFDATA2MSB = 2 // Big-endian object file
64 explicit TargetELFWriterInfo(bool is64Bit_, bool isLittleEndian_);
65 virtual ~TargetELFWriterInfo();
67 unsigned short getEMachine() const { return EMachine; }
68 unsigned getEFlags() const { return 0; }
69 unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
70 unsigned getEIData() const {
71 return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
74 /// ELF Header and ELF Section Header Info
75 unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
76 unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
79 unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
81 /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
82 /// is used to align some sections.
83 unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
85 /// getRelocationEntrySize - Entry size used in the relocation section
86 unsigned getRelocationEntrySize() const {
87 return is64Bit ? (hasRelocationAddend() ? 24 : 16)
88 : (hasRelocationAddend() ? 12 : 8);
91 /// getRelocationType - Returns the target specific ELF Relocation type.
92 /// 'MachineRelTy' contains the object code independent relocation type
93 virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
95 /// hasRelocationAddend - True if the target uses an addend in the
96 /// ELF relocation entry.
97 virtual bool hasRelocationAddend() const = 0;
99 /// getDefaultAddendForRelTy - Gets the default addend value for a
100 /// relocation entry based on the target ELF relocation type.
101 virtual long int getDefaultAddendForRelTy(unsigned RelTy,
102 long int Modifier = 0) const = 0;
104 /// getRelTySize - Returns the size of relocatable field in bits
105 virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
107 /// isPCRelativeRel - True if the relocation type is pc relative
108 virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
110 /// getJumpTableRelocationTy - Returns the machine relocation type used
111 /// to reference a jumptable.
112 virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
114 /// computeRelocation - Some relocatable fields could be relocated
115 /// directly, avoiding the relocation symbol emission, compute the
116 /// final relocation value for this symbol.
117 virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
118 unsigned RelTy) const = 0;
121 } // end llvm namespace
123 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H