From patchwork Sat Aug 26 16:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 74781 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EABE3385842E for ; Sat, 26 Aug 2023 16:38:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EABE3385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693067917; bh=Uy9YVAm0vZOrmdBj0Macak63jdU5hbLjLlYebbbskLo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vfYWAmMoc3dZpqdTz5UTejCHR1PhabU6NVIuH4wmbya1dKo+lmTuk1GNqHYl9kQrX JsIvPoWn/gpu8+yjPTXLA9JUpn45D+32qyG1bj+wDGoTot2LGoKcQ9S9F5q/tsM92n j6mRe5N+TbnxBIZWDiYXGiprXqg0lfha/G75coHU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 455F03858423 for ; Sat, 26 Aug 2023 16:38:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 455F03858423 Received: from stargazer.. (unknown [IPv6:240e:358:1189:1100:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 72E47659C7; Sat, 26 Aug 2023 12:37:09 -0400 (EDT) To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Netto , caiyinyu , WANG Xuerui , Xi Ruoyao Subject: [PATCH 1/3] LoongArch: Simplify the autoconf check for static PIE Date: Sun, 27 Aug 2023 00:36:49 +0800 Message-ID: <20230826163651.35828-2-xry111@xry111.site> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230826163651.35828-1-xry111@xry111.site> References: <20230826163651.35828-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" We are strictly requiring GAS >= 2.41 now, so we don't need to check assembler capability anymore. Signed-off-by: Xi Ruoyao --- sysdeps/loongarch/configure | 36 +++++++--------------------------- sysdeps/loongarch/configure.ac | 30 +++++++++------------------- 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/sysdeps/loongarch/configure b/sysdeps/loongarch/configure index 395ddc92ca..30b60d1983 100644 --- a/sysdeps/loongarch/configure +++ b/sysdeps/loongarch/configure @@ -4,21 +4,19 @@ printf "%s\n" "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the toolchain is sufficient to build static PIE on LoongArch" >&5 -printf %s "checking if the toolchain is sufficient to build static PIE on LoongArch... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ${CC-cc} is sufficient to build static PIE on LoongArch" >&5 +printf %s "checking if ${CC-cc} is sufficient to build static PIE on LoongArch... " >&6; } if test ${libc_cv_static_pie_on_loongarch+y} then : printf %s "(cached) " >&6 else $as_nop - cat > conftest1.S <<\EOF + cat > conftest.S <<\EOF .global _start .type _start, @function _start: li.w $a7, 93 - /* This ensures the assembler supports explicit reloc. */ - pcalau12i $a0, %pc_hi20(x) - ld.w $a0, $a0, %pc_lo12(x) + li.w $a0, 0 syscall 0 .data @@ -27,41 +25,21 @@ x: /* This should produce an R_LARCH_RELATIVE in the static PIE. */ .dword _start EOF - cat > conftest2.S <<\EOF -.global f -.type f, @function -f: - /* The linker should be able to handle this and produce a PLT entry. */ - la.pcrel $t0, $t0, external_func - jirl $zero, $t0, 0 -EOF libc_cv_static_pie_on_loongarch=no - if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S' - { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 - (eval $ac_try) 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } \ - && { ac_try='LC_ALL=C $READELF -Wr conftest1 | grep -q R_LARCH_RELATIVE' - { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 - (eval $ac_try) 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } \ - && ! { ac_try='LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP' + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 (eval $ac_try) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } \ - && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -shared -nostdlib -fPIC -o conftest2.so conftest2.S' + && { ac_try='LC_ALL=C $READELF -Wr conftest | grep -q R_LARCH_RELATIVE' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 (eval $ac_try) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } \ - && { ac_try='LC_ALL=C $READELF -Wr conftest2.so | grep -q 'R_LARCH_JUMP_SLOT.*external_func'' + && ! { ac_try='LC_ALL=C $READELF -Wl conftest | grep -q INTERP' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 (eval $ac_try) 2>&5 ac_status=$? diff --git a/sysdeps/loongarch/configure.ac b/sysdeps/loongarch/configure.ac index 989287c6d2..28a8ae5486 100644 --- a/sysdeps/loongarch/configure.ac +++ b/sysdeps/loongarch/configure.ac @@ -8,19 +8,17 @@ AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC) dnl Test if the toolchain is new enough for static PIE. dnl We need a GAS supporting explicit reloc (older GAS produces stack-based dnl reloc and triggers an internal error in the linker). And, we need GCC to -dnl pass the correct linker flags for static PIE. GCC >= 13 and GAS >= 2.40 -dnl satisfy the requirement, but a distro may backport static PIE support into -dnl earlier GCC or Binutils releases as well. -AC_CACHE_CHECK([if the toolchain is sufficient to build static PIE on LoongArch], +dnl pass the correct linker flags for static PIE. We strictly require GAS >= +dnl 2.41 so we don't need to check the assembler capability, but we need to +dnl check if GCC is doing the correct thing. +AC_CACHE_CHECK([if ${CC-cc} is sufficient to build static PIE on LoongArch], libc_cv_static_pie_on_loongarch, [ - cat > conftest1.S <<\EOF + cat > conftest.S <<\EOF .global _start .type _start, @function _start: li.w $a7, 93 - /* This ensures the assembler supports explicit reloc. */ - pcalau12i $a0, %pc_hi20(x) - ld.w $a0, $a0, %pc_lo12(x) + li.w $a0, 0 syscall 0 .data @@ -29,21 +27,11 @@ x: /* This should produce an R_LARCH_RELATIVE in the static PIE. */ .dword _start EOF - cat > conftest2.S <<\EOF -.global f -.type f, @function -f: - /* The linker should be able to handle this and produce a PLT entry. */ - la.pcrel $t0, $t0, external_func - jirl $zero, $t0, 0 -EOF libc_cv_static_pie_on_loongarch=no - if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S]) \ - && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest1 | grep -q R_LARCH_RELATIVE]) \ - && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP]) \ - && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -shared -nostdlib -fPIC -o conftest2.so conftest2.S]) \ - && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest2.so | grep -q 'R_LARCH_JUMP_SLOT.*external_func']) + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest conftest.S]) \ + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep -q R_LARCH_RELATIVE]) \ + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest | grep -q INTERP]) then libc_cv_static_pie_on_loongarch=yes fi