Message ID | 20230210215141.108958-1-andrea.righi@canonical.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1195682wrn; Fri, 10 Feb 2023 13:58:51 -0800 (PST) X-Google-Smtp-Source: AK7set9Dae99dxJtzZ6sHff7LbvYVDvVfj13wFWU+K2cUOm/9u/mmgsFPPH3xVxw5bht4cn1kjZV X-Received: by 2002:a05:6a21:3a81:b0:bc:c9a8:6e08 with SMTP id zv1-20020a056a213a8100b000bcc9a86e08mr19122859pzb.48.1676066331001; Fri, 10 Feb 2023 13:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676066330; cv=none; d=google.com; s=arc-20160816; b=ktp5BKGj0U/H6jnhj8AMPNMQCMBWR0MNB9ZTXl79HI2e28LBpZ2Wvo7tC9aoPSMOsL LVZ4EACPyEYzk4VQfFn5LjE1mEWB6gT8jpY2zegDW9KMXvekSeYSxRX1wDDG2XAPRRQF I6jPxtRyFFa5XK84vH29emcYfsK7Uis9Q3xMqOTPmnGT1UU/ffJcjFbgNz1s5M7OIZbe ++KHZKBcFPnocDRv6+V0waJj5QDn5qVWjiQza0mvG/rQwrEqeXn2CyeI4TWff3tQ0BPM iWxBkAhd+oEQyiHcj7qX84SRhsiOUCgqiFBa0LRkMNVAUFlt1EVaxgWfFJOlNS8TVD7/ 0lwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zFT0oOBpYveO604RTQTdkSq+7ygdeMz6BBCP0ZNZAbw=; b=zBMJMY0dmxYcD/p93ErEw0HIYR9LiiatDYEQ67cxubF84V5u4ryyT2WsRkL00GOgkr BavGphCGdQj9A44fzpxJtTCK/BX1hOBu9whx7q4aHX06oIxrf/wX9lv/ii/tho8ByC5V FcL+q7eT0Bk8r3stDAFDFhGTwRhdjokhojQvs1OXtDgD3ZrV2DOaClrVEOf7p/lzX9C/ +N5x5ZI7q+auzSesdqvPEko5LfXIbWYOA0ZVqUsKtFU6SoqS4x+5A7glWSayHyFD8hfA MPQD7oC52IYFwztcINOXN/xw2o3DLEurFyISPZnCQ216gGXWj5XMImXZiJPw8T8J2A7T ZfhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=hmEh7MaW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a63600c000000b0047811809072si5421946pgb.92.2023.02.10.13.58.38; Fri, 10 Feb 2023 13:58:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=hmEh7MaW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233943AbjBJVwF (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Fri, 10 Feb 2023 16:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233932AbjBJVvv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 10 Feb 2023 16:51:51 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3816566F for <linux-kernel@vger.kernel.org>; Fri, 10 Feb 2023 13:51:45 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 11CFF3F194 for <linux-kernel@vger.kernel.org>; Fri, 10 Feb 2023 21:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676065904; bh=zFT0oOBpYveO604RTQTdkSq+7ygdeMz6BBCP0ZNZAbw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=hmEh7MaWGz+RUO+0mLratkKjHU3S6FghrjiX84sKsAa/ajkk9ST6P0zPyJb3bO7+t I437AOWk1wGwslgLPjBfQYWWuLfQ/6/izMPDGf7ggwrO5EG5dBuY4PaFrHNmbfhMjW Kx/PBfXOmpsVEd7bpboLaq5coO6qZW1m1qXLAQDml+lHho0NnMqgKh0T5mwmKd1wlO kZo6/BJ0omPv1pexPhQHGi35XzBCTv4H8bYbmHVOz4PU9U5fR91EWs6GZ1GUExqD7V EW54cIP5aB4bLz1m10ukpS1xw96BiOhGQLRRx45rQsymLxZLU8/XySa8SoL8N60d8N 8/2yxihgzFaGA== Received: by mail-ed1-f69.google.com with SMTP id o21-20020aa7dd55000000b004a245f58006so4395308edw.12 for <linux-kernel@vger.kernel.org>; Fri, 10 Feb 2023 13:51:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zFT0oOBpYveO604RTQTdkSq+7ygdeMz6BBCP0ZNZAbw=; b=RQyoXcvXTEyFyxNmzCxbLOtusrEs5Ravgpa8kjcAGXzrds+8kJ8AOLejSN7IRJbcnS EswZHns2oAkAE2ph6dSVK4AU2z/qOb19TFICQDoTDH5k/qF8YCwa0wNJQVqlunCsUaGV l2KzcxPCRykmZqFDoqXLlTPrYca8eg8d46So2jsTs7DLEX6p5EyDrkXqZtjwHYycXmFj QFOOuGVpGBVcgDEOVXXygeXtQ/paScfrPfoVlX/PowYYSTHaZ3KuO5F6EAnI7696TIMl J1mxUV87msU+0x8li5QiJHHRIIU8myI+XcBQBIklpEa4nYLBqkv7GYOJf/wOoqtq0Ydx FV9w== X-Gm-Message-State: AO0yUKWVAuagoLDkffb0mteqAS8Wswc0D/BPbra/LdW/U4kYw97SqTve rnBsLCjeIMveFqm8JT3Fz/FqeBlFx4+dlo4DtUeODEV+qvALmajrwr6l/BF3JvcfAOAOup5MWAl /vHwnD5VuWwfVUZmCX0wEHhP6Jt73rbFrQVVT8O/s+L7yXDDwgw== X-Received: by 2002:a50:9e6e:0:b0:4aa:a709:8aaa with SMTP id z101-20020a509e6e000000b004aaa7098aaamr17736716ede.26.1676065902951; Fri, 10 Feb 2023 13:51:42 -0800 (PST) X-Received: by 2002:a50:9e6e:0:b0:4aa:a709:8aaa with SMTP id z101-20020a509e6e000000b004aaa7098aaamr17736703ede.26.1676065902700; Fri, 10 Feb 2023 13:51:42 -0800 (PST) Received: from righiandr-XPS-13-7390.homenet.telecomitalia.it (host-87-7-128-191.retail.telecomitalia.it. [87.7.128.191]) by smtp.gmail.com with ESMTPSA id o17-20020a50c291000000b0049ef70a2894sm2852729edf.38.2023.02.10.13.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 13:51:42 -0800 (PST) From: Andrea Righi <andrea.righi@canonical.com> To: Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com> Cc: Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, bjorn3_gh@protonmail.com, Kees Cook <keescook@chromium.org>, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] rust: allow to use INIT_STACK_ALL_ZERO Date: Fri, 10 Feb 2023 22:51:41 +0100 Message-Id: <20230210215141.108958-1-andrea.righi@canonical.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757466183728146119?= X-GMAIL-MSGID: =?utf-8?q?1757482928979455697?= |
Series |
[v2] rust: allow to use INIT_STACK_ALL_ZERO
|
|
Commit Message
Andrea Righi
Feb. 10, 2023, 9:51 p.m. UTC
With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes
-ftrivial-auto-var-init=zero to clang, that triggers the following
error:
error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang'
However, this additional option that is currently required by clang is
going to be removed in the future (as the name of the option suggests),
likely with clang-17.
So, make sure bindgen is using this extra option if the major version of
the libclang used by bindgen is < 17.
In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST
without triggering any build error.
Link: https://github.com/llvm/llvm-project/issues/44842
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---
Changes in v2:
- check the version of libclang used by bindgen to determine if we need
to pass the additional clang option
rust/Makefile | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
On February 10, 2023 1:51:41 PM PST, Andrea Righi <andrea.righi@canonical.com> wrote: >With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes >-ftrivial-auto-var-init=zero to clang, that triggers the following >error: > > error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' > >However, this additional option that is currently required by clang is >going to be removed in the future (as the name of the option suggests), >likely with clang-17. > >So, make sure bindgen is using this extra option if the major version of >the libclang used by bindgen is < 17. > >In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST >without triggering any build error. > >Link: https://github.com/llvm/llvm-project/issues/44842 >Signed-off-by: Andrea Righi <andrea.righi@canonical.com> >--- > >Changes in v2: > - check the version of libclang used by bindgen to determine if we need > to pass the additional clang option > > rust/Makefile | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > >diff --git a/rust/Makefile b/rust/Makefile >index ff70c4c916f8..c77d7ce96a85 100644 >--- a/rust/Makefile >+++ b/rust/Makefile >@@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) > # some configurations, with new GCC versions, etc. > bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) > >+# Auto variable zero-initialization requires an additional special option with >+# clang that is going to be removed sometimes in the future (likely in >+# clang-17), so make sure to pass this option only if clang supports it >+# (libclang major version < 17). >+# >+# https://github.com/llvm/llvm-project/issues/44842 >+ifdef CONFIG_INIT_STACK_ALL_ZERO >+libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') >+ifeq ($(shell expr $(libclang_maj_ver) \< 17), 1) >+bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang >+endif >+endif This logic already exists in the top-level Makefile. How does -ftrivial-auto-var-init=zero make it into bindgen_c_flags normally? (I.e. why does the legacy -enable... option not?) >+ > bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \ > $(bindgen_extra_c_flags) > endif
On Fri, Feb 10, 2023 at 02:43:56PM -0800, Kees Cook wrote: > On February 10, 2023 1:51:41 PM PST, Andrea Righi <andrea.righi@canonical.com> wrote: > >With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes > >-ftrivial-auto-var-init=zero to clang, that triggers the following > >error: > > > > error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' > > > >However, this additional option that is currently required by clang is > >going to be removed in the future (as the name of the option suggests), > >likely with clang-17. > > > >So, make sure bindgen is using this extra option if the major version of > >the libclang used by bindgen is < 17. > > > >In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST > >without triggering any build error. > > > >Link: https://github.com/llvm/llvm-project/issues/44842 > >Signed-off-by: Andrea Righi <andrea.righi@canonical.com> > >--- > > > >Changes in v2: > > - check the version of libclang used by bindgen to determine if we need > > to pass the additional clang option > > > > rust/Makefile | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > >diff --git a/rust/Makefile b/rust/Makefile > >index ff70c4c916f8..c77d7ce96a85 100644 > >--- a/rust/Makefile > >+++ b/rust/Makefile > >@@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) > > # some configurations, with new GCC versions, etc. > > bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) > > > >+# Auto variable zero-initialization requires an additional special option with > >+# clang that is going to be removed sometimes in the future (likely in > >+# clang-17), so make sure to pass this option only if clang supports it > >+# (libclang major version < 17). > >+# > >+# https://github.com/llvm/llvm-project/issues/44842 > >+ifdef CONFIG_INIT_STACK_ALL_ZERO > >+libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') > >+ifeq ($(shell expr $(libclang_maj_ver) \< 17), 1) > >+bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > >+endif > >+endif > > This logic already exists in the top-level Makefile. How does -ftrivial-auto-var-init=zero make it into bindgen_c_flags normally? (I.e. why does the legacy -enable... option not?) If we're using gcc, the top-level Makefile doesn't set the clang options, so in this case CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER is undefined. But then bindgen always relies on libclang to parse C, even if gcc is used globally, therefore it needs the extra clang flag. Ideally it'd be nice if bindgen would support a gcc backend, but until then we need to do something special here, like this kind of duplicated logic... -Andrea > > >+ > > bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \ > > $(bindgen_extra_c_flags) > > endif > > > -- > Kees Cook
On February 11, 2023 1:04:16 AM PST, Andrea Righi <andrea.righi@canonical.com> wrote: >On Fri, Feb 10, 2023 at 02:43:56PM -0800, Kees Cook wrote: >> On February 10, 2023 1:51:41 PM PST, Andrea Righi <andrea.righi@canonical.com> wrote: >> >With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes >> >-ftrivial-auto-var-init=zero to clang, that triggers the following >> >error: >> > >> > error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' >> > >> >However, this additional option that is currently required by clang is >> >going to be removed in the future (as the name of the option suggests), >> >likely with clang-17. >> > >> >So, make sure bindgen is using this extra option if the major version of >> >the libclang used by bindgen is < 17. >> > >> >In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST >> >without triggering any build error. >> > >> >Link: https://github.com/llvm/llvm-project/issues/44842 >> >Signed-off-by: Andrea Righi <andrea.righi@canonical.com> >> >--- >> > >> >Changes in v2: >> > - check the version of libclang used by bindgen to determine if we need >> > to pass the additional clang option >> > >> > rust/Makefile | 13 +++++++++++++ >> > 1 file changed, 13 insertions(+) >> > >> >diff --git a/rust/Makefile b/rust/Makefile >> >index ff70c4c916f8..c77d7ce96a85 100644 >> >--- a/rust/Makefile >> >+++ b/rust/Makefile >> >@@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) >> > # some configurations, with new GCC versions, etc. >> > bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) >> > >> >+# Auto variable zero-initialization requires an additional special option with >> >+# clang that is going to be removed sometimes in the future (likely in >> >+# clang-17), so make sure to pass this option only if clang supports it >> >+# (libclang major version < 17). >> >+# >> >+# https://github.com/llvm/llvm-project/issues/44842 >> >+ifdef CONFIG_INIT_STACK_ALL_ZERO >> >+libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') >> >+ifeq ($(shell expr $(libclang_maj_ver) \< 17), 1) >> >+bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang >> >+endif >> >+endif >> >> This logic already exists in the top-level Makefile. How does -ftrivial-auto-var-init=zero make it into bindgen_c_flags normally? (I.e. why does the legacy -enable... option not?) > >If we're using gcc, the top-level Makefile doesn't set the clang >options, so in this case CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER is >undefined. But then bindgen always relies on libclang to parse C, even >if gcc is used globally, therefore it needs the extra clang flag. Ah yes! Thank you, I keep forgetting about mixed compiler builds. > >Ideally it'd be nice if bindgen would support a gcc backend, but until >then we need to do something special here, like this kind of duplicated >logic... Right. Yeah, good fix. One nit: the -enable... flag is removed in Clang 16+: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags With that fixed: Reviewed-by: Kees Cook <keescook@chromium.org>
On Sat, Feb 11, 2023 at 05:44:33AM -0800, Kees Cook wrote: > On February 11, 2023 1:04:16 AM PST, Andrea Righi <andrea.righi@canonical.com> wrote: > >On Fri, Feb 10, 2023 at 02:43:56PM -0800, Kees Cook wrote: > >> On February 10, 2023 1:51:41 PM PST, Andrea Righi <andrea.righi@canonical.com> wrote: > >> >With CONFIG_INIT_STACK_ALL_ZERO enabled, bindgen passes > >> >-ftrivial-auto-var-init=zero to clang, that triggers the following > >> >error: > >> > > >> > error: '-ftrivial-auto-var-init=zero' hasn't been enabled; enable it at your own peril for benchmarking purpose only with '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' > >> > > >> >However, this additional option that is currently required by clang is > >> >going to be removed in the future (as the name of the option suggests), > >> >likely with clang-17. > >> > > >> >So, make sure bindgen is using this extra option if the major version of > >> >the libclang used by bindgen is < 17. > >> > > >> >In this way we can enable CONFIG_INIT_STACK_ALL_ZERO with CONFIG_RUST > >> >without triggering any build error. > >> > > >> >Link: https://github.com/llvm/llvm-project/issues/44842 > >> >Signed-off-by: Andrea Righi <andrea.righi@canonical.com> > >> >--- > >> > > >> >Changes in v2: > >> > - check the version of libclang used by bindgen to determine if we need > >> > to pass the additional clang option > >> > > >> > rust/Makefile | 13 +++++++++++++ > >> > 1 file changed, 13 insertions(+) > >> > > >> >diff --git a/rust/Makefile b/rust/Makefile > >> >index ff70c4c916f8..c77d7ce96a85 100644 > >> >--- a/rust/Makefile > >> >+++ b/rust/Makefile > >> >@@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) > >> > # some configurations, with new GCC versions, etc. > >> > bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) > >> > > >> >+# Auto variable zero-initialization requires an additional special option with > >> >+# clang that is going to be removed sometimes in the future (likely in > >> >+# clang-17), so make sure to pass this option only if clang supports it > >> >+# (libclang major version < 17). > >> >+# > >> >+# https://github.com/llvm/llvm-project/issues/44842 > >> >+ifdef CONFIG_INIT_STACK_ALL_ZERO > >> >+libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') > >> >+ifeq ($(shell expr $(libclang_maj_ver) \< 17), 1) > >> >+bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > >> >+endif > >> >+endif > >> > >> This logic already exists in the top-level Makefile. How does -ftrivial-auto-var-init=zero make it into bindgen_c_flags normally? (I.e. why does the legacy -enable... option not?) > > > >If we're using gcc, the top-level Makefile doesn't set the clang > >options, so in this case CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER is > >undefined. But then bindgen always relies on libclang to parse C, even > >if gcc is used globally, therefore it needs the extra clang flag. > > Ah yes! Thank you, I keep forgetting about mixed compiler builds. > > > > >Ideally it'd be nice if bindgen would support a gcc backend, but until > >then we need to do something special here, like this kind of duplicated > >logic... > > Right. Yeah, good fix. One nit: the -enable... flag is removed in Clang 16+: oic, with clang-16 we get a deprecated warning (but it doesn't fail), then starting with clang-17 the -enable.. flag is not available anymore. Then I agree that a better check would be version < 16, instead of < 17. Thanks, -Andrea > > https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags > > With that fixed: > > Reviewed-by: Kees Cook <keescook@chromium.org> > > > -- > Kees Cook
On Sat, Feb 11, 2023 at 3:35 PM Andrea Righi <andrea.righi@canonical.com> wrote: > > oic, with clang-16 we get a deprecated warning (but it doesn't fail), > then starting with clang-17 the -enable.. flag is not available anymore. Wait, Kees' link says it is deprecated in Clang 16, and the removal will happen in 18. > Then I agree that a better check would be version < 16, instead of < 17. Applied to `rust-fixes` with that changed. Please take a look if it is what you expected (both content and commit message): https://github.com/Rust-for-Linux/linux/commit/1921ea54ab0d91d7a660c5bb980fce1efc9223f9 Thanks! Cheers, Miguel
On Fri, Apr 07, 2023 at 12:52:18AM +0200, Miguel Ojeda wrote: > On Sat, Feb 11, 2023 at 3:35 PM Andrea Righi <andrea.righi@canonical.com> wrote: > > > > oic, with clang-16 we get a deprecated warning (but it doesn't fail), > > then starting with clang-17 the -enable.. flag is not available anymore. > > Wait, Kees' link says it is deprecated in Clang 16, and the removal > will happen in 18. > > > Then I agree that a better check would be version < 16, instead of < 17. > > Applied to `rust-fixes` with that changed. Please take a look if it is > what you expected (both content and commit message): > https://github.com/Rust-for-Linux/linux/commit/1921ea54ab0d91d7a660c5bb980fce1efc9223f9 The check (< 16) looks correct and the comment also looks correct to me, this option will be removed in clang 18, as mentioned here: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags (Maybe we could add also this link as a reference) Thanks! -Andrea
On Fri, Apr 7, 2023 at 8:02 AM Andrea Righi <andrea.righi@canonical.com> wrote: > > The check (< 16) looks correct and the comment also looks correct to me, > this option will be removed in clang 18, as mentioned here: > https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags > > (Maybe we could add also this link as a reference) Thanks for taking a look -- Kees' link added! I removed "(as the name of the option suggests)" from the commit message, by the way, since the name of the option suggests the original `-ftrivial` option was to be removed, not the `-enable` one. If that understanding is wrong, please let me know! Cheers, Miguel
On Sun, Apr 09, 2023 at 10:49:58PM +0200, Miguel Ojeda wrote: > On Fri, Apr 7, 2023 at 8:02 AM Andrea Righi <andrea.righi@canonical.com> wrote: > > > > The check (< 16) looks correct and the comment also looks correct to me, > > this option will be removed in clang 18, as mentioned here: > > https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags > > > > (Maybe we could add also this link as a reference) > > Thanks for taking a look -- Kees' link added! > > I removed "(as the name of the option suggests)" from the commit > message, by the way, since the name of the option suggests the > original `-ftrivial` option was to be removed, not the `-enable` one. > If that understanding is wrong, please let me know! Yes, that looks more clear, the name of the option is a bit misleading. :) To be clear what is going to be removed is -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang, in this way clang will be compatible with gcc and they can both use -ftrivial-auto-var-init=zero. Thanks, -Andrea > > Cheers, > Miguel
On Tue, Apr 11, 2023 at 9:11 AM Andrea Righi <andrea.righi@canonical.com> wrote: > > Yes, that looks more clear, the name of the option is a bit misleading. :) > > To be clear what is going to be removed is > -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang, > in this way clang will be compatible with gcc and they can both use > -ftrivial-auto-var-init=zero. Exactly, i.e. `-enable` is the one getting removed, but the wording within it (`knowing-it-will-be-removed-from-clang`) meant that the `-ftrivial...=zero` one was the one that would be removed, not `-enable` itself (even if now what will happen is the opposite than what the option suggested originally). So when I read the commit message, the "this additional option ... is going to be removed in the future (as the name of the option suggests)" sounded wrong, since the name did not suggest that, but rather that `-ftrivial...=zero` would be removed, not itself (since that was the original plan). If I understood the story properly, that is. :) Thanks for taking a look! Cheers, Miguel
diff --git a/rust/Makefile b/rust/Makefile index ff70c4c916f8..c77d7ce96a85 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -269,6 +269,19 @@ BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) # some configurations, with new GCC versions, etc. bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) +# Auto variable zero-initialization requires an additional special option with +# clang that is going to be removed sometimes in the future (likely in +# clang-17), so make sure to pass this option only if clang supports it +# (libclang major version < 17). +# +# https://github.com/llvm/llvm-project/issues/44842 +ifdef CONFIG_INIT_STACK_ALL_ZERO +libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') +ifeq ($(shell expr $(libclang_maj_ver) \< 17), 1) +bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang +endif +endif + bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \ $(bindgen_extra_c_flags) endif