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