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

compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o is incorrectly compiled with x86-specific options #63270

Open
MaskRay opened this issue Jun 12, 2023 · 0 comments
Labels
cmake Build system in general and CMake in particular compiler-rt:tsan Thread sanitizer

Comments

@MaskRay
Copy link
Member

MaskRay commented Jun 12, 2023

On an x86_64-apple-* macOS machine, COMPILER_RT_HAS_MSSE4_2_FLAG is true (the availability is detected like clang --target=x86_64-apple-darwinXXX -arch x86_64 -Werror -msse4.2 -c src.cxx).

Ensure that an iOS SDK is available. In the following build,

/opt/homebrew/bin/cmake -GNinja -Sllvm -Bout/runtimes -DCMAKE_BUILD_TYPE=Release -DCLANG_ENABLE_ARCMT=off -DCLANG_ENABLE_STATIC_ANALYZER=off -DLLVM_ENABLE_PROJECTS='clang;lld' -DCOMPILER_RT_ENABLE_IOS=on -DLLVM_ENABLE_RUNTIMES=compiler-rt -DLLVM_TARGETS_TO_BUILD='X86;AArch64' -DLLVM_ENABLE_UNWIND_TABLES=OFF
ninja -C out/runtimes runtimes
ninja -C out/runtimes/runtimes/runtimes-bins tsan

compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o (and other clang_rt.tsan_ios_dynamic.dir files due to -DCOMPILER_RT_ENABLE_IOS=on) will have a warning like the following

% clang -c --target=x86_64-apple-darwin -arch arm64 -msse4.2 a.c
clang: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]

This command compiles a.c using the arm64-apple-darwin triple and -msse4.2 should lead to an error instead of a warning.

The full command line will look like the following if Clang issues an error (https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8778547096422852257/+/u/package_clang/stdout)

 FAILED: compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o 
 /Volumes/Work/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/./bin/clang++ --target=x86_64-apple-darwin -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dclang_rt_tsan_ios_dynamic_EXPORTS -I/Volumes/Work/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/tsan/rtl/../.. -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wno-unused-parameter -O3 -DNDEBUG -std=c++17 -arch arm64 -isysroot /Volumes/Work/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -stdlib=libc++ -miphoneos-version-min=9.0 -isysroot /Volumes/Work/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.2.sdk -fno-lto -fPIC -fno-builtin -fno-exceptions -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -g -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fPIE -fno-rtti -msse4.2 -Wframe-larger-than=530 -Wglobal-constructors -MD -MT compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o -MF compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o.d -o compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_ios_dynamic.dir/tsan_debugging.cpp.o -c /Volumes/Work/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/tsan/rtl/tsan_debugging.cpp
 clang++: error: unsupported option '-msse4.2' for target 'x86_64-apple-darwin'

It seems tsan's CMake should be fixed to recognize x86_64 options and not pass them to clang_rt.tsan_ios_dynamic.dir builds (clang --target=x86_64-apple-darwinXXX -arch arm64).

For host files like ./compiler-rt/lib/tsan/rtl/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/tsan_flags.cpp.o, the Clang command line looks like -arch arm64 -arch x86_64 -arch x86_64h.
It is benign to pass -msse4.2 but ideally -Xarch_x86_64 -msse4.2 -Xarch_x86_64h -msse4.2 should be used instead.

@MaskRay MaskRay added cmake Build system in general and CMake in particular compiler-rt:tsan Thread sanitizer labels Jun 12, 2023
MaskRay added a commit that referenced this issue Jun 12, 2023
so that they get an error on non-x86 targets.
Follow-up to D151590.

As a workaround for #63270, we don't
report an error for -msse4.2.
zmodem added a commit that referenced this issue Jun 13, 2023
This broke cross-builds of llvm from x86_64 to arm64 mac, see
comment on
1d6c3e2

> so that they get an error on non-x86 targets.
> Follow-up to D151590.
>
> As a workaround for #63270, we don't
> report an error for -msse4.2.

This reverts commit 1d6c3e2.
MaskRay added a commit to MaskRay/llvm-project that referenced this issue Aug 3, 2023
so that they lead to an error when compiled for non-x86 targets.
Follow-up to D151590.

```
% aarch64-linux-gnu-gcc -c -mavx a.c
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’
% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # without this patch
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
%
```

As a workaround for llvm#63270, we don't
report an error for -msse4.2.
MaskRay added a commit that referenced this issue Aug 4, 2023
so that they lead to an error when compiled for non-x86 targets.
Follow-up to D151590.

```
% aarch64-linux-gnu-gcc -c -mavx a.c
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’
% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # without this patch
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
...

% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # with this patch
clang: error: unsupported option '-mavx' for target 'aarch64-unknown-linux-gnu'
```

As a workaround for #63270, we don't
report an error for -msse4.2.

Reviewed By: pengfei, skan

Differential Revision: https://reviews.llvm.org/D156962
razmser pushed a commit to razmser/llvm-project that referenced this issue Sep 8, 2023
so that they lead to an error when compiled for non-x86 targets.
Follow-up to D151590.

```
% aarch64-linux-gnu-gcc -c -mavx a.c
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’
% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # without this patch
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
...

% clang --target=aarch64-unknown-linux-gnu -c -mavx a.c  # with this patch
clang: error: unsupported option '-mavx' for target 'aarch64-unknown-linux-gnu'
```

As a workaround for llvm#63270, we don't
report an error for -msse4.2.

Reviewed By: pengfei, skan

Differential Revision: https://reviews.llvm.org/D156962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular compiler-rt:tsan Thread sanitizer
Projects
None yet
Development

No branches or pull requests

1 participant