https://gitlab.com/samba-team/samba/-/commit/14feb93d481011765f62614ab49b304e17e4f6fd https://gitlab.com/samba-team/samba/-/merge_requests/2401?commit_id=ac8064cb0d79db377df75a22a240632dbc37f99f https://bugs.gentoo.org/791349 From 14feb93d481011765f62614ab49b304e17e4f6fd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 7 Jun 2022 15:07:59 +1200 Subject: [PATCH] lib/util: Prefer backtrace_symbols() for internal backtraces Backtraces when Samba is in PANIC state are better with backtrace_symbols() than with libunwind on Ubuntu 20.04 x86_64 so move libunwind to a off-by-default option, prompted for if backtrace_symbols() is not available. Based on a request by Fco Javier Felix Signed-off-by: Andrew Bartlett Reviewed-by: Joseph Sutton --- a/lib/util/fault.c +++ b/lib/util/fault.c @@ -222,9 +222,13 @@ _PUBLIC_ void smb_panic(const char *why) void log_stack_trace(void) { #ifdef HAVE_LIBUNWIND - /* Try to use libunwind before any other technique since on ia64 - * libunwind correctly walks the stack in more circumstances than - * backtrace. + /* + * --with-libunwind is required to use libunwind, the + * backtrace_symbols() code below is the default. + * + * This code is available because a previous version of this + * comment asserted that on ia64 libunwind correctly walks the + * stack in more circumstances than backtrace. */ unw_cursor_t cursor; unw_context_t uc; --- a/lib/util/wscript +++ b/lib/util/wscript @@ -2,6 +2,15 @@ def options(opt): ''' This is a bit strange, but disable is the flag, not enable. ''' opt.add_option('--disable-fault-handling', action='store_true', dest='disable_fault_handling', help=('disable the fault handlers'), default=False) + # We do not want libunwind by default (backtrace_symbols() in + # glibc is better) but allow (eg) IA-64 to build with it where it + # might be better (per old comment in fault.c) + opt.samba_add_onoff_option('libunwind', + default=None, + help='''Use libunwind instead of the default backtrace_symbols() + from libc, for example on IA-64 where it might give a better + backtrace.''') + opt.add_option('--with-systemd', help=("Enable systemd integration"), action='store_true', dest='enable_systemd') --- a/lib/util/wscript_configure +++ b/lib/util/wscript_configure @@ -1,23 +1,35 @@ #!/usr/bin/env python -from waflib import Logs, Options +from waflib import Logs, Options, Errors import os, sys if Options.options.disable_fault_handling: conf.DEFINE('HAVE_DISABLE_FAULT_HANDLING',1) -# backtrace could be in libexecinfo or in libc +# backtrace could be in libexecinfo or in libc. +# This is our preferred backtrace handler (more useful output than libunwind as at Ubuntu 20.04 x86_64) conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc=True, headers='execinfo.h') conf.CHECK_HEADERS('execinfo.h') conf.SET_TARGET_TYPE('LIBUNWIND', 'EMPTY') -if conf.check_cfg(package='libunwind-generic', - args='--cflags --libs', - msg='Checking for libunwind', - uselib_store='LIBUNWIND', - mandatory=False): - if conf.CHECK_HEADERS('libunwind.h'): - conf.SET_TARGET_TYPE('LIBUNWIND', 'SYSLIB') +if Options.options.with_libunwind: + if conf.check_cfg(package='libunwind-generic', + args='--cflags --libs', + msg='Checking for libunwind', + uselib_store='LIBUNWIND', + mandatory=False): + if conf.CHECK_HEADERS('libunwind.h'): + conf.SET_TARGET_TYPE('LIBUNWIND', 'SYSLIB') + else: + raise Errors.WafError('--with-libunwind specified but libunwind not found') +elif Options.options.with_libunwind == None: + if not conf.CONFIG_SET('HAVE_BACKTRACE_SYMBOLS') \ + and not Options.options.disable_fault_handling: + raise Errors.WafError( +'''backtrace_symbols() not found but +--with-libunwind not specified. +Use --without-libunwind to build without internal backtrace support or +--disable-fault-handling to totally defer fault handling to the OS.''') conf.CHECK_STRUCTURE_MEMBER('struct statvfs', 'f_frsize', define='HAVE_FRSIZE', headers='sys/statvfs.h') --- a/script/autobuild.py +++ b/script/autobuild.py @@ -480,10 +480,11 @@ tasks = { # MIT Kerberos from the current system. Runtime behaviour is # confirmed via the ktest (static ccache and keytab) environment + # This environment also used to confirm we can still build with --with-libunwind "samba-ktest-mit": { "sequence": [ ("random-sleep", random_sleep(300, 900)), - ("configure", "./configure.developer --without-ad-dc --with-system-mitkrb5 " + samba_configure_params), + ("configure", "./configure.developer --without-ad-dc --with-libunwind --with-system-mitkrb5 " + samba_configure_params), ("make", "make -j"), ("test", make_test(include_envs=[ "ktest", # ktest is also tested in fileserver, samba and GitLab