Bug 93319 - -mtls-dialect=gnu2 doesn't work for x32
Summary: -mtls-dialect=gnu2 doesn't work for x32
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.0
Assignee: H.J. Lu
URL: https://gcc.gnu.org/ml/gcc-patches/20...
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-18 19:44 UTC by H.J. Lu
Modified: 2020-01-21 22:39 UTC (History)
1 user (show)

See Also:
Host:
Target: x86-64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-18 00:00:00


Attachments
A patch (2.24 KB, patch)
2020-01-18 20:08 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2020-01-18 19:44:51 UTC
[hjl@gnu-cfl-2 tls-x32-ld]$ cat lib.c
#include <stdio.h>

static __thread int foo = 30;

int *
test (void)
{
  printf ("foo: %d\n", foo);
  return &foo;
}
[hjl@gnu-cfl-2 tls-x32-ld]$ make lib.o
gcc -mx32 -B./ -O2 -g -mtls-dialect=gnu2 -fPIC   -c -o lib.o lib.c
lib.c: In function ‘test’:
lib.c:10:1: error: unrecognizable insn:
   10 | }
      | ^
(insn 6 5 7 2 (set (reg:SI 85)
        (unspec:DI [
                (symbol_ref:SI ("_TLS_MODULE_BASE_") [flags 0x10])
            ] UNSPEC_TLSDESC)) "lib.c":8:3 -1
     (nil))
during RTL pass: vregs
lib.c:10:1: internal compiler error: in extract_insn, at recog.c:2310
Comment 1 H.J. Lu 2020-01-18 20:08:24 UTC
Created attachment 47674 [details]
A patch
Comment 2 H.J. Lu 2020-01-19 14:00:22 UTC
A patch is posted at

https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01123.html
Comment 3 GCC Commits 2020-01-20 13:15:26 UTC
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:1a2b60b581c373e4ebcee9ee37c0ab2866f98950

commit r10-6090-g1a2b60b581c373e4ebcee9ee37c0ab2866f98950
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Jan 20 05:02:14 2020 -0800

    x32: Add x32 support to -mtls-dialect=gnu2
    
    To add x32 support to -mtls-dialect=gnu2, we need to replace DI with
    P in GNU2 TLS patterns.  Since DEST set by tls_dynamic_gnu2_64 is in
    ptr_mode, PLUS in GNU2 TLS address computation must be done in ptr_mode
    to support -maddress-mode=long.  Also replace the "{q}" suffix on lea
    with "%z0" to support both 32-bit and 64-bit destination register.
    
    Tested on Linux/x86-64.
    
    gcc/
    
    	PR target/93319
    	* config/i386/i386.c (legitimize_tls_address): Pass Pmode to
    	gen_tls_dynamic_gnu2_64.  Compute GNU2 TLS address in ptr_mode.
    	* config/i386/i386.md (tls_dynamic_gnu2_64): Renamed to ...
    	(@tls_dynamic_gnu2_64_<mode>): This.  Replace DI with P.
    	(*tls_dynamic_gnu2_lea_64): Renamed to ...
    	(*tls_dynamic_gnu2_lea_64_<mode>): This.  Replace DI with P.
    	Remove the {q} suffix from lea.
    	(*tls_dynamic_gnu2_call_64): Renamed to ...
    	(*tls_dynamic_gnu2_call_64_<mode>): This.  Replace DI with P.
    	(*tls_dynamic_gnu2_combine_64): Renamed to ...
    	(*tls_dynamic_gnu2_combine_64_<mode>): This.  Replace DI with P.
    	Pass Pmode to gen_tls_dynamic_gnu2_64.
    
    gcc/testsuite/
    
    	PR target/93319
    	* gcc.target/i386/pr93319-1a.c: New test.
    	* gcc.target/i386/pr93319-1b.c: Likewise.
    	* gcc.target/i386/pr93319-1c.c: Likewise.
    	* gcc.target/i386/pr93319-1d.c: Likewise.
Comment 4 GCC Commits 2020-01-21 22:10:58 UTC
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:8e0efc10335bf9bb447f2188254609dcfad7de8a

commit r10-6122-g8e0efc10335bf9bb447f2188254609dcfad7de8a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jan 21 14:09:53 2020 -0800

    i386: Do GNU2 TLS address computation in ptr_mode
    
    Since GNU2 TLS address from glibc run-time is in ptr_mode, we should do
    GNU2 TLS address computation in ptr_mode and zero-extend result to Pmode.
    
    gcc/
    
    	PR target/93319
    	* config/i386/i386.c (ix86_tls_module_base): Replace Pmode
    	with ptr_mode.
    	(legitimize_tls_address): Do GNU2 TLS address computation in
    	ptr_mode and zero-extend result to Pmode.
    	*  config/i386/i386.md (@tls_dynamic_gnu2_64_<mode>): Replace
    	:P with :PTR and Pmode with ptr_mode.
    	(*tls_dynamic_gnu2_lea_64_<mode>): Likewise.
    	(*tls_dynamic_gnu2_call_64_<mode>): Likewise.
    	(*tls_dynamic_gnu2_combine_64_<mode>): Likewise.
    
    gcc/testsuite/
    
    	PR target/93319
    	* gcc.target/i386/pr93319-1a.c: Don't include <stdio.h>.
    	(test1): Replace printf with __builtin_printf.
Comment 5 H.J. Lu 2020-01-21 22:39:04 UTC
Fixed for GCC 10.