Index: lib/libexecinfo/Makefile =================================================================== RCS file: /cvsroot/src/lib/libexecinfo/Makefile,v retrieving revision 1.9 diff -u -p -u -p -r1.9 Makefile --- lib/libexecinfo/Makefile 22 Jan 2020 15:10:32 -0000 1.9 +++ lib/libexecinfo/Makefile 24 Jun 2022 12:00:50 -0000 @@ -27,6 +27,10 @@ SRCS+=unwind_arm_ehabi_stub.c 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 Index: lib/libexecinfo/backtrace.c =================================================================== RCS file: /cvsroot/src/lib/libexecinfo/backtrace.c,v retrieving revision 1.7 diff -u -p -u -p -r1.7 backtrace.c --- lib/libexecinfo/backtrace.c 23 Jun 2022 09:48:00 -0000 1.7 +++ lib/libexecinfo/backtrace.c 24 Jun 2022 12:00:50 -0000 @@ -45,6 +45,7 @@ __RCSID("$NetBSD: backtrace.c,v 1.7 2022 #include #include "execinfo.h" +#include "symbol.h" #include "symtab.h" #ifdef __linux__ @@ -114,7 +115,8 @@ static ssize_t 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; Index: lib/libexecinfo/symbol.h =================================================================== RCS file: lib/libexecinfo/symbol.h diff -N lib/libexecinfo/symbol.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libexecinfo/symbol.h 24 Jun 2022 12:00:50 -0000 @@ -0,0 +1,53 @@ +/* $NetBSD$ */ + +/*- + * 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 + +__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 + +static inline uintptr_t +symbol_canonicalize(void * addr) +{ + return SYMBOL_CANONICALIZE(addr); +} +__END_DECLS + +#endif /* _SYMBOL_H_ */ Index: lib/libexecinfo/symbol_hppa.c =================================================================== RCS file: lib/libexecinfo/symbol_hppa.c diff -N lib/libexecinfo/symbol_hppa.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libexecinfo/symbol_hppa.c 24 Jun 2022 12:00:50 -0000 @@ -0,0 +1,53 @@ +/* $NetBSD$ */ + +/*- + * 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 +__RCSID("$NetBSD$"); + +#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; +} + Index: lib/libexecinfo/symtab.c =================================================================== RCS file: /cvsroot/src/lib/libexecinfo/symtab.c,v retrieving revision 1.8 diff -u -p -u -p -r1.8 symtab.c --- lib/libexecinfo/symtab.c 23 Jun 2022 09:58:25 -0000 1.8 +++ lib/libexecinfo/symtab.c 24 Jun 2022 12:00:50 -0000 @@ -48,6 +48,7 @@ __RCSID("$NetBSD: symtab.c,v 1.8 2022/06 #define ELF_ST_TYPE(x) (((unsigned int)x) & 0xf) #endif +#include "symbol.h" #include "symtab.h" #ifdef SYMTAB_DEBUG @@ -192,11 +193,12 @@ symtab_find(const symtab_t *st, const vo 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)