On Fri, Sep 09, 2022 at 10:50:19PM +0200, Rainer Orth wrote:
> Hi Jakub,
>
> > On Wed, Aug 31, 2022 at 12:56:25PM +0200, Marcel Vollweiler wrote:
> >> libgomp/ChangeLog:
> [...]
> >> (initialize_env): Extended to parse the new syntax of environment
> >> variables.
>
> this patch broke Darwin bootstrap:
>
> Undefined symbols for architecture x86_64:
> "_environ", referenced from:
> _initialize_env in env.o
> ld: symbol(s) not found for architecture x86_64
> collect2: error: ld returned 1 exit status
> make[5]: *** [libgomp.la] Error 1
>
> This is documented in environ(7):
>
> Shared libraries and bundles don't have direct access to environ, which
> is only available to the loader ld(1) when a complete program is being
> linked. The environment routines can still be used, but if direct access
> to environ is needed, the _NSGetEnviron() routine, defined in
> <crt_externs.h>, can be used to retrieve the address of environ at run-
> time.
>
> The following patch/hack, taken from
> libgfortran/intrinsics/execute_command_line.c, allows the link to
> succeed. Bootstrap still running...
My preference would be to introduce some new header for this, which would
say define get_environ inline function, and define it as
static inline char **
get_environ (void)
{
extern char **environ;
return environ;
}
in libgomp/config/posix/env.h
and to that
#include <crt_externs.h>
static inline char **
get_environ (void)
{
return *_NSGetEnviron ();
}
in libgomp/config/darwin/env.h
That way it is easier to override it for other platforms if needed.
Jakub