Skip to content

Commit e44dbfc

Browse files
authored
Merge pull request #37810 from compnerd/enviromentally-friendly
runtime: annotate `_environ` DLL storage, exclude in WinRT
2 parents 955fe85 + f0f81f7 commit e44dbfc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,19 @@ OnceToken_t swift::runtime::environment::initializeToken;
122122
extern "C" char **environ;
123123
#define ENVIRON environ
124124
#elif defined(_WIN32)
125+
// `_environ` is DLL-imported unless we are linking against the static C runtime
126+
// (via `/MT` or `/MTd`).
127+
#if defined(_DLL)
128+
extern "C" __declspec(dllimport) char **_environ;
129+
#else
125130
extern "C" char **_environ;
131+
#endif
132+
// `_environ` is unavailable in the Windows Runtime environment.
133+
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/environ-wenviron?view=msvc-160
134+
#if !defined(_WINRT_DLL)
126135
#define ENVIRON _environ
127136
#endif
137+
#endif
128138

129139
#ifdef ENVIRON
130140
void swift::runtime::environment::initialize(void *context) {

0 commit comments

Comments
 (0)