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

meson: always use libatomic if found #25069

Merged
merged 1 commit into from
Oct 21, 2022
Merged

Conversation

keszybz
Copy link
Member

@keszybz keszybz commented Oct 19, 2022

Semi-quoting #25057:

clang-16 has made the choice to turn on -Werror=implicit-function-declaration,implicit-int. (See Gentoo's tracker bug https://bugs.gentoo.org/870412). Added in commit 132c73b, systemd now does a check to see if libatomic is needed with some compile/link tests with e.g. __atomic_exchange_1, but the tests don't provide a prototype for __atomic_exchange_1 so with clang-16 the test fails, breaking the build.

Add -Wno-implicit-function-declaration (which is supported by both gcc and clang) to should get rid of the warning or error.
(I don't have clang-16 at hand, but with clang-15.0.0-2.fc37.x86_64 the warnings are gone and the link fails, and then when -latomic is added, succeeds.)

Fixes #25057.

@bluca bluca added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed meson labels Oct 19, 2022
@medhefgo
Copy link
Contributor

As suggested in #25057: maybe just drop this test and simply always link against it and rely on --as-needed from meson? Seems so much nicer.

@thesamesam
Copy link
Contributor

As suggested in #25057: maybe just drop this test and simply always link against it and rely on --as-needed from meson? Seems so much nicer.

Let's do that instead, please. It's a good option, especially given my latest comment over there. But note that -latomic may not always exist.

@keszybz keszybz removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Oct 20, 2022
@keszybz
Copy link
Member Author

keszybz commented Oct 20, 2022

Updated.

meson.build Outdated Show resolved Hide resolved
@medhefgo medhefgo changed the title meson: add -Wno-implicit-function-declaration to silence clang meson: always use libatomic if found Oct 20, 2022
@bluca

This comment was marked as resolved.

@bluca bluca added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Oct 20, 2022
@keszybz keszybz removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Oct 20, 2022
@keszybz
Copy link
Member Author

keszybz commented Oct 20, 2022

Pfff, no nice approach works. After trying a few different approaches, a manual check seems to be the most reliable.

meson.build Outdated
threads = dependency('threads')
librt = cc.find_library('rt')
libm = cc.find_library('m')
libdl = cc.find_library('dl')
libcrypt = cc.find_library('crypt')

# On some architectures, libatomic is required. But on some installations,
# it is found, but actual linking fails. So let's try to use it opportunstically.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/opportunstically/opportunistically/

@Arfrever
Copy link

[1123/2080] Linking target systemd-oomd
FAILED: systemd-oomd 
cc  -o systemd-oomd systemd-oomd.p/src_oom_oomd-manager-bus.c.o systemd-oomd.p/src_oom_oomd-manager.c.o systemd-oomd.p/src_oom_oomd-util.c.o systemd-oomd.p/src_oom_oomd.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--fatal-warnings -Wl,-z,now -Wl,-z,relro -fstack-protector -Wl,--warn-common '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/root/build/src/shared -Wl,--start-group src/shared/libsystemd-shared-252.so /usr/lib/gcc/x86_64-redhat-linux/8/libatomic.so -Wl,--end-group
/usr/bin/ld: cannot find /usr/lib64/libatomic.so.1.2.0
collect2: error: ld returned 1 exit status

I found some explanation of Red Hat / Fedora situation in scylladb/seastar#533.
But if Meson considers a library to be found if it is a linker script referring to non-existent file, then I would consider it to be a Meson bug.

Semi-quoting systemd#25057:

clang-16 has made the choice to turn on -Werror=implicit-function-declaration,implicit-int.
(See Gentoo's tracker bug https://bugs.gentoo.org/870412).
Added in commit 132c73b, systemd now does a
check to see if libatomic is needed with some compile/link tests with e.g.
__atomic_exchange_1, but the tests don't provide a prototype for
__atomic_exchange_1 so with clang-16 the test fails, breaking the build.

Let's simplify things by linking to libatomic unconditionally if it is found
and seems to work. If actually unneeded, it might be dropped via --as-needed.
This seems to work with gcc and clang.

declare_dependency() is used instead of cc.find_library(), because the latter
picks up a symlink in gcc private directory (e.g.
/usr/lib/gcc/x86_64-redhat-linux/12/libatomic.so), and we don't want that.

Fixes systemd#25057.
@bluca
Copy link
Member

bluca commented Oct 21, 2022

Fixed the typo since it was trivial, no other changes so merging

@bluca bluca merged commit 96f8c63 into systemd:main Oct 21, 2022
@keszybz keszybz deleted the atomic-clang-16 branch October 23, 2022 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

meson configure fails "Atomic builtin requires -latomic" test with new clang
6 participants