| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 1 | //===- Symbols.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 | |
| 10 | #include "Symbols.h" |
| Rafael Espindola | 49a2ca6 | 2015-08-06 15:33:19 +0000 | [diff] [blame] | 11 | #include "Error.h" |
| Michael J. Spencer | cdae0a4 | 2015-07-28 22:58:25 +0000 | [diff] [blame] | 12 | #include "InputFiles.h" |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 13 | #include "InputSection.h" |
| 14 | #include "OutputSections.h" |
| 15 | #include "Target.h" |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 16 | |
| Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | |
| 19 | using namespace llvm; |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 20 | using namespace llvm::object; |
| Rafael Espindola | 78471f0 | 2015-09-01 23:12:52 +0000 | [diff] [blame] | 21 | using namespace llvm::ELF; |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace lld; |
| Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 24 | using namespace lld::elf; |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 25 | |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 26 | template <class ELFT> |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 27 | static typename ELFT::uint getSymVA(const SymbolBody &Body, |
| 28 | typename ELFT::uint &Addend) { |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 29 | typedef typename ELFT::uint uintX_t; |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 30 | |
| 31 | switch (Body.kind()) { |
| 32 | case SymbolBody::DefinedSyntheticKind: { |
| 33 | auto &D = cast<DefinedSynthetic<ELFT>>(Body); |
| Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 34 | const OutputSectionBase<ELFT> *Sec = D.Section; |
| 35 | if (!Sec) |
| 36 | return D.Value; |
| Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 37 | if (D.Value == DefinedSynthetic<ELFT>::SectionEnd) |
| Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 38 | return Sec->getVA() + Sec->getSize(); |
| 39 | return Sec->getVA() + D.Value; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 40 | } |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 41 | case SymbolBody::DefinedRegularKind: { |
| 42 | auto &D = cast<DefinedRegular<ELFT>>(Body); |
| 43 | InputSectionBase<ELFT> *SC = D.Section; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 44 | |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 45 | // According to the ELF spec reference to a local symbol from outside |
| 46 | // the group are not allowed. Unfortunately .eh_frame breaks that rule |
| 47 | // and must be treated specially. For now we just replace the symbol with |
| 48 | // 0. |
| 49 | if (SC == &InputSection<ELFT>::Discarded) |
| 50 | return 0; |
| 51 | |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 52 | // This is an absolute symbol. |
| 53 | if (!SC) |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 54 | return D.Value; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 55 | |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 56 | uintX_t Offset = D.Value; |
| 57 | if (D.isSection()) { |
| Rafael Espindola | 1f5b70f | 2016-03-11 14:21:37 +0000 | [diff] [blame] | 58 | Offset += Addend; |
| 59 | Addend = 0; |
| 60 | } |
| Eugene Leviant | ceabe80 | 2016-08-11 07:56:43 +0000 | [diff] [blame] | 61 | uintX_t VA = (SC->OutSec ? SC->OutSec->getVA() : 0) + SC->getOffset(Offset); |
| Simon Atanasyan | d10a5ea | 2016-09-14 16:26:19 +0000 | [diff] [blame] | 62 | if (D.isTls() && !Config->Relocatable) |
| Rafael Espindola | 1f5b70f | 2016-03-11 14:21:37 +0000 | [diff] [blame] | 63 | return VA - Out<ELFT>::TlsPhdr->p_vaddr; |
| 64 | return VA; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 65 | } |
| Rui Ueyama | 0778490 | 2016-08-02 01:35:13 +0000 | [diff] [blame] | 66 | case SymbolBody::DefinedCommonKind: |
| 67 | return CommonInputSection<ELFT>::X->OutSec->getVA() + |
| 68 | CommonInputSection<ELFT>::X->OutSecOff + |
| Rafael Espindola | e7553e4 | 2016-08-31 13:28:33 +0000 | [diff] [blame] | 69 | cast<DefinedCommon>(Body).Offset; |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 70 | case SymbolBody::SharedKind: { |
| 71 | auto &SS = cast<SharedSymbol<ELFT>>(Body); |
| 72 | if (!SS.NeedsCopyOrPltAddr) |
| Rafael Espindola | a0a65f9 | 2016-02-09 15:11:01 +0000 | [diff] [blame] | 73 | return 0; |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 74 | if (SS.isFunc()) |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 75 | return Body.getPltVA<ELFT>(); |
| Rui Ueyama | 2df7289 | 2016-03-13 20:54:38 +0000 | [diff] [blame] | 76 | return Out<ELFT>::Bss->getVA() + SS.OffsetInBss; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 77 | } |
| Peter Collingbourne | 60976ed | 2016-04-27 00:05:06 +0000 | [diff] [blame] | 78 | case SymbolBody::UndefinedKind: |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 79 | return 0; |
| Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 80 | case SymbolBody::LazyArchiveKind: |
| 81 | case SymbolBody::LazyObjectKind: |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 82 | assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer"); |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| George Rimar | 777f963 | 2016-03-12 08:31:34 +0000 | [diff] [blame] | 85 | llvm_unreachable("invalid symbol kind"); |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| Rui Ueyama | b5792b2 | 2016-04-04 19:09:08 +0000 | [diff] [blame] | 88 | SymbolBody::SymbolBody(Kind K, uint32_t NameOffset, uint8_t StOther, |
| 89 | uint8_t Type) |
| Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 90 | : SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(true), |
| 91 | IsInGlobalMipsGot(false), Type(Type), StOther(StOther), |
| 92 | NameOffset(NameOffset) {} |
| Rafael Espindola | f476573 | 2016-04-06 13:22:41 +0000 | [diff] [blame] | 93 | |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 94 | SymbolBody::SymbolBody(Kind K, StringRef Name, uint8_t StOther, uint8_t Type) |
| Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 95 | : SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(false), |
| 96 | IsInGlobalMipsGot(false), Type(Type), StOther(StOther), |
| 97 | Name({Name.data(), Name.size()}) {} |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 98 | |
| George Rimar | 4365158 | 2016-06-28 08:21:10 +0000 | [diff] [blame] | 99 | StringRef SymbolBody::getName() const { |
| 100 | assert(!isLocal()); |
| Rui Ueyama | 663b8c2 | 2016-07-17 17:23:17 +0000 | [diff] [blame] | 101 | return StringRef(Name.S, Name.Len); |
| 102 | } |
| 103 | |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 104 | // Returns true if a symbol can be replaced at load-time by a symbol |
| 105 | // with the same name defined in other ELF executable or DSO. |
| 106 | bool SymbolBody::isPreemptible() const { |
| 107 | if (isLocal()) |
| 108 | return false; |
| 109 | |
| Rafael Espindola | 6643456 | 2016-05-05 19:41:49 +0000 | [diff] [blame] | 110 | // Shared symbols resolve to the definition in the DSO. The exceptions are |
| 111 | // symbols with copy relocations (which resolve to .bss) or preempt plt |
| 112 | // entries (which resolve to that plt entry). |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 113 | if (isShared()) |
| Rafael Espindola | 6643456 | 2016-05-05 19:41:49 +0000 | [diff] [blame] | 114 | return !NeedsCopyOrPltAddr; |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 115 | |
| Peter Collingbourne | 66ac1d6 | 2016-04-22 20:21:26 +0000 | [diff] [blame] | 116 | // That's all that can be preempted in a non-DSO. |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 117 | if (!Config->Shared) |
| 118 | return false; |
| Peter Collingbourne | 66ac1d6 | 2016-04-22 20:21:26 +0000 | [diff] [blame] | 119 | |
| Peter Collingbourne | dbe4187 | 2016-04-24 04:29:59 +0000 | [diff] [blame] | 120 | // Only symbols that appear in dynsym can be preempted. |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 121 | if (!symbol()->includeInDynsym()) |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 122 | return false; |
| Peter Collingbourne | 66ac1d6 | 2016-04-22 20:21:26 +0000 | [diff] [blame] | 123 | |
| Rafael Espindola | 580d7a1 | 2016-07-07 22:50:54 +0000 | [diff] [blame] | 124 | // Only default visibility symbols can be preempted. |
| 125 | if (symbol()->Visibility != STV_DEFAULT) |
| 126 | return false; |
| 127 | |
| 128 | // -Bsymbolic means that definitions are not preempted. |
| Peter Collingbourne | dbe4187 | 2016-04-24 04:29:59 +0000 | [diff] [blame] | 129 | if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc())) |
| 130 | return !isDefined(); |
| Rafael Espindola | 580d7a1 | 2016-07-07 22:50:54 +0000 | [diff] [blame] | 131 | return true; |
| Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 134 | template <class ELFT> bool SymbolBody::hasThunk() const { |
| 135 | if (auto *DR = dyn_cast<DefinedRegular<ELFT>>(this)) |
| 136 | return DR->ThunkData != nullptr; |
| 137 | if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this)) |
| 138 | return S->ThunkData != nullptr; |
| 139 | return false; |
| 140 | } |
| 141 | |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 142 | template <class ELFT> |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 143 | typename ELFT::uint SymbolBody::getVA(typename ELFT::uint Addend) const { |
| Rafael Espindola | 8381c56 | 2016-03-17 23:36:19 +0000 | [diff] [blame] | 144 | typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend); |
| 145 | return OutVA + Addend; |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 148 | template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const { |
| Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 149 | return Out<ELFT>::Got->getVA() + getGotOffset<ELFT>(); |
| 150 | } |
| 151 | |
| 152 | template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const { |
| Rui Ueyama | 803b120 | 2016-07-13 18:55:14 +0000 | [diff] [blame] | 153 | return GotIndex * Target->GotEntrySize; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 156 | template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const { |
| Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 157 | return Out<ELFT>::GotPlt->getVA() + getGotPltOffset<ELFT>(); |
| 158 | } |
| 159 | |
| 160 | template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const { |
| Rui Ueyama | 803b120 | 2016-07-13 18:55:14 +0000 | [diff] [blame] | 161 | return GotPltIndex * Target->GotPltEntrySize; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 164 | template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const { |
| Rui Ueyama | 4a90f57 | 2016-06-16 16:28:50 +0000 | [diff] [blame] | 165 | return Out<ELFT>::Plt->getVA() + Target->PltHeaderSize + |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 166 | PltIndex * Target->PltEntrySize; |
| 167 | } |
| 168 | |
| Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 169 | template <class ELFT> typename ELFT::uint SymbolBody::getThunkVA() const { |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 170 | if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this)) |
| 171 | return DR->ThunkData->getVA(); |
| 172 | if (const auto *S = dyn_cast<SharedSymbol<ELFT>>(this)) |
| 173 | return S->ThunkData->getVA(); |
| 174 | fatal("getThunkVA() not supported for Symbol class\n"); |
| Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 177 | template <class ELFT> typename ELFT::uint SymbolBody::getSize() const { |
| Rafael Espindola | e7553e4 | 2016-08-31 13:28:33 +0000 | [diff] [blame] | 178 | if (const auto *C = dyn_cast<DefinedCommon>(this)) |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 179 | return C->Size; |
| 180 | if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this)) |
| 181 | return DR->Size; |
| 182 | if (const auto *S = dyn_cast<SharedSymbol<ELFT>>(this)) |
| 183 | return S->Sym.st_size; |
| Rui Ueyama | 512c61d | 2016-02-03 00:12:24 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 187 | Defined::Defined(Kind K, StringRef Name, uint8_t StOther, uint8_t Type) |
| 188 | : SymbolBody(K, Name, StOther, Type) {} |
| Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 189 | |
| Rafael Espindola | f9b79a4 | 2016-04-06 12:14:31 +0000 | [diff] [blame] | 190 | Defined::Defined(Kind K, uint32_t NameOffset, uint8_t StOther, uint8_t Type) |
| 191 | : SymbolBody(K, NameOffset, StOther, Type) {} |
| Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 192 | |
| Simon Atanasyan | f967f09 | 2016-09-29 12:58:36 +0000 | [diff] [blame^] | 193 | template <class ELFT> bool DefinedRegular<ELFT>::isMipsPIC() const { |
| 194 | if (!Section || !isFunc()) |
| 195 | return false; |
| 196 | return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC || |
| 197 | (Section->getFile()->getObj().getHeader()->e_flags & EF_MIPS_PIC); |
| 198 | } |
| 199 | |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 200 | Undefined::Undefined(StringRef Name, uint8_t StOther, uint8_t Type, |
| 201 | InputFile *File) |
| 202 | : SymbolBody(SymbolBody::UndefinedKind, Name, StOther, Type) { |
| 203 | this->File = File; |
| 204 | } |
| Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 205 | |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 206 | Undefined::Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type, |
| 207 | InputFile *File) |
| 208 | : SymbolBody(SymbolBody::UndefinedKind, NameOffset, StOther, Type) { |
| 209 | this->File = File; |
| 210 | } |
| Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 211 | |
| Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 212 | template <typename ELFT> |
| 213 | DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value, |
| Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 214 | OutputSectionBase<ELFT> *Section) |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 215 | : Defined(SymbolBody::DefinedSyntheticKind, N, STV_HIDDEN, 0 /* Type */), |
| Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 216 | Value(Value), Section(Section) {} |
| 217 | |
| Rafael Espindola | e7553e4 | 2016-08-31 13:28:33 +0000 | [diff] [blame] | 218 | DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, |
| 219 | uint8_t StOther, uint8_t Type, InputFile *File) |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 220 | : Defined(SymbolBody::DefinedCommonKind, N, StOther, Type), |
| Rui Ueyama | 2a7c1c1 | 2016-07-17 17:36:22 +0000 | [diff] [blame] | 221 | Alignment(Alignment), Size(Size) { |
| 222 | this->File = File; |
| 223 | } |
| Rafael Espindola | 1119191 | 2015-12-24 16:23:37 +0000 | [diff] [blame] | 224 | |
| Rui Ueyama | 38dbd3e | 2016-09-14 00:05:51 +0000 | [diff] [blame] | 225 | InputFile *Lazy::fetch() { |
| Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 226 | if (auto *S = dyn_cast<LazyArchive>(this)) |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 227 | return S->fetch(); |
| 228 | return cast<LazyObject>(this)->fetch(); |
| Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 231 | LazyArchive::LazyArchive(ArchiveFile &File, |
| 232 | const llvm::object::Archive::Symbol S, uint8_t Type) |
| 233 | : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) { |
| 234 | this->File = &File; |
| 235 | } |
| 236 | |
| 237 | LazyObject::LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type) |
| 238 | : Lazy(LazyObjectKind, Name, Type) { |
| 239 | this->File = &File; |
| 240 | } |
| 241 | |
| Rui Ueyama | 38dbd3e | 2016-09-14 00:05:51 +0000 | [diff] [blame] | 242 | InputFile *LazyArchive::fetch() { |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 243 | MemoryBufferRef MBRef = file()->getMember(&Sym); |
| Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 244 | |
| 245 | // getMember returns an empty buffer if the member was already |
| 246 | // read from the library. |
| 247 | if (MBRef.getBuffer().empty()) |
| Rui Ueyama | 38dbd3e | 2016-09-14 00:05:51 +0000 | [diff] [blame] | 248 | return nullptr; |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 249 | return createObjectFile(MBRef, file()->getName()); |
| Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| Rui Ueyama | 38dbd3e | 2016-09-14 00:05:51 +0000 | [diff] [blame] | 252 | InputFile *LazyObject::fetch() { |
| Rui Ueyama | 434b561 | 2016-07-17 03:11:46 +0000 | [diff] [blame] | 253 | MemoryBufferRef MBRef = file()->getBuffer(); |
| Rafael Espindola | 65c65ce | 2016-06-14 21:56:36 +0000 | [diff] [blame] | 254 | if (MBRef.getBuffer().empty()) |
| Rui Ueyama | 38dbd3e | 2016-09-14 00:05:51 +0000 | [diff] [blame] | 255 | return nullptr; |
| Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 256 | return createObjectFile(MBRef); |
| 257 | } |
| 258 | |
| Peter Collingbourne | dadcc17 | 2016-04-22 18:42:48 +0000 | [diff] [blame] | 259 | bool Symbol::includeInDynsym() const { |
| 260 | if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) |
| Rafael Espindola | ae605c1 | 2016-04-21 20:35:25 +0000 | [diff] [blame] | 261 | return false; |
| George Rimar | d356630 | 2016-06-20 11:55:12 +0000 | [diff] [blame] | 262 | return (ExportDynamic && VersionId != VER_NDX_LOCAL) || body()->isShared() || |
| Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 263 | (body()->isUndefined() && Config->Shared); |
| Rafael Espindola | ae605c1 | 2016-04-21 20:35:25 +0000 | [diff] [blame] | 264 | } |
| Rui Ueyama | 69c778c | 2016-07-17 17:50:09 +0000 | [diff] [blame] | 265 | |
| 266 | // Print out a log message for --trace-symbol. |
| 267 | void elf::printTraceSymbol(Symbol *Sym) { |
| 268 | SymbolBody *B = Sym->body(); |
| 269 | outs() << getFilename(B->File); |
| 270 | |
| 271 | if (B->isUndefined()) |
| 272 | outs() << ": reference to "; |
| 273 | else if (B->isCommon()) |
| 274 | outs() << ": common definition of "; |
| 275 | else |
| 276 | outs() << ": definition of "; |
| 277 | outs() << B->getName() << "\n"; |
| 278 | } |
| 279 | |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 280 | template bool SymbolBody::hasThunk<ELF32LE>() const; |
| 281 | template bool SymbolBody::hasThunk<ELF32BE>() const; |
| 282 | template bool SymbolBody::hasThunk<ELF64LE>() const; |
| 283 | template bool SymbolBody::hasThunk<ELF64BE>() const; |
| Rafael Espindola | ae605c1 | 2016-04-21 20:35:25 +0000 | [diff] [blame] | 284 | |
| Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 285 | template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const; |
| 286 | template uint32_t SymbolBody::template getVA<ELF32BE>(uint32_t) const; |
| 287 | template uint64_t SymbolBody::template getVA<ELF64LE>(uint64_t) const; |
| 288 | template uint64_t SymbolBody::template getVA<ELF64BE>(uint64_t) const; |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 289 | |
| 290 | template uint32_t SymbolBody::template getGotVA<ELF32LE>() const; |
| 291 | template uint32_t SymbolBody::template getGotVA<ELF32BE>() const; |
| 292 | template uint64_t SymbolBody::template getGotVA<ELF64LE>() const; |
| 293 | template uint64_t SymbolBody::template getGotVA<ELF64BE>() const; |
| 294 | |
| Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 295 | template uint32_t SymbolBody::template getGotOffset<ELF32LE>() const; |
| 296 | template uint32_t SymbolBody::template getGotOffset<ELF32BE>() const; |
| 297 | template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const; |
| 298 | template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const; |
| 299 | |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 300 | template uint32_t SymbolBody::template getGotPltVA<ELF32LE>() const; |
| 301 | template uint32_t SymbolBody::template getGotPltVA<ELF32BE>() const; |
| 302 | template uint64_t SymbolBody::template getGotPltVA<ELF64LE>() const; |
| 303 | template uint64_t SymbolBody::template getGotPltVA<ELF64BE>() const; |
| 304 | |
| Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 305 | template uint32_t SymbolBody::template getThunkVA<ELF32LE>() const; |
| 306 | template uint32_t SymbolBody::template getThunkVA<ELF32BE>() const; |
| 307 | template uint64_t SymbolBody::template getThunkVA<ELF64LE>() const; |
| 308 | template uint64_t SymbolBody::template getThunkVA<ELF64BE>() const; |
| 309 | |
| Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 310 | template uint32_t SymbolBody::template getGotPltOffset<ELF32LE>() const; |
| 311 | template uint32_t SymbolBody::template getGotPltOffset<ELF32BE>() const; |
| 312 | template uint64_t SymbolBody::template getGotPltOffset<ELF64LE>() const; |
| 313 | template uint64_t SymbolBody::template getGotPltOffset<ELF64BE>() const; |
| 314 | |
| Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 315 | template uint32_t SymbolBody::template getPltVA<ELF32LE>() const; |
| 316 | template uint32_t SymbolBody::template getPltVA<ELF32BE>() const; |
| 317 | template uint64_t SymbolBody::template getPltVA<ELF64LE>() const; |
| 318 | template uint64_t SymbolBody::template getPltVA<ELF64BE>() const; |
| 319 | |
| Rui Ueyama | 512c61d | 2016-02-03 00:12:24 +0000 | [diff] [blame] | 320 | template uint32_t SymbolBody::template getSize<ELF32LE>() const; |
| 321 | template uint32_t SymbolBody::template getSize<ELF32BE>() const; |
| 322 | template uint64_t SymbolBody::template getSize<ELF64LE>() const; |
| 323 | template uint64_t SymbolBody::template getSize<ELF64BE>() const; |
| 324 | |
| Simon Atanasyan | f967f09 | 2016-09-29 12:58:36 +0000 | [diff] [blame^] | 325 | template class elf::DefinedRegular<ELF32LE>; |
| 326 | template class elf::DefinedRegular<ELF32BE>; |
| 327 | template class elf::DefinedRegular<ELF64LE>; |
| 328 | template class elf::DefinedRegular<ELF64BE>; |
| 329 | |
| Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 330 | template class elf::DefinedSynthetic<ELF32LE>; |
| 331 | template class elf::DefinedSynthetic<ELF32BE>; |
| 332 | template class elf::DefinedSynthetic<ELF64LE>; |
| 333 | template class elf::DefinedSynthetic<ELF64BE>; |