Remove another unused argument.
[oota-llvm.git] / include / llvm / MC / MCELFObjectWriter.h
1 //===-- llvm/MC/MCELFObjectWriter.h - ELF Object Writer ---------*- 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 #ifndef LLVM_MC_MCELFOBJECTWRITER_H
11 #define LLVM_MC_MCELFOBJECTWRITER_H
12
13 #include "llvm/ADT/Triple.h"
14 #include "llvm/Support/DataTypes.h"
15 #include "llvm/Support/ELF.h"
16 #include <vector>
17
18 namespace llvm {
19 class MCAssembler;
20 class MCFixup;
21 class MCFragment;
22 class MCObjectWriter;
23 class MCSymbol;
24 class MCValue;
25
26 /// @name Relocation Data
27 /// @{
28
29 struct ELFRelocationEntry {
30   // Make these big enough for both 32-bit and 64-bit
31   uint64_t r_offset;
32   int Index;
33   unsigned Type;
34   const MCSymbol *Symbol;
35   uint64_t r_addend;
36   const MCFixup *Fixup;
37
38   ELFRelocationEntry()
39     : r_offset(0), Index(0), Type(0), Symbol(0), r_addend(0), Fixup(0) {}
40
41   ELFRelocationEntry(uint64_t RelocOffset, int Idx, unsigned RelType,
42                      const MCSymbol *Sym, uint64_t Addend, const MCFixup &Fixup)
43     : r_offset(RelocOffset), Index(Idx), Type(RelType), Symbol(Sym),
44       r_addend(Addend), Fixup(&Fixup) {}
45 };
46
47 class MCELFObjectTargetWriter {
48   const uint8_t OSABI;
49   const uint16_t EMachine;
50   const unsigned HasRelocationAddend : 1;
51   const unsigned Is64Bit : 1;
52   const unsigned IsN64 : 1;
53
54 protected:
55
56   MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
57                           uint16_t EMachine_,  bool HasRelocationAddend,
58                           bool IsN64=false);
59
60 public:
61   static uint8_t getOSABI(Triple::OSType OSType) {
62     switch (OSType) {
63       case Triple::FreeBSD:
64         return ELF::ELFOSABI_FREEBSD;
65       case Triple::Linux:
66         return ELF::ELFOSABI_LINUX;
67       default:
68         return ELF::ELFOSABI_NONE;
69     }
70   }
71
72   virtual ~MCELFObjectTargetWriter() {}
73
74   virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
75                                 bool IsPCRel) const = 0;
76   virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm,
77                                          const MCValue &Target,
78                                          const MCFragment &F,
79                                          const MCFixup &Fixup,
80                                          bool IsPCRel) const;
81   virtual const MCSymbol *undefinedExplicitRelSym(const MCValue &Target,
82                                                   const MCFixup &Fixup,
83                                                   bool IsPCRel) const;
84
85   virtual void sortRelocs(const MCAssembler &Asm,
86                           std::vector<ELFRelocationEntry> &Relocs);
87
88   /// @name Accessors
89   /// @{
90   uint8_t getOSABI() const { return OSABI; }
91   uint16_t getEMachine() const { return EMachine; }
92   bool hasRelocationAddend() const { return HasRelocationAddend; }
93   bool is64Bit() const { return Is64Bit; }
94   bool isN64() const { return IsN64; }
95   /// @}
96
97   // Instead of changing everyone's API we pack the N64 Type fields
98   // into the existing 32 bit data unsigned.
99 #define R_TYPE_SHIFT 0
100 #define R_TYPE_MASK 0xffffff00
101 #define R_TYPE2_SHIFT 8
102 #define R_TYPE2_MASK 0xffff00ff
103 #define R_TYPE3_SHIFT 16
104 #define R_TYPE3_MASK 0xff00ffff
105 #define R_SSYM_SHIFT 24
106 #define R_SSYM_MASK 0x00ffffff
107
108   // N64 relocation type accessors
109   uint8_t getRType(uint32_t Type) const {
110     return (unsigned)((Type >> R_TYPE_SHIFT) & 0xff);
111   }
112   uint8_t getRType2(uint32_t Type) const {
113     return (unsigned)((Type >> R_TYPE2_SHIFT) & 0xff);
114   }
115   uint8_t getRType3(uint32_t Type) const {
116     return (unsigned)((Type >> R_TYPE3_SHIFT) & 0xff);
117   }
118   uint8_t getRSsym(uint32_t Type) const {
119     return (unsigned)((Type >> R_SSYM_SHIFT) & 0xff);
120   }
121
122   // N64 relocation type setting
123   unsigned setRType(unsigned Value, unsigned Type) const {
124     return ((Type & R_TYPE_MASK) | ((Value & 0xff) << R_TYPE_SHIFT));
125   }
126   unsigned setRType2(unsigned Value, unsigned Type) const {
127     return (Type & R_TYPE2_MASK) | ((Value & 0xff) << R_TYPE2_SHIFT);
128   }
129   unsigned setRType3(unsigned Value, unsigned Type) const {
130     return (Type & R_TYPE3_MASK) | ((Value & 0xff) << R_TYPE3_SHIFT);
131   }
132   unsigned setRSsym(unsigned Value, unsigned Type) const {
133     return (Type & R_SSYM_MASK) | ((Value & 0xff) << R_SSYM_SHIFT);
134   }
135 };
136
137 /// \brief Construct a new ELF writer instance.
138 ///
139 /// \param MOTW - The target specific ELF writer subclass.
140 /// \param OS - The stream to write to.
141 /// \returns The constructed object writer.
142 MCObjectWriter *createELFObjectWriter(MCELFObjectTargetWriter *MOTW,
143                                       raw_ostream &OS, bool IsLittleEndian);
144 } // End llvm namespace
145
146 #endif