[PATCH] D115342: [benchmarks] Unbreak third-party/benchmark build on Solaris
Rainer Orth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 8 06:47:05 PST 2021
ro created this revision.
ro added a reviewer: mtrofin.
Herald added subscribers: lebedev.ri, fedor.sergeev, jyknight.
Herald added a reviewer: lebedev.ri.
ro requested review of this revision.
Herald added a project: LLVM.
D112012 <https://reviews.llvm.org/D112012> broke the Solaris buildbots (sparcv9 <https://lab.llvm.org/staging/#/builders/50/builds/6611> and amd64 <https://lab.llvm.org/staging/#/builders/1
01/builds/5624>:
/vol/llvm/src/llvm-project/local/third-party/benchmark/src/sysinfo.cc:447:2: error: #warning is a language extension [-Werror,-Wpedantic]
#warning "HOST_NAME_MAX not defined. using 64"
^
/vol/llvm/src/llvm-project/local/third-party/benchmark/src/sysinfo.cc:447:2: error: "HOST_NAME_MAX not defined. using 64" [-Werror,-W#warnings]
/vol/llvm/src/llvm-project/local/third-party/benchmark/src/sysinfo.cc:475:16: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
int NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/vol/llvm/src/llvm-project/local/third-party/benchmark/src/sysinfo.cc:653: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/local/third-party/benchmark/src/sysinfo.cc:653: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/local/third-party/benchmark/src/sysinfo.cc:663: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");
^
- Solaris uses `MAXHOSTNAMELEN` which, contrary to `gethostname(3C) lives in `<netdb.h>`, not `<unistd.h>`.
- `sysconf` returns `long`, not `int`, so account for that
- `kstat_lookup` etc. need `const_cast`s
Tested on `amd64-pc-solaris2.11.`
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115342
Files:
third-party/benchmark/src/sysinfo.cc
Index: third-party/benchmark/src/sysinfo.cc
===================================================================
--- third-party/benchmark/src/sysinfo.cc
+++ third-party/benchmark/src/sysinfo.cc
@@ -37,6 +37,7 @@
#endif
#if defined(BENCHMARK_OS_SOLARIS)
#include <kstat.h>
+#include <netdb.h>
#endif
#if defined(BENCHMARK_OS_QNX)
#include <sys/syspage.h>
@@ -443,6 +444,8 @@
#define HOST_NAME_MAX 154
#elif defined(BENCHMARK_OS_RTEMS)
#define HOST_NAME_MAX 256
+#elif defined(BENCHMARK_OS_SOLARIS)
+#define HOST_NAME_MAX MAXHOSTNAMELEN
#else
#warning "HOST_NAME_MAX not defined. using 64"
#define HOST_NAME_MAX 64
@@ -472,13 +475,13 @@
// group
#elif defined(BENCHMARK_OS_SOLARIS)
// Returns -1 in case of a failure.
- int NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
+ long NumCPU = sysconf(_SC_NPROCESSORS_ONLN);
if (NumCPU < 0) {
fprintf(stderr,
"sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
strerror(errno));
}
- return NumCPU;
+ return (int)NumCPU;
#elif defined(BENCHMARK_OS_QNX)
return static_cast<int>(_syspage_ptr->num_cpu);
#else
@@ -650,7 +653,8 @@
std::cerr << "failed to open /dev/kstat\n";
return -1;
}
- kstat_t *ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
+ kstat_t *ksp = kstat_lookup(kc, const_cast<char *>("cpu_info"), -1,
+ const_cast<char *>("cpu_info0"));
if (!ksp) {
std::cerr << "failed to lookup in /dev/kstat\n";
return -1;
@@ -659,8 +663,8 @@
std::cerr << "failed to read from /dev/kstat\n";
return -1;
}
- kstat_named_t *knp =
- (kstat_named_t*)kstat_data_lookup(ksp, (char*)"current_clock_Hz");
+ kstat_named_t *knp = (kstat_named_t *)kstat_data_lookup(
+ ksp, const_cast<char *>("current_clock_Hz"));
if (!knp) {
std::cerr << "failed to lookup data in /dev/kstat\n";
return -1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115342.392733.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211208/ef274b03/attachment.bin>
More information about the llvm-commits
mailing list