From owner-svn-src-head@freebsd.org Sat Oct 26 07:00:00 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C1912161840; Sat, 26 Oct 2019 07:00:00 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 470X0w4jB9z3LLH; Sat, 26 Oct 2019 07:00:00 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 84A8C42A4; Sat, 26 Oct 2019 07:00:00 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9Q7002d078085; Sat, 26 Oct 2019 07:00:00 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9Q700CJ078075; Sat, 26 Oct 2019 07:00:00 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201910260700.x9Q700CJ078075@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 26 Oct 2019 07:00:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354112 - in head: contrib/libexecinfo lib/libexecinfo X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head: contrib/libexecinfo lib/libexecinfo X-SVN-Commit-Revision: 354112 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Oct 2019 07:00:00 -0000 Author: cem Date: Sat Oct 26 06:59:59 2019 New Revision: 354112 URL: https://svnweb.freebsd.org/changeset/base/354112 Log: Sync up with NetBSD libexecinfo changes 2014-2019 Drop portions that are unlit or redundant with llvm-libunwind: builtin.c, unwind.h, and unwind_arm_ehabi_stub.c. This code should now work with -fPIE binaries, should we choose to build any that way. When backtrace() array is full, signal an error so the underlying Itanium-style C++ exception handling library (llvm-libunwind) knows to stop tracing instead of continuing. (It should stop on its own when it finishes unwinding, so this is mostly an extra seatbelt against an infinite loop bug in the unwinder.) Deleted: head/contrib/libexecinfo/builtin.c head/contrib/libexecinfo/unwind.h head/contrib/libexecinfo/unwind_arm_ehabi_stub.c Modified: head/contrib/libexecinfo/symtab.c head/contrib/libexecinfo/unwind.c head/lib/libexecinfo/Makefile Modified: head/contrib/libexecinfo/symtab.c ============================================================================== --- head/contrib/libexecinfo/symtab.c Sat Oct 26 03:07:28 2019 (r354111) +++ head/contrib/libexecinfo/symtab.c Sat Oct 26 06:59:59 2019 (r354112) @@ -1,4 +1,4 @@ -/* $NetBSD: symtab.c,v 1.2 2013/08/29 15:01:57 christos Exp $ */ +/* $NetBSD: symtab.c,v 1.5 2016/04/20 14:00:16 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -29,12 +29,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: symtab.c,v 1.2 2013/08/29 15:01:57 christos Exp $"); +__RCSID("$NetBSD: symtab.c,v 1.5 2016/04/20 14:00:16 christos Exp $"); #include #include #include #include +#include #include #include @@ -47,7 +48,6 @@ __RCSID("$NetBSD: symtab.c,v 1.2 2013/08/29 15:01:57 c #define ELF_ST_TYPE(x) (((unsigned int)x) & 0xf) #endif - #include "symtab.h" struct symbol { @@ -59,6 +59,7 @@ struct symbol { struct symtab { size_t nsymbols; struct symbol *symbols; + bool ispie; }; static int @@ -86,6 +87,7 @@ symtab_create(int fd, int bind, int type) Elf *elf; symtab_t *st; Elf_Scn *scn = NULL; + GElf_Ehdr ehdr; if (elf_version(EV_CURRENT) == EV_NONE) { warnx("Elf Library is out of date."); @@ -103,7 +105,14 @@ symtab_create(int fd, int bind, int type) elf_end(elf); return NULL; } + if (gelf_getehdr(elf, &ehdr) == NULL) { + warnx("Error getting ELF Ehdr"); + elf_end(elf); + return NULL; + } + st->ispie = ehdr.e_type == ET_DYN; + while ((scn = elf_nextscn(elf, scn)) != NULL) { GElf_Shdr shdr; Elf_Data *edata; @@ -127,6 +136,13 @@ symtab_create(int fd, int bind, int type) GElf_Sym sym; gelf_getsym(edata, (int)i, &sym); +#ifdef SYMTAB_DEBUG + fprintf(stderr, "%s: %s@%#jx=%d,%d\n", __func__, + elf_strptr(elf, shdr.sh_link, sym.st_name), + (uintmax_t)sym.st_value, ELF_ST_BIND(sym.st_info), + ELF_ST_TYPE(sym.st_info)); +#endif + if (bind != -1 && (unsigned)bind != ELF_ST_BIND(sym.st_info)) continue; @@ -159,7 +175,7 @@ out: return NULL; } - + int symtab_find(const symtab_t *st, const void *p, Dl_info *dli) { @@ -168,8 +184,15 @@ symtab_find(const symtab_t *st, const void *p, Dl_info size_t hi = ns; size_t lo = 0; size_t mid = ns / 2; - uintptr_t dd, sd, me = (uintptr_t)p; + 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; +#ifdef SYMTAB_DEBUG + fprintf(stderr, "%s: [fbase=%#jx, saddr=%p, me=%#jx ad=%#jx]\n", + __func__, (uintmax_t)fbase, dli->dli_saddr, (uintmax_t)me, + (uintmax_t)ad); +#endif for (;;) { if (s[mid].st_value < me) lo = mid; @@ -183,11 +206,20 @@ symtab_find(const symtab_t *st, const void *p, Dl_info } mid = (hi + lo) / 2; } - dd = me - (uintptr_t)dli->dli_saddr; + dd = me - ad; sd = me - s[mid].st_value; if (dd > sd) { dli->dli_saddr = (void *)s[mid].st_value; dli->dli_sname = s[mid].st_name; +#ifdef SYMTAB_DEBUG + fprintf(stderr, "%s: me=%#jx -> [%#jx, %s]\n", __func__, + (uintmax_t)me, (uintmax_t)sd, dli->dli_sname); +#endif } +#ifdef SYMTAB_DEBUG + else + fprintf(stderr, "%s: %#jx -> [%#jx, ***]\n", __func__, + (uintmax_t)me, (uintmax_t)sd); +#endif return 1; } Modified: head/contrib/libexecinfo/unwind.c ============================================================================== --- head/contrib/libexecinfo/unwind.c Sat Oct 26 03:07:28 2019 (r354111) +++ head/contrib/libexecinfo/unwind.c Sat Oct 26 06:59:59 2019 (r354112) @@ -1,4 +1,4 @@ -/* $NetBSD: unwind.c,v 1.1 2012/05/26 22:02:29 christos Exp $ */ +/* $NetBSD: unwind.c,v 1.3 2019/01/30 22:46:49 mrg Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -51,8 +51,10 @@ tracer(struct _Unwind_Context *ctx, void *arg) return 0; } if (t->n < t->len) - t->arr[t->n++] = _Unwind_GetIP(ctx); - return 0; + t->arr[t->n++] = (void *)_Unwind_GetIP(ctx); + else + return _URC_END_OF_STACK; + return _URC_NO_REASON; } size_t Modified: head/lib/libexecinfo/Makefile ============================================================================== --- head/lib/libexecinfo/Makefile Sat Oct 26 03:07:28 2019 (r354111) +++ head/lib/libexecinfo/Makefile Sat Oct 26 06:59:59 2019 (r354112) @@ -10,6 +10,7 @@ SHLIB_MAJOR= 1 INCS= execinfo.h SRCS= backtrace.c symtab.c unwind.c +CFLAGS+= -I${SRCTOP}/contrib/libunwind/include LIBADD= elf