This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver] Warn when '-mno-outline-atomics' is used with a non-AArch64 triple
ClosedPublic

Authored by nathanchance on Dec 21 2021, 1:20 PM.

Details

Summary

The Linux kernel has a make macro called cc-option that invokes the
compiler with an option in isolation to see if it is supported before
adding it to CFLAGS. The exit code of the compiler is used to determine
if the flag is supported and should be added to the compiler invocation.

A call to cc-option with '-mno-outline-atomics' was added to prevent
linking errors with newer GCC versions but this call succeeds with a
non-AArch64 target because there is no warning from clang with
'-mno-outline-atomics', just '-moutline-atomics'. Because the call
succeeds and adds '-mno-outline-atomics' to the compiler invocation,
there is a warning from LLVM because the 'outline-atomics target
feature is only supported by the AArch64 backend.

$ echo | clang -target x86_64 -moutline-atomics -Werror -x c -c -o /dev/null -
clang-14: error: The 'x86_64' architecture does not support -moutline-atomics; flag ignored [-Werror,-Woption-ignored]

$ echo $?
1

$ echo | clang -target x86_64 -mno-outline-atomics -Werror -x c -c -o /dev/null -
'-outline-atomics' is not a recognized feature for this target (ignoring feature)

$ echo $?
0

This does not match GCC's behavior, which errors when the flag is added
to a non-AArch64 target.

$ echo | gcc -moutline-atomics -x c -c -o /dev/null -
gcc: error: unrecognized command-line option ‘-moutline-atomics’; did you mean ‘-finline-atomics’?

$ echo | gcc -mno-outline-atomics -x c -c -o /dev/null -
gcc: error: unrecognized command-line option ‘-mno-outline-atomics’; did you mean ‘-fno-inline-atomics’?

$ echo | aarch64-linux-gnu-gcc -moutline-atomics -x c -c -o /dev/null -

$ echo | aarch64-linux-gnu-gcc -mno-outline-atomics -x c -c -o /dev/null -

To get closer to GCC's behavior, issue a warning when
'-mno-outline-atomics' is used without an AArch64 triple and do not add
'{-,+}outline-atomic" to the list of target features in these cases.

Link: https://github.com/ClangBuiltLinux/linux/issues/1552

Diff Detail

Event Timeline

nathanchance created this revision.Dec 21 2021, 1:20 PM
nathanchance requested review of this revision.Dec 21 2021, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2021, 1:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

If there are more qualified people to review and accept this, please add them, I was unsure of who else to add.

nickdesaulniers accepted this revision.Dec 21 2021, 2:49 PM
nickdesaulniers added inline comments.
clang/test/Driver/x86-outline-atomics.c
1–7 ↗(On Diff #395745)

If clang/test/Driver/aarch64-features.c is only testing outline atomics, I wonder if this test should actually go in there? @t.p.northover , thoughts? Otherwise LGTM and thanks for the patch!

This revision is now accepted and ready to land.Dec 21 2021, 2:49 PM
nathanchance added inline comments.Dec 21 2021, 3:00 PM
clang/test/Driver/x86-outline-atomics.c
1–7 ↗(On Diff #395745)

I did consider that initially but:

  1. It does appear to test a few other AArch64 specific things.
  2. It seemed weird to add an x86_64 test to an AArch64 file.

No strong opinions though, I'll go along with whatever works and makes the majority happy.

melver accepted this revision.Dec 22 2021, 3:14 AM
melver added inline comments.
clang/test/Driver/x86-outline-atomics.c
1–7 ↗(On Diff #395745)

There is a similar precedent in clang/test/Driver/aarch64-outliner.c, although maybe that should have been in aarch64-features.c

However, the fact it's called x86-outline-atomics.c makes me think that x86 supports outline atomics.

Other similar tests appear in clang/test/Driver/unsupported-*.

My suggestion is to call it unsupported-outline-atomics.c.

Furthermore, this shouldn't just warn on x86, so one more arch (say riscv or ppc?) would be useful to check as well.

  • Move test from x86-outline-atomics.c to unsupported-outline-atomics.c (Marco).
  • Add a test for riscv64 to ensure it works with multiple architectures (Marco).
melver accepted this revision.Dec 23 2021, 8:34 AM
This revision was landed with ongoing or failed builds.Dec 23 2021, 11:49 AM
This revision was automatically updated to reflect the committed changes.