[PATCH 0/1] MR3984: msv1_0: Fix 'environ' undefined reference link error on FreeBSD.
On FreeBSD, using `environ` in a shared library linked with `-Wl,-z,defs` causes an undefined reference error: ``` gcc -m64 -o dlls/msv1_0/msv1_0.so -shared -Wl,-Bsymbolic -Wl,-soname,msv1_0.so -Wl,-z,defs dlls/msv1_0/unixlib.o dlls/ntdll/ntdll.so /usr/local/bin/ld: dlls/msv1_0/unixlib.o: in function `ntlm_fork': /usr/home/pip/wine/build64/../dlls/msv1_0/unixlib.c:206: undefined reference to `environ' collect2: error: ld returned 1 exit status *** Error code 1 ``` This is unfortunately a common issue on FreeBSD, see: - https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265 - https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=265008 - https://reviews.freebsd.org/D30842 Reported by Gerald Pfeifer. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3984
From: Brendan Shanks <bshanks(a)codeweavers.com> Reported by Gerald Pfeifer. --- dlls/msv1_0/unixlib.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dlls/msv1_0/unixlib.c b/dlls/msv1_0/unixlib.c index b51dde2ef0a..3003c9c6e54 100644 --- a/dlls/msv1_0/unixlib.c +++ b/dlls/msv1_0/unixlib.c @@ -40,7 +40,11 @@ #include "wine/debug.h" #include "unixlib.h" +#ifdef __FreeBSD__ +#include <dlfcn.h> +#else extern char **environ; +#endif WINE_DEFAULT_DEBUG_CHANNEL(ntlm); WINE_DECLARE_DEBUG_CHANNEL(winediag); @@ -160,6 +164,11 @@ static NTSTATUS ntlm_fork( void *args ) struct ntlm_ctx *ctx = params->ctx; posix_spawn_file_actions_t file_actions; int pipe_in[2], pipe_out[2]; +#ifdef __FreeBSD__ + char ***envp = dlsym( RTLD_DEFAULT, "environ" ); +#else + char ***envp = &environ; +#endif #ifdef HAVE_PIPE2 if (pipe2( pipe_in, O_CLOEXEC ) < 0) @@ -193,7 +202,7 @@ static NTSTATUS ntlm_fork( void *args ) posix_spawn_file_actions_addclose( &file_actions, pipe_in[0] ); posix_spawn_file_actions_addclose( &file_actions, pipe_in[1] ); - if (posix_spawnp( &ctx->pid, params->argv[0], &file_actions, NULL, params->argv, environ )) + if (posix_spawnp( &ctx->pid, params->argv[0], &file_actions, NULL, params->argv, *envp )) { ctx->pid = -1; write( pipe_in[1], "BH\n", 3 ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3984
We should probably have a configure check and avoid `-Wl,-z,defs` instead. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3984#note_47189
Happy to confirm the patch fixes the build on my FreeBSD 12.4-STABLE/amd64 tester. (A configure check avoiding #ifdef FreeBSD would be nice, of course.) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3984#note_47201
participants (4)
-
Alexandre Julliard (@julliard) -
Brendan Shanks -
Brendan Shanks (@bshanks) -
Gerald Pfeifer (@gerald)