Mac OS: ld: 在 __DATA,__data 部分 reloc 0: 长度 < 2 和 X86_64_RELOC_UNSIGNED 不支持
Mac OS: ld: in section __DATA,__data reloc 0: length < 2 and X86_64_RELOC_UNSIGNED not supported
网上查了半天没看到类似的问题
所以我正在编写一个小型编译器来将语言编译为 x64 代码。
但是当我尝试执行 clang generated-code.s
时,我得到:
ld: in section __DATA,__data reloc 0: length < 2 and
X86_64_RELOC_UNSIGNED not supported file
'/var/folders/3g/ydlqd7bx3819pfrr9n52zjv80000gn/T/hello_world-795c7e.o'
for architecture x86_64 clang: error: linker command failed with exit
code 1 (use -v to see invocation)
我不太明白这个错误信息的意思。这是否意味着我有未定义的符号?谁能给我解释一下?
这是我的编译器生成的代码:
.data
.globl Main_protoObj
.globl Int_protoObj
.globl String_protoObj
.globl Main_init
.globl Int_init
.globl String_init
.globl Bool_init
.globl Main_main
class_objTab:
.word Object_protoObj
.word Object_init
.word IO_protoObj
.word IO_init
.word String_protoObj
.word String_init
.word Int_protoObj
.word Int_init
.word Bool_protoObj
.word Bool_init
.word Main_protoObj
.word Main_init
Object_protoObj:
.word 0
.word 1
.word Object_dispatch_table
IO_protoObj:
.word 1
.word 3
.word IO_dispatch_table
String_protoObj:
.word 2
.word 3
.word String_dispatch_table
.word 0
.asciz ""
.align 8
Int_protoObj:
.word 3
.word 2
.word Int_dispatch_table
.word 0
Bool_protoObj:
.word 4
.word 2
.word Bool_dispatch_table
.word 0
Main_protoObj:
.word 5
.word 1
.word Main_dispatch_table
String_dispatch_table:
.word Object_abort
.word Object_copy
.word String_length
.word String_concat
.word String_substr
Main_dispatch_table:
.word Object_abort
.word Object_copy
.word IO_out_string
.word IO_out_int
.word IO_in_string
.word IO_in_int
.word Main_main
Bool_dispatch_table:
.word Object_abort
.word Object_copy
Object_dispatch_table:
.word Object_abort
.word Object_copy
IO_dispatch_table:
.word Object_abort
.word Object_copy
.word IO_out_string
.word IO_out_int
.word IO_in_string
.word IO_in_int
Int_dispatch_table:
.word Object_abort
.word Object_copy
int_const0:
.word 3
.word 4
.word Int_dispatch_table
.word 22
string_const0:
.word 2
.word 6
.word String_dispatch_table
.word int_const0
.asciz "Hello, World.\n \n\n"
.align 8
.text
Object_init:
pushq %rbp
movq %rsp, %rbp
leave
ret
IO_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
leave
ret
String_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq '', 32(%rbp)
movq [=15=], 24(%rbp)
leave
ret
Int_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq [=15=], 24(%rbp)
leave
ret
Bool_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq [=15=], 24(%rbp)
leave
ret
Main_main:
pushq %rbp
movq %rsp, %rbp
subq , %rsp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rdi
leaq string_const0(%rip), %rax
movq %rax, %rsi
movq 16(%rdi), %r10
movq 16(%r10), %r10
callq* %r10
leave
ret
Main_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq IO_init
leave
ret
错误:
ld: in section __DATA,__data reloc 0: length < 2 and X86_64_RELOC_UNSIGNED not supported
看起来像是一种相当晦涩的说法,即您的对象已分配 space 以将偏移量存储到可能无法保存在 link 时间生成的偏移量的数据项中。
快速查看您的代码表明您使用 .word
和一个值标签。一个示例 .word Object_protoObj
,其中 Object_protoObj
offset 是一个标签。指令 .word
允许 0x0000 和 0xffff(16 位)之间的值。 linker 错误可能表明它生成的标签的偏移量不适合 16 位字。
也许您应该使用 .quad
(允许 64 位值)或 .int
(32 位值)?我不知道您将如何访问表中的这些偏移量,因此您必须根据您的使用要求选择 .quad
或 .int
。
网上查了半天没看到类似的问题
所以我正在编写一个小型编译器来将语言编译为 x64 代码。
但是当我尝试执行 clang generated-code.s
时,我得到:
ld: in section __DATA,__data reloc 0: length < 2 and X86_64_RELOC_UNSIGNED not supported file '/var/folders/3g/ydlqd7bx3819pfrr9n52zjv80000gn/T/hello_world-795c7e.o' for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不太明白这个错误信息的意思。这是否意味着我有未定义的符号?谁能给我解释一下?
这是我的编译器生成的代码:
.data
.globl Main_protoObj
.globl Int_protoObj
.globl String_protoObj
.globl Main_init
.globl Int_init
.globl String_init
.globl Bool_init
.globl Main_main
class_objTab:
.word Object_protoObj
.word Object_init
.word IO_protoObj
.word IO_init
.word String_protoObj
.word String_init
.word Int_protoObj
.word Int_init
.word Bool_protoObj
.word Bool_init
.word Main_protoObj
.word Main_init
Object_protoObj:
.word 0
.word 1
.word Object_dispatch_table
IO_protoObj:
.word 1
.word 3
.word IO_dispatch_table
String_protoObj:
.word 2
.word 3
.word String_dispatch_table
.word 0
.asciz ""
.align 8
Int_protoObj:
.word 3
.word 2
.word Int_dispatch_table
.word 0
Bool_protoObj:
.word 4
.word 2
.word Bool_dispatch_table
.word 0
Main_protoObj:
.word 5
.word 1
.word Main_dispatch_table
String_dispatch_table:
.word Object_abort
.word Object_copy
.word String_length
.word String_concat
.word String_substr
Main_dispatch_table:
.word Object_abort
.word Object_copy
.word IO_out_string
.word IO_out_int
.word IO_in_string
.word IO_in_int
.word Main_main
Bool_dispatch_table:
.word Object_abort
.word Object_copy
Object_dispatch_table:
.word Object_abort
.word Object_copy
IO_dispatch_table:
.word Object_abort
.word Object_copy
.word IO_out_string
.word IO_out_int
.word IO_in_string
.word IO_in_int
Int_dispatch_table:
.word Object_abort
.word Object_copy
int_const0:
.word 3
.word 4
.word Int_dispatch_table
.word 22
string_const0:
.word 2
.word 6
.word String_dispatch_table
.word int_const0
.asciz "Hello, World.\n \n\n"
.align 8
.text
Object_init:
pushq %rbp
movq %rsp, %rbp
leave
ret
IO_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
leave
ret
String_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq '', 32(%rbp)
movq [=15=], 24(%rbp)
leave
ret
Int_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq [=15=], 24(%rbp)
leave
ret
Bool_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq [=15=], 24(%rbp)
leave
ret
Main_main:
pushq %rbp
movq %rsp, %rbp
subq , %rsp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rdi
leaq string_const0(%rip), %rax
movq %rax, %rsi
movq 16(%rdi), %r10
movq 16(%r10), %r10
callq* %r10
leave
ret
Main_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq IO_init
leave
ret
错误:
ld: in section __DATA,__data reloc 0: length < 2 and X86_64_RELOC_UNSIGNED not supported
看起来像是一种相当晦涩的说法,即您的对象已分配 space 以将偏移量存储到可能无法保存在 link 时间生成的偏移量的数据项中。
快速查看您的代码表明您使用 .word
和一个值标签。一个示例 .word Object_protoObj
,其中 Object_protoObj
offset 是一个标签。指令 .word
允许 0x0000 和 0xffff(16 位)之间的值。 linker 错误可能表明它生成的标签的偏移量不适合 16 位字。
也许您应该使用 .quad
(允许 64 位值)或 .int
(32 位值)?我不知道您将如何访问表中的这些偏移量,因此您必须根据您的使用要求选择 .quad
或 .int
。