[Bug ada/15644] New: invalid read in multitasking stack trace code

gcc-bugzilla at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed May 26 04:43:00 GMT 2004


When an exception is raised in a multitasking program (see below), valgrind
reports that the code in __gnat_backtrace is reading from an invalid memory
location.  I've been seeing segmentation faults in a large multitasking program
at exactly the line that valgrind reports.  When I started cutting away code to
find a minimal example, the segmentation fault went away but valgrind still
notes the same invalid read, so hopefully the example code I came up with is
relevant to the original segmentation fault problem.  This is with the CVS
version of gcc from just before the tree-ssa merge, but I've been seeing the
this problem for several months.  Needless to say it only occurs when using
the -E binder switch, since otherwise __gnat_backtrace is never called.

$ gnatmake -g example -bargs -E
gcc -c -g example.adb
gnatbind -aO./ -E -I- -x example.ali
gnatlink example.ali -g
$ valgrind --tool=memcheck ./example
==25638== Memcheck, a memory error detector for x86-linux.
==25638== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
==25638== Using valgrind-2.1.2.CVS, a program supervision framework for x86-linux.
==25638== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
==25638== For more details, rerun with: -v
==25638==
==25638== warning: Valgrind's pthread_setschedparam does nothing
==25638==          (scheduling not changeable)
==25638==          your program may misbehave as a result
==25638== warning: Valgrind's pthread_attr_destroy does nothing
==25638==          your program may misbehave as a result
==25638== warning: Valgrind's pthread_setschedparam does nothing
==25638==          (scheduling not changeable)
==25638==          your program may misbehave as a result
==25638== Thread 2:
==25638== Invalid read of size 1
==25638==    at 0x805E20A: __gnat_backtrace (tracebak.c:386)
==25638==    by 0x805BC3D: system__traceback__call_chain (s-traceb.adb:86)
==25638==    by 0x8054421: ada__exceptions__call_chain (a-excach.adb:61)
==25638==    by 0x8053A7F: ada__exceptions__exception_propagation__propagate_exceptionXn (a-exexpr.adb:440)
==25638==  Address 0xB800F5AC is not stack'd, malloc'd or (recently) free'd
==25638==
==25638== Thread 2:
==25638== Invalid read of size 1
==25638==    at 0x805E210: __gnat_backtrace (tracebak.c:386)
==25638==    by 0x805BC3D: system__traceback__call_chain (s-traceb.adb:86)
==25638==    by 0x8054421: ada__exceptions__call_chain (a-excach.adb:61)
==25638==    by 0x8053A7F: ada__exceptions__exception_propagation__propagate_exceptionXn (a-exexpr.adb:440)
==25638==  Address 0xB800F5AA is not stack'd, malloc'd or (recently) free'd
==25638==
==25638== Thread 2:
==25638== Invalid read of size 1
==25638==    at 0x805E216: __gnat_backtrace (tracebak.c:386)
==25638==    by 0x805BC3D: system__traceback__call_chain (s-traceb.adb:86)
==25638==    by 0x8054421: ada__exceptions__call_chain (a-excach.adb:61)
==25638==    by 0x8053A7F: ada__exceptions__exception_propagation__propagate_exceptionXn (a-exexpr.adb:440)
==25638==  Address 0xB800F5AE is not stack'd, malloc'd or (recently) free'd
==25638==
==25638== Thread 2:
==25638== Invalid read of size 1
==25638==    at 0x805E21C: __gnat_backtrace (tracebak.c:386)
==25638==    by 0x805BC3D: system__traceback__call_chain (s-traceb.adb:86)
==25638==    by 0x8054421: ada__exceptions__call_chain (a-excach.adb:61)
==25638==    by 0x8053A7F: ada__exceptions__exception_propagation__propagate_exceptionXn (a-exexpr.adb:440)
==25638==  Address 0xB800F5AF is not stack'd, malloc'd or (recently) free'd
==25638== warning: Valgrind's pthread_cond_destroy is incomplete
==25638==          (it doesn't check if the cond is waited on)
==25638==          your program may misbehave as a result
==25638==
==25638== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 15 from 1)
==25638== malloc/free: in use at exit: 12280 bytes in 5 blocks.
==25638== malloc/free: 12 allocs, 7 frees, 24756 bytes allocated.
==25638== For a detailed leak analysis,  rerun with: --leak-check=yes
==25638== For counts of detected errors, rerun with: -v
$

Environment:
System: Linux pbaldrick 2.4.21-215-default #1 Tue Apr 27 01:00:43 UTC 2004 i686 i686 i386 GNU/Linux
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/gnat-cvs --enable-threads=gnat --enable-languages=ada,c : (reconfigured) ../gcc/configure --prefix=/usr/gnat-cvs --enable-threads=gnat --enable-languages=ada,c

How-To-Repeat:
Compile the following program using: gnatmake -g example -bargs -E
Run it under valgrind.
--chop here--
procedure Example is

   task A;

   task body A is
   begin
      raise Program_Error;
   end A;

begin
   null;
end Example;
------- Additional Comments From baldrick at free dot fr  2004-05-25 07:35 -------
Fix:
Workaround: compile without the -E binder switch.

-- 
           Summary: invalid read in multitasking stack trace code
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: baldrick at free dot fr
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list