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