C-shared library can not used in nuvoton ARM926EJ-S rev 5, and will cause segmentaion fault


(Gibbsqi) #1

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
goversion

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)


(Sean Killian) #2

I’m having a hard time confirming this, but I suspect the issue is the ARMV5TEJ doesn’t support floating point instructions and that offending instruction may be a floating point one (is that what F8 means? It looks like a Go assembler specific mnemonic, I’m not familiar with Go’s assembler’s ARM syntax). My guess is the runtime was first built with GOARM=7 and it’s being reused even when you build with GOARM=5. Have you tried adding the -a flag to go build to force it to rebuild everything when you have GOARM=5?


(Gibbsqi) #3

hi, skillian
thank you for your reply.

I add -a flag to force it rebuilding everything, but it also has the same issue.
I get the info that ARMV5TEJ is not support hard floating point instructions.

and i also check that execute binary can run in ARMV5TEJ chip when GOARM=5


(Sean Killian) #4

Can you clarify what you mean here? The way I read this, it sounds like it works when you set GOARM=5 which you have to do to have the runtime emulate floating point instructions (GOARM >=6 assumes hardware floating point).


(Gibbsqi) #5

hi, skillian

I am sorry for the later reply.

this is mean, when i build go code with execute(buildmode = default) for ARMV5TEJ, it is can run.

when i build go code with share library(buildmode = c-share) for ARMV5TEJ, it can not run, and produce the error(segmentation fault)

thanks