From patchwork Sun Feb 18 16:02:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1900661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ivo2mtp3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Td9Rm3Yr6z20Qg for ; Mon, 19 Feb 2024 03:02:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34CEB386181C for ; Sun, 18 Feb 2024 16:02:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 9E6523861024 for ; Sun, 18 Feb 2024 16:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E6523861024 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E6523861024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708272139; cv=none; b=x4rCLDnpIR+RvOQci5/dxHNNJwAcPvxPsBKL6gbM1dbnrRzNuU962/uOEeDVeAKSk6TFvWdCnbE884dWoIXaSOB3XsjNsEDVLZixmimQ4jOFzrojohg+9bYlc2aXx65QQXqnfjGixBehlr1+uhlXONz04i7jWevQ0a+pg4Yh9ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708272139; c=relaxed/simple; bh=d6/kRDsu/R6n0+s3pfShcgxkP8oWTGiseEFxoV7/BTM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DYzccULmIrgJW1EHjlr6Z9JkPdF+RS+NmhgHBvuSP9guEBCjonIgM1XIfD9nY+F6yd+d4dVkOES2l0vjcLoWSIot/PmV4c9/sXWY3NsJL1hRgbF17EjaSkiBQyD8H5mlwOPVGZ7Kb+xlEtLWwmA2l3FHyrB6CrZ/anJKXuLwWls= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6e459b39e2cso200514b3a.1 for ; Sun, 18 Feb 2024 08:02:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708272136; x=1708876936; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MNHqc9nCrDwxOMbnJHnxJVxyjyD0/ea7wqFqfd1G4w8=; b=ivo2mtp3vsGiN0N+a/6v+5MgpHrcgVgfKMefvXLlj36c+4zg0Rp/HynaEPqQKRE70P XWTjW76BgEezrX3VOiUHMm0jsmQvnQZPhOygNmNjCNsCGV+BwkgfEZBDZs6EPWBUjyOv GwGDjw7oAoTCURyrDvQz0URD1mWhRgy6w5ORoyhksv7Kr/XXO68ilvrwQnnko0TK/YGi XqjG1JK3W8q/3C7cU1WThNzYdgbZ69vJ/gg5gCqmT13fYtgBExTq2MPvVmsaLwUGQ9jl sccRNaQWbDIABEB/uCo4q2ajuK+Knl6TrHKBszgxvAgpqyNjM1xkqM9QVFnDgTLUZVRf SZDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708272136; x=1708876936; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MNHqc9nCrDwxOMbnJHnxJVxyjyD0/ea7wqFqfd1G4w8=; b=R0ZmCrhceuPBgYNR2KBRGZAsDuAe8+cXojSSB9m1LdceQLuVPdbmOGgjkqF527RHsS 8ZZTZtKtc0yyRX31Su02sKQfnq3pX11UFlwPbm0qmK0hES1AR9O3UusGwRMwHyKMNHm3 20TnqFps6F4Nvh7oWg/RY6/ap0eaSrm1A8ES6LGnXyDFD5xOq53f8TDbHoTW6ZGjsWIF 82s6MaaxQrmjRDLBc58iPsneoG53HTi7PyfFywgi+bBs6aQIt3s5zWUso+8PCMHGhXX+ G/HTrZ8YqLLjncDHnck/A+Ceu2odI1BrA+2sODvykT0aTmjxcz6QzzQQ56DY/9TZ5Vvx oESg== X-Gm-Message-State: AOJu0Yy/BV1XAxZIm5lH2zuJMGLmhqDT5TmhI/8dxOL08l7q8TKVftrd HpXoZ9HWmxJkYvWneDYuR9w49USG/qoc5WxydSLqiYRDEG0aQibiyqHt4omA X-Google-Smtp-Source: AGHT+IEo8Gtjg5/3QLnYOQM3PcfOJed2EsHdm7mMX/V1DqgWwHfA540eKduIeVmnq9HRHnYE3Q8q5g== X-Received: by 2002:a17:90a:ac01:b0:296:530:996e with SMTP id o1-20020a17090aac0100b002960530996emr13288745pjq.20.1708272135947; Sun, 18 Feb 2024 08:02:15 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.58.89.72]) by smtp.gmail.com with ESMTPSA id bj19-20020a17090b089300b0029988480e2fsm1089723pjb.30.2024.02.18.08.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 08:02:15 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 3E3C77402BB; Sun, 18 Feb 2024 08:02:14 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com Subject: [PATCH] x86-64: Check R_X86_64_CODE_6_GOTTPOFF support Date: Sun, 18 Feb 2024 08:02:14 -0800 Message-ID: <20240218160214.154341-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org If assembler and linker supports add %reg1, name@gottpoff(%rip), %reg2 with R_X86_64_CODE_6_GOTTPOFF, we can generate it instead of mov name@gottpoff(%rip), %reg2 add %reg1, %reg2 gcc/ * configure.ac (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF): Defined as 1 if R_X86_64_CODE_6_GOTTPOFF is supported. * config.in: Regenerated. * configure: Likewise. * config/i386/predicates.md (apx_ndd_add_memory_operand): Allow UNSPEC_GOTNTPOFF if R_X86_64_CODE_6_GOTTPOFF is supported. gcc/testsuite/ * gcc.target/i386/apx-ndd-tls-1b.c: New test. * lib/target-supports.exp (check_effective_target_code_6_gottpoff_reloc): New. --- gcc/config.in | 7 +++ gcc/config/i386/predicates.md | 6 +- gcc/configure | 62 +++++++++++++++++++ gcc/configure.ac | 37 +++++++++++ .../gcc.target/i386/apx-ndd-tls-1b.c | 9 +++ gcc/testsuite/lib/target-supports.exp | 48 ++++++++++++++ 6 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/apx-ndd-tls-1b.c diff --git a/gcc/config.in b/gcc/config.in index ce1d073833f..f3de4ba6776 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -737,6 +737,13 @@ #endif +/* Define 0/1 if your assembler and linker support R_X86_64_CODE_6_GOTTPOFF. + */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_R_X86_64_CODE_6_GOTTPOFF +#endif + + /* Define if your assembler supports relocs needed by -fpic. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_SMALL_PIC_RELOCS diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md index 4c1aedd7e70..391f108c360 100644 --- a/gcc/config/i386/predicates.md +++ b/gcc/config/i386/predicates.md @@ -2299,10 +2299,14 @@ (define_predicate "apx_ndd_memory_operand" ;; Return true if OP is a memory operand which can be used in APX NDD ;; ADD with register source operand. UNSPEC_GOTNTPOFF memory operand -;; isn't allowed with APX NDD ADD. +;; is allowed with APX NDD ADD only if R_X86_64_CODE_6_GOTTPOFF works. (define_predicate "apx_ndd_add_memory_operand" (match_operand 0 "memory_operand") { + /* OK if "add %reg1, name@gottpoff(%rip), %reg2" is supported. */ + if (HAVE_AS_R_X86_64_CODE_6_GOTTPOFF) + return true; + op = XEXP (op, 0); /* Disallow APX NDD ADD with UNSPEC_GOTNTPOFF. */ diff --git a/gcc/configure b/gcc/configure index 41b978b0380..c59c971862c 100755 --- a/gcc/configure +++ b/gcc/configure @@ -29834,6 +29834,68 @@ cat >>confdefs.h <<_ACEOF _ACEOF + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then + ld_ix86_gld_64_opt="-melf_x86_64_sol2" + else + ld_ix86_gld_64_opt="-melf_x86_64" + fi + fi + conftest_s=' + .text + .globl _start + .type _start, @function +_start: + addq %r23,foo@GOTTPOFF(%rip), %r15 + .section .tdata,"awT",@progbits + .type foo, @object +foo: + .quad 0' + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for R_X86_64_CODE_6_GOTTPOFF reloc" >&5 +$as_echo_n "checking assembler for R_X86_64_CODE_6_GOTTPOFF reloc... " >&6; } +if ${gcc_cv_as_x86_64_code_6_gottpoff+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_x86_64_code_6_gottpoff=no + if test x$gcc_cv_as != x; then + $as_echo "$conftest_s" > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&5' + { { 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 + if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \ + && test x$gcc_cv_readelf != x \ + && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \ + | grep R_X86_64_CODE_6_GOTTPOFF > /dev/null 2>&1 \ + && $gcc_cv_ld $ld_ix86_gld_64_opt -o conftest conftest.o > /dev/null 2>&1; then + if $gcc_cv_objdump -dw conftest 2>&1 \ + | grep "add \+\$0xf\+8,%r23,%r15" > /dev/null 2>&1; then + gcc_cv_as_x86_64_code_6_gottpoff=yes + else + gcc_cv_as_x86_64_code_6_gottpoff=no + fi + fi + rm -f conftest + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_x86_64_code_6_gottpoff" >&5 +$as_echo "$gcc_cv_as_x86_64_code_6_gottpoff" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define HAVE_AS_R_X86_64_CODE_6_GOTTPOFF `if test x"$gcc_cv_as_x86_64_code_6_gottpoff" = xyes; then echo 1; else echo 0; fi` +_ACEOF + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for GOTOFF in data" >&5 $as_echo_n "checking assembler for GOTOFF in data... " >&6; } if ${gcc_cv_as_ix86_gotoff_in_data+:} false; then : diff --git a/gcc/configure.ac b/gcc/configure.ac index 72012d61e67..0ae6a4c66f1 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5057,6 +5057,43 @@ _start: [`if test x"$gcc_cv_as_ix86_got32x" = xyes; then echo 1; else echo 0; fi`], [Define 0/1 if your assembler and linker support @GOT.]) + if echo "$ld_ver" | grep GNU > /dev/null; then + if $gcc_cv_ld -V 2>/dev/null | grep elf_x86_64_sol2 > /dev/null; then + ld_ix86_gld_64_opt="-melf_x86_64_sol2" + else + ld_ix86_gld_64_opt="-melf_x86_64" + fi + fi + conftest_s=' + .text + .globl _start + .type _start, @function +_start: + addq %r23,foo@GOTTPOFF(%rip), %r15 + .section .tdata,"awT",@progbits + .type foo, @object +foo: + .quad 0' + gcc_GAS_CHECK_FEATURE([R_X86_64_CODE_6_GOTTPOFF reloc], + gcc_cv_as_x86_64_code_6_gottpoff,, + [$conftest_s], + [if test x$gcc_cv_ld != x && test x$gcc_cv_objdump != x \ + && test x$gcc_cv_readelf != x \ + && $gcc_cv_readelf --relocs --wide conftest.o 2>&1 \ + | grep R_X86_64_CODE_6_GOTTPOFF > /dev/null 2>&1 \ + && $gcc_cv_ld $ld_ix86_gld_64_opt -o conftest conftest.o > /dev/null 2>&1; then + if $gcc_cv_objdump -dw conftest 2>&1 \ + | grep "add \+\$0xf\+8,%r23,%r15" > /dev/null 2>&1; then + gcc_cv_as_x86_64_code_6_gottpoff=yes + else + gcc_cv_as_x86_64_code_6_gottpoff=no + fi + fi + rm -f conftest]) + AC_DEFINE_UNQUOTED(HAVE_AS_R_X86_64_CODE_6_GOTTPOFF, + [`if test x"$gcc_cv_as_x86_64_code_6_gottpoff" = xyes; then echo 1; else echo 0; fi`], + [Define 0/1 if your assembler and linker support R_X86_64_CODE_6_GOTTPOFF.]) + gcc_GAS_CHECK_FEATURE([GOTOFF in data], gcc_cv_as_ix86_gotoff_in_data, [$as_ix86_gas_32_opt], diff --git a/gcc/testsuite/gcc.target/i386/apx-ndd-tls-1b.c b/gcc/testsuite/gcc.target/i386/apx-ndd-tls-1b.c new file mode 100644 index 00000000000..a3eb8106508 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/apx-ndd-tls-1b.c @@ -0,0 +1,9 @@ +/* PR target/113733 */ +/* { dg-do assemble { target { apxf && { ! ia32 } } } } */ +/* { dg-require-effective-target tls } */ +/* { dg-require-effective-target code_6_gottpoff_reloc } */ +/* { dg-options "-save-temps -mapxf -O3 -w" } */ + +#include "apx-ndd-tls-1a.c" + +/* { dg-final { scan-assembler-times "addq\[ \t]+%r\[a-z0-9\]+, a@gottpoff\\(%rip\\), %r\[a-z0-9\]+" 1 { target lp64 } } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 6f4e25f280c..8b3b39411b0 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -12241,6 +12241,54 @@ proc check_effective_target_pie_copyreloc { } { }] } +# Return 1 if the x86-64 target supports R_X86_64_CODE_6_GOTTPOFF +# relocation, 0 otherwise. Cache the result. + +proc check_effective_target_code_6_gottpoff_reloc { } { + global tool + global GCC_UNDER_TEST + + if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } { + return 0 + } + + # Need auto-host.h to check linker support. + if { ![file exists ../../auto-host.h ] } { + return 0 + } + + return [check_cached_effective_target code_6_gottpoff_reloc { + # Include the current process ID in the file names to prevent + # conflicts with invocations for multiple testsuites. + + set src code_6_gottpoff[pid].c + set obj code_6_gottpoff[pid].o + + set f [open $src "w"] + puts $f "#include \"../../auto-host.h\"" + puts $f "#if HAVE_AS_R_X86_64_CODE_6_GOTTPOFF == 0" + puts $f "# error Assembler does not support R_X86_64_CODE_6_GOTTPOFF." + puts $f "#endif" + close $f + + verbose "check_effective_target_code_6_gottpoff_reloc compiling testfile $src" 2 + set lines [${tool}_target_compile $src $obj object ""] + + file delete $src + file delete $obj + + if [string match "" $lines] then { + verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation passed" 2 + return 1 + } else { + verbose "check_effective_target_code_6_gottpoff_reloc testfile compilation failed" 2 + return 0 + } + }] + + return $code_6_gottpoff_reloc_available_saved +} + # Return 1 if the x86 target supports R_386_GOT32X relocation, 0 # otherwise. Cache the result.