[llvm] 304b0ed - [yaml2obj] - Move "repeated section/fill name" check earlier.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Sat May 23 07:46:15 PDT 2020
Author: Georgii Rymar
Date: 2020-05-23T17:40:48+03:00
New Revision: 304b0ed40392830e6f833c56b38cdc8296f58ce4
URL: https://github.com/llvm/llvm-project/commit/304b0ed40392830e6f833c56b38cdc8296f58ce4
DIFF: https://github.com/llvm/llvm-project/commit/304b0ed40392830e6f833c56b38cdc8296f58ce4.diff
LOG: [yaml2obj] - Move "repeated section/fill name" check earlier.
This allows to simplify the code.
Doing checks early is generally useful.
Differential revision: https://reviews.llvm.org/D79985
Added:
Modified:
llvm/lib/ObjectYAML/ELFEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 1ca1dfe0dc4e..95d74eeeb6e6 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -261,7 +261,10 @@ ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
C->Name = StringRef(NewName).copy(StringAlloc);
assert(ELFYAML::dropUniqueSuffix(C->Name).empty());
}
- DocSections.insert(C->Name);
+
+ if (!DocSections.insert(C->Name).second)
+ reportError("repeated section/fill name: '" + C->Name +
+ "' at YAML section/fill number " + Twine(I));
}
std::vector<StringRef> ImplicitSections;
@@ -1435,18 +1438,10 @@ void ELFState<ELFT>::writeFill(ELFYAML::Fill &Fill,
template <class ELFT> void ELFState<ELFT>::buildSectionIndex() {
size_t SecNdx = -1;
- StringSet<> Seen;
- for (size_t I = 0; I < Doc.Chunks.size(); ++I) {
- const std::unique_ptr<ELFYAML::Chunk> &C = Doc.Chunks[I];
- bool IsSection = isa<ELFYAML::Section>(C.get());
- if (IsSection)
- ++SecNdx;
-
- if (!Seen.insert(C->Name).second)
- reportError("repeated section/fill name: '" + C->Name +
- "' at YAML section/fill number " + Twine(I));
- if (!IsSection || HasError)
+ for (const std::unique_ptr<ELFYAML::Chunk> &C : Doc.Chunks) {
+ if (!isa<ELFYAML::Section>(C.get()))
continue;
+ ++SecNdx;
if (!SN2I.addName(C->Name, SecNdx))
llvm_unreachable("buildSectionIndex() failed");
@@ -1509,6 +1504,8 @@ template <class ELFT>
bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc,
yaml::ErrorHandler EH) {
ELFState<ELFT> State(Doc, EH);
+ if (State.HasError)
+ return false;
// Finalize .strtab and .dynstr sections. We do that early because want to
// finalize the string table builders before writing the content of the
@@ -1516,9 +1513,6 @@ bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc,
State.finalizeStrings();
State.buildSectionIndex();
- if (State.HasError)
- return false;
-
State.buildSymbolIndexes();
std::vector<Elf_Phdr> PHeaders;
More information about the llvm-commits
mailing list