Skip to content

Commit 99db287

Browse files
committed
Driver: simplify the profiler linking on Windows
Rather than computing an absolute path relative to Swift's resource directory, use the compiler driver to locate the profiling runtime relative to the C/C++ compiler's resource directory. This ensures that we correctly locate the runtime. Additionally, because clang adds the clang resource directory to the library search path, we do not need to compute the path and can rely on the linker locating the runtime via the library search path. This simplifies the handling for the profile runtime linking on Windows. Out of abundant paranoia, place the library link request after the forced symbol inclusion as a GC root to ensure that `/opt:ref` will not accidentally dead strip the symbol and force a reload of the library. (cherry picked from commit fc3ccdc)
1 parent fe56b22 commit 99db287

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

lib/Driver/WindowsToolChains.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,10 @@ toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job,
172172
}
173173

174174
if (context.Args.hasArg(options::OPT_profile_generate)) {
175-
SmallString<128> LibProfile(SharedResourceDirPath);
176-
llvm::sys::path::remove_filename(LibProfile); // remove platform name
177-
llvm::sys::path::append(LibProfile, "clang", "lib");
178-
179-
llvm::sys::path::append(LibProfile, getTriple().getOSName(),
180-
Twine("clang_rt.profile-") +
181-
getTriple().getArchName() + ".lib");
182-
Arguments.push_back(context.Args.MakeArgString(LibProfile));
183175
Arguments.push_back(context.Args.MakeArgString("-Xlinker"));
184176
Arguments.push_back(context.Args.MakeArgString(
185177
Twine({"-include:", llvm::getInstrProfRuntimeHookVarName()})));
178+
Arguments.push_back(context.Args.MakeArgString("-lclang_rt.profile"));
186179
}
187180

188181
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
@@ -51,8 +51,8 @@
5151
// LINUX: -u__llvm_profile_runtime
5252

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

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

0 commit comments

Comments
 (0)