Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libexecinfo Decode function descriptors (aka plabels) on...
details: https://anonhg.NetBSD.org/src/rev/4496025761d7
branches: trunk
changeset: 368131:4496025761d7
user: skrll <skrll%NetBSD.org@localhost>
date: Sat Jun 25 06:51:37 2022 +0000
description:
Decode function descriptors (aka plabels) on hppa to fix backtrace.
PR/56881: hppa: backtrace_symbols() delivers bogus results for some dynloaded functions
diffstat:
lib/libexecinfo/Makefile | 6 ++++-
lib/libexecinfo/backtrace.c | 8 ++++--
lib/libexecinfo/symbol.h | 49 +++++++++++++++++++++++++++++++++++++++++
lib/libexecinfo/symbol_hppa.c | 51 +++++++++++++++++++++++++++++++++++++++++++
lib/libexecinfo/symtab.c | 14 ++++++-----
5 files changed, 118 insertions(+), 10 deletions(-)
diffs (207 lines):
diff -r 70229239ef72 -r 4496025761d7 lib/libexecinfo/Makefile
--- a/lib/libexecinfo/Makefile Sat Jun 25 05:01:31 2022 +0000
+++ b/lib/libexecinfo/Makefile Sat Jun 25 06:51:37 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2020/01/22 15:10:32 mgorny Exp $
+# $NetBSD: Makefile,v 1.10 2022/06/25 06:51:37 skrll Exp $
.include <bsd.own.mk>
@@ -27,6 +27,10 @@
SRCS+=builtin.c
.endif
+.if exists(${.CURDIR}/symbol_${LIBEXECINFO_MACHINE_ARCH}.c)
+SRCS+=symbol_${LIBEXECINFO_MACHINE_ARCH}.c
+.endif
+
MLINKS+= backtrace.3 backtrace_symbols.3
MLINKS+= backtrace.3 backtrace_symbols_fmt.3
MLINKS+= backtrace.3 backtrace_symbols_fd.3
diff -r 70229239ef72 -r 4496025761d7 lib/libexecinfo/backtrace.c
--- a/lib/libexecinfo/backtrace.c Sat Jun 25 05:01:31 2022 +0000
+++ b/lib/libexecinfo/backtrace.c Sat Jun 25 06:51:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: backtrace.c,v 1.7 2022/06/23 09:48:00 skrll Exp $ */
+/* $NetBSD: backtrace.c,v 1.8 2022/06/25 06:51:37 skrll Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: backtrace.c,v 1.7 2022/06/23 09:48:00 skrll Exp $");
+__RCSID("$NetBSD: backtrace.c,v 1.8 2022/06/25 06:51:37 skrll Exp $");
#include <sys/param.h>
#include <assert.h>
@@ -45,6 +45,7 @@
#include <elf.h>
#include "execinfo.h"
+#include "symbol.h"
#include "symtab.h"
#ifdef __linux__
@@ -114,7 +115,8 @@
format_string(char **buf, size_t *bufsiz, size_t offs, const char *fmt,
Dl_info *dli, const void *addr)
{
- ptrdiff_t diff = (const char *)addr - (const char *)dli->dli_saddr;
+ const uintptr_t symaddr = SYMBOL_CANONICALIZE(dli->dli_saddr);
+ ptrdiff_t diff = (const char *)addr - (const char *)symaddr;
size_t o = offs;
int len;
diff -r 70229239ef72 -r 4496025761d7 lib/libexecinfo/symbol.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libexecinfo/symbol.h Sat Jun 25 06:51:37 2022 +0000
@@ -0,0 +1,49 @@
+/* $NetBSD: symbol.h,v 1.1 2022/06/25 06:51:37 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2022 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYMBOL_H_
+#define _SYMBOL_H_
+
+#include <sys/param.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+#if defined(__HAVE_FUNCTION_DESCRIPTORS)
+uintptr_t symbol_canonicalize_md(const void *);
+#define SYMBOL_CANONICALIZE(x) symbol_canonicalize_md(x)
+#else
+#define SYMBOL_CANONICALIZE(x) ((uintptr_t)(x))
+#endif
+
+__END_DECLS
+
+#endif /* _SYMBOL_H_ */
diff -r 70229239ef72 -r 4496025761d7 lib/libexecinfo/symbol_hppa.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libexecinfo/symbol_hppa.c Sat Jun 25 06:51:37 2022 +0000
@@ -0,0 +1,51 @@
+/* $NetBSD: symbol_hppa.c,v 1.1 2022/06/25 06:51:37 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2022 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: symbol_hppa.c,v 1.1 2022/06/25 06:51:37 skrll Exp $");
+
+#include "symbol.h"
+
+#define HPPA_IS_PLABEL(addr) (((uintptr_t)(addr)) & (1 << 1))
+#define HPPA_GET_PLABEL(addr) ((hppa_plabel *) (((uintptr_t)addr) & ~3))
+
+typedef struct {
+ uintptr_t pl_pc;
+ uintptr_t pl_sl;
+} hppa_plabel;
+
+
+uintptr_t
+symbol_canonicalize_md(const void *addr)
+{
+ return HPPA_IS_PLABEL(addr) ?
+ HPPA_GET_PLABEL(addr)->pl_pc : (uintptr_t)addr;
+}
diff -r 70229239ef72 -r 4496025761d7 lib/libexecinfo/symtab.c
--- a/lib/libexecinfo/symtab.c Sat Jun 25 05:01:31 2022 +0000
+++ b/lib/libexecinfo/symtab.c Sat Jun 25 06:51:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: symtab.c,v 1.8 2022/06/23 09:58:25 skrll Exp $ */
+/* $NetBSD: symtab.c,v 1.9 2022/06/25 06:51:37 skrll Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: symtab.c,v 1.8 2022/06/23 09:58:25 skrll Exp $");
+__RCSID("$NetBSD: symtab.c,v 1.9 2022/06/25 06:51:37 skrll Exp $");
#include <stdlib.h>
#include <stdio.h>
@@ -48,6 +48,7 @@
#define ELF_ST_TYPE(x) (((unsigned int)x) & 0xf)
#endif
+#include "symbol.h"
#include "symtab.h"
#ifdef SYMTAB_DEBUG
@@ -192,11 +193,12 @@
size_t mid = ns / 2;
uintptr_t fbase = st->ispie ? (uintptr_t)dli->dli_fbase : 0;
uintptr_t dd, sd, me = (uintptr_t)p - fbase;
- uintptr_t ad = (uintptr_t)dli->dli_saddr - fbase;
+ uintptr_t sa = SYMBOL_CANONICALIZE(dli->dli_saddr);
+ uintptr_t ad = sa - fbase;
- DPRINTF("[fbase=%#jx, saddr=%p, me=%#jx ad=%#jx]",
- (uintmax_t)fbase, dli->dli_saddr,
- (uintmax_t)me, (uintmax_t)ad);
+ DPRINTF("[fbase=%#jx, saddr=%p, sa=%#jx, me=%#jx ad=%#jx]",
+ (uintmax_t)fbase, dli->dli_saddr, (uintmax_t)sa,
+ (uintmax_t)me, (uintmax_t)ad);
for (;;) {
if (s[mid].st_value < me)
Home |
Main Index |
Thread Index |
Old Index