zig icon indicating copy to clipboard operation
zig copied to clipboard

Failure to use atomics with arm-linux-musleabi target

Open link2xt opened this issue 1 year ago • 1 comments

Zig Version

0.11.0-dev.1928+3169f0529

Steps to Reproduce and Observed Behavior

Create file atom.c:

#include <stdatomic.h>

int main() {
        _Atomic int val;
        atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);
        return 0;
}

Run

$ zig cc atom.c -target arm-linux-musleabi

This results in an error

LLD Link... ld.lld: error: undefined symbol: __atomic_fetch_add_4

I also tried to use -target thumb-linux-musleabi, but it resulted in segmentation fault even without atomics and I filed another bugreport #14891.

Same with Zig 0.10.1.

The problem actually occurs when attempting to compile OpenSSL: https://github.com/openssl/openssl/issues/20490

Expected Behavior

Atomic operations from https://github.com/ziglang/zig/blob/master/lib/compiler_rt/atomics.zig should be available on 32-bit ARM.

link2xt avatar Mar 12 '23 00:03 link2xt

Note: building with zig cc atom.c -target arm-linux-musleabihf works, no idea why. Using it here for now: https://github.com/deltachat/deltachat-core-rust/pull/4155 But it is not obvious how and why "hf" (hard float) affects atomics.

link2xt avatar Mar 13 '23 17:03 link2xt