summaryrefslogtreecommitdiff
path: root/0033-AutoBOLT-Enable-BOLT-linker-plugin-on-aarch64-3-3.patch
blob: e850a4dfbd2ffdccf0ae0b1469b5287d6ae6719f (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
From 94242286383a80e6ab83d824a4d7ea23ea311f75 Mon Sep 17 00:00:00 2001
From: zhenyu--zhao_admin <zhaozhenyu17@huawei.com>
Date: Mon, 22 Jan 2024 15:38:24 +0800
Subject: [PATCH] [AutoBOLT] Enable BOLT linker plugin on aarch64 3/3

---
 Makefile.def     | 10 ++++++++++
 configure        | 27 ++++++++++++++++++++++++++-
 configure.ac     | 22 +++++++++++++++++++++-
 gcc/config.host  |  1 +
 gcc/config.in    | 13 +++++++++++++
 gcc/configure    | 10 ++++++++--
 gcc/configure.ac |  4 ++++
 gcc/gcc.cc       | 23 +++++++++++++++++++++++
 8 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/Makefile.def b/Makefile.def
index 72d585496..0ba868890 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -145,6 +145,9 @@ host_modules= { module= gnattools; };
 host_modules= { module= lto-plugin; bootstrap=true;
 		extra_configure_flags='--enable-shared @extra_linker_plugin_flags@ @extra_linker_plugin_configure_flags@';
 		extra_make_flags='@extra_linker_plugin_flags@'; };
+host_modules= { module= bolt-plugin; bootstrap=true;
+		extra_configure_flags='--enable-shared @extra_linker_plugin_flags@ @extra_linker_plugin_configure_flags@';
+		extra_make_flags='@extra_linker_plugin_flags@'; };
 host_modules= { module= libcc1; extra_configure_flags=--enable-shared; };
 host_modules= { module= gotools; };
 host_modules= { module= libctf; bootstrap=true; };
@@ -349,6 +352,7 @@ dependencies = { module=configure-gcc; on=all-mpfr; };
 dependencies = { module=configure-gcc; on=all-mpc; };
 dependencies = { module=configure-gcc; on=all-isl; };
 dependencies = { module=configure-gcc; on=all-lto-plugin; };
+dependencies = { module=configure-gcc; on=all-bolt-plugin; };
 dependencies = { module=configure-gcc; on=all-binutils; };
 dependencies = { module=configure-gcc; on=all-gas; };
 dependencies = { module=configure-gcc; on=all-ld; };
@@ -374,6 +378,7 @@ dependencies = { module=all-gcc; on=all-libdecnumber; hard=true; };
 dependencies = { module=all-gcc; on=all-libiberty; };
 dependencies = { module=all-gcc; on=all-fixincludes; };
 dependencies = { module=all-gcc; on=all-lto-plugin; };
+dependencies = { module=all-gcc; on=all-bolt-plugin; };
 dependencies = { module=all-gcc; on=all-libiconv; };
 dependencies = { module=info-gcc; on=all-build-libiberty; };
 dependencies = { module=dvi-gcc; on=all-build-libiberty; };
@@ -381,8 +386,10 @@ dependencies = { module=pdf-gcc; on=all-build-libiberty; };
 dependencies = { module=html-gcc; on=all-build-libiberty; };
 dependencies = { module=install-gcc ; on=install-fixincludes; };
 dependencies = { module=install-gcc ; on=install-lto-plugin; };
+dependencies = { module=install-gcc ; on=install-bolt-plugin; };
 dependencies = { module=install-strip-gcc ; on=install-strip-fixincludes; };
 dependencies = { module=install-strip-gcc ; on=install-strip-lto-plugin; };
+dependencies = { module=install-strip-gcc ; on=install-strip-bolt-plugin; };
 
 dependencies = { module=configure-libcpp; on=configure-libiberty; hard=true; };
 dependencies = { module=configure-libcpp; on=configure-intl; };
@@ -401,6 +408,9 @@ dependencies = { module=all-gnattools; on=all-target-libstdc++-v3; };
 dependencies = { module=all-lto-plugin; on=all-libiberty; };
 dependencies = { module=all-lto-plugin; on=all-libiberty-linker-plugin; };
 
+dependencies = { module=all-bolt-plugin; on=all-libiberty; };
+dependencies = { module=all-bolt-plugin; on=all-libiberty-linker-plugin; };
+
 dependencies = { module=configure-libcc1; on=configure-gcc; };
 dependencies = { module=all-libcc1; on=all-gcc; };
 
diff --git a/configure b/configure
index 5dcaab14a..aff62c464 100755
--- a/configure
+++ b/configure
@@ -826,6 +826,7 @@ with_isl
 with_isl_include
 with_isl_lib
 enable_isl_version_check
+enable_bolt
 enable_lto
 enable_linker_plugin_configure_flags
 enable_linker_plugin_flags
@@ -1550,6 +1551,7 @@ Optional Features:
                           enable the PGO build
   --disable-isl-version-check
                           disable check for isl version
+  --enable-bolt           enable bolt optimization support
   --enable-lto            enable link time optimization support
   --enable-linker-plugin-configure-flags=FLAGS
                           additional flags for configuring linker plugins
@@ -8564,6 +8566,15 @@ fi
 
 
 
+# Check for BOLT support.
+# Check whether --enable-bolt was given.
+if test "${enable_bolt+set}" = set; then :
+  enableval=$enable_bolt; enable_bolt=$enableval
+else
+  enable_bolt=no; default_enable_bolt=no
+fi
+
+
 # Check for LTO support.
 # Check whether --enable-lto was given.
 if test "${enable_lto+set}" = set; then :
@@ -8593,6 +8604,16 @@ if test $target_elf = yes; then :
   # ELF platforms build the lto-plugin always.
   build_lto_plugin=yes
 
+  # ELF platforms can build the bolt-plugin.
+  # NOT BUILD BOLT BY DEFAULT.
+  case $target in
+    aarch64*-*-linux*)
+    if test $enable_bolt = yes; then :
+      build_bolt_plugin=yes
+    fi
+    ;;
+  esac
+
 else
   if test x"$default_enable_lto" = x"yes" ; then
     case $target in
