Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 1 | //===- Relocations.cpp ----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
George Rimar | 95912d0 | 2016-06-08 12:29:29 +0000 | [diff] [blame] | 10 | // This file contains platform-independent functions to process relocations. |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 11 | // I'll describe the overview of this file here. |
| 12 | // |
| 13 | // Simple relocations are easy to handle for the linker. For example, |
| 14 | // for R_X86_64_PC64 relocs, the linker just has to fix up locations |
| 15 | // with the relative offsets to the target symbols. It would just be |
| 16 | // reading records from relocation sections and applying them to output. |
| 17 | // |
| 18 | // But not all relocations are that easy to handle. For example, for |
| 19 | // R_386_GOTOFF relocs, the linker has to create new GOT entries for |
| 20 | // symbols if they don't exist, and fix up locations with GOT entry |
| 21 | // offsets from the beginning of GOT section. So there is more than |
| 22 | // fixing addresses in relocation processing. |
| 23 | // |
| 24 | // ELF defines a large number of complex relocations. |
| 25 | // |
| 26 | // The functions in this file analyze relocations and do whatever needs |
| 27 | // to be done. It includes, but not limited to, the following. |
| 28 | // |
| 29 | // - create GOT/PLT entries |
| 30 | // - create new relocations in .dynsym to let the dynamic linker resolve |
| 31 | // them at runtime (since ELF supports dynamic linking, not all |
| 32 | // relocations can be resolved at link-time) |
| 33 | // - create COPY relocs and reserve space in .bss |
| 34 | // - replace expensive relocs (in terms of runtime cost) with cheap ones |
| 35 | // - error out infeasible combinations such as PIC and non-relative relocs |
| 36 | // |
| 37 | // Note that the functions in this file don't actually apply relocations |
| 38 | // because it doesn't know about the output file nor the output file buffer. |
| 39 | // It instead stores Relocation objects to InputSection's Relocations |
| 40 | // vector to let it apply later in InputSection::writeTo. |
| 41 | // |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | |
| 44 | #include "Relocations.h" |
| 45 | #include "Config.h" |
| 46 | #include "OutputSections.h" |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 47 | #include "Strings.h" |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 48 | #include "SymbolTable.h" |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 49 | #include "SyntheticSections.h" |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 50 | #include "Target.h" |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 51 | #include "Thunks.h" |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 52 | |
| 53 | #include "llvm/Support/Endian.h" |
| 54 | #include "llvm/Support/raw_ostream.h" |
| 55 | |
| 56 | using namespace llvm; |
| 57 | using namespace llvm::ELF; |
| 58 | using namespace llvm::object; |
| 59 | using namespace llvm::support::endian; |
| 60 | |
| 61 | namespace lld { |
| 62 | namespace elf { |
| 63 | |
| 64 | static bool refersToGotEntry(RelExpr Expr) { |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 65 | return Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT_LOCAL_PAGE || |
Simon Atanasyan | bed04bf | 2016-10-21 07:22:30 +0000 | [diff] [blame] | 66 | Expr == R_MIPS_GOT_OFF || Expr == R_MIPS_GOT_OFF32 || |
| 67 | Expr == R_MIPS_TLSGD || Expr == R_MIPS_TLSLD || |
| 68 | Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC || Expr == R_GOT_FROM_END || |
| 69 | Expr == R_TLSGD || Expr == R_TLSGD_PC || Expr == R_TLSDESC || |
| 70 | Expr == R_TLSDESC_PAGE; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 73 | static bool isPreemptible(const SymbolBody &Body, uint32_t Type) { |
| 74 | // In case of MIPS GP-relative relocations always resolve to a definition |
| 75 | // in a regular input file, ignoring the one-definition rule. So we, |
| 76 | // for example, should not attempt to create a dynamic relocation even |
| 77 | // if the target symbol is preemptible. There are two two MIPS GP-relative |
| 78 | // relocations R_MIPS_GPREL16 and R_MIPS_GPREL32. But only R_MIPS_GPREL16 |
| 79 | // can be against a preemptible symbol. |
Simon Atanasyan | a26a157 | 2016-06-10 12:26:09 +0000 | [diff] [blame] | 80 | // To get MIPS relocation type we apply 0xff mask. In case of O32 ABI all |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 81 | // relocation types occupy eight bit. In case of N64 ABI we extract first |
| 82 | // relocation from 3-in-1 packet because only the first relocation can |
| 83 | // be against a real symbol. |
Simon Atanasyan | a26a157 | 2016-06-10 12:26:09 +0000 | [diff] [blame] | 84 | if (Config->EMachine == EM_MIPS && (Type & 0xff) == R_MIPS_GPREL16) |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 85 | return false; |
| 86 | return Body.isPreemptible(); |
| 87 | } |
| 88 | |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 89 | // This function is similar to the `handleTlsRelocation`. ARM and MIPS do not |
| 90 | // support any relaxations for TLS relocations so by factoring out ARM and MIPS |
| 91 | // handling in to the separate function we can simplify the code and do not |
| 92 | // pollute `handleTlsRelocation` by ARM and MIPS `ifs` statements. |
| 93 | // FIXME: The ARM implementation always adds the module index dynamic |
| 94 | // relocation even for non-preemptible symbols in applications. For static |
| 95 | // linking support we must either resolve the module index relocation at static |
| 96 | // link time, or hard code the module index (1) for the application in the GOT. |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 97 | template <class ELFT> |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 98 | static unsigned handleNoRelaxTlsRelocation(uint32_t Type, SymbolBody &Body, |
| 99 | InputSectionBase<ELFT> &C, |
| 100 | typename ELFT::uint Offset, |
| 101 | typename ELFT::uint Addend, |
| 102 | RelExpr Expr) { |
| 103 | if (Expr == R_MIPS_TLSLD || Expr == R_TLSLD_PC) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 104 | if (In<ELFT>::Got->addTlsIndex() && |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 105 | (Config->Pic || Config->EMachine == EM_ARM)) |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 106 | In<ELFT>::RelaDyn->addReloc({Target->TlsModuleIndexRel, In<ELFT>::Got, |
| 107 | In<ELFT>::Got->getTlsIndexOff(), false, |
| 108 | nullptr, 0}); |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 109 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 110 | return 1; |
| 111 | } |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 112 | typedef typename ELFT::uint uintX_t; |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 113 | if (Target->isTlsGlobalDynamicRel(Type)) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 114 | if (In<ELFT>::Got->addDynTlsEntry(Body) && |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 115 | (Body.isPreemptible() || Config->EMachine == EM_ARM)) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 116 | uintX_t Off = In<ELFT>::Got->getGlobalDynOffset(Body); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 117 | In<ELFT>::RelaDyn->addReloc( |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 118 | {Target->TlsModuleIndexRel, In<ELFT>::Got, Off, false, &Body, 0}); |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 119 | if (Body.isPreemptible()) |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 120 | In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, In<ELFT>::Got, |
| 121 | Off + (uintX_t)sizeof(uintX_t), false, |
| 122 | &Body, 0}); |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 123 | } |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 124 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 125 | return 1; |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 130 | // Returns the number of relocations processed. |
| 131 | template <class ELFT> |
| 132 | static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body, |
| 133 | InputSectionBase<ELFT> &C, |
| 134 | typename ELFT::uint Offset, |
| 135 | typename ELFT::uint Addend, RelExpr Expr) { |
Rafael Espindola | 1854a8e | 2016-10-26 12:36:56 +0000 | [diff] [blame] | 136 | if (!(C.Flags & SHF_ALLOC)) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 137 | return 0; |
| 138 | |
| 139 | if (!Body.isTls()) |
| 140 | return 0; |
| 141 | |
| 142 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 143 | |
Peter Smith | fde6213 | 2016-09-23 13:54:48 +0000 | [diff] [blame] | 144 | if (Config->EMachine == EM_MIPS || Config->EMachine == EM_ARM) |
| 145 | return handleNoRelaxTlsRelocation<ELFT>(Type, Body, C, Offset, Addend, |
| 146 | Expr); |
Simon Atanasyan | 002e244 | 2016-06-23 15:26:31 +0000 | [diff] [blame] | 147 | |
Peter Smith | d648603 | 2016-10-20 09:59:26 +0000 | [diff] [blame] | 148 | if ((Expr == R_TLSDESC || Expr == R_TLSDESC_PAGE || Expr == R_TLSDESC_CALL) && |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 149 | Config->Shared) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 150 | if (In<ELFT>::Got->addDynTlsEntry(Body)) { |
| 151 | uintX_t Off = In<ELFT>::Got->getGlobalDynOffset(Body); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 152 | In<ELFT>::RelaDyn->addReloc( |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 153 | {Target->TlsDescRel, In<ELFT>::Got, Off, false, &Body, 0}); |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 154 | } |
Peter Smith | d648603 | 2016-10-20 09:59:26 +0000 | [diff] [blame] | 155 | if (Expr != R_TLSDESC_CALL) |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 156 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 157 | return 1; |
| 158 | } |
| 159 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 160 | if (Expr == R_TLSLD_PC || Expr == R_TLSLD) { |
| 161 | // Local-Dynamic relocs can be relaxed to Local-Exec. |
| 162 | if (!Config->Shared) { |
| 163 | C.Relocations.push_back( |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 164 | {R_RELAX_TLS_LD_TO_LE, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 165 | return 2; |
| 166 | } |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 167 | if (In<ELFT>::Got->addTlsIndex()) |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 168 | In<ELFT>::RelaDyn->addReloc({Target->TlsModuleIndexRel, In<ELFT>::Got, |
| 169 | In<ELFT>::Got->getTlsIndexOff(), false, |
| 170 | nullptr, 0}); |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 171 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 172 | return 1; |
| 173 | } |
| 174 | |
| 175 | // Local-Dynamic relocs can be relaxed to Local-Exec. |
| 176 | if (Target->isTlsLocalDynamicRel(Type) && !Config->Shared) { |
| 177 | C.Relocations.push_back( |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 178 | {R_RELAX_TLS_LD_TO_LE, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 179 | return 1; |
| 180 | } |
| 181 | |
Peter Smith | d648603 | 2016-10-20 09:59:26 +0000 | [diff] [blame] | 182 | if (Expr == R_TLSDESC_PAGE || Expr == R_TLSDESC || Expr == R_TLSDESC_CALL || |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 183 | Target->isTlsGlobalDynamicRel(Type)) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 184 | if (Config->Shared) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 185 | if (In<ELFT>::Got->addDynTlsEntry(Body)) { |
| 186 | uintX_t Off = In<ELFT>::Got->getGlobalDynOffset(Body); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 187 | In<ELFT>::RelaDyn->addReloc( |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 188 | {Target->TlsModuleIndexRel, In<ELFT>::Got, Off, false, &Body, 0}); |
Rafael Espindola | a8777c2 | 2016-06-08 21:31:59 +0000 | [diff] [blame] | 189 | |
| 190 | // If the symbol is preemptible we need the dynamic linker to write |
| 191 | // the offset too. |
Simon Atanasyan | 9b86118 | 2016-06-10 12:26:39 +0000 | [diff] [blame] | 192 | if (isPreemptible(Body, Type)) |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 193 | In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, In<ELFT>::Got, |
| 194 | Off + (uintX_t)sizeof(uintX_t), false, |
| 195 | &Body, 0}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 196 | } |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 197 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 198 | return 1; |
| 199 | } |
| 200 | |
| 201 | // Global-Dynamic relocs can be relaxed to Initial-Exec or Local-Exec |
| 202 | // depending on the symbol being locally defined or not. |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 203 | if (isPreemptible(Body, Type)) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 204 | C.Relocations.push_back( |
Rafael Espindola | 69f5402 | 2016-06-04 23:22:34 +0000 | [diff] [blame] | 205 | {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_GD_TO_IE), Type, |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 206 | Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 207 | if (!Body.isInGot()) { |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 208 | In<ELFT>::Got->addEntry(Body); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 209 | In<ELFT>::RelaDyn->addReloc({Target->TlsGotRel, In<ELFT>::Got, |
| 210 | Body.getGotOffset<ELFT>(), false, &Body, |
| 211 | 0}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 212 | } |
Rafael Espindola | e1979ae | 2016-06-04 23:33:31 +0000 | [diff] [blame] | 213 | return Target->TlsGdRelaxSkip; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 214 | } |
| 215 | C.Relocations.push_back( |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 216 | {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_GD_TO_LE), Type, |
Rafael Espindola | 69f5402 | 2016-06-04 23:22:34 +0000 | [diff] [blame] | 217 | Offset, Addend, &Body}); |
Rafael Espindola | f807d47 | 2016-06-04 23:04:39 +0000 | [diff] [blame] | 218 | return Target->TlsGdRelaxSkip; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // Initial-Exec relocs can be relaxed to Local-Exec if the symbol is locally |
| 222 | // defined. |
| 223 | if (Target->isTlsInitialExecRel(Type) && !Config->Shared && |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 224 | !isPreemptible(Body, Type)) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 225 | C.Relocations.push_back( |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 226 | {R_RELAX_TLS_IE_TO_LE, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 227 | return 1; |
| 228 | } |
| 229 | return 0; |
| 230 | } |
| 231 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 232 | template <endianness E> static int16_t readSignedLo16(const uint8_t *Loc) { |
| 233 | return read32<E>(Loc) & 0xffff; |
| 234 | } |
| 235 | |
| 236 | template <class RelTy> |
| 237 | static uint32_t getMipsPairType(const RelTy *Rel, const SymbolBody &Sym) { |
| 238 | switch (Rel->getType(Config->Mips64EL)) { |
| 239 | case R_MIPS_HI16: |
| 240 | return R_MIPS_LO16; |
| 241 | case R_MIPS_GOT16: |
| 242 | return Sym.isLocal() ? R_MIPS_LO16 : R_MIPS_NONE; |
| 243 | case R_MIPS_PCHI16: |
| 244 | return R_MIPS_PCLO16; |
| 245 | case R_MICROMIPS_HI16: |
| 246 | return R_MICROMIPS_LO16; |
| 247 | default: |
| 248 | return R_MIPS_NONE; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | template <class ELFT, class RelTy> |
| 253 | static int32_t findMipsPairedAddend(const uint8_t *Buf, const uint8_t *BufLoc, |
| 254 | SymbolBody &Sym, const RelTy *Rel, |
| 255 | const RelTy *End) { |
| 256 | uint32_t SymIndex = Rel->getSymbol(Config->Mips64EL); |
| 257 | uint32_t Type = getMipsPairType(Rel, Sym); |
| 258 | |
| 259 | // Some MIPS relocations use addend calculated from addend of the relocation |
| 260 | // itself and addend of paired relocation. ABI requires to compute such |
| 261 | // combined addend in case of REL relocation record format only. |
| 262 | // See p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 263 | if (RelTy::IsRela || Type == R_MIPS_NONE) |
| 264 | return 0; |
| 265 | |
| 266 | for (const RelTy *RI = Rel; RI != End; ++RI) { |
| 267 | if (RI->getType(Config->Mips64EL) != Type) |
| 268 | continue; |
| 269 | if (RI->getSymbol(Config->Mips64EL) != SymIndex) |
| 270 | continue; |
| 271 | const endianness E = ELFT::TargetEndianness; |
| 272 | return ((read32<E>(BufLoc) & 0xffff) << 16) + |
| 273 | readSignedLo16<E>(Buf + RI->r_offset); |
| 274 | } |
Rui Ueyama | d31e13f | 2016-09-29 21:00:23 +0000 | [diff] [blame] | 275 | warn("can't find matching " + getRelName(Type) + " relocation for " + |
George Rimar | a4c7e74 | 2016-10-20 08:36:42 +0000 | [diff] [blame] | 276 | getRelName(Rel->getType(Config->Mips64EL))); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | // True if non-preemptable symbol always has the same value regardless of where |
| 281 | // the DSO is loaded. |
| 282 | template <class ELFT> static bool isAbsolute(const SymbolBody &Body) { |
| 283 | if (Body.isUndefined()) |
| 284 | return !Body.isLocal() && Body.symbol()->isWeak(); |
| 285 | if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(&Body)) |
| 286 | return DR->Section == nullptr; // Absolute symbol. |
| 287 | return false; |
| 288 | } |
| 289 | |
Rafael Espindola | d598c81 | 2016-10-27 17:28:56 +0000 | [diff] [blame] | 290 | template <class ELFT> static bool isAbsoluteValue(const SymbolBody &Body) { |
| 291 | return isAbsolute<ELFT>(Body) || Body.isTls(); |
| 292 | } |
| 293 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 294 | static bool needsPlt(RelExpr Expr) { |
Rafael Espindola | 12dc446 | 2016-06-04 19:11:14 +0000 | [diff] [blame] | 295 | return Expr == R_PLT_PC || Expr == R_PPC_PLT_OPD || Expr == R_PLT || |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 296 | Expr == R_PLT_PAGE_PC || Expr == R_THUNK_PLT_PC; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | // True if this expression is of the form Sym - X, where X is a position in the |
| 300 | // file (PC, or GOT for example). |
| 301 | static bool isRelExpr(RelExpr Expr) { |
Rafael Espindola | 719f55d | 2016-09-06 13:57:15 +0000 | [diff] [blame] | 302 | return Expr == R_PC || Expr == R_GOTREL || Expr == R_GOTREL_FROM_END || |
| 303 | Expr == R_PAGE_PC || Expr == R_RELAX_GOT_PC || Expr == R_THUNK_PC || |
| 304 | Expr == R_THUNK_PLT_PC; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | template <class ELFT> |
| 308 | static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type, |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 309 | const SymbolBody &Body, |
| 310 | InputSectionBase<ELFT> &S, |
| 311 | typename ELFT::uint RelOff) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 312 | // These expressions always compute a constant |
| 313 | if (E == R_SIZE || E == R_GOT_FROM_END || E == R_GOT_OFF || |
Simon Atanasyan | bed04bf | 2016-10-21 07:22:30 +0000 | [diff] [blame] | 314 | E == R_MIPS_GOT_LOCAL_PAGE || E == R_MIPS_GOT_OFF || |
| 315 | E == R_MIPS_GOT_OFF32 || E == R_MIPS_TLSGD || E == R_GOT_PAGE_PC || |
| 316 | E == R_GOT_PC || E == R_PLT_PC || E == R_TLSGD_PC || E == R_TLSGD || |
| 317 | E == R_PPC_PLT_OPD || E == R_TLSDESC_CALL || E == R_TLSDESC_PAGE || |
| 318 | E == R_HINT || E == R_THUNK_PC || E == R_THUNK_PLT_PC) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 319 | return true; |
| 320 | |
| 321 | // These never do, except if the entire file is position dependent or if |
| 322 | // only the low bits are used. |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 323 | if (E == R_GOT || E == R_PLT || E == R_TLSDESC) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 324 | return Target->usesOnlyLowPageBits(Type) || !Config->Pic; |
| 325 | |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 326 | if (isPreemptible(Body, Type)) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 327 | return false; |
| 328 | |
| 329 | if (!Config->Pic) |
| 330 | return true; |
| 331 | |
Rafael Espindola | d598c81 | 2016-10-27 17:28:56 +0000 | [diff] [blame] | 332 | bool AbsVal = isAbsoluteValue<ELFT>(Body); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 333 | bool RelE = isRelExpr(E); |
| 334 | if (AbsVal && !RelE) |
| 335 | return true; |
| 336 | if (!AbsVal && RelE) |
| 337 | return true; |
| 338 | |
| 339 | // Relative relocation to an absolute value. This is normally unrepresentable, |
| 340 | // but if the relocation refers to a weak undefined symbol, we allow it to |
| 341 | // resolve to the image base. This is a little strange, but it allows us to |
| 342 | // link function calls to such symbols. Normally such a call will be guarded |
| 343 | // with a comparison, which will load a zero from the GOT. |
| 344 | if (AbsVal && RelE) { |
| 345 | if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak()) |
| 346 | return true; |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 347 | error(getLocation(S, RelOff) + ": relocation " + getRelName(Type) + |
| 348 | " cannot refer to absolute symbol '" + Body.getName() + |
| 349 | "' defined in " + getFilename(Body.File)); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
| 353 | return Target->usesOnlyLowPageBits(Type); |
| 354 | } |
| 355 | |
| 356 | static RelExpr toPlt(RelExpr Expr) { |
| 357 | if (Expr == R_PPC_OPD) |
| 358 | return R_PPC_PLT_OPD; |
| 359 | if (Expr == R_PC) |
| 360 | return R_PLT_PC; |
Rafael Espindola | 12dc446 | 2016-06-04 19:11:14 +0000 | [diff] [blame] | 361 | if (Expr == R_PAGE_PC) |
| 362 | return R_PLT_PAGE_PC; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 363 | if (Expr == R_ABS) |
| 364 | return R_PLT; |
| 365 | return Expr; |
| 366 | } |
| 367 | |
| 368 | static RelExpr fromPlt(RelExpr Expr) { |
| 369 | // We decided not to use a plt. Optimize a reference to the plt to a |
| 370 | // reference to the symbol itself. |
| 371 | if (Expr == R_PLT_PC) |
| 372 | return R_PC; |
| 373 | if (Expr == R_PPC_PLT_OPD) |
| 374 | return R_PPC_OPD; |
| 375 | if (Expr == R_PLT) |
| 376 | return R_ABS; |
| 377 | return Expr; |
| 378 | } |
| 379 | |
| 380 | template <class ELFT> static uint32_t getAlignment(SharedSymbol<ELFT> *SS) { |
| 381 | typedef typename ELFT::uint uintX_t; |
| 382 | |
Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 383 | uintX_t SecAlign = SS->file()->getSection(SS->Sym)->sh_addralign; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 384 | uintX_t SymValue = SS->Sym.st_value; |
| 385 | int TrailingZeros = |
| 386 | std::min(countTrailingZeros(SecAlign), countTrailingZeros(SymValue)); |
| 387 | return 1 << TrailingZeros; |
| 388 | } |
| 389 | |
| 390 | // Reserve space in .bss for copy relocation. |
| 391 | template <class ELFT> static void addCopyRelSymbol(SharedSymbol<ELFT> *SS) { |
| 392 | typedef typename ELFT::uint uintX_t; |
| 393 | typedef typename ELFT::Sym Elf_Sym; |
| 394 | |
| 395 | // Copy relocation against zero-sized symbol doesn't make sense. |
| 396 | uintX_t SymSize = SS->template getSize<ELFT>(); |
| 397 | if (SymSize == 0) |
Petr Hosek | 4071b1b | 2016-08-18 21:55:23 +0000 | [diff] [blame] | 398 | fatal("cannot create a copy relocation for symbol " + SS->getName()); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 399 | |
Rui Ueyama | 424b408 | 2016-06-17 01:18:46 +0000 | [diff] [blame] | 400 | uintX_t Alignment = getAlignment(SS); |
Rafael Espindola | 04a2e34 | 2016-11-09 01:42:41 +0000 | [diff] [blame] | 401 | uintX_t Off = alignTo(Out<ELFT>::Bss->Size, Alignment); |
| 402 | Out<ELFT>::Bss->Size = Off + SymSize; |
Rui Ueyama | 424b408 | 2016-06-17 01:18:46 +0000 | [diff] [blame] | 403 | Out<ELFT>::Bss->updateAlignment(Alignment); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 404 | uintX_t Shndx = SS->Sym.st_shndx; |
| 405 | uintX_t Value = SS->Sym.st_value; |
| 406 | // Look through the DSO's dynamic symbol table for aliases and create a |
| 407 | // dynamic symbol for each one. This causes the copy relocation to correctly |
| 408 | // interpose any aliases. |
Rafael Espindola | 8e23257 | 2016-11-03 20:48:57 +0000 | [diff] [blame] | 409 | for (const Elf_Sym &S : SS->file()->getGlobalSymbols()) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 410 | if (S.st_shndx != Shndx || S.st_value != Value) |
| 411 | continue; |
| 412 | auto *Alias = dyn_cast_or_null<SharedSymbol<ELFT>>( |
Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 413 | Symtab<ELFT>::X->find(check(S.getName(SS->file()->getStringTable())))); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 414 | if (!Alias) |
| 415 | continue; |
| 416 | Alias->OffsetInBss = Off; |
| 417 | Alias->NeedsCopyOrPltAddr = true; |
| 418 | Alias->symbol()->IsUsedInRegularObj = true; |
| 419 | } |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 420 | In<ELFT>::RelaDyn->addReloc( |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 421 | {Target->CopyRel, Out<ELFT>::Bss, SS->OffsetInBss, false, SS, 0}); |
| 422 | } |
| 423 | |
| 424 | template <class ELFT> |
| 425 | static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body, |
George Rimar | 5c33b91 | 2016-05-25 14:31:37 +0000 | [diff] [blame] | 426 | bool IsWrite, RelExpr Expr, uint32_t Type, |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 427 | const uint8_t *Data, InputSectionBase<ELFT> &S, |
| 428 | typename ELFT::uint RelOff) { |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 429 | bool Preemptible = isPreemptible(Body, Type); |
George Rimar | 5c33b91 | 2016-05-25 14:31:37 +0000 | [diff] [blame] | 430 | if (Body.isGnuIFunc()) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 431 | Expr = toPlt(Expr); |
George Rimar | 5c33b91 | 2016-05-25 14:31:37 +0000 | [diff] [blame] | 432 | } else if (!Preemptible) { |
| 433 | if (needsPlt(Expr)) |
| 434 | Expr = fromPlt(Expr); |
Rafael Espindola | d598c81 | 2016-10-27 17:28:56 +0000 | [diff] [blame] | 435 | if (Expr == R_GOT_PC && !isAbsoluteValue<ELFT>(Body)) |
Rafael Espindola | f2956a3 | 2016-06-17 15:01:50 +0000 | [diff] [blame] | 436 | Expr = Target->adjustRelaxExpr(Type, Data, Expr); |
George Rimar | 5c33b91 | 2016-05-25 14:31:37 +0000 | [diff] [blame] | 437 | } |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 438 | Expr = Target->getThunkExpr(Expr, Type, File, Body); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 439 | |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 440 | if (IsWrite || isStaticLinkTimeConstant<ELFT>(Expr, Type, Body, S, RelOff)) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 441 | return Expr; |
| 442 | |
| 443 | // This relocation would require the dynamic linker to write a value to read |
| 444 | // only memory. We can hack around it if we are producing an executable and |
| 445 | // the refered symbol can be preemepted to refer to the executable. |
| 446 | if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) { |
George Rimar | 1a33c0f | 2016-11-10 09:05:20 +0000 | [diff] [blame] | 447 | StringRef Name = getSymbolName(File.getStringTable(), Body); |
George Rimar | f3c1431 | 2016-11-16 08:34:19 +0000 | [diff] [blame] | 448 | error(getLocation(S, RelOff) + ": can't create dynamic relocation " + |
| 449 | getRelName(Type) + " against " + |
| 450 | ((Name.empty() ? "local symbol in readonly segment" |
| 451 | : "symbol '" + Name + "'")) + |
| 452 | " defined in " + getFilename(Body.File)); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 453 | return Expr; |
| 454 | } |
| 455 | if (Body.getVisibility() != STV_DEFAULT) { |
George Rimar | 76f429b | 2016-11-16 17:24:06 +0000 | [diff] [blame^] | 456 | error(getLocation(S, RelOff) + ": cannot preempt symbol '" + |
| 457 | Body.getName() + "' previously defined in " + getFilename(Body.File)); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 458 | return Expr; |
| 459 | } |
| 460 | if (Body.isObject()) { |
| 461 | // Produce a copy relocation. |
| 462 | auto *B = cast<SharedSymbol<ELFT>>(&Body); |
| 463 | if (!B->needsCopy()) |
| 464 | addCopyRelSymbol(B); |
| 465 | return Expr; |
| 466 | } |
| 467 | if (Body.isFunc()) { |
| 468 | // This handles a non PIC program call to function in a shared library. In |
| 469 | // an ideal world, we could just report an error saying the relocation can |
| 470 | // overflow at runtime. In the real world with glibc, crt1.o has a |
| 471 | // R_X86_64_PC32 pointing to libc.so. |
| 472 | // |
| 473 | // The general idea on how to handle such cases is to create a PLT entry and |
| 474 | // use that as the function value. |
| 475 | // |
| 476 | // For the static linking part, we just return a plt expr and everything |
| 477 | // else will use the the PLT entry as the address. |
| 478 | // |
| 479 | // The remaining problem is making sure pointer equality still works. We |
| 480 | // need the help of the dynamic linker for that. We let it know that we have |
| 481 | // a direct reference to a so symbol by creating an undefined symbol with a |
| 482 | // non zero st_value. Seeing that, the dynamic linker resolves the symbol to |
| 483 | // the value of the symbol we created. This is true even for got entries, so |
| 484 | // pointer equality is maintained. To avoid an infinite loop, the only entry |
| 485 | // that points to the real function is a dedicated got entry used by the |
| 486 | // plt. That is identified by special relocation types (R_X86_64_JUMP_SLOT, |
| 487 | // R_386_JMP_SLOT, etc). |
| 488 | Body.NeedsCopyOrPltAddr = true; |
| 489 | return toPlt(Expr); |
| 490 | } |
George Rimar | 76f429b | 2016-11-16 17:24:06 +0000 | [diff] [blame^] | 491 | error("symbol '" + Body.getName() + "' defined in " + getFilename(Body.File) + |
| 492 | " is missing type"); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 493 | |
| 494 | return Expr; |
| 495 | } |
| 496 | |
| 497 | template <class ELFT, class RelTy> |
| 498 | static typename ELFT::uint computeAddend(const elf::ObjectFile<ELFT> &File, |
| 499 | const uint8_t *SectionData, |
| 500 | const RelTy *End, const RelTy &RI, |
| 501 | RelExpr Expr, SymbolBody &Body) { |
| 502 | typedef typename ELFT::uint uintX_t; |
| 503 | |
| 504 | uint32_t Type = RI.getType(Config->Mips64EL); |
| 505 | uintX_t Addend = getAddend<ELFT>(RI); |
| 506 | const uint8_t *BufLoc = SectionData + RI.r_offset; |
| 507 | if (!RelTy::IsRela) |
| 508 | Addend += Target->getImplicitAddend(BufLoc, Type); |
| 509 | if (Config->EMachine == EM_MIPS) { |
| 510 | Addend += findMipsPairedAddend<ELFT>(SectionData, BufLoc, Body, &RI, End); |
| 511 | if (Type == R_MIPS_LO16 && Expr == R_PC) |
| 512 | // R_MIPS_LO16 expression has R_PC type iif the target is _gp_disp |
| 513 | // symbol. In that case we should use the following formula for |
| 514 | // calculation "AHL + GP - P + 4". Let's add 4 right here. |
| 515 | // For details see p. 4-19 at |
| 516 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 517 | Addend += 4; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 518 | if (Expr == R_GOTREL) { |
| 519 | Addend -= MipsGPOffset; |
| 520 | if (Body.isLocal()) |
Simon Atanasyan | ce02cf0 | 2016-11-09 21:36:56 +0000 | [diff] [blame] | 521 | Addend += File.MipsGp0; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | if (Config->Pic && Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC) |
| 525 | Addend += getPPC64TocBase(); |
| 526 | return Addend; |
| 527 | } |
| 528 | |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 529 | // Find symbol that encloses given offset. Used for error reporting. |
| 530 | template <class ELFT> |
| 531 | static DefinedRegular<ELFT> *getSymbolAt(InputSectionBase<ELFT> *S, |
| 532 | typename ELFT::uint Offset) { |
| 533 | for (SymbolBody *B : S->getFile()->getSymbols()) |
| 534 | if (auto *D = dyn_cast<DefinedRegular<ELFT>>(B)) |
| 535 | if (D->Value <= Offset && D->Value + D->Size > Offset && D->Section == S) |
| 536 | return D; |
| 537 | |
| 538 | return nullptr; |
| 539 | } |
| 540 | |
| 541 | template <class ELFT> |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 542 | std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset) { |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 543 | ObjectFile<ELFT> *File = S.getFile(); |
| 544 | |
| 545 | // First check if we can get desired values from debugging information. |
Rui Ueyama | 7556f6b | 2016-11-02 18:42:13 +0000 | [diff] [blame] | 546 | std::string LineInfo = File->getLineInfo(&S, Offset); |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 547 | if (!LineInfo.empty()) |
| 548 | return LineInfo; |
| 549 | |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 550 | // File->SourceFile contains STT_FILE symbol contents which is a |
| 551 | // filename. Compilers usually create STT_FILE symbols. If it's |
| 552 | // missing, we use an actual filename. |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 553 | std::string SrcFile = File->SourceFile; |
| 554 | if (SrcFile.empty()) |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 555 | SrcFile = getFilename(File); |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 556 | |
Rui Ueyama | 5f7e6e6 | 2016-10-26 20:26:29 +0000 | [diff] [blame] | 557 | // Find a symbol at a given location. |
Rui Ueyama | e784ee7 | 2016-10-26 20:27:38 +0000 | [diff] [blame] | 558 | DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset); |
| 559 | if (Encl && Encl->Type == STT_FUNC) { |
George Rimar | 1a33c0f | 2016-11-10 09:05:20 +0000 | [diff] [blame] | 560 | StringRef Func = getSymbolName(File->getStringTable(), *Encl); |
Rui Ueyama | 5ce977c | 2016-10-26 18:28:06 +0000 | [diff] [blame] | 561 | return SrcFile + " (function " + maybeDemangle(Func) + ")"; |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Rui Ueyama | 5f7e6e6 | 2016-10-26 20:26:29 +0000 | [diff] [blame] | 564 | // If there's no symbol, print out the offset instead of a symbol name. |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 565 | return (SrcFile + " (" + S.Name + "+0x" + Twine::utohexstr(Offset) + ")") |
| 566 | .str(); |
| 567 | } |
| 568 | |
| 569 | template <class ELFT> |
| 570 | static void reportUndefined(SymbolBody &Sym, InputSectionBase<ELFT> &S, |
| 571 | typename ELFT::uint Offset) { |
Eugene Leviant | 8983759 | 2016-10-06 09:45:04 +0000 | [diff] [blame] | 572 | if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore) |
| 573 | return; |
| 574 | |
| 575 | if (Config->Shared && Sym.symbol()->Visibility == STV_DEFAULT && |
| 576 | Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef) |
| 577 | return; |
| 578 | |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 579 | std::string Msg = getLocation(S, Offset) + ": undefined symbol '" + |
Rui Ueyama | 5ce977c | 2016-10-26 18:28:06 +0000 | [diff] [blame] | 580 | maybeDemangle(Sym.getName()) + "'"; |
Eugene Leviant | 8983759 | 2016-10-06 09:45:04 +0000 | [diff] [blame] | 581 | |
Eugene Leviant | 8983759 | 2016-10-06 09:45:04 +0000 | [diff] [blame] | 582 | if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn) |
| 583 | warn(Msg); |
| 584 | else |
| 585 | error(Msg); |
| 586 | } |
| 587 | |
Simon Atanasyan | 9e0297b | 2016-11-05 22:58:01 +0000 | [diff] [blame] | 588 | template <class RelTy> |
| 589 | static std::pair<uint32_t, uint32_t> |
| 590 | mergeMipsN32RelTypes(uint32_t Type, uint32_t Offset, RelTy *I, RelTy *E) { |
| 591 | // MIPS N32 ABI treats series of successive relocations with the same offset |
| 592 | // as a single relocation. The similar approach used by N64 ABI, but this ABI |
| 593 | // packs all relocations into the single relocation record. Here we emulate |
| 594 | // this for the N32 ABI. Iterate over relocation with the same offset and put |
| 595 | // theirs types into the single bit-set. |
| 596 | uint32_t Processed = 0; |
| 597 | for (; I != E && Offset == I->r_offset; ++I) { |
| 598 | ++Processed; |
| 599 | Type |= I->getType(Config->Mips64EL) << (8 * Processed); |
| 600 | } |
| 601 | return std::make_pair(Type, Processed); |
| 602 | } |
| 603 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 604 | // The reason we have to do this early scan is as follows |
| 605 | // * To mmap the output file, we need to know the size |
| 606 | // * For that, we need to know how many dynamic relocs we will have. |
| 607 | // It might be possible to avoid this by outputting the file with write: |
| 608 | // * Write the allocated output sections, computing addresses. |
| 609 | // * Apply relocations, recording which ones require a dynamic reloc. |
| 610 | // * Write the dynamic relocations. |
| 611 | // * Write the rest of the file. |
| 612 | // This would have some drawbacks. For example, we would only know if .rela.dyn |
| 613 | // is needed after applying relocations. If it is, it will go after rw and rx |
| 614 | // sections. Given that it is ro, we will need an extra PT_LOAD. This |
| 615 | // complicates things for the dynamic linker and means we would have to reserve |
| 616 | // space for the extra PT_LOAD even if we end up not using it. |
| 617 | template <class ELFT, class RelTy> |
Rui Ueyama | 2487f19 | 2016-05-25 03:40:02 +0000 | [diff] [blame] | 618 | static void scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 619 | typedef typename ELFT::uint uintX_t; |
| 620 | |
Rafael Espindola | 1854a8e | 2016-10-26 12:36:56 +0000 | [diff] [blame] | 621 | bool IsWrite = C.Flags & SHF_WRITE; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 622 | |
| 623 | auto AddDyn = [=](const DynamicReloc<ELFT> &Reloc) { |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 624 | In<ELFT>::RelaDyn->addReloc(Reloc); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 625 | }; |
| 626 | |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 627 | const elf::ObjectFile<ELFT> *File = C.getFile(); |
Rafael Espindola | c7e1e03 | 2016-09-12 13:13:53 +0000 | [diff] [blame] | 628 | ArrayRef<uint8_t> SectionData = C.Data; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 629 | const uint8_t *Buf = SectionData.begin(); |
Rafael Espindola | 5b7a79f | 2016-07-20 11:47:50 +0000 | [diff] [blame] | 630 | |
Rafael Espindola | 3abe3aa | 2016-07-21 21:15:32 +0000 | [diff] [blame] | 631 | ArrayRef<EhSectionPiece> Pieces; |
| 632 | if (auto *Eh = dyn_cast<EhInputSection<ELFT>>(&C)) |
| 633 | Pieces = Eh->Pieces; |
| 634 | |
| 635 | ArrayRef<EhSectionPiece>::iterator PieceI = Pieces.begin(); |
| 636 | ArrayRef<EhSectionPiece>::iterator PieceE = Pieces.end(); |
Rafael Espindola | 5b7a79f | 2016-07-20 11:47:50 +0000 | [diff] [blame] | 637 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 638 | for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) { |
| 639 | const RelTy &RI = *I; |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 640 | SymbolBody &Body = File->getRelocTargetSym(RI); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 641 | uint32_t Type = RI.getType(Config->Mips64EL); |
| 642 | |
Simon Atanasyan | 9e0297b | 2016-11-05 22:58:01 +0000 | [diff] [blame] | 643 | if (Config->MipsN32Abi) { |
| 644 | uint32_t Processed; |
| 645 | std::tie(Type, Processed) = |
| 646 | mergeMipsN32RelTypes(Type, RI.r_offset, I + 1, E); |
| 647 | I += Processed; |
| 648 | } |
| 649 | |
George Rimar | a4c7e74 | 2016-10-20 08:36:42 +0000 | [diff] [blame] | 650 | // We only report undefined symbols if they are referenced somewhere in the |
| 651 | // code. |
Eugene Leviant | 8983759 | 2016-10-06 09:45:04 +0000 | [diff] [blame] | 652 | if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak()) |
Eugene Leviant | b380b24 | 2016-10-26 11:07:09 +0000 | [diff] [blame] | 653 | reportUndefined(Body, C, RI.r_offset); |
Eugene Leviant | 8983759 | 2016-10-06 09:45:04 +0000 | [diff] [blame] | 654 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 655 | RelExpr Expr = Target->getRelExpr(Type, Body); |
Rafael Espindola | 678844e | 2016-06-17 15:42:36 +0000 | [diff] [blame] | 656 | bool Preemptible = isPreemptible(Body, Type); |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 657 | Expr = adjustExpr(*File, Body, IsWrite, Expr, Type, Buf + RI.r_offset, C, |
| 658 | RI.r_offset); |
Rafael Espindola | 678844e | 2016-06-17 15:42:36 +0000 | [diff] [blame] | 659 | if (HasError) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 660 | continue; |
| 661 | |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 662 | // Skip a relocation that points to a dead piece |
Rafael Espindola | 5b7a79f | 2016-07-20 11:47:50 +0000 | [diff] [blame] | 663 | // in a eh_frame section. |
| 664 | while (PieceI != PieceE && |
| 665 | (PieceI->InputOff + PieceI->size() <= RI.r_offset)) |
| 666 | ++PieceI; |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 667 | |
| 668 | // Compute the offset of this section in the output section. We do it here |
| 669 | // to try to compute it only once. |
| 670 | uintX_t Offset; |
| 671 | if (PieceI != PieceE) { |
| 672 | assert(PieceI->InputOff <= RI.r_offset && "Relocation not in any piece"); |
Rafael Espindola | 113860b | 2016-10-20 10:55:58 +0000 | [diff] [blame] | 673 | if (PieceI->OutputOff == -1) |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 674 | continue; |
| 675 | Offset = PieceI->OutputOff + RI.r_offset - PieceI->InputOff; |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 676 | } else { |
George Rimar | 3e6833b | 2016-08-19 15:46:28 +0000 | [diff] [blame] | 677 | Offset = RI.r_offset; |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 678 | } |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 679 | |
| 680 | // This relocation does not require got entry, but it is relative to got and |
| 681 | // needs it to be created. Here we request for that. |
Rafael Espindola | 79202c3 | 2016-08-31 23:24:11 +0000 | [diff] [blame] | 682 | if (Expr == R_GOTONLY_PC || Expr == R_GOTONLY_PC_FROM_END || |
| 683 | Expr == R_GOTREL || Expr == R_GOTREL_FROM_END || Expr == R_PPC_TOC) |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 684 | In<ELFT>::Got->HasGotOffRel = true; |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 685 | |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 686 | uintX_t Addend = computeAddend(*File, Buf, E, RI, Expr, Body); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 687 | |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 688 | if (unsigned Processed = |
| 689 | handleTlsRelocation<ELFT>(Type, Body, C, Offset, Addend, Expr)) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 690 | I += (Processed - 1); |
| 691 | continue; |
| 692 | } |
| 693 | |
Peter Smith | d648603 | 2016-10-20 09:59:26 +0000 | [diff] [blame] | 694 | // Ignore "hint" and TLS Descriptor call relocation because they are |
| 695 | // only markers for relaxation. |
| 696 | if (Expr == R_HINT || Expr == R_TLSDESC_CALL) |
Rafael Espindola | e37d13b | 2016-06-02 19:49:53 +0000 | [diff] [blame] | 697 | continue; |
| 698 | |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 699 | if (needsPlt(Expr) || Expr == R_THUNK_ABS || Expr == R_THUNK_PC || |
| 700 | Expr == R_THUNK_PLT_PC || refersToGotEntry(Expr) || |
Simon Atanasyan | 9a9a316 | 2016-05-28 04:49:57 +0000 | [diff] [blame] | 701 | !isPreemptible(Body, Type)) { |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 702 | // If the relocation points to something in the file, we can process it. |
George Rimar | 463984d | 2016-11-15 08:07:14 +0000 | [diff] [blame] | 703 | bool Constant = |
| 704 | isStaticLinkTimeConstant<ELFT>(Expr, Type, Body, C, RI.r_offset); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 705 | |
| 706 | // If the output being produced is position independent, the final value |
| 707 | // is still not known. In that case we still need some help from the |
| 708 | // dynamic linker. We can however do better than just copying the incoming |
| 709 | // relocation. We can process some of it and and just ask the dynamic |
| 710 | // linker to add the load address. |
| 711 | if (!Constant) |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 712 | AddDyn({Target->RelativeRel, &C, Offset, true, &Body, Addend}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 713 | |
| 714 | // If the produced value is a constant, we just remember to write it |
| 715 | // when outputting this section. We also have to do it if the format |
| 716 | // uses Elf_Rel, since in that case the written value is the addend. |
| 717 | if (Constant || !RelTy::IsRela) |
Rafael Espindola | 664c652 | 2016-09-07 20:37:34 +0000 | [diff] [blame] | 718 | C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 719 | } else { |
| 720 | // We don't know anything about the finaly symbol. Just ask the dynamic |
| 721 | // linker to handle the relocation for us. |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 722 | AddDyn({Target->getDynRel(Type), &C, Offset, false, &Body, Addend}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 723 | // MIPS ABI turns using of GOT and dynamic relocations inside out. |
| 724 | // While regular ABI uses dynamic relocations to fill up GOT entries |
| 725 | // MIPS ABI requires dynamic linker to fills up GOT entries using |
| 726 | // specially sorted dynamic symbol table. This affects even dynamic |
| 727 | // relocations against symbols which do not require GOT entries |
| 728 | // creation explicitly, i.e. do not have any GOT-relocations. So if |
| 729 | // a preemptible symbol has a dynamic relocation we anyway have |
| 730 | // to create a GOT entry for it. |
| 731 | // If a non-preemptible symbol has a dynamic relocation against it, |
| 732 | // dynamic linker takes it st_value, adds offset and writes down |
| 733 | // result of the dynamic relocation. In case of preemptible symbol |
| 734 | // dynamic linker performs symbol resolution, writes the symbol value |
| 735 | // to the GOT entry and reads the GOT entry when it needs to perform |
| 736 | // a dynamic relocation. |
| 737 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf p.4-19 |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 738 | if (Config->EMachine == EM_MIPS) |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 739 | In<ELFT>::Got->addMipsEntry(Body, Addend, Expr); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 740 | continue; |
| 741 | } |
| 742 | |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 743 | // At this point we are done with the relocated position. Some relocations |
| 744 | // also require us to create a got or plt entry. |
| 745 | |
| 746 | // If a relocation needs PLT, we create a PLT and a GOT slot for the symbol. |
| 747 | if (needsPlt(Expr)) { |
| 748 | if (Body.isInPlt()) |
| 749 | continue; |
| 750 | Out<ELFT>::Plt->addEntry(Body); |
| 751 | |
| 752 | uint32_t Rel; |
| 753 | if (Body.isGnuIFunc() && !Preemptible) |
| 754 | Rel = Target->IRelativeRel; |
| 755 | else |
| 756 | Rel = Target->PltRel; |
| 757 | |
Eugene Leviant | 41ca327 | 2016-11-10 09:48:29 +0000 | [diff] [blame] | 758 | In<ELFT>::GotPlt->addEntry(Body); |
Eugene Leviant | a96d902 | 2016-11-16 10:02:27 +0000 | [diff] [blame] | 759 | In<ELFT>::RelaPlt->addReloc({Rel, In<ELFT>::GotPlt, |
| 760 | Body.getGotPltOffset<ELFT>(), !Preemptible, |
| 761 | &Body, 0}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 762 | continue; |
| 763 | } |
| 764 | |
| 765 | if (refersToGotEntry(Expr)) { |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 766 | if (Config->EMachine == EM_MIPS) { |
Simon Atanasyan | af52f6a | 2016-09-08 09:07:12 +0000 | [diff] [blame] | 767 | // MIPS ABI has special rules to process GOT entries and doesn't |
| 768 | // require relocation entries for them. A special case is TLS |
| 769 | // relocations. In that case dynamic loader applies dynamic |
| 770 | // relocations to initialize TLS GOT entries. |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 771 | // See "Global Offset Table" in Chapter 5 in the following document |
| 772 | // for detailed description: |
| 773 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 774 | In<ELFT>::Got->addMipsEntry(Body, Addend, Expr); |
Simon Atanasyan | 919a58c | 2016-09-08 09:07:19 +0000 | [diff] [blame] | 775 | if (Body.isTls() && Body.isPreemptible()) |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 776 | AddDyn({Target->TlsGotRel, In<ELFT>::Got, Body.getGotOffset<ELFT>(), |
Simon Atanasyan | 919a58c | 2016-09-08 09:07:19 +0000 | [diff] [blame] | 777 | false, &Body, 0}); |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 778 | continue; |
| 779 | } |
| 780 | |
| 781 | if (Body.isInGot()) |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 782 | continue; |
| 783 | |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 784 | In<ELFT>::Got->addEntry(Body); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 785 | if (Preemptible || (Config->Pic && !isAbsolute<ELFT>(Body))) { |
| 786 | uint32_t DynType; |
| 787 | if (Body.isTls()) |
| 788 | DynType = Target->TlsGotRel; |
| 789 | else if (Preemptible) |
| 790 | DynType = Target->GotRel; |
| 791 | else |
| 792 | DynType = Target->RelativeRel; |
Eugene Leviant | ad4439e | 2016-11-11 11:33:32 +0000 | [diff] [blame] | 793 | AddDyn({DynType, In<ELFT>::Got, Body.getGotOffset<ELFT>(), !Preemptible, |
| 794 | &Body, 0}); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 795 | } |
| 796 | continue; |
| 797 | } |
| 798 | } |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 801 | template <class ELFT> void scanRelocations(InputSectionBase<ELFT> &S) { |
| 802 | if (S.AreRelocsRela) |
| 803 | scanRelocs(S, S.relas()); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 804 | else |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 805 | scanRelocs(S, S.rels()); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 808 | template <class ELFT, class RelTy> |
| 809 | static void createThunks(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) { |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 810 | const elf::ObjectFile<ELFT> *File = C.getFile(); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 811 | for (const RelTy &Rel : Rels) { |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 812 | SymbolBody &Body = File->getRelocTargetSym(Rel); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 813 | uint32_t Type = Rel.getType(Config->Mips64EL); |
| 814 | RelExpr Expr = Target->getRelExpr(Type, Body); |
| 815 | if (!isPreemptible(Body, Type) && needsPlt(Expr)) |
| 816 | Expr = fromPlt(Expr); |
Vitaly Buka | 029d730 | 2016-11-15 07:32:51 +0000 | [diff] [blame] | 817 | Expr = Target->getThunkExpr(Expr, Type, *File, Body); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 818 | // Some targets might require creation of thunks for relocations. |
| 819 | // Now we support only MIPS which requires LA25 thunk to call PIC |
| 820 | // code from non-PIC one, and ARM which requires interworking. |
| 821 | if (Expr == R_THUNK_ABS || Expr == R_THUNK_PC || Expr == R_THUNK_PLT_PC) { |
| 822 | auto *Sec = cast<InputSection<ELFT>>(&C); |
| 823 | addThunk<ELFT>(Type, Body, *Sec); |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 828 | template <class ELFT> void createThunks(InputSectionBase<ELFT> &S) { |
| 829 | if (S.AreRelocsRela) |
| 830 | createThunks(S, S.relas()); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 831 | else |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 832 | createThunks(S, S.rels()); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 833 | } |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 834 | |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 835 | template void scanRelocations<ELF32LE>(InputSectionBase<ELF32LE> &); |
| 836 | template void scanRelocations<ELF32BE>(InputSectionBase<ELF32BE> &); |
| 837 | template void scanRelocations<ELF64LE>(InputSectionBase<ELF64LE> &); |
| 838 | template void scanRelocations<ELF64BE>(InputSectionBase<ELF64BE> &); |
Rafael Espindola | 0f7ceda | 2016-07-20 17:58:07 +0000 | [diff] [blame] | 839 | |
Rafael Espindola | 9f0c4bb | 2016-11-10 14:53:24 +0000 | [diff] [blame] | 840 | template void createThunks<ELF32LE>(InputSectionBase<ELF32LE> &); |
| 841 | template void createThunks<ELF32BE>(InputSectionBase<ELF32BE> &); |
| 842 | template void createThunks<ELF64LE>(InputSectionBase<ELF64LE> &); |
| 843 | template void createThunks<ELF64BE>(InputSectionBase<ELF64BE> &); |
Eugene Leviant | 825e538 | 2016-11-08 16:26:32 +0000 | [diff] [blame] | 844 | |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 845 | template std::string getLocation<ELF32LE>(InputSectionBase<ELF32LE> &S, |
Eugene Leviant | 825e538 | 2016-11-08 16:26:32 +0000 | [diff] [blame] | 846 | uint32_t Offset); |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 847 | template std::string getLocation<ELF32BE>(InputSectionBase<ELF32BE> &S, |
Eugene Leviant | 825e538 | 2016-11-08 16:26:32 +0000 | [diff] [blame] | 848 | uint32_t Offset); |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 849 | template std::string getLocation<ELF64LE>(InputSectionBase<ELF64LE> &S, |
Eugene Leviant | 825e538 | 2016-11-08 16:26:32 +0000 | [diff] [blame] | 850 | uint64_t Offset); |
Rui Ueyama | edc183e | 2016-11-08 20:30:19 +0000 | [diff] [blame] | 851 | template std::string getLocation<ELF64BE>(InputSectionBase<ELF64BE> &S, |
Eugene Leviant | 825e538 | 2016-11-08 16:26:32 +0000 | [diff] [blame] | 852 | uint64_t Offset); |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 853 | } |
| 854 | } |