]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Add ifunc check to CMakeLists.txt
authorHans Jansen <hansjansen162@outlook.com>
Thu, 22 Jun 2023 17:49:30 +0000 (19:49 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 27 Jun 2023 12:33:15 +0000 (15:33 +0300)
CMake build system will now verify if __attribute__((__ifunc__())) can be
used in the build system. If so, HAVE_FUNC_ATTRIBUTE_IFUNC will be
defined to 1.

CMakeLists.txt

index 458ad49de1d8287dab862e51cb002fca36eaea7e..fb5d2582d7e23507b45401badbdccfba11e4f5d2 100644 (file)
@@ -763,6 +763,25 @@ check_c_source_compiles("
 cmake_pop_check_state()
 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
 
+# Check for __attribute__((__ifunc__())) support.
+option(CHECK_ATTR_IFUNC "Use __attribute__((__ifunc__())) if supported by \
+the system" ON)
+
+if (CHECK_ATTR_IFUNC)
+    cmake_push_check_state()
+    set(CMAKE_REQUIRED_FLAGS "-Werror")
+    check_c_source_compiles("
+            static void func(void) { return; }
+            static void (*resolve_func (void)) (void) { return func; }
+            void func_ifunc (void)
+                    __attribute__ ((__ifunc__ (\"resolve_func\")));
+            int main(void) { return 0; }
+        "
+        HAVE_FUNC_ATTRIBUTE_IFUNC)
+    cmake_pop_check_state()
+    tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_IFUNC)
+endif()
+
 # cpuid.h
 check_include_file(cpuid.h HAVE_CPUID_H)
 tuklib_add_definition_if(liblzma HAVE_CPUID_H)