diff options
| author | Gleb Popov <6yearold@gmail.com> | 2025-11-11 14:23:38 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-11 12:23:38 +0100 |
| commit | 7a73e69ac85faf2e508037e6573fe7438025c4ab (patch) | |
| tree | 3588e839af88df75d9814da6748ac91833edfcab /flang-rt | |
| parent | 0f4c8dd87af61ec5e254bec9f144e9dbc8bc2229 (diff) | |
[flang-rt] Use dlsym to access char** environ on FreeBSD (#158477)
Diffstat (limited to 'flang-rt')
| -rw-r--r-- | flang-rt/lib/runtime/environment.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/flang-rt/lib/runtime/environment.cpp b/flang-rt/lib/runtime/environment.cpp index 97ac56236e79..2a2e19f9f17e 100644 --- a/flang-rt/lib/runtime/environment.cpp +++ b/flang-rt/lib/runtime/environment.cpp @@ -17,6 +17,10 @@ #ifdef _WIN32 extern char **_environ; +#elif defined(__FreeBSD__) +// FreeBSD has environ in crt rather than libc. Using "extern char** environ" +// in the code of a shared library makes it fail to link with -Wl,--no-undefined +// See https://reviews.freebsd.org/D30842#840642 #else extern char **environ; #endif @@ -104,6 +108,11 @@ void ExecutionEnvironment::Configure(int ac, const char *av[], #ifdef _WIN32 envp = _environ; +#elif defined(__FreeBSD__) + auto envpp{reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"))}; + if (envpp) { + envp = *envpp; + } #else envp = environ; #endif |
