llvm.org GIT mirror llvm / 984cea8
[yaml2obj] - Cleanup and simplify the code. NFCI. The current code has the following problems: `initSymtabSectionHeader` and `initStrtabSectionHeader` method names saying us they are going to initialize the section headers. Though for a few cases sh_flags field is initialized outside of them. It does not look clean. This patch moves initialization of the sh_flags inside these methods. Also, it removes an excessive variable, what together with the above change hopefully makes the code a bit more readable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359443 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 5 months ago
1 changed file(s) with 15 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
324324 SHeader.sh_name = DotShStrtab.getOffset(IsStatic ? ".symtab" : ".dynsym");
325325 SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
326326 SHeader.sh_link = IsStatic ? getDotStrTabSecNo() : getDotDynStrSecNo();
327 if (!IsStatic)
328 SHeader.sh_flags |= ELF::SHF_ALLOC;
327329
328330 // One greater than symbol table index of the last local symbol.
329331 const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols;
377379 unsigned SecNdx = getDotDynStrSecNo() - 1;
378380 if (SecNdx < Doc.Sections.size())
379381 SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
382
383 // We assume that .dynstr is always allocatable.
384 SHeader.sh_flags |= ELF::SHF_ALLOC;
380385 }
381386 }
382387
898903 SHeaders.push_back({});
899904
900905 // Initialize the implicit sections
901 auto Index = State.SN2I.get(".symtab");
902 State.initSymtabSectionHeader(SHeaders[Index], SymtabType::Static, CBA);
903 Index = State.SN2I.get(".strtab");
904 State.initStrtabSectionHeader(SHeaders[Index], ".strtab", State.DotStrtab, CBA);
905 Index = State.SN2I.get(".shstrtab");
906 State.initStrtabSectionHeader(SHeaders[Index], ".shstrtab", State.DotShStrtab, CBA);
906 State.initSymtabSectionHeader(SHeaders[State.SN2I.get(".symtab")],
907 SymtabType::Static, CBA);
908 State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".strtab")], ".strtab",
909 State.DotStrtab, CBA);
910 State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".shstrtab")],
911 ".shstrtab", State.DotShStrtab, CBA);
907912 if (!Doc.DynamicSymbols.empty()) {
908 Index = State.SN2I.get(".dynsym");
909 State.initSymtabSectionHeader(SHeaders[Index], SymtabType::Dynamic, CBA);
910 SHeaders[Index].sh_flags |= ELF::SHF_ALLOC;
911 Index = State.SN2I.get(".dynstr");
912 State.initStrtabSectionHeader(SHeaders[Index], ".dynstr", State.DotDynstr, CBA);
913 SHeaders[Index].sh_flags |= ELF::SHF_ALLOC;
913 State.initSymtabSectionHeader(SHeaders[State.SN2I.get(".dynsym")],
914 SymtabType::Dynamic, CBA);
915 State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".dynstr")],
916 ".dynstr", State.DotDynstr, CBA);
914917 }
915918
916919 // Now we can decide segment offsets