Bug 65351 - [5 Regression] libiberty's pic version contains non-pic code on m32 darwin; causes bootstrap fail building libcc1.
Summary: [5 Regression] libiberty's pic version contains non-pic code on m32 darwin; c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P1 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2015-03-08 17:17 UTC by Dominique d'Humieres
Modified: 2015-04-10 06:54 UTC (History)
3 users (show)

See Also:
Host: m32 *-apple-darwin*
Target: m32 *-apple-darwin*
Build: m32 *-apple-darwin*
Known to work:
Known to fail:
Last reconfirmed: 2015-03-08 00:00:00


Attachments
Patch addressing review comments (5.29 KB, patch)
2015-03-29 20:31 UTC, Iain Sandoe
Details | Diff
minimum change (326 bytes, patch)
2015-04-02 11:57 UTC, Iain Sandoe
Details | Diff
patch under test. (924 bytes, patch)
2015-04-07 23:13 UTC, Iain Sandoe
Details | Diff
patch against 221916 (1.76 KB, patch)
2015-04-08 11:15 UTC, Iain Sandoe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2015-03-08 17:17:04 UTC
Boostrapping gcc on powerpc-apple-darwin9 fails with

libtool: link:  /opt/gcc/rel_build/./gcc/xg++ -B/opt/gcc/rel_build/./gcc/ -nostdinc++ -nostdinc++ -I/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/include/powerpc-apple-darwin9.8.0 -I/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/include -I/opt/gcc/rel_work/libstdc++-v3/libsupc++ -I/opt/gcc/rel_work/libstdc++-v3/include/backward -I/opt/gcc/rel_work/libstdc++-v3/testsuite/util -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/src -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/src/.libs -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/libsupc++/.libs -B/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/src/.libs -B/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/libsupc++/.libs -B/opt/gcc/gcc5.0r/powerpc-apple-darwin9.8.0/bin/ -B/opt/gcc/gcc5.0r/powerpc-apple-darwin9.8.0/lib/ -isystem /opt/gcc/gcc5.0r/powerpc-apple-darwin9.8.0/include -isystem /opt/gcc/gcc5.0r/powerpc-apple-darwin9.8.0/sys-include    -Wl,-undefined -Wl,dynamic_lookup -o .libs/libcc1.0.so -bundle  .libs/findcomp.o .libs/libcc1.o .libs/names.o .libs/callbacks.o .libs/connection.o .libs/marshall.o   -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/src -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/src/.libs -L/opt/gcc/rel_build/powerpc-apple-darwin9.8.0/libstdc++-v3/libsupc++/.libs  -static-libstdc++ -static-libgcc ../libiberty/pic/libiberty.a   -Wl,-exported_symbols_list,.libs/libcc1-symbols.expsym
ld: absolute addressing (perhaps -mdynamic-no-pic) used in _byte_common_op_match_null_string_p from ../libiberty/pic/libiberty.a(regex.o) not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs
collect2: error: ld returned 1 exit status
Comment 1 Iain Sandoe 2015-03-08 17:34:13 UTC
this affects all m32 Darwin, and has been "broken" since the pic version of libiberty was added - but has only become noticed now this (pic libiberty) is linked into libcc1.
Comment 2 Dominique d'Humieres 2015-03-08 17:37:59 UTC
Patch posted at https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00017.html.
Comment 3 Iain Sandoe 2015-03-29 20:31:50 UTC
Created attachment 35174 [details]
Patch addressing review comments

