Search code examples
linkerllvm6502

Linking xo65 object files with ELF objects and LLVM IR files


I have a bunch of LLVM IR / BC files that, at the moment, I am compiling to native code with LTO using clang:

llvm-mos/bin/clang 
  --config llvm-mos-sdk/build/commodore/64.cfg \
  -O2 \
  -o _build/chip8.prg  \
  _build/dir.c.ll  \
  _build/interrupt.c.ll \
  _build/main.c.ll  \
  _build/dir.s.o  \
  _build/panic.ll.bc \
  rs/target/release/deps/chip8_engine-2a1bf4bc9333b677.bc \
  rs/target/release/deps/chip8_c64-a95cc9a5a3e99697.bc

Here, I am consuming three kinds of input files:

  • The .ll files are LLVM IR files
  • The .bc files are LLVM BC files
  • The .o file is an ELF file (file reports it as ELF 32-bit LSB relocatable, *unknown arch 0x1966* version 1 (SYSV), not stripped)

This works, but now I would like to add some xo65 object files compiled with CC65 to the mix. I can't just add them to the clang invocation, because that fails on ld.lld guessing the file's meaning wrong:

ld.lld: error: _build/native/readdir.c.o:30: unclosed quote

So my question is, what are my options for linking together these files? The obvious solution would be to just compile readdir.c using clang, foregoing CC65 (and thus the xo65 object file format); unfortunately, that is easier said than done, because readdir.c imports a whole load of low-level platform-specific imports that are written in an assembly syntax that isn't compatible with LLVM's assembler.


Solution

  • I have found a relevant feature request ticket in the LLVM-MOS issue tracker. As of 2021-09-13, the answer to this question is in the negative: this is an open problem with no implemented solution.