Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1647266ybt; Thu, 18 Jun 2020 13:48:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysKeBBW528uYPRpwWfwgN88EWb0/qzrrghMVuC+IlIwhUoxo4mSMfw9BOHiR/Evu4nMbLX X-Received: by 2002:a17:906:945a:: with SMTP id z26mr537679ejx.448.1592513285340; Thu, 18 Jun 2020 13:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513285; cv=none; d=google.com; s=arc-20160816; b=n8xD4Koen7KGGmDmuNFjwORJC5HDP3LANbcbp+R4H+zoARsPclorIlmtM8gjAeXNKg 7DWj+5S1Y3S71xTIDac4zQ7dIdT0fEY4CcgGKNFQoVobjof2NEzT2M6v9v4BrmccobFK EmstJIMGNJVU1Dh+ed9FDac3r8rNIKBaW3SNwIM9c8DnlMoUrwh45mjyhT2HKSSFzwXX 1HiyBtAB2LCcwilxhMvx79y0V0vIp4y1if3p0TK6O8mEKwW23VWzUAx9piyHcz5sqPbF ZIJdRDeE1as7DpiXQxYBI+B4DoN0AH+sfqLgIl8S4R0zzMxOG+RdaVvKI010SAgSVcyN 2vnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3j7gR9Rp8y8xjMaSScXX/ft16KC+9qyyWEmYS8b+eIM=; b=KihDrIm1ZWR5vy5DeG3Ia/bGAkXmk9ztlW3+M49ZsI+tQcBqfihUqezZ2VOG04y1zv J59SOY1SiMeZ+qexWWVQkLm77EExW9FU3UdErktyCGGVSQDIAJoYv8+UuaBA4SQNaJsW eCH4u703amFZW8WMZXeEGxTruelU4OE95eAkWog7u2lSAXPf9bYUDYCE/4ylKMmQQTRJ jCilXSo8mR++SzQPWdzE5xyCHI3pQCq6Za+1DFK8zvNs+I6jkU4NnWPBY1XKklN8gtPs a5Iuv6Xg6C7ODq8ADi7JmNSEtLt+NLEhaRX7XsibtwjyTHQULuOFMo/0zgwi9j0Vr8re sFeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si2678676ejr.510.2020.06.18.13.47.36; Thu, 18 Jun 2020 13:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730793AbgFRUjB (ORCPT + 99 others); Thu, 18 Jun 2020 16:39:01 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:48815 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbgFRUjA (ORCPT ); Thu, 18 Jun 2020 16:39:00 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:38:56 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 52378B2659; Thu, 18 Jun 2020 16:38:59 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 01/51] objtool: Factor out reasons to build objtool Date: Thu, 18 Jun 2020 13:37:47 -0700 Message-ID: <6ac0671bef706812b1751a7a04d1854e9586e890.1592510545.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the reasons to build and run objtool are: Stack validation (objtool subcmds: orc + check) Orc data generation (objtool subcmds: orc) Code analysis (objtool subcmds: check) Since the reasons are varied and the stack validation step is skipped with a warning if libelf is missing, the logic of Kconfig and the Makefiles is somewhat messy and will only get messier the more subcommands objtool supports. In preparation for adding new subcommands, break up the current configurations such as CONFIG_STACK_VALIDATION, CONFIG_UNWINDER_ORC, etc. so that we translate them into the objtool subcommands that we need to build into objtool and whether the objtool pass is optional (SKIP_STACK_VALIDATION=1). This allows us to greatly simplify the objtool Makefile so that the arch-dependence of the subcommands can be encoded in the usual place, arch/Kconfig, rather than a bunch of per-supported-arch ifdef blocks in tools/objtool/Makefile. Signed-off-by: Matt Helsley --- Makefile | 15 ++++++++------- arch/Kconfig | 23 +++++++++++++++++++++++ arch/x86/Kconfig.debug | 1 + lib/Kconfig.debug | 1 + tools/objtool/Makefile | 5 +++-- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index ae5d8220f431..cf731709ebe7 100644 --- a/Makefile +++ b/Makefile @@ -1051,18 +1051,19 @@ mod_sign_cmd = true endif export mod_sign_cmd +ifdef CONFIG_OBJTOOL_SUBCMDS HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) - -ifdef CONFIG_STACK_VALIDATION - has_libelf := $(call try-run,\ +has_libelf := $(call try-run,\ echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) - ifeq ($(has_libelf),1) - objtool_target := tools/objtool FORCE - else +ifeq ($(has_libelf),1) + objtool_target := tools/objtool FORCE +else + ifdef CONFIG_STACK_VALIDATION SKIP_STACK_VALIDATION := 1 export SKIP_STACK_VALIDATION endif -endif +endif # has_libelf +endif # CONFIG_OBJTOOL_SUBCMDS PHONY += prepare0 diff --git a/arch/Kconfig b/arch/Kconfig index 8cc35dc556c7..4919412031eb 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -767,6 +767,29 @@ config HAVE_STACK_VALIDATION Architecture supports the 'objtool check' host tool command, which performs compile-time stack metadata validation. +config OBJTOOL_SUBCMD_CHECK + bool + select OBJTOOL_SUBCMDS + help + Run the 'objtool check' host tool command, which + performs compile-time stack metadata validation. + +config OBJTOOL_SUBCMD_ORC + bool + select OBJTOOL_SUBCMDS + help + Run the 'objtool orc' host tool command, which collects information + enabling reliable runtime kernel stack traces. + +config OBJTOOL_SUBCMDS + bool + default n + help + Other configurations require running objtool host tool commands. + For example, stack validation is available on the architecture + (HAVE_STACK_VALIDATION=y) and has been enabled (STACK_VALIDATION=y) + which selects OBJTOOL_SUBCMD_CHECK and OBJTOOL_SUBCMDS + config HAVE_RELIABLE_STACKTRACE bool help diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index 0dd319e6e5b4..4f2d596505c1 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -241,6 +241,7 @@ config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 select STACK_VALIDATION + select OBJTOOL_SUBCMD_ORC help This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d74ac0fd6b2d..e38e6cb22aa5 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -386,6 +386,7 @@ config FRAME_POINTER config STACK_VALIDATION bool "Compile-time stack metadata validation" depends on HAVE_STACK_VALIDATION + select OBJTOOL_SUBCMD_CHECK default n help Add compile-time checks to validate stack metadata, including frame diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 7770edcda3a0..aa0c6d3d2d46 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 include ../scripts/Makefile.include include ../scripts/Makefile.arch +include $(OUTPUT)/../../include/config/auto.conf # always use the host compiler ifneq ($(LLVM),) @@ -47,8 +48,8 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) AWK = awk -SUBCMD_CHECK := n -SUBCMD_ORC := n +SUBCMD_CHECK := $(CONFIG_OBJTOOL_SUBCMD_CHECK) +SUBCMD_ORC := $(CONFIG_OBJTOOL_SUBCMD_ORC) ifeq ($(SRCARCH),x86) SUBCMD_CHECK := y -- 2.20.1