aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Target/TargetELFWriterInfo.h
blob: 37e903c29e1b0fbba8608123706f83294e6811d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the TargetELFWriterInfo class.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TARGET_TARGETELFWRITERINFO_H
#define LLVM_TARGET_TARGETELFWRITERINFO_H

namespace llvm {
  class Function;
  class TargetData;
  class TargetMachine;

  //===--------------------------------------------------------------------===//
  //                          TargetELFWriterInfo
  //===--------------------------------------------------------------------===//

  class TargetELFWriterInfo {
  protected:
    // EMachine - This field is the target specific value to emit as the
    // e_machine member of the ELF header.
    unsigned short EMachine;
    TargetMachine &TM;
    bool is64Bit, isLittleEndian;
  public:

    // Machine architectures
    enum MachineType {
      EM_NONE = 0,     // No machine
      EM_M32 = 1,      // AT&T WE 32100
      EM_SPARC = 2,    // SPARC
      EM_386 = 3,      // Intel 386
      EM_68K = 4,      // Motorola 68000
      EM_88K = 5,      // Motorola 88000
      EM_486 = 6,      // Intel 486 (deprecated)
      EM_860 = 7,      // Intel 80860
      EM_MIPS = 8,     // MIPS R3000
      EM_PPC = 20,     // PowerPC
      EM_ARM = 40,     // ARM
      EM_ALPHA = 41,   // DEC Alpha
      EM_SPARCV9 = 43, // SPARC V9
      EM_X86_64 = 62   // AMD64
    };

    // ELF File classes
    enum {
      ELFCLASS32 = 1, // 32-bit object file
      ELFCLASS64 = 2  // 64-bit object file
    };

    // ELF Endianess
    enum {
      ELFDATA2LSB = 1, // Little-endian object file
      ELFDATA2MSB = 2  // Big-endian object file
    };

    explicit TargetELFWriterInfo(TargetMachine &tm);
    virtual ~TargetELFWriterInfo();

    unsigned short getEMachine() const { return EMachine; }
    unsigned getEFlags() const { return 0; }
    unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
    unsigned getEIData() const {
      return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
    }

    /// ELF Header and ELF Section Header Info
    unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
    unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }

    /// Symbol Table Info
    unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }

    /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
    /// is used to align some sections.
    unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }

    /// getRelocationEntrySize - Entry size used in the relocation section
    unsigned getRelocationEntrySize() const {
      return is64Bit ? (hasRelocationAddend() ? 24 : 16)
                     : (hasRelocationAddend() ? 12 : 8);
    }

    /// hasCustomJumpTableIndexRelTy - Returns true if the target has a
    /// specific relocation type for a jump table index.
    virtual bool hasCustomJumpTableIndexRelTy() const { return false; }

    /// getJumpTableIndexRelTy - Returns the target specific relocation type
    /// for a jump table index.
    virtual unsigned getJumpTableIndexRelTy() const { return 0; }

    /// getRelocationType - Returns the target specific ELF Relocation type.
    /// 'MachineRelTy' contains the object code independent relocation type
    virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;

    /// hasRelocationAddend - True if the target uses an addend in the
    /// ELF relocation entry.
    virtual bool hasRelocationAddend() const = 0;

    /// getDefaultAddendForRelTy - Gets the default addend value for a
    /// relocation entry based on the target ELF relocation type.
    virtual long int getDefaultAddendForRelTy(unsigned RelTy) const = 0;

    /// getRelTySize - Returns the size of relocatable field in bits
    virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;

    /// isPCRelativeRel - True if the relocation type is pc relative
    virtual bool isPCRelativeRel(unsigned RelTy) const = 0;

    /// getJumpTableRelocationTy - Returns the machine relocation type used
    /// to reference a jumptable.
    virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;

    /// computeRelocation - Some relocatable fields could be relocated
    /// directly, avoiding the relocation symbol emission, compute the
    /// final relocation value for this symbol.
    virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
                                       unsigned RelTy) const = 0;
  };

} // end llvm namespace

#endif // LLVM_TARGET_TARGETELFWRITERINFO_H