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