I'm running this command on an ARM mac, cross-compiling to ARM Linux...it works fine if I cross-compile to x86_64, but...
zig cc --target=aarch64-linux-gnu -o /Users/foo/main.node /Users/foo/main.o /Users/foo/node-to-roc.c -I/Users/foo/.volta/tools/image/node/16.16.0/include/node -fPIC -pthread -Wall -Wextra -Wendif-labels -W -Wno-unused-parameter -fno-omit-frame-pointer -lc -lm -lpthread -ldl -lutil -lrt -shared
...when I change nothing other than the --target to be aarch64 instead of x64, I get:
LLD Link... ld.lld: error: relocation R_AARCH64_MOVW_UABS_G0_NC cannot be used against local symbol; recompile with -fPIC
>>> defined in /Users/foo/main.o
>>> referenced by builtins-aarch64
>>> /Users/foo/main.o:(roc_builtins.str.str_split)
(a bunch more of these, lots of the same error in different str builtins, like str_split here, graphemes, etc) - anyone know why this might be?
it seems to be saying that main.o
is somehow not compiled with PIC, but:
iirc, the issue isn't pic, it is the linker not having been updated to support that relocation type or something like that
@Brendan Hansknecht hm, the linker as in lld?
yes
hrm
I'm fairly sure this worked a few months ago - I wonder if it's some new zig builtins we added since then?
could that possibly make sense?
Yeah, that would totally make sense.
It is a rare relocation type.
Probably weren't generating it before.
interesting! Is there a way we could change them to not encounter this?
hmm, based on this PR, that relocation theoretically got added to lld in 2016: https://reviews.llvm.org/D24403?id=70987
can you test with ld
to see if you get the same behavior?
is there a way to tell zig to use ld instead of lld?
nm chatGPT told me - trying it now!
Also, you could try changing our builtin build.zig files to set force_pic
yeah ld didn't fix it, I'll try that
also didn't fix it, unfortunately
also I noticed mainForHost
is one of the ones giving the error, so maybe it's not just builtins after all :thinking:
I wonder if we are generating llvm ir that can't be pic on aarch64 and llvm is just giving up. Is pic just a suggestion like the calling convention?
oof, I hope not
what's weird is, I definitely had cross-compiling to arm64 working a few months ago
so I'm not sure what could have changed
also this is the last thing blocking getting TypeScript calling Roc into production at Vendr (finally!), so I really hope it doesn't turn into a big rabbit hole :laughing:
Bisecting to the commit where this broke seems like a good next step.
Last updated: Jul 06 2025 at 12:14 UTC