Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1 | //===- OutputSections.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 "OutputSections.h" |
| 11 | #include "Config.h" |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 12 | #include "SymbolTable.h" |
Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 13 | #include "Target.h" |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 14 | #include "llvm/Support/MathExtras.h" |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 15 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | using namespace llvm::object; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 18 | using namespace llvm::support::endian; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 19 | using namespace llvm::ELF; |
| 20 | |
| 21 | using namespace lld; |
| 22 | using namespace lld::elf2; |
| 23 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 24 | template <class ELFT> |
| 25 | OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t sh_type, |
| 26 | uintX_t sh_flags) |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 27 | : Name(Name) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 28 | memset(&Header, 0, sizeof(Elf_Shdr)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 29 | Header.sh_type = sh_type; |
| 30 | Header.sh_flags = sh_flags; |
| 31 | } |
| 32 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 33 | template <class ELFT> |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 34 | GotPltSection<ELFT>::GotPltSection() |
| 35 | : OutputSectionBase<ELFT>(".got.plt", llvm::ELF::SHT_PROGBITS, |
| 36 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { |
| 37 | this->Header.sh_addralign = sizeof(uintX_t); |
| 38 | // .got.plt has 3 reserved entry |
| 39 | Entries.resize(3); |
| 40 | } |
| 41 | |
| 42 | template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody *Sym) { |
| 43 | Sym->GotPltIndex = Entries.size(); |
| 44 | Entries.push_back(Sym); |
| 45 | } |
| 46 | |
| 47 | template <class ELFT> bool GotPltSection<ELFT>::empty() const { |
| 48 | return Entries.size() == 3; |
| 49 | } |
| 50 | |
| 51 | template <class ELFT> |
| 52 | typename GotPltSection<ELFT>::uintX_t |
| 53 | GotPltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { |
| 54 | return this->getVA() + B.GotPltIndex * sizeof(uintX_t); |
| 55 | } |
| 56 | |
| 57 | template <class ELFT> void GotPltSection<ELFT>::finalize() { |
| 58 | this->Header.sh_size = Entries.size() * sizeof(uintX_t); |
| 59 | } |
| 60 | |
| 61 | template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) { |
| 62 | write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>( |
| 63 | Buf, Out<ELFT>::Dynamic->getVA()); |
| 64 | for (const SymbolBody *B : Entries) { |
| 65 | if (B) |
| 66 | Target->writeGotPltEntry(Buf, Out<ELFT>::Plt->getEntryAddr(*B)); |
| 67 | Buf += sizeof(uintX_t); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 72 | GotSection<ELFT>::GotSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 73 | : OutputSectionBase<ELFT>(".got", llvm::ELF::SHT_PROGBITS, |
| 74 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { |
Rui Ueyama | 5f551ae | 2015-10-14 14:02:06 +0000 | [diff] [blame] | 75 | this->Header.sh_addralign = sizeof(uintX_t); |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 78 | template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) { |
Rui Ueyama | 49c68a7 | 2015-10-09 00:42:06 +0000 | [diff] [blame] | 79 | Sym->GotIndex = Entries.size(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 80 | Entries.push_back(Sym); |
| 81 | } |
| 82 | |
| 83 | template <class ELFT> |
| 84 | typename GotSection<ELFT>::uintX_t |
| 85 | GotSection<ELFT>::getEntryAddr(const SymbolBody &B) const { |
Rui Ueyama | 5f551ae | 2015-10-14 14:02:06 +0000 | [diff] [blame] | 86 | return this->getVA() + B.GotIndex * sizeof(uintX_t); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 89 | template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) { |
| 90 | for (const SymbolBody *B : Entries) { |
Rafael Espindola | e782f67 | 2015-10-07 03:56:05 +0000 | [diff] [blame] | 91 | uint8_t *Entry = Buf; |
| 92 | Buf += sizeof(uintX_t); |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 93 | if (canBePreempted(B, false)) |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 94 | continue; // The dynamic linker will take care of it. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 95 | uintX_t VA = getSymVA<ELFT>(*B); |
Rafael Espindola | e782f67 | 2015-10-07 03:56:05 +0000 | [diff] [blame] | 96 | write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, VA); |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 100 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 101 | PltSection<ELFT>::PltSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 102 | : OutputSectionBase<ELFT>(".plt", llvm::ELF::SHT_PROGBITS, |
| 103 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 104 | this->Header.sh_addralign = 16; |
| 105 | } |
| 106 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 107 | template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 108 | size_t Off = 0; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 109 | bool LazyReloc = Target->supportsLazyRelocations(); |
| 110 | if (LazyReloc) { |
| 111 | // First write PLT[0] entry which is special. |
| 112 | Target->writePltZeroEntry(Buf, Out<ELFT>::GotPlt->getVA(), this->getVA()); |
| 113 | Off += Target->getPltZeroEntrySize(); |
| 114 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 115 | for (const SymbolBody *E : Entries) { |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 116 | uint64_t Got = LazyReloc ? Out<ELFT>::GotPlt->getEntryAddr(*E) |
| 117 | : Out<ELFT>::Got->getEntryAddr(*E); |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 118 | uint64_t Plt = this->getVA() + Off; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 119 | Target->writePltEntry(Buf + Off, Got, Plt, E->PltIndex); |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 120 | Off += Target->getPltEntrySize(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody *Sym) { |
Rui Ueyama | 49c68a7 | 2015-10-09 00:42:06 +0000 | [diff] [blame] | 125 | Sym->PltIndex = Entries.size(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 126 | Entries.push_back(Sym); |
| 127 | } |
| 128 | |
| 129 | template <class ELFT> |
| 130 | typename PltSection<ELFT>::uintX_t |
| 131 | PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 132 | return this->getVA() + Target->getPltZeroEntrySize() + |
| 133 | B.PltIndex * Target->getPltEntrySize(); |
| 134 | } |
| 135 | |
| 136 | template <class ELFT> void PltSection<ELFT>::finalize() { |
| 137 | this->Header.sh_size = Target->getPltZeroEntrySize() + |
| 138 | Entries.size() * Target->getPltEntrySize(); |
Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | template <class ELFT> |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 142 | RelocationSection<ELFT>::RelocationSection(StringRef Name, bool IsRela) |
| 143 | : OutputSectionBase<ELFT>(Name, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 144 | IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, |
| 145 | llvm::ELF::SHF_ALLOC), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 146 | IsRela(IsRela) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 147 | this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
| 148 | this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 149 | } |
| 150 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 151 | template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 50534c2 | 2015-09-22 17:49:38 +0000 | [diff] [blame] | 152 | const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 153 | for (const DynamicReloc<ELFT> &Rel : Relocs) { |
Rafael Espindola | 50534c2 | 2015-09-22 17:49:38 +0000 | [diff] [blame] | 154 | auto *P = reinterpret_cast<Elf_Rel *>(Buf); |
| 155 | Buf += EntrySize; |
| 156 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 157 | const InputSection<ELFT> &C = Rel.C; |
| 158 | const Elf_Rel &RI = Rel.RI; |
Rui Ueyama | 6455852 | 2015-10-16 22:51:43 +0000 | [diff] [blame] | 159 | uint32_t SymIndex = RI.getSymbol(Config->Mips64EL); |
Rafael Espindola | 41127ad | 2015-10-05 22:49:16 +0000 | [diff] [blame] | 160 | const ObjectFile<ELFT> &File = *C.getFile(); |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 161 | SymbolBody *Body = File.getSymbolBody(SymIndex); |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 162 | if (Body) |
| 163 | Body = Body->repl(); |
Rafael Espindola | 41127ad | 2015-10-05 22:49:16 +0000 | [diff] [blame] | 164 | |
Rui Ueyama | 6455852 | 2015-10-16 22:51:43 +0000 | [diff] [blame] | 165 | uint32_t Type = RI.getType(Config->Mips64EL); |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 166 | bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body); |
| 167 | bool CanBePreempted = canBePreempted(Body, NeedsGot); |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 168 | bool LazyReloc = Body && Target->supportsLazyRelocations() && |
| 169 | Target->relocNeedsPlt(Type, *Body); |
Rafael Espindola | 4975752 | 2015-10-19 19:58:18 +0000 | [diff] [blame] | 170 | |
| 171 | if (CanBePreempted) { |
| 172 | if (NeedsGot) |
| 173 | P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 174 | LazyReloc ? Target->getPltReloc() |
| 175 | : Target->getGotReloc(), |
| 176 | Config->Mips64EL); |
Rafael Espindola | 4975752 | 2015-10-19 19:58:18 +0000 | [diff] [blame] | 177 | else |
| 178 | P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type, |
| 179 | Config->Mips64EL); |
| 180 | } else { |
Rui Ueyama | 6455852 | 2015-10-16 22:51:43 +0000 | [diff] [blame] | 181 | P->setSymbolAndType(0, Target->getRelativeReloc(), Config->Mips64EL); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 182 | } |
| 183 | |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 184 | if (NeedsGot) { |
| 185 | if (LazyReloc) |
| 186 | P->r_offset = Out<ELFT>::GotPlt->getEntryAddr(*Body); |
| 187 | else |
| 188 | P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body); |
| 189 | } else { |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 190 | P->r_offset = RI.r_offset + C.OutSec->getVA() + C.OutSecOff; |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 191 | } |
Rafael Espindola | 4975752 | 2015-10-19 19:58:18 +0000 | [diff] [blame] | 192 | |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 193 | uintX_t OrigAddend = 0; |
Rafael Espindola | 4975752 | 2015-10-19 19:58:18 +0000 | [diff] [blame] | 194 | if (IsRela && !NeedsGot) |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 195 | OrigAddend = static_cast<const Elf_Rela &>(RI).r_addend; |
Rafael Espindola | 4975752 | 2015-10-19 19:58:18 +0000 | [diff] [blame] | 196 | |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 197 | uintX_t Addend; |
Rui Ueyama | b7f2867 | 2015-10-19 20:31:49 +0000 | [diff] [blame] | 198 | if (CanBePreempted) |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 199 | Addend = OrigAddend; |
Rui Ueyama | b7f2867 | 2015-10-19 20:31:49 +0000 | [diff] [blame] | 200 | else if (Body) |
| 201 | Addend = getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body)) + OrigAddend; |
| 202 | else if (IsRela) |
| 203 | Addend = getLocalRelTarget(File, static_cast<const Elf_Rela &>(RI)); |
| 204 | else |
| 205 | Addend = getLocalRelTarget(File, RI); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 206 | |
| 207 | if (IsRela) |
| 208 | static_cast<Elf_Rela *>(P)->r_addend = Addend; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | template <class ELFT> void RelocationSection<ELFT>::finalize() { |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 213 | this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 214 | this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; |
| 215 | } |
| 216 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 217 | template <class ELFT> |
| 218 | InterpSection<ELFT>::InterpSection() |
| 219 | : OutputSectionBase<ELFT>(".interp", llvm::ELF::SHT_PROGBITS, |
| 220 | llvm::ELF::SHF_ALLOC) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 221 | this->Header.sh_size = Config->DynamicLinker.size() + 1; |
| 222 | this->Header.sh_addralign = 1; |
| 223 | } |
| 224 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 225 | template <class ELFT> |
| 226 | void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *SHdr) { |
| 227 | *SHdr = Header; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 230 | template <class ELFT> void InterpSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 231 | memcpy(Buf, Config->DynamicLinker.data(), Config->DynamicLinker.size()); |
| 232 | } |
| 233 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 234 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 235 | HashTableSection<ELFT>::HashTableSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 236 | : OutputSectionBase<ELFT>(".hash", llvm::ELF::SHT_HASH, |
| 237 | llvm::ELF::SHF_ALLOC) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 238 | this->Header.sh_entsize = sizeof(Elf_Word); |
| 239 | this->Header.sh_addralign = sizeof(Elf_Word); |
| 240 | } |
| 241 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 242 | static uint32_t hashSysv(StringRef Name) { |
Rui Ueyama | 5f1eee1a | 2015-10-15 21:27:17 +0000 | [diff] [blame] | 243 | uint32_t H = 0; |
| 244 | for (char C : Name) { |
| 245 | H = (H << 4) + C; |
| 246 | uint32_t G = H & 0xf0000000; |
| 247 | if (G) |
| 248 | H ^= G >> 24; |
| 249 | H &= ~G; |
| 250 | } |
| 251 | return H; |
| 252 | } |
| 253 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 254 | template <class ELFT> void HashTableSection<ELFT>::finalize() { |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 255 | this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 256 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 257 | unsigned NumEntries = 2; // nbucket and nchain. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 258 | NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); // The chain entries. |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 259 | |
| 260 | // Create as many buckets as there are symbols. |
| 261 | // FIXME: This is simplistic. We can try to optimize it, but implementing |
| 262 | // support for SHT_GNU_HASH is probably even more profitable. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 263 | NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 264 | this->Header.sh_size = NumEntries * sizeof(Elf_Word); |
| 265 | } |
| 266 | |
| 267 | template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 268 | unsigned NumSymbols = Out<ELFT>::DynSymTab->getNumSymbols(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 269 | auto *P = reinterpret_cast<Elf_Word *>(Buf); |
| 270 | *P++ = NumSymbols; // nbucket |
| 271 | *P++ = NumSymbols; // nchain |
| 272 | |
| 273 | Elf_Word *Buckets = P; |
| 274 | Elf_Word *Chains = P + NumSymbols; |
| 275 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 276 | for (const typename SymbolTableSection<ELFT>::SymbolData &Item : |
| 277 | Out<ELFT>::DynSymTab->getSymbols()) { |
| 278 | SymbolBody *Body = Item.Body; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 279 | StringRef Name = Body->getName(); |
| 280 | unsigned I = Body->getDynamicSymbolTableIndex(); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 281 | uint32_t Hash = hashSysv(Name) % NumSymbols; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 282 | Chains[I] = Buckets[Hash]; |
| 283 | Buckets[Hash] = I; |
| 284 | } |
| 285 | } |
| 286 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 287 | static uint32_t hashGnu(StringRef Name) { |
| 288 | uint32_t H = 5381; |
| 289 | for (uint8_t C : Name) |
| 290 | H = (H << 5) + H + C; |
| 291 | return H; |
| 292 | } |
| 293 | |
| 294 | template <class ELFT> |
| 295 | GnuHashTableSection<ELFT>::GnuHashTableSection() |
| 296 | : OutputSectionBase<ELFT>(".gnu.hash", llvm::ELF::SHT_GNU_HASH, |
| 297 | llvm::ELF::SHF_ALLOC) { |
| 298 | this->Header.sh_entsize = ELFT::Is64Bits ? 0 : 4; |
| 299 | this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 300 | } |
| 301 | |
| 302 | template <class ELFT> |
| 303 | unsigned GnuHashTableSection<ELFT>::calcNBuckets(unsigned NumHashed) { |
| 304 | if (!NumHashed) |
| 305 | return 0; |
| 306 | |
| 307 | // These values are prime numbers which are not greater than 2^(N-1) + 1. |
| 308 | // In result, for any particular NumHashed we return a prime number |
| 309 | // which is not greater than NumHashed. |
| 310 | static const unsigned Primes[] = { |
| 311 | 1, 1, 3, 3, 7, 13, 31, 61, 127, 251, |
| 312 | 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071}; |
| 313 | |
| 314 | return Primes[std::min<unsigned>(Log2_32_Ceil(NumHashed), |
| 315 | array_lengthof(Primes) - 1)]; |
| 316 | } |
| 317 | |
| 318 | // Bloom filter estimation: at least 8 bits for each hashed symbol. |
| 319 | // GNU Hash table requirement: it should be a power of 2, |
| 320 | // the minimum value is 1, even for an empty table. |
| 321 | // Expected results for a 32-bit target: |
| 322 | // calcMaskWords(0..4) = 1 |
| 323 | // calcMaskWords(5..8) = 2 |
| 324 | // calcMaskWords(9..16) = 4 |
| 325 | // For a 64-bit target: |
| 326 | // calcMaskWords(0..8) = 1 |
| 327 | // calcMaskWords(9..16) = 2 |
| 328 | // calcMaskWords(17..32) = 4 |
| 329 | template <class ELFT> |
| 330 | unsigned GnuHashTableSection<ELFT>::calcMaskWords(unsigned NumHashed) { |
| 331 | if (!NumHashed) |
| 332 | return 1; |
| 333 | return NextPowerOf2((NumHashed - 1) / sizeof(Elf_Off)); |
| 334 | } |
| 335 | |
| 336 | template <class ELFT> void GnuHashTableSection<ELFT>::finalize() { |
| 337 | const unsigned NumHashed = Out<ELFT>::DynSymTab->getNumGnuHashSymbols(); |
| 338 | NBuckets = calcNBuckets(NumHashed); |
| 339 | MaskWords = calcMaskWords(NumHashed); |
| 340 | // Second hash shift estimation: just predefined values. |
| 341 | Shift2 = ELFT::Is64Bits ? 6 : 5; |
| 342 | |
| 343 | this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; |
| 344 | this->Header.sh_size = sizeof(Elf_Word) * 4 // Header |
| 345 | + sizeof(Elf_Off) * MaskWords // Bloom Filter |
| 346 | + sizeof(Elf_Word) * NBuckets // Hash Buckets |
| 347 | + sizeof(Elf_Word) * NumHashed; // Hash Values |
| 348 | } |
| 349 | |
| 350 | template <class ELFT> void GnuHashTableSection<ELFT>::writeTo(uint8_t *Buf) { |
| 351 | writeHeader(Buf); |
| 352 | if (!NBuckets) // There are no hashed symbols |
| 353 | return; |
| 354 | writeBloomFilter(Buf); |
| 355 | writeHashTable(Buf); |
| 356 | } |
| 357 | |
| 358 | template <class ELFT> |
| 359 | void GnuHashTableSection<ELFT>::writeHeader(uint8_t *&Buf) { |
| 360 | auto *P = reinterpret_cast<Elf_Word *>(Buf); |
| 361 | *P++ = NBuckets; |
| 362 | *P++ = Out<ELFT>::DynSymTab->getNumSymbols() - |
| 363 | Out<ELFT>::DynSymTab->getNumGnuHashSymbols(); |
| 364 | *P++ = MaskWords; |
| 365 | *P++ = Shift2; |
| 366 | Buf = reinterpret_cast<uint8_t *>(P); |
| 367 | } |
| 368 | |
| 369 | template <class ELFT> |
| 370 | void GnuHashTableSection<ELFT>::writeBloomFilter(uint8_t *&Buf) { |
| 371 | unsigned C = sizeof(Elf_Off) * 8; |
| 372 | |
| 373 | auto *Masks = reinterpret_cast<Elf_Off *>(Buf); |
| 374 | for (const typename SymbolTableSection<ELFT>::SymbolData &Item : |
| 375 | Out<ELFT>::DynSymTab->getGnuHashSymbols()) { |
| 376 | size_t Pos = (Item.GnuHash / C) & (MaskWords - 1); |
| 377 | uintX_t V = (uintX_t(1) << (Item.GnuHash % C)) | |
| 378 | (uintX_t(1) << ((Item.GnuHash >> Shift2) % C)); |
| 379 | Masks[Pos] |= V; |
| 380 | } |
| 381 | Buf += sizeof(Elf_Off) * MaskWords; |
| 382 | } |
| 383 | |
| 384 | template <class ELFT> |
| 385 | void GnuHashTableSection<ELFT>::writeHashTable(uint8_t *Buf) { |
| 386 | Elf_Word *Buckets = reinterpret_cast<Elf_Word *>(Buf); |
| 387 | Elf_Word *Values = Buckets + NBuckets; |
| 388 | |
| 389 | int PrevBucket = -1; |
| 390 | int I = 0; |
| 391 | for (const typename SymbolTableSection<ELFT>::SymbolData &Item : |
| 392 | Out<ELFT>::DynSymTab->getGnuHashSymbols()) { |
| 393 | int Bucket = Item.GnuHash % NBuckets; |
| 394 | assert(PrevBucket <= Bucket); |
| 395 | if (Bucket != PrevBucket) { |
| 396 | Buckets[Bucket] = Item.Body->getDynamicSymbolTableIndex(); |
| 397 | PrevBucket = Bucket; |
| 398 | if (I > 0) |
| 399 | Values[I - 1] |= 1; |
| 400 | } |
| 401 | Values[I] = Item.GnuHash & ~1; |
| 402 | ++I; |
| 403 | } |
| 404 | if (I > 0) |
| 405 | Values[I - 1] |= 1; |
| 406 | } |
| 407 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 408 | template <class ELFT> |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 409 | DynamicSection<ELFT>::DynamicSection(SymbolTable<ELFT> &SymTab) |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 410 | : OutputSectionBase<ELFT>(".dynamic", llvm::ELF::SHT_DYNAMIC, |
| 411 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 412 | SymTab(SymTab) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 413 | Elf_Shdr &Header = this->Header; |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 414 | Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 415 | Header.sh_entsize = ELFT::Is64Bits ? 16 : 8; |
| 416 | } |
| 417 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 418 | template <class ELFT> void DynamicSection<ELFT>::finalize() { |
Michael J. Spencer | 52bf0eb | 2015-10-01 21:15:02 +0000 | [diff] [blame] | 419 | if (this->Header.sh_size) |
| 420 | return; // Already finalized. |
| 421 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 422 | Elf_Shdr &Header = this->Header; |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 423 | Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 424 | |
| 425 | unsigned NumEntries = 0; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 426 | if (Out<ELFT>::RelaDyn->hasRelocs()) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 427 | ++NumEntries; // DT_RELA / DT_REL |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 428 | ++NumEntries; // DT_RELASZ / DT_RELSZ |
| 429 | ++NumEntries; // DT_RELAENT / DT_RELENT |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 430 | } |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 431 | if (Out<ELFT>::RelaPlt && Out<ELFT>::RelaPlt->hasRelocs()) { |
| 432 | ++NumEntries; // DT_JMPREL |
| 433 | ++NumEntries; // DT_PLTRELSZ |
| 434 | ++NumEntries; // DT_PLTGOT |
| 435 | ++NumEntries; // DT_PLTREL |
| 436 | } |
| 437 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 438 | ++NumEntries; // DT_SYMTAB |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 439 | ++NumEntries; // DT_SYMENT |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 440 | ++NumEntries; // DT_STRTAB |
| 441 | ++NumEntries; // DT_STRSZ |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 442 | if (Out<ELFT>::GnuHashTab) |
| 443 | ++NumEntries; // DT_GNU_HASH |
| 444 | if (Out<ELFT>::HashTab) |
| 445 | ++NumEntries; // DT_HASH |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 446 | |
Rui Ueyama | 7de3f37 | 2015-10-01 19:36:04 +0000 | [diff] [blame] | 447 | if (!Config->RPath.empty()) { |
Davide Italiano | c39c75d | 2015-10-06 16:20:00 +0000 | [diff] [blame] | 448 | ++NumEntries; // DT_RUNPATH / DT_RPATH |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 449 | Out<ELFT>::DynStrTab->add(Config->RPath); |
Rui Ueyama | 7de3f37 | 2015-10-01 19:36:04 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | if (!Config->SoName.empty()) { |
| 453 | ++NumEntries; // DT_SONAME |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 454 | Out<ELFT>::DynStrTab->add(Config->SoName); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 457 | if (PreInitArraySec) |
| 458 | NumEntries += 2; |
| 459 | if (InitArraySec) |
| 460 | NumEntries += 2; |
| 461 | if (FiniArraySec) |
| 462 | NumEntries += 2; |
| 463 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 464 | for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) { |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 465 | if (!F->isNeeded()) |
| 466 | continue; |
Rui Ueyama | 6ccc8ca | 2015-10-09 20:32:54 +0000 | [diff] [blame] | 467 | Out<ELFT>::DynStrTab->add(F->getSoName()); |
| 468 | ++NumEntries; |
| 469 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 470 | |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 471 | if (Symbol *S = SymTab.getSymbols().lookup(Config->Init)) |
| 472 | InitSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); |
| 473 | if (Symbol *S = SymTab.getSymbols().lookup(Config->Fini)) |
| 474 | FiniSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 475 | if (InitSym) |
| 476 | ++NumEntries; // DT_INIT |
| 477 | if (FiniSym) |
| 478 | ++NumEntries; // DT_FINI |
Rui Ueyama | c96d0dd | 2015-10-21 17:47:10 +0000 | [diff] [blame] | 479 | |
| 480 | if (Config->Bsymbolic) |
| 481 | DtFlags |= DF_SYMBOLIC; |
| 482 | if (Config->ZNodelete) |
| 483 | DtFlags1 |= DF_1_NODELETE; |
| 484 | if (Config->ZNow) { |
| 485 | DtFlags |= DF_BIND_NOW; |
| 486 | DtFlags1 |= DF_1_NOW; |
| 487 | } |
| 488 | if (Config->ZOrigin) { |
| 489 | DtFlags |= DF_ORIGIN; |
| 490 | DtFlags1 |= DF_1_ORIGIN; |
| 491 | } |
| 492 | |
| 493 | if (DtFlags) |
Davide Italiano | 58cbaf0 | 2015-10-19 23:32:16 +0000 | [diff] [blame] | 494 | ++NumEntries; // DT_FLAGS |
Rui Ueyama | c96d0dd | 2015-10-21 17:47:10 +0000 | [diff] [blame] | 495 | if (DtFlags1) |
George Rimar | 97aad17 | 2015-10-07 15:00:21 +0000 | [diff] [blame] | 496 | ++NumEntries; // DT_FLAGS_1 |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 497 | ++NumEntries; // DT_NULL |
| 498 | |
| 499 | Header.sh_size = NumEntries * Header.sh_entsize; |
| 500 | } |
| 501 | |
| 502 | template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 503 | auto *P = reinterpret_cast<Elf_Dyn *>(Buf); |
| 504 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 505 | auto WritePtr = [&](int32_t Tag, uint64_t Val) { |
| 506 | P->d_tag = Tag; |
| 507 | P->d_un.d_ptr = Val; |
| 508 | ++P; |
| 509 | }; |
| 510 | |
| 511 | auto WriteVal = [&](int32_t Tag, uint32_t Val) { |
| 512 | P->d_tag = Tag; |
| 513 | P->d_un.d_val = Val; |
| 514 | ++P; |
| 515 | }; |
| 516 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 517 | if (Out<ELFT>::RelaDyn->hasRelocs()) { |
| 518 | bool IsRela = Out<ELFT>::RelaDyn->isRela(); |
| 519 | WritePtr(IsRela ? DT_RELA : DT_REL, Out<ELFT>::RelaDyn->getVA()); |
| 520 | WriteVal(IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->getSize()); |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 521 | WriteVal(IsRela ? DT_RELAENT : DT_RELENT, |
| 522 | IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 523 | } |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 524 | if (Out<ELFT>::RelaPlt && Out<ELFT>::RelaPlt->hasRelocs()) { |
| 525 | WritePtr(DT_JMPREL, Out<ELFT>::RelaPlt->getVA()); |
| 526 | WriteVal(DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize()); |
| 527 | WritePtr(DT_PLTGOT, Out<ELFT>::GotPlt->getVA()); |
| 528 | WriteVal(DT_PLTREL, Out<ELFT>::RelaPlt->isRela() ? DT_RELA : DT_REL); |
| 529 | } |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 530 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 531 | WritePtr(DT_SYMTAB, Out<ELFT>::DynSymTab->getVA()); |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 532 | WritePtr(DT_SYMENT, sizeof(Elf_Sym)); |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 533 | WritePtr(DT_STRTAB, Out<ELFT>::DynStrTab->getVA()); |
| 534 | WriteVal(DT_STRSZ, Out<ELFT>::DynStrTab->data().size()); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 535 | if (Out<ELFT>::GnuHashTab) |
| 536 | WritePtr(DT_GNU_HASH, Out<ELFT>::GnuHashTab->getVA()); |
| 537 | if (Out<ELFT>::HashTab) |
| 538 | WritePtr(DT_HASH, Out<ELFT>::HashTab->getVA()); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 539 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 540 | if (!Config->RPath.empty()) |
Davide Italiano | c39c75d | 2015-10-06 16:20:00 +0000 | [diff] [blame] | 541 | |
| 542 | // If --enable-new-dtags is set lld emits DT_RUNPATH |
| 543 | // instead of DT_RPATH. The two tags are functionally |
| 544 | // equivalent except for the following: |
| 545 | // - DT_RUNPATH is searched after LD_LIBRARY_PATH, while |
| 546 | // DT_RPATH is searched before. |
| 547 | // - DT_RUNPATH is used only to search for direct |
| 548 | // dependencies of the object it's contained in, while |
| 549 | // DT_RPATH is used for indirect dependencies as well. |
| 550 | WriteVal(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 551 | Out<ELFT>::DynStrTab->getFileOff(Config->RPath)); |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 552 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 553 | if (!Config->SoName.empty()) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 554 | WriteVal(DT_SONAME, Out<ELFT>::DynStrTab->getFileOff(Config->SoName)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 555 | |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 556 | auto WriteArray = [&](int32_t T1, int32_t T2, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 557 | const OutputSectionBase<ELFT> *Sec) { |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 558 | if (!Sec) |
| 559 | return; |
| 560 | WritePtr(T1, Sec->getVA()); |
| 561 | WriteVal(T2, Sec->getSize()); |
| 562 | }; |
| 563 | WriteArray(DT_PREINIT_ARRAY, DT_PREINIT_ARRAYSZ, PreInitArraySec); |
| 564 | WriteArray(DT_INIT_ARRAY, DT_INIT_ARRAYSZ, InitArraySec); |
| 565 | WriteArray(DT_FINI_ARRAY, DT_FINI_ARRAYSZ, FiniArraySec); |
| 566 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 567 | for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 568 | if (F->isNeeded()) |
| 569 | WriteVal(DT_NEEDED, Out<ELFT>::DynStrTab->getFileOff(F->getSoName())); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 570 | |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 571 | if (InitSym) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 572 | WritePtr(DT_INIT, getSymVA<ELFT>(*InitSym)); |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 573 | if (FiniSym) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 574 | WritePtr(DT_FINI, getSymVA<ELFT>(*FiniSym)); |
Rui Ueyama | c96d0dd | 2015-10-21 17:47:10 +0000 | [diff] [blame] | 575 | if (DtFlags) |
| 576 | WriteVal(DT_FLAGS, DtFlags); |
| 577 | if (DtFlags1) |
| 578 | WriteVal(DT_FLAGS_1, DtFlags1); |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 579 | WriteVal(DT_NULL, 0); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 583 | OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t sh_type, |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 584 | uintX_t sh_flags) |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 585 | : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {} |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 586 | |
| 587 | template <class ELFT> |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 588 | void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) { |
| 589 | Sections.push_back(C); |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 590 | C->OutSec = this; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 591 | uint32_t Align = C->getAlign(); |
| 592 | if (Align > this->Header.sh_addralign) |
| 593 | this->Header.sh_addralign = Align; |
| 594 | |
| 595 | uintX_t Off = this->Header.sh_size; |
| 596 | Off = RoundUpToAlignment(Off, Align); |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 597 | C->OutSecOff = Off; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 598 | Off += C->getSize(); |
| 599 | this->Header.sh_size = Off; |
| 600 | } |
| 601 | |
| 602 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 603 | typename ELFFile<ELFT>::uintX_t lld::elf2::getSymVA(const SymbolBody &S) { |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 604 | switch (S.kind()) { |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 605 | case SymbolBody::DefinedSyntheticKind: { |
| 606 | auto &D = cast<DefinedSynthetic<ELFT>>(S); |
| 607 | return D.Section.getVA() + D.Sym.st_value; |
| 608 | } |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 609 | case SymbolBody::DefinedAbsoluteKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 610 | return cast<DefinedAbsolute<ELFT>>(S).Sym.st_value; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 611 | case SymbolBody::DefinedRegularKind: { |
| 612 | const auto &DR = cast<DefinedRegular<ELFT>>(S); |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 613 | const InputSectionBase<ELFT> &SC = DR.Section; |
| 614 | return SC.OutSec->getVA() + SC.getOffset(DR.Sym); |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 615 | } |
| 616 | case SymbolBody::DefinedCommonKind: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 617 | return Out<ELFT>::Bss->getVA() + cast<DefinedCommon<ELFT>>(S).OffsetInBSS; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 618 | case SymbolBody::SharedKind: |
| 619 | case SymbolBody::UndefinedKind: |
| 620 | return 0; |
| 621 | case SymbolBody::LazyKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 622 | assert(S.isUsedInRegularObj() && "Lazy symbol reached writer"); |
| 623 | return 0; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 624 | } |
Denis Protivensky | 92aa1c0 | 2015-10-07 08:21:34 +0000 | [diff] [blame] | 625 | llvm_unreachable("Invalid symbol kind"); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 628 | // Returns a VA which a relocatin RI refers to. Used only for local symbols. |
| 629 | // For non-local symbols, use getSymVA instead. |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 630 | template <class ELFT, bool IsRela> |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 631 | typename ELFFile<ELFT>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 632 | lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File, |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 633 | const Elf_Rel_Impl<ELFT, IsRela> &RI) { |
| 634 | typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 635 | typedef typename ELFFile<ELFT>::uintX_t uintX_t; |
| 636 | |
| 637 | uintX_t Addend = getAddend<ELFT>(RI); |
| 638 | |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame] | 639 | // PPC64 has a special relocation representing the TOC base pointer |
| 640 | // that does not have a corresponding symbol. |
Hal Finkel | 230c5c5 | 2015-10-16 22:37:32 +0000 | [diff] [blame] | 641 | if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC) |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 642 | return getPPC64TocBase() + Addend; |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame] | 643 | |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 644 | const Elf_Sym *Sym = |
| 645 | File.getObj().getRelocationSymbol(&RI, File.getSymbolTable()); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 646 | |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 647 | if (!Sym) |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame] | 648 | error("Unsupported relocation without symbol"); |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 649 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 650 | // According to the ELF spec reference to a local symbol from outside |
| 651 | // the group are not allowed. Unfortunately .eh_frame breaks that rule |
| 652 | // and must be treated specially. For now we just replace the symbol with |
| 653 | // 0. |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 654 | InputSectionBase<ELFT> *Section = File.getSection(*Sym); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 655 | if (Section == &InputSection<ELFT>::Discarded) |
Rafael Espindola | 932efcf | 2015-10-19 20:24:44 +0000 | [diff] [blame] | 656 | return Addend; |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 657 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 658 | uintX_t VA = Section->OutSec->getVA(); |
| 659 | if (isa<InputSection<ELFT>>(Section)) |
| 660 | return VA + Section->getOffset(*Sym) + Addend; |
| 661 | |
| 662 | uintX_t Offset = Sym->st_value; |
| 663 | if (Sym->getType() == STT_SECTION) { |
| 664 | Offset += Addend; |
Rafael Espindola | f5af835 | 2015-10-20 22:08:49 +0000 | [diff] [blame] | 665 | Addend = 0; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 666 | } |
| 667 | return VA + cast<MergeInputSection<ELFT>>(Section)->getOffset(Offset) + |
| 668 | Addend; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 671 | // Returns true if a symbol can be replaced at load-time by a symbol |
| 672 | // with the same name defined in other ELF executable or DSO. |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 673 | bool lld::elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) { |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 674 | if (!Body) |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 675 | return false; // Body is a local symbol. |
Rafael Espindola | cea0b3b | 2015-10-07 04:22:55 +0000 | [diff] [blame] | 676 | if (Body->isShared()) |
| 677 | return true; |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 678 | |
| 679 | if (Body->isUndefined()) { |
| 680 | if (!Body->isWeak()) |
| 681 | return true; |
| 682 | |
| 683 | // This is an horrible corner case. Ideally we would like to say that any |
| 684 | // undefined symbol can be preempted so that the dynamic linker has a |
| 685 | // chance of finding it at runtime. |
| 686 | // |
| 687 | // The problem is that the code sequence used to test for weak undef |
| 688 | // functions looks like |
| 689 | // if (func) func() |
| 690 | // If the code is -fPIC the first reference is a load from the got and |
| 691 | // everything works. |
| 692 | // If the code is not -fPIC there is no reasonable way to solve it: |
| 693 | // * A relocation writing to the text segment will fail (it is ro). |
| 694 | // * A copy relocation doesn't work for functions. |
| 695 | // * The trick of using a plt entry as the address would fail here since |
| 696 | // the plt entry would have a non zero address. |
| 697 | // Since we cannot do anything better, we just resolve the symbol to 0 and |
| 698 | // don't produce a dynamic relocation. |
Hal Finkel | c917406 | 2015-10-16 22:11:05 +0000 | [diff] [blame] | 699 | // |
| 700 | // As an extra hack, assume that if we are producing a shared library the |
| 701 | // user knows what he or she is doing and can handle a dynamic relocation. |
| 702 | return Config->Shared || NeedsGot; |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 703 | } |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 704 | if (!Config->Shared) |
| 705 | return false; |
Rui Ueyama | 8f2c4da | 2015-10-21 18:13:47 +0000 | [diff] [blame] | 706 | return Body->getVisibility() == STV_DEFAULT; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 709 | template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 710 | for (InputSection<ELFT> *C : Sections) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 711 | C->writeTo(Buf); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 714 | template <class ELFT> |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 715 | MergeOutputSection<ELFT>::MergeOutputSection(StringRef Name, uint32_t sh_type, |
| 716 | uintX_t sh_flags) |
| 717 | : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {} |
| 718 | |
| 719 | template <class ELFT> void MergeOutputSection<ELFT>::writeTo(uint8_t *Buf) { |
| 720 | for (const std::pair<ArrayRef<uint8_t>, uintX_t> &P : Offsets) { |
| 721 | ArrayRef<uint8_t> Data = P.first; |
| 722 | memcpy(Buf, Data.data(), Data.size()); |
| 723 | Buf += Data.size(); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | template <class ELFT> |
| 728 | void MergeOutputSection<ELFT>::addSection(MergeInputSection<ELFT> *S) { |
| 729 | S->OutSec = this; |
| 730 | uint32_t Align = S->getAlign(); |
| 731 | if (Align > this->Header.sh_addralign) |
| 732 | this->Header.sh_addralign = Align; |
| 733 | |
| 734 | uintX_t Off = this->Header.sh_size; |
| 735 | ArrayRef<uint8_t> Data = S->getSectionData(); |
| 736 | uintX_t EntSize = S->getSectionHdr()->sh_entsize; |
| 737 | if (Data.size() % EntSize) |
| 738 | error("SHF_MERGE section size must be a multiple of sh_entsize"); |
| 739 | for (unsigned I = 0, N = Data.size(); I != N; I += EntSize) { |
| 740 | auto P = Offsets.insert(std::make_pair(Data.slice(I, EntSize), Off)); |
| 741 | if (P.second) |
| 742 | Off += EntSize; |
| 743 | } |
| 744 | this->Header.sh_size = Off; |
| 745 | } |
| 746 | |
| 747 | template <class ELFT> |
| 748 | unsigned MergeOutputSection<ELFT>::getOffset(ArrayRef<uint8_t> Val) { |
| 749 | return Offsets.find(Val)->second; |
| 750 | } |
| 751 | |
| 752 | template <class ELFT> |
George Rimar | 0f5ac9f | 2015-10-20 17:21:35 +0000 | [diff] [blame] | 753 | StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) |
| 754 | : OutputSectionBase<ELFT>(Name, llvm::ELF::SHT_STRTAB, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 755 | Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 756 | Dynamic(Dynamic) { |
| 757 | this->Header.sh_addralign = 1; |
| 758 | } |
| 759 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 760 | template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 761 | StringRef Data = StrTabBuilder.data(); |
| 762 | memcpy(Buf, Data.data(), Data.size()); |
| 763 | } |
| 764 | |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 765 | template <class ELFT> bool lld::elf2::includeInSymtab(const SymbolBody &B) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 766 | if (!B.isUsedInRegularObj()) |
| 767 | return false; |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 768 | |
| 769 | // Don't include synthetic symbols like __init_array_start in every output. |
| 770 | if (auto *U = dyn_cast<DefinedAbsolute<ELFT>>(&B)) |
| 771 | if (&U->Sym == &DefinedAbsolute<ELFT>::IgnoreUndef) |
| 772 | return false; |
| 773 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 774 | return true; |
| 775 | } |
| 776 | |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 777 | bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) { |
Rui Ueyama | 8f2c4da | 2015-10-21 18:13:47 +0000 | [diff] [blame] | 778 | uint8_t V = B.getVisibility(); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 779 | if (V != STV_DEFAULT && V != STV_PROTECTED) |
| 780 | return false; |
| 781 | |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 782 | if (Config->ExportDynamic || Config->Shared) |
| 783 | return true; |
| 784 | return B.isUsedInDynamicReloc(); |
| 785 | } |
| 786 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 787 | bool lld::elf2::includeInGnuHashTable(const SymbolBody &B) { |
| 788 | // Assume that includeInDynamicSymtab() is already checked. |
| 789 | return !B.isUndefined(); |
| 790 | } |
| 791 | |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 792 | template <class ELFT> |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 793 | bool lld::elf2::shouldKeepInSymtab(const ObjectFile<ELFT> &File, |
| 794 | StringRef SymName, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 795 | const typename ELFFile<ELFT>::Elf_Sym &Sym) { |
| 796 | if (Sym.getType() == STT_SECTION) |
| 797 | return false; |
| 798 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 799 | // If sym references a section in a discarded group, don't keep it. |
Rafael Espindola | 4cda581 | 2015-10-16 15:29:48 +0000 | [diff] [blame] | 800 | if (File.getSection(Sym) == &InputSection<ELFT>::Discarded) |
| 801 | return false; |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 802 | |
Davide Italiano | 6993ba4 | 2015-09-26 00:47:56 +0000 | [diff] [blame] | 803 | if (Config->DiscardNone) |
| 804 | return true; |
| 805 | |
| 806 | // ELF defines dynamic locals as symbols which name starts with ".L". |
| 807 | return !(Config->DiscardLocals && SymName.startswith(".L")); |
| 808 | } |
| 809 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 810 | template <class ELFT> |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 811 | SymbolTableSection<ELFT>::SymbolData::SymbolData(SymbolBody *Body, |
| 812 | bool HasGnuHash) |
| 813 | : Body(Body), HasGnuHash(HasGnuHash), |
| 814 | GnuHash(HasGnuHash ? hashGnu(Body->getName()) : 0) {} |
| 815 | |
| 816 | template <class ELFT> |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 817 | SymbolTableSection<ELFT>::SymbolTableSection( |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 818 | SymbolTable<ELFT> &Table, StringTableSection<ELFT> &StrTabSec) |
| 819 | : OutputSectionBase<ELFT>( |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 820 | StrTabSec.isDynamic() ? ".dynsym" : ".symtab", |
| 821 | StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB, |
| 822 | StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 823 | Table(Table), StrTabSec(StrTabSec) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 824 | typedef OutputSectionBase<ELFT> Base; |
| 825 | typename Base::Elf_Shdr &Header = this->Header; |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 826 | |
| 827 | Header.sh_entsize = sizeof(Elf_Sym); |
| 828 | Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 829 | } |
| 830 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 831 | template <class ELFT> void SymbolTableSection<ELFT>::finalize() { |
| 832 | this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym); |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 833 | this->Header.sh_link = StrTabSec.SectionIndex; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 834 | this->Header.sh_info = NumLocals + 1; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 835 | |
| 836 | if (!StrTabSec.isDynamic()) { |
| 837 | std::stable_sort(Symbols.begin(), Symbols.end(), |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 838 | [](const SymbolData &L, const SymbolData &R) { |
| 839 | return getSymbolBinding(L.Body) == STB_LOCAL && |
| 840 | getSymbolBinding(R.Body) != STB_LOCAL; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 841 | }); |
| 842 | return; |
| 843 | } |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 844 | if (NumGnuHashed) { |
| 845 | unsigned NBuckets = GnuHashTableSection<ELFT>::calcNBuckets(NumGnuHashed); |
| 846 | std::stable_sort(Symbols.begin(), Symbols.end(), |
| 847 | [NBuckets](const SymbolData &L, const SymbolData &R) { |
| 848 | if (!L.HasGnuHash || !R.HasGnuHash) |
| 849 | return R.HasGnuHash; |
| 850 | return L.GnuHash % NBuckets < R.GnuHash % NBuckets; |
| 851 | }); |
| 852 | } |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 853 | size_t I = 0; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 854 | for (const SymbolData &Item : Symbols) |
| 855 | Item.Body->setDynamicSymbolTableIndex(++I); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | template <class ELFT> |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 859 | void SymbolTableSection<ELFT>::addLocalSymbol(StringRef Name) { |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 860 | StrTabSec.add(Name); |
| 861 | ++NumVisible; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 862 | ++NumLocals; |
| 863 | } |
| 864 | |
| 865 | template <class ELFT> |
| 866 | void SymbolTableSection<ELFT>::addSymbol(SymbolBody *Body) { |
| 867 | StrTabSec.add(Body->getName()); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 868 | const bool HasGnuHash = StrTabSec.isDynamic() && Out<ELFT>::GnuHashTab && |
| 869 | includeInGnuHashTable(*Body); |
| 870 | Symbols.emplace_back(Body, HasGnuHash); |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 871 | ++NumVisible; |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 872 | if (HasGnuHash) |
| 873 | ++NumGnuHashed; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 876 | template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 877 | Buf += sizeof(Elf_Sym); |
| 878 | |
| 879 | // All symbols with STB_LOCAL binding precede the weak and global symbols. |
| 880 | // .dynsym only contains global symbols. |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 881 | if (!Config->DiscardAll && !StrTabSec.isDynamic()) |
| 882 | writeLocalSymbols(Buf); |
| 883 | |
| 884 | writeGlobalSymbols(Buf); |
| 885 | } |
| 886 | |
| 887 | template <class ELFT> |
| 888 | void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { |
| 889 | // Iterate over all input object files to copy their local symbols |
| 890 | // to the output symbol table pointed by Buf. |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 891 | for (const std::unique_ptr<ObjectFile<ELFT>> &File : Table.getObjectFiles()) { |
| 892 | Elf_Sym_Range Syms = File->getLocalSymbols(); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 893 | for (const Elf_Sym &Sym : Syms) { |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 894 | ErrorOr<StringRef> SymNameOrErr = Sym.getName(File->getStringTable()); |
Rafael Espindola | 26fd69d | 2015-10-09 16:15:57 +0000 | [diff] [blame] | 895 | error(SymNameOrErr); |
| 896 | StringRef SymName = *SymNameOrErr; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 897 | if (!shouldKeepInSymtab<ELFT>(*File, SymName, Sym)) |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 898 | continue; |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 899 | |
Rui Ueyama | c55733e | 2015-09-30 00:54:29 +0000 | [diff] [blame] | 900 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 901 | uintX_t VA = 0; |
Rafael Espindola | 4cda581 | 2015-10-16 15:29:48 +0000 | [diff] [blame] | 902 | if (Sym.st_shndx == SHN_ABS) { |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 903 | ESym->st_shndx = SHN_ABS; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 904 | VA = Sym.st_value; |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 905 | } else { |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 906 | const InputSectionBase<ELFT> *Section = File->getSection(Sym); |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 907 | if (!Section->isLive()) |
| 908 | continue; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 909 | const OutputSectionBase<ELFT> *OutSec = Section->OutSec; |
| 910 | ESym->st_shndx = OutSec->SectionIndex; |
| 911 | VA += OutSec->getVA() + Section->getOffset(Sym); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 912 | } |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 913 | ESym->st_name = StrTabSec.getFileOff(SymName); |
| 914 | ESym->st_size = Sym.st_size; |
| 915 | ESym->setBindingAndType(Sym.getBinding(), Sym.getType()); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 916 | ESym->st_value = VA; |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 917 | Buf += sizeof(*ESym); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 918 | } |
| 919 | } |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 920 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 921 | |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 922 | template <class ELFT> |
Igor Kudrin | ea6a835 | 2015-10-19 08:01:51 +0000 | [diff] [blame] | 923 | void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) { |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 924 | // Write the internal symbol table contents to the output symbol table |
| 925 | // pointed by Buf. |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 926 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 927 | for (const SymbolData &Item : Symbols) { |
| 928 | SymbolBody *Body = Item.Body; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 929 | const OutputSectionBase<ELFT> *OutSec = nullptr; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 930 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 931 | switch (Body->kind()) { |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 932 | case SymbolBody::DefinedSyntheticKind: |
Rui Ueyama | b490876 | 2015-10-07 17:04:18 +0000 | [diff] [blame] | 933 | OutSec = &cast<DefinedSynthetic<ELFT>>(Body)->Section; |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 934 | break; |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 935 | case SymbolBody::DefinedRegularKind: { |
| 936 | auto *Sym = cast<DefinedRegular<ELFT>>(Body->repl()); |
| 937 | if (!Sym->Section.isLive()) |
| 938 | continue; |
| 939 | OutSec = Sym->Section.OutSec; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 940 | break; |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 941 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 942 | case SymbolBody::DefinedCommonKind: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 943 | OutSec = Out<ELFT>::Bss; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 944 | break; |
| 945 | case SymbolBody::UndefinedKind: |
| 946 | case SymbolBody::DefinedAbsoluteKind: |
| 947 | case SymbolBody::SharedKind: |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 948 | case SymbolBody::LazyKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 949 | break; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame^] | 952 | StringRef Name = Body->getName(); |
| 953 | ESym->st_name = StrTabSec.getFileOff(Name); |
| 954 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 955 | unsigned char Type = STT_NOTYPE; |
| 956 | uintX_t Size = 0; |
| 957 | if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) { |
| 958 | const Elf_Sym &InputSym = EBody->Sym; |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 959 | Type = InputSym.getType(); |
| 960 | Size = InputSym.st_size; |
| 961 | } |
| 962 | |
Igor Kudrin | 853b88d | 2015-10-20 20:52:14 +0000 | [diff] [blame] | 963 | ESym->setBindingAndType(getSymbolBinding(Body), Type); |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 964 | ESym->st_size = Size; |
Rui Ueyama | 8f2c4da | 2015-10-21 18:13:47 +0000 | [diff] [blame] | 965 | ESym->setVisibility(Body->getVisibility()); |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 966 | ESym->st_value = getSymVA<ELFT>(*Body); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 967 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 968 | if (isa<DefinedAbsolute<ELFT>>(Body)) |
Rafael Espindola | 6f4bd53 | 2015-10-06 14:17:53 +0000 | [diff] [blame] | 969 | ESym->st_shndx = SHN_ABS; |
Rui Ueyama | b490876 | 2015-10-07 17:04:18 +0000 | [diff] [blame] | 970 | else if (OutSec) |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 971 | ESym->st_shndx = OutSec->SectionIndex; |
Igor Kudrin | ab665fc | 2015-10-20 21:47:58 +0000 | [diff] [blame] | 972 | |
| 973 | ++ESym; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
Igor Kudrin | 853b88d | 2015-10-20 20:52:14 +0000 | [diff] [blame] | 977 | template <class ELFT> |
| 978 | uint8_t SymbolTableSection<ELFT>::getSymbolBinding(SymbolBody *Body) { |
Rui Ueyama | 8f2c4da | 2015-10-21 18:13:47 +0000 | [diff] [blame] | 979 | uint8_t Visibility = Body->getVisibility(); |
Igor Kudrin | 853b88d | 2015-10-20 20:52:14 +0000 | [diff] [blame] | 980 | if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) |
| 981 | return STB_LOCAL; |
| 982 | if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) |
| 983 | return EBody->Sym.getBinding(); |
| 984 | return Body->isWeak() ? STB_WEAK : STB_GLOBAL; |
| 985 | } |
| 986 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 987 | template <class ELFT> |
| 988 | ArrayRef<typename SymbolTableSection<ELFT>::SymbolData> |
| 989 | SymbolTableSection<ELFT>::getGnuHashSymbols() const { |
| 990 | return getSymbols().slice(Symbols.size() - NumGnuHashed); |
| 991 | } |
| 992 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 993 | namespace lld { |
| 994 | namespace elf2 { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 995 | template class OutputSectionBase<ELF32LE>; |
| 996 | template class OutputSectionBase<ELF32BE>; |
| 997 | template class OutputSectionBase<ELF64LE>; |
| 998 | template class OutputSectionBase<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 999 | |
George Rimar | 648a2c3 | 2015-10-20 08:54:27 +0000 | [diff] [blame] | 1000 | template class GotPltSection<ELF32LE>; |
| 1001 | template class GotPltSection<ELF32BE>; |
| 1002 | template class GotPltSection<ELF64LE>; |
| 1003 | template class GotPltSection<ELF64BE>; |
| 1004 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1005 | template class GotSection<ELF32LE>; |
| 1006 | template class GotSection<ELF32BE>; |
| 1007 | template class GotSection<ELF64LE>; |
| 1008 | template class GotSection<ELF64BE>; |
| 1009 | |
| 1010 | template class PltSection<ELF32LE>; |
| 1011 | template class PltSection<ELF32BE>; |
| 1012 | template class PltSection<ELF64LE>; |
| 1013 | template class PltSection<ELF64BE>; |
| 1014 | |
| 1015 | template class RelocationSection<ELF32LE>; |
| 1016 | template class RelocationSection<ELF32BE>; |
| 1017 | template class RelocationSection<ELF64LE>; |
| 1018 | template class RelocationSection<ELF64BE>; |
| 1019 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 1020 | template class InterpSection<ELF32LE>; |
| 1021 | template class InterpSection<ELF32BE>; |
| 1022 | template class InterpSection<ELF64LE>; |
| 1023 | template class InterpSection<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1024 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 1025 | template class GnuHashTableSection<ELF32LE>; |
| 1026 | template class GnuHashTableSection<ELF32BE>; |
| 1027 | template class GnuHashTableSection<ELF64LE>; |
| 1028 | template class GnuHashTableSection<ELF64BE>; |
| 1029 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1030 | template class HashTableSection<ELF32LE>; |
| 1031 | template class HashTableSection<ELF32BE>; |
| 1032 | template class HashTableSection<ELF64LE>; |
| 1033 | template class HashTableSection<ELF64BE>; |
| 1034 | |
| 1035 | template class DynamicSection<ELF32LE>; |
| 1036 | template class DynamicSection<ELF32BE>; |
| 1037 | template class DynamicSection<ELF64LE>; |
| 1038 | template class DynamicSection<ELF64BE>; |
| 1039 | |
| 1040 | template class OutputSection<ELF32LE>; |
| 1041 | template class OutputSection<ELF32BE>; |
| 1042 | template class OutputSection<ELF64LE>; |
| 1043 | template class OutputSection<ELF64BE>; |
| 1044 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 1045 | template class MergeOutputSection<ELF32LE>; |
| 1046 | template class MergeOutputSection<ELF32BE>; |
| 1047 | template class MergeOutputSection<ELF64LE>; |
| 1048 | template class MergeOutputSection<ELF64BE>; |
| 1049 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 1050 | template class StringTableSection<ELF32LE>; |
| 1051 | template class StringTableSection<ELF32BE>; |
| 1052 | template class StringTableSection<ELF64LE>; |
| 1053 | template class StringTableSection<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1054 | |
| 1055 | template class SymbolTableSection<ELF32LE>; |
| 1056 | template class SymbolTableSection<ELF32BE>; |
| 1057 | template class SymbolTableSection<ELF64LE>; |
| 1058 | template class SymbolTableSection<ELF64BE>; |
| 1059 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 1060 | template ELFFile<ELF32LE>::uintX_t getSymVA<ELF32LE>(const SymbolBody &); |
| 1061 | template ELFFile<ELF32BE>::uintX_t getSymVA<ELF32BE>(const SymbolBody &); |
| 1062 | template ELFFile<ELF64LE>::uintX_t getSymVA<ELF64LE>(const SymbolBody &); |
| 1063 | template ELFFile<ELF64BE>::uintX_t getSymVA<ELF64BE>(const SymbolBody &); |
Rafael Espindola | 4ea0021 | 2015-09-21 22:01:00 +0000 | [diff] [blame] | 1064 | |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 1065 | template ELFFile<ELF32LE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 1066 | getLocalRelTarget(const ObjectFile<ELF32LE> &, |
Hal Finkel | 230c5c5 | 2015-10-16 22:37:32 +0000 | [diff] [blame] | 1067 | const ELFFile<ELF32LE>::Elf_Rel &); |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 1068 | template ELFFile<ELF32BE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 1069 | getLocalRelTarget(const ObjectFile<ELF32BE> &, |
Hal Finkel | 230c5c5 | 2015-10-16 22:37:32 +0000 | [diff] [blame] | 1070 | const ELFFile<ELF32BE>::Elf_Rel &); |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 1071 | template ELFFile<ELF64LE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 1072 | getLocalRelTarget(const ObjectFile<ELF64LE> &, |
Hal Finkel | 230c5c5 | 2015-10-16 22:37:32 +0000 | [diff] [blame] | 1073 | const ELFFile<ELF64LE>::Elf_Rel &); |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 1074 | template ELFFile<ELF64BE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 1075 | getLocalRelTarget(const ObjectFile<ELF64BE> &, |
Hal Finkel | 230c5c5 | 2015-10-16 22:37:32 +0000 | [diff] [blame] | 1076 | const ELFFile<ELF64BE>::Elf_Rel &); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 1077 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 1078 | template ELFFile<ELF32LE>::uintX_t |
| 1079 | getLocalRelTarget(const ObjectFile<ELF32LE> &, |
| 1080 | const ELFFile<ELF32LE>::Elf_Rela &); |
| 1081 | template ELFFile<ELF32BE>::uintX_t |
| 1082 | getLocalRelTarget(const ObjectFile<ELF32BE> &, |
| 1083 | const ELFFile<ELF32BE>::Elf_Rela &); |
| 1084 | template ELFFile<ELF64LE>::uintX_t |
| 1085 | getLocalRelTarget(const ObjectFile<ELF64LE> &, |
| 1086 | const ELFFile<ELF64LE>::Elf_Rela &); |
| 1087 | template ELFFile<ELF64BE>::uintX_t |
| 1088 | getLocalRelTarget(const ObjectFile<ELF64BE> &, |
| 1089 | const ELFFile<ELF64BE>::Elf_Rela &); |
| 1090 | |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 1091 | template bool includeInSymtab<ELF32LE>(const SymbolBody &); |
| 1092 | template bool includeInSymtab<ELF32BE>(const SymbolBody &); |
| 1093 | template bool includeInSymtab<ELF64LE>(const SymbolBody &); |
| 1094 | template bool includeInSymtab<ELF64BE>(const SymbolBody &); |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 1095 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 1096 | template bool shouldKeepInSymtab<ELF32LE>(const ObjectFile<ELF32LE> &, |
| 1097 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 1098 | const ELFFile<ELF32LE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 1099 | template bool shouldKeepInSymtab<ELF32BE>(const ObjectFile<ELF32BE> &, |
| 1100 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 1101 | const ELFFile<ELF32BE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 1102 | template bool shouldKeepInSymtab<ELF64LE>(const ObjectFile<ELF64LE> &, |
| 1103 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 1104 | const ELFFile<ELF64LE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 1105 | template bool shouldKeepInSymtab<ELF64BE>(const ObjectFile<ELF64BE> &, |
| 1106 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 1107 | const ELFFile<ELF64BE>::Elf_Sym &); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |