vps交流

go 交叉编译'V2'(教程)


MediaTek MT762 官方发布的不能用,因为他CPU是小端的.刚折腾了下,自己编译.
记录一下.

git clone https://github.com/v2fly/’V2′-core.git
cd  ‘V2’-core
git branch -a
git checkout remotes/origin/dev-v4main
使用分支
确定编译参数
我们可以通过查看/proc/cpuinfo来确定cpu的基本信息
[email protected]:~# cat /proc/cpuinfo
system type                : MediaTek MT7621 ver:1 eco:3
machine                        : MikroTik RouterBOARD M33G
processor                : 0
cpu model                : MIPS 1004Kc V2.15
BogoMIPS                : 586.13
wait instruction        : yes
microsecond timers        : yes
tlb_entries                : 32
extra interrupt vector        : yes
hardware watchpoint        : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa                        : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp mt
Options implemented        : tlb 4kex 4k_cache prefetch mcheck ejtag llsc pindexed_dcache userlocal vint perf_cntr_intr_bit cdmm perf
shadow register sets        : 1
kscratch registers        : 0
package                        : 0
core                        : 0
VPE                        : 0
VCED exceptions                : not available
VCEI exceptions                : not available

然后我们可以通过file命令来查看一个路由器上可执行文件的文件类型,比如/bin/sh

Fi        : ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, corrupted section header size

这里我们可以看到这个可执行文件是LSB,也就是小端序的,MIPS架构的CPU分为大端序和小端序两种,一定要注意区分清楚。所以我们可以确定我们的编译参数为

export GOOS=linux
export GOARCH=mipsle

但是这时编译出来的程序很有可能执行的时候出现错误
Illegal instruction

在编译参数中加上
export GOMIPS=softfloat

执行:
export GOOS=linux
export GOARCH=mipsle
export GOMIPS=softfloat
go mod tidy
go build -o bin/’V2′ -trimpath -ldflags "-s -w -buildid=" ./main
go build -o bin/v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main
X86
export GOOS=linux
export GOARCH=amd64
go build -o bin/’V2′ -trimpath -ldflags "-s -w -buildid=" ./main
go build -o bin/v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main

本帖最后由 HOH 于 2022-10-1 23:08 编辑

mips大小端 不都是兼容的?

实用的知识,之前在路由器过安装frp,过了一晚就死机了

大端字节序,高字节存于内存低地址,低字节存于内存高地址;小端字节序反之
赞(0)
版权声明:本贴采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
帖子名称:《go 交叉编译'V2'(教程)》
帖子链接:https://bbs.toot.su/170170.html

相关推荐