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

Cannot build with cmake -DCMAKE_ASM_COMPILER=as or llvm-as #3193

Closed
rkitover opened this issue Jul 13, 2022 · 2 comments · Fixed by #3382
Closed

Cannot build with cmake -DCMAKE_ASM_COMPILER=as or llvm-as #3193

rkitover opened this issue Jul 13, 2022 · 2 comments · Fixed by #3382

Comments

@rkitover
Copy link

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:

ccache/ccache#1113
.

To Reproduce

For gcc, running:

git clone git@github.com: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 gcc and clang
  • 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.

@afbjorklund
Copy link

afbjorklund commented Jul 13, 2022

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

terrelln added a commit to terrelln/zstd that referenced this issue Dec 20, 2022
Fixes cmake build when the C compiler isn't used as the assembler.
We need to explicitly set the flag `-x assembler-with-cpp` to enable
the preprocessor.

Fixes facebook#3193.
@terrelln
Copy link
Contributor

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.

terrelln added a commit to terrelln/zstd that referenced this issue Dec 20, 2022
Tell CMake to explicitly compile our assembly as C code, because we
require it is compiled by a C compiler, and it is only enabled for
clang/gcc.

Fixes facebook#3193.
terrelln added a commit to terrelln/zstd that referenced this issue Dec 20, 2022
Tell CMake to explicitly compile our assembly as C code, because we
require it is compiled by a C compiler, and it is only enabled for
clang/gcc.

Fixes facebook#3193.
terrelln added a commit that referenced this issue Dec 20, 2022
Tell CMake to explicitly compile our assembly as C code, because we
require it is compiled by a C compiler, and it is only enabled for
clang/gcc.

Fixes #3193.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants