Skip to content

Commit dfbaf90

Browse files
committed
[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
1 parent adaf62c commit dfbaf90

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/cmake/modules/AddLLVM.cmake

+12-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function(add_llvm_symbol_exports target_name export_file)
118118
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
119119
LINK_FLAGS " -Wl,--version-script,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
120120
endif()
121-
else()
121+
elseif(WIN32)
122122
set(native_export_file "${target_name}.def")
123123

124124
add_custom_command(OUTPUT ${native_export_file}
@@ -129,7 +129,18 @@ function(add_llvm_symbol_exports target_name export_file)
129129
COMMENT "Creating export file for ${target_name}")
130130
set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
131131
if(MSVC)
132+
# cl.exe or clang-cl, i.e. MSVC style command line interface
132133
set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"")
134+
elseif(CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
135+
# clang in msvc mode, calling a link.exe/lld-link style linker
136+
set(export_file_linker_flag "-Wl,/DEF:\"${export_file_linker_flag}\"")
137+
elseif(MINGW)
138+
# ${export_file_linker_flag}, which is the plain file name, works as is
139+
# when passed to the compiler driver, which then passes it on to the
140+
# linker as an input file.
141+
set(export_file_linker_flag "\"${export_file_linker_flag}\"")
142+
else()
143+
message(FATAL_ERROR "Unsupported Windows toolchain")
133144
endif()
134145
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
135146
LINK_FLAGS " ${export_file_linker_flag}")

0 commit comments

Comments
 (0)