summaryrefslogtreecommitdiffstats
path: root/llvm/tools/yaml2obj
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-04-29 11:54:10 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-04-29 11:54:10 +0000
commit4828811a2d5c48e3225157034de11343e52ea7c6 (patch)
tree205f8459a3b0776acf0c9229b989b4be81918db0 /llvm/tools/yaml2obj
parenta6159a226e4685a25acb76571a88283c5b003dc2 (diff)
downloadbcm5719-llvm-4828811a2d5c48e3225157034de11343e52ea7c6.tar.gz
bcm5719-llvm-4828811a2d5c48e3225157034de11343e52ea7c6.zip
[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. llvm-svn: 359443
Diffstat (limited to 'llvm/tools/yaml2obj')
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 1f83656a606..e3246bc2941 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -325,6 +325,8 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
SHeader.sh_name = DotShStrtab.getOffset(IsStatic ? ".symtab" : ".dynsym");
SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
SHeader.sh_link = IsStatic ? getDotStrTabSecNo() : getDotDynStrSecNo();
+ if (!IsStatic)
+ SHeader.sh_flags |= ELF::SHF_ALLOC;
// One greater than symbol table index of the last local symbol.
const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols;
@@ -378,6 +380,9 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
unsigned SecNdx = getDotDynStrSecNo() - 1;
if (SecNdx < Doc.Sections.size())
SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+
+ // We assume that .dynstr is always allocatable.
+ SHeader.sh_flags |= ELF::SHF_ALLOC;
}
}
@@ -899,19 +904,17 @@ int ELFState<ELFT>::writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
SHeaders.push_back({});
// Initialize the implicit sections
- auto Index = State.SN2I.get(".symtab");
- State.initSymtabSectionHeader(SHeaders[Index], SymtabType::Static, CBA);
- Index = State.SN2I.get(".strtab");
- State.initStrtabSectionHeader(SHeaders[Index], ".strtab", State.DotStrtab, CBA);
- Index = State.SN2I.get(".shstrtab");
- State.initStrtabSectionHeader(SHeaders[Index], ".shstrtab", State.DotShStrtab, CBA);
+ State.initSymtabSectionHeader(SHeaders[State.SN2I.get(".symtab")],
+ SymtabType::Static, CBA);
+ State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".strtab")], ".strtab",
+ State.DotStrtab, CBA);
+ State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".shstrtab")],
+ ".shstrtab", State.DotShStrtab, CBA);
if (!Doc.DynamicSymbols.empty()) {
- Index = State.SN2I.get(".dynsym");
- State.initSymtabSectionHeader(SHeaders[Index], SymtabType::Dynamic, CBA);
- SHeaders[Index].sh_flags |= ELF::SHF_ALLOC;
- Index = State.SN2I.get(".dynstr");
- State.initStrtabSectionHeader(SHeaders[Index], ".dynstr", State.DotDynstr, CBA);
- SHeaders[Index].sh_flags |= ELF::SHF_ALLOC;
+ State.initSymtabSectionHeader(SHeaders[State.SN2I.get(".dynsym")],
+ SymtabType::Dynamic, CBA);
+ State.initStrtabSectionHeader(SHeaders[State.SN2I.get(".dynstr")],
+ ".dynstr", State.DotDynstr, CBA);
}
// Now we can decide segment offsets
OpenPOWER on IntegriCloud