@@ -8780,6 +8801,10 @@ if test -d ${srcdir}/gcc; then
     fi
   fi
 
+  if test "${build_bolt_plugin}" = "yes" ; then
+      configdirs="$configdirs bolt-plugin"
+  fi
+
   # If we're building an offloading compiler, add the LTO front end.
   if test x"$enable_as_accelerator_for" != x ; then
     case ,${enable_languages}, in
@@ -9202,7 +9227,7 @@ fi
 extra_host_libiberty_configure_flags=
 extra_host_zlib_configure_flags=
 case " $configdirs " in
-  *" lto-plugin "* | *" libcc1 "*)
+  *" lto-plugin "* | *" libcc1 "* | *" bolt-plugin "*)
     # When these are to be built as shared libraries, the same applies to
     # libiberty.
     extra_host_libiberty_configure_flags=--enable-shared
diff --git a/configure.ac b/configure.ac
index 85977482a..f310d75ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1863,6 +1863,12 @@ fi
 AC_SUBST(isllibs)
 AC_SUBST(islinc)
 
+# Check for BOLT support.
+AC_ARG_ENABLE(bolt,
+[AS_HELP_STRING([--enable-bolt], [enable bolt optimization support])],
+enable_bolt=$enableval,
+enable_bolt=no; default_enable_bolt=no)
+
 # Check for LTO support.
 AC_ARG_ENABLE(lto,
 [AS_HELP_STRING([--enable-lto], [enable link time optimization support])],
@@ -1871,6 +1877,16 @@ enable_lto=yes; default_enable_lto=yes)
 
 ACX_ELF_TARGET_IFELSE([# ELF platforms build the lto-plugin always.
   build_lto_plugin=yes
+
+  # ELF platforms can build the bolt-plugin.
+  # NOT BUILD BOLT BY DEFAULT.
+  case $target in
+    aarch64*-*-linux*)
+    if test $enable_bolt = yes; then :
+      build_bolt_plugin=yes
+    fi
+    ;;
+  esac
 ],[if test x"$default_enable_lto" = x"yes" ; then
     case $target in
       *-apple-darwin[[912]]* | *-cygwin* | *-mingw* | *djgpp*) ;;
@@ -2049,6 +2065,10 @@ if test -d ${srcdir}/gcc; then
     fi
   fi
 
+  if test "${build_bolt_plugin}" = "yes" ; then
+      configdirs="$configdirs bolt-plugin"
+  fi
+
   # If we're building an offloading compiler, add the LTO front end.
   if test x"$enable_as_accelerator_for" != x ; then
     case ,${enable_languages}, in
@@ -2457,7 +2477,7 @@ fi
 extra_host_libiberty_configure_flags=
 extra_host_zlib_configure_flags=
 case " $configdirs " in
-  *" lto-plugin "* | *" libcc1 "*)
+  *" lto-plugin "* | *" libcc1 "* | *" bolt-plugin "*)    
     # When these are to be built as shared libraries, the same applies to
     # libiberty.
     extra_host_libiberty_configure_flags=--enable-shared
diff --git a/gcc/config.host b/gcc/config.host
index 4ca300f11..bf7dcb4cc 100644
--- a/gcc/config.host
+++ b/gcc/config.host
@@ -75,6 +75,7 @@ out_host_hook_obj=host-default.o
 host_can_use_collect2=yes
 use_long_long_for_widest_fast_int=no
 host_lto_plugin_soname=liblto_plugin.so
+host_bolt_plugin_soname=libbolt_plugin.so
 
 # Unsupported hosts list.  Generally, only include hosts known to fail here,
 # since we allow hosts not listed to be supported generically.
