1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# is_rust_module.sh module.ko
5#
6# Returns `0` if `module.ko` is a Rust module, `1` otherwise.
7
8set -e
9
10# Using the `16_` prefix ensures other symbols with the same substring
11# are not picked up (even if it would be unlikely). The last part is
12# used just in case LLVM decides to use the `.` suffix.
13#
14# In the future, checking for the `.comment` section may be another
15# option, see https://github.com/rust-lang/rust/pull/97550.
16${NM} "$*" | grep -qE '^[0-9a-fA-F]+ r _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$'
17