From patchwork Thu Feb 4 06:40:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12066371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5933C433DB for ; Thu, 4 Feb 2021 06:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A366164F58 for ; Thu, 4 Feb 2021 06:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbhBDGla (ORCPT ); Thu, 4 Feb 2021 01:41:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232799AbhBDGl1 (ORCPT ); Thu, 4 Feb 2021 01:41:27 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA10FC061788 for ; Wed, 3 Feb 2021 22:40:46 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id m9so1714792qka.22 for ; Wed, 03 Feb 2021 22:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=iFigka3JXPbuBeHUARia6t3bp5DpIh0Lh5S9mG4lTkc=; b=jXOhuAtQmp2iBB4CXNhILgsBGuonno1OECxXMZX9iyxNm02XOPTxc17MqMTbwqaPqF udTnSMcPmoRk4K6U2d6DxWMSN7g4ndN7nep1DRz8Ch/APFdzZ3oNPeN7deIoM84Ky4XM ijatQ6u3zl4OQG+WD873YWEdjgVilT3rEGIMemu5bqWNi8o2HYjmgLvx3dGpMjnEqXq+ ttQYfWrlK0WjfJu+grCRHxhwNdJblJBw/ntTLE6LD7cKcqh1jZ0z92Fz45dHwpFmZFzj hGctfUAdgO3nTnGL14Rvxk+GUd2Iassm97SjjdNrkEjj0g1SLO5G6tfm3R3aG2sruZG6 MZsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iFigka3JXPbuBeHUARia6t3bp5DpIh0Lh5S9mG4lTkc=; b=hjOTD8+Ud2TbLemx+UYSRLhVpvt+h427O5r3xUoTKBj/HN+Rj8yjkvBvVLByWxYXDa soWoJCE/5Llc0WIXI1H/tFM3QGY+GPn60KQ10MPKxqVa4J7uabsmYS4opGevUvaxkflF FlnSLGYHoLppLcOw4pfbmeOuU2ak2KZ4ZrudUfi0+n5D0QWCY0U0TACN3Lrl9kt0FWGF OOnh2iAVyOamfgbmFnRMg8CJkKFsfWaOrC/lztInDxk+RqykoNJHWVsYR402toAgfO/s 1K4OVdi+MAKjuVF9p0+YikoVOiayCUdhg85yrOEI0H+r8f4wo4eHMtyLebFpRuX0/bK9 DkUA== X-Gm-Message-State: AOAM532qOVxIgwnACYMvnI+KHYU54DVEuQOH6ChUxlQTqYgGv3H9/Stg S4DczydmBw5q6rxZiOy4HiG9TnCiPChgcvIvmbI= X-Google-Smtp-Source: ABdhPJxvSiVjhRNEbyS9ZOTjE3ThjkTruIefIL1DvVqTcqkWnCLGNAOlSfGIlmXetQe7g0Hf8AxkOepCVJnOzV1gtAs= Sender: "ndesaulniers via sendgmr" X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:e070:bc84:c4fd:eb02]) (user=ndesaulniers job=sendgmr) by 2002:a05:6214:18cb:: with SMTP id cy11mr6069393qvb.61.1612420846028; Wed, 03 Feb 2021 22:40:46 -0800 (PST) Date: Wed, 3 Feb 2021 22:40:36 -0800 In-Reply-To: <20210204064037.1281726-1-ndesaulniers@google.com> Message-Id: <20210204064037.1281726-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210204064037.1281726-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v8 1/2] Kbuild: make DWARF version a choice From: Nick Desaulniers To: Masahiro Yamada Cc: Nathan Chancellor , Andrew Morton , Sedat Dilek , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, Jakub Jelinek , Fangrui Song , Caroline Tice , Nick Clifton , Yonghong Song , Jiri Olsa , Andrii Nakryiko , Arnaldo Carvalho de Melo , Arvind Sankar , Chris Murphy , Nick Desaulniers , Nathan Chancellor Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice which is the default. Does so in a way that's forward compatible with existing configs, and makes adding future versions more straightforward. GCC since ~4.8 has defaulted to this DWARF version implicitly. Reviewed-by: Nathan Chancellor Suggested-by: Arvind Sankar Suggested-by: Fangrui Song Suggested-by: Nathan Chancellor Suggested-by: Masahiro Yamada Signed-off-by: Nick Desaulniers --- Makefile | 5 ++--- lib/Kconfig.debug | 16 +++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 407816375983..bed5cc150009 100644 --- a/Makefile +++ b/Makefile @@ -830,9 +830,8 @@ ifneq ($(LLVM_IAS),1) KBUILD_AFLAGS += -Wa,-gdwarf-2 endif -ifdef CONFIG_DEBUG_INFO_DWARF4 -DEBUG_CFLAGS += -gdwarf-4 -endif +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) ifdef CONFIG_DEBUG_INFO_REDUCED DEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index e906ea906cb7..94c1a7ed6306 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -256,13 +256,19 @@ config DEBUG_INFO_SPLIT to know about the .dwo files and include them. Incompatible with older versions of ccache. +choice + prompt "DWARF version" + help + Which version of DWARF debug info to emit. + config DEBUG_INFO_DWARF4 - bool "Generate dwarf4 debuginfo" + bool "Generate DWARF Version 4 debuginfo" help - Generate dwarf4 debug info. This requires recent versions - of gcc and gdb. It makes the debug information larger. - But it significantly improves the success of resolving - variables in gdb on optimized code. + Generate DWARF v4 debug info. This requires gcc 4.5+ and gdb 7.0+. + It makes the debug information larger, but it significantly + improves the success of resolving variables in gdb on optimized code. + +endchoice # "DWARF version" config DEBUG_INFO_BTF bool "Generate BTF typeinfo" From patchwork Thu Feb 4 06:40:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12066375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33570C433E0 for ; Thu, 4 Feb 2021 06:42:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3B3864F58 for ; Thu, 4 Feb 2021 06:42:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233043AbhBDGmH (ORCPT ); Thu, 4 Feb 2021 01:42:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbhBDGmH (ORCPT ); Thu, 4 Feb 2021 01:42:07 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9974AC06178C for ; Wed, 3 Feb 2021 22:40:48 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id c63so1781475qkd.1 for ; Wed, 03 Feb 2021 22:40:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=1kYL5naolZq/u7s+YLc6NTOf19bf1kc+RN2+cQNmUto=; b=Y5YEpMRPKYsYhwk1F0T4sK2BAViMrQNkAniQFRCL61EPw8WHxOBYqn+JTtVmpkIscY 1ZwqGeyx0PgMAsEMUlx3n7PhwO3zzlLWhIQdjj7Grn3q7WWUYL9VMdJ83Dlgba16VFdi JRkZFiRuTQ9KrZdtSqhIp9JyCUhDV+HEe746ZeQSTvzApEppIH58fMJ12OZ/fMIFn2hL pj2R1DOK0yVyrY0ZSAz+//Nh8k2O50F8yI/VXNOqke9oy9fIB+Vu+oP85B4BpdiOcVmK sZ/2b4gNe0eNUV5HOPmrF9qKvZgW68NuDLz3kCkdv6CswZ4kBt4wiDwzxWN4UoNYHz4Q VMcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1kYL5naolZq/u7s+YLc6NTOf19bf1kc+RN2+cQNmUto=; b=WRS7xf7yEVphf3h9XgftsMAKWmzImMpEiVH8lRsU72H7gI/qrW549dW9lgFRIDsxhQ SiHcrXYuvPTT2vH6Lp3RcxZ0ycI6MXflt2mtQS7fMK6m+5VuR54SvJNFXTS2LKo1y5v5 wZxODiu09vfaIj2gyRo5onxrxvnVxEZ/2a2IjlxbGHAZQYsUkjZyCpgAFsULh9DdZ4Jc 8VbUwuHX9un5JcfnQj/ufIHtr57vICGkYdQgOWVWBCokJ79RxjJIBt0k/7ZOSINiTGnP jIAq5WBNKPQ4odil8lyF2lLEi549aOf93T54BjB0MkBEqwIGQ+Vu1kj1un5M9UOTrXbA wz0g== X-Gm-Message-State: AOAM532pD38VpLmM866mk5NarrSWJ+tK8cSFgaUn6N325ySjnqCVsqpx pJliZb0tcalwq2+hkV0Ny4w76LQK7Xpiqe4qDRk= X-Google-Smtp-Source: ABdhPJyTMwEyQuOJejDqtO+KEQ9wfJM71Sduo9lyX51iJrTq8R9JEV1C5MiU6xMUHj/q7mP7Iyv39j5gNv4jw/RW590= Sender: "ndesaulniers via sendgmr" X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:e070:bc84:c4fd:eb02]) (user=ndesaulniers job=sendgmr) by 2002:a05:6214:2ee:: with SMTP id h14mr6477655qvu.34.1612420847819; Wed, 03 Feb 2021 22:40:47 -0800 (PST) Date: Wed, 3 Feb 2021 22:40:37 -0800 In-Reply-To: <20210204064037.1281726-1-ndesaulniers@google.com> Message-Id: <20210204064037.1281726-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210204064037.1281726-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v8 2/2] Kbuild: implement support for DWARF v5 From: Nick Desaulniers To: Masahiro Yamada Cc: Nathan Chancellor , Andrew Morton , Sedat Dilek , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, Jakub Jelinek , Fangrui Song , Caroline Tice , Nick Clifton , Yonghong Song , Jiri Olsa , Andrii Nakryiko , Arnaldo Carvalho de Melo , Arvind Sankar , Chris Murphy , Nick Desaulniers , Nathan Chancellor Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org DWARF v5 is the latest standard of the DWARF debug info format. GCC 11 will change the implicit default DWARF version, if left unspecified, to DWARF v5. DWARF5 wins significantly in terms of size when mixed with compression (CONFIG_DEBUG_INFO_COMPRESSED). 363M vmlinux.clang12.dwarf5.compressed 434M vmlinux.clang12.dwarf4.compressed 439M vmlinux.clang12.dwarf2.compressed 457M vmlinux.clang12.dwarf5 536M vmlinux.clang12.dwarf4 548M vmlinux.clang12.dwarf2 515M vmlinux.gcc10.2.dwarf5.compressed 599M vmlinux.gcc10.2.dwarf4.compressed 624M vmlinux.gcc10.2.dwarf2.compressed 630M vmlinux.gcc10.2.dwarf5 765M vmlinux.gcc10.2.dwarf4 809M vmlinux.gcc10.2.dwarf2 Though the quality of debug info is harder to quantify; size is not a proxy for quality. Jakub notes: One thing is GCC DWARF-5 support, that is whether the compiler will support -gdwarf-5 flag, and that support should be there from GCC 7 onwards. All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental option that enabled some small DWARF subset (initially only a few DW_LANG_* codes newly added to DWARF5 drafts). Only GCC 7 (released after DWARF 5 has been finalized) started emitting DWARF5 section headers and got most of the DWARF5 changes in... Another separate thing is whether the assembler does support the -gdwarf-5 option (i.e. if you can compile assembler files with -Wa,-gdwarf-5) ... That option is about whether the assembler will emit DWARF5 or DWARF2 .debug_line. It is fine to compile C sources with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as doesn't support it. Version check GCC so that we don't need to worry about the difference in command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to validate the DWARF Version in the assembler feature detection script. Most issues with clang produced assembler were fixed in binutils 2.35.1, but 2.35.2 fixed issues related to requiring the flag -Wa,-gdwarf-5 explicitly. The added shell script test checks for the latter, and is only required when using clang without its integrated assembler, though we use for clang regardless as we do not yet have a way to query the assembler from Kconfig. Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet recognize the new additions to the DWARF debug info. This only modifies the DWARF version emitted by the compiler, not the assembler. The DWARF version of a binary can be validated with: $ llvm-dwarfdump | head -n 4 | grep version or $ readelf --debug-dump=info 2>/dev/null | grep Version Parts of the tree don't reuse DEBUG_CFLAGS as they should; such cleanup is left as a follow up. Link: http://www.dwarfstd.org/doc/DWARF5.pdf Link: https://bugzilla.redhat.com/show_bug.cgi?id=1922707 Reported-by: Sedat Dilek Reported-by: Chris Murphy Suggested-by: Arvind Sankar Suggested-by: Caroline Tice Suggested-by: Fangrui Song Suggested-by: Jakub Jelinek Suggested-by: Masahiro Yamada Suggested-by: Nathan Chancellor Reviewed-by: Nathan Chancellor Signed-off-by: Nick Desaulniers --- Makefile | 1 + include/asm-generic/vmlinux.lds.h | 7 ++++++- lib/Kconfig.debug | 18 ++++++++++++++++++ scripts/test_dwarf5_support.sh | 8 ++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 scripts/test_dwarf5_support.sh diff --git a/Makefile b/Makefile index bed5cc150009..8b2deca568ee 100644 --- a/Makefile +++ b/Makefile @@ -831,6 +831,7 @@ KBUILD_AFLAGS += -Wa,-gdwarf-2 endif dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5 DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) ifdef CONFIG_DEBUG_INFO_REDUCED diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 34b7e0d2346c..1e7cde4bd3f9 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -842,8 +842,13 @@ /* DWARF 4 */ \ .debug_types 0 : { *(.debug_types) } \ /* DWARF 5 */ \ + .debug_addr 0 : { *(.debug_addr) } \ + .debug_line_str 0 : { *(.debug_line_str) } \ + .debug_loclists 0 : { *(.debug_loclists) } \ .debug_macro 0 : { *(.debug_macro) } \ - .debug_addr 0 : { *(.debug_addr) } + .debug_names 0 : { *(.debug_names) } \ + .debug_rnglists 0 : { *(.debug_rnglists) } \ + .debug_str_offsets 0 : { *(.debug_str_offsets) } /* Stabs debugging sections. */ #define STABS_DEBUG \ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 94c1a7ed6306..ad6f78989d4f 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -268,6 +268,24 @@ config DEBUG_INFO_DWARF4 It makes the debug information larger, but it significantly improves the success of resolving variables in gdb on optimized code. +config DEBUG_INFO_DWARF5 + bool "Generate DWARF Version 5 debuginfo" + depends on GCC_VERSION >= 50000 || CC_IS_CLANG + depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS)) + depends on !DEBUG_INFO_BTF + help + Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc + 5.0+ accepts the -gdwarf-5 flag but only had partial support for some + draft features until 7.0), and gdb 8.0+. + + Changes to the structure of debug info in Version 5 allow for around + 15-18% savings in resulting image and debug info section sizes as + compared to DWARF Version 4. DWARF Version 5 standardizes previous + extensions such as accelerators for symbol indexing and the format + for fission (.dwo/.dwp) files. Users may not want to select this + config if they rely on tooling that has not yet been updated to + support DWARF Version 5. + endchoice # "DWARF version" config DEBUG_INFO_BTF diff --git a/scripts/test_dwarf5_support.sh b/scripts/test_dwarf5_support.sh new file mode 100755 index 000000000000..c46e2456b47a --- /dev/null +++ b/scripts/test_dwarf5_support.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +# Test that the assembler doesn't need -Wa,-gdwarf-5 when presented with DWARF +# v5 input, such as `.file 0` and `md5 0x00`. Should be fixed in GNU binutils +# 2.35.2. https://sourceware.org/bugzilla/show_bug.cgi?id=25611 +echo '.file 0 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245' | \ + $* -gdwarf-5 -Wno-unused-command-line-argument -c -x assembler -o /dev/null -