[Bug ada/64057] New: Overlapping memcpy generated for array assignment

2014-11-24 Thread tobiasu at tmux dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64057

Bug ID: 64057
   Summary: Overlapping memcpy generated for array assignment
   Product: gcc
   Version: 4.9.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ada
  Assignee: unassigned at gcc dot gnu.org
  Reporter: tobiasu at tmux dot org

Created attachment 34099
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34099&action=edit
memcpy wrapper with overlap detection

The Ada front end generates a overlapping memcpy call for some array
assignments.

Using a strict version of memcpy that checks for overlap breaks gnat 4.8 and
4.9 on my Linux and OpenBSD test systems. Other applications compiled with gnat
may be affected as well.

Easy way to reproduce:

Build gnat and ^C once gcc/ada/bldtools/sinfo is generated.
Build the attached memcpy wrapper or patch your libc with checks.

$ cd $BUILD/gcc/ada/bldtools/sinfo
$ LD_PRELOAD=./memcpy.so gdb ./xsinfo
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./xsinfo...(no debugging symbols found)...done.
(gdb) run
Starting program:
/home/tulmer/tmp/gcc/src/gcc-build/gcc/ada/bldtools/sinfo/xsinfo 
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Check for field name consistency
 OK

Check for function consistency
 OK

Check for missing functions
 OK

Check for set procedure consistency
 OK

Check for missing set procedures
 OK

Check pragma Inlines are all for existing subprograms
memcpy(0x6c125c, 0x6c1260, 14)
dest=Set_ABE_Is_Certainbs src=ABE_Is_Certainbs

Program received signal SIGABRT, Aborted.
0x7786aa97 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0  0x7786aa97 in raise () from /usr/lib/libc.so.6
#1  0x7786be6a in abort () from /usr/lib/libc.so.6
#2  0x77bda879 in memcpy () from ./memcpy.so
#3  0x0042c20e in ada.strings.unbounded.set_unbounded_string ()
#4  0x00443b31 in gnat.spitbol.patterns.xmatch ()
#5  0x0044488b in gnat.spitbol.patterns.match ()
#6  0x0040afd0 in csinfo ()
#7  0x0041bb69 in xsinfo ()



Let me know if you need more info


[Bug ada/64057] Overlapping memcpy generated for array assignment

2014-11-24 Thread tobiasu at tmux dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64057

--- Comment #2 from Tobias Ulmer  ---
(In reply to Eric Botcazou from comment #1)
> > Let me know if you need more info
> 
> We need a testcase that fails with GCC 4.8 or GCC 4.9 since xsinfo is built
> by the base compiler.

The base compiler and the test build were made with the same version compiler
and configuration, respectively.

The only difference between the base compiler and the one that's being built as
a test case is the additional check in memcpy to reveal the wonky behaviour. 

I did try to isolate a testcase out of this, but wasn't successful. I would've
provided one otherwise.