Skip to content

[LLVM][CMake][MSVC] Wrap linker flags for ICX on Windows #112680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ function(add_llvm_symbol_exports target_name export_file)
set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
if(MSVC)
# cl.exe or clang-cl, i.e. MSVC style command line interface
set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
set(export_file_linker_flag "LINKER:/DEF:${export_file_linker_flag}")
elseif(CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
# clang in msvc mode, calling a link.exe/lld-link style linker
set(export_file_linker_flag "-Wl,/DEF:\"${export_file_linker_flag}\"")
set(export_file_linker_flag "-Wl,/DEF:${export_file_linker_flag}")
elseif(MINGW)
# ${export_file_linker_flag}, which is the plain file name, works as is
# when passed to the compiler driver, which then passes it on to the
# linker as an input file.
set(export_file_linker_flag "\"${export_file_linker_flag}\"")
set(export_file_linker_flag "${export_file_linker_flag}")
else()
message(FATAL_ERROR "Unsupported Windows toolchain")
endif()
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " ${export_file_linker_flag}")
set_property(TARGET ${target_name} APPEND PROPERTY
LINK_OPTIONS "${export_file_linker_flag}")
endif()

add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
Expand Down
2 changes: 1 addition & 1 deletion llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ if(MSVC)
# behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default
# value (1 MB) which is not enough for us in tasks such as parsing recursive
# C++ templates in Clang.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/STACK:10000000")
elseif(MINGW OR CYGWIN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,16777216")

Expand Down
4 changes: 4 additions & 0 deletions llvm/cmake/platforms/WinMsvc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ if(case_sensitive_filesystem)
-libpath:"${msvc_lib_symlinks_dir}")
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25")
list(TRANSFORM LINK_FLAGS PREPEND "${CMAKE_CXX_LINKER_WRAPPER_FLAG}")
endif()

string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${LINK_FLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${LINK_FLAGS}")
Expand Down
16 changes: 12 additions & 4 deletions llvm/lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ elseif( CMAKE_HOST_UNIX )
endif()
endif( WIN32 )

set(WL "")
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25"
AND MSVC
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
#IntelLLVM requires to pass linker flags with a wrapper
set(WL "$<$<OR:$<LINK_LANG_AND_ID:C,IntelLLVM>,$<LINK_LANG_AND_ID:CXX,IntelLLVM>,$<LINK_LANG_AND_ID:Fortran,IntelLLVM>>:-Qoption,link,>")
endif()

# Delay load shell32.dll if possible to speed up process startup.
set (delayload_flags)
if (MSVC)
# When linking with Swift, `swiftc.exe` is used as the linker drive rather
# than invoking `link.exe` directly. In such a case, the flags should be
# marked as `-Xlinker` to pass them directly to the linker. As a temporary
# workaround simply elide the delay loading.
set (delayload_flags $<$<NOT:$<LINK_LANGUAGE:Swift>>:delayimp -delayload:shell32.dll -delayload:ole32.dll>)
set (delayload_flags $<$<NOT:$<LINK_LANGUAGE:Swift>>:delayimp ${WL}-delayload:shell32.dll ${WL}-delayload:ole32.dll>)
endif()

# Link Z3 if the user wants to build it.
Expand All @@ -104,16 +112,16 @@ if(LLVM_INTEGRATED_CRT_ALLOC)
if((LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$") OR LLVM_ENABLE_RPMALLOC)
add_compile_definitions(ENABLE_OVERRIDE ENABLE_PRELOAD)
set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c")
set(delayload_flags "${delayload_flags} -INCLUDE:malloc")
set(delayload_flags "${delayload_flags} ${WL}-INCLUDE:malloc")
elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/snmalloc/override/new.cc")
set(system_libs ${system_libs} "mincore.lib" "-INCLUDE:malloc")
set(system_libs ${system_libs} "mincore.lib" "${WL}-INCLUDE:malloc")
elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$")
set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib")
if(NOT EXISTS "${MIMALLOC_LIB}")
message(FATAL_ERROR "Cannot find the mimalloc static library. To build it, first apply the patch from https://github.com/microsoft/mimalloc/issues/268 then build the Release x64 target through ${LLVM_INTEGRATED_CRT_ALLOC}\\ide\\vs2019\\mimalloc.sln")
endif()
set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc")
set(system_libs ${system_libs} "${MIMALLOC_LIB}" "${WL}-INCLUDE:malloc")
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC)

if (LLVM_INTEGRATED_CRT_ALLOC AND MSVC)
# Make sure we search LLVMSupport first, before the CRT libs
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -INCLUDE:malloc")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}-INCLUDE:malloc")
endif()

endif()
Loading