Skip to content

Commit a6b5d6d

Browse files
authored
[DWARFLinker] backport line table patch into the DWARFLinkerParallel. (#77497)
This patch backports #77016 into the DWARFLinkerParallel.
1 parent ef87e66 commit a6b5d6d

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,39 @@ class DebugLineSectionEmitter {
193193
Section.emitString(Include.getForm(), *IncludeStr);
194194
}
195195

196+
bool HasChecksums = P.ContentTypes.HasMD5;
197+
bool HasInlineSources = P.ContentTypes.HasSource;
198+
199+
dwarf::Form FileNameForm = dwarf::DW_FORM_string;
200+
dwarf::Form LLVMSourceForm = dwarf::DW_FORM_string;
201+
196202
if (P.FileNames.empty()) {
197203
// file_name_entry_format_count (ubyte).
198204
Section.emitIntVal(0, 1);
199205
} else {
206+
FileNameForm = P.FileNames[0].Name.getForm();
207+
LLVMSourceForm = P.FileNames[0].Source.getForm();
208+
200209
// file_name_entry_format_count (ubyte).
201-
Section.emitIntVal(2 + (P.ContentTypes.HasMD5 ? 1 : 0), 1);
210+
Section.emitIntVal(
211+
2 + (HasChecksums ? 1 : 0) + (HasInlineSources ? 1 : 0), 1);
202212

203213
// file_name_entry_format (sequence of ULEB128 pairs).
204214
encodeULEB128(dwarf::DW_LNCT_path, Section.OS);
205-
encodeULEB128(P.FileNames[0].Name.getForm(), Section.OS);
215+
encodeULEB128(FileNameForm, Section.OS);
206216

207217
encodeULEB128(dwarf::DW_LNCT_directory_index, Section.OS);
208218
encodeULEB128(dwarf::DW_FORM_data1, Section.OS);
209219

210-
if (P.ContentTypes.HasMD5) {
220+
if (HasChecksums) {
211221
encodeULEB128(dwarf::DW_LNCT_MD5, Section.OS);
212222
encodeULEB128(dwarf::DW_FORM_data16, Section.OS);
213223
}
224+
225+
if (HasInlineSources) {
226+
encodeULEB128(dwarf::DW_LNCT_LLVM_source, Section.OS);
227+
encodeULEB128(LLVMSourceForm, Section.OS);
228+
}
214229
}
215230

216231
// file_names_count (ULEB128).
@@ -226,14 +241,27 @@ class DebugLineSectionEmitter {
226241

227242
// A null-terminated string containing the full or relative path name of a
228243
// source file.
229-
Section.emitString(File.Name.getForm(), *FileNameStr);
244+
Section.emitString(FileNameForm, *FileNameStr);
230245
Section.emitIntVal(File.DirIdx, 1);
231246

232-
if (P.ContentTypes.HasMD5) {
247+
if (HasChecksums) {
248+
assert((File.Checksum.size() == 16) &&
249+
"checksum size is not equal to 16 bytes.");
233250
Section.emitBinaryData(
234251
StringRef(reinterpret_cast<const char *>(File.Checksum.data()),
235252
File.Checksum.size()));
236253
}
254+
255+
if (HasInlineSources) {
256+
std::optional<const char *> FileSourceStr =
257+
dwarf::toString(File.Source);
258+
if (!FileSourceStr) {
259+
U.warn("cann't read string from line table.");
260+
return;
261+
}
262+
263+
Section.emitString(LLVMSourceForm, *FileSourceStr);
264+
}
237265
}
238266
}
239267

llvm/test/tools/dsymutil/ARM/inline-source.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RUN: mkdir -p %t
33
# RUN: llc -filetype=obj -mtriple arm64-apple-darwin %p/../Inputs/inline.ll -o %t/inline.o
44
# RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
5+
# RUN: dsymutil --linker=llvm -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
56

67
# Test inline source files.
78

@@ -17,4 +18,4 @@ objects:
1718
# CHECK: file_names[ 1]:
1819
# CHECK-NEXT: name: "inlined.c"
1920
# CHECK-NEXT: dir_index: 1
20-
# CHECK-NEXT: source: "{{.*}}This is inline source code.
21+
# CHECK-NEXT: source: "{{.*}}This is inline source code.

0 commit comments

Comments
 (0)