BSD /lib/crt0.o and frame pointer

John Bruner jdb at mordor.UUCP
Thu Oct 10 02:55:39 AEST 1985


Recently, while helping someone else debug a debugger, I had
occasion to look at the C runtime startup code.  [Since I was
familiar with the PDP-11 version, I was somewhat surprised to
find that the BSD VAX version is written in C (with, of course,
"asm" hacks).]

When the debuggers perform stack tracebacks, they terminate when
a NULL saved frame pointer or invalid frame pointer is encountered.
Unfortunately, the contents of the frame pointer when a program
is exec'd is NOT zero.  Instead, the frame pointer is unchanged
from its value before the exec().  This value is garbage, and since
the C runtime code doesn't clear FP, this garbage value is stored
on the stack when main() is called.  This can play havoc with
stack tracebacks.

This seems like such an obvious bug, and one which (according
to the creation date in the "crt0.c" comments) must have existed
for several years now, that I have to stop and wonder if there
is something obvious that I'm overlooking (?).

If not, the problem can be fixed either in "crt0.c" or in
"../vax/machdep.c" (setregs()) by clearing the FP.  Apparently  
the register-clearing code in setregs() was #ifdef'd out because
(1) it is wrong and (2) it interferes with the kludgey way that
boot parameters are passed to "/etc/init".
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb at mordor [jdb at s1-c.ARPA]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!seismo!mordor!jdb



More information about the Comp.unix.wizards mailing list