diff --git a/gcc/config.in b/gcc/config.in
index 64c27c9cf..6bb25b25b 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -24,6 +24,13 @@
 #endif
 
 
+/* Define to the name of the BOLT plugin DSO that must be passed to the
+   linker's -plugin=LIB option. */
+#ifndef USED_FOR_TARGET
+#undef BOLTPLUGINSONAME
+#endif
+
+
 /* Define to the root for URLs about GCC changes. */
 #ifndef USED_FOR_TARGET
 #undef CHANGES_ROOT_URL
@@ -2208,6 +2215,12 @@
 #endif
 
 
+/* Define which stat syscall is able to handle 64bit indodes. */
+#ifndef USED_FOR_TARGET
+#undef HOST_STAT_FOR_64BIT_INODES
+#endif
+
+
 /* Define as const if the declaration of iconv() needs const. */
 #ifndef USED_FOR_TARGET
 #undef ICONV_CONST
diff --git a/gcc/configure b/gcc/configure
index 98bbf0f85..30f386789 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -13578,6 +13578,12 @@ case $use_collect2 in
 esac
 
 
+cat >>confdefs.h <<_ACEOF
+#define BOLTPLUGINSONAME "${host_bolt_plugin_soname}"
+_ACEOF
+
+
+
 cat >>confdefs.h <<_ACEOF
 #define LTOPLUGINSONAME "${host_lto_plugin_soname}"
 _ACEOF
@@ -19668,7 +19674,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19671 "configure"
+#line 19677 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19774,7 +19780,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19777 "configure"
+#line 19783 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index c74f4b555..dd6cd60f8 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2531,6 +2531,10 @@ case $use_collect2 in
     ;;
 esac
 
+AC_DEFINE_UNQUOTED(BOLTPLUGINSONAME,"${host_bolt_plugin_soname}",
+[Define to the name of the BOLT plugin DSO that must be
+  passed to the linker's -plugin=LIB option.])
+
 AC_DEFINE_UNQUOTED(LTOPLUGINSONAME,"${host_lto_plugin_soname}",
 [Define to the name of the LTO plugin DSO that must be
   passed to the linker's -plugin=LIB option.])
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index fbcc9d033..b0d03430e 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -1156,6 +1156,8 @@ proper position among the other output files.  */
 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
     %(linker) " \
     LINK_PLUGIN_SPEC \
+   "%{fauto-bolt|fauto-bolt=*|fbolt-use|fbolt-use=*: \
+    -plugin %(linker_auto_bolt_plugin_file) }"\
    "%{flto|flto=*:%<fcompare-debug*} \
     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
    "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
@@ -1210,6 +1212,7 @@ static const char *endfile_spec = ENDFILE_SPEC;
 static const char *startfile_spec = STARTFILE_SPEC;
 static const char *linker_name_spec = LINKER_NAME;
 static const char *linker_plugin_file_spec = "";
+static const char *linker_auto_bolt_plugin_file_spec = "";
 static const char *lto_wrapper_spec = "";
 static const char *lto_gcc_spec = "";
 static const char *post_link_spec = POST_LINK_SPEC;
@@ -1723,6 +1726,8 @@ static struct spec_list static_specs[] =
   INIT_STATIC_SPEC ("multilib_reuse",		&multilib_reuse),
   INIT_STATIC_SPEC ("linker",			&linker_name_spec),
   INIT_STATIC_SPEC ("linker_plugin_file",	&linker_plugin_file_spec),
+  INIT_STATIC_SPEC ("linker_auto_bolt_plugin_file",
+    &linker_auto_bolt_plugin_file_spec),
   INIT_STATIC_SPEC ("lto_wrapper",		&lto_wrapper_spec),
   INIT_STATIC_SPEC ("lto_gcc",			&lto_gcc_spec),
   INIT_STATIC_SPEC ("post_link",		&post_link_spec),
@@ -9118,6 +9123,24 @@ driver::maybe_run_linker (const char *argv0) const
 	    }
 #endif
 	  set_static_spec_shared (&lto_gcc_spec, argv0);
+
+	  /* Set bolt-plugin.  */
+	  const char *fauto_bolt = "fauto-bolt";
+	  const char *fbolt_use = "fbolt-use";
+	  if (switch_matches (fauto_bolt, fauto_bolt + strlen (fauto_bolt), 1)
+	    || switch_matches (fbolt_use, fbolt_use + strlen (fbolt_use), 1))
+	    {
+	      linker_auto_bolt_plugin_file_spec = find_a_file (&exec_prefixes,
+		BOLTPLUGINSONAME, X_OK, false);
+	      if (!linker_auto_bolt_plugin_file_spec)
+		{
+		  fatal_error (input_location,
+			       "-fauto-bolt or -fbolt-use is used, but %s is not found",
+			       BOLTPLUGINSONAME);
+
+		}
+	    }
+
 	}
 
       /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
-- 
2.33.0