Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -373,6 +373,11 @@ DwarfVersion = TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION); + bool Dwarf64 = Asm->TM.Options.MCOptions.Dwarf64 && + DwarfVersion >= 3 && // DWARF64 was introduced in DWARFv3. + TT.isArch64Bit() && // DWARF64 requires 64-bit relocations. + TT.isOSBinFormatELF(); // Support only ELF for now. + UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX(); // Use sections as references. Force for NVPTX. @@ -414,6 +419,8 @@ DwarfVersion >= 5 || (UseGNUDebugMacro && !useSplitDwarf()); Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion); + Asm->OutStreamer->getContext().setDwarfFormat(Dwarf64 ? dwarf::DWARF64 + : dwarf::DWARF32); } // Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h. Index: llvm/test/DebugInfo/X86/debug-frame-dwarf64.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-frame-dwarf64.ll @@ -0,0 +1,25 @@ +; This checks that .debug_frame can be generated in the DWARF64 format. + +; RUN: llc -mtriple=x86_64 -dwarf64 -filetype=obj %s -o %t +; RUN: llvm-dwarfdump -debug-frame %t | FileCheck %s + +; CHECK: .debug_frame contents: +; CHECK: 00000000 {{.+}} ffffffffffffffff CIE +; CHECK-NEXT: Format: DWARF64 +; CHECK: {{.+}} 0000000000000000 FDE cie=00000000 pc= +; CHECK-NEXT: Format: DWARF64 + +define void @f() nounwind !dbg !4 { +entry: + ret void +} + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!0} + +!0 = !{i32 1, !"Debug Info Version", i32 3} +!1 = !DIFile(filename: "foo.c", directory: "/tmp") +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Manual", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !3) +!3 = !{} +!4 = distinct !DISubprogram(name: "foo", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, scopeLine: 1, file: !1, scope: !1, type: !5) +!5 = !DISubroutineType(types: !3) Index: llvm/test/DebugInfo/X86/debug-line-dwarf64.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-line-dwarf64.ll @@ -0,0 +1,24 @@ +; This checks that .debug_line can be generated in the DWARF64 format. + +; RUN: llc -mtriple=x86_64 -dwarf-version=3 -dwarf64 -filetype=obj %s -o %t3 +; RUN: llvm-dwarfdump -debug-line %t3 | FileCheck %s + +; CHECK: .debug_line contents: +; CHECK-NEXT: debug_line[0x00000000] +; CHECK-NEXT: Line table prologue: +; CHECK-NEXT: total_length: +; CHECK-NEXT: format: DWARF64 + +@foo = common dso_local global i32 0, align 4, !dbg !5 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!0} + +!0 = !{i32 2, !"Debug Info Version", i32 3} +!1 = !DIFile(filename: "foo.c", directory: "/tmp") +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Manual", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !{} +!4 = !{!5} +!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) +!6 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true) +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) Index: llvm/test/DebugInfo/X86/dwarf64-support.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/dwarf64-support.ll @@ -0,0 +1,48 @@ +; This checks cases when the 64-bit DWARF debug info should not be generated +; even if '-dwarf64' is specified. + +; The 64-bit DWARF format was introduced in DWARFv3, so the '-dwarf64' switch +; should be ignored for earlier versions. +; RUN: llc -mtriple=x86_64 -dwarf-version=2 -dwarf64 -filetype=obj %s -o - | \ +; RUN: llvm-dwarfdump -debug-line - | \ +; RUN: FileCheck %s --check-prefixes=ELF64,CHECK + +; DWARF64 requires 64-bit relocations, so it is not produced for 32-bit targets. +; RUN: llc -mtriple=i386 -dwarf-version=5 -dwarf64 -filetype=obj %s -o - | \ +; RUN: llvm-dwarfdump -debug-line - | \ +; RUN: FileCheck %s --check-prefixes=ELF32,CHECK + +; DWARF64 is enabled only for ELF targets. The switch should be ignored for COFF. +; RUN: llc -mtriple=x86_64-windows-gnu -dwarf-version=5 -dwarf64 -filetype=obj %s -o - | \ +; RUN: llvm-dwarfdump -debug-line - | \ +; RUN: FileCheck %s --check-prefixes=COFF,CHECK + +; DWARF64 is enabled only for ELF targets. The switch should be ignored for Mach-O. +; RUN: llc -mtriple=x86_64-apple-darwin -dwarf-version=5 -dwarf64 -filetype=obj %s -o - | \ +; RUN: llvm-dwarfdump -debug-line - | \ +; RUN: FileCheck %s --check-prefixes=MACHO,CHECK + +; ELF64: file format elf64-x86-64 +; ELF32: file format elf32-i386 +; COFF: file format COFF-x86-64 +; MACHO: file format Mach-O 64-bit x86-64 + +; CHECK: .debug_line contents: +; CHECK-NEXT: debug_line[0x00000000] +; CHECK-NEXT: Line table prologue: +; CHECK-NEXT: total_length: +; CHECK-NEXT: format: DWARF32 + +@foo = common dso_local global i32 0, align 4, !dbg !5 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!0} + +!0 = !{i32 2, !"Debug Info Version", i32 3} +!1 = !DIFile(filename: "foo.c", directory: "/tmp") +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Manual", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !{} +!4 = !{!5} +!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression()) +!6 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true) +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)