summaryrefslogtreecommitdiff
path: root/llvm/tools/obj2yaml/elf2yaml.cpp
diff options
context:
space:
mode:
authorGeorgii Rymar <grimar@accesssoftek.com>2020-12-28 14:08:26 +0300
committerGeorgii Rymar <grimar@accesssoftek.com>2021-01-13 11:52:40 +0300
commit6d3098e7ff968ad7d3033d7751af05a1fcd2ed9b (patch)
tree4abce38047718fc93dda6ddcab06d11cffdcdd9f /llvm/tools/obj2yaml/elf2yaml.cpp
parentc29ca8551afff316976c2befcd65eeef53798499 (diff)
[obj2yaml,yaml2obj] - Refine how we set/dump the sh_entsize field.
This reuses the code from yaml2obj (moves it to ELFYAML.h). With it we can set the `sh_entsize` in a single place in `obj2yaml`. Note that it also fixes a bug of `yaml2obj`: we do not set the `sh_entsize` field for the `SHT_ARM_EXIDX` section properly. Differential revision: https://reviews.llvm.org/D93858
Diffstat (limited to 'llvm/tools/obj2yaml/elf2yaml.cpp')
-rw-r--r--llvm/tools/obj2yaml/elf2yaml.cpp26
1 files changed, 2 insertions, 24 deletions
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 89bbee49657a..3c7f6dd8319d 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -731,29 +731,6 @@ Error ELFDumper<ELFT>::dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
}
template <class ELFT>
-static unsigned getDefaultShEntSize(ELFYAML::ELF_SHT SecType,
- StringRef SecName) {
- switch (SecType) {
- case ELF::SHT_GROUP:
- return sizeof(typename ELFT::Word);
- case ELF::SHT_REL:
- return sizeof(typename ELFT::Rel);
- case ELF::SHT_RELA:
- return sizeof(typename ELFT::Rela);
- case ELF::SHT_RELR:
- return sizeof(typename ELFT::Relr);
- case ELF::SHT_DYNAMIC:
- return sizeof(typename ELFT::Dyn);
- case ELF::SHT_HASH:
- return sizeof(typename ELFT::Word);
- default:
- if (SecName == ".debug_str")
- return 1;
- return 0;
- }
-}
-
-template <class ELFT>
Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
ELFYAML::Section &S) {
// Dump fields. We do not dump the ShOffset field. When not explicitly
@@ -772,7 +749,8 @@ Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
return NameOrErr.takeError();
S.Name = NameOrErr.get();
- if (Shdr->sh_entsize != getDefaultShEntSize<ELFT>(S.Type, S.Name))
+ if (Shdr->sh_entsize != ELFYAML::getDefaultShEntSize<ELFT>(
+ Obj.getHeader().e_machine, S.Type, S.Name))
S.EntSize = static_cast<llvm::yaml::Hex64>(Shdr->sh_entsize);
if (Shdr->sh_link != ELF::SHN_UNDEF) {