I have exported Rust code to a LLVM-IR (.ll
) file and was able to compile and link it manually using both, clang
and llc
+ link.exe
. It required to link against a lot of system libraries, Rust libraries and a temporary generated .o
file from Rust. I am developing on Windows.
My goal is to run the .ll
file using lli
. For this I have to tell lli
where to find the missing symbols. I couldn’t get the solution from this question to work. I tried -load
and -extra-archive
+ -extra-object
. Sadly, there is no output, not even if the sources where found.
For clang
it was necessary to add 3 types of sources:
- Rust libraries, e.g.:
C:Users$USER_NAME.rustuptoolchainsstable-x86_64-pc-windows-msvclibrustlibx86_64-pc-windows-msvcliblibstd-$RANDOM_STRING.rlib
- System libraries, e.g.:
-lws2_32
- And a temporary file generated by running
cargo rustc --release -- -C save-temps
:.targetreleasedeps$PROJECT_NAME.$RANDOM_STRING.rcgu.o
How do I pass these files to lli
correctly?
Context
My goal is to debug the Rust generated LLVM-IR. I found this answer but found this tool to be more promising. However, it requires lli
as far as I can tell.
Update
The correct way of linking is before passing the .ll
file. This way lli
is complaining about wrong paths, etc. Libraries are passed with:
- Rust libraries, e.g.:
--extra-archive="C:Users$USER_NAME.rustuptoolchainsstable-x86_64-pc-windows-msvclibrustlibx86_64-pc-windows-msvcliblibstd-$RANDOM_STRING.rlib"
- And a temporary
.o
file:--extra-object=".targetreleasedeps$PROJECT_NAME.$RANDOM_STRING.rcgu.o"
- System libraries
.lib
would be:--extra-archive="C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.29.30133libx64msvcrt.lib"
However, ‘lli’ is still complaining about not found symbols which are in ws2_32.lib
and userenv.lib
. For some reason it cannot load them from the static library, but clang can when building? Adding windows libraries dynamically fixed it:
--load="C:WindowsSystem32ws2_32.dll"
Yet, there is another error:
LLVM ERROR: Could not resolve external global address: __rust_no_alloc_shim_is_unstable
The allocator shim was supposed to be added with the temporary file. And I assume it is this way when building with clang.