Traumflug / simulavr

A fork of SimulAVR (http://www.nongnu.org/simulavr/) for handling contributions. The practical SIMINFO mechanism implemented here wasn't accepted upstream, but is crucial for Teacup Firmware simulations, so this fork will stay ... and follow upstream. Default branch is 'traumflug', master here matches master on nongnu.org.
GNU General Public License v2.0
40 stars 26 forks source link

segfault in tcl examples #2

Open pat1 opened 10 years ago

pat1 commented 10 years ago

cd simple_ex1 make do ../simulavr.tcl -d at90s8515 -f fred.elf \ -W 0x20,- -R 0x22,- -T exit make: *\ [do] Segmentation fault (core dumped)

compiling with -g and using core file in gdb: Core was generated by `/usr/bin/tclsh ../simulavr.tcl -d at90s8515 -f fred.elf'. Program terminated with signal 11, Segmentation fault.

0 0x000000000008b0d6 in Tcl_GetVar@plt ()

Missing separate debuginfos, use: debuginfo-install glibc-2.17-20.fc19.x86_64 libgcc-4.8.2-7.fc19.x86_64 libstdc++-4.8.2-7.fc19.x86_64 tcl-8.5.14-1.fc19.x86_64 zlib-1.2.7-10.fc19.x86_64 (gdb) where

0 0x000000000008b0d6 in Tcl_GetVar@plt ()

1 0x00007f53bf1ce3ff in SWIG_Tcl_GetModule (interp=0x1786670)

at simulavr_wrap.cxx:1193

2 SWIG_InitializeModule (clientdata=0x1786670) at simulavr_wrap.cxx:23212

3 Simulavr_Init (interp=0x1786670) at simulavr_wrap.cxx:23465

4 0x000000307f2a1249 in ?? () from /lib64/libtcl8.5.so

5 0x000000307f234244 in ?? () from /lib64/libtcl8.5.so

6 0x000000307f23525e in ?? () from /lib64/libtcl8.5.so

7 0x000000307f235796 in Tcl_EvalEx () from /lib64/libtcl8.5.so

8 0x000000307f29be72 in Tcl_FSEvalFileEx () from /lib64/libtcl8.5.so

9 0x000000307f2a25a3 in Tcl_Main () from /lib64/libtcl8.5.so

10 0x00000000004007d0 in ?? ()

11 0x0000000000000000 in ?? ()

If I use the original simulavr git from clone git://git.savannah.nongnu.org/simulavr.git the tcl example work as expected.

this is my configure: ./configure --enable-python --enable-tcl --enable-verilog --enable-dependency-tracking --with-bfd=/home/pat1/compilazioni/binutils-2.24/bfd/ --with-libiberty=/home/pat1/compilazioni/binutils-2.24/libiberty CXXFLAGS=-g CFLAGS=-g --no-create --no-recursion

and this the configuration for binutils 2.24: ./configure --prefix=/usr --libdir=/usr/lib64 --mandir=/usr/share/man --infodir=/usr/share/info --target=avr --disable-werror --disable-nls CFLAGS=-fpic CXXFLAGS=-fpic

miso- commented 10 years ago

It doesn't work because of unresolvable _Z7ELFLoadPK9AvrDevice symbol that comes from src/simulavr_wrap.cxx generated by SWIG from src/avrdevice.h. Fix is here. As for the segfault: It's caused by double call to dlopen() with the same file as argument in TclpDlopen. First call fails, as it should, with "undefined symbol: _Z7ELFLoadPK9AvrDevice" errstring, then in second dlopen call, _dl_map_object finds mapping left over by previous unsuccessful dlopen call. This is then returned by dlopen as handle. So program ends up with non-zero handle and garbled GOT, this later leads to segfault.

This dlopen behaviour appears to be known, though undocumented "feature".

Traumflug commented 10 years ago

Thanks a lot for the contribution, miso-. Just picked all three of your additional commits (from both topic branches) onto the traumflug branch here, it appears to work fine (as it did for me before).

A bit off topic, running RepRap firmwares inside SimulAVR is a magnificent tool. Precision profiling takes some computing time, but it gives very repeatable and insightful results. For example here: https://github.com/Traumflug/Teacup_Firmware/pull/61#issuecomment-46386878

I hope very much we can find a similarly suited tool for these ARM Cortex-M0, Cortex-M3 and Cortex-M4 based devices.