davidmalcolm / gcc-python-plugin

GCC plugin that embeds CPython inside the compiler
GNU General Public License v3.0
197 stars 58 forks source link

Cannot build in Ubuntu with gcc-7 and gcc-8 #188

Open arquicanedo opened 4 years ago

arquicanedo commented 4 years ago

Hi, I'm trying to compile the gcc-python-plugin. I tried with both gcc-7 and gcc-8. I'm using Python 3.8 and building with

make PYTHON=python3.8 PYTHON_CONFIG=python3.8-config

The first problem is related to this error:

gcc-python-wrapper.c:188:1: error: converting to non-pointer type ‘long int’ from NULL [-Werror=conversion-null]
 };
 ^
cc1plus: all warnings being treated as errors
make: *** [Makefile:168: gcc-python-wrapper.o] Error 1

I thought a workaround is to replace -Werror with -Wno-error in the Makefile.

This generates the python.so but fails in the demo as follows

cc1: error: cannot load plugin /home/canedo/MINDSIGHT/gcc-python-plugin/python.so
   /home/canedo/gcc-python-plugin/python.so: undefined symbol: PyExc_NotImplementedError
make[1]: *** [Makefile:303: demo] Error 1

Any hints would be highly appreciated. Thanks.

davidmalcolm commented 3 years ago

I believe these are incompatibilities with Python 3.8, which hopefully have been fixed by cdb70205bd5854c455dc1af205e9d5f7ce4afb66 and 4deefc840e69e3c2c42f8a50963b8fb69c17efee. That said, I'm still seeing: TypeError: 'gcc.WrapperMeta' object is not iterable (with Python 3.8 and gcc 10) which I'm investigating.

kristerw commented 2 years ago

I'm still seeing: TypeError: 'gcc.WrapperMeta' object is not iterable (with Python 3.8 and gcc 10) which I'm investigating.

I took a quick look at this, and I have a patch (see below).

The issue is that the Python MRO is freeing an object it is using. This started to happen with the change

commit 2e9954d3472a23919b96323fcd5bb6c1d6927155
Author: Jeroen Demeyer <J.Demeyer@UGent.be>
Date:   Mon Jun 17 13:53:21 2019 +0200

    bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)

(which later was cherry-picked to the Python 3.8 branch). I do not understand how the Python MRO works, but this looks unrelated to what gcc-python-plugin does, and seems to just be an optimization... So it seemed likely to me that the plugin sets some flags inconsistently...

And I found one place that looked suspicious. Changing this as in the patch

--- a/generate-gimple-c.py
+++ b/generate-gimple-c.py
@@ -231,7 +231,7 @@ PyGccGimple_get_block(struct PyGccGimple *self, void *closure)
                           tp_str = '(reprfunc)PyGccGimple_str',
                           tp_hash = '(hashfunc)PyGccGimple_hash',
                           tp_richcompare = 'PyGccGimple_richcompare',
-                          tp_flags = 'Py_TPFLAGS_BASETYPE',
+                          tp_flags = '(Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE)',
                           )
     methods = PyMethodTable('PyGccGimple_methods', [])
     methods.add_method('walk_tree',

makes the plugin work again, although I have only tested with some simple scripts (using Python 3.9 and GCC 8.5).

jmikedupont2 commented 2 years ago

Oh nice to see this patch, I did not see that before, my solution was to strip out the entire metaclass #192 I am going to try your patch as well.

kristerw commented 1 year ago

The Python problem giving us gcc.WrapperMeta errors was fixed in Python 3.9.13, and all versions of 3.10 seem to work too.