Skip to content

Commit

Permalink
MC: force eager evaluation of relocations in .debug_info
Browse files Browse the repository at this point in the history
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
  • Loading branch information
compnerd committed Jul 25, 2022
1 parent 1a73ef7 commit d42455a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
const MCSymbol *Lo,
unsigned Size) {
if (!getAssembler().getContext().getTargetTriple().isRISCV())
if (!getAssembler().getContext().getTargetTriple().isRISCV() ||
getCurrentFragment()->getParent()->getName().startswith(".debug_info"))
if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
return emitIntValue(*Diff, Size);
MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
}

void MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
const MCSymbol *Lo) {
if (!getAssembler().getContext().getTargetTriple().isRISCV())
if (!getAssembler().getContext().getTargetTriple().isRISCV() ||
getCurrentFragment()->getParent()->getName().startswith(".debug_info"))
if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
return emitULEB128IntValue(*Diff);
MCStreamer::emitAbsoluteSymbolDiffAsULEB128(Hi, Lo);
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/CodeGen/RISCV/fixups-diff.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ entry:
}

; CHECK: Section {{.*}} .rela.debug_info {
; CHECK: 0x22 R_RISCV_ADD32 - 0x0
; CHECK-NEXT: 0x22 R_RISCV_SUB32 - 0x0
; CHECK: 0x2B R_RISCV_ADD32 - 0x0
; CHECK-NEXT: 0x2B R_RISCV_SUB32 - 0x0
; CHECK: 0x27 R_RISCV_32 - 0x0
; CHECK: 0x31 R_RISCV_32 - 0x0
; CHECK: }

; CHECK: Section {{.*}} .rela.eh_frame {
Expand Down
41 changes: 41 additions & 0 deletions llvm/test/DebugInfo/RISCV/debug_info.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; RUN: llc -mtriple riscv64-unknown-linux-gnu -filetype obj %s -o - | llvm-dwarfdump - | FileCheck %s -check-prefix CHECK-DWARF
; RUN: llc -mtriple riscv64-unknown-linux-gnu -filetype obj %s -o - | llvm-readobj -r - | FileCheck %s -check-prefix CHECK-OBJ

source_filename = "reduced.c"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
target triple = "riscv64-unknown-linux-gnu"

define dso_local signext i32 @f() #0 !dbg !7 {
entry:
ret i32 32, !dbg !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" }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5}
!llvm.ident = !{!6}

!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)
!1 = !DIFile(filename: "reduced.c", directory: "/SourceCache")
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 1, !"target-abi", !"lp64"}
!5 = !{i32 1, !"SmallDataLimit", i32 0}
!6 = !{!"clang version 15.0.0"}
!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
!8 = !DIFile(filename: "/SourceCache/reduced.c", directory: "")
!9 = !DISubroutineType(types: !10)
!10 = !{!11}
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!12 = !{}
!13 = !DILocation(line: 2, column: 15, scope: !7)

; CHECK-DWARF: 0x0000002a: DW_TAG_subprogram
; CHECK-DWARF-NEXT: DW_AT_low_pc (0x0000000000000000)
; CHECK-DWARF-NEXT: DW_AT_high_pc (0x0000000000000008)

; CHECK-OBJ: Section (5) .rela.debug_info {
; CHECK-OBJ: 0x1A R_RISCV_32 - 0x0
; CHECK-OBJ: 0x1E R_RISCV_64 - 0x0
; CHECK-OBJ: }
3 changes: 1 addition & 2 deletions llvm/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

; Check that we actually have relocations, otherwise this is kind of pointless.
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_info {
; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0
; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0
; READOBJ-RELOCS: 0x11 R_RISCV_32 - 0x0
; READOBJ-RELOCS: Section ({{.*}}) .rela.debug_frame {
; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0
; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0
Expand Down

0 comments on commit d42455a

Please sign in to comment.