Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 227383 - sys-power/nvram-wakeup-0.97_p863 compiled with w/ gcc-4.3 segfaults
Summary: sys-power/nvram-wakeup-0.97_p863 compiled with w/ gcc-4.3 segfaults
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] GCC Porting (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-16 07:28 UTC by Michael Brakemeier
Modified: 2016-02-22 20:09 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 Michael Brakemeier 2008-06-16 07:28:07 UTC
After upgrading to gcc-4.3.1/glibc-2.8 and recompilation of the whole world, nvram-wakeup does no longer work. It segfaults  before writing into the cmos ram (or while writing and thereby eating the bios...!).

azrael ~ # nvram-wakeup -C /etc/nvram.conf --directisa -D -N -s$((`date +%s` + 20 * 60))
nvram-wakeup: Printing debug messages enbled.
nvram-wakeup: $Id: nvram-wakeup.h,v 1.35 2004/07/20 14:20:36 bistr-o-math Exp $
nvram-wakeup: $Id: nvram-wakeup.c,v 1.74 2004/07/20 14:30:40 bistr-o-math Exp $
nvram-wakeup: Opening /etc/nvram.conf in 'r' mode...
[...]
nvram-wakeup: 00000D0: 1000 0041 0000 0000 0000 0000 0000 0000
nvram-wakeup: 00000E0: 1010 1818 1818 1818 850D 0057 85E9 0112
nvram-wakeup: 00000F0: 0820 0000 0000 0000 0000 0000 0000 0000
Segmentation fault

nvram-wakeup worked with the same configuration without any problems for two years on this box, (re-)compiled using gcc-3.3 and 4.2.

I've tracked this down to the CFLAGS, even my moderate flags are
to much for this. The provided Makefile uses -O2 -Wall -Wstrict-prototypes -g -march=i686 -pedantic, using this flags the segfault does *not* occur. Changing march to pentium-m in this line is enough to make it segfault.


Reproducible: Always

Steps to Reproduce:
1. emerge nvram-wakeup
2. call nvram-wake with valid parameters...
3. 




Portage 2.1.5.5 (default/linux/x86/2008.0/desktop, gcc-4.3.1, glibc-2.8_p20080602-r0, 2.6.25-gentoo-r4 i686)
=================================================================
System uname: 2.6.25-gentoo-r4 i686 Intel(R) Pentium(R) M processor 1.86GHz
Timestamp of tree: Mon, 16 Jun 2008 04:45:01 +0000
app-shells/bash:     3.2_p39
dev-java/java-config: 1.3.7, 2.1.6
dev-lang/python:     2.5.2-r4
sys-apps/baselayout: 2.0.0
sys-apps/openrc:     0.2.5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.62
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1-r1
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   2.2.4
virtual/os-headers:  2.6.25-r4
ACCEPT_KEYWORDS="x86 ~x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=pentium-m -mtune=pentium-m -O3 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=pentium-m -mtune=pentium-m -O3 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://192.168.0.43/ http://ftp-stud.fht-esslingen.de/pub/Mirrors/gentoo/ http://mirror.qubenet.net/mirror/gentoo/ http://mirror.uni-c.dk/pub/gentoo/ http://linux.rz.ruhr-uni-bochum.de/download/gentoo-mirror/"
LDFLAGS=""
LINGUAS="de de_DE en en_US"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage/layman/vdr-testing /usr/local/portage/brakemeier.de"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="X a52 aac aalib acl acpi alsa audiofile berkdb bluetooth branding bzip2 cairo cdparanoia cdr chm cli cmdsubmenu cracklib crypt css cups curl cvs dbus ddepgentry dga dri dts dv dvb dvbsetup dvd dvdr dvdread dvlvidprefer eds emboss encode esd evo exif fam fame ffmpeg fftw firefox flac gdbm ggi gif gnome gpm gstreamer gtk hal hbci iconv imagemagick inotify ipv6 isdnlog jack jpeg jumpplay kde lame libnotify liemikuutio lirc lm_sensors mad midi mikmod mjpeg mmx mp3 mpeg mudflap ncurses network-cron nls nptl nptlonly nvram ogg opengl openmp oscar osdmaxitems pam pcre pdf perl png ppds pppd projectx python qt3 qt3support qt4 quicktime readline reflection rtc samba sasl sdl session sndfile spell spl sse sse2 ssl startup-notification subversion svg svga tcpd tiff timerinfo truetype tunepimp unicode usb v4l v4l2 vcd vdr vnc vorbis wareagleicon win32codecs x264 x86 xinetd xml xorg xpm xv xvid xvmc zip zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" DVB_CARDS="ttpci" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="ncurses imon text" LINGUAS="de de_DE en en_US" LIRC_DEVICES="imon_pad2keys" USERLAND="GNU" VIDEO_CARDS="ati radeon vesa vga fbdev v4l apm"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, MAKEOPTS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Doug Goldstein (RETIRED) gentoo-dev 2008-06-16 14:00:16 UTC
Well you've got -march and -mtune set to the same thing, which is totally redundant. If -march is specified that's the minimum platform it'll work on so -mtune is by default set to -march.

Additionally, I'm willing to guess that -O3 is enabling some optimization that's causing an issue. You can try removing the redundant -mtune and changing -O3 to -O2 for this one package to be certain.

In the future, for debugging when you have something that segfaults. Please provide a valid backtrace. Information for this can be found in the Bug Reporting Guide:

http://www.gentoo.org/doc/en/bugzilla-howto.xml#doc_chap2

As well as the Backtrace Guide:

http://www.gentoo.org/proj/en/qa/backtraces.xml
Comment 2 Michael Brakemeier 2008-06-16 15:29:08 UTC
Specifying both march and mtune is just an old habit from the
days of gcc-2.x where you've got to specify both march and mcpu
to get the desired result - useless ok, but, anyway, it causes
no harm here. 

The ebuild already contains flag-o-matics "strip-flags", so the
-O3 will be replaced by -02.

BT? At your service...

nvram-wakeup: 00000E0: 1010 1818 1818 1818 850D 0057 85E9 0112
nvram-wakeup: 00000F0: 0820 0000 0000 0000 0000 0000 0000 0000

Program received signal SIGSEGV, Segmentation fault.
0xb7ed9803 in strlen () from /lib/libc.so.6
(gdb) bt
#0  0xb7ed9803 in strlen () from /lib/libc.so.6
#1  0xb7ea7157 in vfprintf () from /lib/libc.so.6
#2  0xb7ea80a1 in ?? () from /lib/libc.so.6
#3  0xb7ea3456 in vfprintf () from /lib/libc.so.6
#4  0xb7ead17f in fprintf () from /lib/libc.so.6
#5  0x080523db in nvprintf (lvl=7, fmt=0x8053a28 "value of the %-12s byte is: 0x%02X.\n") at tools.c:111
#6  0x08048d98 in assign_byte (oPtr=0xbf9e4e9c, nPtr=0xbf9e4e98, addr=157 '\235', str=0x0)
    at nvram-wakeup.c:76
#7  0x0804a61a in main (argc=0, argv=Cannot access memory at address 0x4
) at nvram-wakeup.c:253

