From f00a54f72ffd8b318b29561f02d32a8a6450c6ad Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Wed, 16 Oct 2019 05:25:29 -0400 Subject: [PATCH 1/3] Handle glibc sys/sysctl.h deprecation (#27048) glibc has deprecated sys/sysctl.h: In file included from /coreclr/src/pal/src/misc/sysinfo.cpp:32: /usr/include/sys/sysctl.h:21:2: error: "The header is deprecated and will be removed." [-Werror,-W#warnings] #warning "The header is deprecated and will be removed." ^ 1 error generated. Fix that by preferring sysconf and only including sys/sysctl.h if HAVE_SYSCONF is not true. This mirrors the order of the implementation code in this file (sysinfo.cpp) which checks for HAVE_SYSCONF before HAVE_SYSCTL. Fixes #27008 --- src/pal/src/misc/sysinfo.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index 52e8ec065d73..b8a6a7033356 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -28,9 +28,12 @@ Revision History: #define __STDC_FORMAT_MACROS #include #include -#if HAVE_SYSCTL + +#if HAVE_SYSCONF +// already included above +#elif HAVE_SYSCTL #include -#elif !HAVE_SYSCONF +#else #error Either sysctl or sysconf is required for GetSystemInfo. #endif From de84370eb61dfc64076de44b4e3cdbd8dcfed788 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid Date: Fri, 7 Feb 2020 20:37:10 +0200 Subject: [PATCH 2/3] Fix FreeBSD native build (#31865) --- src/pal/src/misc/sysinfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index b8a6a7033356..e3574fa23a6c 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -37,6 +37,10 @@ Revision History: #error Either sysctl or sysconf is required for GetSystemInfo. #endif +#if HAVE_SYSCTLBYNAME +#include +#endif + #if HAVE_SYSINFO #include #endif From a9d2b4f379376f31f9385c6658c504e0d4641d7f Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Fri, 7 Feb 2020 19:17:24 -0500 Subject: [PATCH 3/3] Only use sys/sysctl.h on non-Linux Guard it with HAVE_SYSCONF/HAVE_XSW_USAGE, just like it is done in master and dotnet/runtime. --- src/gc/unix/gcenv.unix.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp index e7da60747504..bd0c3fd599d4 100644 --- a/src/gc/unix/gcenv.unix.cpp +++ b/src/gc/unix/gcenv.unix.cpp @@ -42,6 +42,10 @@ #include #endif // HAVE_XSWDEV +#if HAVE_XSW_USAGE +#include +#endif // HAVE_XSW_USAGE + #ifdef __APPLE__ #include #include @@ -49,8 +53,12 @@ #include #endif // __APPLE__ -#if HAVE_SYSCTL +#if HAVE_SYSCONF +// already included above +#elif HAVE_SYSCTL #include +#else +#error "Don't know how to get total physical memory on this platform" #endif #ifdef __linux__