From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11780 Path: news.gmane.org!.POSTED!not-for-mail From: Bobby Bingham Newsgroups: gmane.linux.lib.musl.general Subject: Re: possible bug in setjmp implementation for ppc64 Date: Tue, 1 Aug 2017 23:31:55 -0500 Message-ID: <20170802043155.GA5455@dora.lan> References: <1501520360.0.593167188853569@go.bunnymail.go> <20170731203007.GB1627@brightrain.aerifal.cx> <20170801051042.GA14914@dora.lan> <20170801224533.GD1627@brightrain.aerifal.cx> <20170801230759.GF1627@brightrain.aerifal.cx> <20170802002845.GA21256@dora.lan> <20170802035556.GG1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: blaine.gmane.org 1501648332 32523 195.159.176.226 (2 Aug 2017 04:32:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 2 Aug 2017 04:32:12 +0000 (UTC) User-Agent: Mutt/1.8.3 (2017-05-23) To: musl@lists.openwall.com Original-X-From: musl-return-11793-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 02 06:32:09 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dclKH-00084e-GE for gllmg-musl@m.gmane.org; Wed, 02 Aug 2017 06:32:05 +0200 Original-Received: (qmail 30556 invoked by uid 550); 2 Aug 2017 04:32:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30532 invoked from network); 2 Aug 2017 04:32:09 -0000 Content-Disposition: inline In-Reply-To: <20170802035556.GG1627@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:11780 Archived-At: On Tue, Aug 01, 2017 at 11:55:56PM -0400, Rich Felker wrote: > On Tue, Aug 01, 2017 at 07:28:45PM -0500, Bobby Bingham wrote: > > On Tue, Aug 01, 2017 at 07:07:59PM -0400, Rich Felker wrote: > > > On Tue, Aug 01, 2017 at 06:45:33PM -0400, Rich Felker wrote: > > > > On Tue, Aug 01, 2017 at 08:28:27AM +0300, Alexander Monakov wrote: > > > > > On Tue, 1 Aug 2017, Bobby Bingham wrote: > > > > > > I think this either requires having different versions of setjmp/longjmp > > > > > > for static and dynamic libc, > > > > > > > > > > Do you mean for non-pic vs pic objects? As I understand, when libc.a is > > > > > built with -fpic (so it's suitable for static-pie), setjmp-longjmp need > > > > > to preserve saved TOC at (r1+24). So presumably source code would need > > > > > to test #ifdef __PIC__? > > > > > > > > > > > or to increase the size of jmpbuf so we can always save/restore both > > > > > > r2 and the value on the stack, but this would be an ABI change. > > > > > > > > > > Would that work for non-pic, i.e. is (r1+24) a reserved location even in > > > > > non-pic mode? If not, you can't overwrite it from longjmp. > > > > > > > > Pretty much certainly so; there is no separate "non-PIC ABI". PIC code > > > > is just code that doesn't happen to do certain things not permissible > > > > in PIC. It doesn't have additional permissions to do things that > > > > otherwise wouldn't be permitted in "non-PIC code". > > > > > > > > In any case just saving and restoring both is not an ABI change, since > > > > there's plenty of free space (896 bits worth of non-existant signals) > > > > in the jmp_buf due to the "Hurd sigset_t" mess. > > > > > > It might also be possible to manually create both the entry points for > > > setjmp, rather than letting the assembler auto-generate them, in which > > > case I think the choice of which value to save just depends on which > > > entry point was used. Thoughts? > > > > I like this idea. It's slightly more complicated than that because of > > the call to setjmp from sigsetjmp, but should still be ok. I'll work on > > a patch. > > Hmm, can you elaborate on the situation with sigsetjmp? > sigsetjmp calls setjmp, but I believe this will always use the intra-dso entry point. Same for the call siglongjmp makes to longjmp. So calls via sigsetjmp/siglongjmp will always be detected as local calls, even when the originally caller of jig*jmp is in a different dso. My plan right now is create a __setjmp_toc function which is identical to the normal setjmp except that the TOC pointer to save is passed in as another parameter. setjmp will detect which entry point is used, pull the TOC pointer from the right place, and call __setjmp_toc. sigsetjmp will be updated similarly to detect which entry point is used and to call __setjmp_toc directly instead of going through setjmp. siglongjmp is current written in C by just calling longjmp. I'm tempted to just add a "siglongjmp:" label in the asm for longjmp and add an empty powerpc64/siglongjmp.c file to suppress the default implementation. I want to ask if there's any reason it wouldn't be valid for these two functions to have the same address. > Rich