[llvm] r353810 - [yaml2obj/obj2yaml] - Move `Info` field out from `Section` class.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 12 01:09:00 PST 2019
Author: grimar
Date: Tue Feb 12 01:08:59 2019
New Revision: 353810
URL: http://llvm.org/viewvc/llvm-project?rev=353810&view=rev
Log:
[yaml2obj/obj2yaml] - Move `Info` field out from `Section` class.
ELFYAML.h contains a `Section` class which is a base for a few other
sections classes that are used for mapping different section types.
`Section` has a `StringRef Info` field used for storing sh_info.
At the same time, sh_info has very different meanings for sections and
cannot be processed in a similar way generally,
for example ELFDumper does not handle it in `dumpCommonSection`
but do that in `dumpGroup` and `dumpCommonRelocationSection` respectively.
At this moment, we have and handle it as a string, because that was possible for
the current use case. But also it can simply be a number:
For SHT_GNU_verdef is "The number of version definitions within the section."
The patch moves `Info` field out to be able to have it as a number.
With that change, each class will be able to decide what type and purpose
of the sh_info field it wants to use.
I also had to edit 2 test cases. This is because patch fixes a bug. Previously we
accepted yaml files with Info fields for all sections (for example, for SHT_DYNSYM too).
But we do not handle it and the resulting objects had zero sh_info fields set for
such sections. Now it is accepted only for sections that supports it.
Differential revision: https://reviews.llvm.org/D58054
Modified:
llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
llvm/trunk/test/tools/llvm-readobj/demangle.test
llvm/trunk/test/tools/llvm-readobj/gnu-hash-symbols.test
llvm/trunk/tools/obj2yaml/elf2yaml.cpp
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Tue Feb 12 01:08:59 2019
@@ -129,7 +129,6 @@ struct Section {
ELF_SHF Flags;
llvm::yaml::Hex64 Address;
StringRef Link;
- StringRef Info;
llvm::yaml::Hex64 AddressAlign;
Optional<llvm::yaml::Hex64> EntSize;
@@ -172,6 +171,7 @@ struct Group : Section {
// Members of a group contain a flag and a list of section indices
// that are part of the group.
std::vector<SectionOrType> Members;
+ StringRef Signature; /* Info */
Group() : Section(SectionKind::Group) {}
@@ -189,6 +189,7 @@ struct Relocation {
struct RelocationSection : Section {
std::vector<Relocation> Relocations;
+ StringRef RelocatableSec; /* Info */
RelocationSection() : Section(SectionKind::Relocation) {}
Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Tue Feb 12 01:08:59 2019
@@ -854,7 +854,6 @@ static void commonSectionMapping(IO &IO,
IO.mapOptional("Link", Section.Link, StringRef());
IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
IO.mapOptional("EntSize", Section.EntSize);
- IO.mapOptional("Info", Section.Info, StringRef());
}
static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
@@ -875,12 +874,14 @@ static void sectionMapping(IO &IO, ELFYA
static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
commonSectionMapping(IO, Section);
+ IO.mapOptional("Info", Section.RelocatableSec, StringRef());
IO.mapOptional("Relocations", Section.Relocations);
}
-static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
- commonSectionMapping(IO, group);
- IO.mapRequired("Members", group.Members);
+static void groupSectionMapping(IO &IO, ELFYAML::Group &Group) {
+ commonSectionMapping(IO, Group);
+ IO.mapOptional("Info", Group.Signature, StringRef());
+ IO.mapRequired("Members", Group.Members);
}
void MappingTraits<ELFYAML::SectionOrType>::mapping(
Modified: llvm/trunk/test/tools/llvm-readobj/demangle.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/demangle.test?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/demangle.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/demangle.test Tue Feb 12 01:08:59 2019
@@ -133,7 +133,6 @@ Sections:
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
Link: .dynstr
- Info: 1
Address: 0x100
AddressAlign: 0x100
EntSize: 0x18
Modified: llvm/trunk/test/tools/llvm-readobj/gnu-hash-symbols.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/gnu-hash-symbols.test?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/gnu-hash-symbols.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/gnu-hash-symbols.test Tue Feb 12 01:08:59 2019
@@ -63,7 +63,6 @@ Sections:
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
Link: .dynstr
- Info: 1
Address: 0x100
AddressAlign: 0x100
EntSize: 0x18
Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Tue Feb 12 01:08:59 2019
@@ -354,7 +354,7 @@ ELFDumper<ELFT>::dumpCommonRelocationSec
auto NameOrErr = getUniquedSectionName(*InfoSection);
if (!NameOrErr)
return errorToErrorCode(NameOrErr.takeError());
- S.Info = NameOrErr.get();
+ S.RelocatableSec = NameOrErr.get();
return obj2yaml_error::success;
}
@@ -468,7 +468,7 @@ ErrorOr<ELFYAML::Group *> ELFDumper<ELFT
Expected<StringRef> symbolName = getSymbolName(symbol, StrTab, Symtab);
if (!symbolName)
return errorToErrorCode(symbolName.takeError());
- S->Info = *symbolName;
+ S->Signature = *symbolName;
const Elf_Word *groupMembers =
reinterpret_cast<const Elf_Word *>(sectionContents->data());
const long count = (Shdr->sh_size) / sizeof(Elf_Word);
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=353810&r1=353809&r2=353810&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Tue Feb 12 01:08:59 2019
@@ -270,15 +270,16 @@ bool ELFState<ELFT>::initSectionHeaders(
SHeader.sh_link = getDotSymTabSecNo();
unsigned Index;
- if (!convertSectionIndex(SN2I, S->Name, S->Info, Index))
+ if (!convertSectionIndex(SN2I, S->Name, S->RelocatableSec, Index))
return false;
SHeader.sh_info = Index;
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::Group>(Sec.get())) {
unsigned SymIdx;
- if (SymN2I.lookup(S->Info, SymIdx) && !to_integer(S->Info, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << S->Info
+ if (SymN2I.lookup(S->Signature, SymIdx) &&
+ !to_integer(S->Signature, SymIdx)) {
+ WithColor::error() << "Unknown symbol referenced: '" << S->Signature
<< "' at YAML section '" << S->Name << "'.\n";
return false;
}
More information about the llvm-commits
mailing list