Re: Using GS for TLS on x86-64 for target RDOS
I made the suggested changes, and enclose a new patch. Change log: * gcc/config/i386/i386.c: Use DEFAULT_TLS_SEG_REG to access TLS * gcc/config/i386/i386.h: Define default segment register for TLS * gcc/config/i386/rdos.h: Added TLS configuration for RDOS It's been tested with target RDOS, but not with target Linux. Uros, could you commit the patch if it is acceptable? Regards, Leif Ekblad - Original Message - From: Uros Bizjak ubiz...@gmail.com To: Leif Ekblad l...@rdos.net Cc: Michael Matz m...@suse.de; gcc-patches@gcc.gnu.org Sent: Tuesday, May 14, 2013 8:19 PM Subject: Re: Using GS for TLS on x86-64 for target RDOS On Tue, May 14, 2013 at 6:45 PM, Leif Ekblad l...@rdos.net wrote: I've made a patch along these lines (enclosed). Change log: * gcc/config/i386/i386.c: Use DEFAULT_TLS_SEG_REG to access TLS * gcc/config/i386/i386.h: Define default segment register for TLS * gcc/config/i386/rdos.h: Added TLS configuration for RDOS *** gcc-4.9-20130512/gcc/config/i386/i386.h2013-04-29 13:00:10.0 +0200 --- gcc-work/gcc/config/i386/i386.h2013-05-14 13:36:19.041020400 +0200 + /* The default TLS segment register used by target. */ + #define DEFAULT_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS Precedence is a bit tricky with ? ternary operand. Please put the expression in braces... *** gcc-4.9-20130512/gcc/config/i386/i386.c2013-05-06 16:53:03.0 +0200 --- gcc-work/gcc/config/i386/i386.c2013-05-14 13:37:14.338020400 +0200 ! || addr.seg != (DEFAULT_TLS_SEG_REG) ... and remove them there. *** gcc-4.9-20130512/gcc/config/i386/rdos.h2013-01-28 21:42:55.0 +0100 --- gcc-work/gcc/config/i386/rdos.h2013-05-14 13:36:17.940020400 +0200 + #undef TARGET_TLS_DIRECT_SEG_REFS + #define TARGET_TLS_DIRECT_SEG_REFS 1 TARGET_TLS_DIRECT_SEG_REFS_DEFAULT ! #define TARGET_OS_CPP_BUILTINS()\ ! do\ ! { \ ! builtin_define (__RDOS__); \ ! builtin_assert (system=rdos); \ ! } \ This looks like unwanted change to me. The patch is OK for mainline with above changes, if tested on x86_64-linux-gnu. Thanks, Uros. gcc.diff Description: Binary data
Re: Using GS for TLS on x86-64 for target RDOS
On Wed, May 15, 2013 at 9:00 PM, Leif Ekblad l...@rdos.net wrote: I made the suggested changes, and enclose a new patch. ... It's been tested with target RDOS, but not with target Linux. Uros, could you commit the patch if it is acceptable? I have committed attached patch with following ChangeLog: 2013-05-15 Leif Ekblad l...@rdos.net * config/i386/i386.c (ix86_decompose_address): Use DEFAULT_TLS_SEG_REG to access TLS segment register. * config/i386/i386.h (DEFAULT_TLS_SEG_REG): New define. * config/i386/rdos.h (DEFAULT_TLS_SEG_REG): Ditto. (TARGET_TLS_DIRECT_SEG_REFS_DEFAULT): Ditto. Patch was also tested on x86_64-pc-linux-gnu {,-m32}. Uros. Index: config/i386/i386.c === --- config/i386/i386.c (revision 198944) +++ config/i386/i386.c (working copy) @@ -11698,7 +11698,7 @@ ix86_decompose_address (rtx addr, struct ix86_addr if (XINT (op, 1) == UNSPEC_TP TARGET_TLS_DIRECT_SEG_REFS seg == SEG_DEFAULT) - seg = TARGET_64BIT ? SEG_FS : SEG_GS; + seg = DEFAULT_TLS_SEG_REG; else return 0; break; @@ -13650,7 +13650,7 @@ ix86_delegitimize_tls_address (rtx orig_x) if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode) return orig_x; if (ix86_decompose_address (x, addr) == 0 - || addr.seg != (TARGET_64BIT ? SEG_FS : SEG_GS) + || addr.seg != DEFAULT_TLS_SEG_REG || addr.disp == NULL_RTX || GET_CODE (addr.disp) != CONST) return orig_x; Index: config/i386/i386.h === --- config/i386/i386.h (revision 198944) +++ config/i386/i386.h (working copy) @@ -543,6 +543,9 @@ extern tree x86_mfence; /* The default abi used by target. */ #define DEFAULT_ABI SYSV_ABI +/* The default TLS segment register used by target. */ +#define DEFAULT_TLS_SEG_REG (TARGET_64BIT ? SEG_FS : SEG_GS) + /* Subtargets may reset this to 1 in order to enable 96-bit long double with the rounding mode forced to 53 bits. */ #define TARGET_96_ROUND_53_LONG_DOUBLE 0 Index: config/i386/rdos.h === --- config/i386/rdos.h (revision 198944) +++ config/i386/rdos.h (working copy) @@ -21,6 +21,12 @@ along with GCC; see the file COPYING3. If not see #undef TARGET_EXECUTABLE_SUFFIX #define TARGET_EXECUTABLE_SUFFIX .exe +#undef TARGET_TLS_DIRECT_SEG_REFS_DEFAULT +#define TARGET_TLS_DIRECT_SEG_REFS_DEFAULT MASK_TLS_DIRECT_SEG_REFS + +#undef DEFAULT_TLS_SEG_REG +#define DEFAULT_TLS_SEG_REG SEG_GS + #undef TARGET_RDOS #define TARGET_RDOS 1
Re: Using GS for TLS on x86-64 for target RDOS
Hello! I would need a way to use GS segment register instead of FS for x86-64 for target RDOS since RDOS cannot use FS for TLS. It seems like the code related to this is concentrated to two different places: Especially the second reference would become hard-to-read if more conditionals are added to it. Perhaps the code could be changed to something like this: #ifdef TARGET_RDOS #define GET_TLS_SEG_REG SEG_GS #else #define GET_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS #endif Thoughts? I'd propose to introduce: a) #define DEFAULT_TLS_SEG_REG in i386.h to SEG_GS b) #undef and #define DEFAULT_TLS_SEG_REG in x86-64.h to SEG_FS c) #undef and #define DEFAULT_TLS_SEG_REG in rdos.h to SEG_GS Then use DEFAULT_TLS_SEG_REG everywhere. This will avoid compile-time and runtime checks. Please note that sequence of include files gets defined in config.gcc. Uros.
Re: Using GS for TLS on x86-64 for target RDOS
Hi, On Tue, 14 May 2013, Uros Bizjak wrote: I'd propose to introduce: a) #define DEFAULT_TLS_SEG_REG in i386.h to SEG_GS b) #undef and #define DEFAULT_TLS_SEG_REG in x86-64.h to SEG_FS This would break -m32. c) #undef and #define DEFAULT_TLS_SEG_REG in rdos.h to SEG_GS Then use DEFAULT_TLS_SEG_REG everywhere. This will avoid compile-time and runtime checks. ... which you can't avoid in a multilib compiler. Ciao, Michael.
Re: Using GS for TLS on x86-64 for target RDOS
On Tue, May 14, 2013 at 11:13 AM, Michael Matz m...@suse.de wrote: On Tue, 14 May 2013, Uros Bizjak wrote: I'd propose to introduce: a) #define DEFAULT_TLS_SEG_REG in i386.h to SEG_GS b) #undef and #define DEFAULT_TLS_SEG_REG in x86-64.h to SEG_FS This would break -m32. Uh, yes. So instead of a) and b), there should be: #define DEFAULT_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS in i386.h. Uros.
Re: Using GS for TLS on x86-64 for target RDOS
I've made a patch along these lines (enclosed). Change log: * gcc/config/i386/i386.c: Use DEFAULT_TLS_SEG_REG to access TLS * gcc/config/i386/i386.h: Define default segment register for TLS * gcc/config/i386/rdos.h: Added TLS configuration for RDOS Regards, Leif Ekblad - Original Message - From: Uros Bizjak ubiz...@gmail.com To: Michael Matz m...@suse.de Cc: gcc-patches@gcc.gnu.org; Leif Ekblad l...@rdos.net Sent: Tuesday, May 14, 2013 11:35 AM Subject: Re: Using GS for TLS on x86-64 for target RDOS On Tue, May 14, 2013 at 11:13 AM, Michael Matz m...@suse.de wrote: On Tue, 14 May 2013, Uros Bizjak wrote: I'd propose to introduce: a) #define DEFAULT_TLS_SEG_REG in i386.h to SEG_GS b) #undef and #define DEFAULT_TLS_SEG_REG in x86-64.h to SEG_FS This would break -m32. Uh, yes. So instead of a) and b), there should be: #define DEFAULT_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS in i386.h. Uros. gcc-tls.diff Description: Binary data
Re: Using GS for TLS on x86-64 for target RDOS
On Tue, May 14, 2013 at 6:45 PM, Leif Ekblad l...@rdos.net wrote: I've made a patch along these lines (enclosed). Change log: * gcc/config/i386/i386.c: Use DEFAULT_TLS_SEG_REG to access TLS * gcc/config/i386/i386.h: Define default segment register for TLS * gcc/config/i386/rdos.h: Added TLS configuration for RDOS *** gcc-4.9-20130512/gcc/config/i386/i386.h2013-04-29 13:00:10.0 +0200 --- gcc-work/gcc/config/i386/i386.h2013-05-14 13:36:19.041020400 +0200 + /* The default TLS segment register used by target. */ + #define DEFAULT_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS Precedence is a bit tricky with ? ternary operand. Please put the expression in braces... *** gcc-4.9-20130512/gcc/config/i386/i386.c2013-05-06 16:53:03.0 +0200 --- gcc-work/gcc/config/i386/i386.c2013-05-14 13:37:14.338020400 +0200 ! || addr.seg != (DEFAULT_TLS_SEG_REG) ... and remove them there. *** gcc-4.9-20130512/gcc/config/i386/rdos.h2013-01-28 21:42:55.0 +0100 --- gcc-work/gcc/config/i386/rdos.h2013-05-14 13:36:17.940020400 +0200 + #undef TARGET_TLS_DIRECT_SEG_REFS + #define TARGET_TLS_DIRECT_SEG_REFS 1 TARGET_TLS_DIRECT_SEG_REFS_DEFAULT ! #define TARGET_OS_CPP_BUILTINS()\ ! do\ ! { \ ! builtin_define (__RDOS__); \ ! builtin_assert (system=rdos); \ ! } \ This looks like unwanted change to me. The patch is OK for mainline with above changes, if tested on x86_64-linux-gnu. Thanks, Uros.
Using GS for TLS on x86-64 for target RDOS
I would need a way to use GS segment register instead of FS for x86-64 for target RDOS since RDOS cannot use FS for TLS. It seems like the code related to this is concentrated to two different places: The gcc/config/i386/i386.c: 11677:seg = TARGET_64BIT ? SEG_FS : SEG_GS; 13526: if (ix86_decompose_address (x, addr) == 0 || addr.seg != (TARGET_64BIT ? SEG_FS : SEG_GS) || addr.disp == NULL_RTX || GET_CODE (addr.disp) != CONST) Especially the second reference would become hard-to-read if more conditionals are added to it. Perhaps the code could be changed to something like this: #ifdef TARGET_RDOS #define GET_TLS_SEG_REG SEG_GS #else #define GET_TLS_SEG_REG TARGET_64BIT ? SEG_FS : SEG_GS #endif Then the above could be patched to: 11677:seg = GET_TLS_SEG_REG; 13526: if (ix86_decompose_address (x, addr) == 0 || addr.seg != (GET_TLS_SEG_REG) || addr.disp == NULL_RTX || GET_CODE (addr.disp) != CONST) Thoughts? Regards, Leif Ekblad