From: Fangrui Song <i@maskray.me>
To: Andrew Pinski <pinskia@gmail.com>
Cc: Fangrui Song <maskray@google.com>,
GCC Patches <gcc-patches@gcc.gnu.org>,
Jan Hubicka <hubicka@ucw.cz>
Subject: Re: [PATCH] Add --enable-default-semantic-interposition to GCC configure
Date: Sun, 6 Jun 2021 16:36:07 -0700 [thread overview]
Message-ID: <20210606233607.2kx47jmqv4vumai7@gmail.com> (raw)
In-Reply-To: <CA+=Sn1=iKC06d2dx_4md+O1AJDT5FN2E3mHN=2n3gSHgUzEHZg@mail.gmail.com>
On 2021-06-06, Andrew Pinski wrote:
>On Sun, Jun 6, 2021 at 4:13 PM Fangrui Song via Gcc-patches
><gcc-patches@gcc.gnu.org> wrote:
>>
>> From: Fangrui Song <i@maskray.me>
>>
>> --enable-default-semantic-interposition=no makes -fPIC default to
>> -fno-semantic-interposition which enables interprocedural optimizations
>> for default visibility non-vague-linkage function definitions.
>>
>> The suppression of interprocedural optimizations and inlining for such
>> functions is the biggest difference between -fPIE/-fPIC.
>> Distributions may want to enable default -fno-semantic-interposition to
>> reclaim the lost performance (e.g. CPython is said to be 27% faster;
>> Clang is 3% faster).
>
>
>This breaks assumptions across the board. If software packages want
>to use -fno-semantic-interposition that is one thing. But distros
>should not be changing the default. This is just like using
>-ffast-math :).
>
>Thanks,
>Andrew Pinski
What assumption?
Vague linkage function definitions already support IPO/inlining.
For a large non-vague linkage function, presumably GCC will not inline
it into the call sites in the same TU, users can keep using LD_PRELOAD
to interpose that single symbol.
Even if the non-vague function is small and inlined, users can use LD_PRELOAD to
interpose both the callee and callers.
You cannot do such interposition for Windows.
macOS two-level namespace requires explicit `ld -flat_interpose` for such definition interposition.
Users are free to add noinline or -fsemantic-interposition.
>> gcc/
>>
>> PR 100937
>> * common.opt (fsemantic-interposition): Initialize to -1.
>> * configure.ac: Add --enable-default-semantic-interposition. Default
>> to yes.
>> * defaults.h (DEFAULT_FLAG_SEMANTIC_INTERPOSITION): New.
>> * opts.c (finish_options): Update
>> opts->x_flag_semantic_interposition if it is -1.
>> * doc/install.texi: Document --enable-default-semantic-interposition.
>> * config.in: Add template.
>> * configure: Regenerate.
>> ---
>> gcc/common.opt | 2 +-
>> gcc/config.in | 6 ++++++
>> gcc/configure | 22 ++++++++++++++++++++--
>> gcc/configure.ac | 12 ++++++++++++
>> gcc/defaults.h | 6 ++++++
>> gcc/doc/install.texi | 3 +++
>> gcc/opts.c | 3 +++
>> 7 files changed, 51 insertions(+), 3 deletions(-)
>>
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index ffb968d90f8..68fcbac96b1 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -2480,7 +2480,7 @@ Common Var(flag_sel_sched_reschedule_pipelined) Init(0) Optimization
>> Reschedule pipelined regions without pipelining.
>>
>> fsemantic-interposition
>> -Common Var(flag_semantic_interposition) Init(1)
>> +Common Var(flag_semantic_interposition) Init(-1)
>> Allow interposing function (or variables) by ones with different semantics (or initializer) respectively by dynamic linker.
>>
>> ; sched_stalled_insns means that insns can be moved prematurely from the queue
>> diff --git a/gcc/config.in b/gcc/config.in
>> index e54f59ce0c3..7f1d56c1903 100644
>> --- a/gcc/config.in
>> +++ b/gcc/config.in
>> @@ -125,6 +125,12 @@
>> #endif
>>
>>
>> +/* Define if -fPIC defaults to -fsemantic-interposition */
>> +#ifndef USED_FOR_TARGET
>> +#undef ENABLE_DEFAULT_SEMANTIC_INTERPOSITION
>> +#endif
>> +
>> +
>> /* Define if your target supports default stack protector and it is enabled.
>> */
>> #ifndef USED_FOR_TARGET
>> diff --git a/gcc/configure b/gcc/configure
>> index 4a9e4fa08ab..3835b22f6a5 100755
>> --- a/gcc/configure
>> +++ b/gcc/configure
>> @@ -632,6 +632,7 @@ ac_includes_default="\
>> ac_subst_vars='LTLIBOBJS
>> LIBOBJS
>> CET_HOST_FLAGS
>> +enable_default_semantic_interposition
>> NO_PIE_FLAG
>> NO_PIE_CFLAGS
>> enable_default_pie
>> @@ -1027,6 +1028,7 @@ with_linker_hash_style
>> with_diagnostics_color
>> with_diagnostics_urls
>> enable_default_pie
>> +enable_default_semantic_interposition
>> enable_cet
>> enable_s390_excess_float_precision
>> '
>> @@ -1787,6 +1789,8 @@ Optional Features:
>> --disable-libquadmath-support
>> disable libquadmath support for Fortran
>> --enable-default-pie enable Position Independent Executable as default
>> + --enable-default-semantic-interposition
>> + enable -fsemantic-interposition as -fPIC default
>> --enable-cet enable Intel CET in host libraries [default=auto]
>> --enable-s390-excess-float-precision
>> on s390 targets, evaluate float with double
>> @@ -19435,7 +19439,7 @@ else
>> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>> lt_status=$lt_dlunknown
>> cat > conftest.$ac_ext <<_LT_EOF
>> -#line 19438 "configure"
>> +#line 19454 "configure"
>> #include "confdefs.h"
>>
>> #if HAVE_DLFCN_H
>> @@ -19541,7 +19545,7 @@ else
>> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>> lt_status=$lt_dlunknown
>> cat > conftest.$ac_ext <<_LT_EOF
>> -#line 19544 "configure"
>> +#line 19560 "configure"
>> #include "confdefs.h"
>>
>> #if HAVE_DLFCN_H
>> @@ -31893,6 +31897,20 @@ if test "$gcc_cv_no_pie" = "yes"; then
>> fi
>>
>>
>> +# Check whether --enable-default-semantic-interposition=no was given.
>> +if test "${enable_default_semantic_interposition+set}" = set; then :
>> + enableval=$enable_default_semantic_interposition; enable_default_semantic_interposition=$enableval
>> +else
>> + enable_default_semantic_interposition=yes
>> +fi
>> +
>> +if test x$enable_default_semantic_interposition != xno ; then
>> +
>> +$as_echo "#define ENABLE_DEFAULT_SEMANTIC_INTERPOSITION 1" >>confdefs.h
>> +
>> +fi
>> +
>> +
>> # Enable Intel CET on Intel CET enabled host if jit is enabled.
>> # Check whether --enable-cet was given.
>> if test "${enable_cet+set}" = set; then :
>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>> index d9fc3c219e8..1cdf8b4ce00 100644
>> --- a/gcc/configure.ac
>> +++ b/gcc/configure.ac
>> @@ -7419,6 +7419,18 @@ if test "$gcc_cv_no_pie" = "yes"; then
>> fi
>> AC_SUBST([NO_PIE_FLAG])
>>
>> +# Check whether --enable-default-semantic-interposition=no was given.
>> +AC_ARG_ENABLE(default-semantic-interposition,
>> +[AS_HELP_STRING([--enable-default-semantic-interposition],
>> + [enable -fsemantic-interposition as -fPIC default])],
>> +enable_default_semantic_interposition=$enableval,
>> +enable_default_semantic_interposition=yes)
>> +if test x$enable_default_semantic_interposition != xno ; then
>> + AC_DEFINE(ENABLE_DEFAULT_SEMANTIC_INTERPOSITION, 1,
>> + [Define if -fPIC defaults to -fsemantic-interposition.])
>> +fi
>> +AC_SUBST([enable_default_semantic_interposition])
>> +
>> # Enable Intel CET on Intel CET enabled host if jit is enabled.
>> GCC_CET_HOST_FLAGS(CET_HOST_FLAGS)
>> case x$enable_languages in
>> diff --git a/gcc/defaults.h b/gcc/defaults.h
>> index 91216593e75..548b1f64f17 100644
>> --- a/gcc/defaults.h
>> +++ b/gcc/defaults.h
>> @@ -1249,6 +1249,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
>> # define DEFAULT_FLAG_PIE 0
>> #endif
>>
>> +#ifdef ENABLE_DEFAULT_SEMANTIC_INTERPOSITION
>> +# define DEFAULT_FLAG_SEMANTIC_INTERPOSITION 1
>> +#else
>> +# define DEFAULT_FLAG_SEMANTIC_INTERPOSITION 0
>> +#endif
>> +
>> #ifndef SWITCHABLE_TARGET
>> #define SWITCHABLE_TARGET 0
>> #endif
>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>> index 591ccaacbc1..17e756c7e7a 100644
>> --- a/gcc/doc/install.texi
>> +++ b/gcc/doc/install.texi
>> @@ -1867,6 +1867,9 @@ mips-linux and s390-linux.
>> @item --enable-default-pie
>> Turn on @option{-fPIE} and @option{-pie} by default.
>>
>> +@item --enable-default-semantic-interposition=no
>> +Make @option{-fPIC} default to @option{-fno-semantic-interposition}.
>> +
>> @item --enable-secureplt
>> This option enables @option{-msecure-plt} by default for powerpc-linux.
>> @ifnothtml
>> diff --git a/gcc/opts.c b/gcc/opts.c
>> index a751d95d32b..c6f49af2583 100644
>> --- a/gcc/opts.c
>> +++ b/gcc/opts.c
>> @@ -1068,6 +1068,9 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
>> if (opts->x_flag_stack_protect == -1)
>> opts->x_flag_stack_protect = DEFAULT_FLAG_SSP;
>>
>> + if (opts->x_flag_semantic_interposition == -1)
>> + opts->x_flag_semantic_interposition = DEFAULT_FLAG_SEMANTIC_INTERPOSITION;
>> +
>> if (opts->x_optimize == 0)
>> {
>> /* Inlining does not work if not optimizing,
>> --
>> 2.32.0.rc1.229.g3e70b5a671-goog
>>
next prev parent reply other threads:[~2021-06-06 23:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-06 23:12 Fangrui Song
2021-06-06 23:18 ` Andrew Pinski
2021-06-06 23:36 ` Fangrui Song [this message]
2021-06-07 18:01 ` Jeff Law
2021-06-07 18:13 ` Jakub Jelinek
2021-06-07 19:01 ` Fangrui Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210606233607.2kx47jmqv4vumai7@gmail.com \
--to=i@maskray.me \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=maskray@google.com \
--cc=pinskia@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).