Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 564890 - sys-boot/grub-0.97-r14: runtime errors when built with gcc-4.9.3
Summary: sys-boot/grub-0.97-r14: runtime errors when built with gcc-4.9.3
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 566638 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-11-04 20:05 UTC by Anna Tikhomirova
Modified: 2017-01-09 16:03 UTC (History)
4 users (show)

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


Attachments
grub-0.97-Add-esp-to-list-of-clobbered-registers.patch (grub-0.97-Add-esp-to-list-of-clobbered-registers.patch,1.57 KB, patch)
2015-12-15 00:06 UTC, Sergei Trofimovich
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anna Tikhomirova 2015-11-04 20:05:54 UTC
After rebuilding grub-0.97-r14 with the new stable gcc-4.9.3, the grub binary throws random segfaults on exit. Booting works fine though (at least on kvm virtual machine). Rebuilding grub with gcc 4.8.x or earlier or updating to grub2 fixes the problem.

Reproducible: Always




[   92.671920] traps: grub[2721] general protection ip:f75133ff sp:fff127a4 error:0 in libc-2.21.so[f7506000+1a7000]
[   97.268383] traps: grub[2724] general protection ip:f753d3ff sp:fff337e4 error:0 in libc-2.21.so[f7530000+1a7000]
[  112.945409] traps: grub[2737] general protection ip:f6c09038 sp:ffb39294 error:0
[  116.401966] traps: grub[2741] general protection ip:f6c1e038 sp:ffdc8234 error:0
[ 2645.828676] traps: grub[8091] general protection ip:f75573ff sp:ffe64984 error:0 in libc-2.21.so[f754a000+1a7000]
[ 2728.402219] grub[13558]: segfault at f74dc000 ip 00000000f74dc000 sp 00000000ffe83ab4 error 14
[ 2765.768055] traps: grub[13980] general protection ip:f753c3ff sp:ffc6e624 error:0 in libc-2.21.so[f752f000+1a7000]
[ 2779.496112] traps: grub[13984] general protection ip:f75143ff sp:ffd7d934 error:0 in libc-2.21.so[f7507000+1a7000]
[ 2938.265648] grub[14005]: segfault at 28e880c2 ip 00000000f6c16007 sp 00000000ffa838bc error 6
[ 2944.001658] grub[14010]: segfault at 28e880c2 ip 00000000f6bdf007 sp 00000000ff9d75ec error 6
[ 2945.004365] grub[14012]: segfault at 28e880c2 ip 00000000f6bad007 sp 00000000fff805dc error 6
[ 2979.779574] grub[14014]: segfault at 28e880c2 ip 00000000f6b90007 sp 00000000ff84e72c error 6
[ 3209.618285] grub[19507]: segfault at f7513000 ip 00000000f7513000 sp 00000000ffda5ca4 error 14
[ 3629.606693] grub[9518]: segfault at f7540000 ip 00000000f7540000 sp 00000000ffe7dd54 error 14
[ 4075.281149] grub[15634]: segfault at f74ed000 ip 00000000f74ed000 sp 00000000ffc3d244 error 14

# gdb -q grub
Reading symbols from grub...done.
(gdb) run
Starting program: /sbin/grub
Probing devices to guess BIOS drives. This may take a long time.

Program received signal SIGSEGV, Segmentation fault.
0xf7fd7788 in ?? ()
(gdb) bt full
#0  0xf7fd7788 in ?? ()
No symbol table info available.
#1  0xf7e0163c in __libc_start_main (main=0x1, argc=134519034, argv=0x0, init=0x804991b <_start+33>, fini=0x8049646 <main>, rtld_fini=0x1, stack_end=0xffffd4e4) at libc-start.c:289
        result = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {0, 0, 134514696, 134676668, -134750208, 0}, mask_was_saved = 134519034}}, priv = {pad = {0x0, 0xe4f5ae0f, 0xdb76f81f, 0x0}, data = {prev = 0x0, cleanup = 0xe4f5ae0f,
              canceltype = -612960225}}}
        not_first_call = <optimized out>
