Skip to content

Commit 22f1ef4

Browse files
committed
[lld][ELF] Clean up error messages.
- Clean up the error messages in readEntry function - Restore 'const' qualifier to size_t vars in computeEntryPool - Add 'const' qualifier to getChunks function.
1 parent 254ceed commit 22f1ef4

File tree

2 files changed

+31
-42
lines changed

2 files changed

+31
-42
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,29 +2738,25 @@ static Expected<DebugNamesBaseSection::IndexEntry *>
27382738
readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
27392739
uint64_t entriesBase, DWARFDataExtractor &namesExtractor,
27402740
const LLDDWARFSection &namesSec) {
2741-
std::string errMsg;
27422741
auto ie = makeThreadLocal<DebugNamesBaseSection::IndexEntry>();
27432742
ie->poolOffset = offset;
27442743
Error err = Error::success();
27452744
uint64_t ulebVal = namesExtractor.getULEB128(&offset, &err);
2746-
if (err) {
2747-
errMsg = ": invalid abbrev code in entry: ";
2748-
errMsg.append(toString(std::move(err)));
2749-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2750-
}
2751-
if (ulebVal < UINT32_MAX)
2745+
if (err)
2746+
return createStringError(inconvertibleErrorCode(),
2747+
"invalid abbrev code in entry: %s",
2748+
toString(std::move(err)).c_str());
2749+
if (ulebVal <= UINT32_MAX)
27522750
ie->abbrevCode = static_cast<uint32_t>(ulebVal);
2753-
else {
2754-
errMsg = ": abbrev code in entry too large for DWARF32: ";
2755-
errMsg.append(std::to_string(ulebVal));
2756-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2757-
}
2751+
else
2752+
return createStringError(inconvertibleErrorCode(),
2753+
"abbrev code in entry too large for DWARF32: %d",
2754+
ulebVal);
27582755
auto it = ni.getAbbrevs().find_as(ie->abbrevCode);
2759-
if (it == ni.getAbbrevs().end()) {
2760-
errMsg = ": entry abbrev code not found in abbrev table: ";
2761-
errMsg.append(std::to_string(ie->abbrevCode));
2762-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2763-
}
2756+
if (it == ni.getAbbrevs().end())
2757+
return createStringError(inconvertibleErrorCode(),
2758+
"entry abbrev code not found in abbrev table: %d",
2759+
ie->abbrevCode);
27642760

27652761
DebugNamesBaseSection::AttrValue attr, cuAttr = {0, 0};
27662762
for (DWARFDebugNames::AttributeEncoding a : it->Attributes) {
@@ -2769,9 +2765,9 @@ readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
27692765
attr.attrValue = namesExtractor.getU32(&offset, &err);
27702766
attr.attrSize = 4;
27712767
ie->parentOffset = entriesBase + attr.attrValue;
2772-
} else if (a.Form != DW_FORM_flag_present) {
2773-
errMsg = ": invalid form for DW_IDX_parent";
2774-
}
2768+
} else if (a.Form != DW_FORM_flag_present)
2769+
return createStringError(inconvertibleErrorCode(),
2770+
"invalid form for DW_IDX_parent");
27752771
} else {
27762772
switch (a.Form) {
27772773
case DW_FORM_data1:
@@ -2793,17 +2789,15 @@ readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
27932789
break;
27942790
}
27952791
default:
2796-
errMsg = ": unrecognized form encoding ";
2797-
errMsg.append(std::to_string(a.Form));
2798-
errMsg.append(" in abbrev table");
2799-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2792+
return createStringError(
2793+
inconvertibleErrorCode(),
2794+
"unrecognized form encoding %d in abbrev table", a.Form);
28002795
}
28012796
}
2802-
if (err) {
2803-
errMsg = ": error while reading attributes: ";
2804-
errMsg.append(toString(std::move(err)));
2805-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2806-
}
2797+
if (err)
2798+
return createStringError(inconvertibleErrorCode(),
2799+
"error while reading attributes: %s",
2800+
toString(std::move(err)).c_str());
28072801
if (a.Index == DW_IDX_compile_unit)
28082802
cuAttr = attr;
28092803
else if (a.Form != DW_FORM_flag_present)
@@ -2813,10 +2807,7 @@ readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
28132807
// Canonicalize abbrev by placing the CU/TU index at the end.
28142808
ie->attrValues.push_back(cuAttr);
28152809

2816-
if (!errMsg.empty())
2817-
return createStringError(inconvertibleErrorCode(), errMsg.c_str());
2818-
else
2819-
return ie;
2810+
return ie;
28202811
}
28212812

28222813
void DebugNamesBaseSection::parseDebugNames(
@@ -2866,23 +2857,21 @@ void DebugNamesBaseSection::parseDebugNames(
28662857
ne.hashValue = caseFoldingDjbHash(name);
28672858

28682859
// Read a series of index entries that end with abbreviation code 0.
2869-
std::string errMsg;
28702860
uint64_t offset = locs.EntriesBase + entryOffsets[i];
28712861
while (offset < namesSec.Data.size() && namesSec.Data[offset] != 0) {
28722862
// Read & store all entries (for the same string).
28732863
Expected<IndexEntry *> ieOrErr =
28742864
readEntry(offset, ni, locs.EntriesBase, namesExtractor, namesSec);
28752865
if (!ieOrErr) {
2876-
errorOrWarn(toString(namesSec.sec) +
2877-
Twine(toString(ieOrErr.takeError())));
2866+
errorOrWarn(toString(namesSec.sec) + ": " +
2867+
toString(ieOrErr.takeError()));
28782868
return;
28792869
}
28802870
ne.indexEntries.push_back(std::move(*ieOrErr));
28812871
}
28822872
if (offset >= namesSec.Data.size())
2883-
errMsg = ": index entry is out of bounds";
2884-
if (!errMsg.empty())
2885-
errorOrWarn(toString(namesSec.sec) + Twine(errMsg.c_str()));
2873+
errorOrWarn(toString(namesSec.sec) +
2874+
Twine(": index entry is out of bounds"));
28862875

28872876
for (IndexEntry &ie : ne.entries())
28882877
offsetMap[ie.poolOffset] = &ie;
@@ -3023,9 +3012,9 @@ std::pair<uint32_t, uint32_t> DebugNamesBaseSection::computeEntryPool(
30233012
// Collect and de-duplicate all the names (preserving all the entries).
30243013
// Speed it up using multithreading, as the number of symbols can be in the
30253014
// order of millions.
3026-
size_t concurrency =
3015+
const size_t concurrency =
30273016
bit_floor(std::min<size_t>(config->threadCount, numShards));
3028-
size_t shift = 32 - countr_zero(numShards);
3017+
const size_t shift = 32 - countr_zero(numShards);
30293018
uint8_t cuAttrSize = getMergedCuCountForm(hdr.CompUnitCount).first;
30303019
DenseMap<CachedHashStringRef, size_t> maps[numShards];
30313020

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ class DebugNamesBaseSection : public SyntheticSection {
892892
SmallVector<Abbrev *, 0> abbrevTable;
893893
SmallVector<char, 0> abbrevTableBuf;
894894

895-
ArrayRef<OutputChunk> getChunks() {
895+
ArrayRef<OutputChunk> getChunks() const {
896896
return ArrayRef(chunks.get(), numChunks);
897897
}
898898

0 commit comments

Comments
 (0)