Explorar el Código

makefile: no build with unwind when gcc does not support.

Nick Peng hace 1 año
padre
commit
5d76934d83
Se han modificado 3 ficheros con 13 adiciones y 1 borrados
  1. 1 1
      Dockerfile
  2. 5 0
      src/Makefile
  3. 7 0
      src/util.c

+ 1 - 1
Dockerfile

@@ -4,7 +4,7 @@ LABEL previous-stage=smartdns-builder
 # prepare builder
 # prepare builder
 ARG OPENSSL_VER=3.0.10
 ARG OPENSSL_VER=3.0.10
 RUN apt update && \
 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/linux /usr/include/$(uname -m)-linux-musl && \
     ln -s /usr/include/asm-generic /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 && \
     ln -s /usr/include/$(uname -m)-linux-gnu/asm /usr/include/$(uname -m)-linux-musl && \

+ 5 - 0
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
  CFLAGS +=-Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough
 endif
 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 +=-Iinclude
 override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"'
 override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"'
 override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += $(EXTRA_CFLAGS)

+ 7 - 0
src/util.c

@@ -53,7 +53,9 @@
 #include <sys/types.h>
 #include <sys/types.h>
 #include <time.h>
 #include <time.h>
 #include <unistd.h>
 #include <unistd.h>
+#ifdef HAVE_UNWIND_BACKTRACE
 #include <unwind.h>
 #include <unwind.h>
+#endif
 
 
 #define TMP_BUFF_LEN_32 32
 #define TMP_BUFF_LEN_32 32
 
 
@@ -1664,6 +1666,8 @@ uint64_t get_free_space(const char *path)
 	return size;
 	return size;
 }
 }
 
 
+#ifdef HAVE_UNWIND_BACKTRACE
+
 struct backtrace_state {
 struct backtrace_state {
 	void **current;
 	void **current;
 	void **end;
 	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);
 		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, ...)
 void bug_ext(const char *file, int line, const char *func, const char *errfmt, ...)
 {
 {