diff mbox

[build,libgcc] Correctly apply c_flags in shared-object.mk

Message ID yddtybs5un0.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth June 14, 2011, 2:56 p.m. UTC
When I first did a Solaris 11/x86 bootstrap with gld after checking in
my ENABLE_EXECUTE_STACK patch, I found that several acats and gnat.dg
tests were failing.  This hadn't happened with Sun ld.

Reghunting revealed that this had been introduced by that patch.
Fortunately, not the code itself was at fault.  Instead, before the
patch _enable_execute_stack.o had been compiled without -fexceptions,
while afterwards (with enable-execute-stack.c added to LIB2ADD)
-fexceptions was used.  I don't yet understand why this is a problem,
and only with gld, but clearly this is not how the LIB2ADD and
LIB2ADD_ST objects are supposed to be compiled.  In libgcc/Makefile.in,
we have

# Build LIB2ADD and LIB2ADD_ST.
[...]
c_flags :=
iter-items := $(LIB2ADD) $(LIB2ADD_ST)
include $(iterator)

with

iterator = $(srcdir)/empty.mk $(patsubst %,$(srcdir)/shared-object.mk,$(iter-items))

The problem is that the rule created from shared-object.mk to compile
LIB2ADD members refers to $(c_flags), but that variable is evaluated at
the point the rule is invoked, not when it is created.

Makefile.in sets c_flags 3 times:

# Build LIB2ADD and LIB2ADD_ST.
[...]
c_flags :=

# Build LIB2ADDEH, LIB2ADDEHSTATIC, and LIB2ADDEHSHARED.  If we don't have
[...]
c_flags := -fexceptions

# Build LIBUNWIND.
[...]
c_flags := -fexceptions

The effect is that not only LIB2ADDEH* and LIBUNWIND sources are
compiled with -fexceptions, but everything in LIB2ADD{, _ST}.

The following patch fixes this by storing the current value of c_flags
in a per-source variable and using that in the generated rules.  I've
checked that the LIB2ADD members are no longer compiled with
-fexceptions.  With that patch, all the acats and gnat.dg failures are
gone.

Bootstrapped without regressions on i386-pc-solaris2.11.

Ok for mainline?

	Rainer


2011-06-12  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* shared-object.mk ($o-opt): Save c_flags.
	($(base)$(objext)): Use it.
	($(base)_s$(objext)): Likewise.
diff mbox

Patch

diff --git a/libgcc/shared-object.mk b/libgcc/shared-object.mk
--- a/libgcc/shared-object.mk
+++ b/libgcc/shared-object.mk
@@ -6,13 +6,17 @@  iter-items := $(filter-out $o,$(iter-ite
 
 base := $(basename $(notdir $o))
 
+$o-opt := $(c_flags)
+
+#$(info $o: c_flags=$(c_flags) o-opt=$($(o)-opt))
+
 ifeq ($(suffix $o),.c)
 
 $(base)$(objext): $o
-	$(gcc_compile) $(c_flags) -c $< $(vis_hide)
+	$(gcc_compile) $($<-opt) -c $< $(vis_hide)
 
 $(base)_s$(objext): $o
-	$(gcc_s_compile) $(c_flags) -c $<
+	$(gcc_s_compile) $($<-opt) -c $<
 
 else