From owner-freebsd-current@freebsd.org Sun Oct 22 00:19:50 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 953E5E3E7B3 for ; Sun, 22 Oct 2017 00:19:50 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: from mailrelay105.isp.belgacom.be (mailrelay105.isp.belgacom.be [195.238.20.132]) (using TLSv1.2 with cipher RC4-SHA (128/128 bits)) (Client CN "relay.skynet.be", Issuer "GlobalSign Organization Validation CA - SHA256 - G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B199970B6D; Sun, 22 Oct 2017 00:19:49 +0000 (UTC) (envelope-from tijl@freebsd.org) X-Belgacom-Dynamic: yes IronPort-PHdr: =?us-ascii?q?9a23=3APg86CBPcGQ9oCXtdOUkl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0LfX9rarrMEGX3/hxlliBBdydsKMUzbKO+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1?= =?us-ascii?q?Ov71GonPhMiryuy+4ZPebgFLiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPde?= =?us-ascii?q?RWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbY?= =?us-ascii?q?UwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0vRz+s87lkRwPpiC?= =?us-ascii?q?cfNj427mfXitBrjKlGpB6tvgFzz5LIbI2QMvd1Y6HTcs4ARWdZUMhfVzJPDJ6/?= =?us-ascii?q?YYQNAeoOMvpXoYbmqlsSrxayGRWgCP/zxjNWgHL9wK000/4mEQHDxAEuAdMOsH?= =?us-ascii?q?bQrN7oKqoSVue1zLLWwjXGdfxW3yz945XPfxA9oPGMX7ZwfNHRx0k1CQzKkEid?= =?us-ascii?q?p5HrMT+P0eQNqWeb4vNmWOmyhWAnrARxrSKuxscqkoTJiYQVyk3e+SV+2oY1Kt?= =?us-ascii?q?u1Q1N4b968CJZdtD2WO5FoTs8+Xm1koik3x7MctZO4fSUHzoksyQTFZPydaYeI?= =?us-ascii?q?5wruVOOWIThlmn1oYKm/hxOu8Ui4ze38S9W03E5KriVbltnMsWgA1x/J5ciDS/?= =?us-ascii?q?t9+1mu2SyI1wzJ9uFEIEI0la7BJ5E9xb4wkYETvlrGHiDsnkX2l7WadkI++uin?= =?us-ascii?q?8+jnY7PmqYGAN4JsiQzyLr4iltKjDeglKAQDUGaW9f6/2bDi5UH5Ra9Fjvwykq?= =?us-ascii?q?nXqpDaIsEbq7alAw9U0IYj7w2yDzm80NsGg3YIN0lFdw+dg4juIVHOL+j0De2j?= =?us-ascii?q?jFS0jDdr2/fGM6XiApXKNXjDjLbhfbVm5EFCzAo+1t9f55dOBbEAJPL/QFP+tN?= =?us-ascii?q?vdDkxxDwvh6uDrEth0zcsiXmiLD7XRZKrUvUWF7/kzC8eWaYI/gxq7LOIqsa3A?= =?us-ascii?q?l3g8zGMcf63h9pwQc329F/J9axGFYHjoqvkbHGoghSZ4S/bl3g7RGQVPbmq/Cv?= =?us-ascii?q?pvrgowD5irWMKaHtig?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2BvBQDB4utZ/1YryVBcGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBgzRUEG4UE48NjkkBAYF5MQGIGY9/LYUYAoQ?= =?us-ascii?q?7RBQBAQEBAQEBAQEBAWoogjgkAYJBAQUnExwjEAsSBgklDxIYEA4GExSJdAMZD?= =?us-ascii?q?KxvOocvDYNZAQEBAQEBAQMBAQEBAQEdBYMuiDU1gl5UgVOFdQWhKjyHZIgXhGy?= =?us-ascii?q?BAJIuSIxEiik2IYFbVTIIgy2CXByBaT42AYgeKoIaAQEB?= X-IPAS-Result: =?us-ascii?q?A2BvBQDB4utZ/1YryVBcGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgzRUEG4UE48NjkkBAYF5MQGIGY9/LYUYAoQ7RBQBAQEBAQEBA?= =?us-ascii?q?QEBAWoogjgkAYJBAQUnExwjEAsSBgklDxIYEA4GExSJdAMZDKxvOocvDYNZAQE?= =?us-ascii?q?BAQEBAQMBAQEBAQEdBYMuiDU1gl5UgVOFdQWhKjyHZIgXhGyBAJIuSIxEiik2I?= =?us-ascii?q?YFbVTIIgy2CXByBaT42AYgeKoIaAQEB?= Received: from 86.43-201-80.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([80.201.43.86]) by relay.skynet.be with ESMTP; 22 Oct 2017 02:18:36 +0200 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.15.2/8.15.2) with ESMTP id v9M0IZFY005723; Sun, 22 Oct 2017 02:18:35 +0200 (CEST) (envelope-from tijl@FreeBSD.org) Date: Sun, 22 Oct 2017 02:18:35 +0200 From: Tijl Coosemans To: Andreas Tobler Cc: Konstantin Belousov , freebsd-current@FreeBSD.org, gerald@FreeBSD.org Subject: Re: Segfault in _Unwind_* code called from pthread_exit Message-ID: <20171022021835.07ffd30e@kalimero.tijl.coosemans.org> In-Reply-To: References: <20170823163707.096f93ab@kalimero.tijl.coosemans.org> <20170824154235.GD1700@kib.kiev.ua> <20170824180830.199885b0@kalimero.tijl.coosemans.org> <20170825173851.09116ddc@kalimero.tijl.coosemans.org> <20170825234442.GO1700@kib.kiev.ua> <20170826202813.1240a1ef@kalimero.tijl.coosemans.org> <20170826184034.GR1700@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Oct 2017 00:19:50 -0000 On Sat, 21 Oct 2017 22:02:38 +0200 Andreas Tobler wrote: > On 26.08.17 20:40, Konstantin Belousov wrote: >> On Sat, Aug 26, 2017 at 08:28:13PM +0200, Tijl Coosemans wrote: >>> On Sat, 26 Aug 2017 02:44:42 +0300 Konstantin Belousov wrote: >>>> How does llvm unwinder detects that the return address is a garbage ? >>> >>> It just stops unwinding when it can't find frame information (stored in >>> .eh_frame sections). GCC unwinder doesn't give up yet and checks if the >>> return address points to the signal trampoline (which means the current >>> frame is that of a signal handler). It has built-in knowledge of how to >>> unwind to the signal trampoline frame. >> So llvm just gives up on signal frames ? >> >>> A noreturn attribute isn't enough. You can still unwind such functions. >>> They are allowed to throw exceptions for example. >> Ok. >> >>> I did consider using >>> a CFI directive (see patch below) and it works, but it's architecture >>> specific and it's inserted after the function prologue so there's still >>> a window of a few instructions where a stack unwinder will try to use >>> the return address. >>> >>> Index: lib/libthr/thread/thr_create.c >>> =================================================================== >>> --- lib/libthr/thread/thr_create.c (revision 322802) >>> +++ lib/libthr/thread/thr_create.c (working copy) >>> @@ -251,6 +251,7 @@ create_stack(struct pthread_attr *pattr) >>> static void >>> thread_start(struct pthread *curthread) >>> { >>> + __asm(".cfi_undefined %rip"); >>> sigset_t set; >>> >>> if (curthread->attr.suspend == THR_CREATE_SUSPENDED) >> >> I like this approach much more than the previous patch. What can be >> done is to provide asm trampoline which calls thread_start(). There you >> can add the .cfi_undefined right at the entry. >> >> It is somewhat more work than just setting the return address on the >> kernel-constructed pseudo stack frame, but I believe this is ultimately >> correct way. You still can do it only on some arches, if you do not >> have incentive to code asm for all of them. >> >> Also crt1 probably should get the same treatment, despite we already set >> %rbp to zero AFAIR. > > Did some commit result out of this discussion or is this subject still > under investigation? > > Curious because I got this gcc PR: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82635 Sorry, but I didn't and won't have time to work on this. Ideally I think there should be a function attribute to mark functions as entry points. The compiler would add ".cfi_undefined %rip" to such functions (and maybe optimise the function prologue because there are no caller registers that need to be preserved). If you have connections in the GCC community maybe you could discuss that with them.