This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug inline-asm/11807] GCC should error out when clobering the stack pointer or frame pointer


------- Additional Comments From bmills at andrew dot cmu dot edu  2003-11-17 12:39 -------
Presumably if the programmer is intentionally, explicitly clobbering the frame
pointer, the base pointer, or both using inline assembly, they are doing so
knowing full well what they are doing -- and are attempting to do something
unusual and specific with the stack.  We should certainly take this into
consideration when making decisions about what is the correct action for gcc to
take.

The assertion that there is no useful application for such clobbering is false,
as careful adjusting of the frame and base pointers in assembly interleaved with
struct/array accesses in C can produce fairly elegant context-switching code for
multiplexing between threads/processes.  Other applications may exist.

Given that this is the case, it seems that gcc should do one of the following to
provide "correct" behaviour:

1. (the obvious solution) Fail.  If this is the case it should be noted in the
inline assembly documentation that clobbering the frame or stack pointer will
result in a compile-time error.

2. (refinement of Falk's #2) Insert code to save the stack and/or frame pointers
in other registers before the clobber and restore them prior to usage (which
would entail some very sophisticated code and would probably frustrate
programmers who are intentionally abusing the stack discipline, but it would not
be unreasonable).  This doesn't seem like a viable solution, because it would
entail tracking changes through large sections of code and adding significant
amounts of extremely complex register copying, but would not add much in the way
of usefulness other than letting programmers use the stack and/or frame pointers
for arithmetic (not very useful at all).

3. (not considered in this thread so far, because it relies on the assumption
that the programmer knows they're munging the stack) Emit code for function
calls which takes the clobbering of the stack pointer into account when
generating function calls and returns -- don't over-write anything above the
stack pointer when making a function call, but allow arbitrary changes to the
frame pointer, being careful not to use it for any other arithmetic (setting the
frame pointer manually being tantamount to context-switching the execution of
the function).  This is arguably the most intuitive (and useful) behaviour (and
the one that has the most obvious application to context switching), although it
would also require quite a bit of fairly sophisticated code to track the changes
to the stack pointer enough to emit correct function calls.  This is possible to
implement, although it may be quite difficult given the GCC codebase.


I would suggest testing and implementing Falk's patch (solution #1) for now to
preserve correct compilation in the immediate future, with an eye toward
possibly implementing #3 at a later date.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11807


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]