Since the segfault is caused only by a cpu-specific optimization it
seems too me that something is wrong in gcc's optimization for
pentium-m (again...)

Side note: I've originally filed the bug as CRITICAL due to the fact
that nvram-wakeup has happily overwritten all my CMOS-RAM settings
rendering the box unbootable until "F2 load setup defaults" ...
but, quoting the ebuild, "YOU HAVE BEEN WARNED, HAVE A NICE DAY" ;-(

Comment 3 Doug Goldstein (RETIRED) gentoo-dev 2008-06-16 15:34:09 UTC
(In reply to comment #2)
> 
> The ebuild already contains flag-o-matics "strip-flags", so the
> -O3 will be replaced by -02.
> 

Actually if you read flag-o-matic.eclass, you'll see that -Os and -O3 are "unstable" flags which are allowed when a user is on an "unstable" setup. Specifically, any ~arch keyword is in ACCEPT_KEYWORDS. As per your emerge --info, you have ~x86 so -O3 is being passed through to the compile. If you look at one of the compile lines you should see that -O3 is being passed through.

So, please test at -O2.
Comment 4 Michael Brakemeier 2008-06-16 15:44:13 UTC
Using CFLAGS="-march=pentium-m -mtune=pentium-m -O3 -ggdb -pipe" results in

gcc -march=pentium-m -mtune=pentium-m -ggdb -pipe -O2 -pedantic -D_GNU_SOURCE   -c -o nvram-wakeup.o nvram-wakeup.c
gcc -march=pentium-m -mtune=pentium-m -ggdb -pipe -O2 -pedantic -D_GNU_SOURCE   -c -o nvram-wakeup-mb.o nvram-wakeup-mb.c
[...]

These are the flags the BT was generated with.
Comment 5 Doug Goldstein (RETIRED) gentoo-dev 2008-06-16 16:15:36 UTC
Looking at your backtrace and the code in question, I don't think it's an optimization issue. The app is blowing the stack and overwriting argv and argc, which is resulting in the segfault in strlen() since the programmer didn't understand syslog and it creating a global variable for the program's name. But alas, why it's blowing the stack I don't know. The code needs some loving for sure though.
Comment 6 SpanKY gentoo-dev 2009-01-18 18:18:29 UTC
building the package with SSP should detect a stack smash ... just add -fstack-protector to your CFLAGS when emerging it

also, you could try 0.99b ...
Comment 7 Michael Brakemeier 2009-12-28 20:51:22 UTC
nvram-wakeup-1.0 works like a charm for several month now, even if compiled with gcc-4.3x. This bug can be closed.
Comment 8 Michael Brakemeier 2016-02-22 18:18:26 UTC
+1 for closing this one, since it is long ago fixed with newer versions...