Bug 1409009 - Fails to build with GCC 6 and Python 3.6 due to competing HAVE_LONG_LONG definitions
Summary: Fails to build with GCC 6 and Python 3.6 due to competing HAVE_LONG_LONG defi...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc-python-plugin
Version: rawhide
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Dave Malcolm
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-12-28 22:21 UTC by Adam Williamson
Modified: 2017-01-25 20:47 UTC (History)
6 users (show)

Fixed In Version: gcc-python-plugin-0.15-10.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-24 21:27:04 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Build.log when adding `#undef HAVE_LONG_LONG` after `#include <Python.h>` (1013.84 KB, text/plain)
2017-01-03 15:18 UTC, Miro Hrončok
no flags Details
Workaround of this issue (11.00 KB, application/mbox)
2017-01-03 18:08 UTC, Miro Hrončok
no flags Details
Workaround of this issue (2.21 KB, application/mbox)
2017-01-04 02:30 UTC, Miro Hrončok
no flags Details

Description Adam Williamson 2016-12-28 22:21:03 UTC
gcc-python-plugin fails to build on Rawhide. This seems to be because gcc and python have competing definitions of HAVE_LONG_LONG in header files that are both included during the build:

/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h
/usr/include/python3.6m/pyport.h

The exact error messages are:

cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-callbacks.o gcc-python-callbacks.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-callgraph.o gcc-python-callgraph.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-attribute.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-attribute.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-cfg.o gcc-python-cfg.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-callbacks.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-callbacks.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-closure.o gcc-python-closure.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-callgraph.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-callgraph.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-diagnostics.o gcc-python-diagnostics.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-cfg.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-cfg.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python-closure.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-closure.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc -O2 -Werror -g -fPIC -fno-strict-aliasing -Wall -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/c-family -I. -I/usr/include/python3.6m -I/usr/include/python3.6m -DPLUGIN_PYTHONPATH='"/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/python3"'  -c -x c++ -fno-rtti -o gcc-python-function.o gcc-python-function.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-diagnostics.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-diagnostics.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/config.h:6:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/gcc-plugin.h:27,
                 from gcc-python.h:23,
                 from gcc-python-function.c:21:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h:1574:0: error: "HAVE_LONG_LONG" redefined [-Werror]
 #define HAVE_LONG_LONG 1
 
In file included from /usr/include/python3.6m/Python.h:50:0,
                 from gcc-python-function.c:20:
/usr/include/python3.6m/pyport.h:42:0: note: this is the location of the previous definition
 #define HAVE_LONG_LONG
 
cc1plus: all warnings being treated as errors
cc1plus: all warnings being treated as errors
cc1plus: all warnings being treated as errors
make: *** [Makefile:159: gcc-python-closure.o] Error 1
make: *** Waiting for unfinished jobs....

Comment 1 Charalampos Stratakis 2017-01-03 13:37:20 UTC
I couldn't compile gdb with python 3.6 so I filled an upstream issue to protect the HAVE_LONG_LONG definition (as gdb defines it as well), which is in Python 3.6.0 final that currently resides in rawhide.

Relevant issue: http://bugs.python.org/issue28898

This seems to be a different issue though. I guess the gcc defines HAVE_LONG_LONG but it does not protect it against redefinition?

Comment 2 Charalampos Stratakis 2017-01-03 13:55:17 UTC
The people I requested a needinfo might provide us some insight here.

Comment 3 Petr Viktorin (pviktori) 2017-01-03 14:06:05 UTC
Python itself doesn't use HAVE_LONG_LONG (it doesn't work on platforms without the type), but, for backwards compatibility, it defines the macro if undefined.

A possible workaround could be to `#define HAVE_LONG_LONG 1` *before* including the Python headers, or to #undefine it just after.

Comment 4 Miro Hrončok 2017-01-03 15:17:30 UTC
Even if I undefine HAVE_LONG_LONG after including Python.h, the build fails.

Will attach build.log

Comment 5 Miro Hrončok 2017-01-03 15:18:41 UTC
Created attachment 1236911 [details]
Build.log when adding `#undef HAVE_LONG_LONG` after `#include <Python.h>`

Comment 6 Petr Viktorin (pviktori) 2017-01-03 15:38:23 UTC
Um, did a file get corrupted in that build?

gcc-python-tree.c:2:4: error: 'Copyright' does not name a type
    Copyright 2011-2015 David Malcolm <dmalcolm>
    ^~~~~~~~~

Comment 7 Miro Hrončok 2017-01-03 16:04:04 UTC
Oh, my bad. Sorry, will try again.

Comment 8 Miro Hrončok 2017-01-03 18:08:04 UTC
Created attachment 1236947 [details]
Workaround of this issue

So I've managed to workaround this issue by adding `#undef HAVE_LONG_LONG` after `#include <Python.h>`.

Since there are tests that check line numbers in gcc errors of autogenerated C files and the workaround adds an extra line, I disabled those tests for now, because adding workarounds for workarounds was going too deep.

