NetBSD Problem Report #56940

From  Mon Jul 25 22:30:49 2022
Return-Path: <>
Received: from ( [])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "", Issuer " CA" (not verified))
	by (Postfix) with ESMTPS id 588481A921F
	for <>; Mon, 25 Jul 2022 22:30:49 +0000 (UTC)
Message-Id: <>
Date: Mon, 25 Jul 2022 22:30:48 +0000 (UTC)
Subject: libexecinfo fails to trace stack through signal trampoline for SIGSEGV call to null function pointer
X-Send-Pr-Version: www-1.0

>Number:         56940
>Category:       lib
>Synopsis:       libexecinfo fails to trace stack through signal trampoline for SIGSEGV call to null function pointer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 25 22:35:00 +0000 2022
>Last-Modified:  Mon Jul 25 22:40:01 +0000 2022
>Originator:     Taylor R Campbell
>Release:        current
El Fundacion NetBSD
being consumed by an insatiable thirst for oil
When invoked from a signal handler for the SIGSEGV delivered due to a call to a null function pointer, the backtrace(3) functions of libexecinfo bottom out at __sigtramp_siginfo_2 or equivalent, and fail to yield return addresses for the call site of the null function pointer or its callers.

The information is available -- for example, on amd64, r15 of the signal trampoline frame points to a ucontext_t structure with process state where rsp[0] holds the return address and &rsp[1] is where parent frame lives.  But libunwind fails to find this information, and so the stack trace ends at the signal trampoline.
#include <sys/cdefs.h>

#include <err.h>
#include <execinfo.h>
#include <setjmp.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>

void (*f)(void);
jmp_buf env;
void *stack[64];
size_t stackdepth;
char **symbols;

sigsegv(int signo)


	stackdepth = backtrace(stack, __arraycount(stack));
	longjmp(env, 1);

	size_t i;

	if (signal(SIGSEGV, &sigsegv) == SIG_ERR)
		err(1, "signal(SIGSEGV)");
	if (setjmp(env) == 0)
	symbols = backtrace_symbols(stack, stackdepth);
	if (symbols == NULL)
		err(1, "backtrace_symbols");
	for (i = 0; i < stackdepth; i++)
		printf("%s\n", symbols[i]);
	return ferror(stdout);

Yes, please!

From: "Taylor R Campbell" <>
Subject: PR/56940 CVS commit: src/tests/lib/libexecinfo
Date: Mon, 25 Jul 2022 22:37:37 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Jul 25 22:37:37 UTC 2022

 Modified Files:
 	src/tests/lib/libexecinfo: t_sig_backtrace.c

 Log Message:
 execinfo(3): Mark sig_backtrace_jump test as xfail.

 PR lib/56940

 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libexecinfo/t_sig_backtrace.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD:,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.