如何通过 zig builed-exec 生成 armv5 二进制文件
主机
这是目标系统中正在运行的二进制文件
readelf -h asterisk
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x1ee30
Start of program headers: 52 (bytes into file)
Start of section headers: 3431360 (bytes into file)
Flags: 0x4000002, Version4 EABI, <unknown>
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 27
Section header string table index: 26
目标系统 cpu 信息
Processor : ARMv6-compatible processor rev 5 (v6l)
BogoMIPS : 648.80
Features : swp half thumb fastmult edsp java
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 5
Hardware : Comcerto 1000 (EVM)
Revision : 0000
Serial : 0000000000000000
dmesg 信息
dmesg | head
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.33.5 ([email protected]) (gcc version 4.1.2) #5 Mon Jan 29 20:07:16 CST 2018
CPU: ARMv6-compatible processor [4117b365] revision 5 (ARMv6TEJ), cr=00c5387d
CPU: VIPT aliasing data cache, VIPT aliasing instruction cache
Machine: Comcerto 1000 (EVM)
Memory policy: ECC disabled, Data cache writeback
On node 0 totalpages: 30720
free_area_init_node: node 0, pgdat c0399e54, node_mem_map c03c2000
DMA zone: 240 pages used for memmap
zig build-exec
进行构建
# running ./hello Aborted
zig build-exe -target arm-linux-none -mcpu=arm1136j_s hello.zig
# Aborted
zig build-exe -target arm-linux-eabi -mcpu=arm1136j_s hello.zig
# Illegal instruction
zig build-exe -target arm-linux-eabi hello.zig
尝试使用 v4 和 v4 v5 mcpu,但构建失败
- arm710t
- arm1020e
- arm1020t
- arm1022e
ld.lld: warning: lld uses blx instruction, no object with architecture supporting feature detected
ld.lld: error: undefined symbol: __sync_val_compare_and_swap_4
>>> referenced by heap.zig:352 (/usr/lib/zig/std/heap.zig:352)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.heap.PageAllocator.alloc)
>>> referenced by Mutex.zig:101 (/usr/lib/zig/std/Thread/Mutex.zig:101)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lockSlow)
>>> referenced by StaticResetEvent.zig:149 (/usr/lib/zig/std/Thread/StaticResetEvent.zig:149)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.StaticResetEvent.AtomicEvent.timedWait)
>>> referenced 2 more times
ld.lld: error: undefined symbol: __sync_fetch_and_add_1
>>> referenced by debug.zig:284 (/usr/lib/zig/std/debug.zig:284)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.debug.panicImpl)
ld.lld: error: undefined symbol: __sync_fetch_and_sub_1
>>> referenced by debug.zig:305 (/usr/lib/zig/std/debug.zig:305)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.debug.panicImpl)
ld.lld: error: undefined symbol: __sync_lock_test_and_set_4
>>> referenced by Mutex.zig:81 (/usr/lib/zig/std/Thread/Mutex.zig:81)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lock)
>>> referenced by Mutex.zig:88 (/usr/lib/zig/std/Thread/Mutex.zig:88)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.unlock)
>>> referenced by Mutex.zig:123 (/usr/lib/zig/std/Thread/Mutex.zig:123)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lockSlow)
error: LLDReportedFailure
但是交叉构建可以在目标中运行
# produce EABI5 & armv5
GOOS=linux GOARM=5 GOARCH=arm CGO_ENABLED=0 go build hello.go
所以我猜问题是zig产生EABI5或armv6,但是armv5 mcpu没有可以通过构建,我该怎么办使用 zig 生成 EABI4 或 armv5 二进制文件?
相关 PR
Host
Here is a running binary in target system
readelf -h asterisk
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x1ee30
Start of program headers: 52 (bytes into file)
Start of section headers: 3431360 (bytes into file)
Flags: 0x4000002, Version4 EABI, <unknown>
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 27
Section header string table index: 26
The target system cpu info
Processor : ARMv6-compatible processor rev 5 (v6l)
BogoMIPS : 648.80
Features : swp half thumb fastmult edsp java
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 5
Hardware : Comcerto 1000 (EVM)
Revision : 0000
Serial : 0000000000000000
The dmesg info
dmesg | head
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.33.5 ([email protected]) (gcc version 4.1.2) #5 Mon Jan 29 20:07:16 CST 2018
CPU: ARMv6-compatible processor [4117b365] revision 5 (ARMv6TEJ), cr=00c5387d
CPU: VIPT aliasing data cache, VIPT aliasing instruction cache
Machine: Comcerto 1000 (EVM)
Memory policy: ECC disabled, Data cache writeback
On node 0 totalpages: 30720
free_area_init_node: node 0, pgdat c0399e54, node_mem_map c03c2000
DMA zone: 240 pages used for memmap
zig build-exec
Tried build with
# running ./hello Aborted
zig build-exe -target arm-linux-none -mcpu=arm1136j_s hello.zig
# Aborted
zig build-exe -target arm-linux-eabi -mcpu=arm1136j_s hello.zig
# Illegal instruction
zig build-exe -target arm-linux-eabi hello.zig
tried v4 & v5 mcpu, but build failed
- arm710t
- arm1020e
- arm1020t
- arm1022e
ld.lld: warning: lld uses blx instruction, no object with architecture supporting feature detected
ld.lld: error: undefined symbol: __sync_val_compare_and_swap_4
>>> referenced by heap.zig:352 (/usr/lib/zig/std/heap.zig:352)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.heap.PageAllocator.alloc)
>>> referenced by Mutex.zig:101 (/usr/lib/zig/std/Thread/Mutex.zig:101)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lockSlow)
>>> referenced by StaticResetEvent.zig:149 (/usr/lib/zig/std/Thread/StaticResetEvent.zig:149)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.StaticResetEvent.AtomicEvent.timedWait)
>>> referenced 2 more times
ld.lld: error: undefined symbol: __sync_fetch_and_add_1
>>> referenced by debug.zig:284 (/usr/lib/zig/std/debug.zig:284)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.debug.panicImpl)
ld.lld: error: undefined symbol: __sync_fetch_and_sub_1
>>> referenced by debug.zig:305 (/usr/lib/zig/std/debug.zig:305)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.debug.panicImpl)
ld.lld: error: undefined symbol: __sync_lock_test_and_set_4
>>> referenced by Mutex.zig:81 (/usr/lib/zig/std/Thread/Mutex.zig:81)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lock)
>>> referenced by Mutex.zig:88 (/usr/lib/zig/std/Thread/Mutex.zig:88)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.unlock)
>>> referenced by Mutex.zig:123 (/usr/lib/zig/std/Thread/Mutex.zig:123)
>>> zig-cache/o/750724e51d9b1b9d610b91ec3f30a585/hello.o:(std.Thread.Mutex.AtomicMutex.lockSlow)
error: LLDReportedFailure
But go cross build can running in target
# produce EABI5 & armv5
GOOS=linux GOARM=5 GOARCH=arm CGO_ENABLED=0 go build hello.go
So I guess the problem is zig produce EABI5 or armv6, but none of armv5 mcpu can pass the build, how can I produce a EABI4 or armv5 binary by using zig ?
Related PR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论