From patchwork Tue Feb 13 09:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 200298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp427427dyb; Tue, 13 Feb 2024 01:44:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNThmGCgIgcoeM/e1C13555tCARptA6LLoTSZMz0oc0VO12mVEyhR3al5lMbtExKubshAojZGRTXUepM+jmXnMPCT/1A== X-Google-Smtp-Source: AGHT+IHp13C5VDosFI1IwNRvEHP4Xrw81L4X2Bgc3QDLPmqz2c2RS7sXGkpoMuja410woSqnZFrm X-Received: by 2002:a1f:c3c6:0:b0:4c0:1a5c:9185 with SMTP id t189-20020a1fc3c6000000b004c01a5c9185mr5130935vkf.4.1707817481547; Tue, 13 Feb 2024 01:44:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707817481; cv=pass; d=google.com; s=arc-20160816; b=tjFOSA1cHSjGjnhkk6zwphyL+ItJtqKkSLoYsjunCKg5aHABLPt/CUmkqEAr2lcz0u yAzf1O/QyL/WPU2KilzxT00yvxLv7Z40OHe3uA0vteyoL0SWr2C+hTGAtdZUl+QkbsK2 GejaH+gcGp2Cj+AQTnD7ri+z9AfjYyM+XMPsP0YVvI3nrMAEHbEkHSHNasvi5CQk3g3u kIZkMkQrf1yhEtXrDjXLj8SGZGqTza5JWIL2DYmSZhRlj1gSczn+fVRkNTAzgJu+7O9a 60Pp/ZGZoxg3AvGNRyUA+yuiy1haBZLiddl9EJuD8nRnDQWPWWN+FExspUdh6LSus8/y KOTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=7B6P42qclwzY7W6L+kyAJq5pSplV0FVM2CLS/oM3gOw=; fh=zN+OREGSHcn4CMSVESc5EmvzxrukLKIJaZ6v4IbghUA=; b=mC80Wr3wATzeJ/hr40CL8T+7pj7D2XLBCBTWdHPwaYu0ex/e4l/wCY84C0IAvWE04P r7wI5H1Zhy5b7tKeOe7U2WZnDq10Lrof2tDpLKdQIJ4a5ywlwJ+XCNSXUUL0pDs07osS VmS8Kx8oQZ96DgTu/YIAuVZzipiwtCVprcAl9wW9EzSe2pKZnxAwY5gfhlwbXA2LkDSC NJP7sCp8Ra2qxJDh2Trrl1Ug5/cSWB2s5l/Ltu6T+Poj5sZQI4HV64Opmxi0YIfmhf0Y SWoaYdNNPH2xg/Q5AQbKRChvA59nuD0ttCLQvdyeJMFS2VV+xMKY6JPntyxiyaSkzaQN 3CLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eIufFnt5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXqQGH5hBeyOKsvdhw9gpMOiJjwvccyosBBM+pvlpFA2bscq/PVNzlV3ZVFQiyMkx0vnF9thBFBshDfSXD+bYrdWKcS2w== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id kl8-20020a056214518800b0068c4ff7f5a0si2459854qvb.323.2024.02.13.01.44.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:44:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eIufFnt5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46A8C3858C39 for ; Tue, 13 Feb 2024 09:44:41 +0000 (GMT) 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9D0B13858C2D for ; Tue, 13 Feb 2024 09:43:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D0B13858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9D0B13858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707817421; cv=none; b=jBY3rimXabDQNZvkE+nXk2KIzQBlG2ressBCZEKBDLUAVCxdzdgQZfxctZUiH4xWEKchLOn4CcSh0LXJZ9Ac1k4Qy9o84G+Yholz+zs7IlWURD/NDGdLvTGHSodJ06yPH5nOOySBnjLnfRztvy0w8g8u6KyOcztq2R7Is1fljzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707817421; c=relaxed/simple; bh=rYw5Zn0Yv0DSM+v58A1/J53FJ/D7+VzCxgwaV+EJsrQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=JyEnXUjlnEIHDZMo+je12kr7dQIIGl9Ks1f9nfLqP6q7v5CyCHd/zNvtHy1ot2KPhxt1czWhhK7AEh7zUwCiJhNFLrqe9+rCsuyyr4tQX4bmhkSqcRkm85WaF2QKwEZ3FrqOw3q7El9tBo7D1EmiXPKTuGI0NYCJvxdB7P1jIhw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707817419; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=7B6P42qclwzY7W6L+kyAJq5pSplV0FVM2CLS/oM3gOw=; b=eIufFnt5OjPZtpxrlR57F3tl0cEk2fvSTAICawI42+kA9Xg0TNqjCxCJhgDTPNP46r8eLf lUpaNjDwJCC/41A9FzrmRnB1IkvHFkhau28f8CS6u1ltcDNBal8zb1wJn6qcKn57JGsDnf iGW1Ztrbhb1j8h6GL1HdgsFQ1lJLk34= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-YGTGjAJXPAuETQo6iqwAWA-1; Tue, 13 Feb 2024 04:42:57 -0500 X-MC-Unique: YGTGjAJXPAuETQo6iqwAWA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 420E61C2FE26; Tue, 13 Feb 2024 09:42:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01E9AC185D2; Tue, 13 Feb 2024 09:42:56 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41D9grU11329754 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 10:42:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41D9gqBU1329753; Tue, 13 Feb 2024 10:42:52 +0100 Date: Tue, 13 Feb 2024 10:42:52 +0100 From: Jakub Jelinek To: "H.J. Lu" Cc: iain@sandoe.co.uk, gcc-patches@gcc.gnu.org Subject: [PATCH] libgcc: Implement -mx32 [PR113855] Message-ID: References: <20240210171444.132-1-iain@sandoe.co.uk> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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_H2, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790776423244538388 X-GMAIL-MSGID: 1790776423244538388 On Sat, Feb 10, 2024 at 10:05:34AM -0800, H.J. Lu wrote: > > I bet it probably doesn't work properly for -mx32 (which defines > > __x86_64__), CCing H.J. on that, but that is a preexisting issue > > (and I don't have any experience with it; I guess one would either > > need to add 4 bytes of padding after the func_ptr so that those > > bits remain zeros as sizeof (void *) is 4, but presumably it would be > > better to just use movl (but into %r10) and maybe the jmpl instead > > of movabsq. > > Are there any testcases to exercise this code on Linux? Here is an untested attempt to implement it for -mx32 (well, I've compiled it with -mx32 in libgcc by hand after stubbing /usr/include/gnu/stubs-x32.h). Testcase could be something like: /* { dg-do run } */ /* { dg-options "-ftrampoline-impl=heap" } */ __attribute__((noipa)) int bar (int (*fn) (int)) { return fn (42) + 1; } int main () { int a = 0; int foo (int x) { if (x != 42) __builtin_abort (); return ++a; } if (bar (foo) != 2 || a != 1) __builtin_abort (); if (bar (foo) != 3 || a != 2) __builtin_abort (); a = 42; if (bar (foo) != 44 || a != 43) __builtin_abort (); return 0; } but I must say I'm also surprised we have no tests for this in the testsuite. Sure, we'd also need to add some effective target whether -ftrampoline-impl=heap can be used for a link/runtime test or not. 2024-02-13 Jakub Jelinek PR target/113855 * config/i386/heap-trampoline.c (trampoline_insns): Use movabsq instead of movabs in comments. Add -mx32 variant. Jakub --- libgcc/config/i386/heap-trampoline.c.jj 2024-02-12 18:48:08.548886036 +0100 +++ libgcc/config/i386/heap-trampoline.c 2024-02-13 10:24:06.348020670 +0100 @@ -30,18 +30,34 @@ void __gcc_nested_func_ptr_created (void void __gcc_nested_func_ptr_deleted (void); #if __x86_64__ + +#ifdef __LP64__ static const uint8_t trampoline_insns[] = { - /* movabs $,%r11 */ + /* movabsq $,%r11 */ 0x49, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - /* movabs $,%r10 */ + /* movabsq $,%r10 */ 0x49, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* rex.WB jmpq *%r11 */ 0x41, 0xff, 0xe3 }; +#else +static const uint8_t trampoline_insns[] = { + /* movl $,%r11d */ + 0x41, 0xbb, + 0x00, 0x00, 0x00, 0x00, + + /* movl $,%r10d */ + 0x41, 0xba, + 0x00, 0x00, 0x00, 0x00, + + /* rex.WB jmpq *%r11 */ + 0x41, 0xff, 0xe3 +}; +#endif union ix86_trampoline { uint8_t insns[sizeof(trampoline_insns)];