Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 523276 - sys-devel/gcc-4.9.1 produces bad code for dev-libs/libx86
Summary: sys-devel/gcc-4.9.1 produces bad code for dev-libs/libx86
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-20 01:33 UTC by Joshua Kinard
Modified: 2016-03-09 03:46 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Kinard gentoo-dev 2014-09-20 01:33:14 UTC
I finally traced down the problem with pm-suspend not restoring the monitor state correctly on my amd64 system.  It turns out vbetool is generating an illegal instruction when making a call into dev-libs/libx86:

# vbetool vbestate get
Illegal instruction

Tracing through GDB, I discovered this is the faulty instruction:

# gdb vbetool
GNU gdb (Gentoo 7.8 vanilla) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
[snip]
Reading symbols from vbetool...Reading symbols from /usr/lib64/debug//usr/sbin/vbetool.debug...done.
done.
(gdb) set args vbestate get
(gdb) run
Starting program: /usr/sbin/vbetool vbestate get
warning: Cannot call inferior functions, Linux kernel PaX protection forbids return to non-executable pages!
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Program received signal SIGILL, Illegal instruction.
0x000003d4b1be54f7 in LRMI_init.part.0 () from /usr/lib64/libx86.so.1
(gdb) bt
#0  0x000003d4b1be54f7 in LRMI_init.part.0 () from /usr/lib64/libx86.so.1
#1  0x000003d4b1be554d in LRMI_init () from /usr/lib64/libx86.so.1
#2  0x0000006e80c1ff93 in vbetool_init () at vbetool.c:42
#3  main (argc=3, argv=0x3e64eec3ef8) at vbetool.c:62
(gdb) disas
Dump of assembler code for function LRMI_init.part.0:
   0x000003d4b1be53e0 <+0>:     push   %rbp
   0x000003d4b1be53e1 <+1>:     mov    %rsp,%rbp
   0x000003d4b1be53e4 <+4>:     push   %rbx
[snip]
   0x000003d4b1be54e5 <+261>:   mov    $0x10000,%edx
   0x000003d4b1be54ea <+266>:   callq  0x3d4b1bcddb0 <memset@plt>
   0x000003d4b1be54ef <+271>:   movb   $0x0,0x0
=> 0x000003d4b1be54f7 <+279>:   ud2
---Type <return> to continue, or q <return> to quit---
End of assembler dump.
 
LRMI_init.part.0 appears to actually be LRMI_call in the source code.

Wikipedia says this about the 'ud2' instruction:
"Generates an invalid opcode. This instruction is provided for software testing to explicitly generate an invalid opcode. The opcode for this instruction is reserved for this purpose."

I stripped out all CFLAGS except for -O2 -pipe, removed LTO & Graphite optimizations, removed all LDFLAGS and ASFLAGS, and still vbetool would segfault with SIGILL.  Switching the compiler to gcc-4.8.2 and rebuilding both vbetool and libx86 solves the problem.  Likely, only libx86 needs to be rebuilt.
Comment 1 SpanKY gentoo-dev 2014-09-20 05:32:01 UTC
come on man, you know we need `emerge --info` attached for things like this ;)
Comment 2 Joshua Kinard gentoo-dev 2014-09-20 06:06:20 UTC
(In reply to SpanKY from comment #1)
> come on man, you know we need `emerge --info` attached for things like this
> ;)

Eh, I didn't think emerge --info would shed a lot of light on this one, but if you insist...


Portage 2.2.13 (python 2.7.8-final-0, hardened/linux/amd64, gcc-4.9.1, glibc-2.19-r1, 3.16.1 x86_64)
=================================================================
System uname: Linux-3.16.1-x86_64-Intel-R-_Core-TM-_i7_CPU_960_@_3.20GHz-with-gentoo-2.2
KiB Mem:    16491540 total,  14979012 free
KiB Swap:    4209024 total,   4209024 free
Timestamp of tree: Fri, 19 Sep 2014 05:30:01 +0000
ld GNU ld (Gentoo 2.24 p1.4) 2.24
distcc 3.1 x86_64-pc-linux-gnu [disabled]
ccache version 3.1.9 [disabled]
app-shells/bash:          4.2_p47
dev-java/java-config:     2.2.0
dev-lang/python:          2.7.8, 3.2.5-r6, 3.3.5-r1, 3.4.1
dev-util/ccache:          3.1.9-r3
dev-util/cmake:           3.0.2
dev-util/pkgconfig:       0.28-r2
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.13.1
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.4_p6-r1, 1.5-r1, 1.8.5-r4, 1.9.6-r3, 1.10.3, 1.11.6, 1.12.6, 1.13.4, 1.14.1
sys-devel/binutils:       2.24-r3
sys-devel/gcc:            4.7.4, 4.8.3, 4.9.1
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2-r1
sys-devel/make:           4.0-r1
sys-kernel/linux-headers: 3.16 (virtual/os-headers)
sys-libs/glibc:           2.19-r1
Repositories: gentoo local
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=corei7 -mtune=corei7  -mfpmath=sse -msse -msse2 -mssse3 -msse4.1 -msse4.2  -mcx16 -msahf -mcrc32 -maccumulate-outgoing-args  -fforce-addr -fmodulo-sched -fivopts  -ftree-loop-im -ftree-loop-linear -ftree-loop-ivcanon  -fgcse-after-reload -fgcse-lm -fgcse-sm -fgcse-las  -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block  -ftree-vectorize -flto=8 -fuse-linker-plugin"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/init.d /etc/pam.d /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -march=corei7 -mtune=corei7  -mfpmath=sse -msse -msse2 -mssse3 -msse4.1 -msse4.2  -mcx16 -msahf -mcrc32 -maccumulate-outgoing-args  -fforce-addr -fmodulo-sched -fivopts  -ftree-loop-im -ftree-loop-linear -ftree-loop-ivcanon  -fgcse-after-reload -fgcse-lm -fgcse-sm -fgcse-las  -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block  -ftree-vectorize -flto=8 -fuse-linker-plugin"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs candy cgroup config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms sign splitdebug unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
INSTALL_MASK="/usr/lib/systemd /etc/systemd"
LANG="en_US.iso885915"
LDFLAGS="-O2 -march=corei7 -mtune=corei7  -mfpmath=sse -msse -msse2 -mssse3 -msse4.1 -msse4.2  -mcx16 -msahf -mcrc32 -maccumulate-outgoing-args  -fforce-addr -fmodulo-sched -fivopts  -ftree-loop-im -ftree-loop-linear -ftree-loop-ivcanon  -fgcse-after-reload -fgcse-lm -fgcse-sm -fgcse-las  -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block  -ftree-vectorize -flto=8 -fuse-linker-plugin -Wl,-z,now -Wl,-z,relro"
MAKEOPTS="-j9"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/ramfs"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local"
USE="amd64 apache2 berkdb bzip2 cli cracklib curl cxx dbus dri encode gd gdbm graphite hardened inotify ipv6 justify lto mmx modules multilib ncurses nptl nptlonly offensive openmp pam pax_kernel pcre pic readline real rtc session sqlite sse sse2 ssl tcpd unicode urandom xml xtpax zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_3" RUBY_TARGETS="ruby19 ruby20" USERLAND="GNU" VIDEO_CARDS="vesa vga fbdev" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, SYNC, USE_PYTHON
Comment 3 SpanKY gentoo-dev 2016-01-12 16:11:55 UTC
pretty sure this is WAI.  LRMI_init does:
    *((char *)0) = 0x4f;
which is a NULL pointer deref and the C standard says you can assume undefined behavior (i.e. call ud2).

if you add -fno-delete-null-pointer-checks to your CFLAGS, does it work ?
Comment 4 Jesper Saxtorph 2016-03-09 00:12:15 UTC
Thank you SpanKY that info helped me.
I had similar problem with get-edid and indeed adding -fno-delete-null-pointer-checks to CFLAGS for libx86 solved the problem.
I am using dev-libs/libx86-1.1-r3 and sys-devel/gcc-4.9.3
I have tried to switch the -fno-delete-null-pointer-checks flag on and off and running get-edid after each switch and it seems consistently work with the flag and without the flag it is giving an "Illegal instruction" and a syslog message "kernel: traps: get-edid[8356] trap invalid opcode ip:7fce60b51ef7 sp:7ffccf960850 error:0 in libx86.so.1[7fce60b4a000+1f000]"
Comment 5 SpanKY gentoo-dev 2016-03-09 03:46:54 UTC
(In reply to Jesper Saxtorph from comment #4)

i've pushed this now then.  hopefully it still works :).

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f01eb1e0f70f1827c9bcde88b6db5ae4f1e4116a