unsupported symbol modifier in branch relocation: “call printf@PLT”
MichaelScofield opened this issue · 2 comments
MichaelScofield commented
Firstly, thank you for sharing this great compiler writing jounery, I'm rather interested!
I'm in chapter 4 (generating assembly code), and trying to follow the code.
Here's the out assembly codes (saved in file "out.s
"):
.text
LC0:
.string "%d\n"
_printint:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %esi
leaq LC0(%rip), %rdi
movl $0, %eax
call printf@PLT
nop
leave
ret
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
movq $2, %r8
movq $3, %r9
movq $5, %r10
imulq %r9, %r10
addq %r8, %r10
movq $8, %r8
movq $3, %r9
movq %r8,%rax
cqo
idivq %r9
movq %rax,%r8
subq %r8, %r10
movq %r10, %rdi
call _printint
movl $0, %eax
popq %rbp
ret
When running it with
cc -o out out.s
, it complained with
out.s:13:2: error: unsupported symbol modifier in branch relocation
call printf@PLT
^
How is the error happened and how to fix it?
Thanks in advance!
PS:
- I am using macOS Catalina 10.15.2
- cc version is
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
- The souce codes are compiled with
cc -o comp1 -g cg.c expr.c gen.c main.c scan.c tree.c
MichaelScofield commented
Nevermind, change to call _printf
works.
DoctorWkt commented
Thanks Michael. I'd be pretty sure the macOS compiler and environment is different enough from Ubuntu/Debian Linux that some changes to the code generator will be required.