]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/syscall/mksyscall.pl
[dev.regabi] all: merge master (fca94ab) into dev.regabi
[gostls13.git] / src / syscall / mksyscall.pl
index 26c93ffe5b5ab290995651539f39e3dd69fb457e..c1ed3a35d97705be137057129000cc13aaadf3ae 100755 (executable)
@@ -30,6 +30,7 @@ my $openbsd = 0;
 my $netbsd = 0;
 my $dragonfly = 0;
 my $arm = 0; # 64-bit value should use (even, odd)-pair
+my $libc = 0;
 my $tags = "";  # build tags
 
 if($ARGV[0] eq "-b32") {
@@ -45,6 +46,7 @@ if($ARGV[0] eq "-plan9") {
 }
 if($ARGV[0] eq "-darwin") {
        $darwin = 1;
+       $libc = 1;
        shift;
 }
 if($ARGV[0] eq "-openbsd") {
@@ -63,6 +65,10 @@ if($ARGV[0] eq "-arm") {
        $arm = 1;
        shift;
 }
+if($ARGV[0] eq "-libc") {
+       $libc = 1;
+       shift;
+}
 if($ARGV[0] eq "-tags") {
        shift;
        $tags = $ARGV[0];
@@ -125,7 +131,7 @@ while(<>) {
        # without reading the header.
        $text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
 
-       if ($darwin && $func eq "ptrace1") {
+       if (($darwin || ($openbsd && $libc)) && $func eq "ptrace") {
                # The ptrace function is called from forkAndExecInChild where stack
                # growth is forbidden.
                $text .= "//go:nosplit\n"
@@ -176,7 +182,9 @@ while(<>) {
                        push @args, "uintptr(_p$n)", "uintptr(len($name))";
                        $n++;
                } elsif($type eq "int64" && ($openbsd || $netbsd)) {
-                       push @args, "0";
+                       if (!$libc) {
+                               push @args, "0";
+                       }
                        if($_32bit eq "big-endian") {
                                push @args, "uintptr($name>>32)", "uintptr($name)";
                        } elsif($_32bit eq "little-endian") {
@@ -220,7 +228,7 @@ while(<>) {
                        $asm = "RawSyscall";
                }
        }
-       if ($darwin) {
+       if ($libc) {
                # Call unexported syscall functions (which take
                # libc functions instead of syscall numbers).
                $asm = lcfirst($asm);
@@ -243,7 +251,7 @@ while(<>) {
                print STDERR "$ARGV:$.: too many arguments to system call\n";
        }
 
-       if ($darwin) {
+       if ($darwin || ($openbsd && $libc)) {
                # Use extended versions for calls that generate a 64-bit result.
                my ($name, $type) = parseparam($out[0]);
                if ($type eq "int64" || ($type eq "uintptr" && $_32bit eq "")) {
@@ -257,13 +265,13 @@ while(<>) {
                $sysname = "SYS_$func";
                $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar
                $sysname =~ y/a-z/A-Z/;
-               if($darwin) {
+               if($libc) {
                        $sysname =~ y/A-Z/a-z/;
                        $sysname = substr $sysname, 4;
                        $funcname = "libc_$sysname";
                }
        }
-       if($darwin) {
+       if($libc) {
                if($funcname eq "") {
                        $sysname = substr $sysname, 4;
                        $funcname = "libc_$sysname";
@@ -338,14 +346,18 @@ while(<>) {
        }
        $text .= "\treturn\n";
        $text .= "}\n\n";
-       if($darwin) {
+       if($libc) {
                if (not exists $trampolines{$funcname}) {
                        $trampolines{$funcname} = 1;
                        # The assembly trampoline that jumps to the libc routine.
                        $text .= "func ${funcname}_trampoline()\n";
                        # Tell the linker that funcname can be found in libSystem using varname without the libc_ prefix.
                        my $basename = substr $funcname, 5;
-                       $text .= "//go:cgo_import_dynamic $funcname $basename \"/usr/lib/libSystem.B.dylib\"\n\n";
+                       my $libc = "libc.so";
+                       if ($darwin) {
+                               $libc = "/usr/lib/libSystem.B.dylib";
+                       }
+                       $text .= "//go:cgo_import_dynamic $funcname $basename \"$libc\"\n\n";
                }
        }
 }