diff mbox

[COMMITTED] Avoid C++ tests when the C++ cannot be linked.

Message ID 20150304215551.7E6E22C3B7B@topped-with-meat.com
State New
Headers show

Commit Message

Roland McGrath March 4, 2015, 9:55 p.m. UTC
In a bootstrapping environment, libstdc++ is likely not to be available
when building libc.  This changes configure to check whether linking an
empty C++ program with ${CXX} works (it won't when libstdc++ is missing),
and elides all the C++ tests when that check fails.

I've verified the check passes on a normal installation and fails in a
partially-installed cross-compilation environment lacking libstdc++.


Thanks,
Roland


2015-03-04  Roland McGrath  <roland@hack.frob.com>

	* configure.ac (libc_cv_cxx_link_ok): New check.
	Reset CXX to empty if it fails to link.
	* configure: Regenerated.
	* dlfcn/Makefile (tests, modules-names): Add bug-atexit3 and
	bug-atexit3-lib only if $(CXX) is nonempty.
	* nptl/Makefile (tests): Likewise for tst-cancel24.
	(tests, tests-static): Likewise for tst-cancel24-static.
	* debug/Makefile (tests): Likewise for tst-chk4, tst-chk5, tst-chk6,
	tst-lfschk4, tst-lfschk5, and tst-lfschk6.

Comments

Carlos O'Donell March 5, 2015, 8:23 p.m. UTC | #1
On 03/04/2015 04:55 PM, Roland McGrath wrote:
> In a bootstrapping environment, libstdc++ is likely not to be available
> when building libc.  This changes configure to check whether linking an
> empty C++ program with ${CXX} works (it won't when libstdc++ is missing),
> and elides all the C++ tests when that check fails.
> 
> I've verified the check passes on a normal installation and fails in a
> partially-installed cross-compilation environment lacking libstdc++.
> 
> 
> Thanks,
> Roland
> 
> 
> 2015-03-04  Roland McGrath  <roland@hack.frob.com>
> 
> 	* configure.ac (libc_cv_cxx_link_ok): New check.
> 	Reset CXX to empty if it fails to link.
> 	* configure: Regenerated.
> 	* dlfcn/Makefile (tests, modules-names): Add bug-atexit3 and
> 	bug-atexit3-lib only if $(CXX) is nonempty.
> 	* nptl/Makefile (tests): Likewise for tst-cancel24.
> 	(tests, tests-static): Likewise for tst-cancel24-static.
> 	* debug/Makefile (tests): Likewise for tst-chk4, tst-chk5, tst-chk6,
> 	tst-lfschk4, tst-lfschk5, and tst-lfschk6.
> 

I don't like this. The semantics I would rather have are that all such
tests fail, not fail to build, but fail. Then the results of `make check`
represent reality with all the C++ tests failing because you don't have
a libstdc++. This way it's clear that you haven't passed all of the testing
for glibc.

Cheers,
Carlos.
Florian Weimer March 6, 2015, 10:34 a.m. UTC | #2
On 03/04/2015 10:55 PM, Roland McGrath wrote:
> +# It's useless to us if it can't link programs (e.g. missing -lstdc++).
> +AC_CACHE_CHECK([whether $CXX can link programs], libc_cv_cxx_link_ok, [dnl
> +AC_LANG_PUSH([C++])
> +AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
> +	       [libc_cv_cxx_link_ok=yes],
> +	       [libc_cv_cxx_link_ok=no])
> +AC_LANG_POP([C++])])
> +AS_IF([test $libc_cv_cxx_link_ok != yes], [CXX=])

The most common test failure is likely a working C++ compiler which
cannot link libstdc++ statically.  This causes a “make check” abort,
without an error summary report.  Your configure change does not address
that at all.
Roland McGrath March 7, 2015, 12:36 a.m. UTC | #3
> The most common test failure is likely a working C++ compiler which
> cannot link libstdc++ statically.  

That's not something I've seen.

> This causes a  make check  abort, without an error summary report.  Your
> configure change does not address that at all.

Feel free to send a change to make the configure check more demanding.


Thanks,
Roland
Roland McGrath March 7, 2015, 12:37 a.m. UTC | #4
> I don't like this. The semantics I would rather have are that all such
> tests fail, not fail to build, but fail. Then the results of `make check`
> represent reality with all the C++ tests failing because you don't have
> a libstdc++. This way it's clear that you haven't passed all of the testing
> for glibc.

I don't like the conflation of unbuildable with failed.  What we need is
the possibility of UNSUPPORTED as an outcome for our tests.  I'll send a
change in that direction.
Carlos O'Donell March 7, 2015, 6:37 p.m. UTC | #5
On 03/06/2015 07:37 PM, Roland McGrath wrote:
>> I don't like this. The semantics I would rather have are that all such
>> tests fail, not fail to build, but fail. Then the results of `make check`
>> represent reality with all the C++ tests failing because you don't have
>> a libstdc++. This way it's clear that you haven't passed all of the testing
>> for glibc.
> 
> I don't like the conflation of unbuildable with failed.  What we need is
> the possibility of UNSUPPORTED as an outcome for our tests.  I'll send a
> change in that direction.

Good point. I like UNSUPPORTED better. My worry is that these tests simply
go missing and we don't notice. Fail safe is better.

Cheers,
Carlos.
diff mbox

Patch

--- a/configure.ac
+++ b/configure.ac
@@ -50,9 +50,18 @@  if test $host != $build; then
 fi
 AC_SUBST(cross_compiling)
 AC_PROG_CPP
+AC_CHECK_TOOL(READELF, readelf, false)
+
 # We need the C++ compiler only for testing.
 AC_PROG_CXX
-AC_CHECK_TOOL(READELF, readelf, false)
+# It's useless to us if it can't link programs (e.g. missing -lstdc++).
+AC_CACHE_CHECK([whether $CXX can link programs], libc_cv_cxx_link_ok, [dnl
+AC_LANG_PUSH([C++])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+	       [libc_cv_cxx_link_ok=yes],
+	       [libc_cv_cxx_link_ok=no])
+AC_LANG_POP([C++])])
+AS_IF([test $libc_cv_cxx_link_ok != yes], [CXX=])
 
 if test "`cd $srcdir; /bin/pwd`" = "`/bin/pwd`"; then
   AC_MSG_ERROR([you must configure in a separate build directory])
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -133,10 +133,13 @@  LDFLAGS-tst-backtrace6 = -rdynamic
 
 tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \
 	tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \
