我正在尝试交叉编译汇编hello world
目前,当我运行linux构建时,它显示“exec格式错误:./linuxbuild.out”,错误代码为126,下面显示了objdump中的一些差异。我尝试在链接器和lazy lib上使用-F,但没有成功。转储中的一个差异是缺少__mh_execute_header
我是这么做的
在x86-64 linux上我有这个程序集
$ cat hello.s
.global _main
.align 2
_main: mov X0, #1
adr X1, hello
mov X2, #13
mov X16, #4
svc 0
mov X0, #0
mov X16, #1
svc 0
hello: .ascii "Hello\n"
我写了
clang hello.s --target=arm64-apple-macosx12.5.0 -c -o h.o
ld64.lld h.o -arch arm64 -platform_version macos 12 5 -v -dylib -o linuxbuild.out
输出
LLD 14.0.6
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
ld64.lld: warning: h.o has version 12.5.0, which is newer than target minimum of 12
你可以看到区别
% /opt/homebrew/opt/binutils/bin/objdump -x a.out linuxbuild.out
a.out: file format mach-o-arm64
a.out
architecture: aarch64, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x0000000100003f90
MACH-O header:
magic: 0xfeedfacf
cputype: 0x100000c (ARM64)
cpusubtype: 0 (ARM64_ALL)
filetype: 0x2
ncmds: 0x10
sizeocmds: 0x2e8
flags: 0x200085
version: 2
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000026 0000000100003f90 0000000100003f90 00003f90 2**2
CONTENTS, ALLOC, LOAD, CODE
1 __TEXT.__unwind_info 00000048 0000000100003fb8 0000000100003fb8 00003fb8 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
SYMBOL TABLE:
0000000100003fb0 l 0e SECT 01 0000 [.text] hello
0000000100000000 g 0f SECT 01 0010 [.text] __mh_execute_header
0000000100003f90 g 0f SECT 01 0000 [.text] _main
linuxbuild.out: file format mach-o-arm64
linuxbuild.out
architecture: aarch64, flags 0x00000050:
HAS_SYMS, DYNAMIC
start address 0x0000000000000000
MACH-O header:
magic: 0xfeedfacf
cputype: 0x100000c (ARM64)
cpusubtype: 0 (ARM64_ALL)
filetype: 0x6
ncmds: 0xb
sizeocmds: 0x208
flags: 0x100085
version: 2
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000026 0000000000000248 0000000000000248 00000248 2**2
CONTENTS, ALLOC, LOAD, CODE
SYMBOL TABLE:
0000000000000268 l 0e SECT 01 0000 [.text] hello
0000000000000248 g 0f SECT 01 0000 [.text] _main
1条答案
按热度按时间hgqdbh6s1#
我通过在我的mac上写
clang -v
,使用链接器,然后在linux上重复它来解决这个问题。我在linux上有0个mac文件。它似乎可以在我的简单汇编文件上工作