diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 22ec5f592bc..b0d64216cf0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,6 +30,6 @@ jobs: - name: Build and push uses: docker/build-push-action@v3 with: - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7 push: true tags: ${{vars.DOCKERHUB_REPO}}:${{ github.event.inputs.version }} diff --git a/Dockerfile b/Dockerfile index 6cafab58402..2180068ab14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM ubuntu:latest as smartdns-builder +FROM debian:latest as smartdns-builder LABEL previous-stage=smartdns-builder # prepare builder -ARG OPENSSL_VER=3.0.10 +ARG OPENSSL_VER=3.0.12 RUN apt update && \ apt install -y perl curl make musl-tools musl-dev && \ ln -s /usr/include/linux /usr/include/$(uname -m)-linux-musl && \ @@ -11,13 +11,14 @@ RUN apt update && \ \ mkdir -p /build/openssl && \ cd /build/openssl && \ - curl -sSL http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_${OPENSSL_VER}.orig.tar.gz | tar --strip-components=1 -zxv && \ + curl -sSL https://www.openssl.org/source/openssl-${OPENSSL_VER}.tar.gz | tar --strip-components=1 -zxv && \ \ export CC=musl-gcc && \ + export OPENSSL_OPTIONS="no-tests no-ssl3 no-weak-ssl-ciphers no-shared no-idea -DOPENSSL_NO_SECURE_MEMORY" && \ if [ "$(uname -m)" = "aarch64" ]; then \ - ./config --prefix=/opt/build no-tests -mno-outline-atomics ; \ + ./config --prefix=/opt/build $OPENSSL_OPTIONS -mno-outline-atomics; \ else \ - ./config --prefix=/opt/build no-tests ; \ + ./config --prefix=/opt/build $OPENSSL_OPTIONS; \ fi && \ make all -j8 && make install_sw && \ cd / && rm -rf /build @@ -26,8 +27,9 @@ RUN apt update && \ COPY . /build/smartdns/ RUN cd /build/smartdns && \ export CC=musl-gcc && \ - export CFLAGS="-I /opt/build/include" && \ + export EXTRA_CFLAGS="-I /opt/build/include" && \ export LDFLAGS="-L /opt/build/lib -L /opt/build/lib64" && \ + export NOUNWIND=1 && \ sh ./package/build-pkg.sh --platform linux --arch `dpkg --print-architecture` --static && \ \ ( cd package && tar -xvf *.tar.gz && chmod a+x smartdns/etc/init.d/smartdns ) && \ diff --git a/src/Makefile b/src/Makefile index 15e92b10e10..143f445d233 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,6 +34,9 @@ override CFLAGS += $(EXTRA_CFLAGS) ifdef VER override CFLAGS += -DSMARTDNS_VERION='"$(VER)"' endif +ifdef NOUNWIND +override CFLAGS += -DNO_UNWIND +endif CXXFLAGS=-O2 -g -Wall -std=c++11 override CXXFLAGS +=-Iinclude diff --git a/src/util.c b/src/util.c index 224991984d6..9c25bd7af71 100644 --- a/src/util.c +++ b/src/util.c @@ -53,7 +53,6 @@ #include #include #include -#include #define TMP_BUFF_LEN_32 32 @@ -1419,11 +1418,45 @@ uint64_t get_free_space(const char *path) return size; } +#ifdef NO_UNWIND +void print_stack(void) +{ + return; +} +#else +#ifdef __USE_GNU +#include +void print_stack(void) +{ + void *buffer[128]; + int idx = 0; + int frame_num = backtrace(buffer, 128); + if (frame_num == 0) { + return; + } + + tlog(TLOG_FATAL, "Stack:"); + for (idx = 0; idx < frame_num; ++idx) { + const void *addr = buffer[idx]; + const char *symbol = ""; + + Dl_info info; + memset(&info, 0, sizeof(info)); + if (dladdr(addr, &info) && info.dli_sname) { + symbol = info.dli_sname; + } + + void *offset = (void *)((char *)(addr) - (char *)(info.dli_fbase)); + tlog(TLOG_FATAL, "#%.2d: %p %s() from %s+%p", idx + 1, addr, symbol, info.dli_fname, offset); + } +} + +#else +#include struct backtrace_state { void **current; void **end; }; - static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context *context, void *arg) { struct backtrace_state *state = (struct backtrace_state *)(arg); @@ -1466,6 +1499,8 @@ void print_stack(void) tlog(TLOG_FATAL, "#%.2d: %p %s() from %s+%p", idx + 1, addr, symbol, info.dli_fname, offset); } } +#endif +#endif void bug_ext(const char *file, int line, const char *func, const char *errfmt, ...) {