-	tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \
 	tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 tst-backtrace4 \
 	tst-backtrace5 tst-backtrace6
 
+ifneq (,$(CXX))
+tests += tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6
+endif
+
 extra-libs = libSegFault libpcprofile
 extra-libs-others = $(extra-libs)
 
--- a/dlfcn/Makefile
+++ b/dlfcn/Makefile
@@ -36,12 +36,12 @@  endif
 ifeq (yes,$(build-shared))
 tests = glrefmain failtest tst-dladdr default errmsg1 tstcxaatexit \
 	bug-dlopen1 bug-dlsym1 tst-dlinfo bug-atexit1 bug-atexit2 \
-	bug-atexit3 tstatexit bug-dl-leaf tst-rec-dlopen
+	tstatexit bug-dl-leaf tst-rec-dlopen
 endif
 modules-names = glreflib1 glreflib2 glreflib3 failtestmod defaultmod1 \
 		defaultmod2 errmsg1mod modatexit modcxaatexit \
 		bug-dlsym1-lib1 bug-dlsym1-lib2 bug-atexit1-lib \
-		bug-atexit2-lib bug-atexit3-lib bug-dl-leaf-lib \
+		bug-atexit2-lib bug-dl-leaf-lib \
 		bug-dl-leaf-lib-cb moddummy1 moddummy2
 
 failtestmod.so-no-z-defs = yes
@@ -57,6 +57,11 @@  tststatic2-ENV = $(tststatic-ENV)
 tststatic3-ENV = $(tststatic-ENV)
 tststatic4-ENV = $(tststatic-ENV)
 tststatic5-ENV = $(tststatic-ENV)
+
+ifneq (,$(CXX))
+tests += bug-atexit3
+modules-names += bug-atexit3-lib
+endif
 endif
 
 extra-test-objs += $(modules-names:=.os)
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -245,8 +245,8 @@  tests = tst-typesizes \
 	tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
 	tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
 	tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
-	tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 tst-cancel25 \
-	tst-cancel-self tst-cancel-self-cancelstate \
+	tst-cancel21 tst-cancel22 tst-cancel23 $(if $(CXX),tst-cancel24) \
+	tst-cancel25 tst-cancel-self tst-cancel-self-cancelstate \
 	tst-cancel-self-canceltype tst-cancel-self-testcancel \
 	tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
 	tst-flock1 tst-flock2 \
@@ -364,14 +364,19 @@  link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
 		    $(common-objpfx)libc.a
 
 tests-static += tst-locale1 tst-locale2 tst-stackguard1-static \
-		tst-cancel21-static tst-cancel24-static tst-cond8-static \
+		tst-cancel21-static tst-cond8-static \
 		tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
 		tst-sem12-static
-tests += tst-stackguard1-static tst-cancel21-static tst-cancel24-static \
+tests += tst-stackguard1-static tst-cancel21-static \
 	 tst-cond8-static tst-mutex8-static tst-mutexpi8-static \
 	 tst-sem11-static tst-sem12-static
 xtests-static += tst-setuid1-static
 
+ifneq (,$(CXX))
+tests += tst-cancel24-static
+tests-static += tst-cancel24-static
+endif
+
 # These tests are linked with libc before libpthread
 tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x