[llvm] Make DWARFUnitVector threadsafe. (PR #71487)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 7 11:42:50 PST 2023
clayborg wrote:
The issue is this function:
```
DWARFUnitVector &getDWOUnits(bool Lazy) override {
if (DWOUnits.empty()) {
const DWARFObject &DObj = D.getDWARFObj();
DObj.forEachInfoDWOSections([&](const DWARFSection &S) {
DWOUnits.addUnitsForDWOSection(D, S, DW_SECT_INFO, Lazy);
});
DWOUnits.finishedInfoUnits();
DObj.forEachTypesDWOSections([&](const DWARFSection &S) {
DWOUnits.addUnitsForDWOSection(D, S, DW_SECT_EXT_TYPES, Lazy);
});
}
return DWOUnits;
}
```
If someone calls this function with `Lazy = true`, then `DWOUnits` won't be populated. But if they call it with true, then it will be populated. Users can then ask the DWARFUnitVector to get the DWO for a given hash using `DWARFUnitVector::getUnitForIndexEntry(...)`. And that will populate this list with only one entry. The code like this will causes issues:
```
DWARFUnitVector &DWOUnits = DC->getDWOUnits(/*Lazy=*/true);
DWARFUnit *DU = DWOUnits.getUnitForIndexEntry(...); // This will populate the DWOUnits with only one entry that matches
```
Then if you do:
```
DWARFUnitVector &DWOUnits = DC->getDWOUnits(/*Lazy=*/false);
```
We now have a DWARFUnitVector that isn't empty, because it has one entry for the DWARFUnit from the above code and the fact that Lazy is now false won't cause it to repopulate...
https://github.com/llvm/llvm-project/pull/71487
More information about the llvm-commits
mailing list