PR bootstrap/25672: Avoid CFLAGS in CFLAGS_FOR_TARGETS if cross-compiling
diff mbox

Message ID 54FE1D2D.7060301@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez March 9, 2015, 10:22 p.m. UTC
Hello gentlemen.

The problem here is that we pick up the system's CFLAGS and pass it down 
to the target libraries.  This causes havoc when, for instance, CFLAGS 
is -march=x86-64 and the target is powerpc-linux.

I don't see in what scenario the toplevel shell's CFLAGS would be of any 
use in the target libraries, so I've just avoided that code path altogether.

Tested by doing a cross-build from x86-64 to ppc64-linux-gnu in a 
combined tree, and seeing if libgcc starts to build.  Previously we 
would fail while configuring GCC.  Now, gcc builds fine, and the target 
libraries start to build.

OK for mainline?

Aldy
commit f2d130b93f334c5c680761553624964f87594adf
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Mar 9 15:12:33 2015 -0700

    	PR bootstrap/25672
    	* configure.ac: Do not initialize CFLAGS_FOR_TARGET from CFLAGS if
    	cross-compiling.  Similarly for CXX_FOR_TARGET.
    	* configure: Regenerate.

Comments

Jeff Law March 10, 2015, 6:35 a.m. UTC | #1
On 03/09/15 16:22, Aldy Hernandez wrote:
> Hello gentlemen.
>
> The problem here is that we pick up the system's CFLAGS and pass it down
> to the target libraries.  This causes havoc when, for instance, CFLAGS
> is -march=x86-64 and the target is powerpc-linux.
>
> I don't see in what scenario the toplevel shell's CFLAGS would be of any
> use in the target libraries, so I've just avoided that code path
> altogether.
>
> Tested by doing a cross-build from x86-64 to ppc64-linux-gnu in a
> combined tree, and seeing if libgcc starts to build.  Previously we
> would fail while configuring GCC.  Now, gcc builds fine, and the target
> libraries start to build.
>
> OK for mainline?
>
> Aldy
>
> curr
>
>
> commit f2d130b93f334c5c680761553624964f87594adf
> Author: Aldy Hernandez<aldyh@redhat.com>
> Date:   Mon Mar 9 15:12:33 2015 -0700
>
>      	PR bootstrap/25672
>      	* configure.ac: Do not initialize CFLAGS_FOR_TARGET from CFLAGS if
>      	cross-compiling.  Similarly for CXX_FOR_TARGET.
>      	* configure: Regenerate.
I was wondering when someone would come across this oldie-but-goodie...

I'm sure someone, somewhere will complain that

make CFLAGS="whatever" isn't being passed down to the crossses as it has 
been for the last two decades.  And they'll be right.

But in the cross compiler case, I think it's reasonable to expect to 
have to use CFLAGS_FOR_TARGET so that we have separation between the 
host and target flags.  One could easily want to compile the host with 
one set of arguments and the target libraries with something completely 
different.

And note that the various .mt files already use the _FOR_TARGET macros 
to pass down additional flags rather than just CFLAGS or CXXFLAGS.



Are there any docs that need to change?  I don't recall any offhand, but 
if you could look prior to committing, it'd be appreciated.

OK for the trunk.

jeff
Aldy Hernandez March 10, 2015, 4:36 p.m. UTC | #2
On 03/09/2015 11:35 PM, Jeff Law wrote:
> On 03/09/15 16:22, Aldy Hernandez wrote:
>> Hello gentlemen.
>>
>> The problem here is that we pick up the system's CFLAGS and pass it down
>> to the target libraries.  This causes havoc when, for instance, CFLAGS
>> is -march=x86-64 and the target is powerpc-linux.
>>
>> I don't see in what scenario the toplevel shell's CFLAGS would be of any
>> use in the target libraries, so I've just avoided that code path
>> altogether.
>>
>> Tested by doing a cross-build from x86-64 to ppc64-linux-gnu in a
>> combined tree, and seeing if libgcc starts to build.  Previously we
>> would fail while configuring GCC.  Now, gcc builds fine, and the target
>> libraries start to build.
>>
>> OK for mainline?
>>
>> Aldy
>>
>> curr
>>
>>
>> commit f2d130b93f334c5c680761553624964f87594adf
>> Author: Aldy Hernandez<aldyh@redhat.com>
>> Date:   Mon Mar 9 15:12:33 2015 -0700
>>
>>          PR bootstrap/25672
>>          * configure.ac: Do not initialize CFLAGS_FOR_TARGET from
>> CFLAGS if
>>          cross-compiling.  Similarly for CXX_FOR_TARGET.
>>          * configure: Regenerate.
> I was wondering when someone would come across this oldie-but-goodie...
>
> I'm sure someone, somewhere will complain that
>
> make CFLAGS="whatever" isn't being passed down to the crossses as it has
> been for the last two decades.  And they'll be right.

