Skip to content

Commit 92020ac

Browse files
sangbidarustyrussell
authored andcommitted
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
1 parent ed2b0ef commit 92020ac

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,18 @@ $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS): %: %.o
684684
# (as per EXTERNAL_LDLIBS) so we filter them out here.
685685
$(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS):
686686
@$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $($(@)_LDLIBS) -o $@)
687+
ifeq ($(OS),Darwin)
688+
@$(call VERBOSE, "dsymutil $@", dsymutil $@)
689+
endif
687690

688691
# We special case the fuzzing target binaries, as they need to link against libfuzzer,
689692
# which brings its own main().
690693
FUZZ_LDFLAGS = -fsanitize=fuzzer
691694
$(ALL_FUZZ_TARGETS):
692695
@$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $(FUZZ_LDFLAGS) -o $@)
696+
ifeq ($(OS),Darwin)
697+
@$(call VERBOSE, "dsymutil $@", dsymutil $@)
698+
endif
693699

694700

695701
# Everything depends on the CCAN headers, and Makefile

configure

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,18 @@ set_defaults()
148148
# which matters since you might explicitly set of these blank.
149149
PREFIX=${PREFIX:-/usr/local}
150150
CC=${CC:-cc}
151-
CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong}
151+
# Detect macOS and use appropriate debug flags for libbacktrace compatibility
152+
if [ "$(uname -s)" = "Darwin" ]; then
153+
# Always override to avoid DWARF 5
154+
CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fstack-protector-strong"
155+
156+
# Optional: confirm dsymutil is available
157+
if ! command -v dsymutil >/dev/null 2>&1; then
158+
echo "Warning: dsymutil not found. Install Xcode Command Line Tools for better debug support."
159+
fi
160+
else
161+
CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong}
162+
fi
152163
DEBUGBUILD=${DEBUGBUILD:-0}
153164
COMPAT=${COMPAT:-1}
154165
STATIC=${STATIC:-0}
@@ -194,6 +205,9 @@ usage()
194205
usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS"
195206
usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS"
196207
usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS"
208+
if [ "$(uname -s)" = "Darwin" ]; then
209+
echo " Note: On macOS, -g is used instead of -g3 for libbacktrace compatibility"
210+
fi
197211
usage_with_default "CONFIGURATOR_CC" "${CONFIGURATOR_CC:-$CC}"
198212
echo " To override compile line for configurator itself"
199213
usage_with_default "PYTEST" "$PYTEST"

0 commit comments

Comments
 (0)