[Python-Dev] OpenBSD anyone?

Guido van Rossum guido at python.org
Mon Dec 22 16:56:40 EST 2003

(JD: yes, it's real!)

> Script started on Mon Dec 22 15:20:25 2003
> hydra /home/kbk/proj/sandbox/python_clean$ gdb ./python
> GNU gdb 4.16.1
> Copyright 1996 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i386-unknown-openbsd3.3"...
> (gdb) run -S
> Starting program: /home/kbk/proj/sandbox/python_clean/./python -S
> Program received signal SIGSEGV, Segmentation fault.
> 0x401900a0 in strchr ()
> (gdb) bt
> #0  0x401900a0 in strchr ()
> #1  0x1d11d in load_next (mod=0x10905c, altmod=0x10905c, p_name=0xcfbfd640, 
>     buf=0xcfbfd230 "__builtin__", p_buflen=0xcfbfd22c) at Python/import.c:2004
> #2  0x1cc40 in import_module_ex (name=0x19786 "__builtin__", globals=0x0, locals=0x0, 
>     fromlist=0x0) at Python/import.c:1888
> #3  0x1ce29 in PyImport_ImportModuleEx (name=0x19786 "__builtin__", globals=0x0, locals=0x0, 
>     fromlist=0x0) at Python/import.c:1922
> #4  0x1dfe9 in PyImport_Import (module_name=0x115598) at Python/import.c:2333
> #5  0x1caec in PyImport_ImportModule (name=0xb895e "__builtin__") at Python/import.c:1853
> #6  0xb8b3d in _PyExc_Init () at Python/exceptions.c:1755
> #7  0x25ad4 in Py_Initialize () at Python/pythonrun.c:205
> #8  0x282f in Py_Main (argc=2, argv=0xcfbfd82c) at Modules/main.c:376
> #9  0x17e3 in main (argc=2, argv=0xcfbfd82c) at Modules/python.c:23
> (gdb) q
> The program is running.  Quit anyway (and kill it)? (y or n) y
> hydra /home/kbk/proj/sandbox/python_clean$ 
> Script done on Mon Dec 22 15:21:06 2003
> Same result w/o -S
> =============================================================
> Slightly later:
> (gdb) b import.c:2004
> Breakpoint 1 at 0x1d10f: file Python/import.c, line 2004.
> (gdb) r
> Starting program: /home/kbk/proj/sandbox/python_clean/./python 
> Breakpoint 1, load_next (mod=0xe98ec, altmod=0xe98ec, p_name=0xcfbfd88c, buf=0xcfbfd47c "", 
>     p_buflen=0xcfbfd478) at Python/import.c:2004
> 2004            char *dot = strchr(name, '.');
> (gdb) p *p_name
> $1 = 0x19786 "__builtin__"
> (gdb) p name
> $2 = 0x19786 "__builtin__"
> (gdb) p strchr(name, '.')
> Program received signal SIGSEGV, Segmentation fault.
> OTOH, if I break at 2004 and then step once, I get by the strchr call
> OK.  Also if I stepi through it.  If I continue, it segfaults at the
> next execution of line 2004.  Weird.
> Investigating.

The most likely cause then is some kind of bug in the platform's
strchr().  This could explain why -O3 fixes the issue: I think I've
heard of GCC replacing calls to strchr(), strcpy() etc. with inline
code, thereby avoiding the buggy library version (and explaining why
the buggy code could persist undetected in the library -- most system
code is of course compiled fully optimized).

As to why stepi doesn't trigger the segfault: possibly it's a timing
bug that doesn't occur when run one instruction at a time.  This would
even make it CPU dependent, which would explain that some folks didn't
see this.  I don't have the OpenBSD strchr.c source code online here
so I'll stop speculating here...

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list