mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
[yaml2obj][NFCI] - Address post commit comments for "[yaml2obj][ELF] - Simplify the code that performs sections validation."
This addresses post commit comments for D89463.
This commit is contained in:
parent
1584a82e94
commit
35b58c9128
@ -193,8 +193,9 @@ struct Section : public Chunk {
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind != ChunkKind::Fill; }
|
||||
|
||||
// Some derived sections might have own special entries. This method returns
|
||||
// vector of <entry name, is used> pairs. It is used for sections validation.
|
||||
// Some derived sections might have their own special entries. This method
|
||||
// returns a vector of <entry name, is used> pairs. It is used for section
|
||||
// validation.
|
||||
virtual std::vector<std::pair<StringRef, bool>> getEntries() const {
|
||||
return {};
|
||||
};
|
||||
@ -242,7 +243,7 @@ struct StackSizesSection : Section {
|
||||
StackSizesSection() : Section(ChunkKind::StackSizes) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -260,7 +261,7 @@ struct DynamicSection : Section {
|
||||
DynamicSection() : Section(ChunkKind::Dynamic) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Dynamic; }
|
||||
@ -291,7 +292,7 @@ struct NoteSection : Section {
|
||||
NoteSection() : Section(ChunkKind::Note) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Notes", !!Notes}};
|
||||
return {{"Notes", Notes.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Note; }
|
||||
@ -302,7 +303,7 @@ struct HashSection : Section {
|
||||
Optional<std::vector<uint32_t>> Chain;
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Bucket", !!Bucket}, {"Chain", !!Chain}};
|
||||
return {{"Bucket", Bucket.hasValue()}, {"Chain", Chain.hasValue()}};
|
||||
};
|
||||
|
||||
// The following members are used to override section fields.
|
||||
@ -344,10 +345,10 @@ struct GnuHashSection : Section {
|
||||
GnuHashSection() : Section(ChunkKind::GnuHash) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Header", !!Header},
|
||||
{"BloomFilter", !!BloomFilter},
|
||||
{"HashBuckets", !!HashBuckets},
|
||||
{"HashValues", !!HashValues}};
|
||||
return {{"Header", Header.hasValue()},
|
||||
{"BloomFilter", BloomFilter.hasValue()},
|
||||
{"HashBuckets", HashBuckets.hasValue()},
|
||||
{"HashValues", HashValues.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::GnuHash; }
|
||||
@ -373,7 +374,7 @@ struct VerneedSection : Section {
|
||||
VerneedSection() : Section(ChunkKind::Verneed) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Dependencies", !!VerneedV}};
|
||||
return {{"Dependencies", VerneedV.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -387,7 +388,7 @@ struct AddrsigSection : Section {
|
||||
AddrsigSection() : Section(ChunkKind::Addrsig) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Symbols", !!Symbols}};
|
||||
return {{"Symbols", Symbols.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Addrsig; }
|
||||
@ -404,7 +405,7 @@ struct LinkerOptionsSection : Section {
|
||||
LinkerOptionsSection() : Section(ChunkKind::LinkerOptions) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Options", !!Options}};
|
||||
return {{"Options", Options.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -418,7 +419,7 @@ struct DependentLibrariesSection : Section {
|
||||
DependentLibrariesSection() : Section(ChunkKind::DependentLibraries) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Libraries", !!Libs}};
|
||||
return {{"Libraries", Libs.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -442,7 +443,7 @@ struct CallGraphProfileSection : Section {
|
||||
CallGraphProfileSection() : Section(ChunkKind::CallGraphProfile) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -456,7 +457,7 @@ struct SymverSection : Section {
|
||||
SymverSection() : Section(ChunkKind::Symver) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Symver; }
|
||||
@ -478,7 +479,7 @@ struct VerdefSection : Section {
|
||||
VerdefSection() : Section(ChunkKind::Verdef) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Verdef; }
|
||||
@ -493,7 +494,7 @@ struct GroupSection : Section {
|
||||
GroupSection() : Section(ChunkKind::Group) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Members", !!Members}};
|
||||
return {{"Members", Members.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) { return S->Kind == ChunkKind::Group; }
|
||||
@ -513,7 +514,7 @@ struct RelocationSection : Section {
|
||||
RelocationSection() : Section(ChunkKind::Relocation) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Relocations", !!Relocations}};
|
||||
return {{"Relocations", Relocations.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -527,7 +528,7 @@ struct RelrSection : Section {
|
||||
RelrSection() : Section(ChunkKind::Relr) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -541,7 +542,7 @@ struct SymtabShndxSection : Section {
|
||||
SymtabShndxSection() : Section(ChunkKind::SymtabShndxSection) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
@ -560,7 +561,7 @@ struct ARMIndexTableSection : Section {
|
||||
ARMIndexTableSection() : Section(ChunkKind::ARMIndexTable) {}
|
||||
|
||||
std::vector<std::pair<StringRef, bool>> getEntries() const override {
|
||||
return {{"Entries", !!Entries}};
|
||||
return {{"Entries", Entries.hasValue()}};
|
||||
};
|
||||
|
||||
static bool classof(const Chunk *S) {
|
||||
|
@ -871,7 +871,7 @@ std::string MappingTraits<ELFYAML::SectionHeaderTable>::validate(
|
||||
if (!SecHdrTable.NoHeaders && !SecHdrTable.Sections && !SecHdrTable.Excluded)
|
||||
return "SectionHeaderTable can't be empty. Use 'NoHeaders' key to drop the "
|
||||
"section header table";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
|
||||
@ -1093,7 +1093,7 @@ std::string MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
|
||||
ELFYAML::Symbol &Symbol) {
|
||||
if (Symbol.Index && Symbol.Section.data())
|
||||
return "Index and Section cannot both be specified for Symbol";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
|
||||
@ -1427,7 +1427,7 @@ std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
|
||||
if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
|
||||
if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
|
||||
return "\"Size\" can't be 0 when \"Pattern\" is not empty";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
const ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get());
|
||||
@ -1437,7 +1437,7 @@ std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
|
||||
|
||||
auto BuildErrPrefix = [](ArrayRef<std::pair<StringRef, bool>> EntV) {
|
||||
std::string Msg;
|
||||
for (size_t I = 0; I < EntV.size(); ++I) {
|
||||
for (size_t I = 0, E = EntV.size(); I != E; ++I) {
|
||||
StringRef Name = EntV[I].first;
|
||||
if (I == 0) {
|
||||
Msg = "\"" + Name.str() + "\"";
|
||||
@ -1465,13 +1465,13 @@ std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
|
||||
if (const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(C.get())) {
|
||||
if (RawSection->Flags && RawSection->ShFlags)
|
||||
return "ShFlags and Flags cannot be used together";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
if (const auto *NB = dyn_cast<ELFYAML::NoBitsSection>(C.get())) {
|
||||
if (NB->Content)
|
||||
return "SHT_NOBITS section cannot have \"Content\"";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
if (const auto *MF = dyn_cast<ELFYAML::MipsABIFlags>(C.get())) {
|
||||
@ -1480,10 +1480,10 @@ std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
|
||||
"sections";
|
||||
if (MF->Size)
|
||||
return "\"Size\" key is not implemented for SHT_MIPS_ABIFLAGS sections";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -310,7 +310,7 @@ MappingTraits<MachOYAML::Section>::validate(IO &IO,
|
||||
MachOYAML::Section &Section) {
|
||||
if (Section.content && Section.size < Section.content->binary_size())
|
||||
return "Section size must be greater than or equal to the content size";
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
void MappingTraits<MachO::build_tool_version>::mapping(
|
||||
|
Loading…
Reference in New Issue
Block a user