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: 1898153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eIufFnt5; 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 4TYxHG0XTCz20RF for ; Tue, 13 Feb 2024 20:44:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F87A3858417 for ; Tue, 13 Feb 2024 09:44:05 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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)];