Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sosthene-nitrokey opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@sosthene-nitrokey
Copy link
Collaborator

sosthene-nitrokey commented Nov 5, 2024

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
Copy link
Member

robin-nitrokey commented Nov 10, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants