libbacktrace: check for sys/link.h

QNX uses sys/link.h rather than link.h for dl_iterate_phdr

Fixes #86

	* configure.ac: Check for sys/link.h.  Use either link.h or
	sys/link.h when checking for dl_iterate_phdr.
	* elf.c: Include sys/link.h if available.
	* configure, config.h.in: Regenerate.
This commit is contained in:
Ian Lance Taylor
2022-07-08 10:28:24 -07:00
parent 7409767403
commit 8602fda64e
4 changed files with 27 additions and 10 deletions

View File

@@ -85,6 +85,9 @@
/* Define to 1 if you have the <sys/ldr.h> header file. */ /* Define to 1 if you have the <sys/ldr.h> header file. */
#undef HAVE_SYS_LDR_H #undef HAVE_SYS_LDR_H
/* Define to 1 if you have the <sys/link.h> header file. */
#undef HAVE_SYS_LINK_H
/* Define to 1 if you have the <sys/mman.h> header file. */ /* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H #undef HAVE_SYS_MMAN_H

17
configure vendored
View File

@@ -12316,26 +12316,31 @@ fi
# Check for dl_iterate_phdr. # Check for dl_iterate_phdr.
for ac_header in link.h for ac_header in link.h sys/link.h
do : do :
ac_fn_c_check_header_mongrel "$LINENO" "link.h" "ac_cv_header_link_h" "$ac_includes_default" as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
if test "x$ac_cv_header_link_h" = xyes; then : ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_LINK_H 1 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF _ACEOF
fi fi
done done
if test "$ac_cv_header_link_h" = "no"; then if test "$ac_cv_header_link_h" = "no" -a "$ac_cv_header_sys_link_h" = "no"; then
have_dl_iterate_phdr=no have_dl_iterate_phdr=no
else else
if test -n "${with_target_subdir}"; then if test -n "${with_target_subdir}"; then
link_h=link.h
if test "$ac_cv_header_link_h" = "no"; then
link_h=sys/link.h
fi
# When built as a GCC target library, we can't do a link test. # When built as a GCC target library, we can't do a link test.
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
#include <link.h> #include <$link_h>
_ACEOF _ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |

View File

@@ -325,13 +325,17 @@ fi
AC_SUBST(BACKTRACE_USES_MALLOC) AC_SUBST(BACKTRACE_USES_MALLOC)
# Check for dl_iterate_phdr. # Check for dl_iterate_phdr.
AC_CHECK_HEADERS(link.h) AC_CHECK_HEADERS(link.h sys/link.h)
if test "$ac_cv_header_link_h" = "no"; then if test "$ac_cv_header_link_h" = "no" -a "$ac_cv_header_sys_link_h" = "no"; then
have_dl_iterate_phdr=no have_dl_iterate_phdr=no
else else
if test -n "${with_target_subdir}"; then if test -n "${with_target_subdir}"; then
link_h=link.h
if test "$ac_cv_header_link_h" = "no"; then
link_h=sys/link.h
fi
# When built as a GCC target library, we can't do a link test. # When built as a GCC target library, we can't do a link test.
AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes], AC_EGREP_HEADER([dl_iterate_phdr], [$link_h], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no]) [have_dl_iterate_phdr=no])
case "${host}" in case "${host}" in
*-*-solaris2.10*) *-*-solaris2.10*)

7
elf.c
View File

@@ -40,7 +40,12 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_DL_ITERATE_PHDR #ifdef HAVE_DL_ITERATE_PHDR
#include <link.h> #ifdef HAVE_LINK_H
#include <link.h>
#endif
#ifdef HAVE_SYS_LINK_H
#include <sys/link.h>
#endif
#endif #endif
#include "backtrace.h" #include "backtrace.h"