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

Conan build fails with segv on gcc 9.1.0 #897

Closed
scott-eddy opened this issue Oct 27, 2019 · 9 comments
Closed

Conan build fails with segv on gcc 9.1.0 #897

scott-eddy opened this issue Oct 27, 2019 · 9 comments

Comments

@scott-eddy
Copy link

Found when trying to use conan and google benchmark on a brand new repository. Minimum reproducible example is here, which tries to compile the example usage of benchmark and compile/link it to conan library

$ gcc --version
gcc (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ conan --version
Conan version 1.19.2
$ conan install ..
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    benchmark/1.5.0 from 'conan-center' - Cache
Packages
    benchmark/1.5.0:9ec7e6c55ee108e231bdef75e23776b8b86d821d - Cache

benchmark/1.5.0: Already installed!
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
cmake ..
-- The C compiler identification is GNU 9.1.0
-- The CXX compiler identification is GNU 9.1.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Debug' as none was specified.
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /home/eddy/github/algorithms_practice/build
-- Conan: Compiler GCC>=5, checking major version 9
-- Conan: Checking correct version: 9
-- Configuring done
-- Generating done
-- Build files have been written to: /home/eddy/github/algorithms_practice/build
eddy@arch-box:~/github/algorithms_practice/build$ make VERBOSE=1
/usr/bin/cmake -S/home/eddy/github/algorithms_practice -B/home/eddy/github/algorithms_practice/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/eddy/github/algorithms_practice/build/CMakeFiles /home/eddy/github/algorithms_practice/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/eddy/github/algorithms_practice/build'
make -f CMakeFiles/algorithms_benchmark.dir/build.make CMakeFiles/algorithms_benchmark.dir/depend
make[2]: Entering directory '/home/eddy/github/algorithms_practice/build'
cd /home/eddy/github/algorithms_practice/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/eddy/github/algorithms_practice /home/eddy/github/algorithms_practice /home/eddy/github/algorithms_practice/build /home/eddy/github/algorithms_practice/build /home/eddy/github/algorithms_practice/build/CMakeFiles/algorithms_benchmark.dir/DependInfo.cmake --color=
Dependee "/home/eddy/github/algorithms_practice/build/CMakeFiles/algorithms_benchmark.dir/DependInfo.cmake" is newer than depender "/home/eddy/github/algorithms_practice/build/CMakeFiles/algorithms_benchmark.dir/depend.internal".
Dependee "/home/eddy/github/algorithms_practice/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/eddy/github/algorithms_practice/build/CMakeFiles/algorithms_benchmark.dir/depend.internal".
Scanning dependencies of target algorithms_benchmark
make[2]: Leaving directory '/home/eddy/github/algorithms_practice/build'
make -f CMakeFiles/algorithms_benchmark.dir/build.make CMakeFiles/algorithms_benchmark.dir/build
make[2]: Entering directory '/home/eddy/github/algorithms_practice/build'
[ 50%] Building CXX object CMakeFiles/algorithms_benchmark.dir/src/benchmark_main.cpp.o
/usr/bin/c++   -I/home/eddy/.conan/data/benchmark/1.5.0/_/_/package/9ec7e6c55ee108e231bdef75e23776b8b86d821d/include  -g    -o CMakeFiles/algorithms_benchmark.dir/src/benchmark_main.cpp.o -c /home/eddy/github/algorithms_practice/src/benchmark_main.cpp
[100%] Linking CXX executable bin/algorithms_benchmark
/usr/bin/cmake -E cmake_link_script CMakeFiles/algorithms_benchmark.dir/link.txt --verbose=1
/usr/bin/c++     -g        CMakeFiles/algorithms_benchmark.dir/src/benchmark_main.cpp.o  -o bin/algorithms_benchmark  -L/home/eddy/.conan/data/benchmark/1.5.0/_/_/package/9ec7e6c55ee108e231bdef75e23776b8b86d821d/lib -Wl,-rpath,/home/eddy/.conan/data/benchmark/1.5.0/_/_/package/9ec7e6c55ee108e231bdef75e23776b8b86d821d/lib -lbenchmark -lbenchmark_main -lpthread -lrt 
make[2]: Leaving directory '/home/eddy/github/algorithms_practice/build'
[100%] Built target algorithms_benchmark
make[1]: Leaving directory '/home/eddy/github/algorithms_practice/build'
/usr/bin/cmake -E cmake_progress_start /home/eddy/github/algorithms_practice/build/CMakeFiles 0
$ bin/algorithms_benchmark 
2019-10-27 14:58:07
Running bin/algorithms_benchmark
Run on (4 X 3408 MHz CPU s)
CPU Caches:
  L1 Data 32K (x4)
  L1 Instruction 32K (x4)
  L2 Unified 256K (x4)
  L3 Unified 6144K (x4)
Load Average: 0.16, 0.37, 0.51
Segmentation fault (core dumped)
(gdb) run
Starting program: /home/eddy/github/algorithms_practice/build/bin/algorithms_benchmark 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
2019-10-27 14:58:29
Running /home/eddy/github/algorithms_practice/build/bin/algorithms_benchmark
Run on (4 X 3408 MHz CPU s)
CPU Caches:
  L1 Data 32K (x4)
  L1 Instruction 32K (x4)
  L2 Unified 256K (x4)
  L3 Unified 6144K (x4)
Load Average: 0.11, 0.35, 0.50

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x000055555559a458 in benchmark::internal::BenchmarkInstance::Run(unsigned long, int, benchmark::internal::ThreadTimer*, benchmark::internal::ThreadManager*) const ()
#2  0x000055555557d629 in benchmark::internal::(anonymous namespace)::RunInThread(benchmark::internal::BenchmarkInstance const*, unsigned long, int, benchmark::internal::ThreadManager*) ()
#3  0x000055555557dd0a in benchmark::internal::(anonymous namespace)::BenchmarkRunner::DoNIterations() ()
#4  0x000055555557e60d in benchmark::internal::RunBenchmark(benchmark::internal::BenchmarkInstance const&, std::vector<benchmark::BenchmarkReporter::Run, std::allocator<benchmark::BenchmarkReporter::Run> >*) ()
#5  0x0000555555560282 in benchmark::RunSpecifiedBenchmarks(benchmark::BenchmarkReporter*, benchmark::BenchmarkReporter*) ()
#6  0x000055555555e444 in main (argc=1, argv=0x7fffffffdf68) at /home/eddy/github/algorithms_practice/src/benchmark_main.cpp:18
@msporyshev
Copy link

I have similar problem. Conan version is 1.21.2

@dmah42
Copy link
Member

dmah42 commented Feb 25, 2020

@Croydon who did the conan integration... any ideas? it looks a bit like a missing pthread reference (pure guess).

@maddisoj
Copy link

I am currently facing this issue with conan 1.24. I have tried with clang-10, gcc-9.3 and gcc-7.5, all face the same issue.

The problem can be reproduced by using this conan recipe and the below: https://conan.io/center/benchmark/1.5.0/?user=_&channel=_&revision=&os=Linux&tab=recipe

conanfile.txt

[requires]
benchmark/1.5.0

[generators]
cmake_find_package

CMakeLists.txt

project(BenchmarkTest)

set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_MODULE_PATH})
find_package(benchmark REQUIRED)

