* [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error
       [not found] <202409160804.eSg9zh1e-lkp@intel.com>
@ 2024-09-16  0:33 ` Gary Guo
  2024-09-19 16:58   ` Christian Schrefl
  2024-09-26 21:18   ` Miguel Ojeda
  0 siblings, 2 replies; 3+ messages in thread
From: Gary Guo @ 2024-09-16  0:33 UTC (permalink / raw)
  To: lkp, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross
  Cc: conor.dooley, linux-kernel, llvm, oe-kbuild-all, palmer,
	rust-for-linux
We use const helpers in form of
    const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
to aid generation of constants by bindgen because it is otherwise a
macro definition of an expression and bindgen doesn't expand the
constant. The helpers are then have `RUST_CONST_HELPER` prefix stripped
and exposed to Rust code as if `ARCH_SLAB_MISALIGN` is generated
natively by bindgen.
This works well for most constants, but on RISC-V, `ARCH_SLAB_MINALIGN`
is defined directly as literal constant if `!CONFIG_MMU`, and bindgen
would generate `ARCH_SLAB_MINALIGN` directly, thus conflict with the
one generated through the helper.
To fix this, we simply need to block bindgen from generating directly
without going through helper.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202409160804.eSg9zh1e-lkp@intel.com/
Signed-off-by: Gary Guo <gary@garyguo.net>
---
 rust/bindgen_parameters | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters
index a721d466bee4b..b7c7483123b7a 100644
--- a/rust/bindgen_parameters
+++ b/rust/bindgen_parameters
@@ -24,3 +24,8 @@
 # These functions use the `__preserve_most` calling convention, which neither bindgen
 # nor Rust currently understand, and which Clang currently declares to be unstable.
 --blocklist-function __list_.*_report
+
+# These constants are sometimes not recognized by bindgen depending on config.
+# We use const helpers to aid bindgen, to avoid conflicts when constants are
+# recognized, block generation of the non-helper constants.
+--blocklist-item ARCH_SLAB_MINALIGN
base-commit: d077242d68a31075ef5f5da041bf8f6fc19aa231
-- 
2.44.1
^ permalink raw reply related	[flat|nested] 3+ messages in thread
* Re: [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error
  2024-09-16  0:33 ` [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error Gary Guo
@ 2024-09-19 16:58   ` Christian Schrefl
  2024-09-26 21:18   ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Schrefl @ 2024-09-19 16:58 UTC (permalink / raw)
  To: Gary Guo, lkp, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross
  Cc: conor.dooley, linux-kernel, llvm, oe-kbuild-all, palmer,
	rust-for-linux
On 16.09.24 2:33 AM, Gary Guo wrote:
> We use const helpers in form of
> 
>     const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
> 
> to aid generation of constants by bindgen because it is otherwise a
> macro definition of an expression and bindgen doesn't expand the
> constant. The helpers are then have `RUST_CONST_HELPER` prefix stripped
> and exposed to Rust code as if `ARCH_SLAB_MISALIGN` is generated
> natively by bindgen.
> 
> This works well for most constants, but on RISC-V, `ARCH_SLAB_MINALIGN`
> is defined directly as literal constant if `!CONFIG_MMU`, and bindgen
> would generate `ARCH_SLAB_MINALIGN` directly, thus conflict with the
> one generated through the helper.
> 
> To fix this, we simply need to block bindgen from generating directly
> without going through helper.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202409160804.eSg9zh1e-lkp@intel.com/
> Signed-off-by: Gary Guo <gary@garyguo.net>
> ---
>  rust/bindgen_parameters | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters
> index a721d466bee4b..b7c7483123b7a 100644
> --- a/rust/bindgen_parameters
> +++ b/rust/bindgen_parameters
> @@ -24,3 +24,8 @@
>  # These functions use the `__preserve_most` calling convention, which neither bindgen
>  # nor Rust currently understand, and which Clang currently declares to be unstable.
>  --blocklist-function __list_.*_report
> +
> +# These constants are sometimes not recognized by bindgen depending on config.
> +# We use const helpers to aid bindgen, to avoid conflicts when constants are
> +# recognized, block generation of the non-helper constants.
> +--blocklist-item ARCH_SLAB_MINALIGN
> 
> base-commit: d077242d68a31075ef5f5da041bf8f6fc19aa231
This is also needed for 32-bit ARM support.
Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error
  2024-09-16  0:33 ` [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error Gary Guo
  2024-09-19 16:58   ` Christian Schrefl
@ 2024-09-26 21:18   ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2024-09-26 21:18 UTC (permalink / raw)
  To: Gary Guo
  Cc: lkp, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, conor.dooley, linux-kernel, llvm, oe-kbuild-all,
	palmer, rust-for-linux
On Mon, Sep 16, 2024 at 1:09 PM Gary Guo <gary@garyguo.net> wrote:
>
> We use const helpers in form of
>
>     const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
>
> to aid generation of constants by bindgen because it is otherwise a
> macro definition of an expression and bindgen doesn't expand the
> constant. The helpers are then have `RUST_CONST_HELPER` prefix stripped
> and exposed to Rust code as if `ARCH_SLAB_MISALIGN` is generated
> natively by bindgen.
>
> This works well for most constants, but on RISC-V, `ARCH_SLAB_MINALIGN`
> is defined directly as literal constant if `!CONFIG_MMU`, and bindgen
> would generate `ARCH_SLAB_MINALIGN` directly, thus conflict with the
> one generated through the helper.
>
> To fix this, we simply need to block bindgen from generating directly
> without going through helper.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202409160804.eSg9zh1e-lkp@intel.com/
> Signed-off-by: Gary Guo <gary@garyguo.net>
Applied to `rust-fixes` -- thanks!
Cheers,
Miguel
^ permalink raw reply	[flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-26 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <202409160804.eSg9zh1e-lkp@intel.com>
2024-09-16  0:33 ` [PATCH] rust: fix `ARCH_SLAB_MINALIGN` multiple definition error Gary Guo
2024-09-19 16:58   ` Christian Schrefl
2024-09-26 21:18   ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).