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" |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 14 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 15 | using namespace llvm; |
| 16 | using namespace llvm::object; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 17 | using namespace llvm::support::endian; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 18 | using namespace llvm::ELF; |
| 19 | |
| 20 | using namespace lld; |
| 21 | using namespace lld::elf2; |
| 22 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 23 | template <class ELFT> |
| 24 | OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t sh_type, |
| 25 | uintX_t sh_flags) |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 26 | : Name(Name) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 27 | memset(&Header, 0, sizeof(Elf_Shdr)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 28 | Header.sh_type = sh_type; |
| 29 | Header.sh_flags = sh_flags; |
| 30 | } |
| 31 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 32 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 33 | GotSection<ELFT>::GotSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 34 | : OutputSectionBase<ELFT>(".got", llvm::ELF::SHT_PROGBITS, |
| 35 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { |
Rui Ueyama | 5f551ae | 2015-10-14 14:02:06 +0000 | [diff] [blame] | 36 | this->Header.sh_addralign = sizeof(uintX_t); |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 39 | template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) { |
Rui Ueyama | 49c68a7 | 2015-10-09 00:42:06 +0000 | [diff] [blame] | 40 | Sym->GotIndex = Entries.size(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 41 | Entries.push_back(Sym); |
| 42 | } |
| 43 | |
| 44 | template <class ELFT> |
| 45 | typename GotSection<ELFT>::uintX_t |
| 46 | GotSection<ELFT>::getEntryAddr(const SymbolBody &B) const { |
Rui Ueyama | 5f551ae | 2015-10-14 14:02:06 +0000 | [diff] [blame] | 47 | return this->getVA() + B.GotIndex * sizeof(uintX_t); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 50 | template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) { |
| 51 | for (const SymbolBody *B : Entries) { |
Rafael Espindola | e782f67 | 2015-10-07 03:56:05 +0000 | [diff] [blame] | 52 | uint8_t *Entry = Buf; |
| 53 | Buf += sizeof(uintX_t); |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 54 | if (canBePreempted(B, false)) |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 55 | continue; // The dynamic linker will take care of it. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 56 | uintX_t VA = getSymVA<ELFT>(*B); |
Rafael Espindola | e782f67 | 2015-10-07 03:56:05 +0000 | [diff] [blame] | 57 | write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Entry, VA); |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 61 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 62 | PltSection<ELFT>::PltSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 63 | : OutputSectionBase<ELFT>(".plt", llvm::ELF::SHT_PROGBITS, |
| 64 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 65 | this->Header.sh_addralign = 16; |
| 66 | } |
| 67 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 68 | template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 69 | size_t Off = 0; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 70 | for (const SymbolBody *E : Entries) { |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 71 | uint64_t Got = Out<ELFT>::Got->getEntryAddr(*E); |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 72 | uint64_t Plt = this->getVA() + Off; |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 73 | Target->writePltEntry(Buf + Off, Got, Plt); |
Rui Ueyama | 242ddf4 | 2015-10-12 18:56:36 +0000 | [diff] [blame] | 74 | Off += Target->getPltEntrySize(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody *Sym) { |
Rui Ueyama | 49c68a7 | 2015-10-09 00:42:06 +0000 | [diff] [blame] | 79 | Sym->PltIndex = 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 PltSection<ELFT>::uintX_t |
| 85 | PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 86 | return this->getVA() + B.PltIndex * Target->getPltEntrySize(); |
Hal Finkel | 6c2a3b8 | 2015-10-08 21:51:31 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | template <class ELFT> |
| 90 | void PltSection<ELFT>::finalize() { |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 91 | this->Header.sh_size = Entries.size() * Target->getPltEntrySize(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 94 | template <class ELFT> |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 95 | RelocationSection<ELFT>::RelocationSection(bool IsRela) |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 96 | : OutputSectionBase<ELFT>(IsRela ? ".rela.dyn" : ".rel.dyn", |
| 97 | IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, |
| 98 | llvm::ELF::SHF_ALLOC), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 99 | IsRela(IsRela) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 100 | this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
| 101 | this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 102 | } |
| 103 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 104 | template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 50534c2 | 2015-09-22 17:49:38 +0000 | [diff] [blame] | 105 | const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); |
Rafael Espindola | e1901cc | 2015-09-24 15:11:50 +0000 | [diff] [blame] | 106 | bool IsMips64EL = Relocs[0].C.getFile()->getObj().isMips64EL(); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 107 | for (const DynamicReloc<ELFT> &Rel : Relocs) { |
Rafael Espindola | 50534c2 | 2015-09-22 17:49:38 +0000 | [diff] [blame] | 108 | auto *P = reinterpret_cast<Elf_Rel *>(Buf); |
| 109 | Buf += EntrySize; |
| 110 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 111 | const InputSection<ELFT> &C = Rel.C; |
| 112 | const Elf_Rel &RI = Rel.RI; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 113 | uint32_t SymIndex = RI.getSymbol(IsMips64EL); |
Rafael Espindola | 41127ad | 2015-10-05 22:49:16 +0000 | [diff] [blame] | 114 | const ObjectFile<ELFT> &File = *C.getFile(); |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 115 | SymbolBody *Body = File.getSymbolBody(SymIndex); |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 116 | if (Body) |
| 117 | Body = Body->repl(); |
Rafael Espindola | 41127ad | 2015-10-05 22:49:16 +0000 | [diff] [blame] | 118 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 119 | uint32_t Type = RI.getType(IsMips64EL); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 120 | |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 121 | bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body); |
| 122 | bool CanBePreempted = canBePreempted(Body, NeedsGot); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 123 | uintX_t Addend = 0; |
| 124 | if (!CanBePreempted) { |
| 125 | if (IsRela) { |
| 126 | if (Body) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 127 | Addend += getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body)); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 128 | else |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 129 | Addend += getLocalRelTarget(File, RI, Type); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 130 | } |
| 131 | P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL); |
| 132 | } |
| 133 | |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 134 | if (NeedsGot) { |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 135 | P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body); |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 136 | if (CanBePreempted) |
| 137 | P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 138 | Target->getGotReloc(), IsMips64EL); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 139 | } else { |
Rafael Espindola | 3c83e2b | 2015-10-05 21:09:37 +0000 | [diff] [blame] | 140 | if (IsRela) |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 141 | Addend += static_cast<const Elf_Rela &>(RI).r_addend; |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 142 | P->r_offset = RI.r_offset + C.OutSec->getVA() + C.OutSecOff; |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 143 | if (CanBePreempted) |
Rafael Espindola | ae24400 | 2015-10-05 19:30:12 +0000 | [diff] [blame] | 144 | P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type, |
| 145 | IsMips64EL); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 146 | } |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 147 | |
| 148 | if (IsRela) |
| 149 | static_cast<Elf_Rela *>(P)->r_addend = Addend; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | template <class ELFT> void RelocationSection<ELFT>::finalize() { |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 154 | this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 155 | this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; |
| 156 | } |
| 157 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 158 | template <class ELFT> |
| 159 | InterpSection<ELFT>::InterpSection() |
| 160 | : OutputSectionBase<ELFT>(".interp", llvm::ELF::SHT_PROGBITS, |
| 161 | llvm::ELF::SHF_ALLOC) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 162 | this->Header.sh_size = Config->DynamicLinker.size() + 1; |
| 163 | this->Header.sh_addralign = 1; |
| 164 | } |
| 165 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 166 | template <class ELFT> |
| 167 | void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *SHdr) { |
| 168 | *SHdr = Header; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 171 | template <class ELFT> void InterpSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 172 | memcpy(Buf, Config->DynamicLinker.data(), Config->DynamicLinker.size()); |
| 173 | } |
| 174 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 175 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 176 | HashTableSection<ELFT>::HashTableSection() |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 177 | : OutputSectionBase<ELFT>(".hash", llvm::ELF::SHT_HASH, |
| 178 | llvm::ELF::SHF_ALLOC) { |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 179 | this->Header.sh_entsize = sizeof(Elf_Word); |
| 180 | this->Header.sh_addralign = sizeof(Elf_Word); |
| 181 | } |
| 182 | |
Rui Ueyama | 5f1eee1a | 2015-10-15 21:27:17 +0000 | [diff] [blame] | 183 | static uint32_t hash(StringRef Name) { |
| 184 | uint32_t H = 0; |
| 185 | for (char C : Name) { |
| 186 | H = (H << 4) + C; |
| 187 | uint32_t G = H & 0xf0000000; |
| 188 | if (G) |
| 189 | H ^= G >> 24; |
| 190 | H &= ~G; |
| 191 | } |
| 192 | return H; |
| 193 | } |
| 194 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 195 | template <class ELFT> void HashTableSection<ELFT>::addSymbol(SymbolBody *S) { |
| 196 | StringRef Name = S->getName(); |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 197 | Out<ELFT>::DynSymTab->addSymbol(Name); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 198 | Hashes.push_back(hash(Name)); |
| 199 | S->setDynamicSymbolTableIndex(Hashes.size()); |
| 200 | } |
| 201 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 202 | template <class ELFT> void HashTableSection<ELFT>::finalize() { |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 203 | this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 204 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 205 | assert(Out<ELFT>::DynSymTab->getNumSymbols() == Hashes.size() + 1); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 206 | unsigned NumEntries = 2; // nbucket and nchain. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 207 | NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); // The chain entries. |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 208 | |
| 209 | // Create as many buckets as there are symbols. |
| 210 | // FIXME: This is simplistic. We can try to optimize it, but implementing |
| 211 | // support for SHT_GNU_HASH is probably even more profitable. |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 212 | NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 213 | this->Header.sh_size = NumEntries * sizeof(Elf_Word); |
| 214 | } |
| 215 | |
| 216 | template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 217 | unsigned NumSymbols = Out<ELFT>::DynSymTab->getNumSymbols(); |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 218 | auto *P = reinterpret_cast<Elf_Word *>(Buf); |
| 219 | *P++ = NumSymbols; // nbucket |
| 220 | *P++ = NumSymbols; // nchain |
| 221 | |
| 222 | Elf_Word *Buckets = P; |
| 223 | Elf_Word *Chains = P + NumSymbols; |
| 224 | |
| 225 | for (unsigned I = 1; I < NumSymbols; ++I) { |
| 226 | uint32_t Hash = Hashes[I - 1] % NumSymbols; |
| 227 | Chains[I] = Buckets[Hash]; |
| 228 | Buckets[Hash] = I; |
| 229 | } |
| 230 | } |
| 231 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 232 | template <class ELFT> |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 233 | DynamicSection<ELFT>::DynamicSection(SymbolTable<ELFT> &SymTab) |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 234 | : OutputSectionBase<ELFT>(".dynamic", llvm::ELF::SHT_DYNAMIC, |
| 235 | llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 236 | SymTab(SymTab) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 237 | Elf_Shdr &Header = this->Header; |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 238 | Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 239 | Header.sh_entsize = ELFT::Is64Bits ? 16 : 8; |
| 240 | } |
| 241 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 242 | template <class ELFT> void DynamicSection<ELFT>::finalize() { |
Michael J. Spencer | 52bf0eb | 2015-10-01 21:15:02 +0000 | [diff] [blame] | 243 | if (this->Header.sh_size) |
| 244 | return; // Already finalized. |
| 245 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 246 | Elf_Shdr &Header = this->Header; |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 247 | Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 248 | |
| 249 | unsigned NumEntries = 0; |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 250 | if (Out<ELFT>::RelaDyn->hasRelocs()) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 251 | ++NumEntries; // DT_RELA / DT_REL |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 252 | ++NumEntries; // DT_RELASZ / DT_RELSZ |
| 253 | ++NumEntries; // DT_RELAENT / DT_RELENT |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 254 | } |
| 255 | ++NumEntries; // DT_SYMTAB |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 256 | ++NumEntries; // DT_SYMENT |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 257 | ++NumEntries; // DT_STRTAB |
| 258 | ++NumEntries; // DT_STRSZ |
| 259 | ++NumEntries; // DT_HASH |
| 260 | |
Rui Ueyama | 7de3f37 | 2015-10-01 19:36:04 +0000 | [diff] [blame] | 261 | if (!Config->RPath.empty()) { |
Davide Italiano | c39c75d | 2015-10-06 16:20:00 +0000 | [diff] [blame] | 262 | ++NumEntries; // DT_RUNPATH / DT_RPATH |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 263 | Out<ELFT>::DynStrTab->add(Config->RPath); |
Rui Ueyama | 7de3f37 | 2015-10-01 19:36:04 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (!Config->SoName.empty()) { |
| 267 | ++NumEntries; // DT_SONAME |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 268 | Out<ELFT>::DynStrTab->add(Config->SoName); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 271 | if (PreInitArraySec) |
| 272 | NumEntries += 2; |
| 273 | if (InitArraySec) |
| 274 | NumEntries += 2; |
| 275 | if (FiniArraySec) |
| 276 | NumEntries += 2; |
| 277 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 278 | for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) { |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 279 | if (!F->isNeeded()) |
| 280 | continue; |
Rui Ueyama | 6ccc8ca | 2015-10-09 20:32:54 +0000 | [diff] [blame] | 281 | Out<ELFT>::DynStrTab->add(F->getSoName()); |
| 282 | ++NumEntries; |
| 283 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 284 | |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 285 | if (Symbol *S = SymTab.getSymbols().lookup(Config->Init)) |
| 286 | InitSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); |
| 287 | if (Symbol *S = SymTab.getSymbols().lookup(Config->Fini)) |
| 288 | FiniSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 289 | if (InitSym) |
| 290 | ++NumEntries; // DT_INIT |
| 291 | if (FiniSym) |
| 292 | ++NumEntries; // DT_FINI |
Davide Italiano | cebb449 | 2015-10-13 21:02:34 +0000 | [diff] [blame] | 293 | if (Config->ZNow || Config->Bsymbolic) |
George Rimar | 97aad17 | 2015-10-07 15:00:21 +0000 | [diff] [blame] | 294 | ++NumEntries; // DT_FLAGS_1 |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 295 | ++NumEntries; // DT_NULL |
| 296 | |
| 297 | Header.sh_size = NumEntries * Header.sh_entsize; |
| 298 | } |
| 299 | |
| 300 | template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 301 | auto *P = reinterpret_cast<Elf_Dyn *>(Buf); |
| 302 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 303 | auto WritePtr = [&](int32_t Tag, uint64_t Val) { |
| 304 | P->d_tag = Tag; |
| 305 | P->d_un.d_ptr = Val; |
| 306 | ++P; |
| 307 | }; |
| 308 | |
| 309 | auto WriteVal = [&](int32_t Tag, uint32_t Val) { |
| 310 | P->d_tag = Tag; |
| 311 | P->d_un.d_val = Val; |
| 312 | ++P; |
| 313 | }; |
| 314 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 315 | if (Out<ELFT>::RelaDyn->hasRelocs()) { |
| 316 | bool IsRela = Out<ELFT>::RelaDyn->isRela(); |
| 317 | WritePtr(IsRela ? DT_RELA : DT_REL, Out<ELFT>::RelaDyn->getVA()); |
| 318 | WriteVal(IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->getSize()); |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 319 | WriteVal(IsRela ? DT_RELAENT : DT_RELENT, |
| 320 | IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 321 | } |
Rui Ueyama | c58656c | 2015-10-13 16:59:30 +0000 | [diff] [blame] | 322 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 323 | WritePtr(DT_SYMTAB, Out<ELFT>::DynSymTab->getVA()); |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 324 | WritePtr(DT_SYMENT, sizeof(Elf_Sym)); |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 325 | WritePtr(DT_STRTAB, Out<ELFT>::DynStrTab->getVA()); |
| 326 | WriteVal(DT_STRSZ, Out<ELFT>::DynStrTab->data().size()); |
| 327 | WritePtr(DT_HASH, Out<ELFT>::HashTab->getVA()); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 328 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 329 | if (!Config->RPath.empty()) |
Davide Italiano | c39c75d | 2015-10-06 16:20:00 +0000 | [diff] [blame] | 330 | |
| 331 | // If --enable-new-dtags is set lld emits DT_RUNPATH |
| 332 | // instead of DT_RPATH. The two tags are functionally |
| 333 | // equivalent except for the following: |
| 334 | // - DT_RUNPATH is searched after LD_LIBRARY_PATH, while |
| 335 | // DT_RPATH is searched before. |
| 336 | // - DT_RUNPATH is used only to search for direct |
| 337 | // dependencies of the object it's contained in, while |
| 338 | // DT_RPATH is used for indirect dependencies as well. |
| 339 | WriteVal(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 340 | Out<ELFT>::DynStrTab->getFileOff(Config->RPath)); |
Rui Ueyama | 2dfd74f | 2015-09-30 21:57:53 +0000 | [diff] [blame] | 341 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 342 | if (!Config->SoName.empty()) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 343 | WriteVal(DT_SONAME, Out<ELFT>::DynStrTab->getFileOff(Config->SoName)); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 344 | |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 345 | auto WriteArray = [&](int32_t T1, int32_t T2, |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 346 | const OutputSectionBase<ELFT> *Sec) { |
Rafael Espindola | 7757224 | 2015-10-02 19:37:55 +0000 | [diff] [blame] | 347 | if (!Sec) |
| 348 | return; |
| 349 | WritePtr(T1, Sec->getVA()); |
| 350 | WriteVal(T2, Sec->getSize()); |
| 351 | }; |
| 352 | WriteArray(DT_PREINIT_ARRAY, DT_PREINIT_ARRAYSZ, PreInitArraySec); |
| 353 | WriteArray(DT_INIT_ARRAY, DT_INIT_ARRAYSZ, InitArraySec); |
| 354 | WriteArray(DT_FINI_ARRAY, DT_FINI_ARRAYSZ, FiniArraySec); |
| 355 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 356 | for (const std::unique_ptr<SharedFile<ELFT>> &F : SymTab.getSharedFiles()) |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 357 | if (F->isNeeded()) |
| 358 | WriteVal(DT_NEEDED, Out<ELFT>::DynStrTab->getFileOff(F->getSoName())); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 359 | |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 360 | if (InitSym) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 361 | WritePtr(DT_INIT, getSymVA<ELFT>(*InitSym)); |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 362 | if (FiniSym) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 363 | WritePtr(DT_FINI, getSymVA<ELFT>(*FiniSym)); |
Igor Kudrin | b1f2b51 | 2015-10-05 10:29:46 +0000 | [diff] [blame] | 364 | |
Davide Italiano | cebb449 | 2015-10-13 21:02:34 +0000 | [diff] [blame] | 365 | uint32_t Flags = 0; |
| 366 | if (Config->Bsymbolic) |
| 367 | Flags |= DF_SYMBOLIC; |
George Rimar | 97aad17 | 2015-10-07 15:00:21 +0000 | [diff] [blame] | 368 | if (Config->ZNow) |
Davide Italiano | cebb449 | 2015-10-13 21:02:34 +0000 | [diff] [blame] | 369 | Flags |= DF_1_NOW; |
| 370 | if (Flags) |
| 371 | WriteVal(DT_FLAGS_1, Flags); |
George Rimar | 97aad17 | 2015-10-07 15:00:21 +0000 | [diff] [blame] | 372 | |
Rui Ueyama | 8c205d5 | 2015-10-02 01:33:31 +0000 | [diff] [blame] | 373 | WriteVal(DT_NULL, 0); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 377 | OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t sh_type, |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 378 | uintX_t sh_flags) |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 379 | : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {} |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 380 | |
| 381 | template <class ELFT> |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 382 | void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) { |
| 383 | Sections.push_back(C); |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 384 | C->OutSec = this; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 385 | uint32_t Align = C->getAlign(); |
| 386 | if (Align > this->Header.sh_addralign) |
| 387 | this->Header.sh_addralign = Align; |
| 388 | |
| 389 | uintX_t Off = this->Header.sh_size; |
| 390 | Off = RoundUpToAlignment(Off, Align); |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 391 | C->OutSecOff = Off; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 392 | Off += C->getSize(); |
| 393 | this->Header.sh_size = Off; |
| 394 | } |
| 395 | |
| 396 | template <class ELFT> |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 397 | typename ELFFile<ELFT>::uintX_t lld::elf2::getSymVA(const SymbolBody &S) { |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 398 | switch (S.kind()) { |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 399 | case SymbolBody::DefinedSyntheticKind: { |
| 400 | auto &D = cast<DefinedSynthetic<ELFT>>(S); |
| 401 | return D.Section.getVA() + D.Sym.st_value; |
| 402 | } |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 403 | case SymbolBody::DefinedAbsoluteKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 404 | return cast<DefinedAbsolute<ELFT>>(S).Sym.st_value; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 405 | case SymbolBody::DefinedRegularKind: { |
| 406 | const auto &DR = cast<DefinedRegular<ELFT>>(S); |
| 407 | const InputSection<ELFT> *SC = &DR.Section; |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 408 | return SC->OutSec->getVA() + SC->OutSecOff + DR.Sym.st_value; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 409 | } |
| 410 | case SymbolBody::DefinedCommonKind: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 411 | return Out<ELFT>::Bss->getVA() + cast<DefinedCommon<ELFT>>(S).OffsetInBSS; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 412 | case SymbolBody::SharedKind: |
| 413 | case SymbolBody::UndefinedKind: |
| 414 | return 0; |
| 415 | case SymbolBody::LazyKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 416 | assert(S.isUsedInRegularObj() && "Lazy symbol reached writer"); |
| 417 | return 0; |
Rafael Espindola | cd076f0 | 2015-09-25 18:19:03 +0000 | [diff] [blame] | 418 | } |
Denis Protivensky | 92aa1c0 | 2015-10-07 08:21:34 +0000 | [diff] [blame] | 419 | llvm_unreachable("Invalid symbol kind"); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 422 | // Returns a VA which a relocatin RI refers to. Used only for local symbols. |
| 423 | // For non-local symbols, use getSymVA instead. |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 424 | template <class ELFT> |
| 425 | typename ELFFile<ELFT>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 426 | lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File, |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 427 | const typename ELFFile<ELFT>::Elf_Rel &RI, |
| 428 | uint32_t Type) { |
| 429 | // PPC64 has a special relocation representing the TOC base pointer |
| 430 | // that does not have a corresponding symbol. |
| 431 | if (Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC) |
| 432 | return getPPC64TocBase(); |
| 433 | |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 434 | typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym; |
| 435 | const Elf_Sym *Sym = |
| 436 | File.getObj().getRelocationSymbol(&RI, File.getSymbolTable()); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 437 | |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 438 | if (!Sym) |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 439 | error("Unsupported relocation without symbol"); |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 440 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 441 | // According to the ELF spec reference to a local symbol from outside |
| 442 | // the group are not allowed. Unfortunately .eh_frame breaks that rule |
| 443 | // and must be treated specially. For now we just replace the symbol with |
| 444 | // 0. |
Rafael Espindola | 4cda581 | 2015-10-16 15:29:48 +0000 | [diff] [blame] | 445 | InputSection<ELFT> *Section = File.getSection(*Sym); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 446 | if (Section == &InputSection<ELFT>::Discarded) |
| 447 | return 0; |
| 448 | |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 449 | return Section->OutSec->getVA() + Section->OutSecOff + Sym->st_value; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 452 | // Returns true if a symbol can be replaced at load-time by a symbol |
| 453 | // with the same name defined in other ELF executable or DSO. |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 454 | bool lld::elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) { |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 455 | if (!Body) |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 456 | return false; // Body is a local symbol. |
Rafael Espindola | cea0b3b | 2015-10-07 04:22:55 +0000 | [diff] [blame] | 457 | if (Body->isShared()) |
| 458 | return true; |
Rafael Espindola | cc6ebb8 | 2015-10-14 18:42:16 +0000 | [diff] [blame] | 459 | |
| 460 | if (Body->isUndefined()) { |
| 461 | if (!Body->isWeak()) |
| 462 | return true; |
| 463 | |
| 464 | // This is an horrible corner case. Ideally we would like to say that any |
| 465 | // undefined symbol can be preempted so that the dynamic linker has a |
| 466 | // chance of finding it at runtime. |
| 467 | // |
| 468 | // The problem is that the code sequence used to test for weak undef |
| 469 | // functions looks like |
| 470 | // if (func) func() |
| 471 | // If the code is -fPIC the first reference is a load from the got and |
| 472 | // everything works. |
| 473 | // If the code is not -fPIC there is no reasonable way to solve it: |
| 474 | // * A relocation writing to the text segment will fail (it is ro). |
| 475 | // * A copy relocation doesn't work for functions. |
| 476 | // * The trick of using a plt entry as the address would fail here since |
| 477 | // the plt entry would have a non zero address. |
| 478 | // Since we cannot do anything better, we just resolve the symbol to 0 and |
| 479 | // don't produce a dynamic relocation. |
| 480 | return NeedsGot; |
| 481 | } |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 482 | if (!Config->Shared) |
| 483 | return false; |
Rafael Espindola | 52dca34 | 2015-10-07 00:58:20 +0000 | [diff] [blame] | 484 | return Body->getMostConstrainingVisibility() == STV_DEFAULT; |
Rafael Espindola | a662738 | 2015-10-06 23:56:53 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 487 | template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 488 | for (InputSection<ELFT> *C : Sections) |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 489 | C->writeTo(Buf); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 492 | template <class ELFT> |
| 493 | StringTableSection<ELFT>::StringTableSection(bool Dynamic) |
| 494 | : OutputSectionBase<ELFT>(Dynamic ? ".dynstr" : ".strtab", |
| 495 | llvm::ELF::SHT_STRTAB, |
| 496 | Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 497 | Dynamic(Dynamic) { |
| 498 | this->Header.sh_addralign = 1; |
| 499 | } |
| 500 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 501 | template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 502 | StringRef Data = StrTabBuilder.data(); |
| 503 | memcpy(Buf, Data.data(), Data.size()); |
| 504 | } |
| 505 | |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 506 | template <class ELFT> bool lld::elf2::includeInSymtab(const SymbolBody &B) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 507 | if (!B.isUsedInRegularObj()) |
| 508 | return false; |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 509 | |
| 510 | // Don't include synthetic symbols like __init_array_start in every output. |
| 511 | if (auto *U = dyn_cast<DefinedAbsolute<ELFT>>(&B)) |
| 512 | if (&U->Sym == &DefinedAbsolute<ELFT>::IgnoreUndef) |
| 513 | return false; |
| 514 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 515 | return true; |
| 516 | } |
| 517 | |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 518 | bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) { |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 519 | uint8_t V = B.getMostConstrainingVisibility(); |
| 520 | if (V != STV_DEFAULT && V != STV_PROTECTED) |
| 521 | return false; |
| 522 | |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 523 | if (Config->ExportDynamic || Config->Shared) |
| 524 | return true; |
| 525 | return B.isUsedInDynamicReloc(); |
| 526 | } |
| 527 | |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 528 | template <class ELFT> |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 529 | bool lld::elf2::shouldKeepInSymtab(const ObjectFile<ELFT> &File, |
| 530 | StringRef SymName, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 531 | const typename ELFFile<ELFT>::Elf_Sym &Sym) { |
| 532 | if (Sym.getType() == STT_SECTION) |
| 533 | return false; |
| 534 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 535 | // 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] | 536 | if (File.getSection(Sym) == &InputSection<ELFT>::Discarded) |
| 537 | return false; |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 538 | |
Davide Italiano | 6993ba4 | 2015-09-26 00:47:56 +0000 | [diff] [blame] | 539 | if (Config->DiscardNone) |
| 540 | return true; |
| 541 | |
| 542 | // ELF defines dynamic locals as symbols which name starts with ".L". |
| 543 | return !(Config->DiscardLocals && SymName.startswith(".L")); |
| 544 | } |
| 545 | |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 546 | template <class ELFT> |
| 547 | SymbolTableSection<ELFT>::SymbolTableSection( |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 548 | SymbolTable<ELFT> &Table, StringTableSection<ELFT> &StrTabSec) |
| 549 | : OutputSectionBase<ELFT>( |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 550 | StrTabSec.isDynamic() ? ".dynsym" : ".symtab", |
| 551 | StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB, |
| 552 | StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 553 | Table(Table), StrTabSec(StrTabSec) { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 554 | typedef OutputSectionBase<ELFT> Base; |
| 555 | typename Base::Elf_Shdr &Header = this->Header; |
Rafael Espindola | 35c6af3 | 2015-09-25 17:19:10 +0000 | [diff] [blame] | 556 | |
| 557 | Header.sh_entsize = sizeof(Elf_Sym); |
| 558 | Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; |
| 559 | } |
| 560 | |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 561 | template <class ELFT> void SymbolTableSection<ELFT>::finalize() { |
| 562 | this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym); |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 563 | this->Header.sh_link = StrTabSec.SectionIndex; |
Rui Ueyama | 0db335f | 2015-10-07 16:58:54 +0000 | [diff] [blame] | 564 | this->Header.sh_info = NumLocals + 1; |
| 565 | } |
| 566 | |
| 567 | template <class ELFT> |
| 568 | void SymbolTableSection<ELFT>::addSymbol(StringRef Name, bool isLocal) { |
| 569 | StrTabSec.add(Name); |
| 570 | ++NumVisible; |
| 571 | if (isLocal) |
| 572 | ++NumLocals; |
| 573 | } |
| 574 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 575 | template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 576 | Buf += sizeof(Elf_Sym); |
| 577 | |
| 578 | // All symbols with STB_LOCAL binding precede the weak and global symbols. |
| 579 | // .dynsym only contains global symbols. |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 580 | if (!Config->DiscardAll && !StrTabSec.isDynamic()) |
| 581 | writeLocalSymbols(Buf); |
| 582 | |
| 583 | writeGlobalSymbols(Buf); |
| 584 | } |
| 585 | |
| 586 | template <class ELFT> |
| 587 | void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { |
| 588 | // Iterate over all input object files to copy their local symbols |
| 589 | // to the output symbol table pointed by Buf. |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 590 | for (const std::unique_ptr<ObjectFile<ELFT>> &File : Table.getObjectFiles()) { |
| 591 | Elf_Sym_Range Syms = File->getLocalSymbols(); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 592 | for (const Elf_Sym &Sym : Syms) { |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 593 | ErrorOr<StringRef> SymNameOrErr = Sym.getName(File->getStringTable()); |
Rafael Espindola | 26fd69d | 2015-10-09 16:15:57 +0000 | [diff] [blame] | 594 | error(SymNameOrErr); |
| 595 | StringRef SymName = *SymNameOrErr; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 596 | if (!shouldKeepInSymtab<ELFT>(*File, SymName, Sym)) |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 597 | continue; |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 598 | |
Rui Ueyama | c55733e | 2015-09-30 00:54:29 +0000 | [diff] [blame] | 599 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
| 600 | Buf += sizeof(*ESym); |
Rafael Espindola | 26fd69d | 2015-10-09 16:15:57 +0000 | [diff] [blame] | 601 | ESym->st_name = StrTabSec.getFileOff(SymName); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 602 | ESym->st_size = Sym.st_size; |
| 603 | ESym->setBindingAndType(Sym.getBinding(), Sym.getType()); |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 604 | uintX_t VA = Sym.st_value; |
Rafael Espindola | 4cda581 | 2015-10-16 15:29:48 +0000 | [diff] [blame] | 605 | if (Sym.st_shndx == SHN_ABS) { |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 606 | ESym->st_shndx = SHN_ABS; |
| 607 | } else { |
Rafael Espindola | 4cda581 | 2015-10-16 15:29:48 +0000 | [diff] [blame] | 608 | const InputSection<ELFT> *Sec = File->getSection(Sym); |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 609 | ESym->st_shndx = Sec->OutSec->SectionIndex; |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 610 | VA += Sec->OutSec->getVA() + Sec->OutSecOff; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 611 | } |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 612 | ESym->st_value = VA; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 615 | } |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 616 | |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 617 | template <class ELFT> |
| 618 | void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *&Buf) { |
| 619 | // Write the internal symbol table contents to the output symbol table |
| 620 | // pointed by Buf. |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 621 | uint8_t *Start = Buf; |
Rui Ueyama | 8ddfa81 | 2015-09-30 00:32:10 +0000 | [diff] [blame] | 622 | for (const std::pair<StringRef, Symbol *> &P : Table.getSymbols()) { |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 623 | StringRef Name = P.first; |
| 624 | Symbol *Sym = P.second; |
| 625 | SymbolBody *Body = Sym->Body; |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 626 | if (!includeInSymtab<ELFT>(*Body)) |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 627 | continue; |
Rafael Espindola | 05a3dd2 | 2015-09-22 23:38:23 +0000 | [diff] [blame] | 628 | if (StrTabSec.isDynamic() && !includeInDynamicSymtab(*Body)) |
| 629 | continue; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 630 | |
| 631 | auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); |
Rui Ueyama | c55733e | 2015-09-30 00:54:29 +0000 | [diff] [blame] | 632 | Buf += sizeof(*ESym); |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 633 | |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 634 | ESym->st_name = StrTabSec.getFileOff(Name); |
| 635 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 636 | const OutputSectionBase<ELFT> *OutSec = nullptr; |
Rafael Espindola | 25b0acb | 2015-09-25 17:32:37 +0000 | [diff] [blame] | 637 | const InputSection<ELFT> *Section = nullptr; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 638 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 639 | switch (Body->kind()) { |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 640 | case SymbolBody::DefinedSyntheticKind: |
Rui Ueyama | b490876 | 2015-10-07 17:04:18 +0000 | [diff] [blame] | 641 | OutSec = &cast<DefinedSynthetic<ELFT>>(Body)->Section; |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 642 | break; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 643 | case SymbolBody::DefinedRegularKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 644 | Section = &cast<DefinedRegular<ELFT>>(Body)->Section; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 645 | break; |
| 646 | case SymbolBody::DefinedCommonKind: |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 647 | OutSec = Out<ELFT>::Bss; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 648 | break; |
| 649 | case SymbolBody::UndefinedKind: |
| 650 | case SymbolBody::DefinedAbsoluteKind: |
| 651 | case SymbolBody::SharedKind: |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 652 | case SymbolBody::LazyKind: |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 653 | break; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 656 | unsigned char Binding = Body->isWeak() ? STB_WEAK : STB_GLOBAL; |
| 657 | unsigned char Type = STT_NOTYPE; |
| 658 | uintX_t Size = 0; |
| 659 | if (const auto *EBody = dyn_cast<ELFSymbolBody<ELFT>>(Body)) { |
| 660 | const Elf_Sym &InputSym = EBody->Sym; |
| 661 | Binding = InputSym.getBinding(); |
| 662 | Type = InputSym.getType(); |
| 663 | Size = InputSym.st_size; |
| 664 | } |
| 665 | |
| 666 | unsigned char Visibility = Body->getMostConstrainingVisibility(); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 667 | if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) |
| 668 | Binding = STB_LOCAL; |
| 669 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 670 | ESym->setBindingAndType(Binding, Type); |
| 671 | ESym->st_size = Size; |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 672 | ESym->setVisibility(Visibility); |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 673 | ESym->st_value = getSymVA<ELFT>(*Body); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 674 | |
| 675 | if (Section) |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 676 | OutSec = Section->OutSec; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 677 | |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 678 | if (isa<DefinedAbsolute<ELFT>>(Body)) |
Rafael Espindola | 6f4bd53 | 2015-10-06 14:17:53 +0000 | [diff] [blame] | 679 | ESym->st_shndx = SHN_ABS; |
Rui Ueyama | b490876 | 2015-10-07 17:04:18 +0000 | [diff] [blame] | 680 | else if (OutSec) |
Rui Ueyama | 2317d0d | 2015-10-15 20:55:22 +0000 | [diff] [blame] | 681 | ESym->st_shndx = OutSec->SectionIndex; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 682 | } |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 683 | if (!StrTabSec.isDynamic()) |
| 684 | std::stable_sort( |
| 685 | reinterpret_cast<Elf_Sym *>(Start), reinterpret_cast<Elf_Sym *>(Buf), |
| 686 | [](const Elf_Sym &A, const Elf_Sym &B) -> bool { |
| 687 | return A.getBinding() == STB_LOCAL && B.getBinding() != STB_LOCAL; |
| 688 | }); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | namespace lld { |
| 692 | namespace elf2 { |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 693 | template class OutputSectionBase<ELF32LE>; |
| 694 | template class OutputSectionBase<ELF32BE>; |
| 695 | template class OutputSectionBase<ELF64LE>; |
| 696 | template class OutputSectionBase<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 697 | |
| 698 | template class GotSection<ELF32LE>; |
| 699 | template class GotSection<ELF32BE>; |
| 700 | template class GotSection<ELF64LE>; |
| 701 | template class GotSection<ELF64BE>; |
| 702 | |
| 703 | template class PltSection<ELF32LE>; |
| 704 | template class PltSection<ELF32BE>; |
| 705 | template class PltSection<ELF64LE>; |
| 706 | template class PltSection<ELF64BE>; |
| 707 | |
| 708 | template class RelocationSection<ELF32LE>; |
| 709 | template class RelocationSection<ELF32BE>; |
| 710 | template class RelocationSection<ELF64LE>; |
| 711 | template class RelocationSection<ELF64BE>; |
| 712 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 713 | template class InterpSection<ELF32LE>; |
| 714 | template class InterpSection<ELF32BE>; |
| 715 | template class InterpSection<ELF64LE>; |
| 716 | template class InterpSection<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 717 | |
| 718 | template class HashTableSection<ELF32LE>; |
| 719 | template class HashTableSection<ELF32BE>; |
| 720 | template class HashTableSection<ELF64LE>; |
| 721 | template class HashTableSection<ELF64BE>; |
| 722 | |
| 723 | template class DynamicSection<ELF32LE>; |
| 724 | template class DynamicSection<ELF32BE>; |
| 725 | template class DynamicSection<ELF64LE>; |
| 726 | template class DynamicSection<ELF64BE>; |
| 727 | |
| 728 | template class OutputSection<ELF32LE>; |
| 729 | template class OutputSection<ELF32BE>; |
| 730 | template class OutputSection<ELF64LE>; |
| 731 | template class OutputSection<ELF64BE>; |
| 732 | |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 733 | template class StringTableSection<ELF32LE>; |
| 734 | template class StringTableSection<ELF32BE>; |
| 735 | template class StringTableSection<ELF64LE>; |
| 736 | template class StringTableSection<ELF64BE>; |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 737 | |
| 738 | template class SymbolTableSection<ELF32LE>; |
| 739 | template class SymbolTableSection<ELF32BE>; |
| 740 | template class SymbolTableSection<ELF64LE>; |
| 741 | template class SymbolTableSection<ELF64BE>; |
| 742 | |
Rui Ueyama | 15ef5e1 | 2015-10-07 19:18:16 +0000 | [diff] [blame] | 743 | template ELFFile<ELF32LE>::uintX_t getSymVA<ELF32LE>(const SymbolBody &); |
| 744 | template ELFFile<ELF32BE>::uintX_t getSymVA<ELF32BE>(const SymbolBody &); |
| 745 | template ELFFile<ELF64LE>::uintX_t getSymVA<ELF64LE>(const SymbolBody &); |
| 746 | template ELFFile<ELF64BE>::uintX_t getSymVA<ELF64BE>(const SymbolBody &); |
Rafael Espindola | 4ea0021 | 2015-09-21 22:01:00 +0000 | [diff] [blame] | 747 | |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 748 | template ELFFile<ELF32LE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 749 | getLocalRelTarget(const ObjectFile<ELF32LE> &, |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 750 | const ELFFile<ELF32LE>::Elf_Rel &, uint32_t); |
Rafael Espindola | 4ea0021 | 2015-09-21 22:01:00 +0000 | [diff] [blame] | 751 | |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 752 | template ELFFile<ELF32BE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 753 | getLocalRelTarget(const ObjectFile<ELF32BE> &, |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 754 | const ELFFile<ELF32BE>::Elf_Rel &, uint32_t); |
Rafael Espindola | 4ea0021 | 2015-09-21 22:01:00 +0000 | [diff] [blame] | 755 | |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 756 | template ELFFile<ELF64LE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 757 | getLocalRelTarget(const ObjectFile<ELF64LE> &, |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 758 | const ELFFile<ELF64LE>::Elf_Rel &, uint32_t); |
Rafael Espindola | 4ea0021 | 2015-09-21 22:01:00 +0000 | [diff] [blame] | 759 | |
Rafael Espindola | 56f965f | 2015-09-21 22:48:12 +0000 | [diff] [blame] | 760 | template ELFFile<ELF64BE>::uintX_t |
Rui Ueyama | 126d08f | 2015-10-12 20:28:22 +0000 | [diff] [blame] | 761 | getLocalRelTarget(const ObjectFile<ELF64BE> &, |
Hal Finkel | 6f97c2b | 2015-10-16 21:55:40 +0000 | [diff] [blame^] | 762 | const ELFFile<ELF64BE>::Elf_Rel &, uint32_t); |
Rafael Espindola | 4f674ed | 2015-10-05 15:24:04 +0000 | [diff] [blame] | 763 | |
| 764 | template bool includeInSymtab<ELF32LE>(const SymbolBody &); |
| 765 | template bool includeInSymtab<ELF32BE>(const SymbolBody &); |
| 766 | template bool includeInSymtab<ELF64LE>(const SymbolBody &); |
| 767 | template bool includeInSymtab<ELF64BE>(const SymbolBody &); |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 768 | |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 769 | template bool shouldKeepInSymtab<ELF32LE>(const ObjectFile<ELF32LE> &, |
| 770 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 771 | const ELFFile<ELF32LE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 772 | template bool shouldKeepInSymtab<ELF32BE>(const ObjectFile<ELF32BE> &, |
| 773 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 774 | const ELFFile<ELF32BE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 775 | template bool shouldKeepInSymtab<ELF64LE>(const ObjectFile<ELF64LE> &, |
| 776 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 777 | const ELFFile<ELF64LE>::Elf_Sym &); |
Rafael Espindola | 444576d | 2015-10-09 19:25:07 +0000 | [diff] [blame] | 778 | template bool shouldKeepInSymtab<ELF64BE>(const ObjectFile<ELF64BE> &, |
| 779 | StringRef, |
Rafael Espindola | d1cf421 | 2015-10-05 16:25:43 +0000 | [diff] [blame] | 780 | const ELFFile<ELF64BE>::Elf_Sym &); |
Rafael Espindola | 5805c4f | 2015-09-21 21:38:08 +0000 | [diff] [blame] | 781 | } |
| 782 | } |