我在网上搜索了一段时间,还没有看到任何类似的问题。Mac操作系统:ld:在__DATA,__数据reloc 0:长度<2和X86_64_RELOC_UNSIGNED不支持
因此,我正在编写一个小型编译器,将语言编译为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 $0, 24(%rbp)
leave
ret
Int_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq $0, 24(%rbp)
leave
ret
Bool_init:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rdi
callq Object_init
movq $0, 24(%rbp)
leave
ret
Main_main:
pushq %rbp
movq %rsp, %rbp
subq $8, %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
如果我不得不冒险猜测 - 您正在使用'.word'来存储标签的偏移量。 '.word'我相信是16位的,你可能试图将偏移量放在不能用16位表示的标签上。也许你打算在这些情况下使用'.int'或'.quad'? –
@MichaelPetch谢谢,这解决了这个问题 –