Porting to Darwin

"Brian de Alwis" <[email protected]> Mon, 9 Jun 2008 11:06:50 -0600
Newsgroups gmane.comp.lang.smalltalk.strongtalk
Message-ID <[email protected]>
Hi everybody.

I've got the gcc-linux branch to build on Darwin (modulo thread per-time
accounting), and the basic easyunit tests pass.  But running the actual VM
crashes with what looks to be a NULL pointer dereference, which might be
occurring because of a stack alignment issue.  Running with
"+TraceLookupAtMiss" shows that the problem occurs when starting to run
ProcessorScheduler::start.  See further below for the backtrace; the problem
arises in __dyld_misaligned_stack_error, and frame #1 is very suspicious
looking.  The call in DeltaProcess::last_frame is simply creating a 'frame'
object:

840:    frame c(last_Delta_sp(), last_Delta_fp());

Although this could arise because of dynamic linking issues, I'm speculating
that the NULL dereferencing is occurring because of Darwin's slightly
different calling conventions.  In Darwin, EBX must be preserved within
position-independent code and the stack must be 16-byte aligned:

The IA-32 environment uses a stack that—at the point of function calls—is
16-byte aligned, grows downward, and contains local variables and a
function's parameters. Each routine may add linkage information to its stack
frame, but it's not required to do so. Figure 1 shows the stack before and
during a subroutine call.


<
http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/IA32.html#//apple_ref/doc/uid/TP40002492-DontLinkElementID_9
>

It's been ages since I've done an IA32 assembly, but I tried the obvious
changes of pushing and popping ebx in MacroAssembler::enter and
MacroAssembler::leave in vm/asm/assembler.cpp, and adjusting some of the
calls in vm/code/stubRoutines.cpp to instead call masm->leave() rather than
pop off ebp directly, but to no apparent avail.  I'm not quite sure how to
ensure the stack is 16-byte aligned.

Or I just had another thought, that the DeltaProcess is tracing back through
the stack and is unaware of ebx possibly having been pushed on the stack?

Does anybody have any pointers or advice?

Brian.

=================================
(gdb) run -b ../strongtalk.bst
Starting program:
/Users/bsd/personal/Projects/Strongtalk/port-darwin/build/strongtalk -b
../strongtalk.bst
Reading symbols for shared libraries +++. done

Smalltalk Virtual Machine by LongView Technologies LLC
---------------------------------------------------------
(c) 1994-1997 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use and distribution of this software is subject to the
terms of the attached license.
---------------------------------------------------------
Version 1.1 (build Jun  8 2008 22:29:44)
(use argument -? for a list of flags)

- VM is in debug mode
[Reading in ../strongtalk.bst, n, 0.332 secs]
[Switching to process 66972 thread 0x317]

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x00000000
0x8fe18b42 in __dyld_misaligned_stack_error ()
(gdb) where
#0  0x8fe18b42 in __dyld_misaligned_stack_error ()
#1  0x00000001 in ?? ()
#2  0x00117cd2 in DeltaProcess::last_frame (this=0x400870) at
process.cpp:840
#3  0x0009a101 in InterpretedIC::inline_cache_miss () at
interpretedIC.cpp:589
#4  0x001cf1cc in interpreter_code ()
#5  0x0022285c in StubRoutines::_code ()
#6  0x0010d4a4 in Delta::call_generic (ic=0x221d20, receiver=0x100032d,
selector=0x10a4029, nofArgs=0, args=0x0) at delta.cpp:114
#7  0x0010d52b in Delta::call (receiver=0x100032d, selector=0x10a4029) at
delta.cpp:119
#8  0x00116601 in DeltaProcess::launch_delta (process=0x400870) at
process.cpp:413
#9  0x00113e2f in mainWrapper (args=0x400900) at os_darwin.cpp:211
#10 0x903d86f5 in _pthread_start ()
#11 0x903d85b2 in thread_start ()
=================================

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Strongtalk-general" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/strongtalk-general?hl=en
-~----------~----~----~----~------~----~------~--~---