Reputation: 31
Trying to familiarize myself with LLVM-IR, but unfortunately I consistently get segfault errors when attempting to compile. I've been testing in particular with this:
define void @main() {
entry:
ret void
}
Which from what I know should work and does indeed not result in an error when used with lli
(I've also tested a 'hello world' I found with similar results, works in lli
but not when compiled)
I've been using llc
and lld
to compile, and I use ubuntu linux (well, bedrock linux but a ubuntu kernal). The versions are consistent (LLVM 10) and I've tested using the gnu linker instead of lld, which has the same result. I've attempted explicitly setting the target triple to no result. I've also tried reinstalling LLVM and related tools, again to no avail. I get the same results on a windows machine through WSL. I have some basic experience with NASM and as I understand it with that you need to make proper syscalls to exit an assembly program gracefully, is perhaps the same true for LLVM-IR? I can only assume I'm doing something terribly wrong, but I can't figure out what it is.
I'm running the commands llc test.ll --filetype=obj && ld.lld test.o && ./a.out
to compile (as stated above I've tried different params).
Any suggestions on what might be happening here?
Edit:
I've tried to step into it with a debugger, I set a breakpoint at main and interestingly it seg faults before it hits that breakpoint. The result from the debugger is:
* thread #1, name = 'a.out', stop reason = signal SIGSEGV: invalid address (fault address: 0x1)
frame #0: 0x0000000000000001
error: memory read failed for 0x0
Other than the 'Process launched' and 'Process stopped' bits this is the only output from the debugger.
Upvotes: 1
Views: 331
Reputation: 1093
can you try using gnu ld, since the error shows error: memory read failed for 0x0
, i assume the linker is messing with the start address. please provide the output of objdump -D a.out
Upvotes: 0