lizhuohua / linux-kernel-module-rust

GNU General Public License v2.0
634 stars 27 forks source link

Bindgen fails on Arch Linux 5.2.8-arch1-1-ARCH #1

Open kbleeke opened 5 years ago

kbleeke commented 5 years ago

Hi, I just saw this on reddit and want to try. But bindgen seems to fail on my machine running Arch Linux with kernel version 5.2.8-arch1-1-ARCH

I have no experience in kernel development, so I'm not sure what the issue is here. The errors seems to come from clang:

Full output:

 ~/git/linux-kernel-module-rust/hello_world   master  RUST_TARGET_PATH=$(pwd)/.. cargo xbuild --target x86_64-linux-kernel-module
    Updating crates.io index
   Compiling core v0.0.0 (/home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
   Compiling compiler_builtins v0.1.19
   Compiling rustc-std-workspace-core v1.0.0 (/home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/tools/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/tmp/xargo.S1rXilz6pftT)
    Finished release [optimized] target(s) in 16.28s
   Compiling memchr v2.2.1
   Compiling libc v0.2.62
   Compiling version_check v0.1.5
   Compiling cc v1.0.40
   Compiling log v0.4.8
   Compiling bitflags v1.1.0
   Compiling lazy_static v1.3.0
   Compiling glob v0.2.11
   Compiling regex-syntax v0.6.11
   Compiling quick-error v1.2.2
   Compiling cfg-if v0.1.9
   Compiling unicode-width v0.1.5
   Compiling unicode-xid v0.1.0
   Compiling strsim v0.8.0
   Compiling bindgen v0.43.2
   Compiling ansi_term v0.11.0
   Compiling termcolor v1.0.5
   Compiling vec_map v0.8.1
   Compiling peeking_take_while v0.1.2
   Compiling shlex v0.1.1
   Compiling humantime v1.2.0
   Compiling thread_local v0.3.6
   Compiling textwrap v0.11.0
   Compiling proc-macro2 v0.3.5
   Compiling nom v4.2.3
   Compiling clang-sys v0.26.4
   Compiling quote v0.5.2
   Compiling aho-corasick v0.7.6
   Compiling libloading v0.5.2
   Compiling atty v0.2.13
   Compiling which v1.0.5
   Compiling clap v2.33.0
   Compiling cexpr v0.3.5
   Compiling regex v1.2.1
   Compiling env_logger v0.6.2
   Compiling linux-device-driver v0.1.0 (/home/kai/git/linux-kernel-module-rust)
error: failed to run custom build command for `linux-device-driver v0.1.0 (/home/kai/git/linux-kernel-module-rust)`

Caused by:
  process didn't exit successfully: `/home/kai/git/linux-kernel-module-rust/hello_world/target/debug/build/linux-device-driver-fd96a7e17f92603d/build-script-build` (exit code: 101)
--- stdout
Target=x86_64-linux-kernel-module
get output:-nostdinc -isystem /usr/lib/clang/8.0.1/include -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/generated -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/uapi -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/generated/uapi -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/uapi -I/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/generated/uapi -include /usr/lib/modules/5.2.8-arch1-1-ARCH/build/include/linux/kconfig.h -DMODULE

cargo:rerun-if-changed=src/bindgen_helper.h

--- stderr
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:128:2: warning: implicit declaration of function 'barrier' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:209:9: error: 'asm goto' constructs are not supported yet
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:255:9: error: 'asm goto' constructs are not supported yet
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:308:9: error: 'asm goto' constructs are not supported yet
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:47:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:53:26: warning: implicit declaration of function 'hweight32' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:53:41: warning: implicit declaration of function 'hweight64' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:163:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:164:9: warning: implicit declaration of function 'fls64' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:171:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:24:9: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:32:9: warning: implicit declaration of function 'fls64' is invalid in C99 [-Wimplicit-function-declaration]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:197:15: error: unknown type name '__attribute_const__'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:198:1: error: expected identifier or '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:13: error: expected parameter declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:13: error: expected ')'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:13: note: to match this '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:24: error: expected function body after function declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected parameter declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected ')'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: note: to match this '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected function body after function declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:28: error: expected parameter declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:28: error: expected ')'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:27: note: to match this '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:19: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:33: error: expected ';' after top level declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:21: error: expected parameter declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:21: error: expected ')'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:20: note: to match this '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:12: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:26: error: expected ';' after top level declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:21: error: expected parameter declarator
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:21: error: expected ')'
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:20: note: to match this '('
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:12: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
fatal error: too many errors emitted, stopping now [-ferror-limit=]
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:128:2: warning: implicit declaration of function 'barrier' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:209:9: error: 'asm goto' constructs are not supported yet, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:255:9: error: 'asm goto' constructs are not supported yet, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./arch/x86/include/asm/bitops.h:308:9: error: 'asm goto' constructs are not supported yet, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:47:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:53:26: warning: implicit declaration of function 'hweight32' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:53:41: warning: implicit declaration of function 'hweight64' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:163:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:164:9: warning: implicit declaration of function 'fls64' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/bitops.h:171:10: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:24:9: warning: implicit declaration of function 'fls' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:32:9: warning: implicit declaration of function 'fls64' is invalid in C99 [-Wimplicit-function-declaration], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:197:15: error: unknown type name '__attribute_const__', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/log2.h:198:1: error: expected identifier or '(', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:13: error: expected parameter declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:13: error: expected ')', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:142:24: error: expected function body after function declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected parameter declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected ')', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/init.h:149:5: error: expected function body after function declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:28: error: expected parameter declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:28: error: expected ')', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:19: warning: type specifier missing, defaults to 'int' [-Wimplicit-int], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:142:33: error: expected ';' after top level declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:21: error: expected parameter declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:21: error: expected ')', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:12: warning: type specifier missing, defaults to 'int' [-Wimplicit-int], err: false
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:162:26: error: expected ';' after top level declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:21: error: expected parameter declarator, err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:21: error: expected ')', err: true
/usr/lib/modules/5.2.8-arch1-1-ARCH/build/./include/linux/printk.h:167:12: warning: type specifier missing, defaults to 'int' [-Wimplicit-int], err: false
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'Unable to generate bindings: ()', src/libcore/result.rs:1084:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
$clang --version                         
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
mssun commented 5 years ago

