I probably shouldn't bother with such extreme CFLAGS, but it did result in a segfault in ed, so I decided to report it anyway. CFLAGS="-O3 -march=pentium-m -pipe -fomit-frame-pointer -funroll-all-loops -fpeel-loops -ftracer -funswitch-loops -funit-at-a-time" CHOST="i686-pc-linux-gnu" The segmentation fault occurs when opening any file, without any other output. I have to take out both -funroll-all-loops and -fpeel-loops to clear the seg fault. In case it helps: gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.2.2/work/gcc-4.2.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.2.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --disable-multilib --enable-libmudflap --disable-libssp --disable-libgcj --with-arch=i686 --enable-languages=c,c++,treelang,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu Thread model: posix gcc version 4.2.2 (Gentoo 4.2.2 p1.0) Reproducible: Always Steps to Reproduce: 1. Set CFLAGS to above 2. Recompile ed 3. ??? 4. Seg Fault! Portage 2.1.4 (default-linux/x86/2007.0, gcc-4.2.2, glibc-2.7-r1, 2.6.23-gentoo-r6 i686) ================================================================= System uname: 2.6.23-gentoo-r6 i686 Genuine Intel(R) CPU T2250 @ 1.73GHz Timestamp of tree: Thu, 31 Jan 2008 21:46:01 +0000 ccache version 2.4 [enabled] app-shells/bash: 3.2_p33 dev-java/java-config: 1.3.7, 2.1.4 dev-lang/python: 2.5.1-r5 dev-util/ccache: 2.4-r7 sys-apps/baselayout: 1.12.11.1 sys-apps/sandbox: 1.2.18.1-r2 sys-devel/autoconf: 2.13, 2.61-r1 sys-devel/automake: 1.7.9-r1, 1.9.6-r2, 1.10.1 sys-devel/binutils: 2.18-r1 sys-devel/gcc-config: 1.4.0-r4 sys-devel/libtool: 1.5.24 virtual/os-headers: 2.6.24 ACCEPT_KEYWORDS="x86 ~x86" CBUILD="i686-pc-linux-gnu" CFLAGS="-O3 -march=pentium-m -pipe -fomit-frame-pointer -funroll-all-loops -fpeel-loops -ftracer -funswitch-loops -funit-at-a-time" 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/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d" CXXFLAGS="-O3 -march=pentium-m -pipe -fomit-frame-pointer -funroll-all-loops -fpeel-loops -ftracer -funswitch-loops -funit-at-a-time" DISTDIR="/usr/portage/distfiles" FEATURES="ccache distlocks metadata-transfer sandbox sfperms strict unmerge-orphans userfetch" GENTOO_MIRRORS="ftp://gentoo.inf.elte.hu/ http://linux.rz.ruhr-uni-bochum.de/download/gentoo-mirror/ ftp://ftp.rhnet.is/pub/gentoo/" MAKEOPTS="-j3" 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 --filter=H_**/files/digest-*" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" PORTDIR_OVERLAY="/usr/local/overlays/koy" SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage" USE="3dnow X aac acl acpi aim alsa arts avi bash-completion berkdb bitmap-fonts browserplugin cdr cli cracklib crypt ctype cups dri dvd emacs firefox fortran gdbm gpm iconv ipv6 isdnlog java jpeg kde midi mp3 mpeg mudflap ncurses nls nptl nptlonly nsplugin nvidia opengl openmp oss pam pcre pdf pdflib perl png pppd python qt3 quicktime readline reflection session spl ssl tcpd threads truetype truetype-fonts type1-fonts unicode x86 xcomposite xorg xscreensaver xvmc 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" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="nvidia nv vesa" Unset: CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
See: http://devmanual.gentoo.org/ebuild-writing/functions/src_compile/build-environment/index.html http://www.gentoo.org/doc/en/gcc-optimization.xml
While these CFLAGS are indeed over the top, the bug in this case is in ed, and can probably be exposed with different flags just as well. I'll attach a patch to fix this in ed in the most direct (and ugly) way possible.
Created attachment 142426 [details, diff] ed-0.8-aliasing.patch ed ignores C's aliasing rules, and includes casts to prevent GCC from warning about it. This is not a good idea. The casts do not actually fix the problem, they merely tell GCC to shut up about it. Since some pointers are accessed as a char *, the direct fix is to actually define these pointers as a char *, and cast them (as allowed by the language in this case) whenever they're used. The same compiler flags that cause ed to segfault, make it pass its testsuite with this patch. A cleaner patch would alter the reallocation functions, but that would take more work, and I haven't seen if that would cause other unrelated problems.
The problem is not fixed in sys-apps/ed-0.9. The same patch can be applied to 0.9 to make it work and pass its own testsuite.
Harald, have you sent this patch upstream?
No, I have strong doubts that upstream would accept it the way it is now. It's horribly ugly. If you think I should send it anyway (and let them clean it up), I'll do so.
Well, now I see you doubts. I'm not sure about patch, but in any case it's good idea to make upstream aware about bug and being familiar with code you'll do this definitely better then me.
Alright, I've sent a mail to <bug-ed@gnu.org>, and hope Antonio can come up with a cleaner fix.
the patch is ugly, but so is the code it's fixing since the required flag combination is not common by any means, i dont think there's a rush to get it merged ... but if a newer gcc comes out which (in the common case) starts making ed crap itself, we can add the patch to the tree until upstream can get things fixed up
can you check ed-1.0/ed-1.1 ? i think they've fixed this issue upstream ...
In some private e-mails back in April, Antonio (the upstream maintainer) asked me to test various suggestions. They all failed, and it was still broken when he decided to release 1.0.
i dont suppose you feel like looking at ed-1.1 ? :)
I don't mind, but I'm having a bit of trouble reproducing the segfault on 1.0 (but no problems on 0.9). Unless I can get 1.0 to fail again there's going to be little point in checking 1.1.
Ah, right... ed 1.0 and 1.1 both fail with CFLAGS="-march=pentium-m -O2 -fomit-frame-pointer -finline-functions -fpeel-loops", but not with the exact CFLAGS from this bugreport.
sorry, how exactly are you testing ? i have an x86 system with gcc-4.3.2 and glibc-2.9 and i do: $ tar xf ed-1.1.tar.gz $ cd ed-1.1 $ ./configure CFLAGS="-march=pentium-m -O2 -fomit-frame-pointer -finline-functions -fpeel-loops" $ make -j4 $ make check and it works for me also, does appending -fno-strict-aliasing make it work ?
CC=gcc-4.2.4 CFLAGS='-march=pentium-m -O2 -fomit-frame-pointer -finline-functions -fpeel-loops' FEATURES=test emerge ed It doesn't bomb out with gcc 4.3, but does with 4.2. And yes, adding -fno-strict-aliasing makes ed work. Considering how sensitive this is to compiler and flags, though, it's very well possible that -fno-strict-aliasing doesn't get the chance to fix this, if it suppresses the problem. :)
since the patch you posted indicates that it's an aliasing issue, using -fno-strict-aliasing seems correct to me until the source gets sorted out
upstream says that ed-1.1 should be sorted out, and if gcc-4.2 is the only one we can make fail (and only with the proposed CFLAGS), then i say we just close out the issue
Huh? I don't know why he claims he thought 1.0 would be fixed... I was pretty clear that his last suggestion still failed, and the relevant code is identical between that and 1.0. Here's the last mail from back then (without reply): <<< From: Harald van Dijk <truedfx@gentoo.org> To: Antonio Diaz Diaz <ant_diaz@teleline.es> Date: Sun, 4 May 2008 23:00:19 +0200 Subject: Re: [Bug-ed] Aliasing violations in ed cause segfaults. On Sun, May 04, 2008 at 06:50:03PM +0200, Antonio Diaz Diaz wrote: > The attached source compiles and passes the tests with gcc 4.3.0 and 3.3.6. > I have been unable to reproduce the bug you reported. I tried all the > reported options, except -march=pentium-m, but it always passes the tests. I don't have problems with other versions of gcc than 4.2, or without the specific options I mentioned earlier. It was surprising to me that -march=pentium-m was necessary to trigger this, but with -march=pentium4 (for example) and otherwise identical options, ed works. I will try to find another way to reproduce the problem, possibly with other command-line options, possibly with another compiler or compiler version, but I can't promise I'll find one. > If it works on your system or we can't find a way to reproduce the bug on > my system, I'll release the attached source as ed-1.0-rc1. The attached source still fails, with the specific compiler and options that make earlier versions fail too. >>> I'm also curious why you think this is a bug in gcc rather than in ed: you seem to agree it _was_ a bug in ed 0.8, but if you look at the code the issue is clearly suppressed rather than fixed.