[RFC]: patch to detect invalid and missing ATTRIBUTE const/pure

Jan Hubicka jh@suse.cz
Fri Mar 22 07:10:00 GMT 2002


>  > From: John Wehle <john@feith.com>
>  > 
>  > With your change mark_constant_function will attempt to mark
>  > non-static functions which can cause problems due to potentially
>  > differing implementations of a routine present in a shared library.
>  > -- John
> 
> I don't quite understand how that arises.  Here's my understanding:
> 
> Supposing mark_constant_function is examining an extern function foo,
> let's say it decides to mark foo as pure.  That marking only takes
> effect for the rest of that module since the extern prototype of foo()
> seen by other files still doesn't have the attribute automatically
> added to it.
> 
> Now any calls to foo() inside the original module would resovle to the
> definition inside the file, regardless of whether we eventually link
> with a shared lib having another copy of foo, right?  In that case,
> we can't have the "differing implementations" problem AFAICT.
> 
> Can you help me understand where this reasoning is flawed?  (Or if its
> already been discussed, just point me at the URL.)

My understanding is that in the case of shared library, one may overwrite
function foo with external implementation that is not pure.  Since the file
containing original version of foo will have all call sites to foo compiled
like foo was pure, bad things may happen.

I think similar problem has inlining and no one complained for a years, but
the decision has been to be conservative here.

Honza
> 
> 		Thanks,
> 		--Kaveh
> --
> Kaveh R. Ghazi			Director of Systems Architecture
> ghazi@caip.rutgers.edu		Qwest Global Services



More information about the Gcc-patches mailing list