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