[PATCH rdma-core] Check for broken strict aliasing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At least the gcc 4.4 that comes with Centos6 does not support this
properly and throws bogus warnings.

Globally disable strict aliasing for safety on these compilers.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 CMakeLists.txt                 | 10 ++++++++++
 buildlib/RDMA_EnableCStd.cmake | 28 ++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

Here is the patch you wanted Steve.. It works for you?

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 859d7e85d0c274..99202a7548fbdb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,6 +276,13 @@ CHECK_C_SOURCE_COMPILES("
 RDMA_DoFixup("${HAVE_GLIBC_UAPI_COMPAT}" "linux/in.h")
 RDMA_DoFixup("${HAVE_GLIBC_UAPI_COMPAT}" "linux/in6.h")
 
+# The compiler has working -fstrict-aliasing support, old gcc's do not. If
+# broken then globally disable strict aliasing.
+RDMA_Check_Aliasing(HAVE_WORKING_STRICT_ALIASING)
+if (NOT HAVE_WORKING_STRICT_ALIASING)
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NO_STRICT_ALIASING_FLAGS}")
+endif()
+
 # Check if off_t is 64 bits, eg large file support is enabled
 CHECK_C_SOURCE_COMPILES("
 #include <sys/types.h>
@@ -557,6 +564,9 @@ endif()
 if (NOT HAVE_STATIC_ASSERT)
   message(STATUS " C11 static_assert NOT available (old compiler)")
 endif()
+if (NOT HAVE_WORKING_STRICT_ALIASING)
+  message(STATUS " Compiler cannot do strict aliasing")
+endif()
 if (NOT HAVE_VALGRIND_MEMCHECK)
   message(STATUS " Valgrind memcheck.h NOT enabled")
 endif()
diff --git a/buildlib/RDMA_EnableCStd.cmake b/buildlib/RDMA_EnableCStd.cmake
index c2e170929b7dde..dc448726c03cc8 100644
--- a/buildlib/RDMA_EnableCStd.cmake
+++ b/buildlib/RDMA_EnableCStd.cmake
@@ -57,3 +57,31 @@ function(RDMA_EnableCStd)
     set(CMAKE_C_STANDARD 11 PARENT_SCOPE)
   endif()
 endfunction()
+
+function(RDMA_Check_Aliasing TO_VAR)
+  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
+  CHECK_C_SOURCE_COMPILES("
+struct in6_addr {unsigned int u6_addr32[4];};
+struct iphdr {unsigned int daddr;};
+union ibv_gid {unsigned char raw[16];};
+
+static void map_ipv4_addr_to_ipv6(struct in6_addr *ipv6) {ipv6->u6_addr32[0] = 0;}
+static int set_ah_attr_by_ipv4(struct iphdr *ip4h)
+{
+	union ibv_gid sgid = {};
+	map_ipv4_addr_to_ipv6((struct in6_addr *)&sgid);
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	struct in6_addr a;
+	struct iphdr h = {};
+	map_ipv4_addr_to_ipv6(&a);
+	return set_ah_attr_by_ipv4(&h);
+}"
+    HAVE_WORKING_STRICT_ALIASING
+    FAIL_REGEX "warning")
+
+  set(${TO_VAR} "${HAVE_WORKING_STRICT_ALIASING}" PARENT_SCOPE)
+endfunction()
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux