From 11e4ef95716cad79a9cbe34ea39e623a60d8431c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sat, 8 Feb 2025 11:30:06 +0100 Subject: [PATCH] Add latest m4 files --- m4/musl.m4 | 22 +++++ m4/relocatable-lib.m4 | 51 +++++++++++ m4/sigaltstack.m4 | 200 ++++++++++++++++++++++++++++++++++++++++++ m4/stack-direction.m4 | 128 +++++++++++++++++++++++++++ 4 files changed, 401 insertions(+) create mode 100644 m4/musl.m4 create mode 100644 m4/relocatable-lib.m4 create mode 100644 m4/sigaltstack.m4 create mode 100644 m4/stack-direction.m4 diff --git a/m4/musl.m4 b/m4/musl.m4 new file mode 100644 index 0000000..6ff778c --- /dev/null +++ b/m4/musl.m4 @@ -0,0 +1,22 @@ +# musl.m4 +# serial 4 +dnl Copyright (C) 2019-2025 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl This file is offered as-is, without any warranty. + +# Test for musl libc, despite the musl libc authors don't like it +# +# . +# From Bruno Haible. + +AC_DEFUN_ONCE([gl_MUSL_LIBC], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + *-musl* | midipix*) + AC_DEFINE([MUSL_LIBC], [1], [Define to 1 on musl libc.]) + ;; + esac +]) diff --git a/m4/relocatable-lib.m4 b/m4/relocatable-lib.m4 new file mode 100644 index 0000000..5efed52 --- /dev/null +++ b/m4/relocatable-lib.m4 @@ -0,0 +1,51 @@ +# relocatable-lib.m4 +# serial 8 +dnl Copyright (C) 2003, 2005-2007, 2009-2025 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl This file is offered as-is, without any warranty. + +dnl From Bruno Haible. + +dnl Support for relocatable libraries. +AC_DEFUN([gl_RELOCATABLE_LIBRARY], +[ + AC_REQUIRE([gl_RELOCATABLE_LIBRARY_BODY]) +]) +AC_DEFUN([gl_RELOCATABLE_LIBRARY_BODY], +[ + AC_REQUIRE([gl_RELOCATABLE_NOP]) + dnl Easier to put this here once, instead of into the DEFS of each Makefile. + if test "X$prefix" = "XNONE"; then + reloc_final_prefix="$ac_default_prefix" + else + reloc_final_prefix="$prefix" + fi + dnl Define reloc_final_prefix_c and reloc_final_prefix_c_make. + gl_BUILD_TO_HOST([reloc_final_prefix]) + AC_DEFINE_UNQUOTED([INSTALLPREFIX], [${reloc_final_prefix_c}], + [Define to the value of ${prefix}, as a string.]) + if test $RELOCATABLE = yes; then + AC_DEFINE([ENABLE_RELOCATABLE], [1], + [Define to 1 if the package shall run at any location in the file + system.]) + fi +]) + +dnl Support for relocatable packages for which it is a nop. +AC_DEFUN([gl_RELOCATABLE_NOP], +[ + AC_MSG_CHECKING([whether to activate relocatable installation]) + AC_ARG_ENABLE([relocatable], + [AS_HELP_STRING([[--enable-relocatable]], + [install a package that can be moved in the file system])], + [if test "$enableval" != no; then + RELOCATABLE=yes + else + RELOCATABLE=no + fi + ], RELOCATABLE=no) + AC_SUBST([RELOCATABLE]) + AC_MSG_RESULT([$RELOCATABLE]) +]) diff --git a/m4/sigaltstack.m4 b/m4/sigaltstack.m4 new file mode 100644 index 0000000..21cd103 --- /dev/null +++ b/m4/sigaltstack.m4 @@ -0,0 +1,200 @@ +# sigaltstack.m4 +# serial 16 +dnl Copyright (C) 2002-2025 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License as published by the Free Software Foundation; +dnl either version 2 of the License, or (at your option) any later version. +dnl As a special exception to the GNU General Public License, this file +dnl may be distributed as part of a program that contains a configuration +dnl script generated by Autoconf, under the same distribution terms as +dnl the rest of that program. + +dnl Written by Bruno Haible and Eric Blake. + +AC_DEFUN([SV_SIGALTSTACK], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + AC_CHECK_FUNCS_ONCE([sigaltstack setrlimit]) + + if test "$ac_cv_func_sigaltstack" = yes; then + AC_CHECK_TYPE([stack_t], , + [AC_DEFINE(stack_t, [struct sigaltstack], + [Define to 'struct sigaltstack' if that's the type of the argument to sigaltstack]) + ], + [ +#include +#if HAVE_SYS_SIGNAL_H +# include +#endif + ]) + fi + + AC_CACHE_CHECK([for working sigaltstack], [sv_cv_sigaltstack], [ + if test "$ac_cv_func_sigaltstack" = yes; then + case "$host_os" in + macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) + # On MacOS X 10.2 or newer, just assume that if it compiles, it will + # work. If we were to perform the real test, 1 Crash Report dialog + # window would pop up. + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[#include ]], + [[int x = SA_ONSTACK; stack_t ss; sigaltstack ((stack_t*)0, &ss);]])], + [sv_cv_sigaltstack="guessing yes"], + [sv_cv_sigaltstack=no]) + ;; + *) + AC_RUN_IFELSE([ + AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SYS_SIGNAL_H +# include +#endif +#if HAVE_SETRLIMIT +# include +# include +# include +#endif +void stackoverflow_handler (int sig) +{ + /* If we get here, the stack overflow was caught. */ + exit (0); +} +volatile int * recurse_1 (volatile int n, volatile int *p) +{ + if (n >= 0) + *recurse_1 (n + 1, p) += n; + return p; +} +int recurse (volatile int n) +{ + int sum = 0; + return *recurse_1 (n, &sum); +} +char mystack[2 * (1 << 24)]; +int main () +{ + stack_t altstack; + struct sigaction action; +#if defined HAVE_SETRLIMIT && defined RLIMIT_STACK + /* Before starting the endless recursion, try to be friendly to the user's + machine. On some Linux 2.2.x systems, there is no stack limit for user + processes at all. We don't want to kill such systems. */ + struct rlimit rl; + rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ + setrlimit (RLIMIT_STACK, &rl); +#endif + /* Install the alternate stack. Use the midpoint of mystack, to guard + against a buggy interpretation of ss_sp on IRIX. */ +#ifdef SIGSTKSZ + if (sizeof mystack / 2 < SIGSTKSZ) + exit (3); +#endif + altstack.ss_sp = mystack + sizeof mystack / 2; + altstack.ss_size = sizeof mystack / 2; + altstack.ss_flags = 0; /* no SS_DISABLE */ + if (sigaltstack (&altstack, NULL) < 0) + exit (1); + /* Install the SIGSEGV handler. */ + sigemptyset (&action.sa_mask); + action.sa_handler = &stackoverflow_handler; + action.sa_flags = SA_ONSTACK; + sigaction (SIGSEGV, &action, (struct sigaction *) NULL); + sigaction (SIGBUS, &action, (struct sigaction *) NULL); + /* Provoke a stack overflow. */ + recurse (0); + exit (2); +}]])], + [sv_cv_sigaltstack=yes], + [sv_cv_sigaltstack=no], + [ + dnl FIXME: Put in some more known values here. + case "$host_os" in + *) + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[#include ]], + [[int x = SA_ONSTACK; stack_t ss; sigaltstack ((stack_t*)0, &ss);]])], + [sv_cv_sigaltstack="guessing yes"], + [sv_cv_sigaltstack=no]) + ;; + esac + ]) + ;; + esac + else + sv_cv_sigaltstack=no + fi + ]) + if test "$sv_cv_sigaltstack" != no; then + AC_DEFINE([HAVE_WORKING_SIGALTSTACK], [1], + [Define if you have the sigaltstack() function and it works.]) + + dnl The ss_sp field of a stack_t is, according to POSIX, the lowest address + dnl of the memory block designated as an alternate stack. But IRIX 5.3 + dnl interprets it as the highest address! + AC_CACHE_CHECK([for correct stack_t interpretation], + [sv_cv_sigaltstack_low_base], [ + AC_RUN_IFELSE([ + AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SYS_SIGNAL_H +# include +#endif +volatile char *stack_lower_bound; +volatile char *stack_upper_bound; +static void check_stack_location (volatile char *addr) +{ + if (addr >= stack_lower_bound && addr <= stack_upper_bound) + exit (0); + else + exit (1); +} +static void stackoverflow_handler (int sig) +{ + char dummy; + check_stack_location (&dummy); +} +char mystack[2 * (1 << 24)]; +int main () +{ + stack_t altstack; + struct sigaction action; + /* Install the alternate stack. */ + altstack.ss_sp = mystack + sizeof mystack / 2; + altstack.ss_size = sizeof mystack / 2; + stack_lower_bound = (char *) altstack.ss_sp; + stack_upper_bound = (char *) altstack.ss_sp + altstack.ss_size - 1; + altstack.ss_flags = 0; /* no SS_DISABLE */ + if (sigaltstack (&altstack, NULL) < 0) + exit (2); + /* Install the SIGSEGV handler. */ + sigemptyset (&action.sa_mask); + action.sa_handler = &stackoverflow_handler; + action.sa_flags = SA_ONSTACK; + if (sigaction (SIGSEGV, &action, (struct sigaction *) NULL) < 0) + exit(3); + /* Provoke a SIGSEGV. */ + raise (SIGSEGV); + exit (3); +}]])], + [sv_cv_sigaltstack_low_base=yes], + [sv_cv_sigaltstack_low_base=no], + [ + dnl FIXME: Put in some more known values here. + case "$host_os" in + irix5*) sv_cv_sigaltstack_low_base="no" ;; + *) sv_cv_sigaltstack_low_base="guessing yes" ;; + esac + ]) + ]) + if test "$sv_cv_sigaltstack_low_base" = no; then + AC_DEFINE([SIGALTSTACK_SS_REVERSED], [1], + [Define if sigaltstack() interprets the stack_t.ss_sp field incorrectly, + as the highest address of the alternate stack range rather than as the + lowest address.]) + fi + fi +]) diff --git a/m4/stack-direction.m4 b/m4/stack-direction.m4 new file mode 100644 index 0000000..c82304f --- /dev/null +++ b/m4/stack-direction.m4 @@ -0,0 +1,128 @@ +# stack-direction.m4 +# serial 12 +dnl Copyright (C) 2002-2025 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License as published by the Free Software Foundation; +dnl either version 2 of the License, or (at your option) any later version. +dnl As a special exception to the GNU General Public License, this file +dnl may be distributed as part of a program that contains a configuration +dnl script generated by Autoconf, under the same distribution terms as +dnl the rest of that program. + +dnl Written by Bruno Haible. + +# Determine the stack direction. Define the C macro STACK_DIRECTION. +AC_DEFUN([SV_STACK_DIRECTION], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [ + case "$host_cpu" in + dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h. + a29k | \ + aarch64* | \ + alpha* | \ + arc | arceb | arc32 | arc64 | \ + arm* | strongarm* | xscale* | \ + avr | avr32 | \ + bfin | \ + c1 | c2 | c32 | c34 | c38 | \ + clipper | \ + cr16 | \ + cris | \ + csky | \ + d30v | \ + epiphany | \ + elxsi | \ + fr30 | \ + frv | \ + ft32 | \ + h8300 | \ + i?86 | x86_64 | \ + i860 | \ + ia64 | \ + iq2000 | \ + lm32 | \ + loongarch* | \ + m32c | \ + m32r | \ + m68* | \ + m88k | \ + mcore | \ + microblaze* | \ + mips* | \ + mmix | \ + mn10200 | \ + mn10300 | \ + moxie | \ + msp430 | \ + nds32* | \ + nios2 | nios2eb | nios2el | \ + ns32k | \ + nvptx | \ + or1k | \ + pdp11 | \ + pj* | \ + powerpc* | rs6000 | \ + pru | \ + riscv* | \ + rl78 | \ + romp | \ + rx | \ + s390* | \ + sh* | \ + sparc* | \ + tic6x | \ + tilegx | \ + tilepro | \ + v850 | \ + vax | \ + visium | \ + xtensa) + sv_cv_stack_direction=-1 ;; + c4x | \ + dsp16xx | \ + i960 | \ + hppa* | parisc* | \ + stormy16 | \ + we32k) + sv_cv_stack_direction=1 ;; + *) + if test $cross_compiling = no; then + cat > conftest.c < +int +find_stack_direction (int *addr, int depth) +{ + int dir, dummy = 0; + if (! addr) + addr = &dummy; + *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; + dir = depth ? find_stack_direction (addr, depth - 1) : 0; + return dir + dummy; +} +int +main (int argc, char *argv[[]]) +{ + printf ("%d\n", find_stack_direction (NULL, argc + 20)); + return 0; +} +EOF + AC_TRY_EVAL([ac_link]) + sv_cv_stack_direction=`./conftest` + else + sv_cv_stack_direction=0 + fi + ;; + esac + case $sv_cv_stack_direction in + 1) sv_cv_stack_direction_msg="grows up";; + -1) sv_cv_stack_direction_msg="grows down";; + *) sv_cv_stack_direction_msg="unknown";; + esac + ]) + AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction], + [Define as the direction of stack growth for your system. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => spaghetti stack.]) +])