Skip to content

Commit 732ec22

Browse files
committed
Consider the modified str and offsets in the buffer.
1 parent 5e38a3f commit 732ec22

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

bolt/include/bolt/Core/DebugData.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ class DebugStrOffsetsWriter {
471471
return std::move(StrOffsetsBuffer);
472472
}
473473

474+
StringRef bufferStr() {
475+
return StringRef(reinterpret_cast<const char *>(StrOffsetsBuffer->data()),
476+
StrOffsetsBuffer->size());
477+
}
478+
474479
/// Initializes Buffer and Stream.
475480
void initialize(DWARFUnit &Unit);
476481

@@ -507,6 +512,11 @@ class DebugStrWriter {
507512
return std::move(StrBuffer);
508513
}
509514

515+
StringRef bufferStr() {
516+
return StringRef(reinterpret_cast<const char *>(StrBuffer->data()),
517+
StrBuffer->size());
518+
}
519+
510520
/// Adds string to .debug_str.
511521
/// On first invocation it initializes internal data structures.
512522
uint32_t addString(StringRef Str);

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,8 @@ std::optional<StringRef> updateDebugData(
18311831
errs() << "BOLT-WARNING: unsupported debug section: " << SectionName
18321832
<< "\n";
18331833
if (StrWriter.isInitialized()) {
1834+
if (CUDWOEntry)
1835+
return StrWriter.bufferStr();
18341836
OutputBuffer = StrWriter.releaseBuffer();
18351837
return StringRef(reinterpret_cast<const char *>(OutputBuffer->data()),
18361838
OutputBuffer->size());
@@ -1845,6 +1847,8 @@ std::optional<StringRef> updateDebugData(
18451847
}
18461848
case DWARFSectionKind::DW_SECT_STR_OFFSETS: {
18471849
if (StrOffstsWriter.isFinalized()) {
1850+
if (CUDWOEntry)
1851+
return StrOffstsWriter.bufferStr();
18481852
OutputBuffer = StrOffstsWriter.releaseBuffer();
18491853
return StringRef(reinterpret_cast<const char *>(OutputBuffer->data()),
18501854
OutputBuffer->size());
@@ -1959,7 +1963,10 @@ void DWARFRewriter::writeDWOFiles(
19591963
Expected<StringRef> ContentsExp = Section.getContents();
19601964
assert(ContentsExp && "Invalid contents.");
19611965
if (IsDWP && SectionName == "debug_str.dwo") {
1962-
StrDWOContent = *ContentsExp;
1966+
if (StrWriter.isInitialized())
1967+
StrDWOContent = StrWriter.bufferStr();
1968+
else
1969+
StrDWOContent = *ContentsExp;
19631970
continue;
19641971
}
19651972
if (std::optional<StringRef> OutData = updateDebugData(

0 commit comments

Comments
 (0)