google/benchmark

[BUG] Google benchmark doesn't compile on Solaris

開放

#1,499 建立於 2022年10月4日

 (0 則留言) (0 個反應) (0 位負責人)C++ (1,539 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (7,968 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Describe the bug

benchmark doesn't compile on Solaris 11.4 (neither upstream nor the downstream copies in LLVM).

System

  • OS: Solaris 11.4
  • Compiler and version: GCC 12.1.0 and LLVM 15.0.0

To reproduce 2. cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on <srcdir> 4. make

/vol/llvm/src/llvm-project/benchmark/benchmark.git/src/sysinfo.cc: In function ‘std::string benchmark::{anonymous}::GetSystemName()’:
/vol/llvm/src/llvm-project/benchmark/benchmark.git/src/sysinfo.cc:446:54: note: ‘#pragma message: HOST_NAME_MAX not defined. using 64’
  446 | #pragma message("HOST_NAME_MAX not defined. using 64")
      |        
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:13:11: error: ‘namespace single { }’ redeclared as different kind of entity
   13 | namespace single {
      |           ^~~~~~
In file included from /usr/gcc/12/lib/gcc/x86_64-pc-solaris2.11/12.1.0/include-fixed/math.h:391,
                 from /usr/gcc/12/include/c++/12.1.0/bits/std_abs.h:40,
                 from /usr/gcc/12/include/c++/12.1.0/cstdlib:77,
                 from /vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:3:
/usr/include/floatingpoint.h:69:15: note: previous declaration ‘typedef float single’
   69 | typedef float single;
      |               ^~~~~~
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc: In function ‘void DoSetup1(const benchmark::State&)’:
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:18:5: error: ‘single’ is not a class, namespace, or enumeration
   18 |   ++single::setup_call;
      |     ^~~~~~
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc: In function ‘void DoTeardown1(const benchmark::State&)’:
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:25:5: error: ‘single’ is not a class, namespace, or enumeration
   25 |   ++single::teardown_call;
      |     ^~~~~~
In file included from /usr/gcc/12/include/c++/12.1.0/cassert:44,
                 from /vol/llvm/src/llvm-project/benchmark/benchmark.git/include/benchmark/benchmark.h:180,
                 from /vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:9:
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc: In function ‘int main(int, char**)’:
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:137:10: error: ‘single’ is not a class, namespace, or enumeration
  137 |   assert(single::setup_call == 4);
      |          ^~~~~~
/vol/llvm/src/llvm-project/benchmark/benchmark.git/test/benchmark_setup_teardown_test.cc:138:10: error: ‘single’ is not a class, namespace, or enumeration
  138 |   assert(single::teardown_call == 4);
      |          ^~~~~~

The llvm-project in-tree benchmark used to compile with -Wcast-qual added, which produces additional errors:

/vol/llvm/src/llvm-project/benchmark/benchmark-rorth.git/src/sysinfo.cc:658:42: error: cast from 'const char *' to 'char *' drops const qualifier [-Werror,-Wcast-qual]
  kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
                                         ^
/vol/llvm/src/llvm-project/benchmark/benchmark-rorth.git/src/sysinfo.cc:658:65: error: cast from 'const char *' to 'char *' drops const qualifier [-Werror,-Wcast-qual]
  kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
                                                                ^
/vol/llvm/src/llvm-project/benchmark/benchmark-rorth.git/src/sysinfo.cc:668:53: error: cast from 'const char *' to 'char *' drops const qualifier [-Werror,-Wcast-qual]
      (kstat_named_t*)kstat_data_lookup(ksp, (char*)"current_clock_Hz");
                                                    ^
3 errors generated.

Expected behavior The code should compile cleanly.

Additional context

  • Solaris needs to include <netdb.h> for MAXHOSTNAMELEN. Also, sysconf(3C) returns long.
  • Solaris <floatingpoint.h> has a conflicting single typedef. Rename the namespace to singlethreaded to avoid the conflict and reflect what's actually meant here.

I have a patch to fix these issues and mean to post a pull request once the CLA issue is sorted out (I should have one in place from golang work).

貢獻者指南