loader: Only use alloca.h if it exists otherwise fallback to stdlib.h
authorBrad Smith <brad@comstyle.com>
Fri, 2 Sep 2022 22:55:12 +0000 (18:55 -0400)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 2 Sep 2022 23:52:37 +0000 (17:52 -0600)
Check for the existence of the alloca.h header and only use it it exists,
otherwise fallback to stdlib.h. Some OS's like macOS and QNX have both
headers and can use either (stdlib.h includes alloca.h), some OS's like
OpenBSD / FreeBSD / NetBSD do not have the alloca.h header and require
the stdlib.h header.

loader/CMakeLists.txt
loader/stack_allocation.h

index 9235fa244862727639c1286c6d4c55d74c8f3e2a..66ad8cc5031d1837a9b674251a5878d122121c89 100644 (file)
@@ -95,6 +95,10 @@ else()
     if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
         target_compile_definitions(loader_specific_options INTERFACE __BSD_VISIBLE=1)
     endif()
+    check_include_file("alloca.h" HAVE_ALLOCA_H)
+    if(HAVE_ALLOCA_H)
+        target_compile_definitions(loader_specific_options INTERFACE HAVE_ALLOCA_H)
+    endif()
 endif()
 
 set(NORMAL_LOADER_SRCS
index c724de6cab46febc57789bd14a800bb9cd239e2f..d1958fbdccc906d56b143d0be082b1e3c83ef81c 100644 (file)
 
 #if defined(_WIN32)
 #include <malloc.h>
-#else
+#elif defined(HAVE_ALLOCA_H)
 #include <alloca.h>
+#else
+#include <stdlib.h>
 #endif
 
 #if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)