mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
[Windows] Autolink with basenames and add libdir to libpath
Prior to this change, for a few compiler-rt libraries such as ubsan and the profile library, Clang would embed "-defaultlib:path/to/rt-arch.lib" into the .drective section of every object compiled with -finstr-profile-generate or -fsanitize=ubsan as appropriate. These paths assume that the link step will run from the same working directory as the compile step. There is also evidence that sometimes the paths become absolute, such as when clang is run from a different drive letter from the current working directory. This is fragile, and I'd like to get away from having paths embedded in the object if possible. Long ago it was suggested that we use this for ASan, and apparently I felt the same way back then: https://reviews.llvm.org/D4428#56536 This is also consistent with how all other autolinking usage works for PS4, Mac, and Windows: they all use basenames, not paths. To keep things working for people using the standard GCC driver workflow, the driver now adds the resource directory to the linker library search path when it calls the linker. This is enough to make check-ubsan pass, and seems like a generally good thing. Users that invoke the linker directly (most clang-cl users) will have to add clang's resource library directory to their linker search path in their build system. I'm not sure where I can document this. Ideally I'd also do it in the MSBuild files, but I can't figure out where they go. I'd like to start with this for now. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D65543
This commit is contained in:
parent
7453a1bd1f
commit
6c8b4bb2b1
@ -886,6 +886,27 @@ if (LLVM_BUILD_INSTRUMENTED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# When using clang-cl with an instrumentation-based tool, add clang's library
|
||||
# resource directory to the library search path. Because cmake invokes the
|
||||
# linker directly, it isn't sufficient to pass -fsanitize=* to the linker.
|
||||
if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-resource-dir
|
||||
OUTPUT_VARIABLE clang_resource_dir
|
||||
ERROR_VARIABLE clang_cl_stderr
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE clang_cl_exit_code)
|
||||
if (NOT "${clang_cl_exit_code}" STREQUAL "0")
|
||||
message(FATAL_ERROR
|
||||
"Unable to invoke clang-cl to find resource dir: ${clang_cl_stderr}")
|
||||
endif()
|
||||
file(TO_CMAKE_PATH "${clang_resource_dir}" clang_resource_dir)
|
||||
append("/libpath:${clang_resource_dir}/lib/windows"
|
||||
CMAKE_EXE_LINKER_FLAGS
|
||||
CMAKE_SHARED_LINKER_FLAGS)
|
||||
endif()
|
||||
|
||||
if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
|
||||
append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
|
||||
|
Loading…
Reference in New Issue
Block a user