Will be posting this to @patches after some more checking.
Comment 4 Richard Biener 2015-03-31 13:01:30 UTC
i686-apple-darwin is a secondary arch and supposedly (but not verified?) affected.
A workaround is to disable building of libcc1 (but it's enabled by default it seems).
Comment 5 Iain Sandoe 2015-03-31 13:06:44 UTC
(In reply to Richard Biener from comment #4)
> i686-apple-darwin is a secondary arch and supposedly (but not verified?)
> affected.
> A workaround is to disable building of libcc1 (but it's enabled by default
> it seems).

i686-apple-darwin is affected, I will test the patch @comment #3 on linux and then re-post (it is addressing iant's review comments).

The workaround is to disable -mdynamic-no-pic in BOOT_CFLAGS, but that's just pretending that the problem doesn't exist, of course.
Comment 6 Jakub Jelinek 2015-03-31 16:00:07 UTC
The patch looks wrong, but passing -mdynamic-no-pic in BOOT_CFLAGS for Darwin is even more wrong.
BOOT_CFLAGS is feeding STAGE*_CFLAGS which is used to compile various stuff, not just the compiler binary itself, and given that the flag is incompatible with -fpic and some libraries are built with that, you just shouldn't pass that down.
libcc1 isn't the only thing broken by that, I think --enable-host-shared will fail miserably too on Darwin.
So, either config/mh-darwin should set some other variable (say NONPIC_HOST_CFLAGS or whatever) to -mdynamic-no-pic and you should arrange for it to be passed down as NONPIC_CFLAGS for modules being built for host, and you'd use that in e.g.
 # Enable --enable-host-shared
 AC_ARG_ENABLE(host-shared,
 [AS_HELP_STRING([--enable-host-shared],
                 [build host code as shared libraries])],
-[PICFLAG=-fPIC], [PICFLAG=])
+[PICFLAG=-fPIC], [PICFLAG=$NONPIC_CFLAGS])
 AC_SUBST(enable_host_shared)
 AC_SUBST(PICFLAG)
(in gcc/ and libcpp/, perhaps elsewhere where performance criticial), or you just not do it in config/mh-darwin, but in these two spots instead.
Really, passing some bogus flag down everywhere and then trying to remove it again is just too weird.
Another option is to make sure you use -fPIC (or -fpic) together with -mno-dynamic-no-pic on Darwin and that you pass it after the vars where -mdynamic-no-pic is set, then tweak libiberty/pic, gcc & libcpp --enable-host-shared etc. not to use that.
Comment 7 Iain Sandoe 2015-03-31 16:22:16 UTC
BOOT_CFLAGS has included -mdynamic-no-pic for a long time (before my time here), so I'm not aware of what criteria were discussed then, however

-mdynamic-non-pic cannot be overridden by fPIC.
 
I don't have spare cycles to investigate a more fine-grained approach in the short-term (although it seems like a reasonable way forward).

Anyway, in the light of comment #6 I'm abandoning this patch.
Comment 8 Jakub Jelinek 2015-03-31 16:31:56 UTC
But -mdynamic-no-pic can be overridden with -fPIC -mno-dynamic-no-pic , right?
Comment 9 Jakub Jelinek 2015-03-31 16:37:23 UTC
Does the following patch:

--- config/picflag.m4	2013-11-18 09:59:08.420212365 +0100
+++ config/picflag.m4	2015-03-31 18:36:21.989401000 +0200
@@ -9,7 +9,9 @@ case "${$2}" in
     *-*-darwin*)
 	# PIC is the default on this platform
 	# Common symbols not allowed in MH_DYLIB files
-	$1=-fno-common
+	# Cancel any earlier -mdynamic-no-pic, as that makes
+	# the code not suitable for shared libraries.
+	$1=-fno-common -mno-dynamic-no-pic
 	;;
     alpha*-dec-osf5*)
 	# PIC is the default.

fix the libcc1 issue?
Comment 10 Iain Sandoe 2015-03-31 18:48:34 UTC
(In reply to Jakub Jelinek from comment #9)
> Does the following patch:
> 
> --- config/picflag.m4	2013-11-18 09:59:08.420212365 +0100
> +++ config/picflag.m4	2015-03-31 18:36:21.989401000 +0200
> @@ -9,7 +9,9 @@ case "${$2}" in
>      *-*-darwin*)
>  	# PIC is the default on this platform
>  	# Common symbols not allowed in MH_DYLIB files
> -	$1=-fno-common
> +	# Cancel any earlier -mdynamic-no-pic, as that makes
> +	# the code not suitable for shared libraries.
> +	$1=-fno-common -mno-dynamic-no-pic

heh;
.. of course the first thing I tried was appending -fPIC here, which doesn't work.. why i didn't then think of this, no clue :)

