davidmalcolm / gcc-python-plugin

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

python.so: undefined symbol: gcc_location_offset_column #164

Closed nickodell closed 5 years ago

nickodell commented 5 years ago

I'm able to build python.so by running make plugin.

I get this error message when I run gcc -fplugin=python.so test2.c:

cc1: error: cannot load plugin python.so
   python.so: undefined symbol: gcc_location_offset_column

Current revision of gcc-python-plugin: 49fc210b429 gcc version:

gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

System info: Debian 9.6

Also, some tests fail:

219 successes; 14 failures; 0 skipped
Failed tests:
  tests/cpychecker/refcounts/PyDict_SetItem/correct
  tests/cpychecker/refcounts/PyDict_SetItemString/correct
  tests/cpychecker/refcounts/PyDict_SetItemString/incorrect
  tests/cpychecker/refcounts/PyFloat_AsDouble/correct_PyFloatObject
  tests/cpychecker/refcounts/PySequence_Size/correct
  tests/cpychecker/refcounts/PySequence_Size/null
  tests/cpychecker/refcounts/Py_BuildValue/correct-code-N
  tests/cpychecker/refcounts/Py_BuildValue/correct-code-O
  tests/cpychecker/refcounts/attributes/returns-borrowed-ref/correct-usage
  tests/cpychecker/refcounts/loops/complex-loop-conditional-1
  tests/cpychecker/refcounts/loops/complex-loop-conditional-2
  tests/cpychecker/refcounts/macros/Py_XDECREF/crash
  tests/cpychecker/refcounts/object_from_callback
  tests/cpychecker/refcounts/ticket-20
Makefile:313: recipe for target 'test-suite' failed
davidmalcolm commented 5 years ago

gcc_location_offset_column is part of gcc-c-api/gcc-location.c, so this suggests that gcc-c-api isn't being found

nickodell commented 5 years ago

Adding gcc-c-api/libgcc-c-api.so to the command for building python.so fixes this. Here's a patch:

diff --git a/Makefile b/Makefile
index c87ae8d..fb8a3c6 100644
--- a/Makefile
+++ b/Makefile
@@ -152,7 +152,7 @@ $(PLUGIN_DSO): $(PLUGIN_OBJECT_FILES) $(LIBGCC_C_API_SO)
        $(PLUGIN_OBJECT_FILES) \
        -o $@ \
        $(LIBS) \
-       -lgcc-c-api -Lgcc-c-api -Wl,-rpath=$(GCCPLUGINS_DIR)
+       -lgcc-c-api -Lgcc-c-api gcc-c-api/libgcc-c-api.so -Wl,-rpath=$(GCCPLUGINS_DIR)

 $(pwd)/gcc-c-api:
    mkdir -p $@