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

[BUG] All regex tests fail to compile when running cmake #1421

Closed
rchoudhary opened this issue Jun 27, 2022 · 8 comments
Closed

[BUG] All regex tests fail to compile when running cmake #1421

rchoudhary opened this issue Jun 27, 2022 · 8 comments

Comments

@rchoudhary
Copy link

rchoudhary commented Jun 27, 2022

Describe the bug
HAVE_STD_REGEX, HAVE_GNU_POSIX_REGEX, and HAVE_POSIX_REGEX all fail to compile when running cmake.

System
Which OS, compiler, and compiler version are you using:

  • OS: macOS 12.4 (Monterey)
  • Compiler and version: clang version 15.0.0, built from the llvm-project repository. Targets arm64-apple-darwin21.5.0, thread model is posix.

To reproduce
Steps to reproduce the behavior:

  1. Clone llvm-project repo and configure with
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/Users/rutvik/projects/llvm-project/install -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"
  1. Build llvm and clang and install to $LLVM2
  2. Clone benchmark repo and cd into build
  3. Configure with
cmake --debug-output -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$LLVM2/bin/clang -DCMAKE_CXX_COMPILER=$LLVM2/bin/clang -DCMAKE_CXX_STANDARD=20 ../

(note that custom built clang compiler is provided)

Expectation:

I need to use my own custom-built version of LLVM to build the benchmark repo because that's what I'm compiling the program I want to benchmark with (we made some modifications to LLVM and want to test the effect of them).

I'm not sure if the problem is it's not linking against the correct C++ standard library or if something else is going on?

Cmake output:

