From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 9D8F53858425 for ; Mon, 8 Nov 2021 22:48:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D8F53858425 Received: by mail-pf1-x429.google.com with SMTP id x64so17484955pfd.6 for ; Mon, 08 Nov 2021 14:48:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fTyZqHqEkHo7c0u9VOhaCsE+TtU0vRCzZR9lFkPtqZw=; b=kPCNXhUcLVER0oFITOGc0bazhgSwOL7yRKSEBW9zYrXVxjfM9rxxS2Z1N4lEqlvSrr ZJ8J3xHWbw+Nz+3UXZzRAsJFL4vnhO7+1BYnrXuYc+ruy6q+zcabvVnzUznkAhxcUy4q DsaH+v8lljIhVT8IarENr5fOpc1oUKOiqL06ybT3J65zko4mH1OvjhI98de4/0YIdZ2i lVmgVlyemwZwHzejGQqda8Mdkk67/gR8wnq1ax82p+ARztSDz1mTmSdhB2C5NN211WHO WVGc2TBcQikGv1/I5xMgpxMDoQNnn75XoLeBNvZdV5fFYlFRBDr6NmcS6oA8snfQ1WUa FW4g== X-Gm-Message-State: AOAM532qiIrfx8iesJIa7gUvflEOZGm8/THtmc/toBLWHFhUtpwTBHmC dKOlBjNGnKN2LBOLnIbLJI62Bg== X-Google-Smtp-Source: ABdhPJxItntWE7yki6qrS4o5dfhLPYPX3mzGCF+HKjCSMMsJfJW1D3WHXoOA+0+vWmq41F1lWMLYRA== X-Received: by 2002:aa7:91c5:0:b0:49f:a400:9771 with SMTP id z5-20020aa791c5000000b0049fa4009771mr2520019pfa.79.1636411691573; Mon, 08 Nov 2021 14:48:11 -0800 (PST) Received: from google.com ([2620:15c:2ce:200:1205:53ca:e5c0:1a50]) by smtp.gmail.com with ESMTPSA id s21sm1868516pfk.3.2021.11.08.14.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 14:48:10 -0800 (PST) Date: Mon, 8 Nov 2021 14:48:08 -0800 From: Fangrui Song To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Alan Modra , Nemanja Ivanovic , Bill Schmidt , Tulio Magno Quites Machado Filho Subject: Re: [PATCH] powerpc: Define USE_PPC64_NOTOC iff compiler and linker also supports it Message-ID: <20211108224808.iqpddl4vgnx2gwol@google.com> References: <20211108113316.8867-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20211108113316.8867-1-adhemerval.zanella@linaro.org> X-Spam-Status: No, score=-26.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Nov 2021 22:48:16 -0000 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 <+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 <+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`.