I'v been trying to assemble and link some x86_64 assembler using llvm-mc (13.0.1) and lld (13.0.1) on macos (12.5). I'm using the following procedure to assemble and link:
llvm-mc --filetype=obj -g -o test.o test.s
ld64.lld -arch x86_64 -platform_version macos 12.0.0 12.0.0 -e start -o test test.o
Today I got an error that I don't understand:
ld64.lld: error: BRANCH relocation has width 1 bytes, but must be 4 bytes at offset 1 of __TEXT,__text in test.o
I couldn't find an explanation of this error. Google tells me nothing, and I couldn't find the error by searching the llvm source.
Figuring it has something to do with jumps, I commented out code until the error went away, then worked backwards to make a minimum example showing the issue:
.text
.globl start
start:
main:
endloop:
loop main
The key detail is the endloop label between the loop instruction and the label main to which we are looping. If I comment out the main: label, I don't get the error.
Questions: Anybody know what this error message means? How can I fix the issue? Where are the error messages for llvm's lld documented?