Source file src/cmd/link/testdata/linkname/badlinkname.go

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Existing pull linknames in the wild are allowed _for now_,
     6  // for legacy reason. Test a function, a method, and an
     7  // assembly symbol.
     8  // NOTE: this may not be allowed in the future. Don't do this!
     9  
    10  package main
    11  
    12  import (
    13  	_ "reflect"
    14  	"unsafe"
    15  )
    16  
    17  //go:linkname noescape runtime.noescape
    18  func noescape(unsafe.Pointer) unsafe.Pointer
    19  
    20  //go:linkname rtype_String reflect.(*rtype).String
    21  func rtype_String(unsafe.Pointer) string
    22  
    23  //go:linkname memmove runtime.memmove
    24  func memmove(to, from unsafe.Pointer, n uintptr)
    25  
    26  var n uintptr // use a global to prevent compiler optimize out memmove call
    27  
    28  func main() {
    29  	println(rtype_String(noescape(nil)))
    30  	memmove(nil, nil, n)
    31  }
    32  

View as plain text