Well, considering this hasn't worked since 4.0.2, with a brief respite 
in 4.4.0, I wouldn't worry too much.  For that matter, setting 
incompatible CFLAGS won't even survive a toplevel configure on trunk 
right now.  I doubt anyone is dependent on this feature :).

> But in the cross compiler case, I think it's reasonable to expect to
> have to use CFLAGS_FOR_TARGET so that we have separation between the
> host and target flags.  One could easily want to compile the host with
> one set of arguments and the target libraries with something completely
> different.
>
> And note that the various .mt files already use the _FOR_TARGET macros
> to pass down additional flags rather than just CFLAGS or CXXFLAGS.
>
>
>
> Are there any docs that need to change?  I don't recall any offhand, but
> if you could look prior to committing, it'd be appreciated.

Interestingly, there is nothing but a cursory reference to 
CFLAGS_FOR_TARGET in our docs:

@code{BOOT_CFLAGS} does not apply to bootstrapped target libraries.
Since these are always compiled with the compiler currently being
bootstrapped, you can use @code{CFLAGS_FOR_TARGET} to modify their
compilation flags, as for non-bootstrapped target libraries.
Again, if the native compiler miscompiles the stage1 compiler, you may
need to work around this by avoiding non-working parts of the stage1
compiler.  Use @code{STAGE1_TFLAGS} to this end.

Considering our entire cross-compilation section is actually quite 
lacking, I'm going to just commit as is.

Thanks.
Aldy

Patch
diff mbox

diff --git a/configure.ac b/configure.ac
index 00f7452..2a14c35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2319,28 +2319,36 @@  AC_SUBST(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
 # gcc) are built with "-O2 -g", so include those options when setting
 # CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET.
 if test "x$CFLAGS_FOR_TARGET" = x; then
-  CFLAGS_FOR_TARGET=$CFLAGS
-  case " $CFLAGS " in
-    *" -O2 "*) ;;
-    *) CFLAGS_FOR_TARGET="-O2 $CFLAGS_FOR_TARGET" ;;
-  esac
-  case " $CFLAGS " in
-    *" -g "* | *" -g3 "*) ;;
-    *) CFLAGS_FOR_TARGET="-g $CFLAGS_FOR_TARGET" ;;
-  esac
+  if test "x${is_cross_compiler}" = xyes; then
+    CFLAGS_FOR_TARGET="-g -O2"
+  else
+    CFLAGS_FOR_TARGET=$CFLAGS
+    case " $CFLAGS " in
+      *" -O2 "*) ;;
+      *) CFLAGS_FOR_TARGET="-O2 $CFLAGS_FOR_TARGET" ;;
+    esac
+    case " $CFLAGS " in
+      *" -g "* | *" -g3 "*) ;;
+      *) CFLAGS_FOR_TARGET="-g $CFLAGS_FOR_TARGET" ;;
+    esac
+  fi
 fi
 AC_SUBST(CFLAGS_FOR_TARGET)
 
 if test "x$CXXFLAGS_FOR_TARGET" = x; then
-  CXXFLAGS_FOR_TARGET=$CXXFLAGS
-  case " $CXXFLAGS " in
-    *" -O2 "*) ;;
-    *) CXXFLAGS_FOR_TARGET="-O2 $CXXFLAGS_FOR_TARGET" ;;
-  esac
-  case " $CXXFLAGS " in
-    *" -g "* | *" -g3 "*) ;;
-    *) CXXFLAGS_FOR_TARGET="-g $CXXFLAGS_FOR_TARGET" ;;
-  esac
+  if test "x${is_cross_compiler}" = xyes; then
+    CXXFLAGS_FOR_TARGET="-g -O2"
+  else
+    CXXFLAGS_FOR_TARGET=$CXXFLAGS
+    case " $CXXFLAGS " in
+      *" -O2 "*) ;;
+      *) CXXFLAGS_FOR_TARGET="-O2 $CXXFLAGS_FOR_TARGET" ;;
+    esac
+    case " $CXXFLAGS " in
+      *" -g "* | *" -g3 "*) ;;
+      *) CXXFLAGS_FOR_TARGET="-g $CXXFLAGS_FOR_TARGET" ;;
+    esac
+  fi
 fi
 AC_SUBST(CXXFLAGS_FOR_TARGET)