davidgiven / ack

The Amsterdam Compiler Kit
http://tack.sf.net
Other
421 stars 60 forks source link

Undefined `_execve` for Unix module of Modula-2 #31

Closed dram closed 7 years ago

dram commented 7 years ago

When compiling following code:

MODULE test;

IMPORT Unix;

VAR
  r: INTEGER;
BEGIN
  r := Unix.execve (NIL, NIL, NIL);
END test.

ACK reports an error:

"test.mod", line 9: (warning) variable "r" never used
Undefined:
        _execve
dram commented 7 years ago

After adding a new file plat/linux/libsys/execve.c with following content, previous example can be compiled successfully:

#include <unistd.h>
#include "libsys.h"

int execve(const char *path, char *const argv[], char *const envp[])
{
        return _syscall(__NR_execve, (quad) path, (quad) argv, (quad) envp);
}

The signature is copy from Open Group Base Specifications. Not sure if it also needs to be added to plat/linux396/include/unistd.h and plat/linuxppc/include/unistd.h.

BTW, I'm curious and can not figure out the relation between plat and mach directory, as I also find file i386/libsys/execve.s in mach.

dram commented 7 years ago

I kind of think that declaration is needed for unistd.h, which is needed for C code when using this function.

Create a PR #32 for this system call.

davidgiven commented 7 years ago

PR merged. Thanks!

kernigh commented 7 years ago

The files in mach/i386/libsys were for some old system, perhaps Xenix. (A comment in mach/i386/cv/cv.c mentions "XENIX386".) We can't use them with Linux. Now the plat/ directory has libsys and boot.s for our current platforms, while mach/ has assemblers and code generators. But mach/ also has artifacts like old libsys.

Linux has many system calls, and our libsys still doesn't provide most of them.