From patchwork Tue Oct 5 15:46:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 45902 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 E1953385B833 for ; Tue, 5 Oct 2021 15:50:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1953385B833 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633449023; bh=UM1ahHLTyuS2DGwFSVTvvrxLf+pNmTUVzyCLd/w++KE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=o/P/QxUbWyieiTspvN2qZWDQ0hY/bWDKEYB9en/pCXi+43uxiuPo1jZu3zvVgRWXs rWCa+UJCVvJ2wOwfb8rwAvQcrb3xvlW53jC0C2ZxvdU1PUSelgQEBkpqDu8rc2IsNA HHFmtFpoYM47MdQbrOFHODQW/cI48Vin3h7uivFo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 3F522385B83A for ; Tue, 5 Oct 2021 15:48:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F522385B83A Received: by mail-wm1-x335.google.com with SMTP id t16-20020a1c7710000000b003049690d882so3517802wmi.5 for ; Tue, 05 Oct 2021 08:48:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=UM1ahHLTyuS2DGwFSVTvvrxLf+pNmTUVzyCLd/w++KE=; b=TNhEbcxoWZkr3vG1uoPc4tZeNe+wQQ/Zhq+JjvnNYcIUFWjoKuZxk1Czp/0H9BTUiq PFxPmhBxktY6yMnqwt9rwxQIPSS9O1qBgEodbdBOUZZ1FdWauJNYGpICwwVU+7e0Sw0X ulu78YDkIBgOKcKs3ThK8b5iUVd0Ba/i7HFAVvfj5c6YTHIBrIqIykuehd0bKLIINY5B xxfsh6xwtpnEDVox4mtIY/O3jB/XdpJ9JDA+j1QAS8NjVbRLaWXYEmkkWrE8C0NS4Wmd WywxfXf1qAyLh6Y1vmE8xEaMM3uyTJ0Ur2n+nrBJfXXIC/CcYjG68C+WcXikychNCXB7 9QOg== X-Gm-Message-State: AOAM530G+jKVtOJVOgPy0HD+GFXME1tnOp9sUsHyvOyT2vH8gpUY+gpc GH18uWTOCNuzdt5hJqjD2MrNwVEdzH4bQw== X-Google-Smtp-Source: ABdhPJwIGpR2m/TNFY2nTn1RRfUUVU0DnENy3UBHlurw4rFynOVrGv56t018n5T7keu1nJ0t8UVQiA== X-Received: by 2002:a1c:22d7:: with SMTP id i206mr4305825wmi.122.1633448936076; Tue, 05 Oct 2021 08:48:56 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id r2sm2427484wmq.28.2021.10.05.08.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 08:48:55 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [i386] Fix couple of issues in large PIC model on x86-64/VxWorks Date: Tue, 05 Oct 2021 17:46:56 +0200 Message-ID: <7295547.EvYhyI6sBW@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, the first issue is that the !gotoff_operand path of legitimize_pic_address in large PIC model does not make use of REG when it is available, which breaks for thunks because new pseudo-registers can no longer be created. And the second issue is that the system compiler (LLVM) generates @GOTOFF in large model even for RTP, so we do the same. Tested on x86-64/Linux and VxWorks, OK for the mainline? 2021-10-05 Eric Botcazou * config/i386/i386.c (legitimize_pic_address): Adjust comment and use the REG argument on the CM_LARGE_PIC code path as well. * config/i386/predicates.md (gotoff_operand): Do not treat VxWorks specially with the large code models. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index a566d84a61e..a6784c4e9d6 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -11152,7 +11152,7 @@ legitimize_pic_address (rtx orig, rtx reg) new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); } else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0) - /* We can't use @GOTOFF for text labels + /* We can't always use @GOTOFF for text labels on VxWorks, see gotoff_operand. */ || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF)) { @@ -11181,9 +11181,19 @@ legitimize_pic_address (rtx orig, rtx reg) from the Global Offset Table (@GOT). */ new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT); new_rtx = gen_rtx_CONST (Pmode, new_rtx); + if (TARGET_64BIT) - new_rtx = force_reg (Pmode, new_rtx); - new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); + new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode); + + if (reg != 0) + { + gcc_assert (REG_P (reg)); + new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx, + new_rtx, reg, 1, OPTAB_DIRECT); + } + else + new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); + new_rtx = gen_const_mem (Pmode, new_rtx); set_mem_alias_set (new_rtx, ix86_GOT_alias_set ()); } diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md index df5acb425d4..af2a573f3dd 100644 --- a/gcc/config/i386/predicates.md +++ b/gcc/config/i386/predicates.md @@ -617,9 +617,11 @@ ;; use @GOTOFF unless we are absolutely sure that the symbol is in the ;; same segment as the GOT. Unfortunately, the flexibility of linker ;; scripts means that we can't be sure of that in general, so assume -;; that @GOTOFF is never valid on VxWorks. +;; @GOTOFF is not valid on VxWorks, except with the large code model. (define_predicate "gotoff_operand" - (and (not (match_test "TARGET_VXWORKS_RTP")) + (and (ior (not (match_test "TARGET_VXWORKS_RTP")) + (match_test "ix86_cmodel == CM_LARGE") + (match_test "ix86_cmodel == CM_LARGE_PIC")) (match_operand 0 "local_symbolic_operand"))) ;; Test for various thread-local symbols.