<div dir="ltr"><div>This is how my erlang was built:<br></div><div><br></div><div><pre class="" style="margin-top:0px;margin-bottom:0px;width:1135px;color:rgb(51,51,51);line-height:16.7999992370605px"><div class="" id="file-sftest-LC26"><font size="1" face="courier new, monospace">git clone -b OTP-17.3.3 <a href="https://github.com/erlang/otp.git">https://github.com/erlang/otp.git</a> otp</font></div><div class="" id="file-sftest-LC27"><font size="1" face="courier new, monospace">cd otp && ./otp_build autoconf && ./configure --prefix=/usr/local/ --without-javac --disable-hipe --enable-dynamic-ssl-lib --enable-dirty-schedulers && make && make install</font></div><div><font size="1" face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">OS is a Gentoo chroot, gcc is 4.7.3. </font><span style="font-family:arial;line-height:normal;color:rgb(34,34,34)">The nif build commands (via <a href="http://erlang.mk">erlang.mk</a>) are...</span></div></pre></div><div><br></div><div><div><font face="courier new, monospace" size="1">cc -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes -I/usr/local/lib/erlang/erts-6.2/include/ -fPIC -c -o /dlibusb/c_src/dlibusb.o /dlibusb/c_src/dlibusb.c</font></div><div><font face="courier new, monospace" size="1">cc -shared -o /dlibusb/priv/dlibusb.so /dlibusb/c_src/dlibusb.o</font></div></div><div><br></div><div><br></div><div>My minimal test app is here: <a href="https://github.com/goertzenator/dlibusb">https://github.com/goertzenator/dlibusb</a></div><div><br></div><div><br></div><div>I use a Gentoo linux chroot to build an OS for a network appliance. The OS is built for a i486, although the variant that will have Erlang has a beefier i586 CPU. I fooled around changing things external to Erlang but could not get the segfault to go away. This morning I built a minimal vanilla Gentoo chroot and was able to repeat the segfault on my Kubuntu laptop and my Kubuntu desktop VM. The instruction to build the chroot with Erlang and to run the segfault test are here:<br></div><div><br></div><div><a href="https://gist.github.com/goertzenator/c0b19ee84d16f0e82681">https://gist.github.com/goertzenator/c0b19ee84d16f0e82681</a><br></div><div><br></div><div>I'm also providing my Gentoo chroot with prebuilt git and Erlang to save a bit of time and hassle, and to provide binaries of my failing system. (791 MB)<br></div><div><br></div><div><a href="https://drive.google.com/open?id=0B6luM5L22h1oT2QzMWR0Zk9yOWc&authuser=0">https://drive.google.com/open?id=0B6luM5L22h1oT2QzMWR0Zk9yOWc&authuser=0</a><br></div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 31, 2014 at 10:38 PM, Steve Vinoski <span dir="ltr"><<a href="mailto:vinoski@ieee.org" target="_blank">vinoski@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Given the new calls you're using in your NIF, it looks like you're running at least 17.3. I've tried this on Mavericks and Ubuntu 14.04, with and without debug, with and without valgrind, and it always works fine for me. Valgrind reports no problems. I've tried it with 17.3, and I've tried it with a brand new build of maint, and they both work fine.<div><br></div><div>More comments below.<br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Fri, Oct 31, 2014 at 9:57 PM, Daniel Goertzen <span dir="ltr"><<a href="mailto:daniel.goertzen@gmail.com" target="_blank">daniel.goertzen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Thanks for trying it out. That gist was a bit of a hash; apologies.<div><br></div><div>I made all the functions static and also put load and unload as NULL in ERL_NIF_INIT, but I get the same results.<div><br></div><div>I ran it under valgrind and got...</div><div><br></div><div><br></div><div><font face="courier new, monospace"># ERL_LIBS=.. valgrind --trace-children=yes erl<br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">...</font></div><div><font face="courier new, monospace"><br></font></div><div><span><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">Eshell V6.2 (abort with ^G)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">1> </font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">1> dlibusb:mytest_io().</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== Thread 18:</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== Invalid read of size 4</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== at 0x8190B56: process_main (beam_hot.h:935)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== by 0x80E565E: sched_thread_func (erl_process.c:7719)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== by 0x820982B: thr_wrapper (ethread.c:106)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== by 0x40FFF46: start_thread (in /lib/<a href="http://libpthread-2.20.so" target="_blank">libpthread-2.20.so</a>)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== by 0x41FE97D: clone (in /lib/<a href="http://libc-2.20.so" target="_blank">libc-2.20.so</a>)</font></span></p><p dir="ltr" style="line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><font face="courier new, monospace">==9029== Address 0xfffffffe is not stack'd, malloc'd or (recently) free'd</font></span></p></span></div></div></div></blockquote><div><br></div></span><div>There's no dirty scheduler involved in this traceback. The fact that you're hitting an invalid read like this so early, and that it looks like something is dereferencing something close to a null pointer, smells to me like some sort of build problem somewhere. But it's hard to say where exactly.</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><span><div><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;white-space:pre-wrap;background-color:transparent">I know little about beam internals. I don't know if this is useful.</span></div></span></div></div></blockquote><div><br></div></span><div>Unfortunately not. Perhaps you can provide some more details regarding exact Erlang version, OS type and version, how your Erlang was built, and what compiler & version and also the command line you're using to build your nif?</div><span class=""><font color="#888888"><div><br></div><div>--steve</div></font></span></div></div></div></div>
</blockquote></div><br></div></div>