From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 899E23857C59 for ; Tue, 22 Sep 2020 00:30:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 899E23857C59 Received: by mail-pj1-x1029.google.com with SMTP id v14so610925pjd.4 for ; Mon, 21 Sep 2020 17:30:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=W7FNs1HT61cF/WcAY4QoWOEkPqVvevQhDf1Zu0NEClE=; b=g3+cy/SzrYcrTdwjQlifITl6R9Knhvhdzx3uQdCmUU4HbIkE4AlcHfrM4T6HafCZ0i 5eBxiPsP2jmUrN+Y4/zmURHSOraBuE90KWu/dl17MDhhHS2AAJZq3MTLYeEsOhl4g/b5 qwDnVHPe5DZqmef+/nKnySgO0vIsEy0Wsn/+w5Pvggz6ylzXw1/ZgKWpxT60AgG4/cJm HdS5tBfF4OiS4B7lPiFeehoMZjlUbbkpkpIJ6B80BYDWSI3dLELwthqs2xWSshAbjh/a YoiLxI6ws3zP0EqrUdHIqZcyzuJVQm/N1foRAIfd9wVanC4jCmvko5mn0YkyoBUFd1Oa mQ8w== X-Gm-Message-State: AOAM533HEGReUeQiGaih9zv9H+TztNgPQfggCka3NGuFEUMI8TniD7wr O3LHWYqy/K7k+w0Kwra2CxVYo8QIFOk= X-Google-Smtp-Source: ABdhPJyNCChDw2j/nPl1Gf8lkOwqYUimaugRlikMrwItxbn4iRTOaHy0vdw2uoJS/dKz8T1oBJLsxw== X-Received: by 2002:a17:90b:796:: with SMTP id l22mr1570454pjz.199.1600734616100; Mon, 21 Sep 2020 17:30:16 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:a8c1:6a10:a6b6:9baa]) by smtp.gmail.com with ESMTPSA id n2sm505207pja.41.2020.09.21.17.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 17:30:15 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 97A0480BD3; Tue, 22 Sep 2020 10:00:11 +0930 (ACST) Date: Tue, 22 Sep 2020 10:00:11 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [RS6000] Power10 libffi fixes Message-ID: <20200922003011.GB5452@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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-List-Received-Date: Tue, 22 Sep 2020 00:30:20 -0000 Power10 pc-relative code doesn't use or preserve r2 as a TOC pointer. That means calling between pc-relative and TOC using code can't be done without intervening linker stubs, and a call from TOC code to pc-relative code must have a nop after the bl in order to restore r2. Now the PowerPC libffi assembly code doesn't use r2 except for the implicit use when making calls back to C, ffi_closure_helper_LINUX64 and ffi_prep_args64. So changing the assembly to interoperate with pc-relative code without stubs is easily done. Controlling that is a new built-in macro. Upstream libffi currently has a different patch applied to work around the power10 build failure. I'll post a delta for upstream. Bootstrapped and regression tested on power8, built for power10. gcc/ * config/rs6000/rs6000-c.c (rs6000_target_modify_macros): Conditionally define __PCREL__. libffi/ * src/powerpc/linux64.S (ffi_call_LINUX64): Don't emit global entry when __PCREL__. Call using @notoc. (ffi_closure_LINUX64, ffi_go_closure_linux64): Likewise. diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c index f5982907e90..cc1e997524e 100644 --- a/gcc/config/rs6000/rs6000-c.c +++ b/gcc/config/rs6000/rs6000-c.c @@ -597,6 +597,9 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags, /* Tell the user if we support the MMA instructions. */ if ((flags & OPTION_MASK_MMA) != 0) rs6000_define_or_undefine_macro (define_p, "__MMA__"); + /* Whether pc-relative code is being generated. */ + if ((flags & OPTION_MASK_PCREL) != 0) + rs6000_define_or_undefine_macro (define_p, "__PCREL__"); } void diff --git a/libffi/src/powerpc/linux64.S b/libffi/src/powerpc/linux64.S index b2ae60ead6e..bfb4d2957ae 100644 --- a/libffi/src/powerpc/linux64.S +++ b/libffi/src/powerpc/linux64.S @@ -36,8 +36,10 @@ .cfi_startproc # if _CALL_ELF == 2 ffi_call_LINUX64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_call_LINUX64@ha addi %r2, %r2, .TOC.-ffi_call_LINUX64@l +# endif .localentry ffi_call_LINUX64, . - ffi_call_LINUX64 # else .section ".opd","aw" @@ -89,7 +91,11 @@ ffi_call_LINUX64: /* Call ffi_prep_args64. */ mr %r4, %r1 # if defined _CALL_LINUX || _CALL_ELF == 2 +# ifdef __PCREL__ + bl ffi_prep_args64@notoc +# else bl ffi_prep_args64 +# endif # else bl .ffi_prep_args64 # endif diff --git a/libffi/src/powerpc/linux64_closure.S b/libffi/src/powerpc/linux64_closure.S index 6487d2a2970..938e86034f1 100644 --- a/libffi/src/powerpc/linux64_closure.S +++ b/libffi/src/powerpc/linux64_closure.S @@ -37,8 +37,10 @@ .cfi_startproc # if _CALL_ELF == 2 ffi_closure_LINUX64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_closure_LINUX64@ha addi %r2, %r2, .TOC.-ffi_closure_LINUX64@l +# endif .localentry ffi_closure_LINUX64, . - ffi_closure_LINUX64 # else .section ".opd","aw" @@ -155,7 +157,11 @@ ffi_closure_LINUX64: # make the call # if defined _CALL_LINUX || _CALL_ELF == 2 +# ifdef __PCREL__ + bl ffi_closure_helper_LINUX64@notoc +# else bl ffi_closure_helper_LINUX64 +# endif # else bl .ffi_closure_helper_LINUX64 # endif @@ -396,8 +402,10 @@ ffi_closure_LINUX64: .cfi_startproc # if _CALL_ELF == 2 ffi_go_closure_linux64: +# ifndef __PCREL__ addis %r2, %r12, .TOC.-ffi_go_closure_linux64@ha addi %r2, %r2, .TOC.-ffi_go_closure_linux64@l +# endif .localentry ffi_go_closure_linux64, . - ffi_go_closure_linux64 # else .section ".opd","aw" -- Alan Modra Australia Development Lab, IBM