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