Skip to content

Commit 8e9d906

Browse files
[EVM] Treat all .debug sections as DWO
This allows all DWARF debug sections to be emitted into a separate debug-only object, keeping the runtime bytecode free of debug data. SplitDwarfFile is explicitly disallowed, as it would produce both DWO and non-DWO sections in the same debug-only object, which doesn't make sense in our case. Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
1 parent ec67b23 commit 8e9d906

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/lib/Target/EVM/MCTargetDesc/EVMAsmBackend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,7 @@ MCAsmBackend *llvm::createEVMMCAsmBackend(const Target &T,
246246
const MCSubtargetInfo &STI,
247247
const MCRegisterInfo &MRI,
248248
const MCTargetOptions &Options) {
249+
if (!Options.SplitDwarfFile.empty())
250+
report_fatal_error("EVM does not support split dwarf");
249251
return new EVMAsmBackend(T, STI, ELF::ELFOSABI_STANDALONE);
250252
}

llvm/lib/Target/EVM/MCTargetDesc/EVMELFObjectWriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class EVMELFObjectWriter final : public MCELFObjectTargetWriter {
3636

3737
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
3838
bool IsPCRel) const override;
39+
40+
bool isDwoSection(const MCSectionELF &Sec) const override {
41+
return Sec.getName().starts_with(".debug");
42+
}
3943
};
4044
} // end of anonymous namespace
4145

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llc -O2 -filetype=obj -split-dwarf-output=%t.dwo < %s | llvm-readobj --sections - | FileCheck %s --check-prefix=OBJ
2+
; RUN: llvm-readobj --sections %t.dwo | FileCheck %s --check-prefix=DWO
3+
; RUN: not --crash llc -O2 -filetype=obj -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo < %s 2>&1 | FileCheck %s -check-prefix=SPLIT-NOT-SUPPORTED
4+
5+
target datalayout = "E-p:256:256-i256:256:256-S256-a:256:256"
6+
target triple = "evm"
7+
8+
; OBJ-NOT: Name: .debug
9+
; DWO: Name: .debug
10+
; SPLIT-NOT-SUPPORTED: LLVM ERROR: EVM does not support split dwarf
11+
12+
define i256 @foo(i256 %0, i256 %1) !dbg !4 {
13+
%add1 = add nsw i256 %0, 5, !dbg !7
14+
%add2 = add nsw i256 %1, 3, !dbg !8
15+
%mul = mul nsw i256 %add2, %add1, !dbg !9
16+
%add3 = add nsw i256 %add2, %add1, !dbg !10
17+
%add4 = add nsw i256 %add3, %mul, !dbg !11
18+
ret i256 %add4, !dbg !12
19+
}
20+
21+
!llvm.dbg.cu = !{!0}
22+
!llvm.module.flags = !{!2, !3}
23+
24+
!0 = distinct !DICompileUnit(language: DW_LANG_Assembly, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
25+
!1 = !DIFile(filename: "Test.sol", directory: "/tmp")
26+
!2 = !{i32 7, !"Dwarf Version", i32 5}
27+
!3 = !{i32 2, !"Debug Info Version", i32 3}
28+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
29+
!5 = !DISubroutineType(types: !6)
30+
!6 = !{}
31+
!7 = !DILocation(line: 2, column: 7, scope: !4)
32+
!8 = !DILocation(line: 3, column: 7, scope: !4)
33+
!9 = !DILocation(line: 4, column: 17, scope: !4)
34+
!10 = !DILocation(line: 5, column: 17, scope: !4)
35+
!11 = !DILocation(line: 6, column: 16, scope: !4)
36+
!12 = !DILocation(line: 6, column: 5, scope: !4)

0 commit comments

Comments
 (0)