llvm-project/llvm/test/CodeGen/X86/dwarf-aranges-zero-size.ll
Patrick Walton becbbb7e3c Round up zero-sized symbols to 1 byte in .debug_aranges (without breaking other logic).
This commit modifies the AsmPrinter to avoid emitting any zero-sized symbols to
the .debug_aranges table, by rounding their size up to 1. Entries with zero
length violate the DWARF 5 spec, which states:

> Each descriptor is a triple consisting of a segment selector, the beginning
> address within that segment of a range of text or data covered by some entry
> owned by the corresponding compilation unit, followed by the non-zero length
> of that range.

In practice, these zero-sized entries produce annoying warnings in lld and
cause GNU binutils to truncate the table when parsing it.

Other parts of LLVM, such as DWARFDebugARanges in the DebugInfo module
(specifically the appendRange method), already avoid emitting zero-sized
symbols to .debug_aranges, but not comprehensively in the AsmPrinter. In fact,
the AsmPrinter does try to avoid emitting such zero-sized symbols when labels
aren't involved, but doesn't when the symbol to emitted is a difference of two
labels; this patch extends that logic to handle the case in which the symbol is
defined via labels.

Furthermore, this patch fixes a bug in which `available_externally` symbols
would cause unpredictable values to be emitted into the `.debug_aranges` table
under certain circumstances. In practice I don't believe that this caused
issues up until now, but the root cause of this bug--an invalid DenseMap
lookup--triggered failures in Chromium when combined with an earlier version of
this patch. Therefore, this patch fixes that bug too.

This is a revised version of diff D126257, which was reverted due to breaking
tests. The now-reverted version of this patch didn't distinguish between
symbols that didn't have their size reported to the DwarfDebug handler and
those that had their size reported to be zero. This new version of the patch
instead restricts the special handling only to the symbols whose size is
definitively known to be zero.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D126835
2022-06-27 10:01:03 -07:00

40 lines
2.1 KiB
LLVM

; Ensures that the AsmPrinter rounds up zero-sized symbols in `.debug_aranges` to one byte.
; Generated from the following Rust source:
;
; pub static EXAMPLE: () = ();
;
; Compiled with:
;
; $ rustc --crate-type=lib --target=x86_64-unknown-linux-gnu --emit=llvm-ir -g dwarf-aranges-zero-size.rs
; RUN: llc --generate-arange-section < %s | FileCheck %s
; CHECK: .section .debug_aranges
; CHECK: .quad _ZN23dwarf_aranges_zero_size7EXAMPLE17h8ab19f2b0c3b238dE
; CHECK-NEXT: .quad 1
; CHECK: .section
; ModuleID = 'dwarf_aranges_zero_size.fbc28187-cgu.0'
source_filename = "dwarf_aranges_zero_size.fbc28187-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@_ZN23dwarf_aranges_zero_size7EXAMPLE17h8ab19f2b0c3b238dE = constant <{ [0 x i8] }> zeroinitializer, align 1, !dbg !0
@__rustc_debug_gdb_scripts_section__ = linkonce_odr unnamed_addr constant [34 x i8] c"\01gdb_load_rust_pretty_printers.py\00", section ".debug_gdb_scripts", align 1
!llvm.module.flags = !{!5, !6, !7}
!llvm.dbg.cu = !{!8}
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "EXAMPLE", linkageName: "_ZN23dwarf_aranges_zero_size7EXAMPLE17h8ab19f2b0c3b238dE", scope: !2, file: !3, line: 1, type: !4, isLocal: false, isDefinition: true, align: 8)
!2 = !DINamespace(name: "dwarf_aranges_zero_size", scope: null)
!3 = !DIFile(filename: "dwarf-aranges-zero-size.rs", directory: "/Users/pcwalton/Desktop", checksumkind: CSK_MD5, checksum: "c2d51547bfaf5562b9c9061311fe4140")
!4 = !DIBasicType(name: "()", encoding: DW_ATE_unsigned)
!5 = !{i32 7, !"PIC Level", i32 2}
!6 = !{i32 2, !"RtLibUseGOT", i32 1}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !9, producer: "clang LLVM (rustc version 1.60.0-nightly (0c292c966 2022-02-08))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !10, globals: !11)
!9 = !DIFile(filename: "dwarf-aranges-zero-size.rs/@/dwarf_aranges_zero_size.fbc28187-cgu.0", directory: "/Users/pcwalton/Desktop")
!10 = !{}
!11 = !{!0}