Ulrich Weigand changed bug 955832
What Removed Added
CC   amodra@bigpond.net.au, uweigand@de.ibm.com

Comment # 12 on bug 955832 from
(In reply to Michael Matz from comment #7)

> So it wants to inspect the first couple bytes (here eight) of the std::rand
> function to seed some rng. 

This seems a bug.  It looks like the intent was to look at the *address* of the
std::rand function, which would make more sense since this will profit from
address space randomization on many platforms.  This would also explain using
the size of a function pointer as size.

> Compiling this with -O2 (either with gcc or g++) produces a 'rand - 1'
> relocation, but binutils happily links it nevertheless.
> 
> Possibly it requires something more to trigger the problem in binutils,
> like a large .toc or so.

It turns out the only extra thing it requires is some *other* reference to
"rand" as a normal function call in addition to the weird "rand - 1" one.

Changing your test case to:

------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

int main()
{
  int sum = rand();
  const char *p = (const char*)&rand;
  const char *end = p + sizeof (void (*) ());
  for (; p != end; ++p)
    sum += *p;
  printf ("%d\n", sum);
  return 0;
}
------------------------------------------------

triggers the error with "gcc -O".

@Alan: Does this look like a linker bug?


You are receiving this mail because: