diff mbox

[BZ,#20314] Make copies of cstdlib/cmath and use them

Message ID 20160630165739.GA2465@intel.com
State Committed
Delegated to: Carlos O'Donell
Headers show

Commit Message

H.J. Lu June 30, 2016, 4:57 p.m. UTC
If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
/usr/include/stdlib.h or /usr/include/math.h from "#include_next"
(instead of stdlib/stdlib.h or math/math.h in the glibc source
directory), and this turns up as a make dependency.  An implicit
rule will kick in and make will try to install stdlib/stdlib.h or
math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
the target is out of date.  We make a copy of <cstdlib> and <cmath>
in the glibc build directory so that stdlib/stdlib.h and math/math.h
will be used instead of /usr/include/stdlib.h and /usr/include/math.h.

OK for master?

H.J.
---
	[BZ #20314]
	* Makeconfig (CXXFLAGS): Prepend -I$(common-objpfx).
	* Makerules (before-compile): Add $(common-objpfx)cstdlib and
	$(common-objpfx)cmath.
	($(common-objpfx)cstdlib): New target.
	($(common-objpfx)cmath): Likewise.
---
 Makeconfig |  3 ++-
 Makerules  | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

Comments

Mike Frysinger July 4, 2016, 6:45 a.m. UTC | #1
see this thread:
https://sourceware.org/ml/libc-alpha/2016-06/msg00246.html
-mike
H.J. Lu July 4, 2016, 4:04 p.m. UTC | #2
On Sun, Jul 3, 2016 at 11:45 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> see this thread:
> https://sourceware.org/ml/libc-alpha/2016-06/msg00246.html
> -mike

It doesn't fix "make xcheck" nor I think <stdlib.h> should be included
first for any C++ tests.
Carlos O'Donell July 4, 2016, 8:36 p.m. UTC | #3
On 06/30/2016 12:57 PM, H.J. Lu wrote:
> If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
> /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
> (instead of stdlib/stdlib.h or math/math.h in the glibc source
> directory), and this turns up as a make dependency.  An implicit
> rule will kick in and make will try to install stdlib/stdlib.h or
> math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
> the target is out of date.  We make a copy of <cstdlib> and <cmath>
> in the glibc build directory so that stdlib/stdlib.h and math/math.h
> will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
> 
> OK for master?
> 
> H.J.
> ---
> 	[BZ #20314]
> 	* Makeconfig (CXXFLAGS): Prepend -I$(common-objpfx).
> 	* Makerules (before-compile): Add $(common-objpfx)cstdlib and
> 	$(common-objpfx)cmath.
> 	($(common-objpfx)cstdlib): New target.
> 	($(common-objpfx)cmath): Likewise.

This looks good to me.

However, I'd like Florian to sign off on this solution since he's looked
at it more directly when fixing the C++ failure he saw.
Mike Frysinger July 5, 2016, 1:11 a.m. UTC | #4
On 30 Jun 2016 09:57, H.J. Lu wrote:
> +		| grep cstdlib: | sed -e "s/:$$//")

| sed -n "/cstdlib:/{s/:$$//;p}")
-mike
diff mbox

Patch

diff --git a/Makeconfig b/Makeconfig
index 901e253..03fd89c 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -889,7 +889,8 @@  override CFLAGS	= -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
 		  $(CFLAGS-$(@F)) $(tls-model) \
 		  $(foreach lib,$(libof-$(basename $(@F))) \
 				$(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
-override CXXFLAGS = $(c++-sysincludes) \
+# Use our copies of cstdlib and cmath.
+override CXXFLAGS = -I$(common-objpfx) $(c++-sysincludes) \
 		    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
 		    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
 
diff --git a/Makerules b/Makerules
index f1ecd40..0960412 100644
--- a/Makerules
+++ b/Makerules
@@ -109,6 +109,30 @@  endif # avoid-generated
 endif # $(build-shared) = yes
 
 ifndef avoid-generated
+ifneq (,$(CXX))
+# If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
+# /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
+# (instead of stdlib/stdlib.h or math/math.h in the glibc source
+# directory), and this turns up as a make dependency.  An implicit
+# rule will kick in and make will try to install stdlib/stdlib.h or
+# math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
+# the target is out of date.  We make a copy of <cstdlib> and <cmath>
+# in the glibc build directory so that stdlib/stdlib.h and math/math.h
+# will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
+before-compile := $(common-objpfx)cstdlib $(before-compile)
+cstdlib=$(shell echo "\#include <cstdlib>" | $(CXX) -M -MP -x c++ - \
+		| grep cstdlib: | sed -e "s/:$$//")
+$(common-objpfx)cstdlib: $(cstdlib)
+	$(INSTALL_DATA) $< $@T
+	$(move-if-change) $@T $@
+before-compile := $(common-objpfx)cmath $(before-compile)
+cmath=$(shell echo "\#include <cmath>" | $(CXX) -M -MP -x c++ - \
+		| grep cmath: | sed -e "s/:$$//")
+$(common-objpfx)cmath: $(cmath)
+	$(INSTALL_DATA) $< $@T
+	$(move-if-change) $@T $@
+endif
+
 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \