Re: GCC and Linux

Richard B. Johnson (root@analogic.com)
Mon, 28 Apr 1997 21:19:38 -0400 (EDT)


On Mon, 28 Apr 1997, David S. Miller wrote:

> Date: Mon, 28 Apr 1997 17:47:34 -0400 (EDT)
> From: "Richard B. Johnson" <root@analogic.com>
>
> If I push the damn flags onto the stack, they damn-well be
> there when I pop them off. Not so with the GCC Compiler. It
> looks as though it secretly "levels" the stack and I don't
> know why. If so, it is broken and should be fixed instead
> of work-arounds everywhere in the code.
>
> Gcc must know precisely how the stack is layed out in order to know
> where local values on the stack are, and where it can stick
> temporaries for when register contention is larger than can fit
> completely in the register set during a block of code.
>
> If you change the stack pointer (which pushfl and popfl both do) you
> change where all those offsets are. Currently there is no way to tell
> GCC "I changed the stack behind your back, please change your offsets
> so you can still get to the variable slots on there"
>
> It is not a trivial thing to implement either. GCC would have to do
> basic block analysis for all code paths from a pushfl to a popfl and
> vice versa, make sure it does the adjustments in all the right places
> etc. Consider the complexity of outputting the correct code for:
>
> a:
> if(condition)
> pushfl
> do some
> other
> stuff
> b:
> if(some other condition not known at time 'a' is run)
> popfl
>
> You can code up millions of examples like this, the "I changed the
> stack" GCC extension you'd have to write would need to handle all of
> them. At best, the above example would require two, yes two, versions
> of the code path between "a" and "b" to be output, how could this be
> more efficient than just doing it the way it is done now? It isn't.
>
> If anything the Intel is broken for not providing any other way to get
> the EFLAGS other than the one which exists and changes the stack frame
> on you.

Well that's what BP is for in the intel machines. But I forgot that
GCC thinks Intel is backwards and pretends everything is a 68000.

Intel even has built-in MACROS called ENTER and LEAVE. You get the
necessary SUB ESP,length_of_local_data for free, i.e., no clock
cycles. Of course the kernel is compiled with -fomit-frame-pointer so
there goes that.

Normally one would do:

PUSH EBP
MOV EBP,ESP
SUB ESP,local_data_len

; access local variables as
MOV EAX,DWORD PTR [EBP - wherever_it_is_on_the_stack]
; etc.

....
MOV ESP,EBP
POP EBP
RETF

Or use the ENTER and LEAVE built-in.

Cheers,
Dick Johnson
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard B. Johnson
Project Engineer
Analogic Corporation
Voice : (508) 977-3000 ext. 3754
Fax : (508) 532-6097
Modem : (508) 977-6870
Ftp : ftp@boneserver.analogic.com
Email : rjohnson@analogic.com, johnson@analogic.com
Penguin : Linux version 2.1.35 on an i586 machine (66.15 BogoMips).
Warning : I read unsolicited mail for $350.00 per hour. Supply billing address.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-