I'm trying to compile code containing the following function:
void print_stacktrace()
{
void *addr;
asm("mov %0, esp;" : "=r" (addr));
}
As you can see there is some inline i386 assembly involved. The problem is, when trying to run:
clang -masm=intel -m32 test.c -o test
The compiler outputs:
Undefined symbols for architecture i386:
"esp", referenced from:
_print_stacktrace in test-093116.o
ld: symbol(s) not found for architecture i386
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
However the code compiles fine on x64 Ubuntu, so it seems problem is OS X specific. How to get this working? I can't believe Apple didn't supply i386 symbols in Xcode Developer tools package (which I have), so maybe something is misconfigured here... Any ideas?
EDIT: So it seems intel syntax is not supported on OS X by default. Is there any way to fix that?