From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11783 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: Wed, 2 Aug 2017 08:38:25 -0500 Message-ID: <20170802133825.GB5455@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> <20170802043155.GA5455@dora.lan> <20170802045816.GH1627@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 1501681127 2659 195.159.176.226 (2 Aug 2017 13:38:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 2 Aug 2017 13:38:47 +0000 (UTC) User-Agent: Mutt/1.8.3 (2017-05-23) To: musl@lists.openwall.com Original-X-From: musl-return-11796-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 02 15:38:42 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 1dctrA-0000HJ-HJ for gllmg-musl@m.gmane.org; Wed, 02 Aug 2017 15:38:36 +0200 Original-Received: (qmail 20074 invoked by uid 550); 2 Aug 2017 13:38:39 -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 20056 invoked from network); 2 Aug 2017 13:38:39 -0000 Content-Disposition: inline In-Reply-To: <20170802045816.GH1627@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:11783 Archived-At: On Wed, Aug 02, 2017 at 12:58:16AM -0400, Rich Felker wrote: > > 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. > > I've been thinking about it and at first thought it sounded overly > fragile and hard to understand, but now I think it makes sense and > should work. It would just involve copying r2 to a call-clobbered > argument register before loading the new value, right? I'm not sure what "new value" you're referring to here. The idea is basically: setjmp: # non-local entry point r5 = r1[24] goto __setjmp_toc .localentry # local entry point r5 = r2 __setjmp_toc: # all the existing code from setjmp, but save r5 instead of r2 > > I was considering whether you could just avoid loading the TOC pointer > at all (leaving the correct value in r2 for setjmp to save), and this > might work, but I think it would make calling __sigsetjmp_tail > difficult and error-prone. > > > 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. > > I don't see any reason to make this change (it won't make any > functional difference -- call frames and such don't matter at this > point), and at least the siglongjmp symbol would have to be weak to > respect namespace if you did it that way. I'm not sure why a change like this wouldn't be required. The requirements on longjmp here are: * when called through the local entry point, restore the TOC pointer into r2 * when called via the PLT stub, restore the TOC pointer to the stack And siglongjmp needs to have the same behavior. If the main program makes a cross-dso call to siglongjmp, it needs to restore the TOC pointer to the stack. But siglongjmp works by making a local call to longjmp, meaning without this change, it will only ever restore the TOC pointer to r2. > > Rich