[llvm] [DWARFLinker] backport line table patch into the DWARFLinkerParallel. (PR #77497)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 08:49:41 PST 2024
https://github.com/avl-llvm created https://github.com/llvm/llvm-project/pull/77497
This patch backports https://github.com/llvm/llvm-project/pull/77016 into the DWARFLinkerParallel.
>From 78c7bb486e397756567e38ec4d988bd2babc2ae9 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Tue, 9 Jan 2024 18:05:23 +0300
Subject: [PATCH] [DWARFLinker] backport line table patch into the
DWARFLinkerParallel.
This patch backports https://github.com/llvm/llvm-project/pull/77016
into the DWARFLinkerParallel.
---
.../Parallel/DebugLineSectionEmitter.h | 38 ++++++++++++++++---
.../tools/dsymutil/ARM/inline-source.test | 3 +-
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
index 545d04cfbe43d0..1839164dcec17e 100644
--- a/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
+++ b/llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
@@ -193,24 +193,39 @@ class DebugLineSectionEmitter {
Section.emitString(Include.getForm(), *IncludeStr);
}
+ bool HasChecksums = P.ContentTypes.HasMD5;
+ bool HasInlineSources = P.ContentTypes.HasSource;
+
+ dwarf::Form FileNameForm = dwarf::DW_FORM_string;
+ dwarf::Form LLVMSourceForm = dwarf::DW_FORM_string;
+
if (P.FileNames.empty()) {
// file_name_entry_format_count (ubyte).
Section.emitIntVal(0, 1);
} else {
+ FileNameForm = P.FileNames[0].Name.getForm();
+ LLVMSourceForm = P.FileNames[0].Source.getForm();
+
// file_name_entry_format_count (ubyte).
- Section.emitIntVal(2 + (P.ContentTypes.HasMD5 ? 1 : 0), 1);
+ Section.emitIntVal(
+ 2 + (HasChecksums ? 1 : 0) + (HasInlineSources ? 1 : 0), 1);
// file_name_entry_format (sequence of ULEB128 pairs).
encodeULEB128(dwarf::DW_LNCT_path, Section.OS);
- encodeULEB128(P.FileNames[0].Name.getForm(), Section.OS);
+ encodeULEB128(FileNameForm, Section.OS);
encodeULEB128(dwarf::DW_LNCT_directory_index, Section.OS);
encodeULEB128(dwarf::DW_FORM_data1, Section.OS);
- if (P.ContentTypes.HasMD5) {
+ if (HasChecksums) {
encodeULEB128(dwarf::DW_LNCT_MD5, Section.OS);
encodeULEB128(dwarf::DW_FORM_data16, Section.OS);
}
+
+ if (HasInlineSources) {
+ encodeULEB128(dwarf::DW_LNCT_LLVM_source, Section.OS);
+ encodeULEB128(LLVMSourceForm, Section.OS);
+ }
}
// file_names_count (ULEB128).
@@ -226,14 +241,27 @@ class DebugLineSectionEmitter {
// A null-terminated string containing the full or relative path name of a
// source file.
- Section.emitString(File.Name.getForm(), *FileNameStr);
+ Section.emitString(FileNameForm, *FileNameStr);
Section.emitIntVal(File.DirIdx, 1);
- if (P.ContentTypes.HasMD5) {
+ if (HasChecksums) {
+ assert((File.Checksum.size() == 16) &&
+ "checksum size is not equal to 16 bytes.");
Section.emitBinaryData(
StringRef(reinterpret_cast<const char *>(File.Checksum.data()),
File.Checksum.size()));
}
+
+ if (HasInlineSources) {
+ std::optional<const char *> FileSourceStr =
+ dwarf::toString(File.Source);
+ if (!FileSourceStr) {
+ U.warn("cann't read string from line table.");
+ return;
+ }
+
+ Section.emitString(LLVMSourceForm, *FileSourceStr);
+ }
}
}
diff --git a/llvm/test/tools/dsymutil/ARM/inline-source.test b/llvm/test/tools/dsymutil/ARM/inline-source.test
index ec437e3de9008c..6f237820e307d2 100644
--- a/llvm/test/tools/dsymutil/ARM/inline-source.test
+++ b/llvm/test/tools/dsymutil/ARM/inline-source.test
@@ -2,6 +2,7 @@
# RUN: mkdir -p %t
# RUN: llc -filetype=obj -mtriple arm64-apple-darwin %p/../Inputs/inline.ll -o %t/inline.o
# RUN: dsymutil -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: dsymutil --linker=llvm -f -oso-prepend-path=%t -y %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s
# Test inline source files.
@@ -17,4 +18,4 @@ objects:
# CHECK: file_names[ 1]:
# CHECK-NEXT: name: "inlined.c"
# CHECK-NEXT: dir_index: 1
-# CHECK-NEXT: source: "{{.*}}This is inline source code.
\ No newline at end of file
+# CHECK-NEXT: source: "{{.*}}This is inline source code.
More information about the llvm-commits
mailing list