unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Error with -O3 but not -O2: "Wrong type argument: listp".
@ 2006-01-28 21:17 David Koppelman
  2006-01-29  4:50 ` Eli Zaretskii
  2006-01-30  0:57 ` Richard M. Stallman
  0 siblings, 2 replies; 11+ messages in thread
From: David Koppelman @ 2006-01-28 21:17 UTC (permalink / raw)


I've encountered errors in temacs, the same one described by Clemens
Schueller, when make bootstrap is run with "-O3" optimization; -O0,
-O1, and -O2 work fine.  The errors vary with build options but they
all start with "Wrong type argument: listp":

Wrong type argument: listp, -134393892
Wrong type argument: listp, 0
Wrong type argument: listp, [-134218836 [-134218836 #0 gmake[2]: *** [bootstrap-emacs] Segmentation fault
Wrong type argument: listp, []

The lisp error that's followed by a segmentation fault occurs when
loadup.el is loading font-lock. Others occur elsewhere.

The error occurs on today's repository code. I also tried pulling
earlier versions, including 6 January, and the problem occurs there
too.

I'm running on:
 Linux nested 2.6.9-22.0.1.ELsmp #1 SMP Tue Oct 18 18:39:27 EDT 2005 i686 i686 i386 GNU/Linux

and compiling with
 gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)

Is there anything I can do to track down the problem, perhaps
some kind of sanity test?

If it's any help, the difference between -O2 and -O3:
    `-O3'
         Optimize yet more.  `-O3' turns on all optimizations specified by
         `-O2' and also turns on the `-finline-functions', `-fweb' and
         `-frename-registers' options.

I can try compiling at -O2 and try out one of the -O3 optimizations at
a time, if that would help.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-28 21:17 Error with -O3 but not -O2: "Wrong type argument: listp" David Koppelman
@ 2006-01-29  4:50 ` Eli Zaretskii
  2006-01-29 11:47   ` Romain Francoise
                     ` (2 more replies)
  2006-01-30  0:57 ` Richard M. Stallman
  1 sibling, 3 replies; 11+ messages in thread
From: Eli Zaretskii @ 2006-01-29  4:50 UTC (permalink / raw)
  Cc: emacs-devel

> From: David Koppelman <koppel@ece.lsu.edu>
> Date: Sat, 28 Jan 2006 15:17:14 -0600
> 
>     `-O3'
>          Optimize yet more.  `-O3' turns on all optimizations specified by
>          `-O2' and also turns on the `-finline-functions', `-fweb' and
>          `-frename-registers' options.
> 
> I can try compiling at -O2 and try out one of the -O3 optimizations at
> a time, if that would help.

Yes, try that and see which one is the culprit.

Also, it would be useful to run under GDB and see where does Emacs
barf, then compare the machine code between this and the -O2 binary.
We probably have some buggy C code somewhere, or else there's a GCC
bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-29  4:50 ` Eli Zaretskii
@ 2006-01-29 11:47   ` Romain Francoise
  2006-01-29 19:25     ` Xavier Maillard
  2006-01-29 12:46   ` Andreas Schwab
  2006-01-29 18:12   ` David Koppelman
  2 siblings, 1 reply; 11+ messages in thread
From: Romain Francoise @ 2006-01-29 11:47 UTC (permalink / raw)
  Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> We probably have some buggy C code somewhere, or else there's a GCC
> bug.

FWIW, compiling with -O3 used to work with GCC 3.3, and stopped working
with 3.4 and 4.0.

-- 
Romain Francoise <romain@orebokech.com> | The sea! the sea! the open
it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the
                                        | ever free! --Bryan W. Procter

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-29  4:50 ` Eli Zaretskii
  2006-01-29 11:47   ` Romain Francoise
@ 2006-01-29 12:46   ` Andreas Schwab
  2006-01-29 18:12   ` David Koppelman
  2 siblings, 0 replies; 11+ messages in thread
From: Andreas Schwab @ 2006-01-29 12:46 UTC (permalink / raw)
  Cc: David Koppelman, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> We probably have some buggy C code somewhere, or else there's a GCC
> bug.

I couldn't reproduce that on ia64 and ppc (with different compiler
versions), thus a compiler bug is rather likely.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-29  4:50 ` Eli Zaretskii
  2006-01-29 11:47   ` Romain Francoise
  2006-01-29 12:46   ` Andreas Schwab
@ 2006-01-29 18:12   ` David Koppelman
  2006-01-30 18:46     ` Richard M. Stallman
  2 siblings, 1 reply; 11+ messages in thread
From: David Koppelman @ 2006-01-29 18:12 UTC (permalink / raw)
  Cc: emacs-devel

I've re-done the builds at -O2 with -O3 optimizations specified
individually.  Build fails with "-g -O2 -finline-functions" but
succeeds with the other -O3 optimizations. I also re-built with plain
-O3 and -O2 optimizations to verify that the error would and would not
occur at these levels.  (I've listed the variations further below.)

I also tried using -finline-functions at -O0 and -O1, and those builds
worked. I'm not familiar with Emacs' internals but if I had to guess
I'd say this either means that there is a compiler bug which is
encountered with inlining and some -O2 optimization or that there is a
timing issue that's only encountered when Emacs executes very quickly.

I did try using gdb to locate the source of the segmentation fault
but gdb was complaining about threads: 

    (gdb) run --batch --load loadup bootstrap
    Starting program: /fac/drk/localpri/build/emacs/src/temacs --batch --load loadup bootstrap
    [Thread debugging using libthread_db enabled]
    [New Thread -1208084800 (LWP 14053)]
    Cannot find user-level thread for LWP 14053: generic error
    (gdb) quit

I'll try getting gdb to work, I'd appreciate a hint about the gdb
error. (gdb works fine with other programs that I've debugged.)


With the following compile options bootstrap fails:

    CFLAGS="-g -O3"
    CFLAGS="-g -O2 -finline-functions"

With the following compile options bootstrap reaches byte compiling,
at which time I usually interrupt the build and try another
configuration.  I allowed "-g -O2 -fweb -frename-registers" to reach
completion and am using it now.

    CFLAGS="-g -O2 -fweb"
    CFLAGS="-g -O2 -frename-registers"
    CFLAGS="-g -O0 -finline-functions"
    CFLAGS="-g -O1 -finline-functions"
    CFLAGS="-g -O2 -fweb -frename-registers"

Here is a typical build failure:

    ./temacs --batch --load loadup bootstrap
    Loading loadup.el (source)...
    Using load-path (/fac/drk/localpri/build/emacs/lisp /fac/drk/localpri/build/emacs/lisp/emacs-lisp /fac/drk/localpri/build/emacs/lisp/language /fac/drk/localpri/build/emacs/lisp/international /fac/drk/localpri/build/emacs/lisp/textmodes)
    Loading emacs-lisp/byte-run (source)...
    Wrong type argument: listp, []
    gmake[2]: *** [bootstrap-emacs] Error 255
    gmake[2]: Leaving directory `/fac/drk/localpri/build/emacs/src'
    gmake[1]: *** [bootstrap-build] Error 2
    gmake[1]: Leaving directory `/fac/drk/localpri/build/emacs'
    gmake: *** [bootstrap] Error 2

Eli Zaretskii <eliz@gnu.org> writes:

>> From: David Koppelman <koppel@ece.lsu.edu>
>> Date: Sat, 28 Jan 2006 15:17:14 -0600
>> 
>>     `-O3'
>>          Optimize yet more.  `-O3' turns on all optimizations specified by
>>          `-O2' and also turns on the `-finline-functions', `-fweb' and
>>          `-frename-registers' options.
>> 
>> I can try compiling at -O2 and try out one of the -O3 optimizations at
>> a time, if that would help.
>
> Yes, try that and see which one is the culprit.
>
> Also, it would be useful to run under GDB and see where does Emacs
> barf, then compare the machine code between this and the -O2 binary.
> We probably have some buggy C code somewhere, or else there's a GCC
> bug.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-29 11:47   ` Romain Francoise
@ 2006-01-29 19:25     ` Xavier Maillard
  0 siblings, 0 replies; 11+ messages in thread
From: Xavier Maillard @ 2006-01-29 19:25 UTC (permalink / raw)
  Cc: eliz, emacs-devel

   From: Romain Francoise <romain@orebokech.com>
   Cc: emacs-devel@gnu.org

   Eli Zaretskii <eliz@gnu.org> writes:

   > We probably have some buggy C code somewhere, or else there's a GCC
   > bug.

   FWIW, compiling with -O3 used to work with GCC 3.3, and stopped working
   with 3.4 and 4.0.

Confirmed. I did the test here and it worked for GCC 3.3 but not with GCC 3.4
(I did not do the test with 4.0 though).

Xavier

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-28 21:17 Error with -O3 but not -O2: "Wrong type argument: listp" David Koppelman
  2006-01-29  4:50 ` Eli Zaretskii
@ 2006-01-30  0:57 ` Richard M. Stallman
  2006-01-30 15:58   ` David Koppelman
  1 sibling, 1 reply; 11+ messages in thread
From: Richard M. Stallman @ 2006-01-30  0:57 UTC (permalink / raw)
  Cc: emacs-devel

    I've encountered errors in temacs, the same one described by Clemens
    Schueller, when make bootstrap is run with "-O3" optimization; -O0,
    -O1, and -O2 work fine.  The errors vary with build options but they
    all start with "Wrong type argument: listp":

    Wrong type argument: listp, -134393892
    Wrong type argument: listp, 0
    Wrong type argument: listp, [-134218836 [-134218836 #0 gmake[2]: *** [bootstrap-emacs] Segmentation fault
    Wrong type argument: listp, []

The first step is to run under GDB with a breakpoint at
Fsignal and see where the error is signaled.  Then just keep
debugging, tracing things back till you see what caused the
behavior.

What makes this hard is that the bug may not be in the Emacs sources.
It could be that some code was miscompiled.

    I can try compiling at -O2 and try out one of the -O3 optimizations at
    a time, if that would help.

As evidence, it is unlikely to prove anything.  There's no chance
anyone could guess which code is miscompiled just by knowing which
optimization did it.  You will still need to find the miscompiled
line by debugging.

The only way that this is likely to help
is if you can turn off some optimization
that impedes understanding of the machine code.
Having it out of the way would make the job easier.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-30  0:57 ` Richard M. Stallman
@ 2006-01-30 15:58   ` David Koppelman
  2006-01-30 19:21     ` Eli Zaretskii
  2006-01-30 23:25     ` Richard M. Stallman
  0 siblings, 2 replies; 11+ messages in thread
From: David Koppelman @ 2006-01-30 15:58 UTC (permalink / raw)
  Cc: emacs-devel

"Richard M. Stallman" <rms@gnu.org> writes:

> What makes this hard is that the bug may not be in the Emacs sources.
> It could be that some code was miscompiled.

What should be done if it is a compiler bug?  Detect the gcc version
and avoid the -O3 (or use -fno-inline-functions)?  Modify the Emacs
source to work around the bug?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-29 18:12   ` David Koppelman
@ 2006-01-30 18:46     ` Richard M. Stallman
  0 siblings, 0 replies; 11+ messages in thread
From: Richard M. Stallman @ 2006-01-30 18:46 UTC (permalink / raw)
  Cc: eliz, emacs-devel

    I've re-done the builds at -O2 with -O3 optimizations specified
    individually.  Build fails with "-g -O2 -finline-functions" but
    succeeds with the other -O3 optimizations.

This might be a help, but I think there is no avoiding the need to
localize the actual error.  I presume you'll find it occurred in a
function which another function was inlined into.

At that point, careful study of the assembler code of that function
against the source of it and the other functions it calls could be
enough to find the bug.  And maybe the GCC maintainers will do that.

    I did try using gdb to locate the source of the segmentation fault
    but gdb was complaining about threads: 

	(gdb) run --batch --load loadup bootstrap
	Starting program: /fac/drk/localpri/build/emacs/src/temacs --batch --load loadup bootstrap
	[Thread debugging using libthread_db enabled]
	[New Thread -1208084800 (LWP 14053)]
	Cannot find user-level thread for LWP 14053: generic error
	(gdb) quit

Please ask bug-gdb for help on this, and cc me.
GDB should not be doing this when used on Emacs.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-30 15:58   ` David Koppelman
@ 2006-01-30 19:21     ` Eli Zaretskii
  2006-01-30 23:25     ` Richard M. Stallman
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2006-01-30 19:21 UTC (permalink / raw)
  Cc: rms, emacs-devel

> From: David Koppelman <koppel@ece.lsu.edu>
> Date: Mon, 30 Jan 2006 09:58:50 -0600
> Cc: emacs-devel@gnu.org
> 
> What should be done if it is a compiler bug?  Detect the gcc version
> and avoid the -O3 (or use -fno-inline-functions)?  Modify the Emacs
> source to work around the bug?

Probably both, since with compiler bugs, you can never know what other
code it miscompiles.  This one only popped up because you couldn't
bootstrap, but who knows how many other similar problems are out
there.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Error with -O3 but not -O2: "Wrong type argument: listp".
  2006-01-30 15:58   ` David Koppelman
  2006-01-30 19:21     ` Eli Zaretskii
@ 2006-01-30 23:25     ` Richard M. Stallman
  1 sibling, 0 replies; 11+ messages in thread
From: Richard M. Stallman @ 2006-01-30 23:25 UTC (permalink / raw)
  Cc: emacs-devel

    > What makes this hard is that the bug may not be in the Emacs sources.
    > It could be that some code was miscompiled.

    What should be done if it is a compiler bug?

Report it, so that it will get fixed.
All our efforts should be aiming at getting enough
information to report this bug in a useful way.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-01-30 23:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-28 21:17 Error with -O3 but not -O2: "Wrong type argument: listp" David Koppelman
2006-01-29  4:50 ` Eli Zaretskii
2006-01-29 11:47   ` Romain Francoise
2006-01-29 19:25     ` Xavier Maillard
2006-01-29 12:46   ` Andreas Schwab
2006-01-29 18:12   ` David Koppelman
2006-01-30 18:46     ` Richard M. Stallman
2006-01-30  0:57 ` Richard M. Stallman
2006-01-30 15:58   ` David Koppelman
2006-01-30 19:21     ` Eli Zaretskii
2006-01-30 23:25     ` Richard M. Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).