Skip to content

Missing implementations of clang-rt atomic builtins #634

@celskeggs

Description

@celskeggs

When compiling C++ code that uses std::atomic on a 8-byte struct with the 19.1.1 toolchain, I get the following errors:

[build] ld.lld: error: undefined symbol: __atomic_is_lock_free
[build] ld.lld: error: undefined symbol: __atomic_load
[build] ld.lld: error: undefined symbol: __atomic_compare_exchange

These symbols seem to be missing from libclang_rt.builtins.a on all targets. (I checked with the 19.1.5 toolchain, since that was the latest.)

$ nm libclang_rt.builtins.a |& grep __atomic | wc -l
0

The likely cause is that COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN is set to On by default in llvm-project/compiler-rt/lib/builtins/CMakeLists.txt, which means that atomic.c is excluded from compilation, resulting in the absence of these symbols.

The reason this option is set to On by default is to avoid misbehavior on platforms that use shared libraries, where multiple definitions of the fallback locks could result in improperly synchronized access to atomic variables.

However, since this toolchain is (as far as I know) only intended for use with static linking, it seems to me that this option could be set to Off safely when building libclang-rt. Does that sound right?

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