[lld] [lld-macho] Parallelize ObjFile::sourceFile() during STABS emission. (PR #222087)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 12:51:22 PDT 2026
================
@@ -1263,10 +1262,22 @@ void SymtabSection::emitStabs() {
llvm::stable_sort(symbolsNeedingStabs, llvm::less_second());
+ std::vector<ObjFile *> stabFiles;
+ for (const SortingPair &pair : symbolsNeedingStabs) {
+ ObjFile *file = cast<ObjFile>(pair.first->originalIsec->getFile());
+ if (stabFiles.empty() || stabFiles.back() != file)
+ stabFiles.push_back(file);
+ }
+ std::vector<std::string> stabSourceFiles(stabFiles.size());
+ parallelFor(0, stabFiles.size(), [&](size_t i) {
+ stabSourceFiles[i] = stabFiles[i]->sourceFile();
+ });
+
// Emit STABS symbols so that dsymutil and/or the debugger can map address
// regions in the final binary to the source and object files from which they
// originated.
InputFile *lastFile = nullptr;
+ size_t stabFileIdx = 0;
for (SortingPair &pair : symbolsNeedingStabs) {
----------------
ellishg wrote:
Ideally we could change this loop to something like this
```suggestion
for (auto &[file, symbols] : stabsFiles) {
for (auto &defined : symbols) {
```
I think we could first construct this (hopefully in parallel).
```
VectorMap<ObjFile *, SmallVector<Defined *>> stabsFiles;
```
I would like to avoid using `stabSourceFiles[stabFileIdx++]` because that seems prone to errors (I believe the assert is there to make sure the file iterator is in sync with the symbols). I think the new for loop structure could simplify the file deduplication logic as well as the `lastFile` and `emitEndSourceStab()` logic.
https://github.com/llvm/llvm-project/pull/222087
More information about the llvm-commits
mailing list