I am trying to compiler a cross-platform in Golang to run on OpenWRT Router (GDock). The target system is:
Linux OpenWrt 5.15.118 #0 SMP Wed Jul 5 20:20:32 2023 armv7l GNU/Linux
model name : ARMv7 Processor rev 5 (v7l) BogoMIPS : 26.81 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5 I wrote a small program that print "Hello world" with only import "fmt" module. The program below:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello world!")
}
I compile it by:
GO=linux GOARM=7,softfloat GOARCH=arm /usr/local/go/bin/go build .
I checked the file with file
command:
main: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, Go BuildID=z6RADCEu-jOWczIr0anP/cqhqMt2UfXF1iAnzuTKC/uwGWq8e4UU7E-hUo7T7S/eNInvO8n3j0q7bTGVsJ7, with debug_info, not stripped
Current system, that I used to compile:
Linux ubuntu 5.15.0-107-generic #117~20.04.1-Ubuntu SMP Tue Apr 30 10:35:57 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Golang version:
go version go1.22.2 linux/amd64
The program works on Ubuntu:
./main
Hello world!
However, when I copy the program to router, I got Segmentation Fault
. I tried to copy a router busybox and check with file
command, the result I got is:
busybox: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-armhf.so.1, no section header
I searched everywhere on the Internet and could not find the answer, some results resolved for CGO. But it's not my problem!
Why I got segmentation fault? I can not debug because of tidy resource on the router. How can I fixed it?
The problem comes from my ftp, I checked sha2sum and realize my file corrupted when upload to server. So, I use the difference sftp server and checksum to make sure file is not corrupted then it worked!