[applied] Better detect suitable libctf version

Message ID 87fscig17x.fsf@redhat.com
State New
Headers
Series [applied] Better detect suitable libctf version |

Commit Message

Dodji Seketeli Jan. 10, 2023, 9:58 a.m. UTC
  Hello,

On some el9 distros, the version of libctf installed might not have
all the necessary features for the libabigail CTF reader, leading to
compilation errors due to missing types from the ctf-api.h header
file.  For instance, the ctf-api.h on some of those distros lacks the
definition of the type struct ctf_dict_t.

This patch adds a configure test for that struct and disables the CTF
support if that type is absent.

	* configure.ac: If the "struct ctf_dict_t" type is not present in
	the version of ctf-api.h that is present, then switch the support
	of CTF off.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 configure.ac | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
  

Patch

diff --git a/configure.ac b/configure.ac
index d2896020..d19c2f96 100644
--- a/configure.ac
+++ b/configure.ac
@@ -333,6 +333,23 @@  if test x$ENABLE_CTF != xno; then
        AC_CHECK_LIB(ctf, ctf_open, [LIBCTF=yes], [LIBCTF=no])
   fi
 
+  if test x$LIBCTF = xyes; then
+    dnl Test if struct btf_enum64 is present.
+    AC_CHECK_TYPE([struct ctf_dict_t],
+    		  [HAVE_CTF_DICT_T=yes],
+		  [HAVE_CTF_DICT_T=no],
+		  [#include <ctf-api.h>])
+
+    if test x$HAVE_CTF_DICT_T = xyes; then
+      AC_DEFINE([HAVE_CTF_DICT_T], 1, [struct ctf_dict_t is present])
+    fi
+  fi
+
+  if test x$HAVE_CTF_DICT_T = xno; then
+     AC_MSG_NOTICE([Some needed data structures are missing from ctf-api.h. Disabling CTF support.])
+     LIBCTF=no
+  fi
+
   if test x$LIBCTF = xyes; then
     AC_MSG_NOTICE([CTF support enabled])
     AC_DEFINE([WITH_CTF], 1,
@@ -340,7 +357,7 @@  if test x$ENABLE_CTF != xno; then
     CTF_LIBS=-lctf
     ENABLE_CTF=yes
   else
-    AC_MSG_NOTICE([no libctf found, CTF support was disabled])
+    AC_MSG_NOTICE([no suitable libctf found, CTF support was disabled])
     ENABLE_CTF=no
   fi
 fi