diff mbox

[rdma-core] Fix compiler warnings on PPC64 and others

Message ID 20180208224506.GA2462@ziepe.ca (mailing list archive)
State Accepted
Delegated to: Leon Romanovsky
Headers show

Commit Message

Jason Gunthorpe Feb. 8, 2018, 10:45 p.m. UTC
We have places in our code that assume __u64 is unsigned long long, and in
general this is the Linux kernel standard. However a few archs still use
unsigned long by default and require a -D__SANE_USERSPACE_TYPES__ to get
long long.

Detect this and provide the define to eliminate compilation warnings.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
---
 CMakeLists.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e63f4cf563677a..b08d3fd2cf4246 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -250,6 +250,20 @@  CHECK_C_SOURCE_COMPILES("
   HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE
   FAIL_REGEX "warning")
 
+# Linux __u64 is an unsigned long long
+CHECK_C_SOURCE_COMPILES("
+#include <linux/types.h>
+ int main(int argc,const char *argv[]) { __u64 tmp = 0; unsigned long long *tmp2 = &tmp; return *tmp2; }"
+  HAVE_LONG_LONG_U64
+  FAIL_REGEX "warning")
+
+if (NOT HAVE_LONG_LONG_U64)
+  # Modern Linux has switched to use ull in all cases, but to avoid disturbing
+  # userspace some platforms continued to use unsigned long by default. This
+  # define will cause kernel headers to consistently use unsigned long long
+  add_definitions("-D__SANE_USERSPACE_TYPES__")
+endif()
+
 # Provide a shim if C11 stdatomic.h is not supported.
 if (NOT HAVE_SPARSE)
   CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC)