Hi,

Compiling ruby on x86_64 with -D_FORTIFY_SOURCE=2 will cause failure in the
testsuite.

This can be reproduced with
GNU C version 4.1.0 20050819 (experimental) (x86_64-unknown-linux-gnu)

Here is a simplified testcase.

extern void abort (void);

#undef memcpy
#define memcpy(dst, src, len) \
  __builtin___memcpy_chk (dst, src, len, __builtin_object_size (dst, 0))

int
main (void)
{
  static const char data[] = { 0, 0x40, 0xe2, 0x01, 0x00, 0x01, 0x80, 0xc0, 
0x1d };
  const char *s = &data[1];
  int natint = data[0];
  unsigned long tmp = 0;

  memcpy (&tmp, s, natint ? sizeof(tmp) : 4);
  if (sizeof(tmp) > 4 && (tmp >> 32) != 0) /* movq generated? */
    abort ();

  return 0;
}

-- 
           Summary: __builtin___memcpy_chk miscompilation
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gbeauchesne at mandriva dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23484

Reply via email to