Skip to content

Commit 604b555

Browse files
committed
Add new --force-dwarf64-str-offsets option to llvm-dwp and a test that uses it.
This patch adds a new llvm-dwp option that can be used in testing to verify that llvm-dwp can successfully upgrade a .debug_str_offsets tables from DWARF32 to DWARF64.
1 parent 98b0ee5 commit 604b555

File tree

5 files changed

+93
-7
lines changed

5 files changed

+93
-7
lines changed

llvm/include/llvm/DWP/DWP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ struct CompileUnitIdentifiers {
6868
};
6969

7070
LLVM_ABI Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
71-
OnCuIndexOverflow OverflowOptValue);
71+
OnCuIndexOverflow OverflowOptValue,
72+
bool ForceDwarf64StringOffsets);
7273

7374
typedef std::vector<std::pair<DWARFSectionKind, uint32_t>> SectionLengths;
7475

llvm/lib/DWP/DWP.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
429429
MCSection *StrOffsetSection,
430430
StringRef CurStrSection,
431431
StringRef CurStrOffsetSection, uint16_t Version,
432-
SectionLengths &SectionLength) {
432+
SectionLengths &SectionLength,
433+
const bool ForceDwarf64StringOffsets) {
433434
// Could possibly produce an error or warning if one of these was non-null but
434435
// the other was null.
435436
if (CurStrSection.empty() || CurStrOffsetSection.empty())
@@ -442,9 +443,11 @@ void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
442443
uint64_t PrevOffset = 0;
443444

444445
// Keep track if any new string offsets exceed UINT32_MAX. If any do, we can
445-
// emit a DWARF64 .debug_str_offsets table for this compile unit.
446+
// emit a DWARF64 .debug_str_offsets table for this compile unit. If the
447+
// \a ForceDwarf64StringOffsets argument is true, then force the emission of
448+
// DWARF64 .debug_str_offsets for testing.
446449
uint32_t OldOffsetSize = 4;
447-
uint32_t NewOffsetSize = 4;
450+
uint32_t NewOffsetSize = ForceDwarf64StringOffsets ? 8 : 4;
448451
while (const char *S = Data.getCStr(&LocalOffset)) {
449452
uint64_t NewOffset = Strings.getOffset(S, LocalOffset - PrevOffset);
450453
OffsetRemapping[PrevOffset] = NewOffset;
@@ -666,7 +669,8 @@ Error handleSection(
666669
}
667670

668671
Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
669-
OnCuIndexOverflow OverflowOptValue) {
672+
OnCuIndexOverflow OverflowOptValue,
673+
bool ForceDwarf64StringOffsets) {
670674
const auto &MCOFI = *Out.getContext().getObjectFileInfo();
671675
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
672676
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
@@ -759,7 +763,8 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
759763
}
760764

761765
writeStringsAndOffsets(Out, Strings, StrOffsetSection, CurStrSection,
762-
CurStrOffsetSection, Header.Version, SectionLength);
766+
CurStrOffsetSection, Header.Version, SectionLength,
767+
ForceDwarf64StringOffsets);
763768

764769
for (auto Pair : SectionLength) {
765770
auto Index = getContributionIndex(Pair.first, IndexVersion);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This test tests that llvm-dwp can successfully promote .debug_str_offsets to
2+
# DWARF64. We do this by using a hidden option to llvm-dwp which is
3+
# "--force-dwarf64-str-offsets". This allows us to test if llvm-dwp can
4+
# successfully promote a DWARF32 version of .debug_str_offsets to a DWARF64
5+
# version. This allows us to test the functionality without having to create a
6+
# 4GB .dwo file.
7+
8+
# RUN: yaml2obj %s -o %t.dwo
9+
# RUN: llvm-dwp %t.dwo -o %t.32.dwp
10+
# RUN: llvm-dwp %t.dwo -o %t.64.dwp --force-dwarf64-str-offsets
11+
# RUN: llvm-dwarfdump --debug-str-offsets %t.32.dwp | FileCheck --check-prefixes=DWARF32 %s
12+
# RUN: llvm-dwarfdump --debug-str-offsets %t.64.dwp | FileCheck --check-prefixes=DWARF64 %s
13+
14+
# DWARF32: .debug_str_offsets.dwo contents:
15+
# DWARF32-NEXT: 0x00000000: Contribution size = 36, Format = DWARF32, Version = 5
16+
# DWARF32-NEXT: 0x00000008: 00000000 "main"
17+
# DWARF32-NEXT: 0x0000000c: 00000005 "int"
18+
# DWARF32-NEXT: 0x00000010: 00000009 "argc"
19+
# DWARF32-NEXT: 0x00000014: 0000000e "argv"
20+
# DWARF32-NEXT: 0x00000018: 00000013 "char"
21+
# DWARF32-NEXT: 0x0000001c: 00000018 "Apple clang version 17.0.0 (clang-1700.4.4.1)"
22+
# DWARF32-NEXT: 0x00000020: 00000046 "simple.cpp"
23+
# DWARF32-NEXT: 0x00000024: 00000051 "simple.dwo"
24+
25+
# DWARF64: .debug_str_offsets.dwo contents:
26+
# DWARF64-NEXT: 0x00000000: Contribution size = 68, Format = DWARF64, Version = 5
27+
# DWARF64-NEXT: 0x00000010: 0000000000000000 "main"
28+
# DWARF64-NEXT: 0x00000018: 0000000000000005 "int"
29+
# DWARF64-NEXT: 0x00000020: 0000000000000009 "argc"
30+
# DWARF64-NEXT: 0x00000028: 000000000000000e "argv"
31+
# DWARF64-NEXT: 0x00000030: 0000000000000013 "char"
32+
# DWARF64-NEXT: 0x00000038: 0000000000000018 "Apple clang version 17.0.0 (clang-1700.4.4.1)"
33+
# DWARF64-NEXT: 0x00000040: 0000000000000046 "simple.cpp"
34+
# DWARF64-NEXT: 0x00000048: 0000000000000051 "simple.dwo"
35+
36+
--- !ELF
37+
FileHeader:
38+
Class: ELFCLASS64
39+
Data: ELFDATA2LSB
40+
Type: ET_REL
41+
Machine: EM_X86_64
42+
SectionHeaderStringTable: .strtab
43+
Sections:
44+
- Name: .debug_str_offsets.dwo
45+
Type: SHT_PROGBITS
46+
Flags: [ SHF_EXCLUDE ]
47+
AddressAlign: 0x1
48+
Content: '24000000050000000000000005000000090000000E00000013000000180000004600000051000000'
49+
- Name: .debug_str.dwo
50+
Type: SHT_PROGBITS
51+
Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ]
52+
AddressAlign: 0x1
53+
EntSize: 0x1
54+
Content: 6D61696E00696E74006172676300617267760063686172004170706C6520636C616E672076657273696F6E2031372E302E302028636C616E672D313730302E342E342E31290073696D706C652E6370700073696D706C652E64776F00
55+
- Name: .debug_info.dwo
56+
Type: SHT_PROGBITS
57+
Flags: [ SHF_EXCLUDE ]
58+
AddressAlign: 0x1
59+
Content: 540000000500050800000000031DD228762F8E1C0105210006070200190000000156000001400000000302917802000140000000030291700300014400000000040105040549000000054E00000006530000000404060100
60+
- Name: .debug_abbrev.dwo
61+
Type: SHT_PROGBITS
62+
Flags: [ SHF_EXCLUDE ]
63+
AddressAlign: 0x1
64+
Content: 01110125251305032576250000022E01111B1206401803253A0B3B0B49133F190000030500021803253A0B3B0B4913000004240003253E0B0B0B0000050F00491300000626004913000000
65+
- Type: SectionHeaderTable
66+
Sections:
67+
- Name: .strtab
68+
- Name: .debug_str_offsets.dwo
69+
- Name: .debug_str.dwo
70+
- Name: .debug_info.dwo
71+
- Name: .debug_abbrev.dwo
72+
...

llvm/tools/llvm-dwp/Opts.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ def continueOnCuIndexOverflow_EQ : Joined<["-", "--"], "continue-on-cu-index-ove
1616
"\t\ttruncated but valid DWP file, discarding any DWO files that would not fit within \n"
1717
"\t\tthe 32 bit/4GB limits of the format.">,
1818
Values<"continue,soft-stop">;
19+
def forceDwarf64StringOffsets : Flag<["-", "--"], "force-dwarf64-str-offsets">,
20+
Flags<[HelpHidden]>,
21+
HelpText<"Force all .debug_str_offsets to be emitted as DWARF64 tables. This "
22+
"option is used for testing.">;

llvm/tools/llvm-dwp/llvm-dwp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class DwpOptTable : public opt::GenericOptTable {
7373
static std::vector<std::string> ExecFilenames;
7474
static std::string OutputFilename;
7575
static std::string ContinueOption;
76+
static bool ForceDwarf64StringOffsets = false;
7677

7778
static Expected<SmallVector<std::string, 16>>
7879
getDWOFilenames(StringRef ExecFilename) {
@@ -160,6 +161,8 @@ int llvm_dwp_main(int argc, char **argv, const llvm::ToolContext &) {
160161
}
161162
}
162163
}
164+
if (Args.getLastArg(OPT_forceDwarf64StringOffsets))
165+
ForceDwarf64StringOffsets = true;
163166

164167
for (const llvm::opt::Arg *A : Args.filtered(OPT_execFileNames))
165168
ExecFilenames.emplace_back(A->getValue());
@@ -274,7 +277,8 @@ int llvm_dwp_main(int argc, char **argv, const llvm::ToolContext &) {
274277
if (!MS)
275278
return error("no object streamer for target " + TripleName, Context);
276279

277-
if (auto Err = write(*MS, DWOFilenames, OverflowOptValue)) {
280+
if (auto Err = write(*MS, DWOFilenames, OverflowOptValue,
281+
ForceDwarf64StringOffsets)) {
278282
logAllUnhandledErrors(std::move(Err), WithColor::error());
279283
return 1;
280284
}

0 commit comments

Comments
 (0)