[llvm] dfbaf90 - [llvm] prefix linker flag on non-MSVC compilers with `-Wl, `
Ashay Rane via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 21 09:18:48 PDT 2022
Author: Ashay Rane
Date: 2022-09-21T11:18:42-05:00
New Revision: dfbaf90043841d18f5871e12b10c674b9b3abf99
URL: https://github.com/llvm/llvm-project/commit/dfbaf90043841d18f5871e12b10c674b9b3abf99
DIFF: https://github.com/llvm/llvm-project/commit/dfbaf90043841d18f5871e12b10c674b9b3abf99.diff
LOG: [llvm] prefix linker flag on non-MSVC compilers with `-Wl,`
Prior to this patch, a Windows build of llvm-lto using clang failed with
the error: `LTO.def: unknown file type`. The reason for this failure is
that .DEF files are used by the linker not by the clang compiler. The
MSVC compiler+linker handles this transparently, but if we're using
clang (or gcc), then we need to tell the compiler to forward this flag
to the linker. This patch adds the necessary `-Wl` flag to fix the
problem.
Reviewed By: rnk, mstorsjo
Differential Revision: https://reviews.llvm.org/D134165
Added:
Modified:
llvm/cmake/modules/AddLLVM.cmake
Removed:
################################################################################
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index efff21c4f16b..946d66140fa3 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -118,7 +118,7 @@ function(add_llvm_symbol_exports target_name export_file)
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--version-script,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
endif()
- else()
+ elseif(WIN32)
set(native_export_file "${target_name}.def")
add_custom_command(OUTPUT ${native_export_file}
@@ -129,7 +129,18 @@ function(add_llvm_symbol_exports target_name export_file)
COMMENT "Creating export file for ${target_name}")
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}\"")
+ 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}\"")
+ 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}\"")
+ else()
+ message(FATAL_ERROR "Unsupported Windows toolchain")
endif()
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " ${export_file_linker_flag}")
More information about the llvm-commits
mailing list