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" |
Rui Ueyama | a4a628f | 2016-01-13 18:55:39 +0000 | [diff] [blame] | 18 | #include "llvm/Config/config.h" |
| 19 | |
| 20 | #ifdef HAVE_CXXABI_H |
| 21 | #include <cxxabi.h> |
| 22 | #endif |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 25 | using namespace llvm::object; |
Rafael Espindola | 78471f0 | 2015-09-01 23:12:52 +0000 | [diff] [blame] | 26 | using namespace llvm::ELF; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace lld; |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 29 | using namespace lld::elf; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 30 | |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 31 | template <class ELFT> |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 32 | static typename ELFT::uint getSymVA(const SymbolBody &Body, |
| 33 | typename ELFT::uint &Addend) { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 34 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 35 | |
| 36 | switch (Body.kind()) { |
| 37 | case SymbolBody::DefinedSyntheticKind: { |
| 38 | auto &D = cast<DefinedSynthetic<ELFT>>(Body); |
Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 39 | const OutputSectionBase<ELFT> *Sec = D.Section; |
| 40 | if (!Sec) |
| 41 | return D.Value; |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 42 | if (D.Value == DefinedSynthetic<ELFT>::SectionEnd) |
Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 43 | return Sec->getVA() + Sec->getSize(); |
| 44 | return Sec->getVA() + D.Value; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 45 | } |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 46 | case SymbolBody::DefinedRegularKind: { |
| 47 | auto &D = cast<DefinedRegular<ELFT>>(Body); |
| 48 | InputSectionBase<ELFT> *SC = D.Section; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 49 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 50 | // According to the ELF spec reference to a local symbol from outside |
| 51 | // the group are not allowed. Unfortunately .eh_frame breaks that rule |
| 52 | // and must be treated specially. For now we just replace the symbol with |
| 53 | // 0. |
| 54 | if (SC == &InputSection<ELFT>::Discarded) |
| 55 | return 0; |
| 56 | |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 57 | // This is an absolute symbol. |
| 58 | if (!SC) |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 59 | return D.Value; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 60 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 61 | uintX_t Offset = D.Value; |
| 62 | if (D.isSection()) { |
Rafael Espindola | 1f5b70f | 2016-03-11 14:21:37 +0000 | [diff] [blame] | 63 | Offset += Addend; |
| 64 | Addend = 0; |
| 65 | } |
| 66 | uintX_t VA = SC->OutSec->getVA() + SC->getOffset(Offset); |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 67 | if (D.isTls()) |
Rafael Espindola | 1f5b70f | 2016-03-11 14:21:37 +0000 | [diff] [blame] | 68 | return VA - Out<ELFT>::TlsPhdr->p_vaddr; |
| 69 | return VA; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 70 | } |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 71 | case SymbolBody::DefinedCommonKind: |
| 72 | return Out<ELFT>::Bss->getVA() + cast<DefinedCommon>(Body).OffsetInBss; |
| 73 | case SymbolBody::SharedKind: { |
| 74 | auto &SS = cast<SharedSymbol<ELFT>>(Body); |
| 75 | if (!SS.NeedsCopyOrPltAddr) |
Rafael Espindola | a0a65f9 | 2016-02-09 15:11:01 +0000 | [diff] [blame] | 76 | return 0; |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 77 | if (SS.isFunc()) |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 78 | return Body.getPltVA<ELFT>(); |
Rui Ueyama | 2df7289 | 2016-03-13 20:54:38 +0000 | [diff] [blame] | 79 | return Out<ELFT>::Bss->getVA() + SS.OffsetInBss; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 80 | } |
Peter Collingbourne | 60976ed | 2016-04-27 00:05:06 +0000 | [diff] [blame] | 81 | case SymbolBody::UndefinedKind: |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 82 | return 0; |
Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 83 | case SymbolBody::LazyArchiveKind: |
| 84 | case SymbolBody::LazyObjectKind: |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 85 | assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer"); |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 86 | return 0; |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 87 | case SymbolBody::DefinedBitcodeKind: |
Davide Italiano | f6523ae | 2016-03-29 02:20:10 +0000 | [diff] [blame] | 88 | llvm_unreachable("should have been replaced"); |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 89 | } |
George Rimar | 777f963 | 2016-03-12 08:31:34 +0000 | [diff] [blame] | 90 | llvm_unreachable("invalid symbol kind"); |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Rui Ueyama | b5792b2 | 2016-04-04 19:09:08 +0000 | [diff] [blame] | 93 | SymbolBody::SymbolBody(Kind K, uint32_t NameOffset, uint8_t StOther, |
| 94 | uint8_t Type) |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 95 | : SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(true), |
| 96 | IsInGlobalMipsGot(false), Type(Type), StOther(StOther), |
| 97 | NameOffset(NameOffset) {} |
Rafael Espindola | f476573 | 2016-04-06 13:22:41 +0000 | [diff] [blame] | 98 | |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 99 | SymbolBody::SymbolBody(Kind K, StringRef Name, uint8_t StOther, uint8_t Type) |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 100 | : SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(false), |
| 101 | IsInGlobalMipsGot(false), Type(Type), StOther(StOther), |
| 102 | Name({Name.data(), Name.size()}) {} |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 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 | |
Peter Collingbourne | dbe4187 | 2016-04-24 04:29:59 +0000 | [diff] [blame] | 124 | // Normally only default visibility symbols can be preempted, but -Bsymbolic |
| 125 | // means that not even they can be preempted. |
| 126 | if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc())) |
| 127 | return !isDefined(); |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 128 | return symbol()->Visibility == STV_DEFAULT; |
Rui Ueyama | c446660 | 2016-03-13 19:48:18 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Rui Ueyama | 6d0cd2b | 2016-05-02 21:30:42 +0000 | [diff] [blame] | 131 | template <class ELFT> InputFile *SymbolBody::getSourceFile() { |
| 132 | if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this)) |
| 133 | return S->Section ? S->Section->getFile() : nullptr; |
| 134 | if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this)) |
| 135 | return S->File; |
| 136 | if (auto *S = dyn_cast<DefinedBitcode>(this)) |
| 137 | return S->File; |
| 138 | if (auto *S = dyn_cast<Undefined>(this)) |
| 139 | return S->File; |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 143 | template <class ELFT> |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 144 | typename ELFT::uint SymbolBody::getVA(typename ELFT::uint Addend) const { |
Rafael Espindola | 8381c56 | 2016-03-17 23:36:19 +0000 | [diff] [blame] | 145 | typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend); |
| 146 | return OutVA + Addend; |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 149 | template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const { |
Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 150 | return Out<ELFT>::Got->getVA() + getGotOffset<ELFT>(); |
| 151 | } |
| 152 | |
| 153 | template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const { |
Simon Atanasyan | 4132511 | 2016-06-19 21:39:37 +0000 | [diff] [blame] | 154 | return GotIndex * sizeof(typename ELFT::uint); |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 157 | template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const { |
Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 158 | return Out<ELFT>::GotPlt->getVA() + getGotPltOffset<ELFT>(); |
| 159 | } |
| 160 | |
| 161 | template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const { |
| 162 | return GotPltIndex * sizeof(typename ELFT::uint); |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 165 | template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const { |
Rui Ueyama | 4a90f57 | 2016-06-16 16:28:50 +0000 | [diff] [blame] | 166 | return Out<ELFT>::Plt->getVA() + Target->PltHeaderSize + |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 167 | PltIndex * Target->PltEntrySize; |
| 168 | } |
| 169 | |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 170 | template <class ELFT> typename ELFT::uint SymbolBody::getThunkVA() const { |
| 171 | auto *D = cast<DefinedRegular<ELFT>>(this); |
| 172 | auto *S = cast<InputSection<ELFT>>(D->Section); |
| 173 | return S->OutSec->getVA() + S->OutSecOff + S->getThunkOff() + |
| 174 | ThunkIndex * Target->ThunkSize; |
| 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 | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 178 | if (const auto *C = dyn_cast<DefinedCommon>(this)) |
| 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 | |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 193 | DefinedBitcode::DefinedBitcode(StringRef Name, uint8_t StOther, uint8_t Type, |
| 194 | BitcodeFile *F) |
| 195 | : Defined(DefinedBitcodeKind, Name, StOther, Type), File(F) {} |
Rafael Espindola | 9f77ef0 | 2016-02-12 20:54:57 +0000 | [diff] [blame] | 196 | |
| 197 | bool DefinedBitcode::classof(const SymbolBody *S) { |
| 198 | return S->kind() == DefinedBitcodeKind; |
| 199 | } |
| 200 | |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 201 | Undefined::Undefined(StringRef Name, uint8_t StOther, uint8_t Type) |
| 202 | : SymbolBody(SymbolBody::UndefinedKind, Name, StOther, Type) {} |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 203 | |
Rui Ueyama | 62ee16f | 2016-04-28 00:26:54 +0000 | [diff] [blame] | 204 | Undefined::Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type) |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 205 | : SymbolBody(SymbolBody::UndefinedKind, NameOffset, StOther, Type) {} |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 206 | |
Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 207 | template <typename ELFT> |
| 208 | DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value, |
Peter Collingbourne | 6a42259 | 2016-05-03 01:21:08 +0000 | [diff] [blame] | 209 | OutputSectionBase<ELFT> *Section) |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 210 | : Defined(SymbolBody::DefinedSyntheticKind, N, STV_HIDDEN, 0 /* Type */), |
Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 211 | Value(Value), Section(Section) {} |
| 212 | |
Rafael Espindola | 1119191 | 2015-12-24 16:23:37 +0000 | [diff] [blame] | 213 | DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 214 | uint8_t StOther, uint8_t Type) |
| 215 | : Defined(SymbolBody::DefinedCommonKind, N, StOther, Type), |
Rui Ueyama | 17d6983 | 2016-03-10 18:58:53 +0000 | [diff] [blame] | 216 | Alignment(Alignment), Size(Size) {} |
Rafael Espindola | 1119191 | 2015-12-24 16:23:37 +0000 | [diff] [blame] | 217 | |
Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 218 | std::unique_ptr<InputFile> Lazy::getFile() { |
| 219 | if (auto *S = dyn_cast<LazyArchive>(this)) |
| 220 | return S->getFile(); |
| 221 | return cast<LazyObject>(this)->getFile(); |
| 222 | } |
| 223 | |
| 224 | std::unique_ptr<InputFile> LazyArchive::getFile() { |
Rafael Espindola | 07543a8 | 2016-06-14 21:40:23 +0000 | [diff] [blame] | 225 | MemoryBufferRef MBRef = File.getMember(&Sym); |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 226 | |
| 227 | // getMember returns an empty buffer if the member was already |
| 228 | // read from the library. |
| 229 | if (MBRef.getBuffer().empty()) |
| 230 | return std::unique_ptr<InputFile>(nullptr); |
Rafael Espindola | 07543a8 | 2016-06-14 21:40:23 +0000 | [diff] [blame] | 231 | return createObjectFile(MBRef, File.getName()); |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 234 | std::unique_ptr<InputFile> LazyObject::getFile() { |
Rafael Espindola | 65c65ce | 2016-06-14 21:56:36 +0000 | [diff] [blame] | 235 | MemoryBufferRef MBRef = File.getBuffer(); |
| 236 | if (MBRef.getBuffer().empty()) |
| 237 | return std::unique_ptr<InputFile>(nullptr); |
Rui Ueyama | f8baa66 | 2016-04-07 19:24:51 +0000 | [diff] [blame] | 238 | return createObjectFile(MBRef); |
| 239 | } |
| 240 | |
Rui Ueyama | a4a628f | 2016-01-13 18:55:39 +0000 | [diff] [blame] | 241 | // Returns the demangled C++ symbol name for Name. |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 242 | std::string elf::demangle(StringRef Name) { |
Rui Ueyama | a4a628f | 2016-01-13 18:55:39 +0000 | [diff] [blame] | 243 | #if !defined(HAVE_CXXABI_H) |
| 244 | return Name; |
| 245 | #else |
| 246 | if (!Config->Demangle) |
| 247 | return Name; |
Rui Ueyama | 5fa978b | 2016-01-13 19:40:13 +0000 | [diff] [blame] | 248 | |
Rui Ueyama | df15451 | 2016-01-13 22:09:09 +0000 | [diff] [blame] | 249 | // __cxa_demangle can be used to demangle strings other than symbol |
| 250 | // names which do not necessarily start with "_Z". Name can be |
| 251 | // either a C or C++ symbol. Don't call __cxa_demangle if the name |
| 252 | // does not look like a C++ symbol name to avoid getting unexpected |
| 253 | // result for a C symbol that happens to match a mangled type name. |
Rui Ueyama | 5fa978b | 2016-01-13 19:40:13 +0000 | [diff] [blame] | 254 | if (!Name.startswith("_Z")) |
| 255 | return Name; |
| 256 | |
Rui Ueyama | a4a628f | 2016-01-13 18:55:39 +0000 | [diff] [blame] | 257 | char *Buf = |
| 258 | abi::__cxa_demangle(Name.str().c_str(), nullptr, nullptr, nullptr); |
| 259 | if (!Buf) |
| 260 | return Name; |
| 261 | std::string S(Buf); |
| 262 | free(Buf); |
| 263 | return S; |
| 264 | #endif |
| 265 | } |
| 266 | |
Peter Collingbourne | dadcc17 | 2016-04-22 18:42:48 +0000 | [diff] [blame] | 267 | bool Symbol::includeInDynsym() const { |
| 268 | if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) |
Rafael Espindola | ae605c1 | 2016-04-21 20:35:25 +0000 | [diff] [blame] | 269 | return false; |
George Rimar | d03f972 | 2016-06-20 10:29:53 +0000 | [diff] [blame^] | 270 | return (ExportDynamic && VersionScriptGlobal) || body()->isShared() || |
Peter Collingbourne | 4f95270 | 2016-05-01 04:55:03 +0000 | [diff] [blame] | 271 | (body()->isUndefined() && Config->Shared); |
Rafael Espindola | ae605c1 | 2016-04-21 20:35:25 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Rui Ueyama | 6d0cd2b | 2016-05-02 21:30:42 +0000 | [diff] [blame] | 274 | template InputFile *SymbolBody::template getSourceFile<ELF32LE>(); |
| 275 | template InputFile *SymbolBody::template getSourceFile<ELF32BE>(); |
| 276 | template InputFile *SymbolBody::template getSourceFile<ELF64LE>(); |
| 277 | template InputFile *SymbolBody::template getSourceFile<ELF64BE>(); |
| 278 | |
Rafael Espindola | 87d9f10 | 2016-03-11 12:19:05 +0000 | [diff] [blame] | 279 | template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const; |
| 280 | template uint32_t SymbolBody::template getVA<ELF32BE>(uint32_t) const; |
| 281 | template uint64_t SymbolBody::template getVA<ELF64LE>(uint64_t) const; |
| 282 | template uint64_t SymbolBody::template getVA<ELF64BE>(uint64_t) const; |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 283 | |
| 284 | template uint32_t SymbolBody::template getGotVA<ELF32LE>() const; |
| 285 | template uint32_t SymbolBody::template getGotVA<ELF32BE>() const; |
| 286 | template uint64_t SymbolBody::template getGotVA<ELF64LE>() const; |
| 287 | template uint64_t SymbolBody::template getGotVA<ELF64BE>() const; |
| 288 | |
Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 289 | template uint32_t SymbolBody::template getGotOffset<ELF32LE>() const; |
| 290 | template uint32_t SymbolBody::template getGotOffset<ELF32BE>() const; |
| 291 | template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const; |
| 292 | template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const; |
| 293 | |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 294 | template uint32_t SymbolBody::template getGotPltVA<ELF32LE>() const; |
| 295 | template uint32_t SymbolBody::template getGotPltVA<ELF32BE>() const; |
| 296 | template uint64_t SymbolBody::template getGotPltVA<ELF64LE>() const; |
| 297 | template uint64_t SymbolBody::template getGotPltVA<ELF64BE>() const; |
| 298 | |
Rafael Espindola | 74031ba | 2016-04-07 15:20:56 +0000 | [diff] [blame] | 299 | template uint32_t SymbolBody::template getGotPltOffset<ELF32LE>() const; |
| 300 | template uint32_t SymbolBody::template getGotPltOffset<ELF32BE>() const; |
| 301 | template uint64_t SymbolBody::template getGotPltOffset<ELF64LE>() const; |
| 302 | template uint64_t SymbolBody::template getGotPltOffset<ELF64BE>() const; |
| 303 | |
Rui Ueyama | b5a6970 | 2016-02-01 21:00:35 +0000 | [diff] [blame] | 304 | template uint32_t SymbolBody::template getPltVA<ELF32LE>() const; |
| 305 | template uint32_t SymbolBody::template getPltVA<ELF32BE>() const; |
| 306 | template uint64_t SymbolBody::template getPltVA<ELF64LE>() const; |
| 307 | template uint64_t SymbolBody::template getPltVA<ELF64BE>() const; |
| 308 | |
Rui Ueyama | 512c61d | 2016-02-03 00:12:24 +0000 | [diff] [blame] | 309 | template uint32_t SymbolBody::template getSize<ELF32LE>() const; |
| 310 | template uint32_t SymbolBody::template getSize<ELF32BE>() const; |
| 311 | template uint64_t SymbolBody::template getSize<ELF64LE>() const; |
| 312 | template uint64_t SymbolBody::template getSize<ELF64BE>() const; |
| 313 | |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 314 | template uint32_t SymbolBody::template getThunkVA<ELF32LE>() const; |
| 315 | template uint32_t SymbolBody::template getThunkVA<ELF32BE>() const; |
| 316 | template uint64_t SymbolBody::template getThunkVA<ELF64LE>() const; |
| 317 | template uint64_t SymbolBody::template getThunkVA<ELF64BE>() const; |
| 318 | |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 319 | template class elf::DefinedSynthetic<ELF32LE>; |
| 320 | template class elf::DefinedSynthetic<ELF32BE>; |
| 321 | template class elf::DefinedSynthetic<ELF64LE>; |
| 322 | template class elf::DefinedSynthetic<ELF64BE>; |