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