[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread Louis Dionne via cfe-commits

https://github.com/ldionne closed 
https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread Martin Storsjö via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

mstorsjo wrote:

Yeah I think it's totally ok to remove. Whatever the setup was when those might 
have been needed on MSVC-like setups, they're not needed (or usable) currently 
- and our CI coverage is fairly good at the moment, I would say. So if this 
patch works, just go ahead!

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread via cfe-commits


@@ -108,22 +97,18 @@ if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for the
   # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(APPLE)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(FUCHSIA)
-  set(LIBCXX_HAS_M_LIB NO)

EricWF wrote:

Thanks for checking!

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread via cfe-commits

https://github.com/EricWF approved this pull request.

It's nice having CI for all the platforms, otherwise this would be harder to 
review and be confident about.

LGTM assuming everything passes.

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread via cfe-commits


@@ -14,14 +14,6 @@ include(CheckCSourceCompiles)
 # link with --uwnindlib=none. Check if that option works.
 llvm_check_compiler_linker_flag(C "--unwindlib=none" 
CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
 
-if(WIN32 AND NOT MINGW)

EricWF wrote:

If everything passes, I guess we're good? I

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread via cfe-commits

https://github.com/EricWF edited https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread Louis Dionne via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

ldionne wrote:

So it's OK to remove that `/nodefaultlib` and `/Zl` or should we look into 
building with that again? (Preferably in a separate patch since this is a 
pre-existing condition)

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-13 Thread Martin Storsjö via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

mstorsjo wrote:

Interesting; FWIW, it seems like the test for `/Zl` fails because it skips 
including the CRT glue code that takes the startup from the Windows specific 
`mainCRTStartup()` to the regular `main()`. I wonder when/if this test passed 
at some point.

As for how this works without those options: In MSVC build configs, the 
standard libraries usually aren't injected by the compiler when doing the link 
- on the contrary, in most cases, one doesn't actually do linking by invoking 
the compiler, but the build usually calls `link.exe` or `lld-link` directly. 
The info about what libraries should be linked in is conveyed via directives 
embedded in the object files. So as long as we're not using any MS STL headers 
that inject such directives, we don't automatically try to link against it.

Then secondly - in MSVC configurations, libc++ always builds on top of the MSVC 
C++ runtime for the base ABI stuff, so we actually do need it linked - and we 
pass the necessary libraries for that manually when we link our library.

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

ldionne wrote:

@mstorsjo FYI, I checked a recent Clang-CL (DLL) job like 
https://buildkite.com/llvm-project/libcxx-ci/builds/30715#018b257a-9457-4020-a4d0-3d22d4704e25
 and it seems like `/nodefaultlib` and `/Zl` are never detected as supported on 
Windows. Hence, we were never actually enabling those flags.

I'm not certain how the Windows build works without that but it seems like it 
does.

https://github.com/llvm/llvm-project/pull/68832
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68832

>From 9ca88d1a30ec1bcaa9c3c943c32649c36ad136d0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 11 Oct 2023 12:21:39 -0700
Subject: [PATCH 1/3] [libc++] Use -nostdlib++ on GCC unconditionally

We support GCC 13, which supports the flag. This allows simplifying
the CMake logic around the use of -nostdlib++. Note that there are
other places where we don't assume -nostdlib++ yet in the build, but
this patch is intentionally trying to be small because this part of
our CMake is pretty tricky.
---
 libcxx/CMakeLists.txt| 33 -
 libcxx/cmake/config-ix.cmake | 15 ---
 2 files changed, 4 insertions(+), 44 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 16540caf68eaf04..55ad0f49cbdb6fd 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -642,18 +642,11 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
+  if (MSVC)
+target_add_compile_flags(${target} PRIVATE "/Zl")
+target_link_libraries(${target} PRIVATE "/nodefaultlib")
   else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
+target_link_libraries(${target} PRIVATE "-nostdlib++")
   endif()
 
   if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
@@ -663,24 +656,6 @@ function(cxx_link_system_libraries target)
 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
   endif()
 
-  if (NOT APPLE) # On Apple platforms, we always use -nostdlib++ so we don't 
need to re-add other libraries
-if (LIBCXX_HAS_PTHREAD_LIB)
-  target_link_libraries(${target} PRIVATE pthread)
-endif()
-
-if (LIBCXX_HAS_C_LIB)
-  target_link_libraries(${target} PRIVATE c)
-endif()
-
-if (LIBCXX_HAS_M_LIB)
-  target_link_libraries(${target} PRIVATE m)
-endif()
-
-if (LIBCXX_HAS_RT_LIB)
-  target_link_libraries(${target} PRIVATE rt)
-endif()
-  endif()
-
   if (LIBCXX_USE_COMPILER_RT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
 if (LIBCXX_BUILTINS_LIBRARY)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 9962d848d85e846..9fed861a4e193c5 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -14,14 +14,6 @@ include(CheckCSourceCompiles)
 # link with --uwnindlib=none. Check if that option works.
 llvm_check_compiler_linker_flag(C "--unwindlib=none" 
CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
 
-if(WIN32 AND NOT MINGW)
-  # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, 
lets
-  # let the default linking take care of that.
-  set(LIBCXX_HAS_C_LIB NO)
-else()
-  check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
-endif()
-
 if (NOT LIBCXX_USE_COMPILER_RT)
   if(WIN32 AND NOT MINGW)
 set(LIBCXX_HAS_GCC_S_LIB NO)
@@ -54,9 +46,6 @@ else()
 endif()
 
 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
-  if (LIBCXX_HAS_C_LIB)
-list(APPEND CMAKE_REQUIRED_LIBRARIES c)
-  endif ()
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -108,22 +97,18 @@ if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for the
   # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(APPLE)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(FUCHSIA)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 else()
   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
-  check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 endif()

>From db65842e8ef437152a59cb72c9b690dd85bc10df Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Thu, 12 Oct 2023 16:20:32 -0700
Subject: [PATCH