Bug 44169 - Wrong code while generating TLS offsets
Summary: Wrong code while generating TLS offsets
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.4.4
: P3 normal
Target Milestone: ---
Assignee: Alan Modra
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 15:43 UTC by Sebastian Andrzej Siewior
Modified: 2010-06-03 03:26 UTC (History)
3 users (show)

See Also:
Host: powerpc-linux-gnuspe
Target: powerpc-*
Build: powerpc-linux-gnuspe
Known to work: 4.3.5
Known to fail: 4.4.4 4.6.0
Last reconfirmed: 2010-05-28 07:30:15


Attachments
test case (320 bytes, text/plain)
2010-05-17 15:44 UTC, Sebastian Andrzej Siewior
Details
rtl pass 185r.cprop_hardreg (1.75 KB, text/plain)
2010-05-17 15:44 UTC, Sebastian Andrzej Siewior
Details
rtl pass 186r.dce (2.85 KB, text/plain)
2010-05-17 15:45 UTC, Sebastian Andrzej Siewior
Details
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.3.4 (1.51 KB, text/plain)
2010-05-20 12:17 UTC, Kyle Moffett
Details
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.4.4 (1.58 KB, text/plain)
2010-05-20 12:19 UTC, Kyle Moffett
Details
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.4.2 (1.59 KB, text/plain)
2010-05-20 12:29 UTC, Kyle Moffett
Details
ok at this point (4.61 KB, text/plain)
2010-05-28 02:31 UTC, Alan Modra
Details
broken here, see insn 27 (2.09 KB, text/plain)
2010-05-28 02:32 UTC, Alan Modra
Details
gcc-4.4 patch (831 bytes, patch)
2010-05-28 13:16 UTC, Alan Modra
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Andrzej Siewior 2010-05-17 15:43:44 UTC
libgomp testsuite fails with a segfault. It segfaults in gomp_resolve_num_threads(), accessing the second TLS value.

The first access:
 .LBB28:
         .file 2 "../../../src/libgomp/libgomp.h"
         .loc 2 380 0
         bcl 20,31,$+8
         .long _GLOBAL_OFFSET_TABLE_-$
         mflr 9
         lwz 0,0(9)
         add 9,9,0
         lwz 9,gomp_tls_data@got@tprel(9)
         add 9,9,gomp_tls_data@tls
         lwz 9,40(9)

The second:
.LBE27:
         .loc 1 47 0
         cmpwi 7,3,1
         beq- 7,.L37
 .LVL32:
         .loc 1 49 0
         bcl 20,31,$+8
         .long _GLOBAL_OFFSET_TABLE_-$
         mflr 9
         add 9,9,0
         lwz 9,gomp_tls_data@got@tprel(9)
         add 9,9,gomp_tls_data@tls
         lwz 0,28(9)

After mflr, the lwz is missing. r0 has the offset from last lr which is wrong 
here.
The RTL in tc.c.185r.cprop_hardreg has the lwz included, the next pass  
tc.c.186r.dce does not anymore.

lwz gets not killed if I used -mcpu=power or -mcpu=e300c3. I used -mcpu=8540 which is default for powerpc-linux-gnuspe. -O1 was used in the test case.
The complete cmd line:

 /build/bigeasy/gcc-4.4-4.4.4/build/./gcc/xgcc   \
         -B/build/bigeasy/gcc-4.4-4.4.4/build/./gcc/ \
         -B/usr/powerpc-linux-gnuspe/bin/ \
         -B/usr/powerpc-linux-gnuspe/lib/ \
         -isystem \
         /usr/powerpc-linux-gnuspe/include \
         -isystem \
         /usr/powerpc-linux-gnuspe/sys-include \
         -Werror \
         -pthread \
         -ftls-model=initial-exec \
         -O2 \
         -pthread \
         -fPIC \
         -DPIC \
         tc.c \
         -o \
         tc.S \
         -S \
         -mcpu=8540 \
         -O1 \
         -fdump-rtl-all \
         -c \

A side note: the complete file (parallel.c from libgomp) was compiled with -O2 and the lwz was killed between parallel.c.174r.postreload and parallel.c.176r.split2.
Comment 1 Sebastian Andrzej Siewior 2010-05-17 15:44:28 UTC
Created attachment 20683 [details]
test case
Comment 2 Sebastian Andrzej Siewior 2010-05-17 15:44:50 UTC
Created attachment 20684 [details]
rtl pass 185r.cprop_hardreg
Comment 3 Sebastian Andrzej Siewior 2010-05-17 15:45:08 UTC
Created attachment 20685 [details]
rtl pass 186r.dce
Comment 4 Segher Boessenkool 2010-05-18 08:26:21 UTC
Confirmed with current 4.4 branch and mainline.

-mabi=nospe -mno=spe doesn't make the problem go away; only
changing -mcpu does.
Comment 5 Kyle Moffett 2010-05-20 04:53:18 UTC
I am not able to reproduce this with a cross-compiling GCC 4.4.3 or 4.4.4 built from Debian sources.  Configuration parameters for GCC 4.4.4 were:

-v
--with-pkgversion='Debian 4.4.4-2'
--with-bugurl='file:///usr/share/doc/gcc-4.4/README.Bugs'
--prefix=/usr
--enable-shared
--enable-multiarch
--enable-linker-build-id
--with-system-zlib
--libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix
--with-gxx-include-dir=/usr/powerpc-linux-gnuspe/include/c++/4.4.4
--program-suffix=-4.4
--enable-nls
--enable-clocale=gnu
--enable-libstdcxx-debug
--enable-objc-gc
--with-cpu=8548
--enable-e500_double
--with-long-double-128
--disable-multilib
--enable-checking=release
--program-prefix=powerpc-linux-gnuspe-
--includedir=/usr/powerpc-linux-gnuspe/include
--with-headers=/usr/powerpc-linux-gnuspe/include
--with-libs=/usr/powerpc-linux-gnuspe/lib
--build=x86_64-linux-gnu
--host=x86_64-linux-gnu
--target=powerpc-linux-gnuspe
CC=gcc
build_alias=x86_64-linux-gnu
host_alias=x86_64-linux-gnu
target_alias=powerpc-linux-gnuspe
--enable-languages=c,c++,fortran,objc,obj-c++

Versions are:
  powerpc-linux-gnuspe-gcc-4.3 (Debian 4.3.4-10 with a patch to debian/rules) 4.3.4
  powerpc-linux-gnuspe-gcc-4.4 (Debian 4.4.4-2 with a patch to debian/rules) 4.4.4

The C file was compiled as follows in both cases:
  powerpc-linux-gnuspe-gcc -Werror -pthread -ftls-model=initial-exec -O2 -pthread -fPIC -DPIC tc.c -o tc.S -S -mcpu=8540 -O1 -fdump-rtl-all -c

I'm not very familiar with the RTL passes, but if somebody can tell me what else to look for or test I'll go scrounge around to see if I can find what's hiding the problem for me.

Cheers,
Kyle Moffett
Comment 6 Segher Boessenkool 2010-05-20 12:10:13 UTC
I don't see the problem with 4.3 .

Kyle, are you sure it doesn't happen for you with 4.4?

I use

powerpc-linux-gnuspe-gcc -Wall -W -O1 -pthread -ftls-model=initial-exec -mcpu=8540 -fPIC -S t.c -fverbose-asm

paste your output of that?
Comment 7 Kyle Moffett 2010-05-20 12:17:21 UTC
Created attachment 20707 [details]
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.3.4
Comment 8 Kyle Moffett 2010-05-20 12:19:36 UTC
Created attachment 20708 [details]
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.4.4
Comment 9 Kyle Moffett 2010-05-20 12:29:43 UTC
Created attachment 20710 [details]
Assembled tc.c output from Debian-built powerpc-linux-gnuspe-gcc 4.4.2
Comment 10 Kyle Moffett 2010-05-20 12:37:06 UTC
Ok, it looks like the bug was introduced in the 4.4 branch between 4.4.2 and 4.4.4, because my old GCC 4.4.2 compiler works, but the 4.4.4 I built yesterday after I noticed this report does not.

If needed I can spend some time to track down exactly which optimization flag(s) cause the problem, but hopefully we've narrowed down the versions closely enough for it to be easy to find. :-D

Cheers,
Kyle Moffett
Comment 11 Sebastian Andrzej Siewior 2010-05-21 15:21:34 UTC
Reverting the change in PR39254 makes the issue go away.

Any ideas?
Comment 12 Alan Modra 2010-05-28 02:28:21 UTC
This problem can be seen on powerpc-linux-gcc with the options -O1 -fPIC -ftls-model=initial-exec -misel.

The error occurs between 172r.ira and 174r.postreload, not at 186r.dce as previously reported.
Comment 13 Alan Modra 2010-05-28 02:31:03 UTC
Created attachment 20765 [details]
ok at this point
Comment 14 Alan Modra 2010-05-28 02:32:05 UTC
Created attachment 20766 [details]
broken here, see insn 27
Comment 15 Alan Modra 2010-05-28 13:16:31 UTC
Created attachment 20768 [details]
gcc-4.4 patch

The underlying problem is that the load_toc_v4_PIC_1b rtl doesn't properly describe that its output depends both on the value of a symbol, _GLOBAL_OFFSET_TABLE_, and on its location.  This could be fixed by using an unspec_volatile rather than unspec.  I chose instead to add a label to the rtl.
Comment 16 Alan Modra 2010-06-03 02:47:34 UTC
Subject: Bug 44169

Author: amodra
Date: Thu Jun  3 02:47:11 2010
New Revision: 160206

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160206
Log:
	PR target/44169
	* config/rs6000/rs6000.md (load_toc_v4_PIC_1b): Add label operand.
	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Pass label
	rtx to gen_load_toc_v4_PIC_1b.  Tidy.
	(rs6000_emit_load_toc_table): Likewise.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
    trunk/gcc/config/rs6000/rs6000.md

Comment 17 Alan Modra 2010-06-03 02:57:38 UTC
Subject: Bug 44169

Author: amodra
Date: Thu Jun  3 02:57:19 2010
New Revision: 160207

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160207
Log:
	PR target/44169
	* config/rs6000/rs6000.md (load_toc_v4_PIC_1b): Add label operand.
	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Pass label
	rtx to gen_load_toc_v4_PIC_1b.  Tidy.
	(rs6000_emit_load_toc_table): Likewise.


Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-4_5-branch/gcc/config/rs6000/rs6000.md

Comment 18 Alan Modra 2010-06-03 03:09:05 UTC
Subject: Bug 44169

Author: amodra
Date: Thu Jun  3 03:08:32 2010
New Revision: 160208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160208
Log:
	PR target/44169
	* config/rs6000/rs6000.md (load_toc_v4_PIC_1b): Add label operand.
	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Pass label
	rtx to gen_load_toc_v4_PIC_1b.  Tidy.
	(rs6000_emit_load_toc_table): Likewise.


Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-4_4-branch/gcc/config/rs6000/rs6000.md

Comment 19 Alan Modra 2010-06-03 03:26:53 UTC
Fixed all active branches