1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- lib/CodeGen/ELF.h - ELF constants and data structures ---*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This header contains common, non-processor-specific data structures and
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// constants for the ELF file format.
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The details of the ELF32 bits in this file are largely based on the Tool
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Interface Standard (TIS) Executable and Linking Format (ELF) Specification
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Version 1.2, May 1995. The ELF64 is based on HP/Intel definition of the
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// ELF-64 object file format document, Version 1.5 Draft 2 May 27, 1998
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef CODEGEN_ELF_H
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define CODEGEN_ELF_H
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/BinaryObject.h"
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/MachineRelocation.h"
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/ELF.h"
2619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/Support/DataTypes.h"
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  class GlobalValue;
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// ELFSym - This struct contains information about each symbol that is
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// added to logical symbol table for the module.  This is eventually
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// turned into a real symbol table in the file.
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  struct ELFSym {
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // ELF symbols are related to llvm ones by being one of the two llvm
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // types, for the other ones (section, file, func) a null pointer is
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // assumed by default.
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    union {
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      const GlobalValue *GV;  // If this is a pointer to a GV
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      const char *Ext;        // If this is a pointer to a named symbol
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    } Source;
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // Describes from which source type this ELF symbol comes from,
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // they can be GlobalValue, ExternalSymbol or neither.
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    enum {
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      isGV,      // The Source.GV field is valid.
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      isExtSym,  // The Source.ExtSym field is valid.
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      isOther    // Not a GlobalValue or External Symbol
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    };
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned SourceType;
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isGlobalValue() const { return SourceType == isGV; }
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExternalSym() const { return SourceType == isExtSym; }
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getGlobalValue - If this is a global value which originated the
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // elf symbol, return a reference to it.
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    const GlobalValue *getGlobalValue() const {
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(SourceType == isGV && "This is not a global value");
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Source.GV;
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getExternalSym - If this is an external symbol which originated the
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // elf symbol, return a reference to it.
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    const char *getExternalSymbol() const {
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(SourceType == isExtSym && "This is not an external symbol");
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Source.Ext;
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getGV - From a global value return a elf symbol to represent it
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static ELFSym *getGV(const GlobalValue *GV, unsigned Bind,
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                         unsigned Type, unsigned Visibility) {
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ELFSym *Sym = new ELFSym();
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->Source.GV = GV;
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setBind(Bind);
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setType(Type);
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setVisibility(Visibility);
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SourceType = isGV;
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym;
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getExtSym - Create and return an elf symbol to represent an
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // external symbol
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static ELFSym *getExtSym(const char *Ext) {
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ELFSym *Sym = new ELFSym();
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->Source.Ext = Ext;
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setBind(ELF::STB_GLOBAL);
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setType(ELF::STT_NOTYPE);
89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setVisibility(ELF::STV_DEFAULT);
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SourceType = isExtSym;
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym;
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getSectionSym - Returns a elf symbol to represent an elf section
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static ELFSym *getSectionSym() {
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ELFSym *Sym = new ELFSym();
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setBind(ELF::STB_LOCAL);
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setType(ELF::STT_SECTION);
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setVisibility(ELF::STV_DEFAULT);
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SourceType = isOther;
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym;
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getFileSym - Returns a elf symbol to represent the module identifier
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static ELFSym *getFileSym() {
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ELFSym *Sym = new ELFSym();
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setBind(ELF::STB_LOCAL);
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setType(ELF::STT_FILE);
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setVisibility(ELF::STV_DEFAULT);
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SectionIdx = 0xfff1;  // ELFSection::SHN_ABS;
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SourceType = isOther;
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym;
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // getUndefGV - Returns a STT_NOTYPE symbol
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static ELFSym *getUndefGV(const GlobalValue *GV, unsigned Bind) {
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ELFSym *Sym = new ELFSym();
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->Source.GV = GV;
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setBind(Bind);
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setType(ELF::STT_NOTYPE);
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->setVisibility(ELF::STV_DEFAULT);
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SectionIdx = 0;  //ELFSection::SHN_UNDEF;
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Sym->SourceType = isGV;
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym;
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // ELF specific fields
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned NameIdx;         // Index in .strtab of name, once emitted.
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint64_t Value;
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Size;
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint8_t Info;
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint8_t Other;
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned short SectionIdx;
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // Symbol index into the Symbol table
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned SymTabIdx;
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ELFSym() : SourceType(isOther), NameIdx(0), Value(0),
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman               Size(0), Info(0), Other(ELF::STV_DEFAULT), SectionIdx(0),
140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman               SymTabIdx(0) {}
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getBind() const { return (Info >> 4) & 0xf; }
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getType() const { return Info & 0xf; }
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isLocalBind() const { return getBind() == ELF::STB_LOCAL; }
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isFileType() const { return getType() == ELF::STT_FILE; }
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    void setBind(unsigned X) {
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(X == (X & 0xF) && "Bind value out of range!");
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Info = (Info & 0x0F) | (X << 4);
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    void setType(unsigned X) {
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(X == (X & 0xF) && "Type value out of range!");
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Info = (Info & 0xF0) | X;
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    void setVisibility(unsigned V) {
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(V == (V & 0x3) && "Visibility value out of range!");
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Other = V;
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// ELFSection - This struct contains information about each section that is
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// emitted to the file.  This is eventually turned into the section header
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// table at the end of the file.
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  class ELFSection : public BinaryObject {
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    public:
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // ELF specific fields
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned NameIdx;   // sh_name - .shstrtab idx of name, once emitted.
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Type;      // sh_type - Section contents & semantics
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Flags;     // sh_flags - Section flags.
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint64_t Addr;      // sh_addr - The mem addr this section is in.
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Offset;    // sh_offset - Offset from the file start
174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Size;      // sh_size - The section size.
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Link;      // sh_link - Section header table index link.
17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned Info;      // sh_info - Auxiliary information.
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned Align;     // sh_addralign - Alignment of section.
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned EntSize;   // sh_entsize - Size of entries in the section e
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// SectionIdx - The number of the section in the Section Table.
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned short SectionIdx;
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// Sym - The symbol to represent this section if it has one.
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ELFSym *Sym;
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getSymIndex - Returns the symbol table index of the symbol
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// representing this section.
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getSymbolTableIndex() const {
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(Sym && "section not present in the symbol table");
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return Sym->SymTabIdx;
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ELFSection(const std::string &name, bool isLittleEndian, bool is64Bit)
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      : BinaryObject(name, isLittleEndian, is64Bit), Type(0), Flags(0), Addr(0),
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        Offset(0), Size(0), Link(0), Info(0), Align(0), EntSize(0), Sym(0) {}
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// ELFRelocation - This class contains all the information necessary to
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// to generate any 32-bit or 64-bit ELF relocation entry.
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  class ELFRelocation {
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint64_t r_offset;    // offset in the section of the object this applies to
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint32_t r_symidx;    // symbol table index of the symbol to use
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint32_t r_type;      // machine specific relocation type
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    int64_t  r_add;       // explicit relocation addend
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool     r_rela;      // if true then the addend is part of the entry
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                          // otherwise the addend is at the location specified
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                          // by r_offset
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public:
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint64_t getInfo(bool is64Bit) const {
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (is64Bit)
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return ((uint64_t)r_symidx << 32) + ((uint64_t)r_type & 0xFFFFFFFFL);
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      else
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return (r_symidx << 8)  + (r_type & 0xFFL);
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    uint64_t getOffset() const { return r_offset; }
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    int64_t getAddend() const { return r_add; }
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ELFRelocation(uint64_t off, uint32_t sym, uint32_t type,
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                  bool rela = true, int64_t addend = 0) :
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      r_offset(off), r_symidx(sym), r_type(type),
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      r_add(addend), r_rela(rela) {}
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
228