cross icon indicating copy to clipboard operation
cross copied to clipboard

armv5te-unknown-linux-musleabi with OpenSSL fails with undefined reference to `__sync_sub_and_fetch_4'

Open schungx opened this issue 4 years ago • 6 comments

I wonder if this has been fixed? I cannot seem to be able to make an ARMv5TE build OpenSSL without tripping on this error...

Apparently __sync_sub_and_fetch_4 is already supplied by the build target lib, because defining my own version also causes multiple-definition errors. For some reason, the linker just doesn't like to use the library's version.

schungx avatar Jan 27 '20 06:01 schungx

Is this related to your issue? https://github.com/rust-embedded/cross/issues/229

clintfred avatar Mar 23 '20 18:03 clintfred

Nope. I can build a vendored version of OpenSSL just fine with static linking and all. I just cannot resolve the symbol conflicts when I link that OpenSSL lib.

There is a set of atomic intrinics defined in the Rust core lib. But OpenSSL doesn't want to use it and says the functions are not defined. But if I define them myself, it shuts OpenSSL up fine, but then Rust complains that there are conflicting definitions.

schungx avatar Mar 24 '20 01:03 schungx

I have the same problem. It compiles but it fails to link. Is there a solution to the problem?

darxkies avatar Jun 29 '20 14:06 darxkies

I used this to solve the issue as the functions are not defined in the Rust core lib.

#[cfg(target_arch="arm")]
unsafe fn __kernel_cmpxchg_t(old_value: u32, new_value: u32, ptr: *mut u32) -> u32 {
    let __kernel_cmpxchg: extern "C" fn(u32, u32, *mut u32) -> u32 = mem::transmute(0xffff0fc0u32);

    __kernel_cmpxchg(old_value, new_value, ptr)
}

#[cfg(target_arch="arm")]
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub unsafe extern "C" fn __sync_add_and_fetch_4(ptr: *mut u32, value: u32) -> u32 {
    loop {
      let old_value = *ptr;
      let new_value = old_value + value;

      if __kernel_cmpxchg_t(old_value, new_value, ptr) == 0 {
        return new_value;
      }
    };
}

#[cfg(target_arch="arm")]
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub unsafe extern "C" fn __sync_sub_and_fetch_4(ptr: *mut u32, value: u32) -> u32 {
    loop {
      let old_value = *ptr;
      let new_value = old_value - value;

      if __kernel_cmpxchg_t(old_value, new_value, ptr) == 0 {
        return new_value;
      }
    };
}

darxkies avatar Jun 30 '20 13:06 darxkies

Confirmed this is still failing, and due to #485, there's more undefined references to symbols (specifically, the 64-bit time symbols).

Alexhuszagh avatar Jun 02 '22 17:06 Alexhuszagh

This is still failing after the downgrade to musl 1.1.24, however, all the 64-bit time definitions have been fixed, but __sync_add_and_fetch_4 still is not defined, even though the target is supposed to support atomics. Looking through OpenSSL and rust-openssl, there's no internal use of these intrinsics, so this is still a bug, here or upstream.

Alexhuszagh avatar Jul 03 '22 17:07 Alexhuszagh