public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 1/8] nptl: Perform signal initialization upon pthread_create
Date: Fri, 21 May 2021 17:23:42 -0300	[thread overview]
Message-ID: <86d371c0-f995-c5d5-934d-0feab3332831@linaro.org> (raw)
In-Reply-To: <87fsyf6dyl.fsf@oldenburg.str.redhat.com>



On 21/05/2021 17:15, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>>> @@ -106,4 +172,8 @@ versioned_symbol (libc, __pthread_cancel, pthread_cancel, GLIBC_2_34);
>>>  compat_symbol (libpthread, __pthread_cancel, pthread_cancel, GLIBC_2_0);
>>>  #endif
>>>  
>>> -PTHREAD_STATIC_FN_REQUIRE (__pthread_create)
>>> +/* Ensure that the unwinder is always linked in (the __pthread_unwind
>>> +   reference from __do_cancel is weak).  Use ___pthread_unwind_next
>>> +   (three underscores) to produce a strong reference to the same
>>> +   file.  */
>>> +PTHREAD_STATIC_FN_REQUIRE (___pthread_unwind_next)
>>
>> Why __pthread_unwind is marked as weak now? Would be simpler to unmark
>> is as weak and avoid the PTHREAD_STATIC_FN_REQUIRE?
> 
> It's related to the compiled-in cancellation points.  The references to
> __pthread_enable_asynccancel are strong, and that disassembles to:
> 
> 0000000000000000 <__pthread_enable_asynccancel>:
>    0:	mov    %fs:0x10,%rcx
>    9:	mov    %fs:0x308,%r8d
>   12:	mov    %r8d,%edx
>   15:	or     $0x2,%edx
>   18:	cmp    %edx,%r8d
>   1b:	je     35 <__pthread_enable_asynccancel+0x35>
>   1d:	mov    %r8d,%eax
>   20:	lock cmpxchg %edx,0x308(%rcx)
>   28:	cmp    %eax,%r8d
>   2b:	jne    40 <__pthread_enable_asynccancel+0x40>
>   2d:	and    $0xffffffbb,%edx
>   30:	cmp    $0xa,%edx
>   33:	je     45 <__pthread_enable_asynccancel+0x45>
>   35:	mov    %r8d,%eax
>   38:	retq   
>   39:	nopl   0x0(%rax)
>   40:	mov    %eax,%r8d
>   43:	jmp    12 <__pthread_enable_asynccancel+0x12>
>   45:	push   %rax
>   46:	movq   $0xffffffffffffffff,%fs:0x630
>   53:	mov    %fs:0x10,%rax
>   5c:	lock orl $0x10,0x308(%rax)
>   64:	mov    %fs:0x300,%rdi
>   6d:	callq  72 <__pthread_enable_asynccancel+0x72>
> 			6e: R_X86_64_PLT32	__pthread_unwind-0x4
>   72:	data16 nopw %cs:0x0(%rax,%rax,1)
>   7d:	nopl   (%rax)
> 
> And the unwind reference is weak:
> 
>    17: 0000000000000000      0 NOTYPE  WEAK   HIDDEN     UNDEF __pthread_unwind
> 
> There's no address check because the cancellation state in the TCB can
> only change if pthread_cancel is linked in, and that really should pull
> in the unwinder, too.  That's why I added the PTHREAD_STATIC_FN_REQUIRE.
> Without it, I think some of the existing tests will fail (the
> pthread_create PTHREAD_STATIC_FN_REQUIREs are apparently not quite
> correct).
> 
> I think it's always been this way, so that the unwinder is optional in
> static links (in theory, in practice it is still pulled in by the bits
> that are compiled with -fexceptions due to the _Unwind_Resume construct,
> hence the need for elf/static-stubs.c).

Right, it does seem unnecessary to pull the unwinder for SYSCALL_CANCEL.

  reply	other threads:[~2021-05-21 20:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21 12:45 [PATCH v2 0/8] nptl: Complete libpthread move Florian Weimer
2021-05-21 12:45 ` [PATCH 1/8] nptl: Perform signal initialization upon pthread_create Florian Weimer
2021-05-21 20:03   ` Adhemerval Zanella
2021-05-21 20:15     ` Florian Weimer
2021-05-21 20:23       ` Adhemerval Zanella [this message]
2021-05-21 12:45 ` [PATCH 2/8] nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables Florian Weimer
2021-05-21 12:45 ` [PATCH 3/8] nptl: Move semi-public __pthread_get_minstack symbol into libc Florian Weimer
2021-05-21 12:45 ` [PATCH v2 4/8] elf: Use custom NODELETE DSO for tst-dlopenfail, tst-dlopenfail-2 Florian Weimer
2021-05-21 20:11   ` Adhemerval Zanella
2021-05-21 12:45 ` [PATCH 5/8] nptl: Move pthread_create, thrd_create into libc Florian Weimer
2021-05-21 12:46 ` [PATCH 6/8] nptl: Remove remaining code from libpthread Florian Weimer
2021-05-21 12:46 ` [PATCH 7/8] nptl: Do not install libpthread.so and do not link tests with it Florian Weimer
2021-05-24 17:14   ` Adhemerval Zanella
2021-05-21 12:46 ` [PATCH 8/8] Linux: Remove remaining references to $(shared-thread-library) Florian Weimer
2021-05-24 18:27   ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86d371c0-f995-c5d5-934d-0feab3332831@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).