• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     bool is64Bit, isLittleEndian;
32   public:
33 
34     // Machine architectures
35     enum MachineType {
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
46       EM_ARM = 40,     // ARM
47       EM_ALPHA = 41,   // DEC Alpha
48       EM_SPARCV9 = 43, // SPARC V9
49       EM_X86_64 = 62   // AMD64
50     };
51 
52     // ELF File classes
53     enum {
54       ELFCLASS32 = 1, // 32-bit object file
55       ELFCLASS64 = 2  // 64-bit object file
56     };
57 
58     // ELF Endianess
59     enum {
60       ELFDATA2LSB = 1, // Little-endian object file
61       ELFDATA2MSB = 2  // Big-endian object file
62     };
63 
64     explicit TargetELFWriterInfo(bool is64Bit_, bool isLittleEndian_);
65     virtual ~TargetELFWriterInfo();
66 
getEMachine()67     unsigned short getEMachine() const { return EMachine; }
getEFlags()68     unsigned getEFlags() const { return 0; }
getEIClass()69     unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
getEIData()70     unsigned getEIData() const {
71       return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
72     }
73 
74     /// ELF Header and ELF Section Header Info
getHdrSize()75     unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
getSHdrSize()76     unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
77 
78     /// Symbol Table Info
getSymTabEntrySize()79     unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
80 
81     /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
82     /// is used to align some sections.
getPrefELFAlignment()83     unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
84 
85     /// getRelocationEntrySize - Entry size used in the relocation section
getRelocationEntrySize()86     unsigned getRelocationEntrySize() const {
87       return is64Bit ? (hasRelocationAddend() ? 24 : 16)
88                      : (hasRelocationAddend() ? 12 : 8);
89     }
90 
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;
94 
95     /// hasRelocationAddend - True if the target uses an addend in the
96     /// ELF relocation entry.
97     virtual bool hasRelocationAddend() const = 0;
98 
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;
103 
104     /// getRelTySize - Returns the size of relocatable field in bits
105     virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
106 
107     /// isPCRelativeRel - True if the relocation type is pc relative
108     virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
109 
110     /// getJumpTableRelocationTy - Returns the machine relocation type used
111     /// to reference a jumptable.
112     virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
113 
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;
119   };
120 
121 } // end llvm namespace
122 
123 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H
124