rust: fix regexp in scripts/is_rust_module.sh

Message ID 20230210152622.92912-1-andrea.righi@canonical.com
State New
Headers
Series rust: fix regexp in scripts/is_rust_module.sh |

Commit Message

Andrea Righi Feb. 10, 2023, 3:26 p.m. UTC
  nm can use "R" or "r" to show read-only data sections, but
scripts/is_rust_module.sh can only recognize "r", so with some versions
of binutils it can fail to detect if a module is a Rust module or not.

Right now we're using this script only to determine if we need to skip
BTF generation (that is disabled globally if CONFIG_RUST is enabled),
but it's still nice to fix this script to do the proper job.

Moreover, with this patch applied I can also relax the constraint of
"RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF
enabled at the same time (of course BTF generation is still skipped for
Rust modules).

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---
 scripts/is_rust_module.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Vincenzo Palazzo Feb. 11, 2023, 9:25 a.m. UTC | #1
> nm can use "R" or "r" to show read-only data sections, but
> scripts/is_rust_module.sh can only recognize "r", so with some versions
> of binutils it can fail to detect if a module is a Rust module or not.
>
> Right now we're using this script only to determine if we need to skip
> BTF generation (that is disabled globally if CONFIG_RUST is enabled),
> but it's still nice to fix this script to do the proper job.
>
> Moreover, with this patch applied I can also relax the constraint of
> "RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF
> enabled at the same time (of course BTF generation is still skipped for
> Rust modules).
>
> Signed-off-by: Andrea Righi <andrea.righi@canonical.com>

Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  
Miguel Ojeda Feb. 13, 2023, 1:19 p.m. UTC | #2
On Fri, Feb 10, 2023 at 4:26 PM Andrea Righi <andrea.righi@canonical.com> wrote:
>
> nm can use "R" or "r" to show read-only data sections, but
> scripts/is_rust_module.sh can only recognize "r", so with some versions
> of binutils it can fail to detect if a module is a Rust module or not.

Do you know which versions? If so, it would be nice to document it here.

> Moreover, with this patch applied I can also relax the constraint of
> "RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF
> enabled at the same time (of course BTF generation is still skipped for
> Rust modules).

Even if that build succeeds, can you load the modules? i.e. the
constraint was there due to
https://github.com/Rust-for-Linux/linux/issues/735.

Also Cc'ing Daniel, Eric and Martin since they are the ones working on this.

Cheers,
Miguel
  
Eric Curtin Feb. 13, 2023, 2:27 p.m. UTC | #3
On Mon, 13 Feb 2023 at 13:19, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Fri, Feb 10, 2023 at 4:26 PM Andrea Righi <andrea.righi@canonical.com> wrote:
> >
> > nm can use "R" or "r" to show read-only data sections, but
> > scripts/is_rust_module.sh can only recognize "r", so with some versions
> > of binutils it can fail to detect if a module is a Rust module or not.
>
> Do you know which versions? If so, it would be nice to document it here.
>
> > Moreover, with this patch applied I can also relax the constraint of
> > "RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF
> > enabled at the same time (of course BTF generation is still skipped for
> > Rust modules).
>
> Even if that build succeeds, can you load the modules? i.e. the
> constraint was there due to
> https://github.com/Rust-for-Linux/linux/issues/735.
>
> Also Cc'ing Daniel, Eric and Martin since they are the ones working on this.

Don't have any issues with the change. Seems simple enough!

Reviewed-by: Eric Curtin <ecurtin@redhat.com>

>
> Cheers,
> Miguel
>
  
Martin Rodriguez Reboredo Feb. 13, 2023, 2:56 p.m. UTC | #4
On Fri, Feb 10, 2023 at 4:26 PM Andrea Righi <andrea.righi@canonical.com> wrote:
> nm can use "R" or "r" to show read-only data sections, but
> scripts/is_rust_module.sh can only recognize "r", so with some versions
> of binutils it can fail to detect if a module is a Rust module or not.

As __IS_RUST_MODULE can be a dynamic symbol too this change seems
reasonable to merge.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
  
Andrea Righi Feb. 13, 2023, 3:01 p.m. UTC | #5
On Mon, Feb 13, 2023 at 02:19:38PM +0100, Miguel Ojeda wrote:
> On Fri, Feb 10, 2023 at 4:26 PM Andrea Righi <andrea.righi@canonical.com> wrote:
> >
> > nm can use "R" or "r" to show read-only data sections, but
> > scripts/is_rust_module.sh can only recognize "r", so with some versions
> > of binutils it can fail to detect if a module is a Rust module or not.
> 
> Do you know which versions? If so, it would be nice to document it here.
> 
> > Moreover, with this patch applied I can also relax the constraint of
> > "RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF
> > enabled at the same time (of course BTF generation is still skipped for
> > Rust modules).
> 
> Even if that build succeeds, can you load the modules? i.e. the
> constraint was there due to
> https://github.com/Rust-for-Linux/linux/issues/735.

This patch simply fixes scripts/is_rust_module.sh to recognize Rust
modules from "regular" C modules with certain versions of binutils, so
that BTF generation is properly skipped for Rust modules.

In this way both C and Rust modules can be loaded correctly (at least in
my tests I'm able load both with CONFIG_DEBUG_INFO_BTF enabled).

I haven't dropped the "RUST depends on !DEBUG_INFO_BTF" yet, but I think
with this fix is applied we can relax this constraint.

-Andrea

> 
> Also Cc'ing Daniel, Eric and Martin since they are the ones working on this.
> 
> Cheers,
> Miguel
  
Miguel Ojeda Feb. 13, 2023, 3:45 p.m. UTC | #6
On Mon, Feb 13, 2023 at 4:01 PM Andrea Righi <andrea.righi@canonical.com> wrote:
>
> In this way both C and Rust modules can be loaded correctly (at least in
> my tests I'm able load both with CONFIG_DEBUG_INFO_BTF enabled).
>
> I haven't dropped the "RUST depends on !DEBUG_INFO_BTF" yet, but I think
> with this fix is applied we can relax this constraint.

Yeah, but the constraint was there for other reasons, so I got
surprised when I read that in the commit message.

Apparently, Martin cannot load the modules
(https://lore.kernel.org/rust-for-linux/20230213151339.661225-1-yakoyoku@gmail.com/),
but you can.

Cheers,
Miguel
  
Miguel Ojeda April 6, 2023, 10:56 p.m. UTC | #7
On Fri, Feb 10, 2023 at 4:26 PM Andrea Righi <andrea.righi@canonical.com> wrote:
>
> nm can use "R" or "r" to show read-only data sections, but
> scripts/is_rust_module.sh can only recognize "r", so with some versions
> of binutils it can fail to detect if a module is a Rust module or not.

Applied to `rust-fixes`. Thanks!

Cheers,
Miguel
  

Patch

diff --git a/scripts/is_rust_module.sh b/scripts/is_rust_module.sh
index 28b3831a7593..464761a7cf7f 100755
--- a/scripts/is_rust_module.sh
+++ b/scripts/is_rust_module.sh
@@ -13,4 +13,4 @@  set -e
 #
 # In the future, checking for the `.comment` section may be another
 # option, see https://github.com/rust-lang/rust/pull/97550.
-${NM} "$*" | grep -qE '^[0-9a-fA-F]+ r _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$'
+${NM} "$*" | grep -qE '^[0-9a-fA-F]+ [Rr] _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$'