URL:
  <https://savannah.gnu.org/support/?111333>

                 Summary: AC_CHECK_FUNCS fails when cross-compiling to wasm32
                   Group: Autoconf
               Submitter: None
               Submitted: Tue 04 Nov 2025 07:45:29 AM UTC
                Priority: 5 - Unprioritized
                Severity: 5 - Blocker
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: [email protected]
             Open/Closed: Open
         Discussion Lock: Any
        Operating System: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 04 Nov 2025 07:45:29 AM UTC By: Anonymous
I am trying to cross-compile gmp (through its
https://gitlab.com/tspiteri/gmp-mpfr-sys Rust wrapper), which uses autoconf,
to wasm32-wasip1. In its configure.ac script, gmp uses AC_CHECK_FUNCS to check
for the existence of functions such as strnlen. Even though the function
exists (I am linking with the wasi-sdk), the autoconf fails to detect it. The
configure.log section is:

```
configure:24675: checking for strnlen
configure:24675:
/nix/store/5494kp5jix17an5ifqwbpgpr7sql8h3r-clang-20.1.8/bin/clang -o conftest
--target=wasm32-wasip1 -nodefaultlibs -resource-dir
/nix/store/v5a0gqs9r5v406xma832691y8k6srn1i-clang-20.1.8-lib/lib/clang/20
--sysroot=/nix/store/1jdrg3x746sb996gz2znrsp1lzgw41v4-wasi-sysroot-27.0
-isystem
/nix/store/v5a0gqs9r5v406xma832691y8k6srn1i-clang-20.1.8-lib/lib/clang/20/include
-isystem
/nix/store/1jdrg3x746sb996gz2znrsp1lzgw41v4-wasi-sysroot-27.0/include/wasm32-wasip1
-isystem /nix/store/1jdrg3x746sb996gz2znrsp1lzgw41v4-wasi-sysroot-27.0/include
-B /nix/store/0hmsys7m7xywkifjj4dklla0jr0x9afs-lld-20.1.8/bin
-D_WASI_EMULATED_PROCESS_CLOCKS -O3  -lc -lwasi-emulated-process-clocks
-L/nix/store/6xwxdkcyzy3zmkf3rsxjyh2ap5bkyy6x-libclang_rt-27.0/wasm32-unknown-wasip1
-lclang_rt.builtins conftest.c  >&5
[parse exception: popping from empty stack (at 0:662)]
Fatal: error parsing wasm (try --debug for more info)
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
configure:24675: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU MP"
| #define PACKAGE_TARNAME "gmp"
| #define PACKAGE_VERSION "6.3.0"
| #define PACKAGE_STRING "GNU MP 6.3.0"
| #define PACKAGE_BUGREPORT "[email protected] (see
https://gmplib.org/manual/Reporting-Bugs.html)"
| #define PACKAGE_URL "http://www.gnu.org/software/gmp/";
| #define PACKAGE "gmp"
| #define VERSION "6.3.0"
| #define WANT_FFT 1
| #define HAVE_HOST_CPU_wasm32 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define STDC_HEADERS 1
| #define TIME_WITH_SYS_TIME 1
| #define HAVE_FCNTL_H 1
| #define HAVE_FLOAT_H 1
| #define HAVE_LANGINFO_H 1
| #define HAVE_LOCALE_H 1
| #define HAVE_NL_TYPES_H 1
| #define HAVE_SYS_PARAM_H 1
| #define HAVE_SYS_SYSINFO_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_SYS_TIMES_H 1
| #define HAVE_SYS_RESOURCE_H 1
| #define HAVE_DECL_FGETC 1
| #define HAVE_DECL_FSCANF 1
| #define HAVE_DECL_OPTARG 1
| #define HAVE_DECL_UNGETC 1
| #define HAVE_DECL_VFPRINTF 1
| #define HAVE_DECL_SYS_ERRLIST 0
| #define HAVE_DECL_SYS_NERR 0
| #define RETSIGTYPE void
| #define HAVE_INTMAX_T 1
| #define HAVE_LONG_DOUBLE 1
| #define HAVE_LONG_LONG 1
| #define HAVE_PTRDIFF_T 1
| #define HAVE_QUAD_T 1
| #define HAVE_UINT_LEAST32_T 1
| #define HAVE_INTPTR_T 1
| #define restrict __restrict
| #define HAVE_ATTRIBUTE_CONST 1
| #define HAVE_ATTRIBUTE_MALLOC 1
| #define HAVE_ATTRIBUTE_MODE 1
| #define HAVE_ATTRIBUTE_NORETURN 1
| #define HAVE_HIDDEN_ALIAS 1
| #define HAVE_ALLOCA_H 1
| #define HAVE_ALLOCA 1
| #define WANT_TMP_ALLOCA 1
| #define HAVE_LIMB_LITTLE_ENDIAN 1
| #define HAVE_GETPAGESIZE 1
| #define HAVE_LOCALECONV 1
| /* end confdefs.h.  */
| /* Define strnlen to an innocuous variant, in case <limits.h> declares
strnlen.
|    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
| #define strnlen innocuous_strnlen
| 
| /* System header to define __stub macros and hopefully few prototypes,
|     which can conflict with char strnlen (); below.
|     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
|     <limits.h> exists even on freestanding compilers.  */
| 
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
| 
| #undef strnlen
| 
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char strnlen ();
| /* The GNU C library defines this for functions which it implements
|     to always fail with ENOSYS.  Some functions are actually named
|     something starting with __ and the normal name is an alias.  */
| #if defined __stub_strnlen || defined __stub___strnlen
| choke me
| #endif
| 
| int
| main ()
| {
| return strnlen ();
|   ;
|   return 0;
| }
configure:24675: result: no
```

The problem seems to come from wasm-ld, which fails with `[parse exception:
popping from empty stack (at 0:662)]`.
https://github.com/emscripten-core/emscripten/issues/18666 mentions this error
as being caused by an incompatible redeclaration of a function, here strnlen,
which is then called. While calling with incompatible arguments is undefined
behavior in C but compiles, in WASM this is fully unsupported and linking
fails.

Is it possible to run autoconf in a wasm32 cross-compile argument without
invoking this wasm-ld-unsupported undefined behavior?

Thanks for your help!

Kind regards,
Juniper Tyree






    _______________________________________________________
File Attachments:

Name: config.log                     Size: 403KiB
    <https://file.savannah.gnu.org/file/config.log?file_id=57770>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-617ea5df01d753693c126fee1cb8b23ce917ea5d.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/support/?111333>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to