Added a comment to remember to re-enable those tests once a proper fix is introduced.

All worked in mock, so I've tried Koji scratch build. It failed on ppc64le (I think with unrelated issue).

Dist-git commit patch attached.

https://koji.fedoraproject.org/koji/taskinfo?taskID=17157941

As for proper fix I think one of the following is needed:

 * guarded HAVE_LONG_LONG definition in /usr/lib/gcc/x86_64-redhat-linux/6.3.1/plugin/include/auto-host.h
 * don't define HAVE_LONG_LONG in Python.h or undefine it at the end (might possibly break other stuff)

Comment 9 Miro Hrončok 2017-01-03 18:17:22 UTC
ppc64 failed as well

Comment 10 Dave Malcolm 2017-01-03 21:41:28 UTC
(In reply to Charalampos Stratakis from comment #1)
> I couldn't compile gdb with python 3.6 so I filled an upstream issue to
> protect the HAVE_LONG_LONG definition (as gdb defines it as well), which is
> in Python 3.6.0 final that currently resides in rawhide.
> 
> Relevant issue: http://bugs.python.org/issue28898
> 
> This seems to be a different issue though. I guess the gcc defines
> HAVE_LONG_LONG but it does not protect it against redefinition?

Thanks.  Looking at that upstream bug, I see:

  [cherrypicked for 3.6.0rc2]

so it looks like this was fixed in that release of CPython:

  https://hg.python.org/cpython/rev/d6c8803c55b4/

Do we have that patch in our builds on Python 3?

Comment 11 Dave Malcolm 2017-01-03 21:44:42 UTC
(In reply to Miro Hrončok from comment #9)
> ppc64 failed as well

Looks like some of the testsuite failed within %check:

Specifically, ppc64le and ppc64 both show one unexpected failure:
  tests/cpychecker/absinterp/bitfields/reading: FAIL

due to int vs char issues.

Comment 12 Miro Hrončok 2017-01-03 23:51:15 UTC
(In reply to Dave Malcolm from comment #11)
> (In reply to Miro Hrončok from comment #9)
> > ppc64 failed as well
> 
> Looks like some of the testsuite failed within %check:
> 
> Specifically, ppc64le and ppc64 both show one unexpected failure:
>   tests/cpychecker/absinterp/bitfields/reading: FAIL
> 
> due to int vs char issues.

The question is: Is that expected and can the test be safely changed on those arches? I'd say yes, but would like some confirmation.

Comment 13 Miro Hrončok 2017-01-04 00:35:00 UTC
Trying a Koji scratch build with:

  %ifarch ppc64 ppc64p7 ppc64le
  # see https://bugzilla.redhat.com/show_bug.cgi?id=1409009#c11
  sed -i 's/(unsigned char)/(unsigned int)/g' tests/cpychecker/absinterp/bitfields/reading/stdout.txt
  %endif

https://koji.fedoraproject.org/koji/taskinfo?taskID=17159245

Comment 14 Miro Hrončok 2017-01-04 01:49:27 UTC
(In reply to Miro Hrončok from comment #13)
> Trying a Koji scratch build with:
> 
>   %ifarch ppc64 ppc64p7 ppc64le
>   # see https://bugzilla.redhat.com/show_bug.cgi?id=1409009#c11
>   sed -i 's/(unsigned char)/(unsigned int)/g'
> tests/cpychecker/absinterp/bitfields/reading/stdout.txt
>   %endif
> 
> https://koji.fedoraproject.org/koji/taskinfo?taskID=17159245

Apparently, not enough.

Comment 15 Miro Hrončok 2017-01-04 02:30:49 UTC
Created attachment 1237053 [details]
Workaround of this issue

Here is another (more staightforward) attempt to workaround the HAVE_LONG_LONG issue. It just adds `-D HAVE_LONG_LONG=1` to CFLAGS.

It builds and the affected tests from previous attempt are not affected here, so no need to disable them all as before.

However, those test fail on python3-debug with:

  #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]

(The entire line was `gcc -o /tmp/tmp0y9lkyj1/example.cpython-36dm-x86_64-linux-gnu.so -I/usr/include/python3.6dm -I/usr/include/python3.6dm -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O0 -Wall -Werror -fPIC -shared -fplugin=/builddir/build/BUILD/gcc-python-plugin-0.15-building-for-python3_debug/python3_debug.so -fplugin-arg-python3_debug-script=cpychecker.py -fno-diagnostics-show-caret /tmp/tmp0y9lkyj1/example.c`. Notice that `-O*` is used multiple times.)

So I've disabled them on python3-debug for now. Since they were disabled anyway in the previous attempt I think this patch is better and making it obsolete the previous one.

(This is unrelated to the ppc error, that remains there.)

Koji scratch build: https://koji.fedoraproject.org/koji/taskinfo?taskID=17159421

Comment 16 Charalampos Stratakis 2017-01-04 09:39:33 UTC
(In reply to Dave Malcolm from comment #10)
> (In reply to Charalampos Stratakis from comment #1)
> > I couldn't compile gdb with python 3.6 so I filled an upstream issue to
> > protect the HAVE_LONG_LONG definition (as gdb defines it as well), which is
> > in Python 3.6.0 final that currently resides in rawhide.
> > 
> > Relevant issue: http://bugs.python.org/issue28898
> > 
> > This seems to be a different issue though. I guess the gcc defines
> > HAVE_LONG_LONG but it does not protect it against redefinition?
> 
> Thanks.  Looking at that upstream bug, I see:
> 
>   [cherrypicked for 3.6.0rc2]
> 
> so it looks like this was fixed in that release of CPython:
> 
>   https://hg.python.org/cpython/rev/d6c8803c55b4/
> 
> Do we have that patch in our builds on Python 3?

Yep, our build is the 3.6.0 final which includes this fix

Comment 17 Petr Viktorin (pviktori) 2017-01-06 10:13:51 UTC
The macro definition was fixed upstream; the fix should appear in Python 3.6.1.

https://hg.python.org/cpython/rev/fad67c66885f
http://bugs.python.org/issue27961

Even though gcc-plugin is the only thing in Fedora that hit this, I think we should backport it in Python.

Comment 18 Charalampos Stratakis 2017-01-09 13:44:48 UTC
(In reply to Petr Viktorin from comment #17)
> The macro definition was fixed upstream; the fix should appear in Python
> 3.6.1.
> 
> https://hg.python.org/cpython/rev/fad67c66885f
> http://bugs.python.org/issue27961
> 
> Even though gcc-plugin is the only thing in Fedora that hit this, I think we
> should backport it in Python.

Just backported the fix in rawhide at python3-3.6.0-4.fc26 build, so the HAVE_LONg_LONG definition shouldn't be a problem anymore.

Comment 19 Charalampos Stratakis 2017-01-24 16:41:19 UTC
The competing HAVE_LONG_LONG definitions have been fixed.

The issue as it seems is that when the test for reading from a bitfield [0] is invoked then as we can see at the expected output [1], an unsigned int is expected for Trace 0, 3 and 4 [2].

This holds True for all the platforms except the ppc ones where an unsigned int is returned (or sent to the stdout).

[0] https://git.fedorahosted.org/cgit/gcc-python-plugin.git/tree/tests/cpychecker/absinterp/bitfields/reading/input.c

[1] https://git.fedorahosted.org/cgit/gcc-python-plugin.git/tree/tests/cpychecker/absinterp/bitfields/reading/stdout.txt

[2] when considering value == (unsigned char)

Comment 20 Charalampos Stratakis 2017-01-24 21:27:04 UTC
So I used Miro's patch to skip the tests when being invoked with the python3-debug, and also I added an extra patch to skip this one test case that fails on ppc, for the time being.

Comment 21 Adam Williamson 2017-01-25 06:36:47 UTC
I, uh, well, that's a way to fix it, sure =)

maybe file a bug upstream or mention it to the ppc64 team? it sounds a lot like a big-endian bug they'd want to get fixed.

Comment 22 Charalampos Stratakis 2017-01-25 08:51:49 UTC
(In reply to Adam Williamson from comment #21)
> I, uh, well, that's a way to fix it, sure =)
> 
> maybe file a bug upstream or mention it to the ppc64 team? it sounds a lot
> like a big-endian bug they'd want to get fixed.

gcc-python-plugin is not really maintained anymore upstream. I will file a bugzilla for the ppc64 tracker though, if someone wants to tackle that issue.

Comment 23 Dave Malcolm 2017-01-25 14:24:44 UTC
(In reply to Charalampos Stratakis from comment #22)
> (In reply to Adam Williamson from comment #21)
> > I, uh, well, that's a way to fix it, sure =)
> > 
> > maybe file a bug upstream or mention it to the ppc64 team? it sounds a lot
> > like a big-endian bug they'd want to get fixed.

It's not so much a bug in the code as a bug in the tests.  When I wrote the test suite I fell into the trap of the "gold output" anti-pattern.  Rewriting the test suite to work in a saner way is lower priority than my gcc work, so it's unlikely I'll ever do it.

> gcc-python-plugin is not really maintained anymore upstream. I will file a
> bugzilla for the ppc64 tracker though, if someone wants to tackle that issue.

It's, err,  pining for the fjords.   I do a release about once a year, when the a gcc comes out.

Comment 24 Dave Malcolm 2017-01-25 14:26:02 UTC
(In reply to Dave Malcolm from comment #23)
[...]
> It's, err,  pining for the fjords.   I do a release about once a year, when
> the a gcc comes out.

s/a gcc/new release of gcc/

Oh, and thanks for fixing this Charalampos.

Comment 25 Adam Williamson 2017-01-25 20:47:20 UTC
I see, thanks guys! Sounds like there's nothing to worry about.


Note You need to log in before you can comment on or make changes to this bug.