add_executable(BenchmarkTest test.cpp)
target_link_libraries(BenchmarkTest PRIVATE benchmark::benchmark)

test.cpp

#include <benchmark/benchmark.h>

static void BM_Test(benchmark::State &state) {}

BENCHMARK(BM_Test);

The issue is caused inside here:

#define BENCHMARK(n)                                                           \
  BENCHMARK_PRIVATE_DECLARE(n) =                                               \
      (::benchmark::internal::RegisterBenchmarkInternal(                       \
          new ::benchmark::internal::FunctionBenchmark(#n, n)))

The FunctionBenchmark receives a valid pointer:

997           : Benchmark(name), func_(func) {}
(gdb) list
992     // The class used to hold all Benchmarks created from static function.
993     // (ie those created using the BENCHMARK(...) macros.
994     class FunctionBenchmark : public Benchmark {
995      public:
996       FunctionBenchmark(const char* name, Function* func)
997           : Benchmark(name), func_(func) {}
998
999       virtual void Run(State& st);
1000
1001     private:
(gdb) p func
$28 = (benchmark::internal::Function *) 0x55555555ceb0 <BM_Test(benchmark::State&)>
(gdb) fin
Run till exit from #0  0x000055555555ceed in benchmark::internal::FunctionBenchmark::FunctionBenchmark (this=0x55555562feb0,
    name=0x5555555e6004 "BM_Test", func=0x55555555ceb0 <BM_Test(benchmark::State&)>)
    at benchmark/benchmark.h:997
0x000055555555bd30 in __cxx_global_var_init.1(void) ()  at test.cpp:5

But when we get inside RegisterBenchmarkInternal the function pointer is somehow null:

(gdb) s
benchmark::internal::RegisterBenchmarkInternal (bench=0x55555562feb0)
    at benchmark_register.cc:240
240       std::unique_ptr<Benchmark> bench_ptr(bench);
(gdb) list
235       }
236       return true;
237     }
238
239     Benchmark* RegisterBenchmarkInternal(Benchmark* bench) {
240       std::unique_ptr<Benchmark> bench_ptr(bench);
241       BenchmarkFamilies* families = BenchmarkFamilies::GetInstance();
242       families->AddBenchmark(std::move(bench_ptr));
243       return bench;
244     }
(gdb) p ((FunctionBenchmark*)bench)->func_
$29 = (benchmark::internal::Function *) 0x0

@maddisoj
Copy link

maddisoj commented Apr 21, 2020

I have found the culprit, when building with Conan for reasons unbeknownst to me it is adding the compile defintion: -D_GLIBCXX_USE_CXX11_ABI=0.

If I build benchmark manually everything is fine, if I add this flag like Conan I get the segfault occuring above (when the executable doesn't use the same define)

@maddisoj
Copy link

And the fix is to use compiler.libcxx=libstdc++11 not compiler.libcxx=libstd++ in your Conan profile or build your binary with -D_GLIBCXX_USE_CXX11_ABI=0

@Croydon
Copy link
Contributor

Croydon commented Apr 21, 2020

@maddisoj Thanks for figuring this out!

According to the readme Benchmark indeed requires a C++11 compatible standard library, so the Conan recipe should disallow other builds.

I will create PRs here and on CCI

@maddisoj
Copy link

maddisoj commented Apr 21, 2020

For what it's worth benchmark compiles perfectly fine with -D_GLIBCXX_USE_CXX11_ABI=0, the library is still C++11 it just doesn't include the ABI changes introduced by C++11. It's only broken because the two binaries (the one built by Conan and the one linked against it) have different (and incompatible) ABIs.

From what I've been reading that define exists so that you can compile a C++11 binary to be compatible with a C++03 or earlier binary. https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

Conan page on the issue: https://docs.conan.io/en/latest/howtos/manage_gcc_abi.html

@dmah42
Copy link
Member

dmah42 commented May 8, 2021

conan removed :)

@dmah42 dmah42 closed this as completed May 8, 2021
@richjohnson-wwt
Copy link

I had this problem with libavrocpp on Conan. Seems like c++11 should be the default for new projects. We shouldn't have to do something special. If you are targeting older gcc versions, then force the special setup.

Thanks for this thread!!

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

6 participants