From dbc3bbc0232a685fbf181122cad261d4278f9a39 Mon Sep 17 00:00:00 2001 From: Sangbida Chaudhuri <101164840+sangbida@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:54:12 +0930 Subject: [PATCH 1/2] configure: Add macOS-specific debug flags for libbacktrace compatibility On macOS, libbacktrace was failing to find debug information due to: 1. Debug symbols not being properly linked with dsymutil 2. Apple Clang 17.0.0 generating DWARF 5 which libbacktrace couldn't parse In this commit we address both issues: Debug symbol accessibility: - Add dsymutil integration in Makefile to properly link debug symbols - Use -fno-standalone-debug to embed debug info inline in executable DWARF format compatibility: - Force -gdwarf-4 instead of default DWARF 5 to avoid "DW_FORM_addrx value out of range" errors Changelog-added: libbacktrace works with macOS --- Makefile | 6 ++++++ configure | 16 +++++++++++++++- external/libbacktrace | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 55a4ad8bb0bb..09a60e3c265d 100644 --- a/Makefile +++ b/Makefile @@ -684,12 +684,18 @@ $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS): %: %.o # (as per EXTERNAL_LDLIBS) so we filter them out here. $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS): @$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $($(@)_LDLIBS) -o $@) +ifeq ($(OS),Darwin) + @$(call VERBOSE, "dsymutil $@", dsymutil $@) +endif # We special case the fuzzing target binaries, as they need to link against libfuzzer, # which brings its own main(). FUZZ_LDFLAGS = -fsanitize=fuzzer $(ALL_FUZZ_TARGETS): @$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $(FUZZ_LDFLAGS) -o $@) +ifeq ($(OS),Darwin) + @$(call VERBOSE, "dsymutil $@", dsymutil $@) +endif # Everything depends on the CCAN headers, and Makefile diff --git a/configure b/configure index c72981610b2a..bdb803bebbee 100755 --- a/configure +++ b/configure @@ -148,7 +148,18 @@ set_defaults() # which matters since you might explicitly set of these blank. PREFIX=${PREFIX:-/usr/local} CC=${CC:-cc} - CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong} + # Detect macOS and use appropriate debug flags for libbacktrace compatibility + if [ "$(uname -s)" = "Darwin" ]; then + # Always override to avoid DWARF 5 + CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fstack-protector-strong" + + # Optional: confirm dsymutil is available + if ! command -v dsymutil >/dev/null 2>&1; then + echo "Warning: dsymutil not found. Install Xcode Command Line Tools for better debug support." + fi + else + CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong} + fi DEBUGBUILD=${DEBUGBUILD:-0} COMPAT=${COMPAT:-1} STATIC=${STATIC:-0} @@ -194,6 +205,9 @@ usage() usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS" usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS" usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS" + if [ "$(uname -s)" = "Darwin" ]; then + echo " Note: On macOS, -g is used instead of -g3 for libbacktrace compatibility" + fi usage_with_default "CONFIGURATOR_CC" "${CONFIGURATOR_CC:-$CC}" echo " To override compile line for configurator itself" usage_with_default "PYTEST" "$PYTEST" diff --git a/external/libbacktrace b/external/libbacktrace index 2446c6607648..793921876c98 160000 --- a/external/libbacktrace +++ b/external/libbacktrace @@ -1 +1 @@ -Subproject commit 2446c66076480ce07a6bd868badcbceb3eeecc2e +Subproject commit 793921876c981ce49759114d7bb89bb89b2d3a2d From 00563e5ee6f76667b929107edb2f0e03820c8518 Mon Sep 17 00:00:00 2001 From: Sangbida Chaudhuri <101164840+sangbida@users.noreply.github.com> Date: Sat, 2 Aug 2025 20:39:34 +0930 Subject: [PATCH 2/2] configure: Fix debug symbols for installed binaries on macOS When installing core lightning on macOS I found that the debug symbols were not being preserved leading to "no debug info in Mach-O executable". This is because the .dSYM files, which contain the debug information, is generated in the build directory and could not be found by the installed binaries. Changes: - Add -fno-standalone-debug flag to CDEBUGFLAGS on macOS to reduce dependency on absolute source paths - Modify install-program target to copy .dSYM bundles alongside binaries for BIN_PROGRAMS, PKGLIBEXEC_PROGRAMS, and PLUGINS Testing: 1. ./configure --reconfigure 2. make install PREFIX=/tmp/lightning-install 3. make clean (removes all .dSYM files from build directory) 4. /tmp/lightning-install/bin/lightningd --help 5. Verified stack traces now work correctly without "no debug info" errors --- Makefile | 6 ++++++ configure | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 09a60e3c265d..ab36d7b6db23 100644 --- a/Makefile +++ b/Makefile @@ -825,6 +825,12 @@ install-program: installdirs $(BIN_PROGRAMS) $(PKGLIBEXEC_PROGRAMS) $(PLUGINS) $ @if [ -d "$(DESTDIR)$(plugindir)/wss-proxy" ]; then rm -rf $(DESTDIR)$(plugindir)/wss-proxy; fi [ -z "$(PLUGINS)" ] || $(INSTALL_PROGRAM) $(PLUGINS) $(DESTDIR)$(plugindir) for PY in $(PY_PLUGINS); do DIR=`dirname $$PY`; DST=$(DESTDIR)$(plugindir)/`basename $$DIR`; if [ -d $$DST ]; then rm -rf $$DST; fi; $(INSTALL_PROGRAM) -d $$DIR; cp -a $$DIR $$DST ; done +ifeq ($(OS),Darwin) + # Install dSYM bundles alongside binaries on macOS + for BIN in $(BIN_PROGRAMS); do if [ -d $$BIN.dSYM ]; then cp -a $$BIN.dSYM $(DESTDIR)$(bindir)/; fi; done + for BIN in $(PKGLIBEXEC_PROGRAMS); do if [ -d $$BIN.dSYM ]; then cp -a $$BIN.dSYM $(DESTDIR)$(pkglibexecdir)/; fi; done + for PLUGIN in $(PLUGINS); do if [ -d $$PLUGIN.dSYM ]; then cp -a $$PLUGIN.dSYM $(DESTDIR)$(plugindir)/; fi; done +endif MAN1PAGES = $(filter %.1,$(MANPAGES)) MAN5PAGES = $(filter %.5,$(MANPAGES)) diff --git a/configure b/configure index bdb803bebbee..015af842ddd0 100755 --- a/configure +++ b/configure @@ -151,7 +151,7 @@ set_defaults() # Detect macOS and use appropriate debug flags for libbacktrace compatibility if [ "$(uname -s)" = "Darwin" ]; then # Always override to avoid DWARF 5 - CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fstack-protector-strong" + CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong" # Optional: confirm dsymutil is available if ! command -v dsymutil >/dev/null 2>&1; then