Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 419971

Summary: net-libs/wvstreams-4.6.1 compiled with GCC 4.7.0: assertion failed when dialing a 3G/GPRS modem
Product: Gentoo Linux Reporter: Ioannis Galanommatis <galanom>
Component: Current packagesAssignee: C++ Team [disbanded] <cpp+disabled>
Status: RESOLVED FIXED    
Severity: normal CC: ssuominen
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on: 419563    
Bug Blocks:    

Description Ioannis Galanommatis 2012-06-06 19:08:26 UTC
Hi!
If I compile wvstreams-4.6.1-r1 with gcc-4.7.0,
when I call with wvdial my 3G modem on my mobile phone through bluetooth, I receive an error after the three init strings. It appears to be exclusive to mobile phones and 3G sticks.

wvdial: utils/wvtask.cc:409: static void WvTaskMan::_stackmaster(): Assertion
`magic_number == -0x123678' failed.

I googled and I saw an ubuntu guy complaining for the exact same problem and they told him to downgrade wvstreams to an earlier build of the same version.

As a workaround, I downloaded the .deb file, I uncompressed the libwvstreams.so.4.6 and I put it in my gentoo. It worked fine.

As I was googling to find info to report this bug, I saw these pages:
http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1030783.html
http://permalink.gmane.org/gmane.linux.redhat.fedora.extras.cvs/779635
which contain a patch (I have NOT tested it), copy-pasted here for your convinence (both sites appear to have the same patch):

+--- wvstreams-4.6.1/include/wvtask.h.magic	2008-07-14 21:11:35.000000000 +0200
++++ wvstreams-4.6.1/include/wvtask.h	2012-06-03 17:24:47.909187849 +0200
+@@ -45,7 +45,8 @@ class WvTask
+     typedef void TaskFunc(void *userdata);
+     
+     static int taskcount, numtasks, numrunning;
+-    int magic_number, *stack_magic;
++    int volatile magic_number;
++    int *stack_magic;
+     WvString name;
+     int tid;
+     
+@@ -84,7 +85,7 @@ class WvTaskMan
+     static WvTaskMan *singleton;
+     static int links;
+     
+-    static int magic_number;
++    static int volatile magic_number;
+     static WvTaskList all_tasks, free_tasks;
+     
+     static void get_stack(WvTask &task, size_t size);
+diff -up wvstreams-4.6.1/utils/wvtask.cc.magic wvstreams-4.6.1/utils/wvtask.cc
+--- wvstreams-4.6.1/utils/wvtask.cc.magic	2009-05-13 23:42:52.000000000 +0200
++++ wvstreams-4.6.1/utils/wvtask.cc	2012-06-03 14:29:09.729656804 +0200
+@@ -58,7 +58,8 @@ char *alloca ();
+ int WvTask::taskcount, WvTask::numtasks, WvTask::numrunning;
+ 
+ WvTaskMan *WvTaskMan::singleton;
+-int WvTaskMan::links, WvTaskMan::magic_number;
++int WvTaskMan::links;
++int volatile WvTaskMan::magic_number;
+ WvTaskList WvTaskMan::all_tasks, WvTaskMan::free_tasks;
+ ucontext_t WvTaskMan::stackmaster_task, WvTaskMan::get_stack_return,
+     WvTaskMan::toplevel;
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2012-06-06 20:19:56 UTC
So this is after applying the patch from bug #419563, right?
Comment 2 Samuli Suominen (RETIRED) gentoo-dev 2012-06-06 20:34:31 UTC
Fixed by -r2 in Portage. Please test.
Comment 3 Ioannis Galanommatis 2012-06-06 22:04:52 UTC
(In reply to comment #2)
Yes!

(In reply to comment #2)
> Fixed by -r2 in Portage. Please test.

Weird. It segfaults with these flags:
CFLAGS="-O2 -march=native -pipe"
CHOST="x86_64-pc-linux-gnu"
CXXFLAGS="${CFLAGS}"

Output:

--> WvDial: Internet dialer version 1.61
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: AT&F E1 V1 X1 &D2 &C1 S0=0
AT&F E1 V1 X1 &D2 &C1 S0=0
OK
--> Sending: AT+CGDCONT=1,"IP","internet.vodafone.gr"
AT+CGDCONT=1,"IP","internet.vodafone.gr"
OK
--> Modem initialized.
--> Idle Seconds = 3600, disabling automatic reconnect.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff731c9da in WvTaskMan::do_task() () from /usr/lib64/libwvbase.so.4.6
(gdb) bt
#0  0x00007ffff731c9da in WvTaskMan::do_task() () from /usr/lib64/libwvbase.so.4.6
#1  0x00007ffff7de8c75 in ?? () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff7def2c5 in ?? () from /lib64/ld-linux-x86-64.so.2
#3  0x00007ffff7311469 in WvCont::_call(WvCont::Data*) () from /usr/lib64/libwvbase.so.4.6
#4  0x00007ffff7311620 in WvCont::operator()(void*) () from /usr/lib64/libwvbase.so.4.6
#5  0x00007ffff7323fa9 in WvStream::callback() () from /usr/lib64/libwvbase.so.4.6
#6  0x000000000040760c in ?? ()
#7  0x00007ffff6a386c5 in __libc_start_main () from /lib64/libc.so.6
#8  0x0000000000407c11 in ?? ()
#9  0x00007fffffffeac8 in ?? ()
#10 0x0000000000000000 in ?? ()


I don't know why there are these empty parenthesis or question marks, I did not tell portage to strip symbols. I guessed that -O2 removes them. So I switched to -O2 in make.conf and ...it compiles fine!!

Why could compile fine with -O0 and not with -02??? GCC 4.7.0 is stable, according to GNU. Shall I post a bug there?
Comment 4 Samuli Suominen (RETIRED) gentoo-dev 2012-06-06 23:48:06 UTC
(In reply to comment #3)
> (In reply to comment #2)
> Yes!
> 
> (In reply to comment #2)
> > Fixed by -r2 in Portage. Please test.
> 
> Weird. It segfaults with these flags:
> CFLAGS="-O2 -march=native -pipe"
> CHOST="x86_64-pc-linux-gnu"
> CXXFLAGS="${CFLAGS}"
> 
> Output:
> 
> --> WvDial: Internet dialer version 1.61
> --> Cannot get information for serial port.
> --> Initializing modem.
> --> Sending: ATZ
> ATZ
> OK
> --> Sending: AT&F E1 V1 X1 &D2 &C1 S0=0
> AT&F E1 V1 X1 &D2 &C1 S0=0
> OK
> --> Sending: AT+CGDCONT=1,"IP","internet.vodafone.gr"
> AT+CGDCONT=1,"IP","internet.vodafone.gr"
> OK
> --> Modem initialized.
> --> Idle Seconds = 3600, disabling automatic reconnect.
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff731c9da in WvTaskMan::do_task() () from
> /usr/lib64/libwvbase.so.4.6
> (gdb) bt
> #0  0x00007ffff731c9da in WvTaskMan::do_task() () from
> /usr/lib64/libwvbase.so.4.6
> #1  0x00007ffff7de8c75 in ?? () from /lib64/ld-linux-x86-64.so.2
> #2  0x00007ffff7def2c5 in ?? () from /lib64/ld-linux-x86-64.so.2
> #3  0x00007ffff7311469 in WvCont::_call(WvCont::Data*) () from
> /usr/lib64/libwvbase.so.4.6
> #4  0x00007ffff7311620 in WvCont::operator()(void*) () from
> /usr/lib64/libwvbase.so.4.6
> #5  0x00007ffff7323fa9 in WvStream::callback() () from
> /usr/lib64/libwvbase.so.4.6
> #6  0x000000000040760c in ?? ()
> #7  0x00007ffff6a386c5 in __libc_start_main () from /lib64/libc.so.6
> #8  0x0000000000407c11 in ?? ()
> #9  0x00007fffffffeac8 in ?? ()
> #10 0x0000000000000000 in ?? ()
> 
> 
> I don't know why there are these empty parenthesis or question marks, I did
> not tell portage to strip symbols. I guessed that -O2 removes them. So I
> switched to -O2 in make.conf and ...it compiles fine!!

Portage is set to strip symbols by default, see FEATURES="nostrip" here:

http://www.gentoo.org/proj/en/qa/backtraces.xml

> Why could compile fine with -O0 and not with -02??? 

It's -O2 instead of -02.

> GCC 4.7.0 is stable, according to GNU. Shall I post a bug there?

But you are using it on Gentoo so only KEYWORDS matter, and gcc-4.7.0 is not even keyworded for ~arch (testing) yet. 
The portage tree is far from being ready for 4.7.0. I thought you were just testing it to contribute patches, fun, etc. ;-)

Anyway, please get a proper backtrace with those ?? changed to something useful and/or build.log with failure and then reopen the bug if necessary.
Comment 5 Ioannis Galanommatis 2012-06-07 01:59:56 UTC
(In reply to comment #4)

I think I found the most insane bug in my life.

As is it segfaults. 
I added FEATURES="nostrip" and I did not enable debug flag as your page suggests.
If I add -ggdb, I don't get more symbols.
If I add -fno-omit-frame-pointer then instead of sefaulting, it aborts with the initial magic number thing assertion failure.

Just for fun:
I go to utils/wvtask.cc:501 to see what happens
It's

assert(magic_number == -WVTASK_MAGIC);
assert(task);
assert(task->magic_number == WVTASK_MAGIC);

and it sefaults.

If I do this, to see if task==NULL:

assert(magic_number == -WVTASK_MAGIC);
assert(task);
fprintf(stderr, "hello world! %x", task);
assert(task->magic_number == WVTASK_MAGIC);

Then it does NOT segfault! I prints an address (non-NULL) and aborts:
utils/wvtask.cc:502: static void WvTaskMan::do_task(): Assertion `task->magic_number == 0x123678' failed.

