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

clang-cl writes preprocessed assembly source to current dir in some invocations #128688

Open
iskunk opened this issue Feb 25, 2025 · 0 comments
Open
Labels
build-problem clang-cl `clang-cl` driver. Don't use for other compiler parts

Comments

@iskunk
Copy link

iskunk commented Feb 25, 2025

I am using Clang/LLVM 19.1.2, and encountered an error in a cross build of Chromium (host = Linux on AMD64, target = Windows on ARM64), along these lines:

FAILED: clang_x64/obj/third_party/ffmpeg/ffmpeg_nasm/autorename_libavcodec_x86_videodsp.o 
python3 ../../build/gn_run_binary.py clang_x64/nasm -DPIC -felf64 -DARCH_X86_64 -W+error=all -Wno-macro-params-legacy -P../../third_party/ffmpeg/chromium/config/Chrome/linux/x64/config.asm -I../../third_party/ffmpeg/chromium/config/Chrome/linux/x64/ -I../../third_party/ffmpeg/libavcodec/x86/ -I../../third_party/ffmpeg/libavutil/x86/ -I../../third_party/ffmpeg/ -I./ -I../../ -Iclang_x64/gen/ -DPIC -MD clang_x64/obj/third_party/ffmpeg/ffmpeg_nasm/autorename_libavcodec_x86_videodsp.o.d -o clang_x64/obj/third_party/ffmpeg/ffmpeg_nasm/autorename_libavcodec_x86_videodsp.o ../../third_party/ffmpeg/libavcodec/x86/autorename_libavcodec_x86_videodsp.asm
../../third_party/ffmpeg/libavutil/aarch64/asm.S:47: error: parser: instruction expected
../../third_party/ffmpeg/libavutil/aarch64/asm.S:82: error: parser: instruction expected
../../third_party/ffmpeg/libavutil/aarch64/asm.S:83: error: parser: instruction expected
[...]
clang_x64/nasm failed with exit code 1

This error occurred due to the presence of a videodsp.asm file in the assembler's working directory. This file had been generated in a previous build step, and it contained preprocessed assembler source for aarch64. The assembler picked it up for some reason and attempted to generate AMD64 code from it.

Further investigation showed where the videodsp.asm file came from: an invocation of clang-cl. But it was not the Chromium build's intended invocation, which is as follows:

/opt/llvm/bin/clang-cl --target=aarch64-pc-windows -c -oobj/third_party/ffmpeg/ffmpeg_internal/videodsp.obj /showIncludes [various -D flags elided] [various -I flags elided] ../../third_party/ffmpeg/libavcodec/aarch64/videodsp.S

That works as expected, with an .obj file written out, and no other side effects.

However, when ccache is in use, the command is modified slightly into the following:

/opt/llvm/bin/clang-cl --target=aarch64-pc-windows [various -D flags elided] [various -I flags elided] -c /showIncludes -fcolor-diagnostics -Foobj/third_party/ffmpeg/ffmpeg_internal/videodsp.obj ../../third_party/ffmpeg/libavcodec/aarch64/videodsp.S

And for reasons unknown, this invocation generates a videodsp.asm file in the current working directory.

Here is the full output from an invocation of the first command above, with -v added:

clang version 19.1.2 (/home/runner/work/llvm-project/llvm-project/clang 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)
Target: aarch64-pc-windows-msvc
Thread model: posix
InstalledDir: /opt/llvm/bin
 "/opt/llvm/bin/clang-19" -cc1 -triple aarch64-pc-windows-msvc19.33.0 -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name videodsp.S -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -target-abi aapcs -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames --show-includes -sys-header-deps -stack-protector 2 -fdiagnostics-format msvc -fdebug-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -v -fcoverage-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -resource-dir /opt/llvm/lib/clang/19 -D HAVE_AV_CONFIG_H -D _POSIX_C_SOURCE=200112 -D _XOPEN_SOURCE=600 -D PIC -D FFMPEG_CONFIGURATION=NULL -D CHROMIUM_NO_LOGGING -D _ISOC99_SOURCE -D _LARGEFILE_SOURCE -D USE_AURA=1 -D OFFICIAL_BUILD -D __ARM_NEON__=1 -D _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D _LIBCPP_INSTRUMENTED_WITH_ASAN=0 -D CR_LIBCXX_REVISION=1f7db7501cf902d5d3ad5fd9b31bea33bb8bf9da -D TMP_REBUILD_HACK -D __STD_C -D _CRT_RAND_S -D _CRT_SECURE_NO_DEPRECATE -D _SCL_SECURE_NO_DEPRECATE -D _ATL_NO_OPENGL -D _WINDOWS -D CERT_CHAIN_PARA_HAS_EXTRA_FIELDS -D PSAPI_VERSION=2 -D WIN32 -D _SECURE_ATL -D WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D WIN32_LEAN_AND_MEAN -D NOMINMAX -D _UNICODE -D UNICODE -D NTDDI_VERSION=NTDDI_WIN10_NI -D _WIN32_WINNT=0x0A00 -D WINVER=0x0A00 -D NDEBUG -D NVALGRIND -D DYNAMIC_ANNOTATIONS_ENABLED=0 -D _CRT_NONSTDC_NO_WARNINGS -D _WINSOCK_DEPRECATED_NO_WARNINGS -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -internal-isystem /opt/llvm/lib/clang/19/include -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.33 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcolor-diagnostics -target-feature -fmv -faddrsig -o /tmp/videodsp-bb587f.asm -x assembler-with-cpp ../../third_party/ffmpeg/libavcodec/aarch64/videodsp.S
