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: [RFC] Linux system call builtins
Date: Wed, 10 Apr 2024 11:00:39 -0300	[thread overview]
Message-ID: <21fc28d2e993de0bb5e01bacdedf9289@gmail.com> (raw)
In-Reply-To: <ZhZyM97uHvqpc5v6@arm.com>

> because the portable c api layer and syscall abi layer
> has a large enough gap that applications can break
> libc internals by doing raw syscalls.

I think that problem cannot really be fixed.
System call users just have to be aware of it.

It's true that using certain system calls can clobber libc state.
However, it should be up to the programmer to decide whether or not
that's acceptable. The compiler should empower them regardless.

> and it's not just the call convention that's target
> specific (this makes the c syscall() function hard to
> use on linux)

Yes. On Linux, the ABIs are stable and the set of system calls
is only ever added to. However, this property does not hold
across different architectures. Some targets have several numbered
variants of a system call while others only have the latest version.
It's true that this is a source of complexity for system call users.

> and linux evolves fast enough that raw syscalls have
> to be adjusted over time (to support new features)
> which is harder when they are all over the place
> instead of in the libc only.

When those adjustments are done, they avoid breaking existing programs.
New versions of the system calls are created, old ones are maintained.
Existing binaries continue to work. Even statically linked binaries.
It's true that it's harder to update binaries all at once
when they are statically linked but Linux still supports them.

> that does not make it right.

I don't agree with that. I don't think the libc should be required
or that the system calls should be a privilege of the libc.
The libc should be entirely optional.

In the issue I linked you also noticed that the Linux manuals
frequently mix up the kernel perspective with that of the libc,
and that of glibc in particular.

> unfortunately the linux manuals mix the system call
> (linux behaviour) and libc api (glibc behaviour)
> in the same man page in general, and mainly focus
> on the linux behaviour, not on the c api semantics.

That's also something I intend to work on.

> so your proposal does not fix this particular issue,
> just provide a simpler footgun.

This issue cannot really be fixed. I believe the only solution to that
would be to impose a libc on all of Linux user space. I think that goes
against the spirit of Linux as a kernel that's completely independent
of its userspace.

The footgun already exists in inline assembly form regardless.

      reply	other threads:[~2024-04-10 14:00 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
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 [this message]

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=21fc28d2e993de0bb5e01bacdedf9289@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).