(Please note that the first assert is with positive sign and second with negative.)

So, dereferrencing a variable changes its contents??? What is this, quantum programming?

Anyway. Compiling wvstreams and wvdial with -ggdb and FEATURES="nostrip" but without -fno-omit-frame-pointer, all I can get is:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff731c9da in WvTaskMan::do_task () at utils/wvtask.cc:501
501	utils/wvtask.cc: No such file or directory.
(gdb) bt
#0  0x00007ffff731c9da in WvTaskMan::do_task () at utils/wvtask.cc:501
#1  0x00007ffff7de8c75 in ?? () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff7def2c5 in ?? () from /lib64/ld-linux-x86-64.so.2
#3  0x00007ffff7311469 in WvCont::_call (data=0x62e660) at utils/wvcont.cc:176
#4  0x00007ffff7311620 in call (this=0x62e190) at ./include/wvcont.h:54
#5  WvCont::operator() (this=0x62e190, p1=0x0) at utils/wvcont.cc:209
#6  0x00007ffff7323fa9 in operator() (__args#0=<optimized out>, this=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/include/g++-v4/tr1/functional:2154
#7  WvStream::callback (this=0x7fffffffd030) at streams/wvstream.cc:432
#8  0x00000000004074bc in main (argc=<optimized out>, argv=<optimized out>) at wvdial.cc:225

If you need more info, please tell me which packages should compile with what options.

tx
Comment 6 Tiziano Müller (RETIRED) gentoo-dev 2012-06-07 06:40:13 UTC
Well, you posted the patch and the link to it and the cause is described there: "The compiler aggressively optimizes..." 

But still I fail to see why someone wants optimization and not have NDEBUG defined to get rid of the asserts.
Comment 7 Samuli Suominen (RETIRED) gentoo-dev 2012-06-16 20:51:40 UTC
http://pkgs.fedoraproject.org/gitweb/?p=libwvstreams.git;a=commit;h=59d3a449a4595758e0f3701f8754e067a0b8dcad

Fedora inserted these flags to prevent crashing with 4.7:

-fno-tree-dce -fno-optimize-sibling-calls

I've done the same for portage now. Let's try the FIXED resolution again. You will need to recompile wvstreams -r2