Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3700629pxp; Wed, 23 Mar 2022 04:14:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFlwJL1Se+jYGtDpBumGkMt7hevB8y7zp8NkwTITewP/493nrdxQ57/XcnQsyaPdrTZCz6 X-Received: by 2002:a17:903:1c7:b0:154:1831:1f76 with SMTP id e7-20020a17090301c700b0015418311f76mr23486784plh.0.1648034094540; Wed, 23 Mar 2022 04:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648034094; cv=none; d=google.com; s=arc-20160816; b=XyH4q/NDKGmxAZsyshmGH8GBTZC/J5oQNV1Lclli7MCKUHlrU2Hkk1yDtqaPS7ighT HalXbEeBn7p30hLCfp1GuSfRWTHDu1KKcH1s2/Gm9soDJRalTbg0NDaueWIbPNKqW7Qx jBCpm+QhGJ0BcIJCTIAnnGzMxRkcoRMpdtPbdRB8dCsy9bsgqI7lewcfadxe96FrTn4t Ht0OFlupdnnGS7/JG01HRjxeXNS+QYn08+mU/+KT0a+2R2dGoxrg0/Drsa+Tmm9Ahmyf jiDSNIxD1XCkVEXrhUNNSlGmhEEAYsT3Jy+rpCYjc2Bnvjz+EwcBeCY0rUkJfVjppH38 lfzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :content-language:references:cc:to:from:user-agent:mime-version:date :message-id:dkim-signature; bh=jbQUmg+PpEtzP/8M2G6UG3I01HQCqHDmQJ+q8jfEIG4=; b=Y0LzqJO58r3YgnL0F7UmK5j9uJAYE6IXDrKWIA09UNPrsCZfp0LvYzBVqppsunn1UA GPth0wuGox9CB7BfYf9LgACz0yP/KwEcERFP1EpUKJ8Y/pvZETjuP9r+TPNhJD+zaWZe vZXagOEbfyduPM10zRVm0QW3wXR9hoz1iOocSemoUtKpqySxPDOaRm25sjDh9RMOpUei xoPbLmMPkO9v8O1jvdQeigKLpKSZ3XQh5pCLnnn7jLBx4BaMUH1ZCMX/QcRkxqSwRwAB qZESFvEDWAAt9V9CDJa9+zCcYpNWMzn/u504I6KfyV5WepPE6znxWFOz3nhXRMsCDdI3 VyIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b="t0UH9wr/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp9-20020a17090b4a8900b001bd14e01f4dsi1351849pjb.59.2022.03.23.04.14.39; Wed, 23 Mar 2022 04:14:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b="t0UH9wr/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238857AbiCWGbT (ORCPT + 99 others); Wed, 23 Mar 2022 02:31:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiCWGbR (ORCPT ); Wed, 23 Mar 2022 02:31:17 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F43554B5 for ; Tue, 22 Mar 2022 23:29:48 -0700 (PDT) Received: from [192.168.12.80] (unknown [182.2.71.26]) by gnuweeb.org (Postfix) with ESMTPSA id E2BE57E342; Wed, 23 Mar 2022 06:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1648016987; bh=rTYefPkm+7jh3YIcnrUKbBW9z+mAVw1UIN7o+WWdb6g=; h=Date:From:To:Cc:References:Subject:In-Reply-To:From; b=t0UH9wr/A8UAyjs5YliU2fVLk2EdDwauQN1d5rIafsqmJvmDsRIqhhUdBeyxEXGYB 17688upkz47HJcZV9s8yT33VGgTByJHsdWQQE109w68t9w+TZYQRR8bcCgpFCLuUl2 U7WUb03B/zgOdI2o+stWvpmqb8vDMcw06vCtQ6tQmZZ1hAiMhCtaSB8fNrczxSPU3a ejE6x6GxivbB9fX2evVsclML/a/z8TI2n/LC6ny5hCAA+tMSSxaO0X089WOKTWlXii wgABX5JvJuR3uvODbLh2B8fX81o79u71FZ23S2gPS2BmxSooy8D3bWJH0ppbrD1nz6 l0CRZY4NiTgyQ== Message-ID: <2eba5687-6b63-ceb2-3fbd-3d236727ea11@gnuweeb.org> Date: Wed, 23 Mar 2022 13:29:39 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 From: Ammar Faizi To: David Laight , 'Willy Tarreau' Cc: "Paul E. McKenney" , Alviro Iskandar Setiawan , Nugraha , Linux Kernel Mailing List , GNU/Weeb Mailing List , "x86@kernel.org" , "llvm@lists.linux.dev" References: <20220322102115.186179-1-ammarfaizi2@gnuweeb.org> <20220322102115.186179-4-ammarfaizi2@gnuweeb.org> <8653f6784a9b4272a59a75a530663567@AcuMS.aculab.com> <20220322121338.GD10306@1wt.eu> <22fd9709b3a64a548226741b682ca155@AcuMS.aculab.com> Content-Language: en-US Subject: Re: [RFC PATCH v2 3/8] tools/nolibc: i386: Implement syscall with 6 arguments In-Reply-To: <22fd9709b3a64a548226741b682ca155@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/22/22 8:37 PM, David Laight wrote: > dunno, 'asm' register variables are rather more horrid and > should probably only be used (for asm statements) when there aren't > suitable register constraints. > > (I'm sure there is a comment about that in the gcc docs.) ^ Hey David, yes you're right, that is very interesting... I hit a GCC bug when playing with syscall6() implementation here. Using register variables for all inputs for syscall6() causing GCC 11.2 stuck in an endless loop with 100% CPU usage. Reproducible with several versions of GCC. In GCC 6.3, the syscall6() implementation above yields ICE (Internal Compiler Error): ``` : In function '__sys_mmap': :35:1: error: unable to find a register to spill } ^ :35:1: error: this is the insn: (insn 14 13 30 2 (set (reg:SI 95 [92]) (mem/c:SI (plus:SI (reg/f:SI 16 argp) (const_int 28 [0x1c])) [1 offset+0 S4 A32])) :33 86 {*movsi_internal} (expr_list:REG_DEAD (reg:SI 16 argp) (nil))) :35: confused by earlier errors, bailing out Compiler returned: 1 ``` See the full show here: https://godbolt.org/z/dYeKaYWY3 Using the appropriate constraints, it compiles nicely, now it looks like this: ``` #define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ ({ \ long _eax = (long)(num); \ long _arg6 = (long)(arg6); /* Always be in memory */ \ asm volatile ( \ "pushl %[_arg6]\n\t" \ "pushl %%ebp\n\t" \ "movl 4(%%esp), %%ebp\n\t" \ "int $0x80\n\t" \ "popl %%ebp\n\t" \ "addl $4,%%esp\n\t" \ : "+a"(_eax) /* %eax */ \ : "b"(arg1), /* %ebx */ \ "c"(arg2), /* %ecx */ \ "d"(arg3), /* %edx */ \ "S"(arg4), /* %esi */ \ "D"(arg5), /* %edi */ \ [_arg6]"m"(_arg6) /* memory */ \ : "memory", "cc" \ ); \ _eax; \ }) ``` Link: https://godbolt.org/z/ozGbYWbPY Will use that in the next patchset version. -- Ammar Faizi