public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Harmonize types referenced by both C and Go
@ 2019-02-15  1:58 Ian Lance Taylor
  2019-02-15  8:16 ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2019-02-15  1:58 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 599 bytes --]

This patch to the Go frontend and libgo by Nikhil Benesch harmonizes
types referenced by both C and Go.  Compiling with LTO revealed a
number of cases in the runtime and standard library where C and Go
disagreed about the type of an object or function (or where Go and
code generated by the compiler disagreed).  In all cases the
underlying representation was the same (e.g., uintptr vs.void*), so
this wasn't causing actual problems, but it did result in a number of
annoying warnings when compiling with LTO.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 22725 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268922)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-4a6f2bb2c8d3f00966f001a5b03c57cb4a278265
+03e28273a4fcb114f5204d52ed107591404002f4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc	(revision 268891)
+++ gcc/go/gofrontend/expressions.cc	(working copy)
@@ -1344,7 +1344,7 @@ Func_descriptor_expression::make_func_de
   if (Func_descriptor_expression::descriptor_type != NULL)
     return;
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
-  Type* struct_type = Type::make_builtin_struct_type(1, "code", uintptr_type);
+  Type* struct_type = Type::make_builtin_struct_type(1, "fn", uintptr_type);
   Func_descriptor_expression::descriptor_type =
     Type::make_builtin_named_type("functionDescriptor", struct_type);
 }
@@ -3874,7 +3874,9 @@ Unsafe_type_conversion_expression::do_ge
 	      || et->integer_type() != NULL
               || et->is_nil_type());
   else if (et->is_unsafe_pointer_type())
-    go_assert(t->points_to() != NULL);
+    go_assert(t->points_to() != NULL
+	      || (t->integer_type() != NULL
+		  && t->integer_type() == Type::lookup_integer_type("uintptr")->real_type()));
   else if (t->interface_type() != NULL)
     {
       bool empty_iface = t->interface_type()->is_empty();
Index: gcc/go/gofrontend/gogo.cc
===================================================================
--- gcc/go/gofrontend/gogo.cc	(revision 268891)
+++ gcc/go/gofrontend/gogo.cc	(working copy)
@@ -4513,13 +4513,13 @@ Build_recover_thunks::can_recover_arg(Lo
     builtin_return_address =
       Gogo::declare_builtin_rf_address("__builtin_return_address");
 
+  Type* uintptr_type = Type::lookup_integer_type("uintptr");
   static Named_object* can_recover;
   if (can_recover == NULL)
     {
       const Location bloc = Linemap::predeclared_location();
       Typed_identifier_list* param_types = new Typed_identifier_list();
-      Type* voidptr_type = Type::make_pointer_type(Type::make_void_type());
-      param_types->push_back(Typed_identifier("a", voidptr_type, bloc));
+      param_types->push_back(Typed_identifier("a", uintptr_type, bloc));
       Type* boolean_type = Type::lookup_bool_type();
       Typed_identifier_list* results = new Typed_identifier_list();
       results->push_back(Typed_identifier("", boolean_type, bloc));
@@ -4539,6 +4539,7 @@ Build_recover_thunks::can_recover_arg(Lo
   args->push_back(zexpr);
 
   Expression* call = Expression::make_call(fn, args, false, location);
+  call = Expression::make_unsafe_cast(uintptr_type, call, location);
 
   args = new Expression_list();
   args->push_back(call);
Index: gcc/go/gofrontend/runtime.cc
===================================================================
--- gcc/go/gofrontend/runtime.cc	(revision 268369)
+++ gcc/go/gofrontend/runtime.cc	(working copy)
@@ -60,8 +60,6 @@ enum Runtime_function_type
   RFT_IFACE,
   // Go type interface{}, C type struct __go_empty_interface.
   RFT_EFACE,
-  // Go type func(unsafe.Pointer), C type void (*) (void *).
-  RFT_FUNC_PTR,
   // Pointer to Go type descriptor.
   RFT_TYPE,
   // [2]string.
@@ -176,15 +174,6 @@ runtime_function_type(Runtime_function_t
 	  t = Type::make_empty_interface_type(bloc);
 	  break;
 
-	case RFT_FUNC_PTR:
-	  {
-	    Typed_identifier_list* param_types = new Typed_identifier_list();
-	    Type* ptrtype = runtime_function_type(RFT_POINTER);
-	    param_types->push_back(Typed_identifier("", ptrtype, bloc));
-	    t = Type::make_function_type(NULL, param_types, NULL, bloc);
-	  }
-	  break;
-
 	case RFT_TYPE:
 	  t = Type::make_type_descriptor_ptr_type();
 	  break;
@@ -265,7 +254,6 @@ convert_to_runtime_function_type(Runtime
     case RFT_COMPLEX128:
     case RFT_STRING:
     case RFT_POINTER:
-    case RFT_FUNC_PTR:
       {
 	Type* t = runtime_function_type(bft);
 	if (!Type::are_identical(t, e->type(), true, NULL))
Index: gcc/go/gofrontend/runtime.def
===================================================================
--- gcc/go/gofrontend/runtime.def	(revision 268369)
+++ gcc/go/gofrontend/runtime.def	(working copy)
@@ -168,10 +168,10 @@ DEF_GO_RUNTIME(GORECOVER, "runtime.gorec
 DEF_GO_RUNTIME(DEFERREDRECOVER, "runtime.deferredrecover", P0(), R1(EFACE))
 
 // Decide whether this function can call recover.
-DEF_GO_RUNTIME(CANRECOVER, "runtime.canrecover", P1(POINTER), R1(BOOL))
+DEF_GO_RUNTIME(CANRECOVER, "runtime.canrecover", P1(UINTPTR), R1(BOOL))
 
 // Set the return address for defer in a defer thunk.
-DEF_GO_RUNTIME(SETDEFERRETADDR, "runtime.setdeferretaddr", P1(POINTER),
+DEF_GO_RUNTIME(SETDEFERRETADDR, "runtime.setdeferretaddr", P1(UINTPTR),
 	       R1(BOOL))
 
 // Check for a deferred function in an exception handler.
@@ -213,10 +213,10 @@ DEF_GO_RUNTIME(REGISTER_GC_ROOTS, "runti
 DEF_GO_RUNTIME(NEW, "runtime.newobject", P1(TYPE), R1(POINTER))
 
 // Start a new goroutine.
-DEF_GO_RUNTIME(GO, "__go_go", P2(FUNC_PTR, POINTER), R0())
+DEF_GO_RUNTIME(GO, "__go_go", P2(UINTPTR, POINTER), R1(POINTER))
 
 // Defer a function.
-DEF_GO_RUNTIME(DEFERPROC, "runtime.deferproc", P3(BOOLPTR, FUNC_PTR, POINTER),
+DEF_GO_RUNTIME(DEFERPROC, "runtime.deferproc", P3(BOOLPTR, UINTPTR, POINTER),
 	       R0())
 
 
@@ -303,7 +303,7 @@ DEF_GO_RUNTIME(IFACEEFACEEQ, "runtime.if
 
 // Set *dst = src where dst is a pointer to a pointer and src is a pointer.
 DEF_GO_RUNTIME(GCWRITEBARRIER, "runtime.gcWriteBarrier",
-	       P2(POINTER, POINTER), R0())
+	       P2(POINTER, UINTPTR), R0())
 
 // Set *dst = *src for an arbitrary type.
 DEF_GO_RUNTIME(TYPEDMEMMOVE, "runtime.typedmemmove",
Index: gcc/go/gofrontend/wb.cc
===================================================================
--- gcc/go/gofrontend/wb.cc	(revision 268369)
+++ gcc/go/gofrontend/wb.cc	(working copy)
@@ -664,11 +664,19 @@ Gogo::write_barrier_variable()
     {
       Location bloc = Linemap::predeclared_location();
 
-      // We pretend that writeBarrier is a uint32, so that we do a
-      // 32-bit load.  That is what the gc toolchain does.
-      Type* uint32_type = Type::lookup_integer_type("uint32");
-      Variable* var = new Variable(uint32_type, NULL, true, false, false,
-				   bloc);
+      Type* bool_type = Type::lookup_bool_type();
+      Array_type* pad_type = Type::make_array_type(this->lookup_global("byte")->type_value(),
+						   Expression::make_integer_ul(3, NULL, bloc));
+      Type* uint64_type = Type::lookup_integer_type("uint64");
+      Type* wb_type = Type::make_builtin_struct_type(5,
+						     "enabled", bool_type,
+						     "pad", pad_type,
+						     "needed", bool_type,
+						     "cgo", bool_type,
+						     "alignme", uint64_type);
+
+      Variable* var = new Variable(wb_type, NULL,
+				    true, false, false, bloc);
 
       bool add_to_globals;
       Package* package = this->add_imported_package("runtime", "_", false,
@@ -850,8 +858,12 @@ Gogo::assign_with_write_barrier(Function
     case Type::TYPE_FUNCTION:
     case Type::TYPE_MAP:
     case Type::TYPE_CHANNEL:
-      // These types are all represented by a single pointer.
-      call = Runtime::make_call(Runtime::GCWRITEBARRIER, loc, 2, lhs, rhs);
+      {
+	// These types are all represented by a single pointer.
+	Type* uintptr_type = Type::lookup_integer_type("uintptr");
+	rhs = Expression::make_unsafe_cast(uintptr_type, rhs, loc);
+	call = Runtime::make_call(Runtime::GCWRITEBARRIER, loc, 2, lhs, rhs);
+      }
       break;
 
     case Type::TYPE_STRING:
@@ -882,7 +894,17 @@ Gogo::check_write_barrier(Block* enclosi
 {
   Location loc = without->location();
   Named_object* wb = this->write_barrier_variable();
+  // We pretend that writeBarrier is a uint32, so that we do a
+  // 32-bit load.  That is what the gc toolchain does.
+  Type* void_type = Type::make_void_type();
+  Type* unsafe_pointer_type = Type::make_pointer_type(void_type);
+  Type* uint32_type = Type::lookup_integer_type("uint32");
+  Type* puint32_type = Type::make_pointer_type(uint32_type);
   Expression* ref = Expression::make_var_reference(wb, loc);
+  ref = Expression::make_unary(OPERATOR_AND, ref, loc);
+  ref = Expression::make_cast(unsafe_pointer_type, ref, loc);
+  ref = Expression::make_cast(puint32_type, ref, loc);
+  ref = Expression::make_unary(OPERATOR_MULT, ref, loc);
   Expression* zero = Expression::make_integer_ul(0, ref->type(), loc);
   Expression* cond = Expression::make_binary(OPERATOR_EQEQ, ref, zero, loc);
 
Index: libgo/go/runtime/mgc.go
===================================================================
--- libgo/go/runtime/mgc.go	(revision 268369)
+++ libgo/go/runtime/mgc.go	(working copy)
@@ -238,7 +238,7 @@ func setGCPercent(in int32) (out int32)
 var gcphase uint32
 
 // The compiler knows about this variable.
-// If you change it, you must change builtin/runtime.go, too.
+// If you change it, you must change gofrontend/wb.cc, too.
 // If you change the first four bytes, you must also change the write
 // barrier insertion code.
 var writeBarrier struct {
Index: libgo/go/runtime/netpoll.go
===================================================================
--- libgo/go/runtime/netpoll.go	(revision 268465)
+++ libgo/go/runtime/netpoll.go	(working copy)
@@ -112,7 +112,7 @@ func poll_runtime_isPollServerDescriptor
 }
 
 //go:linkname poll_runtime_pollOpen internal..z2fpoll.runtime_pollOpen
-func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
+func poll_runtime_pollOpen(fd uintptr) (uintptr, int) {
 	pd := pollcache.alloc()
 	lock(&pd.lock)
 	if pd.wg != 0 && pd.wg != pdReady {
@@ -133,11 +133,12 @@ func poll_runtime_pollOpen(fd uintptr) (
 
 	var errno int32
 	errno = netpollopen(fd, pd)
-	return pd, int(errno)
+	return uintptr(unsafe.Pointer(pd)), int(errno)
 }
 
 //go:linkname poll_runtime_pollClose internal..z2fpoll.runtime_pollClose
-func poll_runtime_pollClose(pd *pollDesc) {
+func poll_runtime_pollClose(ctx uintptr) {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	if !pd.closing {
 		throw("runtime: close polldesc w/o unblock")
 	}
@@ -159,7 +160,8 @@ func (c *pollCache) free(pd *pollDesc) {
 }
 
 //go:linkname poll_runtime_pollReset internal..z2fpoll.runtime_pollReset
-func poll_runtime_pollReset(pd *pollDesc, mode int) int {
+func poll_runtime_pollReset(ctx uintptr, mode int) int {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	err := netpollcheckerr(pd, int32(mode))
 	if err != 0 {
 		return err
@@ -173,7 +175,8 @@ func poll_runtime_pollReset(pd *pollDesc
 }
 
 //go:linkname poll_runtime_pollWait internal..z2fpoll.runtime_pollWait
-func poll_runtime_pollWait(pd *pollDesc, mode int) int {
+func poll_runtime_pollWait(ctx uintptr, mode int) int {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	err := netpollcheckerr(pd, int32(mode))
 	if err != 0 {
 		return err
@@ -195,7 +198,8 @@ func poll_runtime_pollWait(pd *pollDesc,
 }
 
 //go:linkname poll_runtime_pollWaitCanceled internal..z2fpoll.runtime_pollWaitCanceled
-func poll_runtime_pollWaitCanceled(pd *pollDesc, mode int) {
+func poll_runtime_pollWaitCanceled(ctx uintptr, mode int) {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	// This function is used only on windows after a failed attempt to cancel
 	// a pending async IO operation. Wait for ioready, ignore closing or timeouts.
 	for !netpollblock(pd, int32(mode), true) {
@@ -203,7 +207,8 @@ func poll_runtime_pollWaitCanceled(pd *p
 }
 
 //go:linkname poll_runtime_pollSetDeadline internal..z2fpoll.runtime_pollSetDeadline
-func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
+func poll_runtime_pollSetDeadline(ctx uintptr, d int64, mode int) {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	lock(&pd.lock)
 	if pd.closing {
 		unlock(&pd.lock)
@@ -288,7 +293,8 @@ func poll_runtime_pollSetDeadline(pd *po
 }
 
 //go:linkname poll_runtime_pollUnblock internal..z2fpoll.runtime_pollUnblock
-func poll_runtime_pollUnblock(pd *pollDesc) {
+func poll_runtime_pollUnblock(ctx uintptr) {
+	pd := (*pollDesc)(unsafe.Pointer(ctx))
 	lock(&pd.lock)
 	if pd.closing {
 		throw("runtime: unblock on closing polldesc")
Index: libgo/go/runtime/proc.go
===================================================================
--- libgo/go/runtime/proc.go	(revision 268369)
+++ libgo/go/runtime/proc.go	(working copy)
@@ -153,7 +153,7 @@ var runtimeInitTime int64
 var initSigmask sigset
 
 // The main goroutine.
-func main() {
+func main(unsafe.Pointer) {
 	g := getg()
 
 	// Max stack size is 1 GB on 64-bit, 250 MB on 32-bit.
Index: libgo/go/runtime/stubs.go
===================================================================
--- libgo/go/runtime/stubs.go	(revision 268369)
+++ libgo/go/runtime/stubs.go	(working copy)
@@ -283,8 +283,7 @@ func eqstring(x, y string) bool {
 // For gccgo this is in the C code.
 func osyield()
 
-// For gccgo this can be called directly.
-//extern syscall
+//extern __go_syscall6
 func syscall(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) uintptr
 
 // For gccgo, to communicate from the C code to the Go code.
Index: libgo/go/syscall/syscall_unix.go
===================================================================
--- libgo/go/syscall/syscall_unix.go	(revision 268459)
+++ libgo/go/syscall/syscall_unix.go	(working copy)
@@ -19,11 +19,8 @@ var (
 	Stderr = 2
 )
 
-//extern syscall
-func c_syscall32(trap int32, a1, a2, a3, a4, a5, a6 int32) int32
-
-//extern syscall
-func c_syscall64(trap int64, a1, a2, a3, a4, a5, a6 int64) int64
+//extern __go_syscall6
+func syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) uintptr
 
 const (
 	darwin64Bit    = runtime.GOOS == "darwin" && sizeofPtr == 8
@@ -38,14 +35,7 @@ const (
 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
 	Entersyscall()
 	SetErrno(0)
-	var r uintptr
-	if unsafe.Sizeof(r) == 4 {
-		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
-		r = uintptr(r1)
-	} else {
-		r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
-		r = uintptr(r1)
-	}
+	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
 	err = GetErrno()
 	Exitsyscall()
 	return r, 0, err
@@ -54,47 +44,22 @@ func Syscall(trap, a1, a2, a3 uintptr) (
 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
 	Entersyscall()
 	SetErrno(0)
-	var r uintptr
-	if unsafe.Sizeof(r) == 4 {
-		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
-			int32(a4), int32(a5), int32(a6))
-		r = uintptr(r1)
-	} else {
-		r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
-			int64(a4), int64(a5), int64(a6))
-		r = uintptr(r1)
-	}
+	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
 	err = GetErrno()
 	Exitsyscall()
 	return r, 0, err
 }
 
 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
-	var r uintptr
 	SetErrno(0)
-	if unsafe.Sizeof(r) == 4 {
-		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
-		r = uintptr(r1)
-	} else {
-		r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3), 0, 0, 0)
-		r = uintptr(r1)
-	}
+	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
 	err = GetErrno()
 	return r, 0, err
 }
 
 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
-	var r uintptr
 	SetErrno(0)
-	if unsafe.Sizeof(r) == 4 {
-		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
-			int32(a4), int32(a5), int32(a6))
-		r = uintptr(r1)
-	} else {
-		r1 := c_syscall64(int64(trap), int64(a1), int64(a2), int64(a3),
-			int64(a4), int64(a5), int64(a6))
-		r = uintptr(r1)
-	}
+	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
 	err = GetErrno()
 	return r, 0, err
 }
Index: libgo/go/syscall/wait.c
===================================================================
--- libgo/go/syscall/wait.c	(revision 268828)
+++ libgo/go/syscall/wait.c	(working copy)
@@ -65,10 +65,10 @@ CoreDump (uint32_t *w)
   return WCOREDUMP (*w) != 0;
 }
 
-extern int ExitStatus (uint32_t *w)
+extern intgo ExitStatus (uint32_t *w)
   __asm__ (GOSYM_PREFIX "syscall.WaitStatus.ExitStatus");
 
-int
+intgo
 ExitStatus (uint32_t *w)
 {
   if (!WIFEXITED (*w))
@@ -76,10 +76,10 @@ ExitStatus (uint32_t *w)
   return WEXITSTATUS (*w);
 }
 
-extern int Signal (uint32_t *w)
+extern intgo Signal (uint32_t *w)
   __asm__ (GOSYM_PREFIX "syscall.WaitStatus.Signal");
 
-int
+intgo
 Signal (uint32_t *w)
 {
   if (!WIFSIGNALED (*w))
@@ -87,10 +87,10 @@ Signal (uint32_t *w)
   return WTERMSIG (*w);
 }
 
-extern int StopSignal (uint32_t *w)
+extern intgo StopSignal (uint32_t *w)
   __asm__ (GOSYM_PREFIX "syscall.WaitStatus.StopSignal");
 
-int
+intgo
 StopSignal (uint32_t *w)
 {
   if (!WIFSTOPPED (*w))
@@ -98,10 +98,10 @@ StopSignal (uint32_t *w)
   return WSTOPSIG (*w);
 }
 
-extern int TrapCause (uint32_t *w)
+extern intgo TrapCause (uint32_t *w)
   __asm__ (GOSYM_PREFIX "syscall.WaitStatus.TrapCause");
 
-int
+intgo
 TrapCause (uint32_t *w __attribute__ ((unused)))
 {
 #ifndef __linux__
Index: libgo/runtime/go-caller.c
===================================================================
--- libgo/runtime/go-caller.c	(revision 268369)
+++ libgo/runtime/go-caller.c	(working copy)
@@ -192,12 +192,12 @@ struct caller_ret
   _Bool ok;
 };
 
-struct caller_ret Caller (int n) __asm__ (GOSYM_PREFIX "runtime.Caller");
+struct caller_ret Caller (intgo n) __asm__ (GOSYM_PREFIX "runtime.Caller");
 
 /* Implement runtime.Caller.  */
 
 struct caller_ret
-Caller (int skip)
+Caller (intgo skip)
 {
   struct caller_ret ret;
   Location loc;
Index: libgo/runtime/go-callers.c
===================================================================
--- libgo/runtime/go-callers.c	(revision 268369)
+++ libgo/runtime/go-callers.c	(working copy)
@@ -236,11 +236,11 @@ runtime_callers (int32 skip, Location *l
   return data.index;
 }
 
-int Callers (int, struct __go_open_array)
+intgo Callers (intgo, struct __go_open_array)
   __asm__ (GOSYM_PREFIX "runtime.Callers");
 
-int
-Callers (int skip, struct __go_open_array pc)
+intgo
+Callers (intgo skip, struct __go_open_array pc)
 {
   Location *locbuf;
   int ret;
Index: libgo/runtime/go-libmain.c
===================================================================
--- libgo/runtime/go-libmain.c	(revision 268369)
+++ libgo/runtime/go-libmain.c	(working copy)
@@ -231,7 +231,7 @@ gostart (void *arg)
   setpagesize (getpagesize ());
   runtime_sched = runtime_getsched();
   runtime_schedinit ();
-  __go_go (runtime_main, NULL);
+  __go_go ((uintptr)(runtime_main), NULL);
   runtime_mstart (runtime_m ());
   abort ();
 }
Index: libgo/runtime/go-main.c
===================================================================
--- libgo/runtime/go-main.c	(revision 268369)
+++ libgo/runtime/go-main.c	(working copy)
@@ -55,7 +55,7 @@ main (int argc, char **argv)
   setpagesize (getpagesize ());
   runtime_sched = runtime_getsched();
   runtime_schedinit ();
-  __go_go (runtime_main, NULL);
+  __go_go ((uintptr)(runtime_main), NULL);
   runtime_mstart (runtime_m ());
   abort ();
 }
Index: libgo/runtime/go-reflect-call.c
===================================================================
--- libgo/runtime/go-reflect-call.c	(revision 268369)
+++ libgo/runtime/go-reflect-call.c	(working copy)
@@ -229,7 +229,8 @@ reflect_call (const struct __go_func_typ
 
   call_result = (unsigned char *) malloc (go_results_size (func_type));
 
-  ffi_call_go (&cif, func_val->fn, call_result, params, func_val);
+  ffi_call_go (&cif, (void (*)(void)) func_val->fn, call_result, params,
+	       func_val);
 
   /* Some day we may need to free result values if RESULTS is
      NULL.  */
Index: libgo/runtime/go-varargs.c
===================================================================
--- libgo/runtime/go-varargs.c	(revision 268369)
+++ libgo/runtime/go-varargs.c	(working copy)
@@ -89,3 +89,14 @@ __go_openat (int fd, char *path, int fla
 }
 
 #endif
+
+// __go_syscall6 is called by both the runtime and syscall packages.
+// We use uintptr_t to make sure that the types match, since the Go
+// and C "int" types are not the same.
+
+uintptr_t
+__go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, uintptr_t a3,
+	      uintptr_t a4, uintptr_t a5, uintptr_t a6)
+{
+  return syscall (flag, a1, a2, a3, a4, a5, a6);
+}
Index: libgo/runtime/panic.c
===================================================================
--- libgo/runtime/panic.c	(revision 268369)
+++ libgo/runtime/panic.c	(working copy)
@@ -34,7 +34,7 @@ runtime_panicstring(const char *s)
 			runtime_throw("panic holding locks");
 		}
 	}
-	runtime_newErrorCString(s, &err);
+	runtime_newErrorCString((uintptr) s, &err);
 	runtime_panic(err);
 }
 
Index: libgo/runtime/runtime.h
===================================================================
--- libgo/runtime/runtime.h	(revision 268458)
+++ libgo/runtime/runtime.h	(working copy)
@@ -94,7 +94,7 @@ struct String
 
 struct FuncVal
 {
-	void	(*fn)(void);
+	uintptr_t fn;
 	// variable-size, fn-specific data here
 };
 
@@ -295,7 +295,7 @@ void	runtime_entersyscall()
   __asm__ (GOSYM_PREFIX "runtime.entersyscall");
 void	runtime_entersyscallblock()
   __asm__ (GOSYM_PREFIX "runtime.entersyscallblock");
-G*	__go_go(void (*pfn)(void*), void*);
+G*	__go_go(uintptr, void*);
 int32	runtime_callers(int32, Location*, int32, bool keep_callers);
 int64	runtime_nanotime(void)	// monotonic time
   __asm__(GOSYM_PREFIX "runtime.nanotime");
@@ -389,7 +389,7 @@ void runtime_panic(Eface)
 /*
  * runtime c-called (but written in Go)
  */
-void	runtime_newErrorCString(const char*, Eface*)
+void	runtime_newErrorCString(uintptr, Eface*)
      __asm__ (GOSYM_PREFIX "runtime.NewErrorCString");
 
 /*
Index: libgo/runtime/stack.c
===================================================================
--- libgo/runtime/stack.c	(revision 268369)
+++ libgo/runtime/stack.c	(working copy)
@@ -20,7 +20,7 @@ extern void * __splitstack_find_context
 // tail call to doscanstack1.
 #pragma GCC optimize ("-fno-optimize-sibling-calls")
 
-extern void scanstackblock(void *addr, uintptr size, void *gcw)
+extern void scanstackblock(uintptr addr, uintptr size, void *gcw)
   __asm__("runtime.scanstackblock");
 
 static bool doscanstack1(G*, void*)
@@ -84,11 +84,11 @@ static bool doscanstack1(G *gp, void *gc
 		}
 	}
 	if(sp != nil) {
-		scanstackblock(sp, (uintptr)(spsize), gcw);
+		scanstackblock((uintptr)(sp), (uintptr)(spsize), gcw);
 		while((sp = __splitstack_find(next_segment, next_sp,
 					      &spsize, &next_segment,
 					      &next_sp, &initial_sp)) != nil)
-			scanstackblock(sp, (uintptr)(spsize), gcw);
+			scanstackblock((uintptr)(sp), (uintptr)(spsize), gcw);
 	}
 #else
 	byte* bottom;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-15  1:58 Go patch committed: Harmonize types referenced by both C and Go Ian Lance Taylor
@ 2019-02-15  8:16 ` Andreas Schwab
  2019-02-15 12:03   ` Rainer Orth
  2019-02-15 13:55   ` Ian Lance Taylor
  0 siblings, 2 replies; 8+ messages in thread
From: Andreas Schwab @ 2019-02-15  8:16 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, gofrontend-dev

This breaks non-split-stack builds.

../../../libgo/runtime/stack.c: In function 'doscanstack1':
../../../libgo/runtime/stack.c:113:18: error: passing argument 1 of 'scanstackblock' makes integer from pointer without a cast [-Werror=int-conversion]
  113 |   scanstackblock(bottom, (uintptr)(top - bottom), gcw);
      |                  ^~~~~~
      |                  |
      |                  byte * {aka unsigned char *}

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-15  8:16 ` Andreas Schwab
@ 2019-02-15 12:03   ` Rainer Orth
  2019-02-15 14:26     ` Ian Lance Taylor
  2019-02-15 13:55   ` Ian Lance Taylor
  1 sibling, 1 reply; 8+ messages in thread
From: Rainer Orth @ 2019-02-15 12:03 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Ian Lance Taylor, gcc-patches, gofrontend-dev

Andreas Schwab <schwab@linux-m68k.org> writes:

> This breaks non-split-stack builds.
>
> ../../../libgo/runtime/stack.c: In function 'doscanstack1':
> ../../../libgo/runtime/stack.c:113:18: error: passing argument 1 of
> 'scanstackblock' makes integer from pointer without a cast
> [-Werror=int-conversion]
>   113 |   scanstackblock(bottom, (uintptr)(top - bottom), gcw);
>       |                  ^~~~~~
>       |                  |
>       |                  byte * {aka unsigned char *}

I see the same on Solaris.  Even with that fixed by appropriate casts to
uintptr (plus a few more times), Solaris bootstrap is still broken by
that patch:

/vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c: In function '__go_syscall6':
/vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c:101:10: error: implicit declaration of function 'syscall' [-Werror=implicit-function-declaration]
  101 |   return syscall (flag, a1, a2, a3, a4, a5, a6);
      |          ^~~~~~~

This needs to include <sys/syscall.h> for the syscall declaration, apart
from the fundamental problem that syscall isn't a stable interface on
Solaris.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-15  8:16 ` Andreas Schwab
  2019-02-15 12:03   ` Rainer Orth
@ 2019-02-15 13:55   ` Ian Lance Taylor
  1 sibling, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2019-02-15 13:55 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

On Fri, Feb 15, 2019 at 12:15 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> This breaks non-split-stack builds.
>
> ../../../libgo/runtime/stack.c: In function 'doscanstack1':
> ../../../libgo/runtime/stack.c:113:18: error: passing argument 1 of 'scanstackblock' makes integer from pointer without a cast [-Werror=int-conversion]
>   113 |   scanstackblock(bottom, (uintptr)(top - bottom), gcw);
>       |                  ^~~~~~
>       |                  |
>       |                  byte * {aka unsigned char *}

Thanks, and sorry.  Fixed like so.  Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1416 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268923)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-03e28273a4fcb114f5204d52ed107591404002f4
+a9c1a76e14b66a356d3c3dfb50f1e6138e97733c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/stack.c
===================================================================
--- libgo/runtime/stack.c	(revision 268923)
+++ libgo/runtime/stack.c	(working copy)
@@ -110,15 +110,15 @@ static bool doscanstack1(G *gp, void *gc
 	}
 	top = (byte*)(void*)(gp->gcinitialsp) + gp->gcstacksize;
 	if(top > bottom)
-		scanstackblock(bottom, (uintptr)(top - bottom), gcw);
+		scanstackblock((uintptr)(bottom), (uintptr)(top - bottom), gcw);
 	else
-		scanstackblock(top, (uintptr)(bottom - top), gcw);
+		scanstackblock((uintptr)(top), (uintptr)(bottom - top), gcw);
 	if (nextsp2 != nil) {
 		initialsp2 = (byte*)(void*)(gp->gcinitialsp2);
 		if(initialsp2 > nextsp2)
-			scanstackblock(nextsp2, (uintptr)(initialsp2 - nextsp2), gcw);
+			scanstackblock((uintptr)(nextsp2), (uintptr)(initialsp2 - nextsp2), gcw);
 		else
-			scanstackblock(initialsp2, (uintptr)(nextsp2 - initialsp2), gcw);
+			scanstackblock((uintptr)(initialsp2), (uintptr)(nextsp2 - initialsp2), gcw);
 	}
 #endif
 	return true;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-15 12:03   ` Rainer Orth
@ 2019-02-15 14:26     ` Ian Lance Taylor
  2019-02-18 10:48       ` Rainer Orth
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2019-02-15 14:26 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Andreas Schwab, gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 1554 bytes --]

On Fri, Feb 15, 2019 at 4:03 AM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>
> Andreas Schwab <schwab@linux-m68k.org> writes:
>
> > This breaks non-split-stack builds.
> >
> > ../../../libgo/runtime/stack.c: In function 'doscanstack1':
> > ../../../libgo/runtime/stack.c:113:18: error: passing argument 1 of
> > 'scanstackblock' makes integer from pointer without a cast
> > [-Werror=int-conversion]
> >   113 |   scanstackblock(bottom, (uintptr)(top - bottom), gcw);
> >       |                  ^~~~~~
> >       |                  |
> >       |                  byte * {aka unsigned char *}
>
> I see the same on Solaris.  Even with that fixed by appropriate casts to
> uintptr (plus a few more times), Solaris bootstrap is still broken by
> that patch:
>
> /vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c: In function '__go_syscall6':
> /vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c:101:10: error: implicit declaration of function 'syscall' [-Werror=implicit-function-declaration]
>   101 |   return syscall (flag, a1, a2, a3, a4, a5, a6);
>       |          ^~~~~~~
>
> This needs to include <sys/syscall.h> for the syscall declaration, apart
> from the fundamental problem that syscall isn't a stable interface on
> Solaris.

I committed this patch which should fix the Solaris build.

The code was already calling syscall, it was just doing it in a way
that the types didn't necessarily match the C declaration.  This is
the implementation of Go's syscall.Syscall function, so there isn't
really anything else we can do.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 942 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268939)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-a9c1a76e14b66a356d3c3dfb50f1e6138e97733c
+6877c95a5f44c3ab4f492d2000ce07771341d7b7
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/go-varargs.c
===================================================================
--- libgo/runtime/go-varargs.c	(revision 268923)
+++ libgo/runtime/go-varargs.c	(working copy)
@@ -12,6 +12,12 @@
 #include <sys/types.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
 
 /* The syscall package calls C functions.  The Go compiler can not
    represent a C varargs functions.  On some systems it's important

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-15 14:26     ` Ian Lance Taylor
@ 2019-02-18 10:48       ` Rainer Orth
  2019-02-18 19:55         ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Rainer Orth @ 2019-02-18 10:48 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Andreas Schwab, gcc-patches, gofrontend-dev

Hi Ian,

> On Fri, Feb 15, 2019 at 4:03 AM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>>
>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>
>> > This breaks non-split-stack builds.
>> >
>> > ../../../libgo/runtime/stack.c: In function 'doscanstack1':
>> > ../../../libgo/runtime/stack.c:113:18: error: passing argument 1 of
>> > 'scanstackblock' makes integer from pointer without a cast
>> > [-Werror=int-conversion]
>> >   113 |   scanstackblock(bottom, (uintptr)(top - bottom), gcw);
>> >       |                  ^~~~~~
>> >       |                  |
>> >       |                  byte * {aka unsigned char *}
>>
>> I see the same on Solaris.  Even with that fixed by appropriate casts to
>> uintptr (plus a few more times), Solaris bootstrap is still broken by
>> that patch:
>>
>> /vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c: In function '__go_syscall6':
>> /vol/gcc/src/hg/trunk/local/libgo/runtime/go-varargs.c:101:10: error: implicit declaration of function 'syscall' [-Werror=implicit-function-declaration]
>>   101 |   return syscall (flag, a1, a2, a3, a4, a5, a6);
>>       |          ^~~~~~~
>>
>> This needs to include <sys/syscall.h> for the syscall declaration, apart
>> from the fundamental problem that syscall isn't a stable interface on
>> Solaris.
>
> I committed this patch which should fix the Solaris build.

it did, and certainly in a cleaner way than just unconditionally
including <sys/syscall.h> ;-)  Thanks.

> The code was already calling syscall, it was just doing it in a way
> that the types didn't necessarily match the C declaration.  This is
> the implementation of Go's syscall.Syscall function, so there isn't
> really anything else we can do.

I feared as much.  Some time ago when debugging another issue I saw
libgo using syscall() directly, certainly unexpected in that particular
case.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-18 10:48       ` Rainer Orth
@ 2019-02-18 19:55         ` Ian Lance Taylor
  2019-02-19 12:59           ` Rainer Orth
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2019-02-18 19:55 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Andreas Schwab, gcc-patches, gofrontend-dev

On Mon, Feb 18, 2019 at 2:48 AM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>
> > The code was already calling syscall, it was just doing it in a way
> > that the types didn't necessarily match the C declaration.  This is
> > the implementation of Go's syscall.Syscall function, so there isn't
> > really anything else we can do.
>
> I feared as much.  Some time ago when debugging another issue I saw
> libgo using syscall() directly, certainly unexpected in that particular
> case.

Those cases--where libgo calls syscall.Syscall--we can clean up where
appropriate.  What we can't clean up is user written Go code that
calls syscall.Syscall directly.

Ian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Go patch committed: Harmonize types referenced by both C and Go
  2019-02-18 19:55         ` Ian Lance Taylor
@ 2019-02-19 12:59           ` Rainer Orth
  0 siblings, 0 replies; 8+ messages in thread
From: Rainer Orth @ 2019-02-19 12:59 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Andreas Schwab, gcc-patches, gofrontend-dev

Hi Ian,

> On Mon, Feb 18, 2019 at 2:48 AM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>>
>> > The code was already calling syscall, it was just doing it in a way
>> > that the types didn't necessarily match the C declaration.  This is
>> > the implementation of Go's syscall.Syscall function, so there isn't
>> > really anything else we can do.
>>
>> I feared as much.  Some time ago when debugging another issue I saw
>> libgo using syscall() directly, certainly unexpected in that particular
>> case.
>
> Those cases--where libgo calls syscall.Syscall--we can clean up where
> appropriate.  What we can't clean up is user written Go code that
> calls syscall.Syscall directly.

I'll keep an eye open for the former when looking into the remaining Go
failures.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-02-19 12:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15  1:58 Go patch committed: Harmonize types referenced by both C and Go Ian Lance Taylor
2019-02-15  8:16 ` Andreas Schwab
2019-02-15 12:03   ` Rainer Orth
2019-02-15 14:26     ` Ian Lance Taylor
2019-02-18 10:48       ` Rainer Orth
2019-02-18 19:55         ` Ian Lance Taylor
2019-02-19 12:59           ` Rainer Orth
2019-02-15 13:55   ` Ian Lance Taylor

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).