ef3ca1c4fc4eeb05a87e90bdaa898122f4a4c3a4
[oota-llvm.git] / include / llvm / Target / TargetELFWriterInfo.h
1 //===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the TargetELFWriterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H
15 #define LLVM_TARGET_TARGETELFWRITERINFO_H
16
17 namespace llvm {
18   class Function;
19   class TargetData;
20   class TargetMachine;
21
22   //===--------------------------------------------------------------------===//
23   //                          TargetELFWriterInfo
24   //===--------------------------------------------------------------------===//
25
26   class TargetELFWriterInfo {
27   protected:
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     TargetMachine &TM;
32     bool is64Bit, isLittleEndian;
33   public:
34
35     // Machine architectures
36     enum MachineType {
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
47       EM_ARM = 40,     // ARM
48       EM_ALPHA = 41,   // DEC Alpha
49       EM_SPARCV9 = 43, // SPARC V9
50       EM_X86_64 = 62   // AMD64
51     };
52
53     // ELF File classes
54     enum {
55       ELFCLASS32 = 1, // 32-bit object file
56       ELFCLASS64 = 2  // 64-bit object file
57     };
58
59     // ELF Endianess
60     enum {
61       ELFDATA2LSB = 1, // Little-endian object file
62       ELFDATA2MSB = 2  // Big-endian object file
63     };
64
65     explicit TargetELFWriterInfo(TargetMachine &tm);
66     virtual ~TargetELFWriterInfo();
67
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;
73     }
74
75     /// ELF Header and ELF Section Header Info
76     unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
77     unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
78
79     /// Symbol Table Info
80     unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
81
82     /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
83     /// is used to align some sections.
84     unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
85
86     /// getRelocationEntrySize - Entry size used in the relocation section
87     unsigned getRelocationEntrySize() const {
88       return is64Bit ? (hasRelocationAddend() ? 24 : 16)
89                      : (hasRelocationAddend() ? 12 : 8);
90     }
91
92     /// hasCustomJumpTableIndexRelTy - Returns true if the target has a
93     /// specific relocation type for a jump table index.
94     virtual bool hasCustomJumpTableIndexRelTy() const { return false; }
95
96     /// getJumpTableIndexRelTy - Returns the target specific relocation type
97     /// for a jump table index.
98     virtual unsigned getJumpTableIndexRelTy() const { return 0; }
99
100     /// getRelocationType - Returns the target specific ELF Relocation type.
101     /// 'MachineRelTy' contains the object code independent relocation type
102     virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
103
104     /// hasRelocationAddend - True if the target uses an addend in the
105     /// ELF relocation entry.
106     virtual bool hasRelocationAddend() const = 0;
107
108     /// getDefaultAddendForRelTy - Gets the default addend value for a
109     /// relocation entry based on the target ELF relocation type.
110     virtual long int getDefaultAddendForRelTy(unsigned RelTy) const = 0;
111
112     /// getRelTySize - Returns the size of relocatable field in bits
113     virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
114
115     /// isPCRelativeRel - True if the relocation type is pc relative
116     virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
117
118     /// getJumpTableRelocationTy - Returns the machine relocation type used
119     /// to reference a jumptable.
120     virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
121
122     /// computeRelocation - Some relocatable fields could be relocated
123     /// directly, avoiding the emission of a relocation symbol, compute the
124     /// final relocation value for this symbol.
125     virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
126                                        unsigned RelTy) const = 0;
127   };
128
129 } // end llvm namespace
130
131 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H