Bug 28956

Summary: liboil crashing on OpenBSD/amd64 when built with gcc4.
Product: liboil Reporter: Brad Smith <brad>
Component: unknownAssignee: David Schleef <ds>
Status: RESOLVED FIXED QA Contact: David Schleef <ds>
Severity: major    
Priority: medium    
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: OpenBSD   
Whiteboard:
i915 platform: i915 features:
Attachments: patch

Description Brad Smith 2010-07-07 20:04:41 UTC
Not too long ago OpenBSD/amd64 switched from gcc3 (3.3.5) to gcc4 (4.2.1) and we noticed that liboil started to crash with a stack overflow in oil_cpu_detect_arch().

liboil 0.3.17

$ cc -v
Reading specs from /usr/lib/gcc-lib/amd64-unknown-openbsd4.7/4.2.1/specs
Target: amd64-unknown-openbsd4.7
Configured with: OpenBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719 
$ libtool --mode=execute gdb align align.core 
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd4.7"...
Core was generated by `align'.
Program terminated with signal 6, Aborted.
Reading symbols from /home/ports/devel/liboil/w-liboil-0.3.17p1/liboil-0.3.17/liboil/.libs/liboil-0.3.so.4.0...done.
Loaded symbols for /home/ports/devel/liboil/w-liboil-0.3.17p1/liboil-0.3.17/liboil/.libs/liboil-0.3.so.4.0
Reading symbols from /usr/lib/libm.so.5.2...done.
Loaded symbols for /usr/lib/libm.so.5.2
Reading symbols from /usr/lib/libc.so.55.0...done.
Loaded symbols for /usr/lib/libc.so.55.0
Reading symbols from /usr/libexec/ld.so...done.
Loaded symbols for /usr/libexec/ld.so
#0  0x000000020b68104a in kill () from /usr/lib/libc.so.55.0
(gdb) bt full
#0  0x000000020b68104a in kill () from /usr/lib/libc.so.55.0
No symbol table info available.
#1  0x000000020b6ad18d in __stack_smash_handler (func=0x20a0b41e0 "oil_cpu_detect_arch", damaged=Variable "damaged" is not available.
) at /usr/src/lib/libc/sys/stack_protector.c:89
        sdata = {log_file = -1, connected = 0, opened = 1, log_stat = 0, log_tag = 0x802540 "align", log_fac = 8, log_mask = 255}
        message = "stack overflow in function %s"
        sa = {__sigaction_u = {__sa_handler = 0, __sa_sigaction = 0}, sa_mask = 0, sa_flags = 0}
        mask = 4294967263
#2  0x0000000209f8ce7c in oil_cpu_detect_arch () at liboilcpu-x86.c:358
No locals.
#3  0x0000000209f889f0 in _oil_cpu_init () at liboilcpu.c:107
        envvar = Variable "envvar" is not available.
Comment 1 David Schleef 2010-07-13 16:27:38 UTC
Created attachment 37005 [details] [review]
patch
Comment 2 David Schleef 2010-07-13 16:28:02 UTC
Could you do one or more of the following:

 - try the same test with Orc (I tried to fix this bug in Orc, curious if I succeeded), either with git or the upcoming 0.4.6 release.

 - attach the file liboil/.libs/liboil_0.3_la-liboilcpu-x86.o

 - try the attached patch
Comment 3 Brad Smith 2010-07-13 17:04:00 UTC
With the patch applied all of the regression tests now pass.
Comment 4 Brad Smith 2010-07-13 19:48:00 UTC
Currently OpenBSD ports is using Orc 0.4.4, but I have an update to 0.4.6 and this also passes all of the included testsuite on OpenBSD/amd64. Still have to test on i386/arm. I didn't update to 0.4.5 because it was crashing on arm.
Comment 5 Brad Smith 2010-07-19 10:23:00 UTC
David, if the diff is Ok with you could you please see about getting it commited to the liboil repo?
Comment 6 David Schleef 2010-07-20 14:06:47 UTC
Pushed.

commit 705916007fba0a845229a02dc6474cb523eff150
Author: David Schleef <ds@schleef.org>
Date:   Tue Jul 20 14:05:26 2010 -0700

    x86: Fix cpuid function on x86-64
    
    Fixes: #28956.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.