mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-01-09 03:08:38 +01:00
6faea4d2a0
The GNU .init_array support is an extension over the standard System V ABI .init_array support, which passes the main() arguments to the init function. This support comes in three parts. First the dynamic linker (from glibc) needs to support it. Then function pointers need to be placed in the section, for example by using __attribute__((constructor)), that the compiler (gcc or clang for example) might place in section .ctors and the linker (from binutils) will move to .init_array on the output object, or by placing them directly into .init_array by the compiler when compiling. If this does not happen and the function pointers end up in .ctors, then they will not get passed the main() arguments, which we do really need in this case. But this relies on recent binutils or gcc having native .init_array support, and not having it disabled through --disable-initfini-array. To guarantee we get the correct behaviour, let's just place the function pointer in the .init_array section directly, so we only require a recent enough glibc. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=65029
133 lines
3.5 KiB
Plaintext
133 lines
3.5 KiB
Plaintext
# Process this file with autoconf to produce a configure script.
|
|
|
|
AC_PREREQ([2.67])
|
|
AC_INIT([libbsd], m4_esyscmd([./get-version]), [libbsd@lists.freedesktop.org])
|
|
AC_CONFIG_SRCDIR([src/fgetln.c])
|
|
AC_CONFIG_AUX_DIR([build-aux])
|
|
AC_CONFIG_MACRO_DIR([m4])
|
|
|
|
AM_INIT_AUTOMAKE([1.8 foreign nostdinc no-dist-gzip dist-xz])
|
|
|
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
|
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
|
|
|
# Check and store if we got user supplied variables
|
|
user_CFLAGS=${CFLAGS-unset}
|
|
|
|
# Checks for operating system services and capabilities.
|
|
AC_USE_SYSTEM_EXTENSIONS
|
|
AC_SYS_LARGEFILE
|
|
|
|
LT_INIT
|
|
|
|
# Checks for programs.
|
|
AC_PROG_CC
|
|
AC_PROG_INSTALL
|
|
AC_PROG_LN_S
|
|
|
|
# Set default compiler variables
|
|
if test "$user_CFLAGS" = unset && test "$GCC" = yes; then
|
|
CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter"
|
|
fi
|
|
|
|
# Checks for libraries.
|
|
|
|
# Checks for header files.
|
|
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h dir.h dirent.h])
|
|
|
|
# Checks for typedefs, structures, and compiler characteristics.
|
|
AC_TYPE_UID_T
|
|
AC_C_INLINE
|
|
AC_C_TYPEOF
|
|
AC_TYPE_INT64_T
|
|
AC_TYPE_MODE_T
|
|
AC_TYPE_OFF_T
|
|
AC_TYPE_PID_T
|
|
AC_TYPE_SIZE_T
|
|
AC_TYPE_SSIZE_T
|
|
|
|
AC_CHECK_DECL([F_CLOSEM],
|
|
[AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
|
[Define to 1 if you have fcntl(F_CLOSEM)])],
|
|
[],
|
|
[#include <limits.h>
|
|
#include <fcntl.h>])
|
|
|
|
AC_CACHE_CHECK(
|
|
[for GNU .init_array section support],
|
|
[libbsd_cv_gnu_init_array_support],
|
|
[AC_RUN_IFELSE(
|
|
[AC_LANG_SOURCE(
|
|
[[
|
|
static int rc = 1;
|
|
static void init(int argc) { if (argc == 1) rc = 0; }
|
|
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
|
|
int main() { return rc; }
|
|
]]
|
|
)],
|
|
[libbsd_cv_gnu_init_array_support=yes],
|
|
[libbsd_cv_gnu_init_array_support=no],
|
|
[AC_PREPROC_IFELSE(
|
|
[AC_LANG_SOURCE(
|
|
[[
|
|
/* Look for a known libc that supports .init_array with the GNU extension
|
|
* to pass main() arguments to the init functions. */
|
|
#include <stdlib.h>
|
|
#if defined __GLIBC_PREREQ
|
|
# if __GLIBC_PREREQ(2, 4)
|
|
/* glibc supports GNU .init_array since 2.4. */
|
|
# else
|
|
# error glibc does not support GNU .init_array
|
|
# endif
|
|
#else
|
|
/*
|
|
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
|
* - Bionic since its inception.
|
|
* - uClibc since 0.9.29.
|
|
*/
|
|
# error unknown whether libc supports GNU .init_array
|
|
#endif
|
|
]]
|
|
)],
|
|
[libbsd_cv_gnu_init_array_support=yes],
|
|
[libbsd_cv_gnu_init_array_support=no])
|
|
]
|
|
)]
|
|
)
|
|
if test "$libbsd_cv_gnu_init_array_support" = no; then
|
|
AC_MSG_ERROR([missing required GNU .init_array section support])
|
|
fi
|
|
|
|
# Checks for library functions.
|
|
AC_MSG_CHECKING([for program_invocation_short_name])
|
|
AC_LINK_IFELSE(
|
|
[AC_LANG_PROGRAM([[#include <errno.h>]],
|
|
[[const char *p = program_invocation_short_name;]])],
|
|
[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
|
[Define to 1 if you have program_invocation_short_name])
|
|
AC_MSG_RESULT([yes])],
|
|
[AC_MSG_RESULT([no])])
|
|
|
|
AC_MSG_CHECKING([for __progname])
|
|
AC_LINK_IFELSE(
|
|
[AC_LANG_PROGRAM([[]],
|
|
[[extern char *__progname;
|
|
const char *p = __progname;]])],
|
|
[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
|
AC_MSG_RESULT([yes])],
|
|
[AC_MSG_RESULT([no])])
|
|
|
|
AC_CHECK_FUNCS([clearenv dirfd __fpurge getexecname getline sysconf])
|
|
|
|
AC_CONFIG_FILES([
|
|
Makefile
|
|
include/Makefile
|
|
man/Makefile
|
|
src/Makefile
|
|
src/libbsd.pc
|
|
src/libbsd-overlay.pc
|
|
test/Makefile
|
|
])
|
|
AC_CONFIG_HEADERS([config.h])
|
|
AC_OUTPUT
|