diff options
author | Rui Ueyama <ruiu@google.com> | 2017-02-27 22:39:50 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2017-02-27 22:39:50 +0000 |
commit | 3bc39016cddeca90879bf2e4022190c3fd7a0831 (patch) | |
tree | f792f29f6fdf9d20ec6b874d0289451c22c3f0e5 | |
parent | f52ee17a09eabe216562ef57115d8976b9d7f70e (diff) | |
download | bcm5719-llvm-3bc39016cddeca90879bf2e4022190c3fd7a0831.tar.gz bcm5719-llvm-3bc39016cddeca90879bf2e4022190c3fd7a0831.zip |
Refactor write{Global,Local}Symbols.
This part of code is hard to understand because NumLocals does not
actually mean the number of local symbols but something else (!).
We need to rewrite. But before that we need to clean it up.
llvm-svn: 296400
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index f78b9da6a98..41f176766a0 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1377,7 +1377,6 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { // .dynsym only contains global symbols. if (Config->Discard != DiscardPolicy::All && !StrTabSec.isDynamic()) writeLocalSymbols(Buf); - writeGlobalSymbols(Buf); } @@ -1386,22 +1385,23 @@ void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { // Iterate over all input object files to copy their local symbols // to the output symbol table pointed by Buf. - for (auto I = Symbols.begin(); I != Symbols.begin() + NumLocals; ++I) { - const DefinedRegular<ELFT> &Body = *cast<DefinedRegular<ELFT>>(I->Symbol); - InputSectionBase *Section = Body.Section; + for (auto It = Symbols.begin(), End = Symbols.begin() + NumLocals; + It != End; ++It) { + auto *Body = cast<DefinedRegular<ELFT>>(It->Symbol); + InputSectionBase *Section = Body->Section; auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); if (!Section) { ESym->st_shndx = SHN_ABS; - ESym->st_value = Body.Value; + ESym->st_value = Body->Value; } else { const OutputSection *OutSec = Section->getOutputSection<ELFT>(); ESym->st_shndx = OutSec->SectionIndex; - ESym->st_value = OutSec->Addr + Section->getOffset(Body); + ESym->st_value = OutSec->Addr + Section->getOffset(*Body); } - ESym->st_name = I->StrTabOffset; - ESym->st_size = Body.template getSize<ELFT>(); - ESym->setBindingAndType(STB_LOCAL, Body.Type); + ESym->st_name = It->StrTabOffset; + ESym->st_size = Body->template getSize<ELFT>(); + ESym->setBindingAndType(STB_LOCAL, Body->Type); Buf += sizeof(*ESym); } } @@ -1412,17 +1412,13 @@ void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) { // pointed by Buf. auto *ESym = reinterpret_cast<Elf_Sym *>(Buf); - for (auto I = Symbols.begin() + NumLocals; I != Symbols.end(); ++I) { - const SymbolTableEntry &S = *I; - SymbolBody *Body = S.Symbol; - size_t StrOff = S.StrTabOffset; - - uint8_t Type = Body->Type; - uintX_t Size = Body->getSize<ELFT>(); + for (auto It = Symbols.begin() + NumLocals, End = Symbols.end(); + It != End; ++It) { + SymbolBody *Body = It->Symbol; - ESym->setBindingAndType(Body->symbol()->computeBinding(), Type); - ESym->st_size = Size; - ESym->st_name = StrOff; + ESym->setBindingAndType(Body->symbol()->computeBinding(), Body->Type); + ESym->st_size = Body->getSize<ELFT>(); + ESym->st_name = It->StrTabOffset; ESym->setVisibility(Body->symbol()->Visibility); ESym->st_value = Body->getVA<ELFT>(); |