From 2b83e78bdfe35eaa294379e77ee4f18ae80a3c3e Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 21 Mar 2026 18:31:11 +0100 Subject: [PATCH] Compile with FilC and ship the artifacts ##ci --- .github/workflows/build.yml | 25 ++++++++++++++++++++- config-user.mk.acr | 1 + libr/fs/p/fs_zip.c | 27 +++++++++++++++------- libr/util/thread.c | 7 +++--- mk/filcc.mk | 9 ++++++++ shlr/bochs/src/libbochs.c | 11 +++++---- shlr/winkd/iob_pipe.c | 2 +- shlr/zip/Makefile | 7 +++++- shlr/zip/deps.mk | 6 +++-- subprojects/Makefile | 12 +++++++++- sys/filc.sh | 45 +++++++++++++++++++++++++++++++++++++ sys/filc/Dockerfile | 6 +++++ sys/ios-cydia.sh | 4 ++-- sys/make-jobs.inc.sh | 6 ++--- sys/wasi-api.sh | 2 +- sys/wasi-browser.sh | 2 +- sys/wasi.sh | 2 +- 17 files changed, 145 insertions(+), 29 deletions(-) create mode 100644 mk/filcc.mk create mode 100755 sys/filc.sh create mode 100644 sys/filc/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4fcffa84f5..22e09e6950 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,6 @@ concurrency: cancel-in-progress: true jobs: - # WASI linux-wasi: runs-on: ubuntu-22.04 env: @@ -111,6 +110,28 @@ jobs: name: tarball path: radare2-?.?.?.* + filc: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Extract r2 version + shell: bash + run: echo "branch=`./configure -qV`" >> $GITHUB_OUTPUT + id: r2v + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y curl git gperf patchelf xz-utils + - name: Build with filc + run: ./sys/filc.sh --prefix=/opt/r2filc + - name: Install filc build + run: sudo make install + - name: Create filc tarball + run: tar -cJvf radare2-${{ steps.r2v.outputs.branch }}-filc.tar.xz /opt/r2filc + - uses: actions/upload-artifact@v7 + with: + name: filc + path: radare2-*-filc.tar.xz + # Linux linux-static: strategy: @@ -788,6 +809,7 @@ jobs: - linux-wasi-api - linux-wasi-browser - tarball + - filc # - linux-static # - linux-acr-rpm-64 - linux-acr-deb @@ -827,6 +849,7 @@ jobs: env: ASSET_FILES: | dist/artifacts/tarball/*.tar.xz + dist/artifacts/filc/*.tar.xz dist/artifacts/linux-acr-deb-*/radare2_*.deb dist/artifacts/w64-meson/*.zip dist/artifacts/w32-meson/*.zip diff --git a/config-user.mk.acr b/config-user.mk.acr index a9e5eb3acb..1dac1d3fc4 100644 --- a/config-user.mk.acr +++ b/config-user.mk.acr @@ -103,6 +103,7 @@ HAVE_LIB_MAGIC=@HAVE_LIB_MAGIC@ USE_LIB_MAGIC=@USE_LIB_MAGIC@ HAVE_LIB_XXHASH=@HAVE_LIB_XXHASH@ USE_LIB_XXHASH=@USE_LIB_XXHASH@ +WANT_ZIP=@WANT_ZIP@ USE_LIB_ZIP=@USE_LIB_ZIP@ LIBATOMIC=@LIBATOMIC@ LIBMAGIC=@LIBMAGIC@ diff --git a/libr/fs/p/fs_zip.c b/libr/fs/p/fs_zip.c index 3c2efc460a..6185da6668 100644 --- a/libr/fs/p/fs_zip.c +++ b/libr/fs/p/fs_zip.c @@ -1,9 +1,11 @@ -/* radare - LGPL - Copyright 2022-2025 - pancake */ +/* radare - LGPL - Copyright 2022-2026 - pancake */ #include #include -#include #include +#include +#if WANT_ZIP +#include static RFSFile *fs_zip_open(RFSRoot *root, const char *path, bool create) { R_LOG_INFO ("zip.open (%s)", path); @@ -94,13 +96,12 @@ static void fs_zip_close(RFSFile *file) { static void append_file(RList *list, const char *name, int type, int time, ut64 size) { RFSFile *fsf = r_fs_file_new (NULL, name); - if (!fsf) { - return; + if (fsf) { + fsf->type = type; + fsf->time = time; + fsf->size = size; + r_list_append (list, fsf); } - fsf->type = type; - fsf->time = time; - fsf->size = size; - r_list_append (list, fsf); } static RList *fs_zip_dir(RFSRoot *root, const char *path, R_UNUSED int view) { @@ -208,6 +209,16 @@ RFSPlugin r_fs_plugin_zip = { .close = fs_zip_close, .dir = &fs_zip_dir, }; +#else +RFSPlugin r_fs_plugin_zip = { + .meta = { + .name = "zip", + .author = "pancake", + .desc = "access compressed zip contents (not available)", + .license = "MIT", + }, +}; +#endif #ifndef R2_PLUGIN_INCORE R_API RLibStruct radare_plugin = { diff --git a/libr/util/thread.c b/libr/util/thread.c index dda5d416c8..e932237cd5 100644 --- a/libr/util/thread.c +++ b/libr/util/thread.c @@ -17,6 +17,7 @@ #include #endif +#if HAVE_PTHREAD || R2__WINDOWS__ #if R2__WINDOWS__ static DWORD WINAPI _r_th_launcher(void *_th) { #else @@ -93,6 +94,7 @@ static void *_r_th_launcher(void *_th) { #endif return 0; } +#endif R_API bool r_th_is_running(RThread *th) { r_th_lock_enter (th->lock); @@ -124,8 +126,7 @@ R_API R_TH_TID r_th_self(void) { #elif R2__WINDOWS__ return GetCurrentThread (); #else -#pragma message("Not implemented on this platform") - return (R_TH_TID)-1; + return (R_TH_TID)0; #endif } @@ -209,7 +210,7 @@ R_API RThread *r_th_new(RThreadFunction fun, void *user, ut32 delay) { #elif R2__WINDOWS__ th->tid = CreateThread (NULL, 0, _r_th_launcher, th, 0, 0); #endif - th->running = true; + th->running = !!th->tid; return th; } diff --git a/mk/filcc.mk b/mk/filcc.mk new file mode 100644 index 0000000000..cd08886c05 --- /dev/null +++ b/mk/filcc.mk @@ -0,0 +1,9 @@ +ifeq (${_INCLUDE_MK_FILCC_},) +_INCLUDE_MK_FILCC_=1 +include $(dir $(lastword $(MAKEFILE_LIST)))clang.mk +CFLAGS:=$(filter-out -MD,$(CFLAGS)) +CC?=filcc +AR?=ar +RANLIB?=ranlib +LD?=ld +endif diff --git a/shlr/bochs/src/libbochs.c b/shlr/bochs/src/libbochs.c index 1284b0350f..5fadf76718 100644 --- a/shlr/bochs/src/libbochs.c +++ b/shlr/bochs/src/libbochs.c @@ -257,13 +257,17 @@ bool bochs_open(libbochs_t* b, const char * pathBochs, const char * pathConfig) if (pipe (aStdinPipe) < 0) { R_LOG_ERROR ("allocating pipe for child input redirect"); - goto done; + R_FREE (b->data); + R_FREE (lpTmpBuffer); + return result; } - if (pipe(aStdoutPipe) < 0) { + if (pipe (aStdoutPipe) < 0) { close (aStdinPipe[PIPE_READ]); close (aStdinPipe[PIPE_WRITE]); R_LOG_ERROR ("allocating pipe for child output redirect"); - goto done; + R_FREE (b->data); + R_FREE (lpTmpBuffer); + return result; } nChild = fork (); @@ -324,7 +328,6 @@ bool bochs_open(libbochs_t* b, const char * pathBochs, const char * pathConfig) close (aStdoutPipe[PIPE_WRITE]); } #endif -done: R_FREE (b->data); R_FREE (lpTmpBuffer); return result; diff --git a/shlr/winkd/iob_pipe.c b/shlr/winkd/iob_pipe.c index 5671d5dac7..88ae86aab8 100644 --- a/shlr/winkd/iob_pipe.c +++ b/shlr/winkd/iob_pipe.c @@ -60,10 +60,10 @@ static int iob_pipe_write(void *p, const uint8_t *buf, const uint64_t count, con #include static void *iob_pipe_open(const char *path) { +#ifndef __wasi__ int sock; struct sockaddr_un sa; -#ifndef __wasi__ sock = socket (AF_UNIX, SOCK_STREAM, 0); if (sock == -1) { perror ("socket"); diff --git a/shlr/zip/Makefile b/shlr/zip/Makefile index 4874181c72..d0792f8cbf 100644 --- a/shlr/zip/Makefile +++ b/shlr/zip/Makefile @@ -6,6 +6,7 @@ include ../../libr/config.mk include ../../mk/platform.mk include ../../mk/$(COMPILER).mk include ../../shlr/sdb.mk +SHLR?=.. pre: all @@ -13,10 +14,14 @@ include deps.mk all: rm -f librz.$(EXT_AR) +ifneq ($(WANT_ZIP),1) + @echo zip support disabled +else ifeq ($(USE_LIB_ZIP),1) @echo no bundled zip to build else - $(MAKE) $(OTEZIP_LIBA) + $(MAKE) -C $(OTEZIP_ROOT) CC="$(CC)" EXT_AR="$(EXT_AR)" AR="$(AR)" RANLIB="$(RANLIB)" CFLAGS="$(CFLAGS) -fPIC" libotezip.$(EXT_AR) +endif endif clean: diff --git a/shlr/zip/deps.mk b/shlr/zip/deps.mk index 646589e01f..26ad6edba3 100644 --- a/shlr/zip/deps.mk +++ b/shlr/zip/deps.mk @@ -1,8 +1,9 @@ ifneq (${_INCLUDE_ZIP_DEPS_MK},1) _INCLUDE_ZIP_DEPS_MK=1 -# Link against system libzip when USE_LIB_ZIP=1 -# Otherwise link against bundled otezip from subprojects/otezip +# Link against system libzip when USE_LIB_ZIP=1. +# Otherwise link against bundled otezip from subprojects/otezip. +ifeq ($(WANT_ZIP),1) ifeq ($(USE_LIB_ZIP),1) LINK+=$(LIBZIP) else @@ -14,5 +15,6 @@ $(OTEZIP_LIBA): $(MAKE) -C $(OTEZIP_ROOT) CC="$(CC)" EXT_AR="$(EXT_AR)" AR="$(AR)" RANLIB="$(RANLIB)" CFLAGS="$(CFLAGS) -fPIC" libotezip.$(EXT_AR) LINK+=$(OTEZIP_LIBA) endif +endif endif diff --git a/subprojects/Makefile b/subprojects/Makefile index c55c106150..a56b33f480 100644 --- a/subprojects/Makefile +++ b/subprojects/Makefile @@ -2,7 +2,17 @@ -include ../config-user.mk -DEPS=sdb qjs otezip +DEPS=sdb + +ifeq ($(WANT_QJS),1) + DEPS += qjs +endif + +ifeq ($(WANT_ZIP),1) + ifeq ($(USE_LIB_ZIP),0) + DEPS += otezip + endif +endif ifeq ($(WANT_V35),1) DEPS += binaryninja diff --git a/sys/filc.sh b/sys/filc.sh new file mode 100755 index 0000000000..6e6124d2bc --- /dev/null +++ b/sys/filc.sh @@ -0,0 +1,45 @@ +#!/bin/sh +set -eu + +ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +FILC_DIR="$ROOT/sys/filc" +FILC_VERSION=${FILC_VERSION:-0.678} +FILC_NAME="filc-${FILC_VERSION}-linux-x86_64" +FILC_ROOT=${FILC_ROOT:-$FILC_DIR/$FILC_NAME} + +if [ "$(uname -s)-$(uname -m)" != "Linux-x86_64" ]; then + echo "filc only supports linux-amd64, falling back to Docker..." + docker build -t r2filc -f "$FILC_DIR/Dockerfile" "$FILC_DIR" + exec docker run --rm -v "$ROOT:/r2" -w /r2 r2filc ./sys/filc.sh "$@" +fi + +command -v filcc || [ -x "$FILC_ROOT/build/bin/filcc" ] || { + mkdir -p "$FILC_DIR" + [ -f "$FILC_DIR/$FILC_NAME.tar.xz" ] || \ + curl -L --fail -o "$FILC_DIR/$FILC_NAME.tar.xz" \ + "https://github.com/pizlonator/fil-c/releases/download/v${FILC_VERSION}/${FILC_NAME}.tar.xz" + [ -d "$FILC_ROOT" ] || \ + tar -C "$FILC_DIR" -xf "$FILC_DIR/$FILC_NAME.tar.xz" +} + +[ ! -x "$FILC_ROOT/setup.sh" ] || [ -L "$FILC_ROOT/pizfix/os-include/linux" ] || (cd "$FILC_ROOT" && ./setup.sh) + +if [ -d "$FILC_ROOT/pizfix/lib" ] && command -v cc; then + for obj in Scrt1.o crtbegin.o crtend.o crti.o crtn.o; do + dst="$FILC_ROOT/pizfix/lib/$obj" + [ -e "$dst" ] && continue + src=$(cc -print-file-name="$obj" || true) + [ -n "$src" ] && [ "$src" != "$obj" ] && [ -e "$src" ] && ln -s "$src" "$dst" + done +fi + +FILC_BIN=$(dirname "$(command -v filcc || echo "$FILC_ROOT/build/bin/filcc")") +export PATH="$FILC_BIN:$PATH" CC=filcc USERCC=filcc HOST_CC=${HOST_CC:-cc} + +[ -z "${MAKE:-}" ] && MAKE=make +cd "$ROOT" +. ./sys/make-jobs.inc.sh +${MAKE} mrproper || true +[ -z "${KEEP_PLUGINS_CFG:-}" ] && rm -f plugins.cfg +./configure --with-rpath "$@" || exit 1 +${MAKE} -j || exit 1 diff --git a/sys/filc/Dockerfile b/sys/filc/Dockerfile new file mode 100644 index 0000000000..b4634ae468 --- /dev/null +++ b/sys/filc/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:24.04 +RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends \ + ca-certificates curl gcc make patchelf pkg-config tar xz-utils \ + && rm -rf /var/lib/apt/lists/* +WORKDIR /r2 diff --git a/sys/ios-cydia.sh b/sys/ios-cydia.sh index bf4754a557..39ce704566 100755 --- a/sys/ios-cydia.sh +++ b/sys/ios-cydia.sh @@ -100,10 +100,10 @@ else cp -f dist/plugins-cfg/plugins.ios.cfg plugins.cfg if [ "$static" = 1 ]; then ./configure --prefix="${PREFIX}" --with-ostype=darwin \ - --with-compiler=ios-sdk-clang --target=arm-unknown-darwin --with-libr --without-zip + --with-compiler=ios-sdk-clang --target=arm-unknown-darwin --with-libr else ./configure --prefix="${PREFIX}" --with-ostype=darwin \ - --with-compiler=ios-sdk-clang --target=arm-unknown-darwin --without-zip + --with-compiler=ios-sdk-clang --target=arm-unknown-darwin fi RV=$? fi diff --git a/sys/make-jobs.inc.sh b/sys/make-jobs.inc.sh index d6f4f16796..1908a2908e 100755 --- a/sys/make-jobs.inc.sh +++ b/sys/make-jobs.inc.sh @@ -1,5 +1,5 @@ -[ -z "${MAKE_JOBS}" ] && MAKE_JOBS=12 +[ -z "${MAKE_JOBS:-}" ] && MAKE_JOBS=12 export MAKE_JOBS GetPlatform() { @@ -26,7 +26,7 @@ BuildJobsThrottler(){ FREE_RAM=$(grep MemAvailable /proc/meminfo | sed 's/[^0-9]//g') DEFAULT_MAX_MEM_PER_JOB=200000 - [ -z "${MAX_MEM_PER_JOB}" ] && MAX_MEM_PER_JOB="$DEFAULT_MAX_MEM_PER_JOB" # Defensive, prevent division by 0 + [ -z "${MAX_MEM_PER_JOB:-}" ] && MAX_MEM_PER_JOB="$DEFAULT_MAX_MEM_PER_JOB" # Defensive, prevent division by 0 # Assuming we may have many 300MB compilation jobs running in parallel MEM_ALLOWED_JOBS=$((FREE_RAM / MAX_MEM_PER_JOB)) @@ -40,7 +40,7 @@ BuildJobsThrottler(){ echo "So, the build will run on $MAKE_JOBS job(s)." } -if [ "${OSNAME}" = Linux ]; then +if [ "${OSNAME:-}" = Linux ]; then # Identify current platform GetPlatform # Define number of parallel jobs depending on ncpus and memory diff --git a/sys/wasi-api.sh b/sys/wasi-api.sh index 6a6742d144..ec51d8f5b4 100755 --- a/sys/wasi-api.sh +++ b/sys/wasi-api.sh @@ -14,7 +14,7 @@ wasi_setup_sdk wasi_setup_plugins # Configure and build -./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi-api --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl --without-zip || exit 1 +./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi-api --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl || exit 1 make -s -j${MAKE_JOBS} || exit 1 diff --git a/sys/wasi-browser.sh b/sys/wasi-browser.sh index 0906329dbb..ef1669ef5e 100755 --- a/sys/wasi-browser.sh +++ b/sys/wasi-browser.sh @@ -31,7 +31,7 @@ wasi_setup_plugins # Configure and build # XXX gperf-builds are broken # ./configure --with-static-themes --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl -./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl --with-wasm-browser --without-zip || exit 1 +./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl --with-wasm-browser || exit 1 make -s -j${MAKE_JOBS} || exit 1 diff --git a/sys/wasi.sh b/sys/wasi.sh index 893ce9bfab..755d60aa3f 100755 --- a/sys/wasi.sh +++ b/sys/wasi.sh @@ -16,7 +16,7 @@ wasi_setup_plugins # Configure and build # XXX gperf-builds are broken # ./configure --with-static-themes --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl -./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl --without-zip || exit 1 +./configure --with-static-themes --without-gperf --with-compiler=wasi --disable-debugger --without-fork --with-ostype=wasi --with-checks-level=0 --disable-threads --without-dylink --with-libr --without-gpl || exit 1 make -s -j${MAKE_JOBS} || exit 1