public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <maskray@google.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org, Alan Modra <amodra@gmail.com>,
	Nemanja Ivanovic <nemanjai@ca.ibm.com>,
	Bill Schmidt <wschmidt@linux.ibm.com>,
	Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Subject: Re: [PATCH] powerpc: Define USE_PPC64_NOTOC iff compiler and linker also supports it
Date: Mon, 8 Nov 2021 14:48:08 -0800	[thread overview]
Message-ID: <20211108224808.iqpddl4vgnx2gwol@google.com> (raw)
In-Reply-To: <20211108113316.8867-1-adhemerval.zanella@linaro.org>

On 2021-11-08, Adhemerval Zanella wrote:
>The @ntoc usage only yields any advantage on ISA 3.1+ machine (power10)
>and for ld.bfd also when it see pcrel relocations used on the code
>(generated if compiler targets ISA 3.1+).  On bfd case ISA 3.1+
>instruction on stubs are used iff linker also sees the new pc-relative
>relocations (for instance R_PPC64_D34), otherwise it generates default
>stubs (ppc64_elf_check_relocs:4700).
>
>This patch also help on linkers that do not implement this optimization,
>since building for older ISA (such as 3.0 / power9) will also trigger
>power10 stubs generation in the assembly code uses the NOTOC imacro.
>
>Checked on powerpc64le-linux-gnu.
>---
> sysdeps/powerpc/powerpc64/configure    | 42 ++++++++++++++++----------
> sysdeps/powerpc/powerpc64/configure.ac | 25 ++++++++++-----
> 2 files changed, 43 insertions(+), 24 deletions(-)
>
>diff --git a/sysdeps/powerpc/powerpc64/configure b/sysdeps/powerpc/powerpc64/configure
>index 5ce77af631..db18791a55 100644
>--- a/sysdeps/powerpc/powerpc64/configure
>+++ b/sysdeps/powerpc/powerpc64/configure
>@@ -32,26 +32,36 @@ if test x$libc_cv_overlapping_opd = xyes; then
>
> fi
>
>-# @notoc started to be supported in GNU Binutils 2.31.
>-
>-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the assembler supports @notoc" >&5
>-$as_echo_n "checking if the assembler supports @notoc... " >&6; }
>+# We check if compiler supports @notoc generation since there is no
>+# gain by enabling it if it will be optimized away by the linker.
>+# It also helps linkers that might not optimize it and end up
>+# generating stubs with ISA 3.1 instruction even targetting older ISA.
>+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the compiler supports @notoc" >&5
>+$as_echo_n "checking if the compiler supports @notoc... " >&6; }
> if ${libc_cv_ppc64_notoc+:} false; then :
>   $as_echo_n "(cached) " >&6
> else
>-
>-	       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>-/* end confdefs.h.  */
>-
>-void foo (void) {asm("b foo@notoc");}
>-
>-_ACEOF
>-if ac_fn_c_try_compile "$LINENO"; then :
>-  libc_cv_ppc64_notoc=yes
>-else
>+    cat > conftest.c <<EOF
>+int bar (void);
>+int foo (void) { return bar () + 1; }
>+EOF
>   libc_cv_ppc64_notoc=no
>-fi
>-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
>+  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -S -o conftest.s conftest.c'
>+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>+  (eval $ac_try) 2>&5
>+  ac_status=$?
>+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>+  test $ac_status = 0; }; } \
>+     && { ac_try='grep -q -E 'bar@notoc' conftest.s'
>+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>+  (eval $ac_try) 2>&5
>+  ac_status=$?
>+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>+  test $ac_status = 0; }; }
>+  then
>+    libc_cv_ppc64_notoc=yes
>+  fi
>+  rm -rf conftest.*
> fi
> { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ppc64_notoc" >&5
> $as_echo "$libc_cv_ppc64_notoc" >&6; }
>diff --git a/sysdeps/powerpc/powerpc64/configure.ac b/sysdeps/powerpc/powerpc64/configure.ac
>index b77156f696..05f0000807 100644
>--- a/sysdeps/powerpc/powerpc64/configure.ac
>+++ b/sysdeps/powerpc/powerpc64/configure.ac
>@@ -22,13 +22,22 @@ if test x$libc_cv_overlapping_opd = xyes; then
>   AC_DEFINE(USE_PPC64_OVERLAPPING_OPD)
> fi
>
>-# @notoc started to be supported in GNU Binutils 2.31.
>-AC_CACHE_CHECK([if the assembler supports @notoc],
>-	       libc_cv_ppc64_notoc, [
>-	       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
>-void foo (void) {asm("b foo@notoc");}
>-		  ])],
>-		  [libc_cv_ppc64_notoc=yes],
>-		  [libc_cv_ppc64_notoc=no])])
>+# We check if compiler supports @notoc generation since there is no
>+# gain by enabling it if it will be optimized away by the linker.
>+# It also helps linkers that might not optimize it and end up
>+# generating stubs with ISA 3.1 instruction even targetting older ISA.
>+AC_CACHE_CHECK([if the compiler supports @notoc],
>+	       libc_cv_ppc64_notoc, [dnl
>+  cat > conftest.c <<EOF
>+int bar (void);
>+int foo (void) { return bar () + 1; }
>+EOF
>+  libc_cv_ppc64_notoc=no
>+  if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -S -o conftest.s conftest.c]) \
>+     && AC_TRY_COMMAND([grep -q -E 'bar@notoc' conftest.s])
>+  then
>+    libc_cv_ppc64_notoc=yes
>+  fi
>+  rm -rf conftest.*])
> AS_IF([test x$libc_cv_ppc64_notoc = xyes],
>       [AC_DEFINE(USE_PPC64_NOTOC)])
>-- 
>2.32.0
>

I think the original fix to https://sourceware.org/bugzilla/show_bug.cgi?id=26173
complicated things. A simpler fix is to just check whether CC CFLAGS
generates @notoc and use that to guide whether assembly code needs @notoc.

That will fix ld.lld 13.0.0 build which doesn't have the heuristic GNU
ld currently has.

AIUI If the jump target (e.g. __syscall_error) is non-preemptible and
doesn't use PC-relative, we will not hit `lacks nop, can't restore toc`.

  reply	other threads:[~2021-11-08 22:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 11:33 Adhemerval Zanella
2021-11-08 22:48 ` Fangrui Song [this message]
2021-11-09 11:05   ` Alan Modra
2021-11-16 19:42     ` Tulio Magno Quites Machado Filho
2021-11-16 20:20       ` Tulio Magno Quites Machado Filho
2021-11-16 20:48         ` Florian Weimer
2021-11-16 22:12           ` Fāng-ruì Sòng
2021-11-16 22:46           ` Bill Schmidt
2021-11-17  2:16       ` Alan Modra
2021-11-17  2:30         ` Alan Modra
2021-11-09 13:03   ` Adhemerval Zanella
2021-11-09 17:44     ` Fangrui Song
2021-11-09 18:44       ` Adhemerval Zanella
2021-11-19 15:52 ` Tulio Magno Quites Machado Filho
2021-11-22 17:54   ` Adhemerval Zanella
2021-11-25 17:02     ` Tulio Magno Quites Machado Filho
2021-11-25 17:16       ` Adhemerval Zanella

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=20211108224808.iqpddl4vgnx2gwol@google.com \
    --to=maskray@google.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=amodra@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nemanjai@ca.ibm.com \
    --cc=tuliom@linux.ibm.com \
    --cc=wschmidt@linux.ibm.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).