From b9933c5013a77fc4377d3d508c922050aae94215 Mon Sep 17 00:00:00 2001 From: Iori Yanokura Date: Mon, 5 Jan 2026 14:01:47 +0900 Subject: [PATCH] loadelf.c: Fix dlsym symbol conflict with system libraries on macOS On newer macOS versions (Darwin 25.x), dlsym(0, "history") returns libedit's history function instead of EusLisp's ___history function, causing a segmentation fault when loading modules. This change reverses the symbol lookup order to first try the ___ prefixed symbol name, avoiding conflicts with system library symbols. --- lisp/c/loadelf.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/c/loadelf.c b/lisp/c/loadelf.c index e07e8fb1a..695d76ff3 100644 --- a/lisp/c/loadelf.c +++ b/lisp/c/loadelf.c @@ -166,10 +166,11 @@ pointer initnames; module_count=0; while (iscons(initnames)) { /* printf("%s ", ccar(initnames)->c.str.chars); */ - initfunc= dlsym(dlhandle, (char *)ccar(initnames)->c.str.chars); - if (initfunc==NULL) { - sprintf(namebuf,"___%s",ccar(initnames)->c.str.chars); - initfunc=dlsym(dlhandle, namebuf);} + /* First try with ___ prefix to avoid symbol conflicts with system libraries (e.g., libedit's history) */ + sprintf(namebuf, "___%s", ccar(initnames)->c.str.chars); + initfunc = dlsym(dlhandle, namebuf); + if (initfunc == NULL) { + initfunc = dlsym(dlhandle, (char *)ccar(initnames)->c.str.chars);} if (initfunc) { /* printf(" ok\n"); */ @@ -218,10 +219,11 @@ pointer *argv; if (dlhandle==NULL) error(E_USER,(pointer)"This module was not loaded"); while (iscons(initnames)) { - initfunc= dlsym(dlhandle, (char *)ccar(initnames)->c.str.chars); - if (initfunc==NULL) { - sprintf(namebuf,"___%s",ccar(initnames)->c.str.chars); - initfunc=dlsym(dlhandle, namebuf);} + /* First try with ___ prefix to avoid symbol conflicts with system libraries */ + sprintf(namebuf, "___%s", ccar(initnames)->c.str.chars); + initfunc = dlsym(dlhandle, namebuf); + if (initfunc == NULL) { + initfunc = dlsym(dlhandle, (char *)ccar(initnames)->c.str.chars);} if (initfunc) { modname=ccar(initnames);