clang++: error: unknown argument: '-imsvc' when cross compiling on Windows
We use ExternalProject_Add and a custom toolchain file (below), to cross compile with Clang/LLVM. On Linux, this works great, with no issues. On Windows, we get:
clang++: error: unknown argument: '-imsvc'
I tracked this down to:
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC")
macro(__compiler_clang lang)
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-imsvc ")
endmacro()
else()
If I comment this out, it works great. Everything compiles and links without an issue. My concern is, I am not sure if that is the right approach or not. If I look at the output to the compiler, I see:
C:\working\llvm-project-build\Debug\bin\clang++.exe --target=x86_64-elf -ffreestanding -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4 -mno-avx -mno-aes -mno-sse4a -mcmodel=large -DBSL_DEBUG_LEVEL=bsl::V -DBSL_PAGE_SIZE=0x1000 -DENABLE_COLOR=true -IC:/working/hypervisor/runtime/../syscall/include/cpp -IC:/working/hypervisor/runtime/include -IC:/working/bsl/cmake/interface/../../include -IC:/working/bsl/cmake/interface/../../include/bsl/arch/x86 -imsvc include -Og -g -Wframe-larger-than=1024 -ftime-trace -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++20-compat -Wno-c11-extensions -Wno-padded
-Wno-weak-vtables -Wno-ctad-maybe-unsupported -Wno-enum-compare-conditional -Wno-return-std-move-in-c++11 -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-covered-switch-default -fcomment-block-commands=include -fcomment-block-commands=cond -fcomment-block-commands=endcond -fdiagnostics-color=always -fansi-escape-codes -fno-exceptions -fno-rtti -fstack-protector-strong -std=c++20 -o runtime/CMakeFiles/runtime.dir/src/_start.cpp.obj -c C:/working/hypervisor/runtime/src/_start.cpp
Everything here looks good minus the "-imsvc include".
Any thoughts on how to properly address this? Is there a variable I can set in the toolchain to fix this? Not really sure where to go from here. One option is I could write a custom wrapper around the compiler to filter this out, but that would be pretty annoying.
Thanks a ton
#
# Copyright (C) 2020 Assured Information Security, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CXX_COMPILER_WORKS 1)
string(CONCAT HYPERVISOR_EXT_CXX_FLAGS
"--target=x86_64-elf "
"-ffreestanding "
"-mno-mmx "
"-mno-sse "
"-mno-sse2 "
"-mno-sse3 "
"-mno-ssse3 "
"-mno-sse4.1 "
"-mno-sse4.2 "
"-mno-sse4 "
"-mno-avx "
"-mno-aes "
"-mno-sse4a "
"-mcmodel=large "
)
string(CONCAT HYPERVISOR_EXT_LINK_FLAGS
"-static "
"-nostdlib "
"-z noexecstack "
"-T ${CMAKE_BINARY_DIR}/toolchain/x64/ext.ld "
)
set(CMAKE_ASM_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> ${HYPERVISOR_EXT_CXX_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> ${HYPERVISOR_EXT_CXX_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
set(CMAKE_CXX_LINK_EXECUTABLE
"${HYPERVISOR_CXX_LINKER} ${HYPERVISOR_EXT_LINK_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
)
And for reference, all of the code is here: https://github.com/Bareflank/hypervisor