Skip to content

Commit ddb43ca

Browse files
committed
[flang][runtime] Use dlsym to access char** environ on FreeBSD
1 parent 94213a4 commit ddb43ca

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

flang-rt/lib/runtime/environment.cpp

Lines changed: 6 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,8 @@ void ExecutionEnvironment::Configure(int ac, const char *av[],
104108

105109
#ifdef _WIN32
106110
envp = _environ;
111+
#elif defined(__FreeBSD__)
112+
envp = *reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"));
107113
#else
108114
envp = environ;
109115
#endif

0 commit comments

Comments
 (0)