Fix: elfutils detection fallback for sles12
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 16 Sep 2020 18:46:55 +0000 (14:46 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Oct 2020 20:27:26 +0000 (16:27 -0400)
Turns out SLES12 doesn't bother shipping .pc files for elfutils, add a
fallback compile test that will work even in cross-compilation.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia31b9add4831a9c4a67a440e7b1777d5f12d94d9

configure.ac
m4/ae_lib_elfutils.m4 [new file with mode: 0644]

index f424973d531bbaf7ff024d61468c3ca13346b19d..8c7dec29bc236e443d00ff66870b1606530e9a8e 100644 (file)
@@ -543,7 +543,14 @@ AE_IF_FEATURE_ENABLED([debug-info], [
       dnl PKG_CHECK_MODULES defines ELFUTILS_LIBS
     ],
     [
       dnl PKG_CHECK_MODULES defines ELFUTILS_LIBS
     ],
     [
-      AC_MSG_ERROR([elfutils >= 0.154 is required to use the debug info feature. You can disable this feature using --disable-debug-info.])
+      AC_MSG_WARN([pkg-config was unable to find a valid .pc for libelf/libdw. Set PKG_CONFIG_PATH to specify the pkg-config configuration file location.])
+
+      # Turns out SLES12 doesn't bother shipping .pc file for libelf
+      AC_MSG_WARN([Finding libelf without pkg-config.])
+      AC_CHECK_LIB([elf], [elf_version], [], [AC_MSG_ERROR(Missing libelf (from elfutils >= 0.154) which is required by debug info. You can disable this feature using --disable-debug-info.)])
+      AC_CHECK_LIB([dw], [dwarf_begin], [], [AC_MSG_ERROR(Missing libdw (from elfutils >= 0.154) which is required by debug info. You can disable this feature using --disable-debug-info.)])
+      AE_LIB_ELFUTILS([0], [154], [], [AC_MSG_ERROR(elfutils >= 0.154 is required to use the debug info feature. You can disable this feature using --disable-debug-info.)])
+      ELFUTILS_LIBS="-lelf -ldw"
     ])
 ])
 AC_SUBST([ELFUTILS_LIBS])
     ])
 ])
 AC_SUBST([ELFUTILS_LIBS])
diff --git a/m4/ae_lib_elfutils.m4 b/m4/ae_lib_elfutils.m4
new file mode 100644 (file)
index 0000000..5030091
--- /dev/null
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: MIT
+#
+# Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+# Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+#
+# ae_lib_elfutils.m4 -- Check elfutils version
+#
+# Check the currently installed version of elfutils by using the
+# `_ELFUTILS_PREREQ` macro defined in <elfutils/version.h>.
+#
+# The cache variable for this test is `ae_cv_lib_elfutils`.
+#
+# AE_LIB_ELFUTILS(MAJOR_VERSION, MINOR_VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ---------------------------------------------------------------------------
+AC_DEFUN([AE_LIB_ELFUTILS], [
+m4_pushdef([major_version], [$1])
+m4_pushdef([minor_version], [$2])
+m4_pushdef([true_action], m4_default([$3], [:]))
+m4_pushdef([false_action], m4_default(
+       [$4], [AC_MSG_ERROR(elfutils >= major_version.minor_version is required)]
+))
+
+AC_CACHE_CHECK(
+       [for elfutils version >= major_version.minor_version],
+       [ae_cv_lib_elfutils], [
+       AC_LANG_PUSH([C])
+       AC_COMPILE_IFELSE(
+               [AC_LANG_SOURCE([
+               #include <elfutils/version.h>
+
+               #if (!_ELFUTILS_PREREQ(][]major_version[][, ][]minor_version[][))
+               #error "elfutils minimum required version not met."
+               #endif
+
+               void main(void) {
+                       return;
+               }
+               ])],
+               [ae_cv_lib_elfutils=yes],
+               [ae_cv_lib_elfutils=no]
+       )
+       AC_LANG_POP([C])
+])
+
+AS_IF([test "x$ae_cv_lib_elfutils" = "xyes"], [true_action], [false_action])
+
+m4_popdef([false_action])
+m4_popdef([true_action])
+m4_popdef([minor_version])
+m4_popdef([major_version])
+])
This page took 0.025418 seconds and 4 git commands to generate.