Skip to content

[BOLT][DWARF] Fix handling of debug_str_offsets #75100

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
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bolt/include/bolt/Core/DebugData.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ class DebugStrOffsetsWriter {
std::unique_ptr<raw_svector_ostream> StrOffsetsStream;
std::map<uint32_t, uint32_t> IndexToAddressMap;
std::unordered_map<uint64_t, uint64_t> ProcessedBaseOffsets;
// Section size not including header.
uint32_t CurrentSectionSize{0};
bool StrOffsetSectionWasModified = false;
};

Expand Down
6 changes: 4 additions & 2 deletions bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,10 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
// Handling re-use of str-offsets section.
if (RetVal == ProcessedBaseOffsets.end() || StrOffsetSectionWasModified) {
// Writing out the header for each section.
support::endian::write(*StrOffsetsStream, CurrentSectionSize + 4,
llvm::endianness::little);
support::endian::write(
*StrOffsetsStream,
static_cast<uint32_t>(IndexToAddressMap.size() * 4 + 4),
llvm::endianness::little);
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(5),
llvm::endianness::little);
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(0),
Expand Down
5 changes: 3 additions & 2 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,9 @@ void DWARFRewriter::updateDebugInfo() {
std::optional<DWARFUnit *> SplitCU;
std::optional<uint64_t> RangesBase;
std::optional<uint64_t> DWOId = Unit->getDWOId();
StrOffstsWriter->initialize(Unit->getStringOffsetSection(),
Unit->getStringOffsetsTableContribution());
if (Unit->getVersion() >= 5)
StrOffstsWriter->initialize(Unit->getStringOffsetSection(),
Unit->getStringOffsetsTableContribution());
if (DWOId)
SplitCU = BC.getDWOCU(*DWOId);
DebugLocWriter *DebugLocWriter = createRangeLocList(*Unit);
Expand Down
66 changes: 66 additions & 0 deletions bolt/test/X86/dwarf5-two-cu-str-offset-table.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# REQUIRES: system-linux

# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5_main.s -o %tmain.o
# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5_helper.s -o %thelper.o
# RUN: %clang %cflags -dwarf-5 %tmain.o %thelper.o -o %t.exe -Wl,-q
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it -gdwarf-5 here ? :)

# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections
# RUN: llvm-dwarfdump --show-form --verbose --debug-str-offsets %t.exe > %t.txt
# RUN: llvm-dwarfdump --show-form --verbose --debug-str-offsets %t.bolt >> %t.txt
# RUN: cat %t.txt | FileCheck --check-prefix=CHECK %s

## This test checks we correclty re-renerate .debug_str_offsets.

# CHECK: .debug_str_offsets contents
# CHECK-NEXT: 0x00000000: Contribution size = 52, Format = DWARF32, Version = 5
# CHECK-NEXT: "clang version 15.0.0"
# CHECK-NEXT: "main.cpp"
# CHECK-NEXT: "/testLocListMultiple"
# CHECK-NEXT: "_Z3usePiS_"
# CHECK-NEXT: "use"
# CHECK-NEXT: "main"
# CHECK-NEXT: "int"
# CHECK-NEXT: "x"
# CHECK-NEXT: "y"
# CHECK-NEXT: "argc"
# CHECK-NEXT: "argv"
# CHECK-NEXT: "char"
# CHECK-NEXT: 0x00000038: Contribution size = 48, Format = DWARF32, Version = 5
# CHECK-NEXT: "clang version 15.0.0)"
# CHECK-NEXT: "foo.cpp"
# CHECK-NEXT: "/testLocListMultiple"
# CHECK-NEXT: "fooVar"
# CHECK-NEXT: "int"
# CHECK-NEXT: "_Z6useFooPi"
# CHECK-NEXT: "useFoo"
# CHECK-NEXT: "x"
# CHECK-NEXT: "_Z3fooi"
# CHECK-NEXT: "foo"
# CHECK-NEXT: "argc"

## Checking post bolt
# CHECK: .debug_str_offsets contents
# CHECK-NEXT: 0x00000000: Contribution size = 52, Format = DWARF32, Version = 5
# CHECK-NEXT: "clang version 15.0.0"
# CHECK-NEXT: "main.cpp"
# CHECK-NEXT: "/testLocListMultiple"
# CHECK-NEXT: "_Z3usePiS_"
# CHECK-NEXT: "use"
# CHECK-NEXT: "main"
# CHECK-NEXT: "int"
# CHECK-NEXT: "x"
# CHECK-NEXT: "y"
# CHECK-NEXT: "argc"
# CHECK-NEXT: "argv"
# CHECK-NEXT: "char"
# CHECK-NEXT: 0x00000038: Contribution size = 48, Format = DWARF32, Version = 5
# CHECK-NEXT: "clang version 15.0.0)"
# CHECK-NEXT: "foo.cpp"
# CHECK-NEXT: "/testLocListMultiple"
# CHECK-NEXT: "fooVar"
# CHECK-NEXT: "int"
# CHECK-NEXT: "_Z6useFooPi"
# CHECK-NEXT: "useFoo"
# CHECK-NEXT: "x"
# CHECK-NEXT: "_Z3fooi"
# CHECK-NEXT: "foo"
# CHECK-NEXT: "argc"