Skip to content

Commit 7a73e69

Browse files
authored
[flang-rt] Use dlsym to access char** environ on FreeBSD (llvm#158477)
1 parent 0f4c8dd commit 7a73e69

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

flang-rt/lib/runtime/environment.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
#ifdef _WIN32
1919
extern char **_environ;
20+
#elif defined(__FreeBSD__)
21+
// FreeBSD has environ in crt rather than libc. Using "extern char** environ"
22+
// in the code of a shared library makes it fail to link with -Wl,--no-undefined
23+
// See https://reviews.freebsd.org/D30842#840642
2024
#else
2125
extern char **environ;
2226
#endif
@@ -104,6 +108,11 @@ void ExecutionEnvironment::Configure(int ac, const char *av[],
104108

105109
#ifdef _WIN32
106110
envp = _environ;
111+
#elif defined(__FreeBSD__)
112+
auto envpp{reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"))};
113+
if (envpp) {
114+
envp = *envpp;
115+
}
107116
#else
108117
envp = environ;
109118
#endif

0 commit comments

Comments
 (0)