Skip to content

Using compiler-builtins with FFI, linking with libc? #345

Closed
@apullin

Description

@apullin

I am having some issues using a rust staticlib that is being called from C via FFI, being built for an embedded target (Cortex M). This issue is sort-of a result of needing this library, not necessarily an error in the code.

To get the linking step to succeed, I have to link the rust staticlib in last. If not, I will get link errors for multiple definitions of memset, where one implementation is providing the unmangled symbol from this compiler-builtins crate.

Linking the rustlib last does resolve that. However, it causes all uses of memset in the C code to be linked to the compiler-builtins implementations.

Even beyond that, using a softfp MCU, even FP multiple like float a=b*c will end up linking the __aebi_fmul to the Rust implementation!

Example of how invoke linking:
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -specs=nano.specs -specs=nosys.specs -TSTM32L072CZEx_FLASH.ld -lnosys -Wl,-Map=target/double.map,--cref -Wl,--gc-sections target/startup_stm32l072xx.o target/stm32l0xx_it.o target/main.o target/thumbv6m-none-eabi/debug/libdouble_input.a -o target/double

(where the name "double" is because I am using the libdouble_input from FFI examples and adding a few other tests: https://github.com/alexcrichton/rust-ffi-examples/tree/master/c-to-rust )

Is this a known limitation?
Is there a workaround to avoid that level of hybridization of the C codes into the rust code, given the overlapping implementations?

As far as I understand the notes in the README, that does not cover this case for the behavior I am trying to get.

I have tried partially linking all the C code first with -lc, and it does pick up the libc implementations of memcpy, float multiply, etc, but then the final linking step fails becasue there are still two memset objects in the output files.

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