From 86cc736df1fccfe804a6fe3f4a7f8c65f17ae50a Mon Sep 17 00:00:00 2001 From: George Rimar Date: Mon, 2 Sep 2019 09:47:17 +0000 Subject: [yaml2obj] - Allow overriding sh_name fields of the sections. This is in line with the previous changes which allowed to override the sh_offset/sh_size and useful for writing test cases. Differential revision: https://reviews.llvm.org/D66998 llvm-svn: 370633 --- llvm/lib/ObjectYAML/ELFEmitter.cpp | 8 ++++++-- llvm/lib/ObjectYAML/ELFYAML.cpp | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'llvm/lib/ObjectYAML') diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 44af64eadef..9c74d8ba205 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -292,8 +292,10 @@ bool ELFState::initImplicitHeader(ELFState &State, else return false; - // Override the sh_offset/sh_size fields if requested. + // Override the fields if requested. if (YAMLSec) { + if (YAMLSec->ShName) + Header.sh_name = *YAMLSec->ShName; if (YAMLSec->ShOffset) Header.sh_offset = *YAMLSec->ShOffset; if (YAMLSec->ShSize) @@ -395,8 +397,10 @@ bool ELFState::initSectionHeaders(ELFState &State, } else llvm_unreachable("Unknown section type"); - // Override the sh_offset/sh_size fields if requested. + // Override the fields if requested. if (Sec) { + if (Sec->ShName) + SHeader.sh_name = *Sec->ShName; if (Sec->ShOffset) SHeader.sh_offset = *Sec->ShOffset; if (Sec->ShSize) diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 04084e990c0..6f05d7ddc1a 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -986,10 +986,11 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { IO.mapOptional("EntSize", Section.EntSize); // obj2yaml does not dump these fields. They are expected to be empty when we - // are producing YAML, because yaml2obj sets appropriate values for sh_offset - // and sh_size automatically when they are not explicitly defined. + // are producing YAML, because yaml2obj sets appropriate values for them + // automatically when they are not explicitly defined. assert(!IO.outputting() || (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue())); + IO.mapOptional("ShName", Section.ShName); IO.mapOptional("ShOffset", Section.ShOffset); IO.mapOptional("ShSize", Section.ShSize); } -- cgit v1.2.3