Skip to content

Commit

Permalink
makefile: no build with unwind when gcc does not support.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed May 9, 2024
1 parent f92fbb8 commit 5d76934
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
5 changes: 5 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <unwind.h>\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)
Expand Down
7 changes: 7 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#ifdef HAVE_UNWIND_BACKTRACE
#include <unwind.h>
#endif

#define TMP_BUFF_LEN_32 32

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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, ...)
{
Expand Down

1 comment on commit 5d76934

@zxlhhyccc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.