delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/10/28/22:19:43

Date: Tue, 28 Oct 1997 19:18:55 -0800 (PST)
Message-Id: <199710290318.TAA13003@adit.ap.net>
Mime-Version: 1.0
To: djgpp-workers AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Suggestions for startup code

(previously posted to djgpp AT delorie DOT com)
A potential problem with the startup code, when profiling:

1. In `src/libc/crt0/mcount.c'. It seems, from looking at generated
assembly, that mcount(), the function which counts calls to profiled
functions, gets an argument in the %edx register. But the value is fetched
using inline assembly from C, and several lines into the code. IMHO, this is
dangerous. There's nothing to stop the compiler from using %edx for
something else before that line gets a shot at it. Admittedly, the current
version of GCC doesn't, but future versions might. I think it would be a
better idea to put an assembly wrapper around the function. Perhaps just this:

.global _mcount
_mcount:
        pushl %edx
        call real_mcount
        popl %edx  # smaller than addl $4,%esp
        ret

Then the existing mcount() would be changed to real_mcount, and have these args:

void real_mcount(MTABE **cache, int _to);

since `cache' is the variable into which %edx is moved. Since the address of
_to is used to peek around on the stack, all references to `&_to' in the
function would be changed to `&_to+1' (since it is now 1 stack slot lower
than otherwise).
[Another issue already addressed and deleted]

Just my $0.02. If anyone has any other ideas, let me know.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019