This is an archive of the discontinued LLVM Phabricator instance.

[runtimes] [cmake] Fix -Werror detection in common build configs
ClosedPublic

Authored by mstorsjo on Apr 25 2022, 3:48 AM.

Details

Reviewers
phosek
MaskRay
ldionne
Group Reviewers
Restricted Project
Restricted Project
Commits
rGf8da28f52288: [runtimes] [cmake] Fix -Werror detection in common build configs
Summary

We add --unwindlib=none to CMAKE_REQUIRED_FLAGS
to make sure that builds with a yet-incomplete toolchain succeed,
to avoid linker failures about missing unwindlib.

When this option is added to CMAKE_REQUIRED_FLAGS, it gets added to
both compile and link commands in CMake compile tests. If
--unwindlib=none is included in compilation commands, it causes
warnings about unused arguments, as the flag only is relevant for
linking.

Due to the warnings in CMake tests, the later CMake test for the
-Werror option failed (as the tested -Werror option caused the
preexisting warning due to unused --unwindlib=none to become a
hard error). Therefore, most CI configurations that build with
LIBCXX_ENABLE_WERROR didn't actually end up enabling -Werror
after all.

When looking at the CI build log of recent CI builds, they do
end up printing:

  • Performing Test LIBCXX_SUPPORTS_WERROR_FLAG
  • Performing Test LIBCXX_SUPPORTS_WERROR_FLAG - Failed
  • Performing Test LIBCXX_SUPPORTS_WX_FLAG
  • Performing Test LIBCXX_SUPPORTS_WX_FLAG - Failed

Thus while the configurations are meant to error out on warnings,
they actually haven't done that, due to the interaction of these
options.

To fix this, remove the individual cases of adding --unwindlib=none
into CMAKE_REQUIRED_FLAGS in libcxx and libunwind.
runtimes/CMakeLists.txt still adds --unwindlib=none if needed, but
not otherwise. (The same issue with enabling -Werror does remain
if --unwindlib=none strictly is needed though - that can be fixed
separately afterwards.)

These individual cases in libunwind and libcxx were added while
standalone builds of the runtimes still were supported - but no longer
are necessary now.

Diff Detail

Event Timeline

mstorsjo created this revision.Apr 25 2022, 3:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 25 2022, 3:48 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
mstorsjo requested review of this revision.Apr 25 2022, 3:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 3:48 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

This exposes some preexisting warnings in some build configs, that weren’t caught before as LIBCXX_ENABLE_WERROR didn’t end up having any effect. The arm builders warnings should be fixed by D124371.

The AIX 32 bit build produces these warnings:

/scratch/powerllvm/cpap8006/llvm-project/libcxx-ci/build/aix/include/c++/v1/atomic:1005:12: error: large atomic operation may incur significant performance penalty; the access size (8 bytes) exceeds the max lock-free size (4  bytes) [-Werror,-Watomic-alignment]
    return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));

@daltenty - what do you want to do about it? Add LIBCXX_ENABLE_WERROR=OFF in the AIX build config (which also would affect the 64 bit build), do silence it differently somehow?

ldionne accepted this revision.Apr 25 2022, 8:56 AM

Thanks for noticing this! I had indeed noticed some warnings when we built libc++, but didn't realize this would mess with our detection of -Werror's availability.

LGTM once we've fixed the issues that prevent the CI from passing.

This revision is now accepted and ready to land.Apr 25 2022, 8:56 AM
MaskRay accepted this revision.Apr 25 2022, 12:16 PM
phosek added inline comments.Apr 25 2022, 4:02 PM
libcxx/cmake/config-ix.cmake
15–16

Should we drop this check as well since this is done in runtimes/CMakeLists.txt?

libunwind/cmake/config-ix.cmake
12–13

Ditto

mstorsjo added inline comments.Apr 25 2022, 10:44 PM
libcxx/cmake/config-ix.cmake
15–16

I guess we could do that too, now that using runtimes/ is mandatory. In one sense, it's a bit of a bigger step than before though - then libcxx would start relying on specific cmake variables being set, without the code for setting the variables residing in libcxx itself.

mstorsjo added inline comments.Apr 26 2022, 12:11 AM
libcxx/cmake/config-ix.cmake
15–16

Actually, we can't drop it just like that without further changes. In runtimes/CMakeLists.txt we only check for this option if it seems to be needed (if linking fails without it), while libcxx uses the result of this check if LIBCXXABI_USE_LLVM_UNWINDER is set.

phosek accepted this revision.Apr 26 2022, 1:15 AM

LGTM

mstorsjo updated this revision to Diff 425164.Apr 26 2022, 2:38 AM

Rebased to rerun CI, with hopefully only the AIX 32 bit issue left.

@daltenty - what do you want to do about it? Add LIBCXX_ENABLE_WERROR=OFF in the AIX build config (which also would affect the 64 bit build), do silence it differently somehow?

Seems like we could add a diagnostic ignore pragma for -Watomic-alignment to atomic.cpp under a defined(_AIX) && defined(__64BIT__) guard to unblock this (alternatively I'm ok with setting LIBCXX_ENABLE_WERROR=OFF temporarily if that's preferred while we investigate the cause)

ldionne accepted this revision.May 12 2022, 8:45 AM

Let's land D124519 and rebase this on top.

mstorsjo updated this revision to Diff 428961.May 12 2022, 9:03 AM

Rebased, rerunning CI