Running with debug output on.
-- git version: v1.6.1-58-gb7afda2c normalized to 1.6.1.58
   Called from: [2]	/Users/rutvik/projects/benchmark/cmake/GetGitVersion.cmake
                [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Version: 1.6.1.58
   Called from: [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
   Called from: [2]	/Users/rutvik/projects/benchmark/cmake/CXXFeatureCheck.cmake
                [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Performing Test HAVE_STD_REGEX -- failed to compile
   Called from: [2]	/Users/rutvik/projects/benchmark/cmake/CXXFeatureCheck.cmake
                [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
   Called from: [2]	/Users/rutvik/projects/benchmark/cmake/CXXFeatureCheck.cmake
                [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Performing Test HAVE_POSIX_REGEX -- failed to compile
   Called from: [2]	/Users/rutvik/projects/benchmark/cmake/CXXFeatureCheck.cmake
                [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
CMake Error at CMakeLists.txt:309 (message):
  Failed to determine the source files for the regular expression backend


   Called from: [1]	/Users/rutvik/projects/benchmark/CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "/Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeOutput.log".
See also "/Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeError.log".

Contents of CMakeError.log:

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /Users/rutvik/projects/llvm-project/install/bin/clang 
Build flags: 
Id flags:  

The output was:
1
ld: library not found for -lSystem
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)


Determining if the function shm_open exists in the rt failed with the following output:
Change Dir: /Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_086a9/fast && /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_086a9.dir/build.make CMakeFiles/cmTC_086a9.dir/build
Building CXX object CMakeFiles/cmTC_086a9.dir/CheckFunctionExists.cxx.o
/Users/rutvik/projects/llvm-project/install/bin/clang   -DCHECK_FUNCTION_EXISTS=shm_open -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -MD -MT CMakeFiles/cmTC_086a9.dir/CheckFunctionExists.cxx.o -MF CMakeFiles/cmTC_086a9.dir/CheckFunctionExists.cxx.o.d -o CMakeFiles/cmTC_086a9.dir/CheckFunctionExists.cxx.o -c /Users/rutvik/projects/benchmark/build/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx
Linking CXX executable cmTC_086a9
/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_086a9.dir/link.txt --verbose=1
/Users/rutvik/projects/llvm-project/install/bin/clang  -DCHECK_FUNCTION_EXISTS=shm_open -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/homebrew/opt/llvm/lib  CMakeFiles/cmTC_086a9.dir/CheckFunctionExists.cxx.o -o cmTC_086a9  -lrt 
ld: library not found for -lrt
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_086a9] Error 1
make: *** [cmTC_086a9/fast] Error 2



Performing C++ SOURCE FILE Test HAVE_CXX_FLAG_WD654 failed with the following output:
Change Dir: /Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_63d40/fast && /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_63d40.dir/build.make CMakeFiles/cmTC_63d40.dir/build
Building CXX object CMakeFiles/cmTC_63d40.dir/src.cxx.o
/Users/rutvik/projects/llvm-project/install/bin/clang -DHAVE_CXX_FLAG_WD654  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -wd654 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk   -wd654 -MD -MT CMakeFiles/cmTC_63d40.dir/src.cxx.o -MF CMakeFiles/cmTC_63d40.dir/src.cxx.o.d -o CMakeFiles/cmTC_63d40.dir/src.cxx.o -c /Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeTmp/src.cxx
clang-15: error: unknown argument: '-wd654'
clang-15: error: unknown argument: '-wd654'
make[1]: *** [CMakeFiles/cmTC_63d40.dir/src.cxx.o] Error 1
make: *** [cmTC_63d40/fast] Error 2


Source file was:
int main() { return 0; }
Performing C++ SOURCE FILE Test HAVE_CXX_FLAG_COVERAGE failed with the following output:
Change Dir: /Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_a49d1/fast && /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_a49d1.dir/build.make CMakeFiles/cmTC_a49d1.dir/build
Building CXX object CMakeFiles/cmTC_a49d1.dir/src.cxx.o
/Users/rutvik/projects/llvm-project/install/bin/clang -DHAVE_CXX_FLAG_COVERAGE  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  --coverage -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk   --coverage -MD -MT CMakeFiles/cmTC_a49d1.dir/src.cxx.o -MF CMakeFiles/cmTC_a49d1.dir/src.cxx.o.d -o CMakeFiles/cmTC_a49d1.dir/src.cxx.o -c /Users/rutvik/projects/benchmark/build/CMakeFiles/CMakeTmp/src.cxx
Linking CXX executable cmTC_a49d1
/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a49d1.dir/link.txt --verbose=1
/Users/rutvik/projects/llvm-project/install/bin/clang   -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  --coverage -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/homebrew/opt/llvm/lib  CMakeFiles/cmTC_a49d1.dir/src.cxx.o -o cmTC_a49d1 
ld: file not found: /Users/rutvik/projects/llvm-project/install/lib/clang/15.0.0/lib/darwin/libclang_rt.profile_osx.a
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_a49d1] Error 1
make: *** [cmTC_a49d1/fast] Error 2


Source file was:
int main() { return 0; }
@rchoudhary
Copy link
Author

rchoudhary commented Jun 27, 2022

I also ran the following in the llvm-project repo in order to build libc++:

cmake -S runtimes -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/Users/rutvik/projects/llvm-project/install -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"

Now there's actually a libc++.a file in $LLVM2/lib. Unfortunately, benchmark still fails to configure...

@rchoudhary
Copy link
Author

rchoudhary commented Jun 27, 2022

I read about using a custom libc++ when building. I added the following to benchmark/src/CMakeLists.txt in order to use my custom libc++:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -nostdlib++ -isystem /Users/rutvik/projects/llvm-project/install/include/c++/v1 -L /Users/rutvik/projects/llvm-project/install/lib -Wl,-rpath,/Users/rutvik/projects/llvm-project/install/lib -lc++")

The configuration still fails however.

@dmah42
Copy link
Member

dmah42 commented Jul 4, 2022

this appears to be the failure the clang sanitizers are seeing. i have tried to replicate locally and been unable (with clang 13).

@dmah42
Copy link
Member

dmah42 commented Jul 4, 2022

tested with clang-11 and i can reproduce the failure:

-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- failed to compile
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- failed to compile

@dmah42
Copy link
Member

dmah42 commented Jul 4, 2022

STD_REGEX failure:

dev/benchmark/cmake/std_regex.cpp:1:10: fatal error: 'regex' file not found
#include <regex>

POSIX_REGEX failure:

dev/benchmark/cmake/posix_regex.cpp:2:10: fatal error: 'string' file not found
#include <string>

@dmah42
Copy link
Member

dmah42 commented Jul 4, 2022

clang 11 command line:

/usr/bin/clang++-11   -g -O2 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all -stdlib=libc++  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  -MD -MT CMakeFiles/cmTC_5c8f2.dir/posix_regex.cpp.o -MF CMakeFiles/cmTC_5c8f2.dir/posix_regex.cpp.o.d -o CMakeFiles/cmTC_5c8f2.dir/posix_regex.cpp.o -c /home/dominic/dev/benchmark/cmake/posix_regex.cpp

clang-13 command line:

/usr/bin/clang++-13   -g -O2 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all -stdlib=libc++  -std=c++11  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety  -MD -MT CMakeFiles/cmTC_355ef.dir/posix_regex.cpp.o -MF CMakeFiles/cmTC_355ef.dir/posix_regex.cpp.o.d -o CMakeFiles/cmTC_355ef.dir/posix_regex.cpp.o -c /home/dominic/dev/benchmark/cmake/posix_regex.cpp

@dmah42
Copy link
Member

dmah42 commented Jul 4, 2022

in short: i don't know why this fails under clang-11.

@rchoudhary
Copy link
Author

Ah the fix for the error is quite silly, I needed to specify clang++ and not clang. After making that change the configuration finishes successfully.

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

No branches or pull requests

2 participants