[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

2016-10-14 Thread Michał Górny via cfe-commits
mgorny added a comment.

In https://reviews.llvm.org/D25568#570222, @EricWF wrote:

> This doesn't seem right seeing as `print-libgcc_file-name`  prints the 
> `libgcc.a` path, and we were previously linking `libgcc_s`.


Do you have any other solution in mind? There is no switch to print the shared 
library path. Should I modify it to detect whether the printed path matches 
`libgcc.a` and use `libgcc_s` in that case?

Just to be clear, since libgcc_s is the shared version of libgcc (+ libgcc_eh), 
this is mostly a matter of replacing dynamic linking with static. However, it 
doesn't matter much since in most of the cases no library function is actually 
used. From my experience, throughout 3.8.1 .. HEAD, no builtin functions were 
needed on amd64 and only one (__udiv3, if I recall correctly) was needed on 
32-bit x86. In this case, I dare say using the static library may actually be 
less problematic as it makes libc++ less dependent on compiler runtime.

Of course, on the other hand we have the unwinder library which still can be 
`gcc_s` and there is no easy way to solve this dependency.


https://reviews.llvm.org/D25568



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

2016-10-14 Thread Eric Fiselier via cfe-commits
EricWF requested changes to this revision.
EricWF added a comment.
This revision now requires changes to proceed.

This doesn't seem right seeing as `print-libgcc_file-name`  prints the 
`libgcc.a` path, and we were previously linking `libgcc_s`.


https://reviews.llvm.org/D25568



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

2016-10-13 Thread Michał Górny via cfe-commits
mgorny updated this revision to Diff 74538.
mgorny added a comment.

Fixed indentation.


https://reviews.llvm.org/D25568

Files:
  cmake/Modules/HandleLibcxxFlags.cmake
  lib/CMakeLists.txt


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_CXX_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  if (${libgcc_check_ret} EQUAL 0)
+add_library_flags("${libgcc_path}")
+  else()
+add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+  endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_CXX_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  if (${libgcc_check_ret} EQUAL 0)
+add_library_flags("${libgcc_path}")
+  else()
+add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+  endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

2016-10-13 Thread Michał Górny via cfe-commits
mgorny updated the summary for this revision.
mgorny updated this revision to Diff 74536.

https://reviews.llvm.org/D25568

Files:
  cmake/Modules/HandleLibcxxFlags.cmake
  lib/CMakeLists.txt


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_CXX_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+if (${libgcc_check_ret} EQUAL 0)
+  add_library_flags("${libgcc_path}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_CXX_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+if (${libgcc_check_ret} EQUAL 0)
+  add_library_flags("${libgcc_path}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

2016-10-13 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added a reviewer: EricWF.
mgorny added a subscriber: cfe-commits.
Herald added subscribers: modocache, beanz.

Use the -print-libgcc-file-name compiler option to obtain the path to
libgcc or an equivalent compiler runtime library, rather than hardcoding
-lgcc_s. This aims to make it possible to avoid linking with -lgcc_s
when -rtlib=compiler-rt is used along with libunwind.


https://reviews.llvm.org/D25568

Files:
  cmake/Modules/HandleLibcxxFlags.cmake
  lib/CMakeLists.txt


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_C_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+if (${libgcc_check_ret} EQUAL 0)
+  add_library_flags("${libgcc_path}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -83,7 +83,7 @@
 add_library_flags_if(LIBCXX_HAS_C_LIB c)
 add_library_flags_if(LIBCXX_HAS_M_LIB m)
 add_library_flags_if(LIBCXX_HAS_RT_LIB rt)
-add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+add_libgcc_library()
 add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
 
 # Add the unwinder library.
@@ -95,6 +95,8 @@
   else()
 add_interface_library(unwind)
   endif()
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
 endif()
 
 # Setup flags.
Index: cmake/Modules/HandleLibcxxFlags.cmake
===
--- cmake/Modules/HandleLibcxxFlags.cmake
+++ cmake/Modules/HandleLibcxxFlags.cmake
@@ -196,6 +196,29 @@
   endforeach()
 endmacro()
 
+# Attempt to detect the correct compiler runtime library and add it
+# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available.
+macro(add_libgcc_library)
+  # split space-separated vars into a list
+  set(libgcc_cmd ${CMAKE_C_COMPILER}
+ ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}
+ ${CMAKE_CXX_FLAGS}
+ ${CMAKE_SHARED_LINKER_FLAGS}
+ -print-libgcc-file-name)
+
+  execute_process(
+COMMAND "${libgcc_cmd}"
+RESULT_VARIABLE libgcc_check_ret
+OUTPUT_VARIABLE libgcc_path
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+if (${libgcc_check_ret} EQUAL 0)
+  add_library_flags("${libgcc_path}")
+else()
+  add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s)
+endif()
+endmacro()
+
 # Turn a comma separated CMake list into a space separated string.
 macro(split_list listname)
   string(REPLACE ";" " " ${listname} "${${listname}}")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits