-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
Examples are very simple functions, I wrote a simple function which use printf to print a message, but got crashed, is there anything else I should do?
The lib src:
#include "stdio.h"
void test_go() {
printf("invoke test_go");
}Compiled to lib:
gcc -shared testlib/biz.c -o testlib.soRun with the following go src:
package main
import (
"fmt"
"io/ioutil"
"github.com/Binject/universal"
)
func main() {
var (
libPath = "testlib.so"
fName = "test_go"
)
image, err := ioutil.ReadFile(libPath)
if err != nil {
panic(err)
}
loader, err := universal.NewLoader()
if err != nil {
panic(err)
}
lib, err := loader.LoadLibrary("main", &image)
if err != nil {
panic(err)
}
for k := range lib.Exports {
fmt.Printf("exported function: %s\n", k)
}
addr, ok := lib.FindProc(fName)
if ok {
fmt.Printf("function address of %s: %x\n", fName, addr)
} else {
panic("function not found")
}
val, err := lib.Call(fName)
if err != nil {
panic(err)
}
fmt.Printf("returned value: %v\n", val)
}But got a sad crash:
Go version: go version go1.17.1 linux/amd64
GCC version: gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
System: WSL1, and ubuntu20.04 also fails.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
