From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 8D6463858D39 for ; Tue, 9 Nov 2021 13:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D6463858D39 Received: by mail-ot1-x329.google.com with SMTP id q33-20020a056830442100b0055abeab1e9aso30738443otv.7 for ; Tue, 09 Nov 2021 05:03:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=nnTfluyVB8B4dIVj9UBPKOxAAVOv8M2FHruMKp86gh0=; b=tPjKslrw2XzaSIS6kKjK1sdrjSodfuj59zG2gj+c7SL9FnI4P06wsPBv1/4btGiCLW 67BKj+WEd0/aHmgNwfBli8U2a0sh3lxwvm2RBGnaJ/aUR3DRA0/lHbKOJCcXaBUS9Izg rupCfLU1O8R0lMRsy11vbCjp/9Waf1QVmvMi5i5kQ698rw7waHwv7VQvkOoPRO0OwIl2 4QTxxqujdGBmLmckhCI79Y67VFvZ5rKvaF9goiLMmSUEwzpq9o+MqRCXbEOZKOKgLr+4 VadFrcH2eqUvVD+oxMmeG+0DgV15wCN1pXdv9V9+oC1cOwDfcOPcNDtSbeJd3Q25hciI HfsA== X-Gm-Message-State: AOAM531uQk1bXEF/h6N5pY8rg3vAbr1OOOKc5JQ2TEGjfB9fIyrLJz96 An12SIny0rb+hqZZ4r23v7PE1Q== X-Google-Smtp-Source: ABdhPJxw+JYGVg+eHbIvBZsYEJbAT5RV4sPmOZG/Rb+mq2qNhaY3+jnz4xyhg2gIyysEyrYCacE3Vw== X-Received: by 2002:a9d:6b8e:: with SMTP id b14mr5739799otq.174.1636463008826; Tue, 09 Nov 2021 05:03:28 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:55a:94d0:2630:9b29:e621? ([2804:431:c7cb:55a:94d0:2630:9b29:e621]) by smtp.gmail.com with ESMTPSA id j187sm2136713oih.5.2021.11.09.05.03.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Nov 2021 05:03:28 -0800 (PST) Message-ID: <1d510215-15de-4723-31d8-779d8e4e7f67@linaro.org> Date: Tue, 9 Nov 2021 10:03:25 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH] powerpc: Define USE_PPC64_NOTOC iff compiler and linker also supports it Content-Language: en-US To: Fangrui Song Cc: libc-alpha@sourceware.org, Alan Modra , Nemanja Ivanovic , Bill Schmidt , Tulio Magno Quites Machado Filho References: <20211108113316.8867-1-adhemerval.zanella@linaro.org> <20211108224808.iqpddl4vgnx2gwol@google.com> From: Adhemerval Zanella In-Reply-To: <20211108224808.iqpddl4vgnx2gwol@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: Tue, 09 Nov 2021 13:03:33 -0000 On 08/11/2021 19:48, Fangrui Song wrote: > 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. This is exactly what this patch does in fact: it check if $CC $CFLAGS generates @notoc and defines USE_PPC64_NOTOC which is used internally on NOTOC macro. The title is misleading in fact, is should be "powerpc: Define USE_PPC64_NOTOC iff compiler supports it"