cinvoke-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-dev] OS X x86 trivial port & extreme strangeness.


From: Brad Beveridge
Subject: [cinvoke-dev] OS X x86 trivial port & extreme strangeness.
Date: Wed, 5 Dec 2007 10:12:13 -0800

I've trivially ported gcc_x86_unix.* -> gcc_x86_osx.* with the "cp"
command :)  I'm running OS X Tiger on an X86 Core Duo (note, _not_
x86-64).
Oh, and thanks for this very cool library!

With a little change to the cinvoke.c file to include the correct
arch, the library and tests compile.
The extreme strangeness occurs when I try to run the tests.
Test1 works, and prints.  Then I get EXEC_BAD_INSTRUCTION.
So I started stepping through the source & disassembly with Apple's
sucky Xcode debugger.
I can see c/invoke calling into lib:test1.  Interestingly, lib:test1
doesn't call printf, it calls puts - I assume this is the compiler
being smart.

Then I can see lib:test2 being run.  Everything looks fine, the
literal 22 is on the stack, I call printf.  It looks like because lib
is a dynamic library, it does lazy resolution of the printf call, so I
bounce through what looks to me like a memory fault & then the DL
loader function.  In here I hit an invalid instruction.  The debugger
doesn't catch the "memory fault", but I kind of expect that - is that
normal?

Now, the really weird thing is this, if I:
 - Force lib:test1 to actually call printf by supplying my own
argument to printf, OR
 - Manually call lib:test2 by casting it to a function & calling, OR
 - call test3 first
Then all the tests run & return good results!

I don't have any good ideas on what is going on.  I'm not that
familiar with x86 assembly, but it looks like the stack discipline is
being maintained.  Any thoughts on what might be going on, or steps I
can take to debug this?

Cheers,
Brad




reply via email to

[Prev in Thread] Current Thread [Next in Thread]