Skip to content

Commit b3d5181

Browse files
committed
Driver: correct profiling symbol preservation on Windows
The Windows linker does not support `-u`. Furthermore, the compiler driver does not forward the `-u` option to the linker. We correctly use the `/include:` option from the linker. This should ensure that the symbol is preserved even with `/opt:ref`. This spelling should be compatible with both lld and link, which should provide sufficient portability. Take the opportunity to make it more obvious that the two parameters are creating a pair that will be concatenated by using a braced initializer. See https://docs.microsoft.com/en-us/cpp/build/reference/include-force-symbol-references?view=msvc-160 for more details on the option.
1 parent 47ed173 commit b3d5181

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/Driver/WindowsToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job,
180180
Twine("clang_rt.profile-") +
181181
getTriple().getArchName() + ".lib");
182182
Arguments.push_back(context.Args.MakeArgString(LibProfile));
183+
Arguments.push_back(context.Args.MakeArgString("-Xlinker"));
183184
Arguments.push_back(context.Args.MakeArgString(
184-
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
185+
Twine({"-include:", llvm::getInstrProfRuntimeHookVarName()})));
185186
}
186187

187188
context.Args.AddAllArgs(Arguments, options::OPT_Xlinker);

test/Driver/profiling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
// WINDOWS: clang{{(\.exe)?"? }}
5454
// WINDOWS: lib{{(\\\\|/)}}swift{{(\\\\|/)}}clang{{(\\\\|/)}}lib{{(\\\\|/)}}windows{{(\\\\|/)}}clang_rt.profile-x86_64.lib
55-
// WINDOWS: -u__llvm_profile_runtime
55+
// WINDOWS: -Xlinker -include:__llvm_profile_runtime
5656

5757
// WASI: clang{{(\.exe)?"? }}
5858
// WASI: lib{{(\\\\|/)}}swift{{(\\\\|/)}}clang{{(\\\\|/)}}lib{{(\\\\|/)}}wasi{{(\\\\|/)}}libclang_rt.profile-wasm32.a

0 commit comments

Comments
 (0)