[PATCH] D104159: [not for review][lld-macho] Simple cstring literal implementation
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 11 16:33:09 PDT 2021
int3 created this revision.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is just an experiment to see if not creating heavyweight
InputSections for literals is worth it. The answer seems to be "yes".
This diff only creates the additional InputSections w/o deduplicating
them, and it's a 3.6% regression when linking chromium_framework. In
contrast, the StringPiece-based implementation in D102964 <https://reviews.llvm.org/D102964> (which
includes deduplication) is only a 2.2% regression.
N Min Max Median Avg Stddev
x 20 3.98 4.09 4.025 4.032 0.035629674
+ 20 4.14 4.22 4.175 4.177 0.019493589
Difference at 95.0% confidence
0.145 +/- 0.018381
3.59623% +/- 0.455877%
(Student's t, pooled s = 0.0287182)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104159
Files:
lld/MachO/InputFiles.cpp
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -589,6 +589,47 @@
// We populate subsecMap by repeatedly splitting the last (highest address)
// subsection.
SubsectionEntry subsecEntry = subsecMap.back();
+
+ if (sectionType(sectionHeaders[i].flags) == S_CSTRING_LITERALS) {
+ size_t off = 0;
+ StringRef s = toStringRef(subsecEntry.isec->data);
+ size_t nextSymIdxIdx = 0;
+ while (!s.empty()) {
+ InputSection *isec = subsecEntry.isec;
+ size_t end = s.find(0);
+ if (end == StringRef::npos)
+ fatal(toString(this) + ": string is not null terminated");
+ size_t size = end + 1;
+ isec->data = ArrayRef<uint8_t>(
+ reinterpret_cast<const uint8_t *>(s.substr(0, size).data()), size);
+ s = s.substr(size);
+
+ while (nextSymIdxIdx < symbolIndices.size()) {
+ uint32_t symIndex = symbolIndices[nextSymIdxIdx];
+ const NList &sym = nList[symIndex];
+ uint64_t subsecAddr = sectionAddr + off;
+ if (sym.n_value >= subsecAddr + size)
+ break;
+ nextSymIdxIdx++;
+ StringRef name = strtab + sym.n_strx;
+ uint64_t symbolOffset = sym.n_value - subsecAddr;
+ symbols[symIndex] =
+ createDefined(sym, name, isec, symbolOffset, size - symbolOffset);
+ }
+
+ if (s.empty())
+ break;
+
+ auto *nextIsec = make<InputSection>(*isec);
+ nextIsec->numRefs = 0;
+ nextIsec->wasCoalesced = false;
+ off += size;
+ subsecMap.push_back({off, nextIsec});
+ subsecEntry = subsecMap.back();
+ }
+ continue;
+ }
+
for (size_t j = 0; j < symbolIndices.size(); ++j) {
uint32_t symIndex = symbolIndices[j];
const NList &sym = nList[symIndex];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104159.351578.patch
Type: text/x-patch
Size: 1930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/e2e54837/attachment.bin>
More information about the llvm-commits
mailing list