#2  0xf7ffcfcc in _DYNAMIC () from /lib/ld-linux.so.2
No symbol table info available.
#3  0x00000001 in ?? ()
No symbol table info available.
#4  0x080498fa in printf (__fmt=0x8061050 "Run \"gdb %s %d\", and set HOLD to zero.\n") at /usr/include/bits/stdio2.h:104
No locals.
#5  main (argc=<error reading variable: Cannot access memory at address 0x74c13904>, argv=<error reading variable: Cannot access memory at address 0x74c13908>) at main.c:252
        c = <optimized out>
        hold = <optimized out>
Backtrace stopped: Cannot access memory at address 0x74c13900

# gdb -q grub
Reading symbols from grub...done.
(gdb) run
Starting program: /sbin/grub
Probing devices to guess BIOS drives. This may take a long time.

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt full
#0  0x00000000 in ?? ()
No symbol table info available.
#1  0x00000000 in ?? ()
No symbol table info available.

# emerge --info
Portage 2.2.20.1 (python 3.4.3-final-0, default/linux/amd64/13.0, gcc-4.9.3, glibc-2.21-r1, 4.3.0-gentoo x86_64)
=================================================================
System uname: Linux-4.3.0-gentoo-x86_64-QEMU_Virtual_CPU_version_2.2.0-with-gentoo-2.2
KiB Mem:      503116 total,    332168 free
KiB Swap:     524284 total,    524284 free
Timestamp of repository gentoo: Tue, 03 Nov 2015 14:00:01 +0000
sh bash 4.3_p39
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
app-shells/bash:          4.3_p39::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.10::gentoo, 3.4.3::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.17::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.69::gentoo
sys-devel/automake:       1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            4.9.3::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 3.18::gentoo (virtual/os-headers)
sys-libs/glibc:           2.21-r1::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=nocona -pipe"
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/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=nocona -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j2"
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="/var/tmp"
USE="acl amd64 berkdb bindist bzip2 cli cracklib crypt cxx dri fortran gdbm iconv idn ipv6 mmx mmxext modules multilib ncurses nls nptl openmp pam pcre readline seccomp session sse sse2 ssl tcpd threads unicode xattr xml 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="authn_core authz_core socache_shmcb unixd 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 cgi cgid 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" 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" CPU_FLAGS_X86="mmx mmxext sse sse2" 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 ru" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="fbdev glint intel mach64 mga nouveau nv r128 radeon savage sis tdfx trident vesa via vmware dummy v4l" 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:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

