Bug 57777 - [4.7 Regression] Python module fails compilation with "-march=core-avx2 -O3"
Summary: [4.7 Regression] Python module fails compilation with "-march=core-avx2 -O3"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.3
: P3 normal
Target Milestone: 4.7.4
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-02 11:22 UTC by Dirkjan Ochtman
Modified: 2014-05-07 16:18 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-*-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-02 00:00:00


Attachments
_randommodule-preprocessed.c (45.78 KB, text/x-csrc)
2013-07-02 12:33 UTC, Julian Ospald
Details
gcc49-pr57777.patch (803 bytes, patch)
2013-07-02 18:50 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirkjan Ochtman 2013-07-02 11:22:53 UTC
gcc-4.7 "-march=core-avx2 -O3" -> fails
gcc-4.7 "-march=core-avx2 -O2" -> succeeds

gcc-4.7 "-march=core-avx-i -O3" -> succeeds
gcc-4.7 "-march=core-avx-i -O2" -> succeeds

gcc-4.6 "-march=core-avx-i -O3" -> succeeds
gcc-4.6 "-march=core-avx-i -O2" -> succeeds

Failure happens like this:

building '_random' extension
x86_64-pc-linux-gnu-gcc -pthread -fPIC -fno-strict-aliasing -march=core-avx2 -O2 -pipe -Wall -g -O3 -fwrapv -DNDEBUG -I. -IInclude -I/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Include -I/var/tmp/portage/dev-lang/python-2.7.5/work/x86_64-pc-linux-gnu -c /var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Modules/_randommodule.c -o build/temp.linux-x86_64-2.7/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Modules/_randommodule.o
x86_64-pc-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -L. -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -L. -fno-strict-aliasing -march=core-avx2 -O2 -pipe -Wall -g -O3 -fwrapv -DNDEBUG -I. -IInclude -I/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Include build/temp.linux-x86_64-2.7/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Modules/_randommodule.o -L/usr/local/lib -L. -lpython2.7 -o build/lib.linux-x86_64-2.7/_random.so

/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: build/temp.linux-x86_64-2.7/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Modules/_randommodule.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

build/temp.linux-x86_64-2.7/var/tmp/portage/dev-lang/python-2.7.5/work/Python-2.7.5/Modules/_randommodule.o: could not read symbols: Bad value

collect2: error: ld returned 1 exit status
Comment 1 Dirkjan Ochtman 2013-07-02 11:23:15 UTC
See https://bugs.gentoo.org/show_bug.cgi?id=475482 for more information.
Comment 2 Jonathan Wakely 2013-07-02 11:43:12 UTC
Please provide preprocessed source of _randommodule.c
Comment 3 Julian Ospald 2013-07-02 12:33:38 UTC
Created attachment 30418 [details]
_randommodule-preprocessed.c
Comment 4 H.J. Lu 2013-07-02 15:41:22 UTC
The problem is in

        .text
        vpgatherqq      %ymm8, mag01.10849(,%ymm6,8), %ymm5
        .section        .rodata
        .align 16
        .type   mag01.10849, @object
        .size   mag01.10849, 16
mag01.10849:
        .quad   0   
        .quad   2567483615

"mag01.10849(,%ymm6,8)" isn't PC relative.
Comment 5 Jakub Jelinek 2013-07-02 17:40:57 UTC
Reduced testcase for -O3 -mavx2 -fpic:
void
foo (unsigned long *x, int *y)
{
  static unsigned long b[2] = { 0x0UL, 0x9908b0dfUL };
  int c;
  for (c = 0; c < 512; c++)
    x[c] = b[x[c] & 1UL];
}
Comment 6 Jakub Jelinek 2013-07-02 18:50:24 UTC
Created attachment 30425 [details]
gcc49-pr57777.patch

Untested fix.
Comment 7 Julian Ospald 2013-07-02 21:15:51 UTC
(In reply to Jakub Jelinek from comment #6)
> Created attachment 30425 [details]
> gcc49-pr57777.patch
> 
> Untested fix.

I have tested that patch on gcc-4.8 and was able to compile the python module successfully with "-march=core-avx2 -O3".

gcc-4.8 is affected as well without that patch, as the title correctly says.
Comment 8 Julian Ospald 2013-07-02 21:37:38 UTC
tested with gcc-4.7.3, and it works as well

for clarification: the previous test was with 4.8.1
Comment 9 Julian Ospald 2013-07-03 13:49:21 UTC
patch tested with gcc-4.9.0_alpha20130505, works as well
Comment 10 Jakub Jelinek 2013-07-03 20:30:15 UTC
Author: jakub
Date: Wed Jul  3 20:23:38 2013
New Revision: 200649

URL: http://gcc.gnu.org/viewcvs?rev=200649&root=gcc&view=rev
Log:
	PR target/57777
	* config/i386/predicates.md (vsib_address_operand): Disallow
	SYMBOL_REF or LABEL_REF in parts.disp if TARGET_64BIT && flag_pic.

	* gcc.target/i386/pr57777.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr57777.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/predicates.md
    trunk/gcc/testsuite/ChangeLog

Author: jakub
Date: Wed Jul  3 20:24:19 2013
New Revision: 200650

URL: http://gcc.gnu.org/viewcvs?rev=200650&root=gcc&view=rev
Log:
	PR target/57777
	* config/i386/predicates.md (vsib_address_operand): Disallow
	SYMBOL_REF or LABEL_REF in parts.disp if TARGET_64BIT && flag_pic.

	* gcc.target/i386/pr57777.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.target/i386/pr57777.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/config/i386/predicates.md
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog

Fixed for 4.8.2+ so far.
Comment 11 Piotr 2013-08-10 18:47:03 UTC
(In reply to Julian Ospald from comment #7)
> (In reply to Jakub Jelinek from comment #6)
> > Created attachment 30425 [details]
> > gcc49-pr57777.patch
> > 
> > Untested fix.
> 
> I have tested that patch on gcc-4.8 and was able to compile the python
> module successfully with "-march=core-avx2 -O3".
> 
> gcc-4.8 is affected as well without that patch, as the title correctly says.

I had a similar situation with gcc 4.8.1, with "-O3 -march=core-avx2" and had to pass -mno-avx2 in order to compile. For the sake of curiosity could you confirm if "-O3 -march=core-avx2 -mno-avx2" compiles?



gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-isl=/builddir/build/BUILD/gcc-4.8.1-20130603/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130603/obj-x86_64-redhat-linux/cloog-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.1 20130603 (Red Hat 4.8.1-1) (GCC) 

system, fedora19
Comment 12 Jakub Jelinek 2014-05-07 16:00:09 UTC
Author: jakub
Date: Wed May  7 15:59:37 2014
New Revision: 210169

URL: http://gcc.gnu.org/viewcvs?rev=210169&root=gcc&view=rev
Log:
	Backported from mainline
	2013-07-03  Jakub Jelinek  <jakub@redhat.com>

	PR target/57777
	* config/i386/predicates.md (vsib_address_operand): Disallow
	SYMBOL_REF or LABEL_REF in parts.disp if TARGET_64BIT && flag_pic.

	* gcc.target/i386/pr57777.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/i386/pr57777.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/predicates.md
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 13 Jakub Jelinek 2014-05-07 16:18:11 UTC
Fixed.