summaryrefslogtreecommitdiff
blob: b79f421695c75c02a4302babedbff1e8cb313ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Noticed when looking through git logs for Darwin but wasn't
sure until I saw it in macports as well:
https://raw.githubusercontent.com/macports/macports-ports/master/lang/gcc10/files/patch-gcc10-i686-clang-bootstrap-fix.diff
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=54258e22b0846aaa6bd3265f592feb161eecda75

From 54258e22b0846aaa6bd3265f592feb161eecda75 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Sat, 3 Jul 2021 15:42:16 +0100
Subject: [PATCH] Darwin, config: Revise host config fragment.

There were two uses for the Darwin host config fragment:

The first is to arrange for targets that support mdynamic-no-pic
to be built with that enabled (since it makes a significant
difference to the compiler performance).  We can be more specific
in the application of this, since it only applies to 32b hosts
plus powerpc64-darwin9.

The second was to work around a tool bug where -fno-PIE was not
propagated to the link stage.  This second use is redundant,
since the buggy toolchain cannot bootstrap current GCC sources
anyway.

This makes the host fragment more specific and reduces the number
of toolchains for which it is included which reduces clutter in
configure lines.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

config/ChangeLog:

	* mh-darwin: Make this specific to handling the
	mdynamic-no-pic case.

ChangeLog:

	* configure: Regenerate.
	* configure.ac: Adjust cases for which it is necessary to
	include the Darwin host config fragment.
---
 config/mh-darwin | 57 ++++++++++++++++++++++++++++--------------------
 configure        |  2 +-
 configure.ac     |  2 +-
 3 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/config/mh-darwin b/config/mh-darwin
index 148b73038c3..fb2bb5ad1d9 100644
--- a/config/mh-darwin
+++ b/config/mh-darwin
@@ -1,29 +1,38 @@
 # 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%.  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*) \
-   $(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`
+# position-independent-code -- the usual default on Darwin. This speeds compiles
+# by 8-20% (measurements made against GCC-11).
+# However, we cannot add it unless the bootstrap compiler supports
+# -mno-dynamic-no-pic to undo it, since libiberty, at least, needs this.
 
-# ld on Darwin versions >= 10.7 defaults to PIE executables. Disable this for
-# gcc components, since it is incompatible with our pch implementation.
-DARWIN_NO_PIE := `case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+#Â We use Werror, since some versions of clang report unknown command line flags
+# as a warning only.
 
-BOOT_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
-BOOT_LDFLAGS += $(DARWIN_NO_PIE)
+# We only need to determine this for the host tool used to build stage1 (or a
+# non-bootstrapped compiler), later stages will be built by GCC which supports
+# the required flags.
 
-# Similarly, for cross-compilation.
-STAGE1_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
-STAGE1_LDFLAGS += $(DARWIN_NO_PIE)
+BOOTSTRAP_TOOL_CAN_USE_MDYNAMIC_NO_PIC := $(shell \
+  $(CC) -S -xc /dev/null -o /dev/null -Werror -mno-dynamic-no-pic 2>/dev/null \
+  && echo true)
 
-# 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)
+@if gcc-bootstrap
+ifeq (${BOOTSTRAP_TOOL_CAN_USE_MDYNAMIC_NO_PIC},true)
+STAGE1_CFLAGS += -mdynamic-no-pic
+else
+STAGE1_CFLAGS += -fPIC
+endif
+# Add -mdynamic-no-pic to later stages when we know it is built with GCC.
+BOOT_CFLAGS += -mdynamic-no-pic
+@endif gcc-bootstrap
+
+@unless gcc-bootstrap
+ifeq (${BOOTSTRAP_TOOL_CAN_USE_MDYNAMIC_NO_PIC},true)
+# FIXME: we should also enable this for cross and non-bootstrap builds but
+# that needs amendment to libcc1.
+# CFLAGS += -mdynamic-no-pic
+# CXXFLAGS += -mdynamic-no-pic
+else
+CFLAGS += -fPIC
+CXXFLAGS += -fPIC
+endif
+@endunless gcc-bootstrap
diff --git a/configure b/configure
index 732d1870b3d..85ab9915402 100755
--- a/configure
+++ b/configure
@@ -4074,7 +4074,7 @@ fi
   hppa*-*)
     host_makefile_frag="config/mh-pa"
     ;;
-  *-*-darwin*)
+  i?86-*-darwin[89]* | i?86-*-darwin1[0-7]* | powerpc*-*-darwin*)
     host_makefile_frag="config/mh-darwin"
     ;;
   powerpc-*-aix*)
diff --git a/configure.ac b/configure.ac
index 041ee249bac..1df038b04f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1318,7 +1318,7 @@ case "${host}" in
   hppa*-*)	
     host_makefile_frag="config/mh-pa"
     ;;
-  *-*-darwin*)
+  i?86-*-darwin[[89]]* | i?86-*-darwin1[[0-7]]* | powerpc*-*-darwin*)
     host_makefile_frag="config/mh-darwin"
     ;;
   powerpc-*-aix*)
-- 
2.27.0