I've solved the problem by migrating to Grub2. So I just want to warn about incompatibility.
Comment 1 Ian Stakenvicius gentoo-dev 2015-12-08 21:30:34 UTC
I added a workaround to grub-0.97-r16 to help prevent this issue.  It tested fine for me, but it might be too heavy-handed and/or not necessary for gcc-5.  Anyhow, anyone still using grub:0 please report failures.
Comment 2 Ian Stakenvicius gentoo-dev 2015-12-08 21:31:46 UTC
*** Bug 566638 has been marked as a duplicate of this bug. ***
Comment 3 Marc Burkhardt 2015-12-12 17:52:55 UTC
(In reply to Ian Stakenvicius from comment #1)
> I added a workaround to grub-0.97-r16 to help prevent this issue.  It tested
> fine for me, but it might be too heavy-handed and/or not necessary for
> gcc-5.  Anyhow, anyone still using grub:0 please report failures.

Hi Ian,

just a quick question:

the fix replaces the "-O2" in our CFLAGS. What if I am setup to use "-O3" oder "-Ofast"?

"-O3" contains all the "-O2" stuff plus more ...

Thanks for feedback,
Marc
Comment 4 Martin Mokrejš 2015-12-12 18:07:44 UTC
(In reply to Marc Burkhardt from comment #3)
> (In reply to Ian Stakenvicius from comment #1)
> > I added a workaround to grub-0.97-r16 to help prevent this issue.  It tested
> > fine for me, but it might be too heavy-handed and/or not necessary for
> > gcc-5.  Anyhow, anyone still using grub:0 please report failures.
 
> the fix replaces the "-O2" in our CFLAGS. What if I am setup to use "-O3"
> oder "-Ofast"?
> 
> "-O3" contains all the "-O2" stuff plus more ...
> 
> Thanks for feedback,
> Marc

Hi Marc,
 in https://bugs.gentoo.org/show_bug.cgi?id=566638#c1 I showed that all these resulted in a broken binary: -O1, O2, -Os . I did not test -Ofast but maybe you can check gcc manpage for clues? I guess -O3 will for sure result in a broken code as well. Well, somebody should ensure this gets reported to gcc developers.
Comment 5 Ian Stakenvicius gentoo-dev 2015-12-13 04:21:10 UTC
(In reply to Marc Burkhardt from comment #3)
> (In reply to Ian Stakenvicius from comment #1)
> 
> Hi Ian,
> 
> just a quick question:
> 
> the fix replaces the "-O2" in our CFLAGS. What if I am setup to use "-O3"
> oder "-Ofast"?
> 
> "-O3" contains all the "-O2" stuff plus more ...
> 
> Thanks for feedback,
> Marc

The patch I did replaces the -O2 that the build system hard-codes, when USE="custom-cflags" is off.  Unless you enable that flag, your system cflags are totally ignored by the grub:0 build system.  You can certainly try other flags/settings yourself by enabling the use flag so that your system cflags are used, but as the use flag (should?) state, you're on your own.
Comment 6 Sergei Trofimovich gentoo-dev 2015-12-15 00:06:40 UTC
Created attachment 419232 [details, diff]
grub-0.97-Add-esp-to-list-of-clobbered-registers.patch

fixes misoptimization by -fcombine-stack-adjustments
Comment 7 Sergei Trofimovich gentoo-dev 2015-12-15 00:10:49 UTC
I think i have a plausible theory why it crashes (see patch header) :)

Please try the patch with reverted change in ebuild (stop forcing O0 back to default O2):

https://gitweb.gentoo.org/repo/gentoo.git/commit/sys-boot/grub/grub-0.97-r16.ebuild?id=69273f1d085c5d44071c1f209e9048faa7c78202

Or the equivalent change:

diff --git a/sys-boot/grub/grub-0.97-r16.ebuild b/sys-boot/grub/grub-0.97-r16.ebuild
index 9da0d0e..512b7bb 100644
--- a/sys-boot/grub/grub-0.97-r16.ebuild
+++ b/sys-boot/grub/grub-0.97-r16.ebuild
@@ -77,7 +77,7 @@ src_prepare() {
                        ewarn "incompatibilities."
                else
                        einfo "Forcing -O0 to get around optimization issue caused by gcc-4.9 and newer with -O2"
-                       sed -i  -e "/CFLAGS/s/-O2/-O0/" \
+                       sed -i  -e "/CFLAGS/s/-O2/-O2/" \
                                "${S}"/configure.ac || die
                fi
        fi

Thanks!
Comment 8 Ian Stakenvicius gentoo-dev 2015-12-15 17:09:58 UTC
Thanks slyfox!   Tested with gcc-4.8.5 and gcc-4.9.3 , no errors or issues either on use of 'grub' or on bootup.  Pushed to gentoo repo in grub-0.97-r17; i think we can consider this bug to be fixed.

I will request stabilization of -r17 as soon as bug 568222 is resolved.
Comment 9 Martin Mokrejš 2015-12-18 15:02:52 UTC
So -r17 ebuild compiles a working binary for me as well using gcc-4.9.3. Thank you.