From patchwork Tue Dec 1 08:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1408675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=NehmunAk; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4ClbTz6J6zz9sW4 for ; Tue, 1 Dec 2020 19:53:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D3C53892033; Tue, 1 Dec 2020 08:53:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D3C53892033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606812788; bh=mRH9Oq+LeTzuph5fJEW028s1BIN5X5v76ThGK0TCoBg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=NehmunAk11lToLI7LJOcxCIS2z9UubPPWH+pp3x0DV4h6Kz4F1nkNoxSzaDYZQGlD 5cUWjuvepIwyxS/FkE4woW2HZeZMcFPijZqgPLXO91ALduivsoaGzj5zV3NQ7TagHc KcQX/WTMjr7f1sjepAG9T5W8AWMMtFIV1mpuGn2U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id AA9203857000 for ; Tue, 1 Dec 2020 08:53:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AA9203857000 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-rERsl8QINnyc7jBisPsA7g-1; Tue, 01 Dec 2020 03:53:01 -0500 X-MC-Unique: rERsl8QINnyc7jBisPsA7g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 607423E74B; Tue, 1 Dec 2020 08:53:00 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-127.ams2.redhat.com [10.36.113.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BFF65C1A3; Tue, 1 Dec 2020 08:52:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 0B18qvVI2004411 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 1 Dec 2020 09:52:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 0B18qvYD2004410; Tue, 1 Dec 2020 09:52:57 +0100 Date: Tue, 1 Dec 2020 09:52:56 +0100 To: Uros Bizjak , "H.J. Lu" Subject: [PATCH] x86_64: Fix up -fpic -mcmodel=large -fno-plt [PR98063] Message-ID: <20201201085256.GQ3788@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! On the following testcase with -fpic -mcmodel=large -fno-plt we emit call puts@GOTPCREL(%rip) but that is not really appropriate for CM_LARGE_PIC, the .text can be larger than 2GB in that case and the .got slot further away from %rip than what can fit into the signed 32-bit immediate. The following patch computes the address of the .got slot the way it is computed for that model for function pointer loads, and calls that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-12-01 Jakub Jelinek PR target/98063 * config/i386/i386-expand.c (ix86_expand_call): Handle non-plt CM_LARGE_PIC calls. * gcc.target/i386/pr98063.c: New test. Jakub --- gcc/config/i386/i386-expand.c.jj 2020-11-26 16:22:29.091353066 +0100 +++ gcc/config/i386/i386-expand.c 2020-11-30 12:55:52.936300739 +0100 @@ -8063,7 +8063,17 @@ ix86_expand_call (rtx retval, rtx fnaddr } else if (!TARGET_PECOFF && !TARGET_MACHO) { - if (TARGET_64BIT) + if (TARGET_64BIT + && ix86_cmodel == CM_LARGE_PIC + && DEFAULT_ABI != MS_ABI) + { + fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), + UNSPEC_GOT); + fnaddr = gen_rtx_CONST (Pmode, fnaddr); + fnaddr = force_reg (Pmode, fnaddr); + fnaddr = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, fnaddr); + } + else if (TARGET_64BIT) { fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), --- gcc/testsuite/gcc.target/i386/pr98063.c.jj 2020-11-30 13:00:31.699214198 +0100 +++ gcc/testsuite/gcc.target/i386/pr98063.c 2020-11-30 13:24:05.352485291 +0100 @@ -0,0 +1,13 @@ +/* PR target/98063 */ +/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-O2 -fpic -mcmodel=large -fno-plt -save-temps" } */ +/* { dg-final { scan-assembler-not "puts@GOTPCREL" } } */ + +int +main () +{ + __builtin_puts ("Hello, world!"); + return 0; +}