lkml.org 
[lkml]   [2002]   [Jan]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] C undefined behavior fix
On Wed, Jan 02, 2002 at 06:17:09PM -0700, Tom Rini wrote:
>
> I'm partial to Paul's' suggestion of redoing RELOC and friends in asm.


So am I--with the portable fallback of turning RELOC into an extern
function. As an added benefit, that would probably eliminate a lot
of individual offset variables and hide the ugliness in a single place.

Just so it's documented, here's why I think the changes I coined earlier
won't work:

(1) Turn offset into an extern variable.

This doesn't work in cases like "strlen("string" + offset)", which the
compiler may translate to the equivalent of "strlen("string") - offset",
ie. "6 - offset" which of course still breaks.


(2) Cast to const volatile void *.

This *might* work, because gcc ought to suppress some optimizations upon
finding the 'volatile,' but the volatile would have to be cast out again
to make functions accept it as a nonvolatile parameter. And if it's cast
out, gcc might decide to ignore it as well--or even perform its regular
constant propagation regardless. Not casting the volatile away again
OTOH might make the code a lot slower.


(3) Use -fPIC.

This isn't supported by all architectures, and requires special linker
support which may not be available yet at the time it's needed.

IIRC SAS/C used to have an option to allocate strings in the same
section of the object file as the code, and use PC-relative addressing
to get at them. Anyone know if gcc has anything like that? That should
also fix the problem by deferring computation of the string's address
to computation time. Frankly though I don't even know if all
architectures have PC-relative addressing...


> Well, RELOC _always_ is doing funny arithmetic, and there's not much we
> can do about it. At this point in the bootup we aren't running where
> things think we are yet, and have to adjust things as such.

The arithmetic can't be helped--agreed. We just have to break some
assumptions that gcc is allowed to make based on the information it has
and the C memory model.

Let's just make sure we break them beyond repair. :-)


Jeroen

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:15    [W:0.118 / U:1.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site