Hi, this is the smallest example I can think of but I have know idea how I 
am suppose to do the syscall and trampoline part?

./c/hello.c
---------
#include <stdio.h>
#include <string.h>


int hello(char *s) {
  char c[80];
  strcpy (c, s);
  sprintf(s, "hello %s", c);
  return 0;
}

clang -shared -fpic hello.c -o hello.dylib

./trampoline.s
-----------------

#include "textflag.h"

TEXT ·hello_trampoline(SB),NOSPLIT,$0-0
  JMP hello(SB)

./main.go
-----------

package main

import "unsafe"

//go:linkname hello_c hello_c
//go:cgo_import_dynamic hello_c hello "./c/hello.dylib"
func hello_c(s unsafe.Pointer) uintptr {
return syscall(funcPC(hello_trampoline), uintptr(s), uintptr(0), 0, 0, 
uintptr(s), 0)
}

func hello_trampoline()

func syscall(fn, a1, a2, a3, a4, a5, a6 uintptr) uintptr

//go:nosplit
func funcPC(f func()) uintptr {
   return **(**uintptr)(unsafe.Pointer(&f))
}

func main() {
  s := "test"
  hello_c(unsafe.Pointer(&s))
  print(s)
}

(go version devel +98d20fb235 Fri May 8 02:31:13 2020 +0000 darwin/amd64)

main.main: relocation target main.syscall not defined
main.hello_trampoline: relocation target hello not defined

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6e9eae3e-d060-44e3-9361-e9ef89d82515%40googlegroups.com.

Reply via email to