clang -cc1 version 19.1.2 based upon LLVM 19.1.2 default target x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64
 ../../third_party/ffmpeg
 ../..
 gen
 ../../buildtools/third_party/libc++
 ../../third_party/opus/src/include
 /opt/llvm/lib/clang/19/include
End of search list.
Note: including file: ../../third_party/ffmpeg/libavutil/aarch64/asm.S
Note: including file:  ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64/config.h
 "/opt/llvm/bin/clang-19" -cc1as -triple aarch64-pc-windows-msvc19.33.0 -filetype obj -main-file-name videodsp.S -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -fdebug-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -dwarf-debug-producer "clang version 19.1.2 (/home/runner/work/llvm-project/llvm-project/clang 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)" -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -dwarf-version=4 -mrelocation-model pic -mincremental-linker-compatible -o obj/third_party/ffmpeg/ffmpeg_internal/videodsp.obj /tmp/videodsp-bb587f.asm

And here is the same for the second command:

clang version 19.1.2 (/home/runner/work/llvm-project/llvm-project/clang 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)
Target: aarch64-pc-windows-msvc
Thread model: posix
InstalledDir: /opt/llvm/bin
 "/opt/llvm/bin/clang-19" -cc1 -triple aarch64-pc-windows-msvc19.33.0 -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name videodsp.S -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -target-abi aapcs -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames --show-includes -sys-header-deps -stack-protector 2 -fdiagnostics-format msvc -fdebug-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -v -fcoverage-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -resource-dir /opt/llvm/lib/clang/19 -D HAVE_AV_CONFIG_H -D _POSIX_C_SOURCE=200112 -D _XOPEN_SOURCE=600 -D PIC -D FFMPEG_CONFIGURATION=NULL -D CHROMIUM_NO_LOGGING -D _ISOC99_SOURCE -D _LARGEFILE_SOURCE -D USE_AURA=1 -D OFFICIAL_BUILD -D __ARM_NEON__=1 -D _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D _LIBCPP_INSTRUMENTED_WITH_ASAN=0 -D CR_LIBCXX_REVISION=1f7db7501cf902d5d3ad5fd9b31bea33bb8bf9da -D TMP_REBUILD_HACK -D __STD_C -D _CRT_RAND_S -D _CRT_SECURE_NO_DEPRECATE -D _SCL_SECURE_NO_DEPRECATE -D _ATL_NO_OPENGL -D _WINDOWS -D CERT_CHAIN_PARA_HAS_EXTRA_FIELDS -D PSAPI_VERSION=2 -D WIN32 -D _SECURE_ATL -D WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D WIN32_LEAN_AND_MEAN -D NOMINMAX -D _UNICODE -D UNICODE -D NTDDI_VERSION=NTDDI_WIN10_NI -D _WIN32_WINNT=0x0A00 -D WINVER=0x0A00 -D NDEBUG -D NVALGRIND -D DYNAMIC_ANNOTATIONS_ENABLED=0 -D _CRT_NONSTDC_NO_WARNINGS -D _WINSOCK_DEPRECATED_NO_WARNINGS -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -internal-isystem /opt/llvm/lib/clang/19/include -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.33 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcolor-diagnostics -target-feature -fmv -faddrsig -o videodsp.asm -x assembler-with-cpp ../../third_party/ffmpeg/libavcodec/aarch64/videodsp.S
clang -cc1 version 19.1.2 based upon LLVM 19.1.2 default target x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64
 ../../third_party/ffmpeg
 ../..
 gen
 ../../buildtools/third_party/libc++
 ../../third_party/opus/src/include
 /opt/llvm/lib/clang/19/include
End of search list.
Note: including file: ../../third_party/ffmpeg/libavutil/aarch64/asm.S
Note: including file:  ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64/config.h
 "/opt/llvm/bin/clang-19" -cc1as -triple aarch64-pc-windows-msvc19.33.0 -filetype obj -main-file-name videodsp.S -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -fdebug-compilation-dir=/home/build/u-c-windows/cross-build/build/src/out/Default-arm64 -dwarf-debug-producer "clang version 19.1.2 (/home/runner/work/llvm-project/llvm-project/clang 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)" -I ../../third_party/ffmpeg/chromium/config/Chrome/win/arm64 -I ../../third_party/ffmpeg -I ../.. -I gen -I ../../buildtools/third_party/libc++ -I ../../third_party/opus/src/include -dwarf-version=4 -mrelocation-model pic -mincremental-linker-compatible -o obj/third_party/ffmpeg/ffmpeg_internal/videodsp.obj videodsp.asm

Note how the first command writes the preprocessed source to a temporary file (-o /tmp/videodsp-bb587f.asm), whereas the second just writes it to a path-less file (-o videodsp.asm).

As the Chromium build error I presented above illustrates, writing unexpected intermediate files to the current directory should be avoided.

@frederick-vs-ja frederick-vs-ja added build-problem clang-cl `clang-cl` driver. Don't use for other compiler parts and removed new issue labels Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem clang-cl `clang-cl` driver. Don't use for other compiler parts
Projects
None yet
Development

No branches or pull requests

3 participants