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

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

Closed
schungx opened this issue Jan 27, 2020 · 6 comments · Fixed by #987
Labels
A-musl Area: musl libc targets bug upstream

Comments

@schungx
Copy link

schungx commented Jan 27, 2020

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.

@clintfred
Copy link

Is this related to your issue? #229

@schungx
Copy link
Author

schungx commented Mar 24, 2020

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.

@darxkies
Copy link

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

@darxkies
Copy link

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;
      }
    };
}

@Alexhuszagh
Copy link
Contributor

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

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jul 3, 2022

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.

bors bot added a commit that referenced this issue Aug 10, 2022
987: Link to libgcc for `armv5te-unknown-linux-musleabi` target. r=Emilgardis a=Alexhuszagh

Fixes missing sync builtins required for libraries such as OpenSSL, specifically, the `__sync_X_and_fetch` builtins.

Closes #367.
Improves documentation related to #906.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@bors bors bot closed this as completed in a93c2b7 Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-musl Area: musl libc targets bug upstream
Projects
None yet
4 participants