Skip to content

dependency('atomic') can return false results on Fedora #14946

@meator

Description

@meator

Describe the bug
dependency('atomic') is marked as found even though the /usr/lib64/libatomic.so.1.2.0 library doesn't exist.

This is most likely caused by my build environment missing the appropriate package (I think it's libatomic or something, I'm not a Fedora guy). But that is no excuse for dependency('atomic') to return a found dependency.

Relevant error messages
(These come from the Dockerfile below)

Run-time dependency atomic found: YES
Checking if "Check if libatomic is required" with dependency atomic links: NO

meson.build:35:2: ERROR: Problem encountered: Host machine cannot handle atomics!
Command line: `c++ /build/meson-private/tmpe47p63sa/testfile.cpp -o /build/meson-private/tmpe47p63sa/output.obj -c -D_FILE_OFFSET_BITS=64 -O0 -fpermissive --print-search-dirs` -> 0
stdout:
install: /usr/lib/gcc/x86_64-redhat-linux/15/
programs: =/usr/libexec/gcc/x86_64-redhat-linux/15/:/usr/libexec/gcc/x86_64-redhat-linux/15/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/15/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../x86_64-redhat-linux/bin/x86_64-redhat-linux/15/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../x86_64-redhat-linux/bin/
libraries: =/usr/lib/gcc/x86_64-redhat-linux/15/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../x86_64-redhat-linux/lib/x86_64-redhat-linux/15/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../x86_64-redhat-linux/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../x86_64-redhat-linux/15/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/:/lib/x86_64-redhat-linux/15/:/lib/../lib64/:/usr/lib/x86_64-redhat-linux/15/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../../x86_64-redhat-linux/lib/:/usr/lib/gcc/x86_64-redhat-linux/15/../../../:/lib/:/usr/lib/
-----------
Run-time dependency atomic found: YES
Running compile:
Working directory:  /build/meson-private/tmpdd0hyh67
Code:

#include <atomic>
#include <cstdint>
int main() {
    volatile std::atomic<std::uint64_t> testvar;
    // The line below will lead to
    // undefined reference to `__atomic_fetch_add_8'
    // on armv6l to give an example.
    volatile auto unused = testvar.fetch_add(0);
}

-----------
Command line: `c++ /build/meson-private/tmpdd0hyh67/testfile.cpp -o /build/meson-private/tmpdd0hyh67/output.exe -D_FILE_OFFSET_BITS=64 -O0 -fpermissive /usr/lib/gcc/x86_64-redhat-linux/15/libatomic.so` -> 1
stderr:
/usr/sbin/ld: cannot find /usr/lib64/libatomic.so.1.2.0: No such file or directory
collect2: error: ld returned 1 exit status
-----------
Checking if "Check if libatomic is required" with dependency atomic links: NO

meson.build:35:2: ERROR: Problem encountered: Host machine cannot handle atomics!

To Reproduce

FROM fedora:42
RUN <<EOF
set -eu
dnf install -y gcc gcc-g++ meson
cat > meson.build <<"END"
project(
  'repro',
  'c', 'cpp',
)

if meson.version().version_compare('>=1.7.0')
  atomic_dep = dependency(
    'atomic',
    required: false,
  )
else
  atomic_dep = meson.get_compiler('cpp').find_library(
    'atomic',
    required: false,
  )
endif

# Make reasonable effort (volatile) to prevent the compiler from optimizing the atomic away without using tested
# functionality.
if not meson.get_compiler('cpp').links(
  '''
#include <atomic>
#include <cstdint>
int main() {
    volatile std::atomic<std::uint64_t> testvar;
    // The line below will lead to
    // undefined reference to `__atomic_fetch_add_8'
    // on armv6l to give an example.
    volatile auto unused = testvar.fetch_add(0);
}
  ''',
  name: 'Check if libatomic is required',
  dependencies: atomic_dep,
)
  error('Host machine cannot handle atomics!')
endif
END
if ! meson setup build; then
  cat build/meson-logs/meson-log.txt >&2
  exit 1
fi
EOF

Expected behavior
The dependency should fail to resolve (in the sample code above it's set as required: false, so it should resolve to a not-found dependency).

system parameters

  • native build
  • Fedora latest and rawhide (42, 43)
  • I think Meson is using Python version 3.13.7, but I don't think that's hugely relevant here.
  • tested Meson versions 1.7.2 (from Fedora package used above) and 0f5cd5f (current HEAD)
  • Ninja 1.12.1

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