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
47 EM_HEXAGON = 164 // Qualcomm Hexagon
52 ELFCLASS32 = 1, // 32-bit object file
53 ELFCLASS64 = 2 // 64-bit object file
58 ELFDATA2LSB = 1, // Little-endian object file
59 ELFDATA2MSB = 2 // Big-endian object file
62 explicit TargetELFWriterInfo(bool is64Bit_, bool isLittleEndian_);
63 virtual ~TargetELFWriterInfo();
65 unsigned short getEMachine() const { return EMachine; }
66 unsigned getEFlags() const { return 0; }
67 unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
68 unsigned getEIData() const {
69 return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
72 /// ELF Header and ELF Section Header Info
73 unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
74 unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
77 unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
79 /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
80 /// is used to align some sections.
81 unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
83 /// getRelocationEntrySize - Entry size used in the relocation section
84 unsigned getRelocationEntrySize() const {
85 return is64Bit ? (hasRelocationAddend() ? 24 : 16)
86 : (hasRelocationAddend() ? 12 : 8);
89 /// getRelocationType - Returns the target specific ELF Relocation type.
90 /// 'MachineRelTy' contains the object code independent relocation type
91 virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
93 /// hasRelocationAddend - True if the target uses an addend in the
94 /// ELF relocation entry.
95 virtual bool hasRelocationAddend() const = 0;
97 /// getDefaultAddendForRelTy - Gets the default addend value for a
98 /// relocation entry based on the target ELF relocation type.
99 virtual long int getDefaultAddendForRelTy(unsigned RelTy,
100 long int Modifier = 0) const = 0;
102 /// getRelTySize - Returns the size of relocatable field in bits
103 virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
105 /// isPCRelativeRel - True if the relocation type is pc relative
106 virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
108 /// getJumpTableRelocationTy - Returns the machine relocation type used
109 /// to reference a jumptable.
110 virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
112 /// computeRelocation - Some relocatable fields could be relocated
113 /// directly, avoiding the relocation symbol emission, compute the
114 /// final relocation value for this symbol.
115 virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
116 unsigned RelTy) const = 0;
119 } // end llvm namespace
121 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H