It would be a good idea to check that the -fPIC default gets set correctly for -mdynamic-no-pic -mno-dynamic-no-pic, or alternately just append -fPIC here.  Will check which is needed.

I notice that there's no use of GCC_PICFLAG by libdecnumber (it just assumes -fPIC) and that several of the libraries have auto-tools with different versions from the default.

That aside, I'll look at applying this and regenerating configures where required.
Comment 11 Iain Sandoe 2015-04-02 11:57:47 UTC
Created attachment 35212 [details]
minimum change

OK - So Jakub's patch works with a minor change (quote the two components) viz:

-	$1=-fno-common
+	$1='-fno-common -mno-dynamic-no-pic'


1. the minimum change to fix this bug is to reconfigure libiberty with the changed picflag.m4 (the attached patch includes the regenerated libiberty/configure so that folks can test if they like).
 -- Perhaps we should extend that to all cases where */configure.ac calls GCC_PICFLAG (although it's not needed for this pr, it might save confusion when someone subsequently reconfigures).

2. I investigated --enable-host-shared and this seems to be a can of worms.
 - some places in the GCC tree just don't consider the possibility that the host/target might need pic options
 - most places just jam -fPIC regardless of the host.
 - if I go through all of these cases and add in GCC_PICFLAG / GCC_PICFLAG_TARGET as appropriate I can get --enable-host-shared builds to complete on m32 darwin (but it doesn't seem like stage4 change and isn't a regression in any case).
 - Even on x86_64 linux I don't see --enable-host-shared producing any .so for these host-side libs (it seems to just generate convenience libs with PIC code).
 - It's possible that some other places should be linking the PIC version of libiberty (e.g. libsupc++) …

- I need to test this minimum change on a couple more boxes.
Comment 12 Jakub Jelinek 2015-04-02 12:06:39 UTC
Thanks for fixing that thinko.  Please regenerate not just libiberty/configure, but also {gcc,libada,libgcc}/configure too.
The patch is ok for trunk with those changes with proper ChangeLog entry and when posted to gcc-patches.
I agree --enable-host-shared for darwin can certainly wait for stage1 or for whenever later anybody is actually interested in that on darwin.
Comment 13 Jakub Jelinek 2015-04-07 09:58:17 UTC
Author: jakub
Date: Tue Apr  7 09:57:46 2015
New Revision: 221891

URL: https://gcc.gnu.org/viewcvs?rev=221891&root=gcc&view=rev
Log:
	PR target/65351
config/
	* picflag.m4: Append -mno-dynamic-no-pic for Darwin.
libiberty/
	* configure: Regenerate.
libada/
	* configure: Regenerate.
libgcc/
	* configure: Regenerate.
gcc/
	* configure: Regenerate.

Modified:
    trunk/config/ChangeLog
    trunk/config/picflag.m4
    trunk/gcc/ChangeLog
    trunk/gcc/configure
    trunk/libada/ChangeLog
    trunk/libada/configure
    trunk/libgcc/ChangeLog
    trunk/libgcc/configure
    trunk/libiberty/ChangeLog
    trunk/libiberty/configure
Comment 14 Jakub Jelinek 2015-04-07 10:05:11 UTC
So hopefully fixed now.
Comment 15 Jack Howarth 2015-04-07 21:25:15 UTC
(In reply to Jakub Jelinek from comment #14)
> So hopefully fixed now.

This breaks the bootstrap on darwin14 here...

make[3]: Entering directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/libiberty'
if [ x"-fno-common -mno-dynamic-no-pic" != x ]; then \
  gcc -c -DHAVE_CONFIG_H -g   -I. -I../../gcc-5-20150407/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -pedantic  -fno-common -mno-dynamic-no-pic ../../gcc-5-20150407/libiberty/regex.c -o pic/regex.o; \
else true; fi
clang: error: unknown argument: '-mno-dynamic-no-pic'
Makefile:1167: recipe for target 'regex.o' failed
make[3]: *** [regex.o] Error 1
make[3]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/libiberty'
Makefile:9585: recipe for target 'all-stage1-libiberty' failed
make[2]: *** [all-stage1-libiberty] Error 2
make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir'
Makefile:20760: recipe for target 'stage1-bubble' failed
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir'
Makefile:21064: recipe for target 'bootstrap' failed
make: *** [bootstrap] Error 2

The default system compiler (Apple Clang 6.0) doesn't understand -mno-dynamic-no-pic.
Comment 16 Iain Sandoe 2015-04-07 21:30:37 UTC
(In reply to Jack Howarth from comment #15)
> (In reply to Jakub Jelinek from comment #14)
> > So hopefully fixed now.
> 
> This breaks the bootstrap on darwin14 here...
> 
> make[3]: Entering directory
> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/libiberty'
> if [ x"-fno-common -mno-dynamic-no-pic" != x ]; then \
>   gcc -c -DHAVE_CONFIG_H -g   -I.
> -I../../gcc-5-20150407/libiberty/../include  -W -Wall -Wwrite-strings
> -Wc++-compat -Wstrict-prototypes -pedantic  -fno-common -mno-dynamic-no-pic
> ../../gcc-5-20150407/libiberty/regex.c -o pic/regex.o; \
> else true; fi
> clang: error: unknown argument: '-mno-dynamic-no-pic'
> Makefile:1167: recipe for target 'regex.o' failed
> make[3]: *** [regex.o] Error 1
> make[3]: Leaving directory
> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/libiberty'
> Makefile:9585: recipe for target 'all-stage1-libiberty' failed
> make[2]: *** [all-stage1-libiberty] Error 2
> make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir'
> Makefile:20760: recipe for target 'stage1-bubble' failed
> make[1]: *** [stage1-bubble] Error 2
> make[1]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir'
> Makefile:21064: recipe for target 'bootstrap' failed
> make: *** [bootstrap] Error 2
> 
> The default system compiler (Apple Clang 6.0) doesn't understand
> -mno-dynamic-no-pic.

hmm OK. that's going to make life difficult.
Comment 17 Jack Howarth 2015-04-07 21:34:31 UTC
Can you revert r221891?
Comment 18 Iain Sandoe 2015-04-07 23:13:00 UTC
Created attachment 35249 [details]
patch under test.

treats m32 darwin as distinct from m64,

Since -mdynamic=no-pic is not used for the bootstrap compiler, this should still work to bootstrap i686-darwin* with clang.

Testing on x86_64=darwin13 (with clang bootstrap) and on powerpc-darwin9 (GCC bootstrap).

really, clang should respond properly to the inverse of -mdynamic-no-pic (will try to cook up a patch for that tomorrow).
Comment 19 Iain Sandoe 2015-04-07 23:19:33 UTC
(In reply to Iain Sandoe from comment #18)
> Created attachment 35249 [details]
> patch under test.
> 

> Since -mdynamic=no-pic is not used for the bootstrap compiler, this should
> still work to bootstrap i686-darwin* with clang.

this isn't correct on reflection, since the cancelling flag will be emitted at stage1 as well.

However, as an interim solution it will allow default bootstraps to complete while we find a wider fix.
Comment 20 Jakub Jelinek 2015-04-08 05:26:05 UTC
x86_64-darwin doesn't add -mdynamic-no-pic, so it is indeed not needed to add -mno-dynamic-no-pic for it.  I've been wondering about that, but then checked that gcc supports -mno-dynamic-no-pic even there.
So, does clang support -mno-dynamic-no-pic at least on i686 and powerpc 32-bit?
Or do we need to check for it in the config/picflag.m4 snippet?  Though, if it doesn't support -mno-dynamic-no-pic, is there any way how to cancel that flag in clang?
Comment 21 Jakub Jelinek 2015-04-08 05:47:47 UTC
Another option is not to add -mdynamic-no-pic for clang and other compilers that don't support -mno-dynamic-no-pic.
Comment 22 Iain Sandoe 2015-04-08 07:10:02 UTC
(In reply to Jakub Jelinek from comment #21)
> Another option is not to add -mdynamic-no-pic for clang and other compilers
> that don't support -mno-dynamic-no-pic.

clang supports (and generates appropriate code for) -mdynamic-no-pic.
as wee see (at present) it doesn't support -mno-dynamic-no-pic [(In reply to Jakub Jelinek from comment #21)
> Another option is not to add -mdynamic-no-pic for clang and other compilers
> that don't support -mno-dynamic-no-pic.

Yeah, that seems like the safest bet :-(.
(will try to get a patch together to fix future clang versions, but that won't alter the ones out in the wild).
Comment 23 Iain Sandoe 2015-04-08 07:52:50 UTC
something like this 

dnl Check if the current compiler supports -mno-dynamic-no-pic.
AC_DEFUN([GCC_CHECK_FLAG_NO_DYNAMIC_NO_PIC], [
  AC_CACHE_CHECK([whether the current compiler supports -mno-dynamic-no-pic],
		 ac_cv_have_mno_dynamic_no_pic, [
  mno_dynamic_no_pic_saved_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -mno-dynamic-no-pic"
  AC_TRY_COMPILE([void foo(void) { }],
		 [], ac_cv_have_mno_dynamic_no_pic=yes,
		 ac_cv_have_mno_dynamic_no_pic=no)
  CFLAGS="$mno_dynamic_no_pic_saved_CFLAGS"])
  if test x"$ac_cv_have_mno_dynamic_no_pic" = xyes; then
    MDYNAMIC_NO_PIC=-mdynamic-no-pic
    MNO_DYNAMIC_NO_PIC=-mno-dynamic-no-pic
  else
    MDYNAMIC_NO_PIC=
    MNO_DYNAMIC_NO_PIC=
  fi])

but .. the results need to be available to the mh-darwin
Comment 24 Jakub Jelinek 2015-04-08 08:40:13 UTC
So perhaps for the top level something like:
--- config/mh-darwin	2013-09-30 22:13:57.243907474 +0200
+++ config/mh-darwin	2015-04-08 10:36:58.100665592 +0200
@@ -1,18 +1,29 @@
 # The -mdynamic-no-pic ensures that the compiler executable is built without
 # position-independent-code -- the usual default on Darwin. This fix speeds
-# compiles by 3-5%.
-BOOT_CFLAGS += \
+# compiles by 3-5%.  Don't add it if the compiler doesn't also support
+# -mno-dynamic-no-pic to undo it.
+DARWIN_MDYNAMIC_NO_PIC := \
 `case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
-                 echo -mdynamic-no-pic ;; esac;`
+   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
+   && echo -mdynamic-no-pic ;; esac`
+DARWIN_GCC_MDYNAMIC_NO_PIC := \
+`case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
+   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
+   || echo -mdynamic-no-pic ;; esac`
 
 # ld on Darwin versions >= 10.7 defaults to PIE executables. Disable this for
 # gcc components, since it is incompatible with our pch implementation.
-BOOT_LDFLAGS += \
-`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+DARWIN_NO_PIE := `case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+
+BOOT_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
+BOOT_LDFLAGS += $(DARWIN_NO_PIE)
 
 # Similarly, for cross-compilation.
-STAGE1_CFLAGS += \
-`case ${host} in i?86-*-darwin* | powerpc-*-darwin*)\
-                 echo -mdynamic-no-pic ;; esac;`
-STAGE1_LDFLAGS += \
-`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+STAGE1_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
+STAGE1_LDFLAGS += $(DARWIN_NO_PIE)
+
+# Without -mno-dynamic-no-pic support, add -mdynamic-no-pic just to later
+# stages when we know it is built with gcc.
+STAGE2_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
+STAGE3_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
+STAGE4_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)

Thus, add -mdynamic-no-pic for gcc (or fixed clang) bootstrap compiler to
BOOT_CFLAGS and STAGE1_CFLAGS, but only to STAGE{2,3,4}_CFLAGS otherwise?

Then GCC_PICFLAG, being a configure snippet, can surely just use normal autoconfy way.
Comment 25 Iain Sandoe 2015-04-08 09:25:06 UTC
(In reply to Jakub Jelinek from comment #24)
> So perhaps for the top level something like:

yeah looks better than what i was drafting.

> --- config/mh-darwin	2013-09-30 22:13:57.243907474 +0200
> +++ config/mh-darwin	2015-04-08 10:36:58.100665592 +0200
> @@ -1,18 +1,29 @@
>  # The -mdynamic-no-pic ensures that the compiler executable is built without
>  # position-independent-code -- the usual default on Darwin. This fix speeds
> -# compiles by 3-5%.
> -BOOT_CFLAGS += \
> +# compiles by 3-5%.  Don't add it if the compiler doesn't also support
> +# -mno-dynamic-no-pic to undo it.
> +DARWIN_MDYNAMIC_NO_PIC := \
>  `case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
> -                 echo -mdynamic-no-pic ;; esac;`
> +   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
> +   && echo -mdynamic-no-pic ;; esac`
> +DARWIN_GCC_MDYNAMIC_NO_PIC := \
> +`case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
> +   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
> +   || echo -mdynamic-no-pic ;; esac`

I don't think we need the test here ^ ?

>  # ld on Darwin versions >= 10.7 defaults to PIE executables. Disable this
> for
>  # gcc components, since it is incompatible with our pch implementation.
> -BOOT_LDFLAGS += \
> -`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
> +DARWIN_NO_PIE := `case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;;
> esac;`
> +
> +BOOT_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
> +BOOT_LDFLAGS += $(DARWIN_NO_PIE)
>  
>  # Similarly, for cross-compilation.
> -STAGE1_CFLAGS += \
> -`case ${host} in i?86-*-darwin* | powerpc-*-darwin*)\
> -                 echo -mdynamic-no-pic ;; esac;`
> -STAGE1_LDFLAGS += \
> -`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
> +STAGE1_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
> +STAGE1_LDFLAGS += $(DARWIN_NO_PIE)
> +
> +# Without -mno-dynamic-no-pic support, add -mdynamic-no-pic just to later
> +# stages when we know it is built with gcc.
> +STAGE2_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
> +STAGE3_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
> +STAGE4_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
> 
> Thus, add -mdynamic-no-pic for gcc (or fixed clang) bootstrap compiler to
> BOOT_CFLAGS and STAGE1_CFLAGS, but only to STAGE{2,3,4}_CFLAGS otherwise?
> 
> Then GCC_PICFLAG, being a configure snippet, can surely just use normal
> autoconfy way.

well, GCC_PICFLAG is not really very autoconf-y at present, just a bunch of tests of triple.  Will try to find some cycles later on.
Comment 26 Jakub Jelinek 2015-04-08 09:40:05 UTC
(In reply to Iain Sandoe from comment #25)
> > +DARWIN_GCC_MDYNAMIC_NO_PIC := \
> > +`case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
> > +   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
> > +   || echo -mdynamic-no-pic ;; esac`
> 
> I don't think we need the test here ^ ?

I wanted to avoid adding -mdynamic-no-pic twice for the case when bootstrap compiler is gcc (once in BOOT_CFLAGS, once in STAGE{2,3,4}_CFLAGS.
Sure, the test could be 
DARWIN_GCC_MDYNAMIC_NO_PIC := \
`case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
   test -z "$(DARWIN_MDYNAMIC_NO_PIC)" && echo -mdynamic-no-pic ;; esac`
instead or similar.

> > Thus, add -mdynamic-no-pic for gcc (or fixed clang) bootstrap compiler to
> > BOOT_CFLAGS and STAGE1_CFLAGS, but only to STAGE{2,3,4}_CFLAGS otherwise?
> > 
> > Then GCC_PICFLAG, being a configure snippet, can surely just use normal
> > autoconfy way.
> 
> well, GCC_PICFLAG is not really very autoconf-y at present, just a bunch of
> tests of triple.  Will try to find some cycles later on.

What I meant is that it is processed by autoconf.
Anyway, perhaps an alternative would be to just add -mdynamic-no-pic if
-mdynamic-no-pic is in CFLAGS.
Like
  $1=-fno-common
  case "${CFLAGS}" in *-mdynamic-no-pic*) \
    $1='-fno-common -mno-dynamic no-pic';; esac
in config/picflag.m4 ?
Needs verification that -mdynamic-no-pic is really in CFLAGS when it should and not when it should not be.
Comment 27 Iain Sandoe 2015-04-08 11:15:56 UTC
Created attachment 35255 [details]
patch against 221916


Jakub's suggested approach to picflag.m4 seems reasonable.
AFAIK, the only place that GCC adds the flag is in mh-darwin which is now checked.

If someone building GCC passes "-mdynamic-no-pic" on the command line for (say) an i686-darwin12 native cross with clang as the compiler - then it will, presumably, fail but that's something easy for the person doing the build to rectify (and someone building native crosses is probably not a novice anyway)


checking on powerpc-darwin9 (GCC 5 bootstrap) x86_64-darwin12 (gcc 5 bootstrap) x86_64-darwin13 (clang XCode6 bootstrap) i686-darwin10 (gcc-4.2.1 bootstrap).
Comment 28 Dominique d'Humieres 2015-04-08 12:49:50 UTC
I have successfully  bootstrapped r221917 on x86_64-apple-darwin14 with the patch in comment 27.
Comment 29 Iain Sandoe 2015-04-08 22:59:17 UTC
(In reply to Iain Sandoe from comment #27)
> Created attachment 35255 [details]

> checking on powerpc-darwin9 (GCC 5 bootstrap) x86_64-darwin12 (gcc 5
> bootstrap) x86_64-darwin13 (clang XCode6 bootstrap) i686-darwin10 (gcc-4.2.1
> bootstrap).

these all completed ok and sanity-checks seem reasonable.
Comment 30 Jakub Jelinek 2015-04-09 07:16:00 UTC
(In reply to Iain Sandoe from comment #29)
> (In reply to Iain Sandoe from comment #27)
> > Created attachment 35255 [details]
> 
> > checking on powerpc-darwin9 (GCC 5 bootstrap) x86_64-darwin12 (gcc 5
> > bootstrap) x86_64-darwin13 (clang XCode6 bootstrap) i686-darwin10 (gcc-4.2.1
> > bootstrap).
> 
> these all completed ok and sanity-checks seem reasonable.

Thanks for testing it.  Will you post the patch, or shall I?
Comment 31 Iain Sandoe 2015-04-09 11:32:53 UTC
(In reply to Jakub Jelinek from comment #30)
> (In reply to Iain Sandoe from comment #29)
> > (In reply to Iain Sandoe from comment #27)
> > > Created attachment 35255 [details]
> > 
> > > checking on powerpc-darwin9 (GCC 5 bootstrap) x86_64-darwin12 (gcc 5
> > > bootstrap) x86_64-darwin13 (clang XCode6 bootstrap) i686-darwin10 (gcc-4.2.1
> > > bootstrap).
> > 
> > these all completed ok and sanity-checks seem reasonable.
> 
> Thanks for testing it.  Will you post the patch, or shall I?

Posted:
https://gcc.gnu.org/ml/gcc-patches/2015-04/msg00382.html

FWIW: I also posted a fix for the clang driver:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150406/127137.html
Comment 32 Iain Sandoe 2015-04-10 06:44:24 UTC
Author: iains
Date: Fri Apr 10 06:43:52 2015
New Revision: 221967

URL: https://gcc.gnu.org/viewcvs?rev=221967&root=gcc&view=rev
Log:
	PR target/65351
config/
	* mh-darwin: Only apply -mdynamic-no-pic for m32 Darwin when the compiler in
	use supports -mno-dynamic-no-pic.
	* picflag.m4: Only append -mno-dynamic-no-pic for Darwin when -mdynamic-no-pic
	is present in CFLAGS.

libiberty/
	* configure: Regenerate.
libada/
	* configure: Regenerate.
libgcc/
	* configure: Regenerate.
gcc/
	* configure: Regenerate.


Modified:
    trunk/config/ChangeLog
    trunk/config/mh-darwin
    trunk/config/picflag.m4
    trunk/gcc/ChangeLog
    trunk/gcc/configure
    trunk/libada/ChangeLog
    trunk/libada/configure
    trunk/libgcc/ChangeLog
    trunk/libgcc/configure
    trunk/libiberty/ChangeLog
    trunk/libiberty/configure
Comment 33 Jakub Jelinek 2015-04-10 06:54:52 UTC
Hopefully fixed now.