Hi, @pluth, thanks for your report. @lizhuohua and I will look into this issue and get back to you later. Thanks.

geofft commented 5 years ago

This looks like kernel-cflags-finder (which is from our upstream project - see https://github.com/fishinabarrel/linux-kernel-module-rust/tree/master/kernel-cflags-finder which has a README) isn't returning quite the right thing on Arch. I've only tested it on Debian and Ubuntu so that's not totally surprising. (And fundamentally kernel-cflags-finder is a huge hack, there's no direct way to extract the kernel's CFLAGS for use in bindgen, so we scrape it out of a Makefile's output :) ) Can you directly run make -s inside that directory and see what it outputs?

In particular on my Debian box I also get various defines like -D__KERNEL__. I'm surprised to just see -DMODULE, and I think most of the missing things are guarded by #ifdef __KERNEL__.

geofft commented 5 years ago

Actually I can repro this with the Debian 5.2 kernel, so it's not an Arch packaging thing.

lizhuohua commented 5 years ago

It seems like clang doesn't support asm goto, which is required for kernel compilation since 4.17.

Some references: https://www.spinics.net/lists/netdev/msg544057.html http://clang-developers.42468.n3.nabble.com/Building-linux-kernel-with-clang-td4064258.html#a4064259

geofft commented 5 years ago

Yeah, this is complicated. 4.19 works fine (it's what I'm using at the moment), but torvalds/linux@e9666d10a5677a494260d60d1fa0b73cc7646eb3 in 5.0 changed the asm goto check from a build-time check to a config-time check. Therefore if your kernel was configured with gcc, the build system tries to use asm gotos for modules, even if you're compiling the modules with clang. Before that, it would correctly detect CC=clang at build time and skip it. I don't see a way to override the config option from inside a module.

(Also since torvalds/linux@cdd750bfb1f76fe9be8cfb53cbe77b2e811081ab in v5.2 you need to change __c_flags in kernel-cflags-helper/Makefile to _c_flags. We should probably auto-detect that.)

geofft commented 5 years ago

Oh, the code review in your second link https://reviews.llvm.org/D56571 looks like it was closed in June 3, so maybe a very recent version of clang works?

geofft commented 5 years ago

Yes, this works for me on Debian with the LLVM 9 snapshot from https://apt.llvm.org .

@pluth - can you try

  1. install LLVM 9 and Clang 9, or higher (not sure what the preferred way to do this on Arch is, maybe llvm-git from AUR?)
  2. edit kernel-cflags-finder/Makefile to change __c_flags (two underscores) to _c_flags
  3. if necessary (i.e., if Arch lets you install Clang 8 and 9 side by side), export CLANG=clang-9 so that bindgen and kbuild both pick up the right version and see if that works?
geofft commented 5 years ago

I made this change to kernel-cflags-finder to make it 5.2 compatible: fishinabarrel/linux-kernel-module-rust@f7f85515 This project should probably pick up the same change.

Also I have some robustness changes for kernel-cflags-finder in fishinabarrel/linux-kernel-module-rust@985985c7 that are worth picking up too.

kbleeke commented 5 years ago

I installed clang-10 from llvm-minimal-git (difference to llvm-git as far as i can tell is that it's not building lldb, lld and polly). Now its failing with a different error:


error: failed to run custom build command for `linux-kernel-module v0.1.0 (/home/kai/git/linux-kernel-module-rust)`

Caused by:
  process didn't exit successfully: `/home/kai/git/linux-kernel-module-rust/hello_world/target/debug/build/linux-kernel-module-c89bbfe05213a2b2/build-script-build` (exit code: 101)
--- stdout
Target=x86_64-linux-kernel-module
get output:-nostdinc -isystem /usr/lib/clang/10.0.0/include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/generated -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/generated/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include/generated/uapi -include /usr/lib/modules/5.2.9-arch1-1-ARCH/build/include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -no-integrated-as -Werror=unknown-warning-option -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mstack-alignment=8 -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -fno-jump-tables -fno-delete-null-pointer-checks -Wno-address-of-packed-member -O2 -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -pg -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -DMODULE

cargo:rerun-if-changed=src/bindgen_helper.h

--- stderr
error: unknown argument: '-fplugin-arg-structleak_plugin-byref-all'
error: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include/linux/printk.h:192:68: warning: unknown attribute 'user' ignored [-Wunknown-attributes]

Full output is here. Its quite long since it contains about 600 more unknown attribute 'user' warnings.

There don't seem to be any pre-built packages for Arch, so compiling from git seems to be the best I can do. Anyways, as I understand llvm 9 is supposed to be release next week so I guess I'll just wait for that.

geofft commented 5 years ago

Did you edit kernel-cflags-finder/Makefile to change __c_flags to _c_flags? It looks like it's still not picking up some required CFLAGS.

kbleeke commented 5 years ago

Yes, I did.

$(M)/dummy.c:
    @echo $(NOSTDINC_FLAGS) $(call our_flags,LINUXINCLUDE) $(_c_flags) $(modkern_cflags)
    @touch $@

You meant this, right?

geofft commented 5 years ago

Yes. Hm, also try running touch build.rs to force it to rerun kernel-cflags-finder?

kbleeke commented 5 years ago

Doesn't change anything. Also, running the kernel-cflag-finder directly produces the same error (or one of them):

make CC=clang HOSTCC=clang  -C /lib/modules/5.2.9-arch1-1-ARCH/build M=/home/kai/git/linux-kernel-module-rust/kernel-cflags-finder
make[1]: Entering directory '/usr/lib/modules/5.2.9-arch1-1-ARCH/build'
-nostdinc -isystem /usr/lib/clang/10.0.0/include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/generated -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./arch/x86/include/generated/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include/uapi -I/usr/lib/modules/5.2.9-arch1-1-ARCH/build/./include/generated/uapi -include /usr/lib/modules/5.2.9-arch1-1-ARCH/build/include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -no-integrated-as -Werror=unknown-warning-option -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mstack-alignment=8 -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -fno-jump-tables -fno-delete-null-pointer-checks -Wno-address-of-packed-member -O2 -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -pg -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -DMODULE
  CC [M]  /home/kai/git/linux-kernel-module-rust/kernel-cflags-finder/dummy.o
clang-10: error: unknown argument: '-fplugin-arg-structleak_plugin-byref-all'
make[2]: *** [scripts/Makefile.build:285: /home/kai/git/linux-kernel-module-rust/kernel-cflags-finder/dummy.o] Error 1
make[1]: *** [Makefile:1597: _module_/home/kai/git/linux-kernel-module-rust/kernel-cflags-finder] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.2.9-arch1-1-ARCH/build'
make: *** [Makefile:56: all] Error 2
kbleeke commented 5 years ago

There is some commented out code in build.rs that removes options. If I do that for the two unknown options to that, then cargo runs successfully

geofft commented 4 years ago

We've since fixed this in https://github.com/fishinabarrel/linux-kernel-module-rust (which is where kernel-cflags-finder comes from) - we've removed kernel-cflags-finder and set up Kbuild to call cargo and pass the appropriate flags. Importantly, it picks up the flags as if CC is clang so we no longer need to do the trick with ignoring unknown options.