[Ecls-list] Bug in code detecting stack growth direction

Gabriel Dos Reis gdr at integrable-solutions.net
Fri Feb 3 16:24:54 UTC 2012


On Fri, Feb 3, 2012 at 10:13 AM, Juan Jose Garcia-Ripoll
<juanjose.garciaripoll at googlemail.com> wrote:

> ECL is assuming that local variables are kept in the stack. Is this wrong?

What is undefined behaviour isn't assuming the notion of "stack" -- which the
C standard effectively does not know about.

The crucial point is that it is undefined to compare the address of two distinct
objects for relative position (e.g. before or after) unless they are part of
an array  (or one last the end address.)

> Perhaps, but this is an implicit assumption in all C garbage collectors I
> know and so far no compiler has broken this assumption. It is an undefined
> behavior as per the ANSI C specification, but that is not what broke the
> code ECL used.

That wasn't it (thought it could have.)

> What broke the test is the fact that the functions from the test were
> inlined and thus the local variables ended up in a different order in the
> stack, not the original assumption.

Exactly.  Because the local variables were distinct objects.

> I have made the code non-deterministic
> so most compilers will not inline the calls and hopefully the growth test
> works.

I hope you realize that it is just delaying the breakage point in time.

>
> Finally, though the test is fragile, it is not critical. Stack growth
> direction is only used in two places
>
> 1* In ECL's code for detecting stack overflows. We might do without it, but
> graceful handling of stack overflows based on alternative stacks proved to
> be useless due to the signal-async problem.
>
> 2* In the Boehm-Weiser garbage collector to detect the extent of the stack
> on different threads. As I said, this is a common assumption across C
> implementations of garbage collectors and so far never broken.

This confusese two things: (1) the existence of a stack; (2) the
direction of growth.
The test for (2) is invoking an undefined behaviour.  Therefore, the outcome of
that test does not say anything about the collector's assumption that there is
a stack (1) and a defined direction of growth.

>
> So all in all, the broken test only affected "1" and now it seems to work.
>
> Best,
>
> Juanjo
>
> --
> Instituto de Física Fundamental, CSIC
> c/ Serrano, 113b, Madrid 28006 (Spain)
> http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list