From fbd825927bbf29ff560f8b2436dcf16812e7b5cc Mon Sep 17 00:00:00 2001 From: sailor001 Date: Wed, 24 Jun 2026 15:18:34 +0800 Subject: [PATCH] Add musl/OHOS compatibility: dlopen caching, _LARGEFILE64_SOURCE, config.guess * configure.ac: Check for dlopen in libc before trying -ldl. On musl (and OpenHarmony), dlopen is part of libc with no separate libdl. * configure.ac: Add _LARGEFILE64_SOURCE fallback detection for fopen64. On musl, fopen64 needs this define to be declared; glibc exposes it via _LARGEFILE_SOURCE alone. * config.guess: Recognize HarmonyOS uname -s output and canonicalize as *-unknown-linux-ohos. --- config.guess | 5 ++++- configure.ac | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config.guess b/config.guess index a9d01fde4..ac51e315b 100644 --- a/config.guess +++ b/config.guess @@ -940,6 +940,9 @@ EOF *:SerenityOS:*:*) GUESS=$UNAME_MACHINE-pc-serenity ;; + *:HarmonyOS:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-ohos + ;; *:Interix*:*) case $UNAME_MACHINE in x86) @@ -952,7 +955,7 @@ EOF GUESS=ia64-unknown-interix$UNAME_RELEASE ;; esac ;; - i*:UWIN*:*) + i*:UWIN:*:*) GUESS=$UNAME_MACHINE-pc-uwin ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) diff --git a/configure.ac b/configure.ac index 7cbb6b2dd..6dac7ccc1 100644 --- a/configure.ac +++ b/configure.ac @@ -274,7 +274,9 @@ AC_MSG_RESULT($do_times) AC_CHECK_HEADERS(dlfcn.h dl.h, break) DLLIB='' -AC_CHECK_LIB(dl,dlopen,[DLLIB=-ldl]) +# First check if dlopen is in libc (musl, OHOS, etc.) +AC_CHECK_FUNC(dlopen, [DLLIB=], + [AC_CHECK_LIB(dl,dlopen,[DLLIB=-ldl])]) if test -z "$DLLIB" ; then AC_CHECK_LIB(dld,shl_load,[DLLIB=-ldld]) fi @@ -363,6 +365,16 @@ AC_CHECK_FUNCS(realpath) # Check that these functions exist. They are mostly C99 # functions that older compilers may not yet support. AC_CHECK_FUNCS(fopen64) +# On musl-based systems, fopen64 may need _LARGEFILE64_SOURCE to be +# declared. Try again with it defined if the first check failed. +if test "$ac_cv_func_fopen64" != yes; then + iverilog_saved_cppflags="$CPPFLAGS" + CPPFLAGS="-D_LARGEFILE64_SOURCE $CPPFLAGS" + AC_CHECK_FUNCS(fopen64, + [AC_DEFINE([_LARGEFILE64_SOURCE], [1], + [Define to 1 if _LARGEFILE64_SOURCE is needed for fopen64])]) + CPPFLAGS="$iverilog_saved_cppflags" +fi # The following math functions may be defined in the math library so look # in the default libraries first and then look in -lm for them. On some # systems we may need to use the compiler in C99 mode to get a definition.