I submitted the following GCC bug report a couple of days ago, and had
a discussion with Geoff Keating about asm constraints. It looks as if
the problem I was seeing is a (very) longstanding bug in GCC's reload
pass, and is very unlikely to get fixed.
How does this workaround patch look? I changed the constant-using
functions from io.h into macros. I'm not thrilled by it, but it does
seem to be correct. I have a suspicion we could change the confusing
"i#*X" constraints back to simply "i" - they were part of my effort to
make the inline functions work, before I was defeated by reload. It
should be correct either way, though.
----- Forwarded message from Daniel Jacobowitz <email@example.com> -----
Date: Fri, 9 Mar 2001 18:10:02 -0500
From: Daniel Jacobowitz <firstname.lastname@example.org>
Subject: Inlining bug on MIPS - both 2.95.3 and 3.0 branches
I've put together a testcase for a bug exposed by (accidentally) trying to
build a mipsel-linux kernel with VGA console enabled.
The problem seems to be that we lift a constant term out of a loop into a
spare register. Of course, __builtin_constant_p is still true for it, so in
the original case we chose to use an inline function which required that
argument to be constant. We inline the function using the scratch register
instead of the constant, and we lose.
The inline function seems to me to be doing something dodgy - it specifies
the operand with the constraint "ir", implying that a register would be
acceptable. We're lying to the compiler, so it's not that startling that it
bites us. On the other hand, there's no need to waste a register on this,
so I'm not sure why the constant gets stored in a temporary.
Is the invalid result a compiler bug? I'd say that there is at least a
small optimization bug here, but the "ir" constraint might mean that the
compiler's doing everything as best it can. There doesn't seem to be a way
to use an inline function safely and specify a constant constraint on one
argument to the function - does this need to be a macro?
----- End forwarded message -----
Daniel Jacobowitz Debian GNU/Linux Developer
Monta Vista Software Debian Security Team
"I am croutons!"
Description: Text document