From: Nikhil Benesch Date: Sun, 18 Oct 2020 19:28:54 +0000 (+0000) Subject: syscall: only compile ptrace varargs shim on Linux X-Git-Tag: basepoints/gcc-12~4050 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=439407aa2c678a96bd5b430ab9c335e65beb5751;p=thirdparty%2Fgcc.git syscall: only compile ptrace varargs shim on Linux Only compile the __go_ptrace varargs shim on Linux to avoid compilation failures on some other platforms. The C ptrace function is not entirely portable (e.g., NetBSD has `int data` instead of `void* data`), and so far Linux is the only platform that needs the varargs shim. Additionally, make the types in the ptrace and raw_ptrace function declarations match. This makes it more clear that the only difference between the two is that calls via the former are allowed to block while calls via the latter are not. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/263517 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index aedaf4664d55..384ca6e88647 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -64c25b2365f7125a32b3146618b627f26a78c1fc +fa66bd11bbe58943e273cfa74356771c996f5b24 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/syscall/exec_bsd.go b/libgo/go/syscall/exec_bsd.go index 7e06943f13ec..ca7fdc0825e7 100644 --- a/libgo/go/syscall/exec_bsd.go +++ b/libgo/go/syscall/exec_bsd.go @@ -93,7 +93,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Enable tracing if requested. if sys.Ptrace { - err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil) + err1 = raw_ptrace(_PTRACE_TRACEME, 0, 0, 0) if err1 != 0 { goto childerror } diff --git a/libgo/go/syscall/exec_linux.go b/libgo/go/syscall/exec_linux.go index 2f0a34fef0b7..389758104329 100644 --- a/libgo/go/syscall/exec_linux.go +++ b/libgo/go/syscall/exec_linux.go @@ -538,7 +538,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att // Do this right before exec so that we don't unnecessarily trace the runtime // setting up after the fork. See issue #21428. if sys.Ptrace { - err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil) + err1 = raw_ptrace(_PTRACE_TRACEME, 0, 0, 0) if err1 != 0 { goto childerror } diff --git a/libgo/go/syscall/exec_stubs.go b/libgo/go/syscall/exec_stubs.go index e95b4158e1a0..c837cf7a4e2f 100644 --- a/libgo/go/syscall/exec_stubs.go +++ b/libgo/go/syscall/exec_stubs.go @@ -30,6 +30,6 @@ func (w WaitStatus) Signal() int { return 0 } func (w WaitStatus) StopSignal() int { return 0 } func (w WaitStatus) TrapCause() int { return 0 } -func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno { +func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno { return ENOSYS } diff --git a/libgo/go/syscall/libcall_aix.go b/libgo/go/syscall/libcall_aix.go index 27b469e1e477..92c7f3cc2323 100644 --- a/libgo/go/syscall/libcall_aix.go +++ b/libgo/go/syscall/libcall_aix.go @@ -19,7 +19,7 @@ const SYS_EXECVE = 0 //sys ptrace64(request int, id int64, addr int64, data int, buff uintptr) (err error) //ptrace64(request _C_int, id int64, addr int64, data _C_int, buff *byte) _C_int -func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno { +func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno { if request == _PTRACE_TRACEME { // Convert to AIX ptrace call. err := ptrace64(_PT_TRACE_ME, 0, 0, 0, 0) diff --git a/libgo/go/syscall/libcall_glibc.go b/libgo/go/syscall/libcall_glibc.go index 823343d5075a..a32d6968f24f 100644 --- a/libgo/go/syscall/libcall_glibc.go +++ b/libgo/go/syscall/libcall_glibc.go @@ -31,9 +31,6 @@ func Futimes(fd int, tv []Timeval) (err error) { return Utimes("/proc/self/fd/"+itoa(fd), tv) } -//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error) -//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long - //sys accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd int, err error) //accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int diff --git a/libgo/go/syscall/libcall_hurd.go b/libgo/go/syscall/libcall_hurd.go index f0e038ca616c..44ff46d1016e 100644 --- a/libgo/go/syscall/libcall_hurd.go +++ b/libgo/go/syscall/libcall_hurd.go @@ -7,7 +7,7 @@ package syscall // Dummy function -func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno { +func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno { return ENOSYS } diff --git a/libgo/go/syscall/libcall_irix.go b/libgo/go/syscall/libcall_irix.go index 9b6cdcca2c81..98807668d527 100644 --- a/libgo/go/syscall/libcall_irix.go +++ b/libgo/go/syscall/libcall_irix.go @@ -6,5 +6,5 @@ package syscall -//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno) +//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno) //ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long diff --git a/libgo/go/syscall/libcall_linux.go b/libgo/go/syscall/libcall_linux.go index 78fda0ea7ef1..96974bd3269a 100644 --- a/libgo/go/syscall/libcall_linux.go +++ b/libgo/go/syscall/libcall_linux.go @@ -10,7 +10,10 @@ import ( "unsafe" ) -//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno) +//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno) +//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long + +//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno) //__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err error) { diff --git a/libgo/go/syscall/libcall_solaris_386.go b/libgo/go/syscall/libcall_solaris_386.go index 20eba22a302d..ef86f09711d1 100644 --- a/libgo/go/syscall/libcall_solaris_386.go +++ b/libgo/go/syscall/libcall_solaris_386.go @@ -8,5 +8,5 @@ package syscall //sysnb Uname(buf *Utsname) (err error) //_nuname(buf *Utsname) _C_int -//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno) +//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno) //ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long diff --git a/libgo/go/syscall/libcall_solaris_amd64.go b/libgo/go/syscall/libcall_solaris_amd64.go index 69b11ba5ee64..f44025e1eec7 100644 --- a/libgo/go/syscall/libcall_solaris_amd64.go +++ b/libgo/go/syscall/libcall_solaris_amd64.go @@ -5,6 +5,6 @@ package syscall // 64-bit ptrace(3C) doesn't exist -func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno { +func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno { return ENOSYS } diff --git a/libgo/go/syscall/libcall_solaris_sparc.go b/libgo/go/syscall/libcall_solaris_sparc.go index 50863fadf180..3d50309983f1 100644 --- a/libgo/go/syscall/libcall_solaris_sparc.go +++ b/libgo/go/syscall/libcall_solaris_sparc.go @@ -4,5 +4,5 @@ package syscall -//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno) +//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno) //ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long diff --git a/libgo/go/syscall/libcall_solaris_sparc64.go b/libgo/go/syscall/libcall_solaris_sparc64.go index 69b11ba5ee64..f44025e1eec7 100644 --- a/libgo/go/syscall/libcall_solaris_sparc64.go +++ b/libgo/go/syscall/libcall_solaris_sparc64.go @@ -5,6 +5,6 @@ package syscall // 64-bit ptrace(3C) doesn't exist -func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno { +func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno { return ENOSYS } diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c index d8f7dc55ea41..f84860891e6c 100644 --- a/libgo/runtime/go-varargs.c +++ b/libgo/runtime/go-varargs.c @@ -114,12 +114,11 @@ __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, uintptr_t a3, #endif -// AIX ptrace is really different from Linux ptrace. Let syscall -// package handles it. -#if defined(HAVE_SYS_PTRACE_H) && !defined(_AIX) + +#if defined(HAVE_SYS_PTRACE_H) && defined(__linux__) // Despite documented appearances, this is actually implemented as -// a variadic function within glibc. +// a variadic function within glibc on Linux. long __go_ptrace(int request, pid_t pid, void *addr, void *data)