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