From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5D347389853A for ; Mon, 1 Mar 2021 13:54:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5D347389853A Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-EzLmpZtkPlq53RPI4e3Atg-1; Mon, 01 Mar 2021 08:54:42 -0500 X-MC-Unique: EzLmpZtkPlq53RPI4e3Atg-1 Received: by mail-qv1-f69.google.com with SMTP id n1so12439660qvi.4 for ; Mon, 01 Mar 2021 05:54:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=8tiXJXQ4uxscO2XQR7iIHvkwdUuBYb9ZxkzIufsk5Cc=; b=kl+qAG77+ZsScQYZ1XlMGfVrqMr/CevDmTIcfuy8PcOMiyN83cO2DYXWbP2b47BEHZ HZ4N7EpJfsvCF2fVdUVrWusSqlJRbkH+hEgbrXYYm7sYzmGlrpX9V7U256myASIKTkaz JxgrbZRm3GzmJhctJErJ9PGn1fDKvStyvzcJddPWFq6GGKLMbsAP+K7TOYDnVpl7sHVG DG/sLxirqz9TbfIGmpP90PYKQj9RUpDJsxYOece6bWOmabHwTJ2GtzkbcXmVGVApT2Lo vXAgmtVtqomYSSoIRxloutOr2I9fL+wDHg4zt+DJ9CEeG9swwtZxybRLN3rxsVEgQKX+ eIAg== X-Gm-Message-State: AOAM5312CUZ4QkOiTGlDgpg/JulpTLb6uQqAOOnWNICJ2jRvExXM2KYc h6Hqsv7PpT6qzHu++XkZdclBnY25j9OUfKo7NnGyQezwAA/YL2ryorqXVuncr40PYS+0qawCOLG vG2N77ljKZFAF5dlV0hua15goHq9HzV+wEyi/6c/Hpjdo+3p91xm+HEKTVFGXY2n1w1VWAg== X-Received: by 2002:ac8:7186:: with SMTP id w6mr13376343qto.255.1614606882055; Mon, 01 Mar 2021 05:54:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6UV8358bcpQHxk8AfYaDV/IxsSVx+e0cSb8TB1WL1Au5Ay7a4IBZj5ARBVvhP+XpdXJ5uRA== X-Received: by 2002:ac8:7186:: with SMTP id w6mr13376331qto.255.1614606881765; Mon, 01 Mar 2021 05:54:41 -0800 (PST) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id o76sm1807822qke.79.2021.03.01.05.54.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Mar 2021 05:54:41 -0800 (PST) Subject: Re: [PATCH 04/10] i386: Implement backtrace on top of To: Florian Weimer , libc-alpha@sourceware.org References: From: Carlos O'Donell Organization: Red Hat Message-ID: Date: Mon, 1 Mar 2021 08:54:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Mar 2021 13:54:45 -0000 On 2/17/21 11:03 AM, Florian Weimer via Libc-alpha wrote: LGTM. And the i386 version. Reviewed-by: Carlos O'Donell > --- > sysdeps/i386/backtrace.c | 82 +++++++++------------------------------- > 1 file changed, 18 insertions(+), 64 deletions(-) > > diff --git a/sysdeps/i386/backtrace.c b/sysdeps/i386/backtrace.c > index 124b0b73e3..4631f68fdc 100644 > --- a/sysdeps/i386/backtrace.c > +++ b/sysdeps/i386/backtrace.c > @@ -17,52 +17,18 @@ > License along with the GNU C Library; if not, see > . */ > > -#include > -#include > #include > #include > -#include > +#include > > struct trace_arg > { > void **array; > + struct unwind_link *unwind_link; > int cnt, size; > void *lastebp, *lastesp; > }; > > -#ifdef SHARED > -static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); > -static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); > -static _Unwind_Ptr (*unwind_getcfa) (struct _Unwind_Context *); > -static _Unwind_Ptr (*unwind_getgr) (struct _Unwind_Context *, int); > -static void *libgcc_handle; > - > -static void > -init (void) > -{ > - libgcc_handle = __libc_dlopen ("libgcc_s.so.1"); > - > - if (libgcc_handle == NULL) > - return; > - > - unwind_backtrace = __libc_dlsym (libgcc_handle, "_Unwind_Backtrace"); > - unwind_getip = __libc_dlsym (libgcc_handle, "_Unwind_GetIP"); > - unwind_getcfa = __libc_dlsym (libgcc_handle, "_Unwind_GetCFA"); > - unwind_getgr = __libc_dlsym (libgcc_handle, "_Unwind_GetGR"); > - if (unwind_getip == NULL || unwind_getgr == NULL || unwind_getcfa == NULL) > - { > - unwind_backtrace = NULL; > - __libc_dlclose (libgcc_handle); > - libgcc_handle = NULL; > - } > -} > -#else > -# define unwind_backtrace _Unwind_Backtrace > -# define unwind_getip _Unwind_GetIP > -# define unwind_getcfa _Unwind_GetCFA > -# define unwind_getgr _Unwind_GetGR > -#endif > - > static _Unwind_Reason_Code > backtrace_helper (struct _Unwind_Context *ctx, void *a) > { > @@ -71,13 +37,16 @@ backtrace_helper (struct _Unwind_Context *ctx, void *a) > /* We are first called with address in the __backtrace function. > Skip it. */ > if (arg->cnt != -1) > - arg->array[arg->cnt] = (void *) unwind_getip (ctx); > + arg->array[arg->cnt] > + = (void *) UNWIND_LINK_PTR (arg->unwind_link, _Unwind_GetIP) (ctx); > if (++arg->cnt == arg->size) > return _URC_END_OF_STACK; > > /* %ebp is DWARF2 register 5 on IA-32. */ > - arg->lastebp = (void *) unwind_getgr (ctx, 5); > - arg->lastesp = (void *) unwind_getcfa (ctx); > + arg->lastebp > + = (void *) UNWIND_LINK_PTR (arg->unwind_link, _Unwind_GetGR) (ctx, 5); > + arg->lastesp > + = (void *) UNWIND_LINK_PTR (arg->unwind_link, _Unwind_GetCFA) (ctx); > return _URC_NO_REASON; > } > > @@ -111,20 +80,19 @@ struct layout > int > __backtrace (void **array, int size) > { > - struct trace_arg arg = { .array = array, .size = size, .cnt = -1 }; > - > - if (size <= 0) > - return 0; > - > -#ifdef SHARED > - __libc_once_define (static, once); > + struct trace_arg arg = > + { > + .array = array, > + .unwind_link = __libc_unwind_link_get (), > + .size = size, > + .cnt = -1, > + }; > > - __libc_once (once, init); > - if (unwind_backtrace == NULL) > + if (size <= 0 || arg.unwind_link == NULL) > return 0; > -#endif > > - unwind_backtrace (backtrace_helper, &arg); > + UNWIND_LINK_PTR (arg.unwind_link, _Unwind_Backtrace) > + (backtrace_helper, &arg); > > if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL) > --arg.cnt; > @@ -147,17 +115,3 @@ __backtrace (void **array, int size) > } > weak_alias (__backtrace, backtrace) > libc_hidden_def (__backtrace) > - > - > -#ifdef SHARED > -/* Free all resources if necessary. */ > -libc_freeres_fn (free_mem) > -{ > - unwind_backtrace = NULL; > - if (libgcc_handle != NULL) > - { > - __libc_dlclose (libgcc_handle); > - libgcc_handle = NULL; > - } > -} > -#endif > -- Cheers, Carlos.