the c-shared library building by go code can not used in nuvoton ARM926EJ-S rev 5.
when the binary using this shared library, it will break segmentation fault when run.
I build c-shared library in linux amd64, go version is 1.11.5
library code is
package main
/*
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<string.h>
#include<stdbool.h>
#define RETURN_OK 1
#define RETURN_ERROR_INPUTPARAM 1001
typedef struct{
char version[256];
uint16_t size;
}VersionInfo;
*/
import "C"
import "fmt"
//export GetVersion
func GetVersion() C.int {
fmt.Println("GetVersion In")
return C.int(1)
}
func main() {
}
and save as versiontest.go
using “go build -buildmode=c-shared -o libversiontest.so versiontest.go” build to libversiontest.so and libversiontest.h
gcc is the nuvoton cross-compiler, and I set
GOARCH=arm
GOARM=5 //because arch is ARMV5TEJ
CGO_ENABLED=1
other go env value is default.
c-shared library code is
#include "libversiontest.h"
int main(){
GetVersion();
return 1;
}
and build to execute file testversion.
then, copy testversion and libversiontest.so to nuvoton chip.
when run binary testversion, it will break “segmentation default”.
and using gdb, it will output
Program received signal SIGILL, Illegal instruction.
_rt0_arm_lib () at /usr/local/go/src/runtime/asm_arm.s:46
46 MOVD F8, (40+8*0)(R13)
I check the asm_arm.s code, it is
MOVD F8, (40+8*0)(R13)
but the same code is can run in Pi 2 model B(armV7)