From ab6e9effe1e0e74b400a45dd899c94e3a58c5311 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Thu, 5 Mar 2026 11:09:49 +0000 Subject: [PATCH 1/3] Merge duplicated ivl_dlfcn.h files. The vvp/ivl_dlfcn.h and cadpli/ivl_dlfcn.h files are essentially the same, but have diverged a bit over the years. Merge them into a single shared file at the top level. Use the static prefix for all inline functins (currently only used in the cadpli version) as that will fix issue #1301. We now require the compiler to support at least C99, so can use "inline", not "__inline__". (cherry picked from commit 3f936d2d8b4fe5e58c34577e815e36f280b6ef3f) --- cadpli/cadpli.c | 4 +- cadpli/ivl_dlfcn.h | 94 ---------------------------------- vvp/ivl_dlfcn.h => ivl_dlfcn.h | 36 ++++++++----- vpi_modules.cc | 2 +- 4 files changed, 26 insertions(+), 110 deletions(-) delete mode 100644 cadpli/ivl_dlfcn.h rename vvp/ivl_dlfcn.h => ivl_dlfcn.h (73%) diff --git a/cadpli/cadpli.c b/cadpli/cadpli.c index 66b213e56..ed8a9e738 100644 --- a/cadpli/cadpli.c +++ b/cadpli/cadpli.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2026 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -53,7 +53,7 @@ static void thunker_register(void) strncpy(module, cp, bp-cp); module[bp-cp] = 0; - mod = ivl_dlopen(module); + mod = ivl_dlopen(module, false); if (mod == 0) { vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror()); free(module); diff --git a/cadpli/ivl_dlfcn.h b/cadpli/ivl_dlfcn.h deleted file mode 100644 index c18247daa..000000000 --- a/cadpli/ivl_dlfcn.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef IVL_ivl_dlfcn_H -#define IVL_ivl_dlfcn_H -/* - * Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com) - * - * This source code is free software; you can redistribute it - * and/or modify it in source code form under the terms of the GNU - * General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#if defined(__MINGW32__) -# include -# include -typedef void * ivl_dll_t; -#elif defined(HAVE_DLFCN_H) -# include -typedef void* ivl_dll_t; -#elif defined(HAVE_DL_H) -# include -typedef shl_t ivl_dll_t; -#endif - -#if defined(__MINGW32__) -static __inline__ ivl_dll_t ivl_dlopen(const char *name) -{ return (void *)LoadLibrary(name); } - -static __inline__ void *ivl_dlsym(ivl_dll_t dll, const char *nm) -{ return (void *)GetProcAddress((HINSTANCE)dll,nm);} - -static __inline__ void ivl_dlclose(ivl_dll_t dll) -{ (void)FreeLibrary((HINSTANCE)dll);} - -static __inline__ const char *dlerror(void) -{ - static char msg[256]; - unsigned long err = GetLastError(); - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &msg, - sizeof(msg) - 1, - NULL - ); - return msg; -} - -#elif defined(HAVE_DLFCN_H) -static __inline__ ivl_dll_t ivl_dlopen(const char*name) -{ return dlopen(name,RTLD_LAZY); } - -static __inline__ void* ivl_dlsym(ivl_dll_t dll, const char*nm) -{ - void*sym = dlsym(dll, nm); - /* Not found? try without the leading _ */ - if (sym == 0 && nm[0] == '_') - sym = dlsym(dll, nm+1); - return sym; -} - -static __inline__ void ivl_dlclose(ivl_dll_t dll) -{ dlclose(dll); } - -#elif defined(HAVE_DL_H) -static __inline__ ivl_dll_t ivl_dlopen(const char*name) -{ return shl_load(name, BIND_IMMEDIATE, 0); } - -static __inline__ void* ivl_dlsym(ivl_dll_t dll, const char*nm) -{ - void*sym; - int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym); - return (rc == 0) ? sym : 0; -} - -static __inline__ void ivl_dlclose(ivl_dll_t dll) -{ shl_unload(dll); } - -static __inline__ const char*dlerror(void) -{ return strerror( errno ); } -#endif - -#endif /* IVL_ivl_dlfcn_H */ diff --git a/vvp/ivl_dlfcn.h b/ivl_dlfcn.h similarity index 73% rename from vvp/ivl_dlfcn.h rename to ivl_dlfcn.h index 10f09d1b8..ebbc04eea 100644 --- a/vvp/ivl_dlfcn.h +++ b/ivl_dlfcn.h @@ -1,7 +1,7 @@ #ifndef IVL_ivl_dlfcn_H #define IVL_ivl_dlfcn_H /* - * Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2026 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -21,7 +21,11 @@ #if defined(__MINGW32__) # include +#if defined(__cplusplus) # include +#else +# include +#endif typedef void * ivl_dll_t; #elif defined(HAVE_DLFCN_H) # include @@ -32,7 +36,7 @@ typedef shl_t ivl_dll_t; #endif #if defined(__MINGW32__) -inline ivl_dll_t ivl_dlopen(const char *name, bool) +static inline ivl_dll_t ivl_dlopen(const char *name, bool global_flag) { static char full_name[4096]; unsigned long length = GetFullPathName(name, sizeof(full_name), @@ -40,16 +44,18 @@ inline ivl_dll_t ivl_dlopen(const char *name, bool) if ((length == 0) || (length > sizeof(full_name))) return 0; + (void)global_flag; + return (void *)LoadLibrary(full_name); } -inline void *ivl_dlsym(ivl_dll_t dll, const char *nm) +static inline void *ivl_dlsym(ivl_dll_t dll, const char *nm) { return (void *)GetProcAddress((HINSTANCE)dll,nm);} -inline void ivl_dlclose(ivl_dll_t dll) +static inline void ivl_dlclose(ivl_dll_t dll) { (void)FreeLibrary((HINSTANCE)dll);} -inline const char *dlerror(void) +static inline const char *dlerror(void) { static char msg[256]; unsigned long err = GetLastError(); @@ -66,10 +72,10 @@ inline const char *dlerror(void) } #elif defined(HAVE_DLFCN_H) -inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag) +static inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag) { return dlopen(name,RTLD_LAZY|(global_flag?RTLD_GLOBAL:0)); } -inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) +static inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) { void*sym = dlsym(dll, nm); /* Not found? try without the leading _ */ @@ -78,24 +84,28 @@ inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) return sym; } -inline void ivl_dlclose(ivl_dll_t dll) +static inline void ivl_dlclose(ivl_dll_t dll) { dlclose(dll); } #elif defined(HAVE_DL_H) -inline ivl_dll_t ivl_dlopen(const char*name) -{ return shl_load(name, BIND_IMMEDIATE, 0); } +static inline ivl_dll_t ivl_dlopen(const char*name, bool global_flag) +{ + (void)global_flag; -inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) + return shl_load(name, BIND_IMMEDIATE, 0); +} + +static inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) { void*sym; int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym); return (rc == 0) ? sym : 0; } -inline void ivl_dlclose(ivl_dll_t dll) +static inline void ivl_dlclose(ivl_dll_t dll) { shl_unload(dll); } -inline const char*dlerror(void) +static inline const char*dlerror(void) { return strerror( errno ); } #endif diff --git a/vpi_modules.cc b/vpi_modules.cc index ec62af550..17a42c69f 100644 --- a/vpi_modules.cc +++ b/vpi_modules.cc @@ -21,7 +21,7 @@ #include "compiler.h" #include "vpi_user.h" #include "sv_vpi_user.h" -#include "vvp/ivl_dlfcn.h" +#include "ivl_dlfcn.h" using namespace std; From 0c575e6166c2f6fc0c83d7b71037121ffafbdf8c Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Thu, 5 Mar 2026 12:01:03 +0000 Subject: [PATCH 2/3] Remove duplicated typeders and functions from t-dll.h and t-dll.c These duplicate the contents of ivl_dlfcn.h (cherry picked from commit 4dfac864ce924fe68635d1bb40271e8cf3d49b00) --- t-dll.cc | 76 +++----------------------------------------------------- t-dll.h | 14 +---------- 2 files changed, 5 insertions(+), 85 deletions(-) diff --git a/t-dll.cc b/t-dll.cc index 77836c737..6a99ec8d6 100644 --- a/t-dll.cc +++ b/t-dll.cc @@ -38,74 +38,6 @@ using namespace std; struct dll_target dll_target_obj; -#if defined(__WIN32__) - -inline ivl_dll_t ivl_dlopen(const char *name) -{ - ivl_dll_t res = static_cast(LoadLibrary(name)); - return res; -} - - -inline void * ivl_dlsym(ivl_dll_t dll, const char *nm) -{ - return reinterpret_cast(GetProcAddress((HMODULE)dll, nm)); -} - -inline void ivl_dlclose(ivl_dll_t dll) -{ - FreeLibrary((HMODULE)dll); -} - -const char *dlerror(void) -{ - static char msg[256]; - unsigned long err = GetLastError(); - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &msg, - sizeof(msg) - 1, - NULL - ); - return msg; -} -#elif defined(HAVE_DLFCN_H) -inline ivl_dll_t ivl_dlopen(const char*name) -{ return dlopen(name,RTLD_LAZY); } - -inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) -{ - void*sym = dlsym(dll, nm); - /* Not found? try without the leading _ */ - if (sym == 0 && nm[0] == '_') - sym = dlsym(dll, nm+1); - return sym; -} - -inline void ivl_dlclose(ivl_dll_t dll) -{ dlclose(dll); } - -#elif defined(HAVE_DL_H) -inline ivl_dll_t ivl_dlopen(const char*name) -{ return shl_load(name, BIND_IMMEDIATE, 0); } - -inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) -{ - void*sym; - int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym); - return (rc == 0) ? sym : 0; -} - -inline void ivl_dlclose(ivl_dll_t dll) -{ shl_unload(dll); } - -inline const char*dlerror(void) -{ return strerror( errno ); } -#endif - ivl_scope_s::ivl_scope_s() : func_type(IVL_VT_NO_TYPE) { @@ -667,13 +599,13 @@ bool dll_target::start_design(const Design*des) { const char*dll_path_ = des->get_flag("DLL"); - dll_ = ivl_dlopen(dll_path_); + dll_ = ivl_dlopen(dll_path_, false); if ((dll_ == 0) && (dll_path_[0] != '/')) { size_t len = strlen(basedir) + 1 + strlen(dll_path_) + 1; char*tmp = new char[len]; snprintf(tmp, len, "%s/%s", basedir, dll_path_); - dll_ = ivl_dlopen(tmp); + dll_ = ivl_dlopen(tmp, false); delete[]tmp; } @@ -2852,13 +2784,13 @@ bool dll_target::signal_paths(const NetNet*net) void dll_target::test_version(const char*target_name) { - dll_ = ivl_dlopen(target_name); + dll_ = ivl_dlopen(target_name, false); if ((dll_ == 0) && (target_name[0] != '/')) { size_t len = strlen(basedir) + 1 + strlen(target_name) + 1; char*tmp = new char[len]; snprintf(tmp, len, "%s/%s", basedir, target_name); - dll_ = ivl_dlopen(tmp); + dll_ = ivl_dlopen(tmp, false); delete[]tmp; } diff --git a/t-dll.h b/t-dll.h index 2953a4877..4dc074247 100644 --- a/t-dll.h +++ b/t-dll.h @@ -22,24 +22,12 @@ # include "target.h" # include "ivl_target.h" # include "ivl_target_priv.h" +# include "ivl_dlfcn.h" # include "StringHeap.h" # include "netlist.h" # include # include -#if defined(__MINGW32__) -#include -typedef void *ivl_dll_t; -#elif defined(HAVE_DLFCN_H) -# include -typedef void* ivl_dll_t; -#elif defined(HAVE_DL_H) -# include -typedef shl_t ivl_dll_t; -#else -# error No DLL stub support for this target. -#endif - /* * The DLL target type loads a named object file to handle the process * of scanning the netlist. When it is time to start the design, I From 28d31c6df1ad5350a27217fd0675e9998f609c77 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Thu, 5 Mar 2026 17:41:41 +0000 Subject: [PATCH 3/3] Update the copy of ax_prog_cc_for_build.m4 embedded in aclocal.m4 This correctly generates the EXEEXT variable when cross-compiling and using autoconf 2.70+ (issue #1301). (cherry picked from commit 14a25bfe92172d886ba3172db1273687e46d38b6) --- aclocal.m4 | 66 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index cb844a2a1..f92aa2ad4 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -285,7 +285,7 @@ echo "timestamp for $_config_header" > `AS_DIRNAME(["$_config_header"])`/[]$_sta # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 18 +#serial 26 AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl @@ -296,14 +296,16 @@ AC_REQUIRE([AC_CANONICAL_BUILD])dnl dnl Use the standard macros, but make them use other variable names dnl pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl -pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl +pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl +pushdef([ac_cv_prog_cc_c99], ac_cv_build_prog_cc_c99)dnl +pushdef([ac_cv_prog_cc_c11], ac_cv_build_prog_cc_c11)dnl +pushdef([ac_cv_prog_cc_c23], ac_cv_build_prog_cc_c23)dnl +pushdef([ac_cv_prog_cc_stdc], ac_cv_build_prog_cc_stdc)dnl pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl -pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl -pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl -pushdef([ac_cv_objext], ac_cv_build_objext)dnl +pushdef([ac_prog_cc_stdc], ac_build_prog_cc_stdc)dnl pushdef([ac_exeext], ac_build_exeext)dnl pushdef([ac_objext], ac_build_objext)dnl pushdef([CC], CC_FOR_BUILD)dnl @@ -311,9 +313,7 @@ pushdef([CPP], CPP_FOR_BUILD)dnl pushdef([GCC], GCC_FOR_BUILD)dnl pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl -pushdef([EXEEXT], BUILD_EXEEXT)dnl pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl -pushdef([OBJEXT], BUILD_OBJEXT)dnl pushdef([host], build)dnl pushdef([host_alias], build_alias)dnl pushdef([host_cpu], build_cpu)dnl @@ -328,6 +328,32 @@ pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl pushdef([am_cv_CC_dependencies_compiler_type], am_cv_build_CC_dependencies_compiler_type)dnl pushdef([am_cv_prog_cc_c_o], am_cv_build_prog_cc_c_o)dnl pushdef([cross_compiling], cross_compiling_build)dnl +dnl +dnl These variables are problematic to rename by M4 macros, so we save +dnl their values in alternative names, and restore the values later. +dnl +dnl _AC_COMPILER_EXEEXT and _AC_COMPILER_OBJEXT internally call +dnl AC_SUBST which prevents the renaming of EXEEXT and OBJEXT +dnl variables. It's not a good idea to rename ac_cv_exeext and +dnl ac_cv_objext either as they're related. +dnl Renaming ac_exeext and ac_objext is safe though. +dnl +ac_cv_host_exeext=$ac_cv_exeext +AS_VAR_SET_IF([ac_cv_build_exeext], + [ac_cv_exeext=$ac_cv_build_exeext], + [AS_UNSET([ac_cv_exeext])]) +ac_cv_host_objext=$ac_cv_objext +AS_VAR_SET_IF([ac_cv_build_objext], + [ac_cv_objext=$ac_cv_build_objext], + [AS_UNSET([ac_cv_objext])]) +dnl +dnl ac_cv_c_compiler_gnu is used in _AC_LANG_COMPILER_GNU (called by +dnl AC_PROG_CC) indirectly. +dnl +ac_cv_host_c_compiler_gnu=$ac_cv_c_compiler_gnu +AS_VAR_SET_IF([ac_cv_build_c_compiler_gnu], + [ac_cv_c_compiler_gnu=$ac_cv_build_c_compiler_gnu], + [AS_UNSET([ac_cv_c_compiler_gnu])]) cross_compiling_build=no @@ -341,6 +367,9 @@ _AC_COMPILER_EXEEXT _AC_COMPILER_OBJEXT AC_PROG_CPP +BUILD_EXEEXT=$ac_cv_exeext +BUILD_OBJEXT=$ac_cv_objext + dnl Restore the old definitions dnl popdef([cross_compiling])dnl @@ -357,9 +386,7 @@ popdef([host_vendor])dnl popdef([host_cpu])dnl popdef([host_alias])dnl popdef([host])dnl -popdef([OBJEXT])dnl popdef([LDFLAGS])dnl -popdef([EXEEXT])dnl popdef([CPPFLAGS])dnl popdef([CFLAGS])dnl popdef([GCC])dnl @@ -367,25 +394,34 @@ popdef([CPP])dnl popdef([CC])dnl popdef([ac_objext])dnl popdef([ac_exeext])dnl -popdef([ac_cv_objext])dnl -popdef([ac_cv_exeext])dnl -popdef([ac_cv_c_compiler_gnu])dnl +popdef([ac_prog_cc_stdc])dnl popdef([ac_cv_prog_cc_g])dnl popdef([ac_cv_prog_cc_cross])dnl popdef([ac_cv_prog_cc_works])dnl +popdef([ac_cv_prog_cc_stdc])dnl +popdef([ac_cv_prog_cc_c23])dnl +popdef([ac_cv_prog_cc_c11])dnl +popdef([ac_cv_prog_cc_c99])dnl popdef([ac_cv_prog_cc_c89])dnl popdef([ac_cv_prog_gcc])dnl popdef([ac_cv_prog_CPP])dnl +dnl +ac_cv_exeext=$ac_cv_host_exeext +EXEEXT=$ac_cv_host_exeext +ac_cv_objext=$ac_cv_host_objext +OBJEXT=$ac_cv_host_objext +ac_cv_c_compiler_gnu=$ac_cv_host_c_compiler_gnu +ac_compiler_gnu=$ac_cv_host_c_compiler_gnu dnl restore global variables ac_ext, ac_cpp, ac_compile, -dnl ac_link, ac_compiler_gnu (dependant on the current +dnl ac_link, ac_compiler_gnu (dependent on the current dnl language after popping): AC_LANG_POP([C]) dnl Finally, set Makefile variables dnl -AC_SUBST(BUILD_EXEEXT)dnl -AC_SUBST(BUILD_OBJEXT)dnl +AC_SUBST([BUILD_EXEEXT])dnl +AC_SUBST([BUILD_OBJEXT])dnl AC_SUBST([CFLAGS_FOR_BUILD])dnl AC_SUBST([CPPFLAGS_FOR_BUILD])dnl AC_SUBST([LDFLAGS_FOR_BUILD])dnl