i386: Change offset of __private_ss to 0x30

Message ID CAMe9rOqv-3HbE=3k34-iyjwTc9S5nQvvMbFkVxXXzgaB7p3WQA@mail.gmail.com
State New, archived
Headers

Commit Message

H.J. Lu May 30, 2018, 2:49 p.m. UTC
  On Wed, May 30, 2018 at 5:13 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> TARGET_THREAD_SPLIT_STACK_OFFSET has been wrong for Linux/i386 from
> the start.  Should we change glibc for GCC's mistake or fix GCC?
>

We have to update tcbhead_t to match GCC to avoid libgcc ABI
change.

OK for master?
  

Comments

Florian Weimer May 30, 2018, 4:43 p.m. UTC | #1
On 05/30/2018 04:49 PM, H.J. Lu wrote:
> diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
> index 6c36e58e9c..afb71ce431 100644
> --- a/sysdeps/i386/nptl/tls.h
> +++ b/sysdeps/i386/nptl/tls.h
> @@ -43,11 +43,16 @@ typedef struct
>     int gscope_flag;
>     int __glibc_reserved1;
>     /* Reservation of some values for the TM ABI.  */
> -  void *__private_tm[4];
> +  void *__private_tm[3];
>     /* GCC split stack support.  */
>     void *__private_ss;
> +  void *__glibc_reserved2;
>   } tcbhead_t;

What's the state of TM in GCC?  Has it already been removed?

Thanks,
Florian
  
H.J. Lu May 30, 2018, 4:47 p.m. UTC | #2
On Wed, May 30, 2018 at 9:43 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 05/30/2018 04:49 PM, H.J. Lu wrote:
>>
>> diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
>> index 6c36e58e9c..afb71ce431 100644
>> --- a/sysdeps/i386/nptl/tls.h
>> +++ b/sysdeps/i386/nptl/tls.h
>> @@ -43,11 +43,16 @@ typedef struct
>>     int gscope_flag;
>>     int __glibc_reserved1;
>>     /* Reservation of some values for the TM ABI.  */
>> -  void *__private_tm[4];
>> +  void *__private_tm[3];
>>     /* GCC split stack support.  */
>>     void *__private_ss;
>> +  void *__glibc_reserved2;
>>   } tcbhead_t;
>
>
> What's the state of TM in GCC?  Has it already been removed?

libitm has its own issue:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85988

Fortunately, only the first 2 elements in __private_tm are used by
libitm.
  
Florian Weimer June 4, 2018, 1:30 p.m. UTC | #3
On 05/30/2018 06:47 PM, H.J. Lu wrote:
> On Wed, May 30, 2018 at 9:43 AM, Florian Weimer <fweimer@redhat.com> wrote:
>> On 05/30/2018 04:49 PM, H.J. Lu wrote:
>>>
>>> diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
>>> index 6c36e58e9c..afb71ce431 100644
>>> --- a/sysdeps/i386/nptl/tls.h
>>> +++ b/sysdeps/i386/nptl/tls.h
>>> @@ -43,11 +43,16 @@ typedef struct
>>>      int gscope_flag;
>>>      int __glibc_reserved1;
>>>      /* Reservation of some values for the TM ABI.  */
>>> -  void *__private_tm[4];
>>> +  void *__private_tm[3];
>>>      /* GCC split stack support.  */
>>>      void *__private_ss;
>>> +  void *__glibc_reserved2;
>>>    } tcbhead_t;
>>
>>
>> What's the state of TM in GCC?  Has it already been removed?
> 
> libitm has its own issue:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85988
> 
> Fortunately, only the first 2 elements in __private_tm are used by
> libitm.

Looks like the reuse of the TM fields was actually deliberate:

   <https://sourceware.org/bugzilla/show_bug.cgi?id=10686>

But the offsets are still wrong.

The question still remains whether we still need libitm.

Thanks,
Florian
  
H.J. Lu June 4, 2018, 1:43 p.m. UTC | #4
On Mon, Jun 4, 2018 at 6:30 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 05/30/2018 06:47 PM, H.J. Lu wrote:
>>
>> On Wed, May 30, 2018 at 9:43 AM, Florian Weimer <fweimer@redhat.com>
>> wrote:
>>>
>>> On 05/30/2018 04:49 PM, H.J. Lu wrote:
>>>>
>>>>
>>>> diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
>>>> index 6c36e58e9c..afb71ce431 100644
>>>> --- a/sysdeps/i386/nptl/tls.h
>>>> +++ b/sysdeps/i386/nptl/tls.h
>>>> @@ -43,11 +43,16 @@ typedef struct
>>>>      int gscope_flag;
>>>>      int __glibc_reserved1;
>>>>      /* Reservation of some values for the TM ABI.  */
>>>> -  void *__private_tm[4];
>>>> +  void *__private_tm[3];
>>>>      /* GCC split stack support.  */
>>>>      void *__private_ss;
>>>> +  void *__glibc_reserved2;
>>>>    } tcbhead_t;
>>>
>>>
>>>
>>> What's the state of TM in GCC?  Has it already been removed?
>>
>>
>> libitm has its own issue:
>>
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85988
>>
>> Fortunately, only the first 2 elements in __private_tm are used by
>> libitm.
>
>
> Looks like the reuse of the TM fields was actually deliberate:

True.

>   <https://sourceware.org/bugzilla/show_bug.cgi?id=10686>
>
> But the offsets are still wrong.

Yes, we are stuck with the wrong offset.

> The question still remains whether we still need libitm.
>

libitm is enabled by default in GCC.
  
