Strange locks in the kernel
Basically, I’m busy loading the object code from the mach object file and linking it to the Linux kernel, and when I do
printk from inside that object, I notice something strange. If I call printk (printk(“%d,%
d,%d\n", 1, 1, 1) with more than 3 (4 or more) arguments, the system will lock, but at a later point in time (it will not return from the system call but just lock). In all cases, the actual printing works and prints out the expected values.
Now, oddly enough, this only happens when I build it with Clang+LLVM. Here is the culprit code:
On the other hand, it works just fine when it’s built with LLVM GCC:
This also works when building with GNU GCC:
Can anyone come up with the reason why the clang version is causing the system to lock up? So basically, the first piece of code that causes the system to lock is problematic, but in the rest. I don’t really know what’s wrong.
I don’t know how you generated the object file, but you seem to be using Darwin ABI, which is basically a heavily modified APCS (“old” ARM ABI). However, for Linux etc., you need to use EABI (aka AAPCS), which is different from APCS in many cases.
For example, R9 saves calls in EABI, but calls break on darwin, differs in passing 64-bit values, etc. Note that your clang example breaks R9, and llvm-gcc – no 🙂