Skip to content

Commit 3b8935a

Browse files
committed
[BOLT][DWARF][NFC] Fix DebugStrOffsetsWriter so updateAddressMap can't be called after it is finalized
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60293063
1 parent 60e5892 commit 3b8935a

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

bolt/include/bolt/Core/DebugData.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,15 @@ class DebugStrOffsetsWriter {
503503
return StrOffsetSectionWasModified;
504504
}
505505

506+
std::unordered_map<uint64_t, bool> &getDebugStrOffsetFinalized() {
507+
return DebugStrOffsetFinalized;
508+
}
509+
506510
private:
507511
std::unique_ptr<DebugStrOffsetsBufferVector> StrOffsetsBuffer;
508512
std::unique_ptr<raw_svector_ostream> StrOffsetsStream;
509513
std::map<uint32_t, uint32_t> IndexToAddressMap;
514+
std::unordered_map<uint64_t, bool> DebugStrOffsetFinalized;
510515
SmallVector<uint32_t, 5> StrOffsets;
511516
std::unordered_map<uint64_t, uint64_t> ProcessedBaseOffsets;
512517
bool StrOffsetSectionWasModified = false;

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static void addStringHelper(DebugStrOffsetsWriter &StrOffstsWriter,
7777
DIEValue &DIEAttrInfo, StringRef Str) {
7878
uint32_t NewOffset = StrWriter.addString(Str);
7979
if (Unit.getVersion() >= 5) {
80+
assert(StrOffstsWriter.getDebugStrOffsetFinalized().count(
81+
Unit.getOffset()) == 0 &&
82+
"debug_str_offsets was already finalized.");
8083
StrOffstsWriter.updateAddressMap(DIEAttrInfo.getDIEInteger().getValue(),
8184
NewOffset);
8285
return;

bolt/lib/Core/DebugData.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
906906
}
907907

908908
StrOffsetSectionWasModified = false;
909+
DebugStrOffsetFinalized[Unit.getOffset()] = true;
909910
clear();
910911
}
911912

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ void DWARFRewriter::updateDebugInfo() {
757757
: std::optional<std::string>(opts::DwarfOutputPath.c_str());
758758
std::string DWOName = DIEBlder.updateDWONameCompDir(
759759
*StrOffstsWriter, *StrWriter, *CU, DwarfOutputPath, std::nullopt);
760+
if (CU->getVersion() >= 5)
761+
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
760762
processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
761763
AddressWriter, DWOName, DwarfOutputPath);
762764
}

bolt/test/X86/dwarf5-df-input-lowpc-ranges-cus.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-other.s \
77
; RUN: -split-dwarf-file=mainOther.dwo -o other.o
88
; RUN: %clang %cflags main.o other.o -o main.exe
9-
; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections
9+
; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections --cu-processing-batch-size=2
1010
; RUN: llvm-dwarfdump --show-form --verbose --debug-rnglists main.exe.bolt &> %t/foo.txt
1111
; RUN: llvm-dwarfdump --show-form --verbose --debug-addr main.exe.bolt >> %t/foo.txt
1212
; RUN: llvm-dwarfdump --show-form --verbose --debug-info main.exe.bolt >> %t/foo.txt

0 commit comments

Comments
 (0)