From patchwork Fri Dec 13 11:31:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13906922 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 7E6BE1DF276 for ; Fri, 13 Dec 2024 11:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734089510; cv=none; b=Vv6fu8s0TK1Hn/aWvpYsX/MaLHuvcOGOZwABZmvViXmYLYLMzOWD3deRzcUbgw3n2+WjjgWOxZHoyYLSR3XlzKJwgBhuwOMqPD2KK1/MgaMpEBO8WVkNlEh7p/u/831Hr7lUeuWuvP9RMj2L861EXE6HvIufTgYXetRSoQoWsVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734089510; c=relaxed/simple; bh=RL2+sa7FqlB5keLFzemHFNSTwj0vyUQXIodq1LlTmxg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vDnfzhtIfpAK6OgMnJi33gWZ2ZYOqEKYictvYezPFkZMr5vsblJqRqa5zSh88mErJ/r964nYtVujmTo2W7bUDNuPhoCri5aIahNwKNcdz55gqAkdCoUjgfMxReL1DP/iTJ2wNuQisfdfQWTS2ew8KFiP9ld9vby3Seuu281PL58= 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=ciiw3bD+; arc=none smtp.client-ip=209.85.128.73 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="ciiw3bD+" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so15237715e9.3 for ; Fri, 13 Dec 2024 03:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734089507; x=1734694307; 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=A/liT58PKYw7HwtStWEUG+08/cDBkM9nfVGzjd6G6SU=; b=ciiw3bD+HUhNW8rAO8St0Zexrb7QFz3QeKpShEz/GzF8uyLrab0p/S0AIuraQEF8mP bVo3TKDKUvkOMAg15dNPWsGbMBcPx75YOBKHIL0H4bYXIx/zq+O2EBL62EWGcSYL6VDK sMTtsh5xkBIiEruINv6X0tf33lEkZFKBuH5/HVCWfQFQRJirsIoDT534/tKLmvmVSENI dl1DEMLZ79qd3W0A9Mgab5iwB7Ej+gsShnP2AOy+gL/eEeiiuH0FFqDV5N/FjcUwRkDa H57XjidmIQbSLnrVdl6m9WjONeCMeayTh8XEz2o+0h5oe/MQI0xzp6kjpneYdWHuzELu PaPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734089507; x=1734694307; 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=A/liT58PKYw7HwtStWEUG+08/cDBkM9nfVGzjd6G6SU=; b=b8pViPV02VsNcV+/OncPvuGPVE5bWU/qP/dpUKW5vtA2d09MEk9MlYv56u6nEf93z7 mTS2Rb/wIR8E39MmjyJL7bbxyl/WTjDgF1ci4hW3Gz5N5e0OZ6ViHHkxzIHyxGJA648Y LiPQ/Q9Ar/40Xnfdq8GIIfva53uHXlnFFz78TJoErWHQDX2ehFGwInR1a4fS4xiZ17La IJDwiHcx6IZLdDLeMqzJLywnfN5AffCDM3Fcq2SWS6sawmrmTiFKTIK96o2R7/Sl5TYR WwMPolGnol+53CA3Os7FQHzRtfue5arjF5YhdK62V1yWQggM0htRKV23tAvofV7QnYWC grJQ== X-Forwarded-Encrypted: i=1; AJvYcCVhfSaIKPbHarMs4EgCeAz1vJbytjIh22whcT3NFVdnUU5EMgyddKxv1OqgUQp1sQTQyiA1WhTfdzljd9E=@vger.kernel.org X-Gm-Message-State: AOJu0YxRQ/5r9b0exW3xCoibO8dw4+7/Zd631SmhpS6B2bybCIkxwa9U Z1YvFtL3WiZftES6HoL5SeTU56nFZxcQhbX7EW1L8uWEFW12f07bGsQDky22bNyTYzXkY1AvXy7 wGmbrR6x1/g== X-Google-Smtp-Source: AGHT+IH7cHlQeRy1xZRu5M7RBxGpX53bIPU0Rj1rBgppyxRggT+ne4NlBEvps3MOKD7DTPzL3SAILj1cLz/mhA== X-Received: from wmbd13.prod.google.com ([2002:a05:600c:58cd:b0:434:9dec:7cc5]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:154c:b0:434:ff30:a159 with SMTP id 5b1f17b1804b1-4362a982c34mr20114835e9.0.1734089506939; Fri, 13 Dec 2024 03:31:46 -0800 (PST) Date: Fri, 13 Dec 2024 11:31:30 +0000 In-Reply-To: <20241213-objtool-strict-v1-0-fd388f9d971f@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213-objtool-strict-v1-0-fd388f9d971f@google.com> X-Mailer: b4 0.15-dev Message-ID: <20241213-objtool-strict-v1-1-fd388f9d971f@google.com> Subject: [PATCH 1/2] objtool: Add --fail-on-warn 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. My use case for this is noinstr validation; so far I've never seen any false warnings here, but it quite often detects real bugs. I'd like my build to fail when I have those bugs. Signed-off-by: Brendan Jackman --- 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..dd70cbb98929b7f558c27766bda46ad276c0750d 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, "fail-on-warn", &opts.fail_on_warn, "fail on fatal warnings"), OPT_END(), }; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4ce176ad411fb12a10101bbedbb6180275941b4b..266896b46e92c5c4a3244aa73deb3a355e6d8f8d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4941,10 +4941,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.fail_on_warn && warnings) + return 1; return 0; } diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h index fcca6662c8b4b5e0048e54fada8694cc2e6ebc34..f9af81ad9f600044280085cd1a743609ce054a21 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 fail_on_warn; }; extern struct opts opts; From patchwork Fri Dec 13 11:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13906923 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 3BFB01DF723 for ; Fri, 13 Dec 2024 11:31:50 +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=1734089512; cv=none; b=ZzBFPyBKFWl7egWLRULrzug4jISToOLiY+fpee2p5dm57kIKGgNAlBWZ4ldxbTKY2IOujOZJNt247c8yNboTLr8o5jyM+h71ZqWEwe2LS7neJEVR47ubnWY8vP7AG4y83AN+xgJfqRxAFnclxaFGuGtm3vLOLM/ftIOj1LKDYrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734089512; c=relaxed/simple; bh=8Z+fkcLpCW50dgG3XgGbc9Y+J6ZITUqaOeKIYboitQ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FI4emZ+Rt9gWg6BSjNCM3kESZYK4eJhKlnCd4ppJtwLcauLUVARQHhbs0gEWbPfHYM2s9sGsXr9q8YiXtj5O6Ef0k7G9iAWjl02r0v3fPehVJs0kvQkOTaAU9BQ8sC8W3Jil2vhv09eDbauHpOjCUPeNYGpZuN+i8LlN8Y9lD60= 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=e8V4rozR; 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="e8V4rozR" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43627bb20b5so10416395e9.1 for ; Fri, 13 Dec 2024 03:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734089509; x=1734694309; 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=12jc0w/fivkkryMIJsg9WOh7az7NrRYvkDaKh8q38vk=; b=e8V4rozRZDQGgq2bdNP9Nlyfwa9Xh7OHavGBO4y1dBS7KWB5hmAmheJzIpiE8Va8Hy tThS8pUJk+855bCGr1xkxdKgL+hKir2WTVNg7Sc2SyCYixDonXpuRd6r5FlibvVngQcN mwy3BUdGVR30Y4FuGy/8eHAkKHR/oaiv3Zu4Zn3S5cU6OVkiFAUwpKXHM4rEfSaXRXTU 86GA5bMq24zb1IKPkw36n/JZVcyaac3/a4mjNGebq//WyJDnr91JCxT2IheOBCBy4hkW ZhukrohU3vzuLVu+yHxu1pRPoUeggUG3fdP0eCFvVhA4oL/RSlYrjmhnfQpw/WhsAKda Ofvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734089509; x=1734694309; 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=12jc0w/fivkkryMIJsg9WOh7az7NrRYvkDaKh8q38vk=; b=XHAsoVSDzR4i4TrtA0WBt5Yb//zZv1Se8rI9nfc2RYjLukmU/s+6CjP9HVkOekrEgN itGxJ6dm8zYX9kyzNRZtik39BYUN8kRhYlgvsCOkCe32NWo/pEKwl7UE91ZFxq/OP1DM GCPrLyUcdMAvnO6gsHf2S6IRiRcXjCT90Qg48X+x40H8x1YtwstKGUwMm06CNz99iLcS SkCB0BrhvVpSTl+mv1GKN1hVXTSTnJa4EcDWrM1/c6IGaujbfA/sKY0xT2QTiOWhfCqg 2RmuGt4s0oCUBRG7iDtVQPXv+pfnjJe8KH001sOHIowyUvA+KeDNdrT0lA0dcz6haqwm nPQg== X-Forwarded-Encrypted: i=1; AJvYcCXCpKOx2DmO1XD6PRDUh02cI3ieqY1yujFdeAtO3S1ADvLMwOeHNG3Q014h/9CCb2vAbvWMudY31DToZds=@vger.kernel.org X-Gm-Message-State: AOJu0YyiA9Qf3teA2cd6WpHS/dhnaoeYI7o09BOCtIGwARA6whyfnmMf XJNYEBJ6e+hMyZNXAnwUrzfFzN00v4QoQ2zS4lOZUFoLJ2qrgiDUhlPqtA7F8rbiJb19mKopdEf KVhm15USXRA== X-Google-Smtp-Source: AGHT+IEZ4eA8bhHHA8R9uWIaOs6w9kxA+a6SSCc9PyYcjPq9AgHQF76/B6v8e4W1chnsdD7KewFoDA8hfeL33Q== X-Received: from wmbdx22.prod.google.com ([2002:a05:600c:63d6:b0:436:3ea:c491]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a14:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-4362aa3bcdcmr19895245e9.14.1734089508870; Fri, 13 Dec 2024 03:31:48 -0800 (PST) Date: Fri, 13 Dec 2024 11:31:31 +0000 In-Reply-To: <20241213-objtool-strict-v1-0-fd388f9d971f@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241213-objtool-strict-v1-0-fd388f9d971f@google.com> X-Mailer: b4 0.15-dev Message-ID: <20241213-objtool-strict-v1-2-fd388f9d971f@google.com> Subject: [PATCH 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, I would like my build to fail when those bugs arise. If we wanted to we could enable this for individual warnings, it seems unlikely there's a use-case for that though. So for now I've just added a global setting for vmlinux. Signed-off-by: Brendan Jackman --- lib/Kconfig.debug | 11 +++++++++++ scripts/Makefile.vmlinux_o | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f3d72370587936fa373129cc9b246f15dac907be..b1f0f8c83b050d4112428e0d8dece059ebf8dcd2 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -563,6 +563,17 @@ config NOINSTR_VALIDATION select OBJTOOL default y +config VMLINUX_OBJTOOL_STRICT + bool "Strict objtool on vmlinux" + default n + # Conditions when we run objtool on vmlinux + depends on NOINSTR_VALIDATION || LTO_CLANG || X86_KERNEL_IBT + help + Fail the build when objtool produces warnings on vmlinux. + + By default, objtool just prints warnings to the terminal without + causing a build failure. This config changes that for vmlinux. + config VMLINUX_MAP bool "Generate vmlinux.map file when linking" depends on EXPERT diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index 0b6e2ebf60dc1bb69d9651d5b7858ccd296e92dd..97b6b262d482e0bac1a4d74f9a2e7b1867b6ee00 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -39,6 +39,7 @@ vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y) vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \ $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret) +vmlinux-objtool-args-$(CONFIG_VMLINUX_OBJTOOL_STRICT) += --fail-on-warn objtool-args = $(vmlinux-objtool-args-y) --link