build: remove optional support for libunwind

backtrace() was only ever used for bringup, not actually meant to be used
in any production capacity.
This commit is contained in:
Christian Hergert
2023-08-11 12:22:46 -07:00
parent 912f8e8852
commit 4ad44609d0
5 changed files with 10 additions and 46 deletions

View File

@ -14,8 +14,6 @@
#mesondefine GETTEXT_PACKAGE
#mesondefine HAVE_EXECINFO_H
#mesondefine HAVE_LIBSYSTEMD
#mesondefine HAVE_PERF_CLOCKID

View File

@ -92,7 +92,6 @@ if get_option('default_library') != 'static'
endif
endif
config_h.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h'))
config_h.set('HAVE_REALLOCARRAY', cc.has_function('reallocarray'))
config_h.set('HAVE_STRLCPY', cc.has_function('strlcpy'))
config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
@ -107,16 +106,13 @@ config_h.set10('HAVE_POLKIT_AGENT', polkit_agent_dep.found())
polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false)
config_h.set10('HAVE_POLKIT', polkit_dep.found())
if get_option('libunwind')
# Force libunwind usage if it's specified to avoid back compiles
# and backtrace() showing up in builds
if get_option('libsysprof')
libunwind_dep = dependency('libunwind-generic', required: true)
config_h.set('ENABLE_LIBUNWIND', libunwind_dep.found())
config_h.set('HAVE_UNW_SET_CACHE_SIZE',
(libunwind_dep.found() and
cc.has_header_symbol('libunwind.h',
'unw_set_cache_size',
dependencies: [libunwind_dep])))
cc.has_header_symbol('libunwind.h',
'unw_set_cache_size',
dependencies: [libunwind_dep]))
endif
# Development build setup

View File

@ -29,9 +29,6 @@ option('systemdunitdir', type: 'string',
# If Yelp documentation should be installed
option('help', type: 'boolean')
# Disable use of libunwind
option('libunwind', type: 'boolean')
# Build libsysprof (required by tools, tests, sysprof, etc)
option('libsysprof', type: 'boolean')

View File

@ -20,23 +20,16 @@
#pragma once
#ifdef HAVE_EXECINFO_H
# include <execinfo.h>
#endif
#ifdef ENABLE_LIBUNWIND
# define UNW_LOCAL_ONLY
# include <libunwind.h>
#endif
#define UNW_LOCAL_ONLY
#include <libunwind.h>
static void
backtrace_init (void)
{
#ifdef ENABLE_LIBUNWIND
unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_PER_THREAD);
# ifdef HAVE_UNW_SET_CACHE_SIZE
#ifdef HAVE_UNW_SET_CACHE_SIZE
unw_set_cache_size (unw_local_addr_space, 1024, 0);
#endif
#endif
}
static int
@ -44,36 +37,20 @@ backtrace_func (SysprofCaptureAddress *addrs,
guint n_addrs,
G_GNUC_UNUSED gpointer user_data)
{
#if defined(ENABLE_LIBUNWIND)
# if GLIB_SIZEOF_VOID_P == 8
#if GLIB_SIZEOF_VOID_P == 8
/* We know that collector will overwrite fields *AFTER* it
* has called the backtrace function allowing us to cheat
* and subtract an offset from addrs to avoid having to
* copy frame pointers around.
*/
return unw_backtrace ((void **)addrs - 2, n_addrs) - 2;
# else
#else
static const int skip = 2;
void **stack = alloca (n_addrs * sizeof (gpointer));
int n = unw_backtrace (stack, n_addrs);
for (guint i = skip; i < n; i++)
addrs[i-skip] = GPOINTER_TO_SIZE (stack[i]);
return MAX (0, n - skip);
# endif
#elif defined(HAVE_EXECINFO_H)
# if GLIB_SIZEOF_VOID_P == 8
/* See note on unw_backtrace() */
return backtrace ((void **)addrs - 2, n_addrs) - 2;
# else /* GLIB_SIZEOF_VOID_P != 8 */
static const int skip = 2;
void **stack = alloca (n_addrs * sizeof (gpointer));
int n = backtrace (stack, n_addrs);
for (guint i = skip; i < n; i++)
addrs[i-skip] = GPOINTER_TO_SIZE (stack[i]);
return MAX (0, n - skip);
# endif /* GLIB_SIZEOF_VOID_P */
#else
return 0;
#endif
}

View File

@ -3,14 +3,10 @@ libdl_dep = dependency('dl', required: false)
preload_deps = [
dependency('glib-2.0'),
libsysprof_capture_dep,
libunwind_dep,
libdl_dep,
]
if get_option('libunwind')
preload_deps += [libunwind_dep]
endif
libsysprof_memory_preload = shared_library('sysprof-memory-@0@'.format(libsysprof_api_version),
['sysprof-memory-collector.c'],
dependencies: preload_deps,