Skip to content

Cross-endian linking error when building littlefs2-sys for xtensa-esp32s3-none-elf #105

@anilperi

Description

@anilperi

I am encountering a linker error when building my no_std project for the xtensa-esp32s3-none-elf target using littlefs2. The error indicates a cross-endian linking issue with the littlefs2-sys crate's object files.

The specific error message is:

/Users/anilp/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: cross-endian linking for /var/folders/.../liblittlefs2_sys-...rlib(9276db2ed6ff6dcb-lfs.o) not supported
collect2: error: ld returned 1 exit status

(Similar errors occur for lfs_util.o and string.o from littlefs2_sys.rlib)

Steps Taken & Analysis:

Verified toolchain installation and PATH by running which xtensa-esp32-elf-gcc. The compiler executable was found at /Users/anilp/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.
Attempted build after sourcing the ESP environment script (. $HOME/export-esp.sh). The error persisted.
Attempted build after explicitly setting the CC environment variable to the path of xtensa-esp32-elf-gcc (export CC="...") and running cargo clean. The error still persisted.
Analyzed the verbose build output (cargo build -vv --release --target xtensa-esp32s3-none-elf) with the CC variable set.

Finding from Verbose Output:

The verbose output shows that cc-rs, when compiling the LittleFS C code (lfs.c, lfs_util.c, string.c) within littlefs2-sys, is indeed using the correct compiler (xtensa-esp32-elf-gcc as specified by CC). However, the executed C compilation command lacks explicit endianness flags (like -mlittle-endian) or possibly sufficient architecture flags (-march=, -mabi=) to ensure little-endian compilation for the Xtensa target.

This seems to result in the compiler producing object files with big-endian target data for these generic C files, which are incompatible with the little-endian ESP32-S3 during the final linking step.

Expected Behavior:

The build should complete successfully, linking code compiled for the little-endian xtensa-esp32s3-none-elf target.

Actual Behavior:

The build fails at the linking stage due to a cross-endian mismatch originating from the littlefs2-sys object files.

Environment:

OS: macOS
Target: xtensa-esp32s3-none-elf
Toolchain: esp-14.2.0_20240906 
Rust version: 1.86
littlefs2 version: 0.6.1
littlefs2-sys version: 0.3.1 
cc-rs version: 1.2.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions