/// referenced in the program.
void __wasilibc_maybe_reinitialize_environ_eagerly(void);
+/// Return the value of the `environ` variable. Using `environ` directly
+/// requires eager initialization of the environment variables. Using this
+/// function instead of `environ` allows initialization to happen lazily.
+char **__wasilibc_get_environ(void);
+
#ifdef __cplusplus
}
#endif
--- /dev/null
+#include <wasi/libc-environ.h>
+
+extern char **__wasilibc_environ;
+
+// See the comments in libc-environ.h.
+char **__wasilibc_get_environ(void) {
+ // Perform lazy initialization if needed.
+ __wasilibc_ensure_environ();
+
+ // Return `environ`. Use the `__wasilibc_`-prefixed name so that we don't
+ // pull in the `environ` symbol directly, which would lead to eager
+ // initialization being done instead.
+ return __wasilibc_environ;
+}