From 7f37775e56e24770edb30205c9cddae23a7754b4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 1 Sep 2015 20:30:52 +0000 Subject: [PATCH] Every symbol now has an Elf_Sym. Simplify. NFC. llvm-svn: 246581 --- lld/ELF/Writer.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 91a0bf5abaa4..7faa71d759ab 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -298,43 +298,36 @@ template void SymbolTableSection::writeTo(uint8_t *Buf) { for (auto &P : Table.getSymbols()) { StringRef Name = P.first; Symbol *Sym = P.second; + SymbolBody *Body = Sym->Body; + const Elf_Sym &InputSym = cast>(Body)->Sym; auto *ESym = reinterpret_cast(Buf); ESym->st_name = Builder.getOffset(Name); - SymbolBody *Body = Sym->Body; const SectionChunk *Section = nullptr; - const Elf_Sym *InputSym = nullptr; OutputSection *Out = nullptr; switch (Body->kind()) { - case SymbolBody::DefinedRegularKind: { - auto *Def = cast>(Body); - InputSym = &Def->Sym; - Section = &Def->Section; + case SymbolBody::DefinedRegularKind: + Section = &cast>(Body)->Section; break; - } case SymbolBody::DefinedCommonKind: - InputSym = &cast>(Body)->Sym; Out = BSSSec; break; case SymbolBody::UndefinedKind: assert(Body->isWeak() && "Should be defined by now"); case SymbolBody::DefinedAbsoluteKind: - InputSym = &cast>(Body)->Sym; break; } - if (InputSym) { - uint8_t Type = InputSym->getType(); - uint8_t Binding = InputSym->getBinding(); - ESym->setBindingAndType(Binding, Type); - ESym->st_size = InputSym->st_size; - ESym->st_other = InputSym->st_other; - if (InputSym->isAbsolute()) { - ESym->st_shndx = SHN_ABS; - ESym->st_value = InputSym->st_value; - } + uint8_t Type = InputSym.getType(); + uint8_t Binding = InputSym.getBinding(); + ESym->setBindingAndType(Binding, Type); + ESym->st_size = InputSym.st_size; + ESym->st_other = InputSym.st_other; + if (InputSym.isAbsolute()) { + ESym->st_shndx = SHN_ABS; + ESym->st_value = InputSym.st_value; } if (Section) @@ -348,7 +341,7 @@ template void SymbolTableSection::writeTo(uint8_t *Buf) { if (auto *C = dyn_cast>(Body)) VA += C->OffsetInBSS; else - VA += InputSym->st_value; + VA += InputSym.st_value; ESym->st_value = VA; }