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;
32 bool is64Bit, isLittleEndian;
35 // Machine architectures
37 EM_NONE = 0, // No machine
38 EM_M32 = 1, // AT&T WE 32100
39 EM_SPARC = 2, // SPARC
40 EM_386 = 3, // Intel 386
41 EM_68K = 4, // Motorola 68000
42 EM_88K = 5, // Motorola 88000
43 EM_486 = 6, // Intel 486 (deprecated)
44 EM_860 = 7, // Intel 80860
45 EM_MIPS = 8, // MIPS R3000
46 EM_PPC = 20, // PowerPC
48 EM_ALPHA = 41, // DEC Alpha
49 EM_SPARCV9 = 43, // SPARC V9
50 EM_X86_64 = 62 // AMD64
55 ELFCLASS32 = 1, // 32-bit object file
56 ELFCLASS64 = 2 // 64-bit object file
61 ELFDATA2LSB = 1, // Little-endian object file
62 ELFDATA2MSB = 2 // Big-endian object file
65 explicit TargetELFWriterInfo(TargetMachine &tm);
66 virtual ~TargetELFWriterInfo();
68 unsigned short getEMachine() const { return EMachine; }
69 unsigned getEFlags() const { return 0; }
70 unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
71 unsigned getEIData() const {
72 return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
75 /// ELF Header and ELF Section Header Info
76 unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
77 unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
80 unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
82 /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
83 /// is used to align some sections.
84 unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
86 /// getRelocationEntrySize - Entry size used in the relocation section
87 unsigned getRelocationEntrySize() const {
88 return is64Bit ? (hasRelocationAddend() ? 24 : 16)
89 : (hasRelocationAddend() ? 12 : 8);
92 /// getRelocationType - Returns the target specific ELF Relocation type.
93 /// 'MachineRelTy' contains the object code independent relocation type
94 virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
96 /// hasRelocationAddend - True if the target uses an addend in the
97 /// ELF relocation entry.
98 virtual bool hasRelocationAddend() const = 0;
100 /// getDefaultAddendForRelTy - Gets the default addend value for a
101 /// relocation entry based on the target ELF relocation type.
102 virtual long int getDefaultAddendForRelTy(unsigned RelTy,
103 long int Modifier = 0) const = 0;
105 /// getRelTySize - Returns the size of relocatable field in bits
106 virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
108 /// isPCRelativeRel - True if the relocation type is pc relative
109 virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
111 /// getJumpTableRelocationTy - Returns the machine relocation type used
112 /// to reference a jumptable.
113 virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
115 /// computeRelocation - Some relocatable fields could be relocated
116 /// directly, avoiding the relocation symbol emission, compute the
117 /// final relocation value for this symbol.
118 virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
119 unsigned RelTy) const = 0;
122 } // end llvm namespace
124 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H