From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 59433385828E for ; Wed, 10 Apr 2024 01:26:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59433385828E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59433385828E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712712412; cv=none; b=pImNK+9/FfdrOI/0332ECrFLlEIORF90B31WnL6ss2Y/l3qehyGFnjbZd8ULlzXHrmS8By/1+QCJC1lwma+6kJ7T5ucLhNQNID1Su2y0xN7dqRblePHQpvNOC7Zf7TG7p4hQTlbsAVXoKThZh/Ly1Hhe6sJLm+HVlE6WwcMPZmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712712412; c=relaxed/simple; bh=Pwa+nRrIMkpAOi1nw8OKuZuWIqSEjuL7tX1DR5gLZUw=; h=DKIM-Signature:Date:Message-ID:From:To:Subject; b=EHvo5muR18yx4Nmb5GsfkYRg6sFAt135SHKpuJrA06AoObItqq1+LHby7KYi4NS03Wt4umc6EvGUgdaxNw/0uAQxTFM2hQzvF+pg0pttocp22/tLpsRh6tNqyOwPIAG+zuKh4XNFCP43gs866Pmoo9f8uCFdNrolf8aDv/dZjv8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ece8991654so5617122b3a.3 for ; Tue, 09 Apr 2024 18:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712712409; x=1713317209; darn=gcc.gnu.org; h=in-reply-to:subject:to:from:message-id:date:from:to:cc:subject:date :message-id:reply-to; bh=0jjqnYT8zSEWm3YGVxLANCkN0l6e+tjp58oc2dTy2HQ=; b=VeeinJSDRaQgrp82u2GqHyMTtsEooecFYMVx4exTacFpnHudAKz+7tBMTjkJS1rbD7 GubZdH9YvzNyGDddqIMpOX8O5xNQlCP8GdGI/arS0fm6EwTOwfeFrW+16GybQ+InKfX1 96l6Dbs6QdztmTUAo74IrImsfRTDWwE/3n77ZPUl0YPLPmZU0sYeB5ezYoRjNsqLqa27 q4O883k19IHomJWdeiNjDKkObHFcZvr6Tsf4SD0VY/I95YP9He19GlWFm8MEWz4F9ecj 86MXVzEiVrloPRtNdrcPqZ7Cz/xqkS6cJ7AlVeFWwosY3J1f7/0bxSoYbHRfOy7MG4kS FL+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712712409; x=1713317209; h=in-reply-to:subject:to:from:message-id:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0jjqnYT8zSEWm3YGVxLANCkN0l6e+tjp58oc2dTy2HQ=; b=JDii+Nlo7je9DgcyPMB2trUPj+Dq+KVjauIndmMcGlGOYzNFHozB6xx/SeDi35DmOj U4v11gBBUzV/T3tLyHfT8zyFvBnbUh4MB+9KLey2HvKwQ4P/FOrQGUhAh5Rq5cu9AxoQ mIf9r+5jUgZCN4FGKxujMY/7Ou5qv7IwzT/Qy7I2hvI47HZu7cSDOhyhaZzQNXAmPRxb uHkVCttKkRrwbIKH1W6iz8GKibHO1z0w0jgpumA2uvhmGXSqQXqX0SiLgzHTF7zmJkP2 kBa7sfcSGF27utXzDguoBBTonqhwJQx0HGscP01hFlJJiLS8mluKD2lVWQFkuJTlzTcM XCBw== X-Gm-Message-State: AOJu0YzMsJ6/6noAjlYsbxTJuKhOgYAyPE9k++6RV2g/FlxomgTrEcCo vNTWufqjUuno/Bn+Z/QFXEzOwX8FauNe/KlE9v1igf9GugdrEzfEQGZfvhee X-Google-Smtp-Source: AGHT+IEox0ud+C2Q5xyy0gwW2RkEJflyrSZYyAcNqi+NLR29Cg0+GcpUBosa2HdoWMKQGcpMSBoGgQ== X-Received: by 2002:a05:6a21:151b:b0:1a7:aa08:4b6c with SMTP id nq27-20020a056a21151b00b001a7aa084b6cmr1841600pzb.17.1712712408603; Tue, 09 Apr 2024 18:26:48 -0700 (PDT) Received: from localhost ([138.117.155.58]) by smtp.gmail.com with ESMTPSA id j1-20020a17090a734100b002a2b06cbe46sm271181pjs.22.2024.04.09.18.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 18:26:48 -0700 (PDT) Date: Tue, 09 Apr 2024 22:26:49 -0300 Message-ID: From: Matheus Afonso Martins Moreira To: gcc@gcc.gnu.org Subject: [RFC] Linux system call builtins In-Reply-To: <20240408181831.pizpq7n7k4n5u6dh@ws2202.lin.mbt.kalray.eu> X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > As noted by J. Wakely, you don't need to have one variant > for each number of arguments. Yes, he is right about that. I have already deleted all the variants from my code since the variadic builtin will be able to generate optimal code, unlike a variadic C function. > I assume you're talking about the interface > which is often abstracted by functions such as > the following which are often found in libcs or > freestanding libraries. > long linux_system_call_1(long number, long _1) Yes, that's exactly what I have in mind. My goal is to implement those functions inside the compiler itself as builtins. > I think that at least on sysv x86_64, syscalls have > the same calling conventions as regular functions. However, the function descriptor is not an address (or a symbol reference) but a number. They are similar but not equal. x86_64 function calling convention passes the first 6 arguments in the following registers: rdi, rsi, rdx, rcx, r8, r9. x86_64 system call calling convention passes only 6 arguments in the following registers: rdi, rsi, rdx, r10, r8, r9. System calls use r10 instead of rcx and don't support more than 6 arguments. > At least, it would be nice if not all freestanding libraries had to reimplement those syscalls stubs. Completely agree! > I think you could have a look at the function 'expand_call' > in calls.cc to see how regular calls are expanded to RTL Thanks for the pointer!! I had been looking in the gcc/config/ directory for platform specific code that implemented calling conventions. Somehow that calls.cc file slipped past my attention. My thinking is that I need to have the compiler evaluate the input expressions and place the results in specific registers, while also ensuring all the input expressions are register sized and emitting type errors in case they are not. I looked for some kind of "register" type but didn't find anything. So I used long int, just like the libraries do. Thanks, Matheus