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
17namespace llvm {
18
19  //===--------------------------------------------------------------------===//
20  //                          TargetELFWriterInfo
21  //===--------------------------------------------------------------------===//
22
23  class TargetELFWriterInfo {
24  protected:
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;
29  public:
30
31    // Machine architectures
32    enum MachineType {
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
43      EM_ARM = 40,     // ARM
44      EM_ALPHA = 41,   // DEC Alpha
45      EM_SPARCV9 = 43, // SPARC V9
46      EM_X86_64 = 62,  // AMD64
47      EM_HEXAGON = 164 // Qualcomm Hexagon
48    };
49
50    // ELF File classes
51    enum {
52      ELFCLASS32 = 1, // 32-bit object file
53      ELFCLASS64 = 2  // 64-bit object file
54    };
55
56    // ELF Endianess
57    enum {
58      ELFDATA2LSB = 1, // Little-endian object file
59      ELFDATA2MSB = 2  // Big-endian object file
60    };
61
62    explicit TargetELFWriterInfo(bool is64Bit_, bool isLittleEndian_);
63    virtual ~TargetELFWriterInfo();
64
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;
70    }
71
72    /// ELF Header and ELF Section Header Info
73    unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
74    unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
75
76    /// Symbol Table Info
77    unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
78
79    /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
80    /// is used to align some sections.
81    unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
82
83    /// getRelocationEntrySize - Entry size used in the relocation section
84    unsigned getRelocationEntrySize() const {
85      return is64Bit ? (hasRelocationAddend() ? 24 : 16)
86                     : (hasRelocationAddend() ? 12 : 8);
87    }
88
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;
92
93    /// hasRelocationAddend - True if the target uses an addend in the
94    /// ELF relocation entry.
95    virtual bool hasRelocationAddend() const = 0;
96
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;
101
102    /// getRelTySize - Returns the size of relocatable field in bits
103    virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
104
105    /// isPCRelativeRel - True if the relocation type is pc relative
106    virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
107
108    /// getJumpTableRelocationTy - Returns the machine relocation type used
109    /// to reference a jumptable.
110    virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
111
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;
117  };
118
119} // end llvm namespace
120
121#endif // LLVM_TARGET_TARGETELFWRITERINFO_H
122