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