diff mbox

Fix bootsrap/68041

Message ID 5627A7AA.40105@partner.samsung.com
State New
Headers show

Commit Message

max Oct. 21, 2015, 2:56 p.m. UTC
Hi,

recent libsanitizer merge ( 
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01851.html) broke 
bootstrap on x86_64-apple-darwin14 because for Darwin sanitizer libs 
shouldn't be linked with -lrt flag. Also, right now, libubsan links with 
-lc++abi for Darwin, that is wrong, because we don't want to link 
against system clang++'s C++ library (Dominique, am I right here?). This 
patch fixes bootstrap by adding additional check to determine if we 
really need librt for sanitizer_common into configure script and removes 
-lc++abi flag for UBSan on Darwin.

Tested on x86_64-linux-gnu, how does it look?

-Maxim

Comments

Jakub Jelinek Oct. 21, 2015, 3:01 p.m. UTC | #1
On Wed, Oct 21, 2015 at 05:56:42PM +0300, Maxim Ostapenko wrote:
> Hi,
> 
> recent libsanitizer merge (
> https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01851.html) broke bootstrap on
> x86_64-apple-darwin14 because for Darwin sanitizer libs shouldn't be linked
> with -lrt flag. Also, right now, libubsan links with -lc++abi for Darwin,
> that is wrong, because we don't want to link against system clang++'s C++
> library (Dominique, am I right here?). This patch fixes bootstrap by adding
> additional check to determine if we really need librt for sanitizer_common
> into configure script and removes -lc++abi flag for UBSan on Darwin.
> 
> Tested on x86_64-linux-gnu, how does it look?

Ok with me if it is ok with the Darwin maintainers.

> libsanitizer/ChangeLog:
> 
> 2015-10-21  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>
> 
> 	PR bootstrap/68041
> 
> 	* configure.ac (link_sanitizer_common): Link against librt only if it
> 	contains shm_open, required by sanitizers.
> 	(CXX_ABI_NEEDED): Remove variable.
> 	* configure: Regenerate.
> 	* ubsan/Makefile.am (libubsan_la_LIBADD): Do not add -lc++abi anymore.
> 	* ubsan/Makefile.in: Regenerate.

	Jakub
Mike Stump Oct. 21, 2015, 5:46 p.m. UTC | #2
On Oct 21, 2015, at 8:01 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Oct 21, 2015 at 05:56:42PM +0300, Maxim Ostapenko wrote:
>> 
>> recent libsanitizer merge (
>> https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01851.html) broke bootstrap on
>> x86_64-apple-darwin14 because for Darwin sanitizer libs shouldn't be linked
>> with -lrt flag. Also, right now, libubsan links with -lc++abi for Darwin,
>> that is wrong, because we don't want to link against system clang++'s C++
>> library (Dominique, am I right here?). This patch fixes bootstrap by adding
>> additional check to determine if we really need librt for sanitizer_common
>> into configure script and removes -lc++abi flag for UBSan on Darwin.
>> 
>> Tested on x86_64-linux-gnu, how does it look?
> 
> Ok with me if it is ok with the Darwin maintainers.

Ok.
diff mbox

Patch

libsanitizer/ChangeLog:

2015-10-21  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>

	PR bootstrap/68041

	* configure.ac (link_sanitizer_common): Link against librt only if it
	contains shm_open, required by sanitizers.
	(CXX_ABI_NEEDED): Remove variable.
	* configure: Regenerate.
	* ubsan/Makefile.am (libubsan_la_LIBADD): Do not add -lc++abi anymore.
	* ubsan/Makefile.in: Regenerate.

Index: libsanitizer/configure
===================================================================
--- libsanitizer/configure	(revision 229119)
+++ libsanitizer/configure	(working copy)
@@ -616,8 +616,6 @@ 
 FORMAT_FILE
 SANITIZER_SUPPORTED_FALSE
 SANITIZER_SUPPORTED_TRUE
-USE_CXX_ABI_FLAG_FALSE
-USE_CXX_ABI_FLAG_TRUE
 USING_MAC_INTERPOSE_FALSE
 USING_MAC_INTERPOSE_TRUE
 link_liblsan
@@ -12029,7 +12027,7 @@ 
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12032 "configure"
+#line 12030 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12135,7 +12133,7 @@ 
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12138 "configure"
+#line 12136 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15516,8 +15514,52 @@ 
 
 
 # Common libraries that we need to link against for all sanitizer libs.
-link_sanitizer_common='-lrt -lpthread -ldl -lm'
+link_sanitizer_common='-lpthread -ldl -lm'
 
+# At least for glibc, shm_open is in librt.  But don't pull that
+# in if it still doesn't give us the function we want.  This
+# test is copied from libgomp.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for shm_open in -lrt" >&5
+$as_echo_n "checking for shm_open in -lrt... " >&6; }
+if test "${ac_cv_lib_rt_shm_open+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lrt  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shm_open ();
+int
+main ()
+{
+return shm_open ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_rt_shm_open=yes
+else
+  ac_cv_lib_rt_shm_open=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_shm_open" >&5
+$as_echo "$ac_cv_lib_rt_shm_open" >&6; }
+if test "x$ac_cv_lib_rt_shm_open" = x""yes; then :
+  link_sanitizer_common="-lrt $link_sanitizer_common"
+fi
+
+
 # Set up the set of additional libraries that we need to link against for libasan.
 link_libasan=$link_sanitizer_common
 
@@ -15534,9 +15576,57 @@ 
 link_liblsan=$link_sanitizer_common
 
 
+
+# At least for glibc, clock_gettime is in librt.  But don't pull that
+# in if it still doesn't give us the function we want.  This
+# test is copied from libgomp.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5
+$as_echo_n "checking for clock_gettime in -lrt... " >&6; }
+if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lrt  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clock_gettime ();
+int
+main ()
+{
+return clock_gettime ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_rt_clock_gettime=yes
+else
+  ac_cv_lib_rt_clock_gettime=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5
+$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; }
+if test "x$ac_cv_lib_rt_clock_gettime" = x""yes; then :
+  link_libasan="-lrt $link_libasan"
+link_libtsan="-lrt $link_libtsan"
+# Other sanitizers do not override clock_* API
+
+fi
+
+
 case "$host" in
-  *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ; CXX_ABI_NEEDED=true ;;
-  *) MAC_INTERPOSE=false ; CXX_ABI_NEEDED=false ;;
+  *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
+  *) MAC_INTERPOSE=false ;;
 esac
  if $MAC_INTERPOSE; then
   USING_MAC_INTERPOSE_TRUE=
@@ -15546,15 +15636,7 @@ 
   USING_MAC_INTERPOSE_FALSE=
 fi
 
- if $CXX_ABI_NEEDED; then
-  USE_CXX_ABI_FLAG_TRUE=
-  USE_CXX_ABI_FLAG_FALSE='#'
-else
-  USE_CXX_ABI_FLAG_TRUE='#'
-  USE_CXX_ABI_FLAG_FALSE=
-fi
 
-
 backtrace_supported=yes
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for necessary platform features" >&5
@@ -16511,10 +16593,6 @@ 
   as_fn_error "conditional \"USING_MAC_INTERPOSE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
-if test -z "${USE_CXX_ABI_FLAG_TRUE}" && test -z "${USE_CXX_ABI_FLAG_FALSE}"; then
-  as_fn_error "conditional \"USE_CXX_ABI_FLAG\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
-fi
 if test -z "${SANITIZER_SUPPORTED_TRUE}" && test -z "${SANITIZER_SUPPORTED_FALSE}"; then
   as_fn_error "conditional \"SANITIZER_SUPPORTED\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
Index: libsanitizer/configure.ac
===================================================================
--- libsanitizer/configure.ac	(revision 229119)
+++ libsanitizer/configure.ac	(working copy)
@@ -96,8 +96,14 @@ 
 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
 
 # Common libraries that we need to link against for all sanitizer libs.
-link_sanitizer_common='-lrt -lpthread -ldl -lm'
+link_sanitizer_common='-lpthread -ldl -lm'
 
+# At least for glibc, shm_open is in librt.  But don't pull that
+# in if it still doesn't give us the function we want.  This
+# test is copied from libgomp.
+AC_CHECK_LIB(rt, shm_open,
+  [link_sanitizer_common="-lrt $link_sanitizer_common"])
+
 # Set up the set of additional libraries that we need to link against for libasan.
 link_libasan=$link_sanitizer_common
 AC_SUBST(link_libasan)
@@ -114,12 +120,21 @@ 
 link_liblsan=$link_sanitizer_common
 AC_SUBST(link_liblsan)
 
+
+# At least for glibc, clock_gettime is in librt.  But don't pull that
+# in if it still doesn't give us the function we want.  This
+# test is copied from libgomp.
+AC_CHECK_LIB(rt, clock_gettime,
+  [link_libasan="-lrt $link_libasan"
+link_libtsan="-lrt $link_libtsan"
+# Other sanitizers do not override clock_* API
+])
+
 case "$host" in
-  *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ; CXX_ABI_NEEDED=true ;;
-  *) MAC_INTERPOSE=false ; CXX_ABI_NEEDED=false ;;
+  *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
+  *) MAC_INTERPOSE=false ;;
 esac
 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
-AM_CONDITIONAL(USE_CXX_ABI_FLAG, $CXX_ABI_NEEDED)
 
 backtrace_supported=yes
 
Index: libsanitizer/ubsan/Makefile.am
===================================================================
--- libsanitizer/ubsan/Makefile.am	(revision 229119)
+++ libsanitizer/ubsan/Makefile.am	(working copy)
@@ -35,9 +35,6 @@ 
 libubsan_la_LIBADD += $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la
 endif
 libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS)
-if USE_CXX_ABI_FLAG
-libubsan_la_LIBADD += -lc++abi
-endif
 libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan)
 
 # Use special rules for files that require RTTI support.
Index: libsanitizer/ubsan/Makefile.in
===================================================================
--- libsanitizer/ubsan/Makefile.in	(revision 229119)
+++ libsanitizer/ubsan/Makefile.in	(working copy)
@@ -54,7 +54,6 @@ 
 target_triplet = @target@
 @USING_MAC_INTERPOSE_FALSE@am__append_1 = $(top_builddir)/interception/libinterception.la
 @LIBBACKTRACE_SUPPORTED_TRUE@am__append_2 = $(top_builddir)/libbacktrace/libsanitizer_libbacktrace.la
-@USE_CXX_ABI_FLAG_TRUE@am__append_3 = -lc++abi
 subdir = ubsan
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -107,8 +106,7 @@ 
 am__DEPENDENCIES_1 =
 libubsan_la_DEPENDENCIES =  \
 	$(top_builddir)/sanitizer_common/libsanitizer_common.la \
-	$(am__append_1) $(am__append_2) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1)
+	$(am__append_1) $(am__append_2) $(am__DEPENDENCIES_1)
 am__objects_1 = ubsan_diag.lo ubsan_flags.lo ubsan_handlers.lo \
 	ubsan_handlers_cxx.lo ubsan_init.lo ubsan_type_hash.lo \
 	ubsan_type_hash_itanium.lo ubsan_type_hash_win.lo \
@@ -312,8 +310,7 @@ 
 libubsan_la_SOURCES = $(ubsan_files) 
 libubsan_la_LIBADD =  \
 	$(top_builddir)/sanitizer_common/libsanitizer_common.la \
-	$(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS) \
-	$(am__append_3)
+	$(am__append_1) $(am__append_2) $(LIBSTDCXX_RAW_CXX_LDFLAGS)
 libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan)
 
 # Work around what appears to be a GNU make bug handling MAKEFLAGS