This libgo patch by Cherry Zhang changes the runtime package to use the builtin memmove function directly, rather than calling through C code. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian 2019-05-08 Cherry Zhang <cherr...@google.com> * go-gcc.cc (Gcc_backend::Gcc_backend): Define memmove builtin.
Index: gcc/go/go-gcc.cc =================================================================== --- gcc/go/go-gcc.cc (revision 270877) +++ gcc/go/go-gcc.cc (working copy) @@ -604,6 +604,15 @@ Gcc_backend::Gcc_backend() NULL_TREE), false, false); + // We use __builtin_memmove for copying data. + this->define_builtin(BUILT_IN_MEMMOVE, "__builtin_memmove", "memmove", + build_function_type_list(void_type_node, + ptr_type_node, + const_ptr_type_node, + size_type_node, + NULL_TREE), + false, false); + // Used by runtime/internal/sys. this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz", build_function_type_list(integer_type_node, Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 271014) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -0b4cf8ded107ccbfbd4af7f4e056f23f941d0f86 +3a9bccfbf4af1c756978c40967838d9f6a4e7a62 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: libgo/Makefile.am =================================================================== --- libgo/Makefile.am (revision 270877) +++ libgo/Makefile.am (working copy) @@ -461,7 +461,6 @@ runtime_files = \ runtime/go-memclr.c \ runtime/go-memcmp.c \ runtime/go-memequal.c \ - runtime/go-memmove.c \ runtime/go-nanotime.c \ runtime/go-now.c \ runtime/go-nosys.c \ Index: libgo/go/runtime/stubs.go =================================================================== --- libgo/go/runtime/stubs.go (revision 270877) +++ libgo/go/runtime/stubs.go (working copy) @@ -100,6 +100,7 @@ func reflect_memclrNoHeapPointers(ptr un // memmove copies n bytes from "from" to "to". //go:noescape +//extern __builtin_memmove func memmove(to, from unsafe.Pointer, n uintptr) //go:linkname reflect_memmove reflect.memmove Index: libgo/runtime/go-memmove.c =================================================================== --- libgo/runtime/go-memmove.c (revision 270877) +++ libgo/runtime/go-memmove.c (nonexistent) @@ -1,16 +0,0 @@ -/* go-memmove.c -- move one memory buffer to another - - Copyright 2016 The Go Authors. All rights reserved. - Use of this source code is governed by a BSD-style - license that can be found in the LICENSE file. */ - -#include "runtime.h" - -void move(void *, void *, uintptr) - __asm__ (GOSYM_PREFIX "runtime.memmove"); - -void -move (void *p1, void *p2, uintptr len) -{ - __builtin_memmove (p1, p2, len); -}