Nitrokey / nitrokey-3-firmware

Nitrokey 3 firmware
Apache License 2.0
250 stars 26 forks source link

Investigate if CI builds are done with `clang` rather than `gcc` #557

Open sosthene-nitrokey opened 4 weeks ago

sosthene-nitrokey commented 4 weeks ago

On my machine, the cc crate used to compile littlefs uses gcc by default, but we would probably benefit from using clang instead, as it would allow us to reduce the need for multiple toolchains, and also it might allow cross-language LTO, meaning more inlining/optimizations.

When changing littlefs2-sys's build system to use clang instead it fails to find the definitions for the C standard functions it relies upon (while gcc bundles them with the custom compiler toolchain).

robin-nitrokey commented 3 weeks ago

The CC environment variable is not set to in the CI docker container, so the cc crate should default to the cc binary AFAIS which is gcc in the container.

https://github.com/rust-lang/cc-rs/blob/5835783f0e3a02cc343ed02e272b54988ee8a423/src/lib.rs#L2625

I tried to build the firmware with CC=clang but ran into some linker errors – requires some more investigation.

``` = note: rust-lld: error: undefined symbol: __stack_chk_fail >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(P256_mod_n_inv) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(p256_verify) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(p256_sign_step1) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced 40 more times rust-lld: error: undefined symbol: __stack_chk_guard >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(P256_mod_n_inv) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(P256_mod_n_inv) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced by p256-cortex-m4.c:0 (/home/robin/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/p256-cortex-m4-sys-0.1.0/P256-Cortex-M4/p256-cortex-m4.c:0) >>> d339f994e07e7ee9-p256-cortex-m4.o:(p256_verify) in archive /tmp/rustcnCovjb/libp256_cortex_m4_sys-f6743727ec458918.rlib >>> referenced 85 more times rust-lld: error: no memory region specified for section '.got' rust-lld: error: ERROR(cortex-m-rt): .got section detected in the input object files Dynamic relocations are not supported. If you are linking to C code compiled using the 'cc' crate then modify your build script to compile the C code _without_ the -fPIC flag. See the documentation of the `cc::Build.pic` method for details. rust-lld: error: ERROR(cortex-m-rt): .got section detected in the input object files Dynamic relocations are not supported. If you are linking to C code compiled using the 'cc' crate then modify your build script to compile the C code _without_ the -fPIC flag. See the documentation of the `cc::Build.pic` method for details. rust-lld: error: ERROR(cortex-m-rt): .got section detected in the input object files Dynamic relocations are not supported. If you are linking to C code compiled using the 'cc' crate then modify your build script to compile the C code _without_ the -fPIC flag. See the documentation of the `cc::Build.pic` method for details. rust-lld: warning: address (0x72674) of section .rodata is not a multiple of alignment (8) ```