From patchwork Mon Jan 13 14:05:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13937418 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68E7B23DE81 for ; Mon, 13 Jan 2025 14:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736777123; cv=none; b=JFoqzFu6eMLqxpOLPGPzD80UMGPht3ej20HAJQlapsSxhkwbSkNRUrfUCWY7iC+kvNT3MoCeSct3x59QeI/J4Dqv8WQqtccU8EdOb19ydNkEuQIY+qd5AEu1kxqAqGyI3bndUdQVhNCJlsnn+YfSKWMkcfZrW180OvKy7FdAXH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736777123; c=relaxed/simple; bh=iWwaIcsDZ4Sr3b4S/577j90zLHdoeIMa/iamDlPNBwA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ipJ96Z+SWGfrUPQm9NpORpeLKH+aTvRFcV6mkauuyGoxJH7/PYd7AaBtR4l/szkF/TfLqGLM7Pu0corSG+T3Knh/Nvt88kvRclrZpnHbCyin+IEL/f/SbQul5GucvcwzLXKpx2GCaCMadngRY5lv76op/6k8D/pKpVIgFmw6Z6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=010+OfKi; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="010+OfKi" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso35775075e9.2 for ; Mon, 13 Jan 2025 06:05:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736777120; x=1737381920; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xf7YP3IkAsRQQJxEEobRB3kyQUwCz1GCIfo0L/Ujnio=; b=010+OfKi2PDi6GWJmLdf2Fb8T5kupeQm3PGu2IQPKwBeU296lW9UJR1QutqjuWYhEo tYl4yeR0961UrPm5wbRWNjR5VoEVoS7vwdE/f6/Hf2lfZSH07odWbE3vFHQhRo8zTlUT 5vI/yiCX/4G/aWM8P4WK5uzKFO6N+yapGy+G40z1mheK0wf0KZKKOJCuDLD6RDgTkC/M K9lCVIsgfDwrKdKLCdeSsXxxLgkxoHco/YXoDoJJ0jbinFxheCeaSlCRRSmW6Aqjk0oI voXZn3F9dhSxN30d1DN+Ak97X1aKsYX5kE+HuUHm63DrWFsBjNFE5eH7bJQEMWNaQ1d/ OUog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736777120; x=1737381920; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xf7YP3IkAsRQQJxEEobRB3kyQUwCz1GCIfo0L/Ujnio=; b=GpJbuGGLV7hkpMrSPVDSI0TyAtE2Tw2reYpUaGDzQtBYDn5j6hmBkn4ynrdAMMgAmk 7uridGdgRUBLVdz35zKkV7Vt3Gt+qnyVhpV8xSk8E/70dEJ0XKWjcCDfapesA5Sk1gKw /PvwbIj8NGtI7hZ2X2cGkD4sci928YySxQTMQTvl5tHW/xPnTAKHGF1eMHpnwrAZ5F9M CtdQLYPOXbbtVS/ONYKP59PpNKgWAQbD2AzHpbrqmcsTe1tye0pX1KsBWKuCWnSjgGSS nIusmZ/5YKMj4lBHwtPOiNaIE5vjTLStNGV6L9rLkiTz+IWstk35gDvqo53MU+mHnKGX ugsQ== X-Forwarded-Encrypted: i=1; AJvYcCUzBSbxYnO84PlLsD2XC5qWpvoBBH8s0+uXH/1SKrQxgckkMZ6FmqMOyJdDMIDlgUOO4Rg8CQgq5ogEdP8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8dGlEP/UmAW9Oo1Y0LRC4DYyFUcqknKkdq8ouQa2kr+OIzXP6 nsrgXgXeI10IAjXRkOwMcT26fm/UorweqRo8v6PKPa3HnHPNveWuhCwQYXTIP46HiOtmOS/2pjI KvCBb3jH2jQ== X-Google-Smtp-Source: AGHT+IHnIaAjS6kBqmfKE63dAzuPWGyY5MpgyWZmqfJgPPlsZjSHP5Qbhww3cRWn0ef6rWZdDf/BMeBb6tlkEw== X-Received: from wmrn32.prod.google.com ([2002:a05:600c:5020:b0:434:a7ee:3c40]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f47:b0:431:5632:448b with SMTP id 5b1f17b1804b1-436e26e23f8mr165897915e9.25.1736777119969; Mon, 13 Jan 2025 06:05:19 -0800 (PST) Date: Mon, 13 Jan 2025 14:05:15 +0000 In-Reply-To: <20250113-objtool-strict-v3-0-8b51f94957fb@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250113-objtool-strict-v3-0-8b51f94957fb@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250113-objtool-strict-v3-1-8b51f94957fb@google.com> Subject: [PATCH v3 1/2] objtool: Add --Werror From: Brendan Jackman To: Josh Poimboeuf , Peter Zijlstra , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Brendan Jackman At present objtool only prints to the terminal when observing "fatal warnings". This option lets you have it produce an error instead. The use case for this is noinstr validation; so far I've never seen any false warnings here, but it quite often detects real bugs. It would be useful for the build to fail when I have those bugs. Signed-off-by: Brendan Jackman Signed-off-by: Josh Poimboeuf --- tools/objtool/builtin-check.c | 6 ++++++ tools/objtool/check.c | 7 ++----- tools/objtool/include/objtool/builtin.h | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 387d56a7f5fb8da8435d0a3f5c05eeee66932c9b..0b28082df90710ff7127327deb857c0548f378c7 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -94,6 +94,12 @@ static const struct option check_options[] = { OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"), + /* + * For now, don't fail the kernel build on fatal warnings by default. + * These errors are still fairly common due to the growing matrix of + * supported toolchains and their recent pace of change. + */ + OPT_BOOLEAN(0, "Werror", &opts.werror, "fail on fatal warnings"), OPT_END(), }; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 76060da755b5c51cda3a669d8245d7d004e25f22..e44135293eb45f908e00359d84d954cfeddd266f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4944,10 +4944,7 @@ int check(struct objtool_file *file) } out: - /* - * For now, don't fail the kernel build on fatal warnings. These - * errors are still fairly common due to the growing matrix of - * supported toolchains and their recent pace of change. - */ + if (opts.werror && warnings) + return 1; return 0; } diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h index fcca6662c8b4b5e0048e54fada8694cc2e6ebc34..97d668010efadfa05bb6e25e1967a7d72bf77815 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -38,6 +38,7 @@ struct opts { bool sec_address; bool stats; bool verbose; + bool werror; }; extern struct opts opts; From patchwork Mon Jan 13 14:05:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13937419 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9839823DEAE for ; Mon, 13 Jan 2025 14:05:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736777125; cv=none; b=n5JYz3XMe0SZk+vM3IfBZqAgsuYjF7GssXBfIObqOPVBZr2f7tl72AO+qAKtGzFMZG+6000jP+yJBoeJ1yda39oSN8JRi5rTHCxsH4CRwrkYSGrATZq+ElSHJbdISrD9X/DH6MXm/btIvhtOL0PKUpBL10CG6No7MsJ+HPkYxPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736777125; c=relaxed/simple; bh=3LnAsMhP1pZpm6rI95kHTS+/gw5w1gOhLmu4sHb5rac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LtJCDAx3ui8mkPQm5bnOHwprAp3D3cWgau8qGC5hTvsSvtQ+ejEgaK6oB+pJBxYfup0YSug505vQXmL0VbrxZXywIgKwralRuxzF7TXnBT1jfIIpWShdBJ+6/kSSRk74+RX//XBP+XNYPOkoTSAUVdICCTRRBYmomJ6Jqse8+6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2x/WFUad; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2x/WFUad" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-386333ea577so1595302f8f.1 for ; Mon, 13 Jan 2025 06:05:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736777122; x=1737381922; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+ZPe1bNvuiIIATFBKvXi5cf5G8IqMVRN5Iv2+H/k4HE=; b=2x/WFUadoEo7uUqSwCj0yJbk8qbVaSXaDYcY619iuq4MZHQSxuwbRFo9/Zu8sf5vOI PmnmSQHC7sSoDi7GeiXWfSx4GT5Efe1x8gFpRfqWpDkBE9UaJbYhze6uAJepM4e1EBsP eJcEh4YDZaoj7puwz/UHSkD3IQDR2JbkFpsqU8AooZ1L2Tu2xgNnMcnPUN6wxcrkQndN DelVT0a8+dBbWO8PDv/xBEGPOyMVp/ItDr+JwA12nIbU2d2Ug1ApJzR7GTIJk1AezVcK gRv7tv9V5l3WxA7NXNHpBIi8vuGL+ZHcUjZFr7vySd/Z1CqRZ82ScX9tuOvb05SnYOIf vC3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736777122; x=1737381922; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+ZPe1bNvuiIIATFBKvXi5cf5G8IqMVRN5Iv2+H/k4HE=; b=OV/bLsOX+HyZeTitlWHHOKQb9D2HMPXtE4/nXGTldLW+FbPqNZcfrVGgwBsynAIJfR sK0sT+qkRoO1sl4Ell1aQY82WWgikXvVVf5wUyL9O3O1c4uU/CSa5nCBfSTcmQLKHEMP fZUqf3N5azwTeZ5f5VCWpWKVxfYWbjvEj2DKEYgkGF0/LAzXO1aT+xXRk5eAuxSXaVcf nTbZzzLgKqaNB0tPkg7LJQlZtP3VdK0bYnDL8QDnLYkQ4iUmRziHyITSL5LzUH9ye992 bUlWlIYy6WI6tSb2jOrCC6Cc/N54gC445z8qZ7toEMTRCQ64NsirItmDvKzZU8knjAeV BZlA== X-Forwarded-Encrypted: i=1; AJvYcCU/nSktyzE19MjoAY03IBkQpFrSsTdnRZ20hwoVgcxyc2DUa5ezN/XoS2N+UZ+2T+u1S6Mdo/zowBARYVY=@vger.kernel.org X-Gm-Message-State: AOJu0YynvsIO/ecZm4Bu2KMJwfR1JsIs5I1gT+mqK5LYdzwH2NbCqzfB mikwZzR5opx36RLjl8xy+ipwtEUhryK9rdLxgzlBuIkkfDNF3pIAKpta2Em1m65sLTVj/a5AquC iuR9275SK+A== X-Google-Smtp-Source: AGHT+IFCImalmFtqftfgPV7fXo5SPWkGINMDlx+uQu0uulLu5xXIGdZVMHnmcWHtKguwAmvevmLaJ75QWCDdYA== X-Received: from wmbjg22.prod.google.com ([2002:a05:600c:a016:b0:436:a247:a0e6]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:adf:a108:0:b0:38a:88ac:ed10 with SMTP id ffacd0b85a97d-38a88acedf9mr15222851f8f.25.1736777122192; Mon, 13 Jan 2025 06:05:22 -0800 (PST) Date: Mon, 13 Jan 2025 14:05:16 +0000 In-Reply-To: <20250113-objtool-strict-v3-0-8b51f94957fb@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250113-objtool-strict-v3-0-8b51f94957fb@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250113-objtool-strict-v3-2-8b51f94957fb@google.com> Subject: [PATCH v3 2/2] kbuild: Add option to fail build on vmlinux objtool issues From: Brendan Jackman To: Josh Poimboeuf , Peter Zijlstra , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Brendan Jackman NOINSTR_VALIDATION is pretty helpful for detecting bugs, it would be helpful for the build to fail when those bugs arise. If necessary it would be possible to enable this for individual warnings, it seems unlikely there's a use-case for that though. So for now just add a global setting. When the this new option, OBJTOOL_WERROR, is set, also add --verbose: if the build is failing then it's better to spit out any information that might help diagnose the failure, even if that risks a very verbose output. Checkpatch-args: --ignore=CONFIG_DESCRIPTION Signed-off-by: Brendan Jackman --- lib/Kconfig.debug | 10 ++++++++++ scripts/Makefile.lib | 1 + 2 files changed, 11 insertions(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f3d72370587936fa373129cc9b246f15dac907be..3ee92da4733a3a504991d5dbb4d0cee84f519d64 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -545,6 +545,16 @@ config FRAME_POINTER config OBJTOOL bool +config OBJTOOL_WERROR + bool "Run objtool with warnings as errors" + default n + depends on OBJTOOL + help + Fail the build when objtool produces warnings. + + By default, objtool just prints warnings to the terminal without + causing a build failure. This config changes that. + config STACK_VALIDATION bool "Compile-time stack metadata validation" depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7395200538da89a2f6e6d21f8959f3f60d291d79..a1b264e532920dd649122968d5782ca8eff34ad9 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -277,6 +277,7 @@ objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES) +objtool-args-$(CONFIG_OBJTOOL_WERROR) += --Werror --verbose objtool-args = $(objtool-args-y) \ $(if $(delay-objtool), --link) \