This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils 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]

Re: Detecting wrong linkage on mips PIC code


On Fri, 24 Jun 2005, Atsushi Nemoto wrote:

> This simple queer program does not work on mips-linux if compiled with
> -O2 option.  It works if compiled with -O.  I'm using gcc 3.4.4 and
> binutils 2.16.1.
> 
> int main(int argc, char **argv)
> {
> 	static long int random(void);
> 	random();
> 	return 0;
> }
> 
> Declaring random() as a static function is definitely wrong, but I
> wonder why none of gcc, as, or ld give me any error or warning.
[...]
> Is it possible to detect this sort of error when compiling or linking?

 It is.  With GCC 4.0.0 I get:

static.c: In function 'main':
static.c:3: error: invalid storage class for function 'random'

Also this program, which is similarly incorrect:

long int random(void);

int main(void)
{
	random();
	return 0;
}

static long int random(void)
{
	return 0;
}

compiles to bad code with GCC 3.4.x and is rejected by 4.0.0.

  Maciej


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