[RFC] Linux system call builtins

2024-04-10 Thread Matheus Afonso Martins Moreira via Gcc
> Yes, for regular function calls, > but at least in the case of NetBSD, > not for syscalls. Those are the registers Linux uses for system calls on MIPS. They are documented as such here: https://www.man7.org/linux/man-pages/man2/syscall.2.html > The second table shows the registers used > to pa

[RFC] Linux system call builtins

2024-04-10 Thread Matheus Afonso Martins Moreira via Gcc
> 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 l

Re: [RFC] Linux system call builtins

2024-04-10 Thread Paul Koning via Gcc
> On Apr 9, 2024, at 9:48 PM, Matheus Afonso Martins Moreira via Gcc > wrote: > > ... > MIPS calling conventions work like this: > >> mips/n32,64 a0 a1 a2 a3 a4 a5 >> mips/o32a0 a1 a2 a3 ... >> mips/o32args5-8 are passed on the stack Yes, for regular function calls, but at least in

Re: [RFC] Linux system call builtins

2024-04-10 Thread Szabolcs Nagy via Gcc
The 04/09/2024 23:59, Matheus Afonso Martins Moreira via Gcc wrote: > > and using raw syscalls outside of the single runtime the > > application is using is problematic (at least on linux). > > Why do you say they are problematic on Linux though? Please elaborate. because the portable c api layer

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> note: some syscalls / features don't work without asm > (posix thread cancellation, vfork, signal return,..) That's true. On the other hand, POSIX compliance is not always a goal or a requirement. > and using raw syscalls outside of the single runtime the > application is using is problematic (

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> I see systems making it more difficult for code to make syscalls, > not easier. That's true. I think it's because other systems can afford to keep that ABI unstable. Since Linux is an independently developed kernel, it _must_ be possible to target the kernel directly with no user space compone

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> Now the question comes is the argument long or some other type? I believe so. Every library I've seen and the kernel itself uses long. Other types just get typecasted to long. I think it's just supposed to mean "register type" since all the arguments must be in registers. > E.g. for some 32bit

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> 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 a

Re: [RFC] Linux system call builtins

2024-04-09 Thread Szabolcs Nagy via Gcc
The 04/08/2024 06:19, Matheus Afonso Martins Moreira via Gcc wrote: > __builtin_linux_system_call(long n, ...) ... > Calling these builtins will make GCC place all the parameters > in the correct registers for the system call, emit the appropriate > instruction for the target architecture and r

Re: [RFC] Linux system call builtins

2024-04-08 Thread Paul Floyd via Gcc
On 08-04-24 09:19, Matheus Afonso Martins Moreira via Gcc wrote: + It's becoming common Despite being specific to the Linux kernel, support for it is showing up in other systems. FreeBSD implements limited support[4] for Linux ABIs. Windows Subsystem fo

Re: [RFC] Linux system call builtins

2024-04-08 Thread Paul Koning via Gcc
> On Apr 8, 2024, at 4:01 PM, Paul Iannetta via Gcc wrote: > > On Mon, Apr 08, 2024 at 11:26:40AM -0700, Andrew Pinski wrote: >> On Mon, Apr 8, 2024 at 11:20 AM Paul Iannetta via Gcc >> wrote: >>> ... >> Also do you sign or zero extend a 32bit argument for LP64 targets? >> Right now it is no

Re: [RFC] Linux system call builtins

2024-04-08 Thread Paul Iannetta via Gcc
On Mon, Apr 08, 2024 at 11:26:40AM -0700, Andrew Pinski wrote: > On Mon, Apr 8, 2024 at 11:20 AM Paul Iannetta via Gcc wrote: > > > > Hi, > > > > On Mon, Apr 08, 2024 at 06:19:14AM -0300, Matheus Afonso Martins Moreira > > via Gcc wrote: > > > Hello! I'm a beginner when it comes to GCC developmen

Re: [RFC] Linux system call builtins

2024-04-08 Thread Andrew Pinski via Gcc
On Mon, Apr 8, 2024 at 11:20 AM Paul Iannetta via Gcc wrote: > > Hi, > > On Mon, Apr 08, 2024 at 06:19:14AM -0300, Matheus Afonso Martins Moreira via > Gcc wrote: > > Hello! I'm a beginner when it comes to GCC development. > > I want to learn how it works and start contributing. > > Decided to st

Re: [RFC] Linux system call builtins

2024-04-08 Thread Paul Iannetta via Gcc
Hi, On Mon, Apr 08, 2024 at 06:19:14AM -0300, Matheus Afonso Martins Moreira via Gcc wrote: > Hello! I'm a beginner when it comes to GCC development. > I want to learn how it works and start contributing. > Decided to start by implementing something relatively simple > but which would still be ve

Re: Re: [RFC] Linux system call builtins

2024-04-08 Thread Jonathan Wakely via Gcc
On Mon, 8 Apr 2024, 13:00 Matheus Afonso Martins Moreira via Gcc, < gcc@gcc.gnu.org> wrote: > > Compiler support for system calls help by eliminating the need for the > system call stub functions traditionally provided by these C libraries. > There's no need to link against the C libraries just fo

Re: Re: [RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
> 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 symbol

Re: [RFC] Linux system call builtins

2024-04-08 Thread Alexander Monakov
On Mon, 8 Apr 2024, Florian Weimer wrote: > * Alexander Monakov: > > >> There is quite a bit of variance in how the kernel is entered. On > >> x86-64, one once popular mechanism is longer present in widely-used > >> kernels. > > > > I assume you're implicitly referencing the vsyscall mechanism

Re: Re: [RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
> What's the advantage of the _1, _2 etc. forms? Now that you mention it... I don't believe there are any. > The compiler knows how many arguments you're passing, > why can't there just be one built-in handling all cases? You're right about that. When I started working on this I just mirrored t

Re: [RFC] Linux system call builtins

2024-04-08 Thread Florian Weimer via Gcc
* Alexander Monakov: > On Mon, 8 Apr 2024, Florian Weimer via Gcc wrote: > >> * Matheus Afonso Martins Moreira via Gcc: >> >> > + It's stable >> > >> > This is one of the things which makes Linux unique >> > in the operating system landscape: applications >> > can target

Re: [RFC] Linux system call builtins

2024-04-08 Thread Alexander Monakov
On Mon, 8 Apr 2024, Florian Weimer via Gcc wrote: > * Matheus Afonso Martins Moreira via Gcc: > > > + It's stable > > > > This is one of the things which makes Linux unique > > in the operating system landscape: applications > > can target the kernel directly. Unlike i

Re: [RFC] Linux system call builtins

2024-04-08 Thread Florian Weimer via Gcc
* Matheus Afonso Martins Moreira via Gcc: > + It's stable > > This is one of the things which makes Linux unique > in the operating system landscape: applications > can target the kernel directly. Unlike in virtually > every other operating system out there, the L

Re: [RFC] Linux system call builtins

2024-04-08 Thread Jonathan Wakely via Gcc
Hello, On Mon, 8 Apr 2024 at 10:20, Matheus Afonso Martins Moreira via Gcc wrote: > > I'd like to add GCC builtins for generating Linux system call > code for all architectures supported by Linux. > > They would look like this: > > __builtin_linux_system_call(long n, ...) > __builtin_linu

[RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
Hello! I'm a beginner when it comes to GCC development. I want to learn how it works and start contributing. Decided to start by implementing something relatively simple but which would still be very useful for me: Linux builtins. I sought help in the OFTC IRC channel and it was suggested that I di