This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Linking to gcc's gomp causes crash later.
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: hoytak, iritkatriel, terry.reedy
Priority: normal Keywords:

Created on 2011-02-21 17:54 by hoytak, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-gomp-bug.tar.gz hoytak, 2011-02-21 17:54 Code to reproduce gomp loading bug.
Messages (4)
msg128974 - (view) Author: Hoyt Koepke (hoytak) Date: 2011-02-21 17:54
Hello,

I've encountered a strange bug that appears to be either in gcc's gomp
implementation or in how python loads extension modules linked against
gomp.  Here's the error:

Using gcc (multiple versions) on linux, I compile an empty c extension
module and pass -lgomp as a linker arg.  If I import it, running a
simple script in matplotlib causes a segfault.  Not passing -lgomp or
not loading the empty module makes the code works fine.  More
specifically, if I compile:

#include "Python.h"
static struct PyMethodDef methods[] = {
 {0, 0, 0, 0}
};
PyMODINIT_FUNC initempty(void) {
 Py_InitModule4("empty", methods, 0, 0, PYTHON_API_VERSION);
}

using ``ext_modules = [Extension("empty", ["empty.c"], extra_link_args
= ["-lgomp"])]``, then

import empty
import matplotlib.pylab as plt

plt.figure()
plt.plot([0,1], [0,1], '-b')
plt.show()


causes the program to segfault (removing ``import empty`` makes it
fine).  Looking at a traceback:

#0  0x00f78bc7 in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6
#1  0x008f51f2 in py_to_agg_transformation_matrix (obj=0x8223f58,
errors=false) at src/agg_py_transforms.cpp:20
#2  0x008fdd73 in _path_module::update_path_extents (this=0x8e45f90,
args=...) at src/path.cpp:378
#3  0x009048bd in
Py::ExtensionModule<_path_module>::invoke_method_varargs (this=<value
optimized out>, method_def=0x8e9ae30, args=...) at
./CXX/Python2/ExtensionModule.hxx:184
#4  0x008f0d96 in method_varargs_call_handler
(_self_and_name_tuple=0x8e6eeac, _args=0x94e683c) at
CXX/Python2/cxx_extensions.cxx:1714
#5  0x080dc0d0 in PyEval_EvalFrameEx ()
#6  0x080dddf2 in PyEval_EvalCodeEx ()

While occurring in some of matplotlib's extension code (and I haven't
found another library that crashes it), the fact that the deciding
factor is whether I link against gomp indicates the it's probably
upstream somewhere.

I encountered this error a year ago and asked about it on the
matplotlib mailing list, but found a quick workaround then, and with
deadline pressure I forgot about it.  However, it's come up again, and
then I was asked to bump it to python-dev, which is why I'm posting it
here.

I can reproduce it on the following systems.  In all cases, matplotlib
is compiled from source on the development branch (r8969) and uses
QT4Agg as the backend, as is numpy, scipy, etc.  If needed, I can
track down more versions.

gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.4, 64bit, Python 2.6.6, ubuntu 10.10
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3, 64bit, Python 2.6.5, ubuntu 10.04
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1, 32bit, Python 2.6.4, ubuntu 9.10

gcc 4.5.2 (source build), Python 2.6.5, ubuntu 10.04.  On this build,
the given source example does not produce the result, and I haven't
been able to tweak it so it does.  However, linking to a much larger
extension library that uses many different parts of openmp causes
exactly the same crash.  If I recompile that library without openmp
support, then everything works fine; with openmp support it corrupts
something and matplotlib crashes in exactly the same way.

gcc 4.3.2, Python 2.6.2, ubuntu 9.04 (I don't have access to this
system any more, since it got upgraded, but it had the same problem a
year ago).

I attached example code that reproduces it.  

Thanks,

--Hoyt
msg129412 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-02-25 20:03
2.6 is in security-fix only mode (though this might qualify as a security issue). Can you test with a current version (2.7.1, 3.2.0)?
That said, most problems with extensions crashing are with the extension, though hard to determine sometimes.
msg129672 - (view) Author: Hoyt Koepke (hoytak) Date: 2011-02-28 00:22
Okay, finally got to test this on a system with python 2.7.1+ (development branch, r88606, and indeed, the same crash occurs.  This one was compiled from scratch with gcc 4.5.2.
msg404213 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-10-18 19:35
Please create a new issue if you see the problem on a current python version.
History
Date User Action Args
2022-04-11 14:57:13adminsetgithub: 55484
2021-10-18 19:35:07iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg404213

resolution: out of date
stage: test needed -> resolved
2011-02-28 00:22:19hoytaksetnosy: terry.reedy, hoytak
messages: + msg129672
2011-02-25 20:03:29terry.reedysetnosy: + terry.reedy

messages: + msg129412
stage: test needed
2011-02-21 17:54:35hoytakcreate