From patchwork Thu Feb 13 17:08:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 38045 Received: (qmail 51267 invoked by alias); 13 Feb 2020 17:08:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 51195 invoked by uid 89); 13 Feb 2020 17:08:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581613706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aMZIufhtRskyeNVAhXUGXFklweWSooHNpcCGVKFGtm8=; b=eBlXqSYrbbxhYEpCe98ZxmIF326fq1jABoNXIq1hDlYD+Rt5Bp2djqExPv/WWI37FJfe0u nj9U4fEkk9Xb+aROufuVmWd0O3HJjROy3iJ7k6af1rFPKmWlDyORxjbZFSNMuQN+iBwDQc aIk/QoJew1hYt6gtizIgx6OWziN4PZk= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 07/11] s390: Implement backtrace on top of In-Reply-To: References: X-From-Line: 00a31f83fdc74473ba1eaac8fa49d1f46a2d706c Mon Sep 17 00:00:00 2001 Message-Id: <00a31f83fdc74473ba1eaac8fa49d1f46a2d706c.1581613260.git.fweimer@redhat.com> Date: Thu, 13 Feb 2020 18:08:16 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com --- sysdeps/s390/s390-32/backtrace.c | 45 ++++++++++--------------------- sysdeps/s390/s390-64/backtrace.c | 46 ++++++++++---------------------- 2 files changed, 28 insertions(+), 63 deletions(-) diff --git a/sysdeps/s390/s390-32/backtrace.c b/sysdeps/s390/s390-32/backtrace.c index 497e4f8875..21da6761f2 100644 --- a/sysdeps/s390/s390-32/backtrace.c +++ b/sysdeps/s390/s390-32/backtrace.c @@ -17,12 +17,10 @@ License along with the GNU C Library; if not, see . */ -#include -#include #include #include #include -#include +#include /* This is a global variable set at program start time. It marks the highest used stack address. */ @@ -57,27 +55,11 @@ struct layout struct trace_arg { void **array; + struct unwind_link *unwind_link; int cnt, size; }; #ifdef SHARED -static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); -static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); - -static void -init (void) -{ - void *handle = __libc_dlopen ("libgcc_s.so.1"); - - if (handle == NULL) - return; - - unwind_backtrace = __libc_dlsym (handle, "_Unwind_Backtrace"); - unwind_getip = __libc_dlsym (handle, "_Unwind_GetIP"); - if (unwind_getip == NULL) - unwind_backtrace = NULL; -} - static int __backchain_backtrace (void **array, int size) { @@ -103,9 +85,6 @@ __backchain_backtrace (void **array, int size) return cnt; } -#else -# define unwind_backtrace _Unwind_Backtrace -# define unwind_getip _Unwind_GetIP #endif static _Unwind_Reason_Code @@ -116,7 +95,8 @@ 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; return _URC_NO_REASON; @@ -125,21 +105,24 @@ backtrace_helper (struct _Unwind_Context *ctx, void *a) int __backtrace (void **array, int size) { - struct trace_arg arg = { .array = array, .size = size, .cnt = -1 }; + struct trace_arg arg = + { + .array = array, + .unwind_link = __libc_unwind_link_get (), + .size = size, + .cnt = -1 + }; if (size <= 0) return 0; #ifdef SHARED - __libc_once_define (static, once); - - __libc_once (once, init); - - if (unwind_backtrace == NULL) + if (arg.unwind_link == NULL) return __backchain_backtrace (array, size); #endif - unwind_backtrace (backtrace_helper, &arg); + UNWIND_LINK_PTR (arg.unwind_link, _Unwind_Backtrace) + (backtrace_helper, &arg); return arg.cnt != -1 ? arg.cnt : 0; } diff --git a/sysdeps/s390/s390-64/backtrace.c b/sysdeps/s390/s390-64/backtrace.c index 5d14e01280..1b8818f219 100644 --- a/sysdeps/s390/s390-64/backtrace.c +++ b/sysdeps/s390/s390-64/backtrace.c @@ -17,13 +17,10 @@ License along with the GNU C Library; if not, see . */ -#include -#include #include #include #include -#include - +#include /* This is a global variable set at program start time. It marks the highest used stack address. */ @@ -56,27 +53,11 @@ struct layout struct trace_arg { void **array; + struct unwind_link *unwind_link; int cnt, size; }; #ifdef SHARED -static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); -static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); - -static void -init (void) -{ - void *handle = __libc_dlopen ("libgcc_s.so.1"); - - if (handle == NULL) - return; - - unwind_backtrace = __libc_dlsym (handle, "_Unwind_Backtrace"); - unwind_getip = __libc_dlsym (handle, "_Unwind_GetIP"); - if (unwind_getip == NULL) - unwind_backtrace = NULL; -} - static int __backchain_backtrace (void **array, int size) { @@ -102,9 +83,6 @@ __backchain_backtrace (void **array, int size) return cnt; } -#else -# define unwind_backtrace _Unwind_Backtrace -# define unwind_getip _Unwind_GetIP #endif static _Unwind_Reason_Code @@ -115,7 +93,8 @@ 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; return _URC_NO_REASON; @@ -124,21 +103,24 @@ backtrace_helper (struct _Unwind_Context *ctx, void *a) int __backtrace (void **array, int size) { - struct trace_arg arg = { .array = array, .size = size, .cnt = -1 }; + struct trace_arg arg = + { + .array = array, + .unwind_link = __libc_unwind_link_get (), + .size = size, + .cnt = -1 + }; if (size <= 0) return 0; #ifdef SHARED - __libc_once_define (static, once); - - __libc_once (once, init); - - if (unwind_backtrace == NULL) + if (arg.unwind_link == NULL) return __backchain_backtrace (array, size); #endif - unwind_backtrace (backtrace_helper, &arg); + UNWIND_LINK_PTR (arg.unwind_link, _Unwind_Backtrace) + (backtrace_helper, &arg); return arg.cnt != -1 ? arg.cnt : 0; }