public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
To: gcc@gcc.gnu.org
Subject: Re: Re: [RFC] Linux system call builtins
Date: Mon, 08 Apr 2024 10:37:27 -0300	[thread overview]
Message-ID: <1742c098fd77d159c0834838ee71f283@gmail.com> (raw)
In-Reply-To: <87plv0w10k.fsf@oldenburg.str.redhat.com>

> There is quite a bit of variance in how the kernel is entered.

I assume you mean the vDSO. It is also documented and stable.

https://www.kernel.org/doc/html/latest/admin-guide/abi-stable.html#vdso

> Unless otherwise noted, the set of symbols with any given version
> and the ABI of those symbols is considered stable.
> It may vary across architectures, though.

> As of this writing, this ABI documentation as been confirmed
> for x86_64. The maintainers of the other vDSO-using architectures
> should confirm that it is correct for their architecture.

It is an also entirely optional. The architecture specific system call
entry point is always available. The vDSO exists to provide much more
efficient ways to access frequently queried system information such
as the current time. While the optimized approaches are preferable,
the slower system call entry points are still available and stable.

> On x86-64, one once popular mechanism
> is longer present in widely-used kernels.

Please elaborate. Do you mean the vDSO?

Linux places a pointer to the vDSO in the auxiliary vector,
and a pointer to that vector is located immediately after
the program's environment. The program will have to walk that
vector in order to find the vDSO. If the vDSO is missing,
then the program will fail to find that pointer and hopefully
fall back to traditional system call entry points.

Perhaps GCC could also have builtins for accessing things like
argc, argv, envp and auxvec. They are part of the ABI too.
This would allow programs to access the vDSO via the auxvec.
It'd also allow implementation of ELF entry points entirely in C.

> But using a builtin obfuscates that relationship.
> There is no __builtin_call_ms_abi, is there?

That's true but that's because there's no need for those builtins.
Functions which conform to specific ABIs will have been marked with
the relevant attribute so GCC will know how what to do when it is called.
Linux system calls do not actually exist as functions so they can't be
marked that way.

It could be implemented that way by having a naked system call
function whose entire body is just the syscall instruction.
Then it could be marked with a linux_syscall_abi attribute
and the compiler would know to where to put the arguments
and from where to obtain the return value.

That just replicates what the builtin is supposed to do though.
The builtin would not need any declarations or attributes.
It would just work.

  parent reply	other threads:[~2024-04-08 13:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  9:19 Matheus Afonso Martins Moreira
2024-04-08  9:58 ` Jonathan Wakely
2024-04-08 11:59   ` Matheus Afonso Martins Moreira
2024-04-08 14:00     ` Jonathan Wakely
2024-04-08 11:24 ` Florian Weimer
2024-04-08 11:44   ` Alexander Monakov
2024-04-08 11:50     ` Florian Weimer
2024-04-08 13:01       ` Alexander Monakov
2024-04-08 13:37   ` Matheus Afonso Martins Moreira [this message]
2024-04-08 18:18 ` Paul Iannetta
2024-04-08 18:26   ` Andrew Pinski
2024-04-08 20:01     ` Paul Iannetta
2024-04-08 20:20       ` Paul Koning
2024-04-10  1:48     ` Matheus Afonso Martins Moreira
2024-04-10 13:15       ` Paul Koning
2024-04-10 14:10         ` Matheus Afonso Martins Moreira
2024-04-10  1:26   ` Matheus Afonso Martins Moreira
2024-04-08 20:24 ` Paul Floyd
2024-04-10  2:19   ` Matheus Afonso Martins Moreira
2024-04-09 11:45 ` Szabolcs Nagy
2024-04-10  2:59   ` Matheus Afonso Martins Moreira
2024-04-10 11:04     ` Szabolcs Nagy
2024-04-10 14:00       ` Matheus Afonso Martins Moreira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1742c098fd77d159c0834838ee71f283@gmail.com \
    --to=matheus.a.m.moreira@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).