Skip to content
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

[libcxx] it should pass -Xlinker when user uses clang instead of clang-cl for build libcxx #96430

Closed
trcrsired opened this issue Jun 23, 2024 · 5 comments · Fixed by #96967
Closed
Labels
cmake Build system in general and CMake in particular libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@trcrsired
Copy link

trcrsired commented Jun 23, 2024

[cqwrteur@DESKTOP-9B705LH llvm_build]$ /home/cqwrteur/toolchains/llvm/x86_64-unknown-linux-gnu/llvm/bin/clang++ --target=x86_64-windows-msvc -nostartfiles -nostdlib -fuse-ld=lld --sysroot=/home/cqwrteur/toolchains/windows-msvc-sysroot -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview  /MANIFEST:NO  -fuse-ld=lld-link -shared -o lib/c++.dll  -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib/c++.lib -Xlinker /pdb:lib/c++.pdb -Xlinker /version:1.0 libcxx/src/CMakeFiles/cxx_shared.dir/algorithm.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/any.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/bind.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/call_once.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/charconv.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/chrono.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/error_category.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/exception.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/expected.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/filesystem_clock.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/filesystem_error.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/path.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/functional.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/hash.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/legacy_pointer_safety.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/memory.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/memory_resource.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/new_handler.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/new_helpers.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/optional.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/print.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/random_shuffle.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ryu/d2fixed.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ryu/d2s.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ryu/f2s.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/stdexcept.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/string.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/system_error.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/typeinfo.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/valarray.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/variant.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/vector.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/verbose_abort.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/atomic.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/barrier.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/condition_variable_destructor.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/condition_variable.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/future.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/mutex_destructor.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/mutex.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/shared_mutex.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/thread.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/random.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/fstream.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ios.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ios.instantiations.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/iostream.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/locale.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/ostream.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/regex.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/strstream.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/support/win32/locale_win32.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/support/win32/support.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/support/win32/thread_win32.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/directory_entry.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/directory_iterator.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.obj libcxx/src/CMakeFiles/cxx_shared.dir/filesystem/int128_builtins.cpp.obj  -nostdlib++  --unwindlib=none  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames
clang++: error: no such file or directory: '/MANIFEST:NO'

Proposed change:

diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 9e6c70335a79..c19041dd9da6 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -275,8 +275,14 @@ if (LIBCXX_ENABLE_SHARED)
     # Since we most likely do not have a mt.exe replacement, disable the
     # manifest bundling.  This allows a normal cmake invocation to pass which
     # will attempt to use the manifest tool to generate the bundled manifest
-    set_target_properties(cxx_shared PROPERTIES
+    if (${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL "MSVC")
+        set_target_properties(cxx_shared PROPERTIES
                           APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO")
+    else()
+        set_target_properties(cxx_shared PROPERTIES
+                         APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker /MANIFEST:NO")
+    endif()
+
   endif()
 endif()
@github-actions github-actions bot added clang Clang issues not falling into any other category libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. labels Jun 23, 2024
@EugeneZelenko EugeneZelenko added cmake Build system in general and CMake in particular and removed clang Clang issues not falling into any other category labels Jun 23, 2024
@trcrsired
Copy link
Author

BTW. -lmsvcrp wasn't linked

Similar issue for compiler-rt

diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 9c7fe64d0bd3..fd2f4e6a8bb7 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -370,7 +370,7 @@ macro(construct_compiler_rt_default_triple)

   if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
     set(option_prefix "")
-    if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
+    if ((CMAKE_C_SIMULATE_ID MATCHES "MSVC") AND (CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))
       set(option_prefix "/clang:")
     endif()
     execute_process(COMMAND ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple

@trcrsired
Copy link
Author

FAILED: lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/mulxc3.c.obj
/home/cqwrteur/toolchains/llvm/x86_64-unknown-linux-gnu/llvm/bin/clang --target=x86_64-windows-msvc -DVISIBILITY_HIDDEN  -fuse-ld=lld --sysroot=/home/cqwrteur/toolchains/windows-msvc-sysroot -Wall -Wno-unused-parameter -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -m64 -fno-lto -Werror=array-bounds -Werror=uninitialized -Werror=shadow -Werror=empty-body -Werror=sizeof-pointer-memaccess -Werror=sizeof-array-argument -Werror=suspicious-memaccess -Werror=builtin-memcpy-chk-size -Werror=array-bounds-pointer-arithmetic -Werror=return-stack-address -Werror=sizeof-array-decay -Werror=format-insufficient-args -Wformat -std=c11 -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/mulxc3.c.obj -MF lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/mulxc3.c.obj.d -o lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/mulxc3.c.obj -c /home/cqwrteur/toolchains_build/llvm-project/compiler-rt/lib/builtins/mulxc3.c
/home/cqwrteur/toolchains_build/llvm-project/compiler-rt/lib/builtins/mulxc3.c:20:35: error: unknown type name 'xf_float'
   20 | COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,
      |                                   ^
/home/cqwrteur/toolchains_build/llvm-project/compiler-rt/lib/builtins/mulxc3.c:20:49: error: unknown type name 'xf_float'
   20 | COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,
   

long double is not 80 bits on msvc

@ldionne
Copy link
Member

ldionne commented Jun 25, 2024

Can you please describe what you're trying to do? It looks like you are trying to build the runtimes using Clang for a Windows target from a host, can you expand on this?

@trcrsired
Copy link
Author

yes
Using clang --target=, not clang-cl to build

@trcrsired
Copy link
Author

trcrsired commented Jun 27, 2024

Can you please describe what you're trying to do? It looks like you are trying to build the runtimes using Clang for a Windows target from a host, can you expand on this?

i use clang, not clang-cl to build libcxx but it does not pass -Xlinker to check the CMAKE_C_SIMULATE_ID.

https://github.com/trcrsired/windows-msvc-sysroot
See this PR:
#96417

Here is a test that shows how it works.
https://github.com/llvm/llvm-project/blob/3a1790211a993908d6a9ab3cca1fa6eb2421e710/clang/test/Driver/msvc-sysroot.cpp

ldionne added a commit to ldionne/llvm-project that referenced this issue Jun 27, 2024
If we're compiling with Clang (not clang-cl) on Windows, we need
to use -Xlinker to pass the /MANIFEST option.

Fixes llvm#96430
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this issue Jul 3, 2024
…lvm#96967)

If we're compiling with Clang (not clang-cl) on Windows, we need to use
-Xlinker to pass the /MANIFEST option.

Fixes llvm#96430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants