From 5d76934d8359e6894ad9a5f4465cbf216a5dbc02 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Thu, 9 May 2024 22:47:48 +0800 Subject: [PATCH] makefile: no build with unwind when gcc does not support. --- Dockerfile | 2 +- src/Makefile | 5 +++++ src/util.c | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6cafab5840..e88d1b2a60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ LABEL previous-stage=smartdns-builder # prepare builder ARG OPENSSL_VER=3.0.10 RUN apt update && \ - apt install -y perl curl make musl-tools musl-dev && \ + apt install -y binutils perl curl make musl-tools musl-dev && \ ln -s /usr/include/linux /usr/include/$(uname -m)-linux-musl && \ ln -s /usr/include/asm-generic /usr/include/$(uname -m)-linux-musl && \ ln -s /usr/include/$(uname -m)-linux-gnu/asm /usr/include/$(uname -m)-linux-musl && \ diff --git a/src/Makefile b/src/Makefile index df0687e0a7..7e79eb4640 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,6 +29,11 @@ ifndef CFLAGS CFLAGS +=-Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough endif +HAS_UNWIND := $(shell echo '#include \nvoid main() { _Unwind_Backtrace(0, 0);}' | $(CC) -x c - -o /dev/null >/dev/null 2>&1 && echo 1 || echo 0) +ifeq ($(HAS_UNWIND), 1) +override CFLAGS += -DHAVE_UNWIND_BACKTRACE +endif + override CFLAGS +=-Iinclude override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"' override CFLAGS += $(EXTRA_CFLAGS) diff --git a/src/util.c b/src/util.c index 611bac5aac..41a9bbde45 100644 --- a/src/util.c +++ b/src/util.c @@ -53,7 +53,9 @@ #include #include #include +#ifdef HAVE_UNWIND_BACKTRACE #include +#endif #define TMP_BUFF_LEN_32 32 @@ -1664,6 +1666,8 @@ uint64_t get_free_space(const char *path) return size; } +#ifdef HAVE_UNWIND_BACKTRACE + struct backtrace_state { void **current; void **end; @@ -1711,6 +1715,9 @@ void print_stack(void) tlog(TLOG_FATAL, "#%.2d: %p %s() from %s+%p", idx + 1, addr, symbol, info.dli_fname, offset); } } +#else +void print_stack(void) { } +#endif void bug_ext(const char *file, int line, const char *func, const char *errfmt, ...) {