H.J. Lu June 12, 2018, 11:53 a.m. UTC | #5
On Mon, Jun 4, 2018 at 6:43 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Jun 4, 2018 at 6:30 AM, Florian Weimer <fweimer@redhat.com> wrote:
>> On 05/30/2018 06:47 PM, H.J. Lu wrote:
>>>
>>> On Wed, May 30, 2018 at 9:43 AM, Florian Weimer <fweimer@redhat.com>
>>> wrote:
>>>>
>>>> On 05/30/2018 04:49 PM, H.J. Lu wrote:
>>>>>
>>>>>
>>>>> diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
>>>>> index 6c36e58e9c..afb71ce431 100644
>>>>> --- a/sysdeps/i386/nptl/tls.h
>>>>> +++ b/sysdeps/i386/nptl/tls.h
>>>>> @@ -43,11 +43,16 @@ typedef struct
>>>>>      int gscope_flag;
>>>>>      int __glibc_reserved1;
>>>>>      /* Reservation of some values for the TM ABI.  */
>>>>> -  void *__private_tm[4];
>>>>> +  void *__private_tm[3];
>>>>>      /* GCC split stack support.  */
>>>>>      void *__private_ss;
>>>>> +  void *__glibc_reserved2;
>>>>>    } tcbhead_t;
>>>>
>>>>
>>>>
>>>> What's the state of TM in GCC?  Has it already been removed?
>>>
>>>
>>> libitm has its own issue:
>>>
>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85988
>>>
>>> Fortunately, only the first 2 elements in __private_tm are used by
>>> libitm.
>>
>>
>> Looks like the reuse of the TM fields was actually deliberate:
>
> True.
>
>>   <https://sourceware.org/bugzilla/show_bug.cgi?id=10686>
>>
>> But the offsets are still wrong.
>
> Yes, we are stuck with the wrong offset.
>
>> The question still remains whether we still need libitm.
>>
>
> libitm is enabled by default in GCC.
>

I am checking in my patch:

https://sourceware.org/ml/libc-alpha/2018-05/msg00883.html

today to match what libgcc uses.
  

Patch

From 5dc6c46daaabb501f345be2c10dfb952c1d5b5bf Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 30 May 2018 07:41:55 -0700
Subject: [PATCH] i386: Change offset of __private_ss to 0x30

sysdeps/i386/nptl/tls.h has

typedef struct
{
  void *tcb;            /* Pointer to the TCB.  Not necessarily the
                           thread descriptor used by libpthread.  */
  dtv_t *dtv;
  void *self;           /* Pointer to the thread descriptor.  */
  int multiple_threads;
  uintptr_t sysinfo;
  uintptr_t stack_guard;
  uintptr_t pointer_guard;
  int gscope_flag;
  int __glibc_reserved1;
  /* Reservation of some values for the TM ABI.  */
  void *__private_tm[4];
  /* GCC split stack support.  */
  void *__private_ss;
} tcbhead_t;

The offset of __private_ss is 0x34.  But GCC defines

/* We steal the last transactional memory word.  */
 #define TARGET_THREAD_SPLIT_STACK_OFFSET 0x30

and libgcc/config/i386/morestack.S has

	cmpl	%gs:0x30,%eax		# See if we have enough space.
	movl	%eax,%gs:0x30		# Save the new stack boundary.
	movl	%eax,%gs:0x30		# Save the new stack boundary.
	movl	%ecx,%gs:0x30		# Save new stack boundary.
	movl	%eax,%gs:0x30
	movl	%gs:0x30,%eax
	movl	%eax,%gs:0x30

Since update TARGET_THREAD_SPLIT_STACK_OFFSET changes split stack ABI,
this patch updates tcbhead_t to match GCC.

	[BZ #23250]
	* sysdeps/i386/nptl/tls.h (tcbhead_t): Change __private_tm[4]
	to _private_tm[3] and add __glibc_reserved2.
	Add _Static_assert of offset of __private_ss == 0x30.
	* sysdeps/x86_64/nptl/tls.h: Add Add _Static_assert of offset of
	__private_ss == 0x40 for ILP32 and == 0x70 for LP64.
---
 sysdeps/i386/nptl/tls.h   |  7 ++++++-
 sysdeps/x86_64/nptl/tls.h | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index 6c36e58e9c..afb71ce431 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -43,11 +43,16 @@  typedef struct
   int gscope_flag;
   int __glibc_reserved1;
   /* Reservation of some values for the TM ABI.  */
-  void *__private_tm[4];
+  void *__private_tm[3];
   /* GCC split stack support.  */
   void *__private_ss;
+  void *__glibc_reserved2;
 } tcbhead_t;
 
+/* morestack.S in libgcc uses offset 0x30 to access __private_ss,   */
+_Static_assert (offsetof (tcbhead_t, __private_ss) == 0x30,
+		"offset of __private_ss != 0x30");
+
 # define TLS_MULTIPLE_THREADS_IN_TCB 1
 
 #else /* __ASSEMBLER__ */
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index 6da1c04a98..65c0051dcf 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -65,6 +65,16 @@  typedef struct
   void *__padding[8];
 } tcbhead_t;
 
+# ifdef __ILP32__
+/* morestack.S in libgcc uses offset 0x40 to access __private_ss,   */
+_Static_assert (offsetof (tcbhead_t, __private_ss) == 0x40,
+		"offset of __private_ss != 0x40");
+# else
+/* morestack.S in libgcc uses offset 0x70 to access __private_ss,   */
+_Static_assert (offsetof (tcbhead_t, __private_ss) == 0x70,
+		"offset of __private_ss != 0x70");
+# endif
+
 #else /* __ASSEMBLER__ */
 # include <tcb-offsets.h>
 #endif
-- 
2.17.0