Skip to content

Commit d42455a

Browse files
committed
MC: force eager evaluation of relocations in .debug_info
Force eager evaluation of symbolic difference on debug_info which is required to be resolved eagerly for fission as dwo sections may not contain relocations. Fixes: llvm#56642
1 parent 1a73ef7 commit d42455a

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

llvm/lib/MC/MCObjectStreamer.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,17 @@ static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
162162
void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
163163
const MCSymbol *Lo,
164164
unsigned Size) {
165-
if (!getAssembler().getContext().getTargetTriple().isRISCV())
165+
if (!getAssembler().getContext().getTargetTriple().isRISCV() ||
166+
getCurrentFragment()->getParent()->getName().startswith(".debug_info"))
166167
if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
167168
return emitIntValue(*Diff, Size);
168169
MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
169170
}
170171

171172
void MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
172173
const MCSymbol *Lo) {
173-
if (!getAssembler().getContext().getTargetTriple().isRISCV())
174+
if (!getAssembler().getContext().getTargetTriple().isRISCV() ||
175+
getCurrentFragment()->getParent()->getName().startswith(".debug_info"))
174176
if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
175177
return emitULEB128IntValue(*Diff);
176178
MCStreamer::emitAbsoluteSymbolDiffAsULEB128(Hi, Lo);

llvm/test/CodeGen/RISCV/fixups-diff.ll

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ entry:
2323
}
2424

2525
; CHECK: Section {{.*}} .rela.debug_info {
26-
; CHECK: 0x22 R_RISCV_ADD32 - 0x0
27-
; CHECK-NEXT: 0x22 R_RISCV_SUB32 - 0x0
28-
; CHECK: 0x2B R_RISCV_ADD32 - 0x0
29-
; CHECK-NEXT: 0x2B R_RISCV_SUB32 - 0x0
26+
; CHECK: 0x27 R_RISCV_32 - 0x0
27+
; CHECK: 0x31 R_RISCV_32 - 0x0
3028
; CHECK: }
3129

3230
; CHECK: Section {{.*}} .rela.eh_frame {
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; RUN: llc -mtriple riscv64-unknown-linux-gnu -filetype obj %s -o - | llvm-dwarfdump - | FileCheck %s -check-prefix CHECK-DWARF
2+
; RUN: llc -mtriple riscv64-unknown-linux-gnu -filetype obj %s -o - | llvm-readobj -r - | FileCheck %s -check-prefix CHECK-OBJ
3+
4+
source_filename = "reduced.c"
5+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
6+
target triple = "riscv64-unknown-linux-gnu"
7+
8+
define dso_local signext i32 @f() #0 !dbg !7 {
9+
entry:
10+
ret i32 32, !dbg !13
11+
}
12+
13+
attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit" }
14+
15+
!llvm.dbg.cu = !{!0}
16+
!llvm.module.flags = !{!2, !3, !4, !5}
17+
!llvm.ident = !{!6}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 15.0.0", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "reduced.dwo", emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
20+
!1 = !DIFile(filename: "reduced.c", directory: "/SourceCache")
21+
!2 = !{i32 2, !"Debug Info Version", i32 3}
22+
!3 = !{i32 1, !"wchar_size", i32 4}
23+
!4 = !{i32 1, !"target-abi", !"lp64"}
24+
!5 = !{i32 1, !"SmallDataLimit", i32 0}
25+
!6 = !{!"clang version 15.0.0"}
26+
!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
27+
!8 = !DIFile(filename: "/SourceCache/reduced.c", directory: "")
28+
!9 = !DISubroutineType(types: !10)
29+
!10 = !{!11}
30+
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
31+
!12 = !{}
32+
!13 = !DILocation(line: 2, column: 15, scope: !7)
33+
34+
; CHECK-DWARF: 0x0000002a: DW_TAG_subprogram
35+
; CHECK-DWARF-NEXT: DW_AT_low_pc (0x0000000000000000)
36+
; CHECK-DWARF-NEXT: DW_AT_high_pc (0x0000000000000008)
37+
38+
; CHECK-OBJ: Section (5) .rela.debug_info {
39+
; CHECK-OBJ: 0x1A R_RISCV_32 - 0x0
40+
; CHECK-OBJ: 0x1E R_RISCV_64 - 0x0
41+
; CHECK-OBJ: }

llvm/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
; Check that we actually have relocations, otherwise this is kind of pointless.
88
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_info {
9-
; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0
10-
; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0
9+
; READOBJ-RELOCS: 0x11 R_RISCV_32 - 0x0
1110
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_frame {
1211
; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0
1312
; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0

0 commit comments

Comments
 (0)