------- Additional Comments From amodra at bigpond dot net dot au 2005-09-07 13:20 ------- This is not a problem with dynamic stack allocation, but rather with the instrumentation code.
The following diagram is supposed to show what the V4 stack layout looks like just after the function prologue, then a little later after some dynamic space has been allocated (eg. alloca or dynamically sized variables). The thing to note is that the old 8 byte stack header (consisting of the back chain and lr save space) before dynamic allocation becomes part of the new dynamic area, and a new stack header is just below. The old stack header thus can be overwritten, and this is what happens for certains sizes of dynamic vars. Missing this fact is no doubt why comment #2 incorrectly claims that not enough space is allocated. |------------| |------------| | lr save | | lr save | |------------| |------------| | back chain | | back chain | |------------|<- |------------|<- | reg save, | | | reg save, | | | local vars | | | local vars | | | | | etc. | | | etc. | | 8| | | | | | |------------| | |------------| | 4| | | | dynamic | | |------------| | | var | | 0| back chain |--- | space | | FP,SP->|------------| FP->| | | | | | | | | 8| | | |------------| | 4| | | |------------| | 0| back chain |--- SP->|------------| The error is that the instrumentation code on function exit tries to access the old stack header via FP. gcc-4.0 and gcc-4.1 avoid this problem by calling the instrumentation function after the dynamic space has been deallocated. I should note that gcc typically allocates too much dynamic space (to allow for a non-aligned initial stack pointer, which doesn't happen for ppc) and this is why most sizes of dynamic variables don't cause a problem. -- What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|amodra at bigpond dot net |unassigned at gcc dot gnu |dot au |dot org Status|ASSIGNED |NEW Known to work| |4.0.2 4.1.0 Summary|[PPC] -finstrument-functions|[3.4 only] -finstrument- |and variable size with sizes|functions and dynamic stack |> 17 and -fPIC |allocation http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11015