-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BOLT][DWARF] Refactor helper functions that update DW_AT_comp_dir/DW_AT_dwo_name #91237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompDIr/DWO_name Summary: We need to update DW_AT_comp_dir/DW_AT_dwo_name TU in the .debug_info.dwo section so that the path is correct. Refactored helper functions to make it easier for next step. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D57003722
@llvm/pr-subscribers-bolt Author: Alexander Yermolovich (ayermolo) ChangesWe need to update DW_AT_comp_dir/DW_AT_dwo_name TU in the .debug_info.dwo section so that the path is correct. Refactored helper functions to make it easier for next step. Full diff: https://github.com/llvm/llvm-project/pull/91237.diff 2 Files Affected:
diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h
index 2c482bd2b9ea96..12e0813d089d14 100644
--- a/bolt/include/bolt/Rewrite/DWARFRewriter.h
+++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h
@@ -177,13 +177,6 @@ class DWARFRewriter {
DIEValue &HighPCAttrInfo,
std::optional<uint64_t> RangesBase = std::nullopt);
- /// Adds a \p Str to .debug_str section.
- /// Uses \p AttrInfoVal to either update entry in a DIE for legacy DWARF using
- /// \p DebugInfoPatcher, or for DWARF5 update an index in .debug_str_offsets
- /// for this contribution of \p Unit.
- void addStringHelper(DIEBuilder &DIEBldr, DIE &Die, const DWARFUnit &Unit,
- DIEValue &DIEAttrInfo, StringRef Str);
-
public:
DWARFRewriter(BinaryContext &BC) : BC(BC) {}
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index feeba89a40dc4d..26e4889faadace 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -582,19 +582,51 @@ static void emitDWOBuilder(const std::string &DWOName,
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter);
}
-void DWARFRewriter::addStringHelper(DIEBuilder &DIEBldr, DIE &Die,
- const DWARFUnit &Unit,
- DIEValue &DIEAttrInfo, StringRef Str) {
- uint32_t NewOffset = StrWriter->addString(Str);
+/// Adds a \p Str to .debug_str section.
+/// Uses \p AttrInfoVal to either update entry in a DIE for legacy DWARF using
+/// \p DebugInfoPatcher, or for DWARF5 update an index in .debug_str_offsets
+/// for this contribution of \p Unit.
+static void addStringHelper(DebugStrOffsetsWriter &StrOffstsWriter,
+ DebugStrWriter &StrWriter, DIEBuilder &DIEBldr,
+ DIE &Die, const DWARFUnit &Unit,
+ DIEValue &DIEAttrInfo, StringRef Str) {
+ uint32_t NewOffset = StrWriter.addString(Str);
if (Unit.getVersion() >= 5) {
- StrOffstsWriter->updateAddressMap(DIEAttrInfo.getDIEInteger().getValue(),
- NewOffset);
+ StrOffstsWriter.updateAddressMap(DIEAttrInfo.getDIEInteger().getValue(),
+ NewOffset);
return;
}
DIEBldr.replaceValue(&Die, DIEAttrInfo.getAttribute(), DIEAttrInfo.getForm(),
DIEInteger(NewOffset));
}
+static std::string
+updateDWONameCompDir(DebugStrOffsetsWriter &StrOffstsWriter,
+ DebugStrWriter &StrWriter,
+ std::unordered_map<std::string, uint32_t> &NameToIndexMap,
+ DWARFUnit &Unit, DIEBuilder &DIEBldr, DIE &UnitDIE) {
+ DIEValue DWONameAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_dwo_name);
+ if (!DWONameAttrInfo)
+ DWONameAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_GNU_dwo_name);
+ assert(DWONameAttrInfo && "DW_AT_dwo_name is not in Skeleton CU.");
+ std::string ObjectName;
+
+ ObjectName = getDWOName(Unit, NameToIndexMap);
+ addStringHelper(StrOffstsWriter, StrWriter, DIEBldr, UnitDIE, Unit,
+ DWONameAttrInfo, ObjectName.c_str());
+
+ DIEValue CompDirAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_comp_dir);
+ assert(CompDirAttrInfo && "DW_AT_comp_dir is not in Skeleton CU.");
+
+ if (!opts::DwarfOutputPath.empty()) {
+ if (!sys::fs::exists(opts::DwarfOutputPath))
+ sys::fs::create_directory(opts::DwarfOutputPath);
+ addStringHelper(StrOffstsWriter, StrWriter, DIEBldr, UnitDIE, Unit,
+ CompDirAttrInfo, opts::DwarfOutputPath.c_str());
+ }
+ return ObjectName;
+}
+
using DWARFUnitVec = std::vector<DWARFUnit *>;
using CUPartitionVector = std::vector<DWARFUnitVec>;
/// Partitions CUs in to buckets. Bucket size is controlled by
@@ -692,33 +724,6 @@ void DWARFRewriter::updateDebugInfo() {
// specified.
std::unordered_map<std::string, uint32_t> NameToIndexMap;
- auto updateDWONameCompDir = [&](DWARFUnit &Unit, DIEBuilder &DIEBldr,
- DIE &UnitDIE) -> std::string {
- DIEValue DWONameAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_dwo_name);
- if (!DWONameAttrInfo)
- DWONameAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_GNU_dwo_name);
- assert(DWONameAttrInfo && "DW_AT_dwo_name is not in Skeleton CU.");
- std::string ObjectName;
-
- {
- std::lock_guard<std::mutex> Lock(AccessMutex);
- ObjectName = getDWOName(Unit, NameToIndexMap);
- }
- addStringHelper(DIEBldr, UnitDIE, Unit, DWONameAttrInfo,
- ObjectName.c_str());
-
- DIEValue CompDirAttrInfo = UnitDIE.findAttribute(dwarf::DW_AT_comp_dir);
- assert(CompDirAttrInfo && "DW_AT_comp_dir is not in Skeleton CU.");
-
- if (!opts::DwarfOutputPath.empty()) {
- if (!sys::fs::exists(opts::DwarfOutputPath))
- sys::fs::create_directory(opts::DwarfOutputPath);
- addStringHelper(DIEBldr, UnitDIE, Unit, CompDirAttrInfo,
- opts::DwarfOutputPath.c_str());
- }
- return ObjectName;
- };
-
DWARF5AcceleratorTable DebugNamesTable(opts::CreateDebugNames, BC,
*StrWriter);
DWPState State;
@@ -741,8 +746,13 @@ void DWARFRewriter::updateDebugInfo() {
DIEBuilder DWODIEBuilder(BC, &(*SplitCU)->getContext(), DebugNamesTable,
Unit);
DWODIEBuilder.buildDWOUnit(**SplitCU);
- std::string DWOName = updateDWONameCompDir(
- *Unit, *DIEBlder, *DIEBlder->getUnitDIEbyUnit(*Unit));
+ std::string DWOName = "";
+ {
+ std::lock_guard<std::mutex> Lock(AccessMutex);
+ DWOName = updateDWONameCompDir(*StrOffstsWriter, *StrWriter,
+ NameToIndexMap, *Unit, *DIEBlder,
+ *DIEBlder->getUnitDIEbyUnit(*Unit));
+ }
DebugLoclistWriter DebugLocDWoWriter(*Unit, Unit->getVersion(), true);
DebugRangesSectionWriter *TempRangesSectionWriter = RangesSectionWriter;
|
aaupov
approved these changes
May 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We need to update DW_AT_comp_dir/DW_AT_dwo_name TU in the .debug_info.dwo section so that the path is correct. Refactored helper functions to make it easier for next step.