lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240731034112.6060-1-zehuixu@whu.edu.cn>
Date: Wed, 31 Jul 2024 06:41:12 +0300
From: Zehui Xu <zehuixu@....edu.cn>
To: ojeda@...nel.org,
	alex.gaynor@...il.com,
	wedsonaf@...il.com
Cc: boqun.feng@...il.com,
	gary@...yguo.net,
	bjorn3_gh@...tonmail.com,
	benno.lossin@...ton.me,
	a.hindborg@...sung.com,
	aliceryhl@...gle.com,
	rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	zehuixu@....edu.cn
Subject: [PATCH v2] rust: Kbuild: Skip -fmin-function-alignment in bindgen flags

GCC 14 recently added the -fmin-function-alignment option and the
root Makefile uses it to replace -falign-functions when available.
However, this flag can cause issues when passed to the Rust
Makefile and affect the bindgen process. Bindgen relies on
libclang to parse C code, and currently does not support the
-fmin-function-alignment flag, leading to compilation failures
when GCC 14 is used.

This patch addresses the issue by adding -fmin-function-alignment
to the bindgen_skip_c_flags in rust/Makefile. This prevents the
flag from causing compilation issues and maintains compatibility.

In addition, since -falign-functions is not used when
-fmin-function-alignment is available but skipped and libclang
supports -falign-functions, this patch adds it back to the
bindgen_extra_c_flags to ensure the intended function alignment
is maintained.

Link: https://lore.kernel.org/linux-kbuild/20240222133500.16991-1-petr.pavlu@suse.com/
Signed-off-by: Zehui Xu <zehuixu@....edu.cn>
---
Hello again!

This is the second version of my patch. I discovered some issues right after
sending the email. Since this is my first kernel patch, I was too excited.
I will be more careful and calm during my checks next time. Compared to the
first patch, this version includes not only changes to the format of the
commit message (thanks to Miguel Ojeda for the patient guidance) but also
some code changes.

While preparing the second version of the patch, I realized that the root
Makefile replaces -falign-functions with -fmin-function-alignment, and if we
simply skip we'll lose this config. To ensure consistency, I added it back in
bindgen_extra_c_flags. Though I am uncertain if this is a good approach.

Looking for suggestions and thank you all for your time!

v1:
* https://lore.kernel.org/all/20240730222053.37066-1-zehuixu@whu.edu.cn/

v2:
* Added -falign-functions to bindgen_extra_c_flags when skipping 
  -fmin-function-alignment to maintain function alignment settings in GCC 14
* Used reasonable length to wrap commit messages
* Moved email content out of the commit message
* Used the "Link" tag instead of "Reference:" and removed empty lines between tags
* Specified the base commit

 rust/Makefile | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/rust/Makefile b/rust/Makefile
index 1f10f92737f2..bb21e74abd87 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -227,7 +227,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
 	-fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
 	-fzero-call-used-regs=% -fno-stack-clash-protection \
 	-fno-inline-functions-called-once -fsanitize=bounds-strict \
-	-fstrict-flex-arrays=% \
+	-fstrict-flex-arrays=% -fmin-function-alignment=% \
 	--param=% --param asan-%
 
 # Derived from `scripts/Makefile.clang`.
@@ -254,6 +254,16 @@ bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-r
 endif
 endif
 
+# Starting from GCC 14, the root Makefile uses -fmin-function-alignment to replace
+# -falign-functions, which libclang doesn't support. We skipped
+# -fmin-function-alignment in bindgen_skip_c_flags, resulting in missing
+# compilation flags. Therefore we add -falign-functions in bindgen_extra_c_flags
+# to fall back and complete the alignment settings.
+# https://lore.kernel.org/linux-kbuild/20240222133500.16991-1-petr.pavlu@suse.com/
+ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT
+bindgen_extra_c_flags += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
+endif
+
 bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
 	$(bindgen_extra_c_flags)
 endif

base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