zstd
zstd copied to clipboard
Cannot build with cmake -DCMAKE_ASM_COMPILER=as or llvm-as
Describe the bug
Build of assembly sources fails if cmake is invoked with -DCMAKE_ASM_COMPILER=as using the as from GNU binutils. My version of as is 2.38.
It also fails in a different way with clang and llvm-as.
Originally reported here:
https://github.com/ccache/ccache/issues/1113 .
To Reproduce
For gcc, running:
git clone [email protected]:facebook/zstd
cd zstd
mkdir build-asm-opt
cd build-asm-opt
cmake ../build/cmake -DCMAKE_ASM_COMPILER=as -G Ninja
LANG=C ninja -v
, gives:
[1/15] /usr/bin/as --defsym XXH_NAMESPACE=ZSTD_ --defsym ZSTD_LEGACY_SUPPORT=5 --defsym ZSTD_MULTITHREAD --defsym libzstd_shared_EXPORTS -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -O3 -DNDEBUG -fPIC --MD lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o.d -o lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
FAILED: lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o
/usr/bin/as --defsym XXH_NAMESPACE=ZSTD_ --defsym ZSTD_LEGACY_SUPPORT=5 --defsym ZSTD_MULTITHREAD --defsym libzstd_shared_EXPORTS -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -O3 -DNDEBUG -fPIC --MD lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o.d -o lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
Assembler messages:
Fatal error: bad defsym; format is --defsym name=value
[2/15] /usr/bin/as --defsym XXH_NAMESPACE=ZSTD_ --defsym ZSTD_LEGACY_SUPPORT=5 --defsym ZSTD_MULTITHREAD -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -O3 -DNDEBUG -fPIC --MD lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o.d -o lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
FAILED: lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o
/usr/bin/as --defsym XXH_NAMESPACE=ZSTD_ --defsym ZSTD_LEGACY_SUPPORT=5 --defsym ZSTD_MULTITHREAD -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -O3 -DNDEBUG -fPIC --MD lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o.d -o lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
Assembler messages:
Fatal error: bad defsym; format is --defsym name=value
[3/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstdgrep.1 .
[4/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstd.1 .
[5/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstdless.1 .
ninja: build stopped: subcommand failed.
. For clang and llvm-as (from llvm 14.0.5) running:
cmake ../build/cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_ASM_COMPILER=llvm-as -G Ninja
, produces in the cmake messages:
-- The ASM compiler identification is unknown
-- Found assembler: /usr/lib/llvm/14/bin/llvm-as
-- Warning: Did not find file Compiler/-ASM
, while running the build with LANG=C ninja -v produces:
[1/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstdless.1 .
[2/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstdgrep.1 .
[3/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E copy /home/rkitover/source/repos/zstd/build/cmake/../../programs/zstd.1 .
[4/15] /usr/lib/llvm/14/bin/llvm-as -DXXH_NAMESPACE=ZSTD_ -DZSTD_LEGACY_SUPPORT=5 -DZSTD_MULTITHREAD -Dlibzstd_shared_EXPORTS -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -o lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
FAILED: lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o
/usr/lib/llvm/14/bin/llvm-as -DXXH_NAMESPACE=ZSTD_ -DZSTD_LEGACY_SUPPORT=5 -DZSTD_MULTITHREAD -Dlibzstd_shared_EXPORTS -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -o lib/CMakeFiles/libzstd_shared.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
llvm-as: Unknown command line argument '-DXXH_NAMESPACE=ZSTD_'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--o=ZSTD_'?
llvm-as: Unknown command line argument '-DZSTD_LEGACY_SUPPORT=5'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--o=5'?
llvm-as: Unknown command line argument '-DZSTD_MULTITHREAD'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '-o'?
llvm-as: Unknown command line argument '-Dlibzstd_shared_EXPORTS'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--print-all-options'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build-asm-opt/lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--print-all-options'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-c'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '-o'?
[5/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E create_symlink zstd.1 zstdcat.1
[6/15] cd /home/rkitover/source/repos/zstd/build-asm-opt/programs && /usr/bin/cmake -E create_symlink zstd.1 unzstd.1
[7/15] /usr/lib/llvm/14/bin/llvm-as -DXXH_NAMESPACE=ZSTD_ -DZSTD_LEGACY_SUPPORT=5 -DZSTD_MULTITHREAD -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -o lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
FAILED: lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o
/usr/lib/llvm/14/bin/llvm-as -DXXH_NAMESPACE=ZSTD_ -DZSTD_LEGACY_SUPPORT=5 -DZSTD_MULTITHREAD -I/home/rkitover/source/repos/zstd/build-asm-opt/lib -I/home/rkitover/source/repos/zstd/build/cmake/lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common -I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy -o lib/CMakeFiles/libzstd_static.dir/home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S.o -c /home/rkitover/source/repos/zstd/lib/decompress/huf_decompress_amd64.S
llvm-as: Unknown command line argument '-DXXH_NAMESPACE=ZSTD_'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--o=ZSTD_'?
llvm-as: Unknown command line argument '-DZSTD_LEGACY_SUPPORT=5'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--o=5'?
llvm-as: Unknown command line argument '-DZSTD_MULTITHREAD'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '-o'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build-asm-opt/lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--print-all-options'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib/common'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-I/home/rkitover/source/repos/zstd/build/cmake/../../lib/legacy'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '--preserve-bc-uselistorder'?
llvm-as: Unknown command line argument '-c'. Try: '/usr/lib/llvm/14/bin/llvm-as --help'
llvm-as: Did you mean '-o'?
ninja: build stopped: subcommand failed.
.
Expected behavior Assembly sources to compile successfully using binutils or llvm assembler.
Desktop (please complete the following information):
- OS: recent Gentoo using a systemd profile, but same problems on Ubuntu
- Version: just merged world a few days ago from unstable
- Compiler: affects both
gccandclang - Build system: this applies to
cmake
Additional context I suspect that not passing the C/C++ flags when compiling the assembly sources and using only the minimal required flags for the assembler would fix this issue. I can probably fix this in a PR if you would like.
The .S files contain preprocessor statements and other compiler flags, so need to be handled by cc unlike the .s files that are handled by as.
The Makefile does the right thing, by using COMPILE.S instead of COMPILE.s
So CMake should use CMAKE_C_COMPILER, instead of CMAKE_ASM_COMPILER
I believe that PR #3382 fixes this issue. But I'm not a CMake expert, so please @afbjorklund, @rkitover let me know if this fixes the issue for you.