From b43bb235efeab5324c5e486882ef46749188eee2 Mon Sep 17 00:00:00 2001 From: embr Date: Tue, 12 Sep 2023 13:34:11 +0200 Subject: [PATCH] syncterm: Cherry-pick upstream fixes for `pthread_yield` errors This non-standard function has been deprecated since glibc 2.34 (August 2021), and calls to it were breaking the build. This has since been fixed in the upstream Synchronet tree, from which SyncTERM releases are cut, but this was last done in 2020. Big thanks to @aexoxea, who not only dug into this, but adapted the upstream patches to the SyncTERM tree and posted almost this exact diff in #174749 - where it completely slipped my mind until now, sorry! Fixes #174749 --- .../0001-use-sched-yield-53264f2b.patch | 38 +++++++++++++++++++ .../terminal-emulators/syncterm/default.nix | 18 +++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 pkgs/applications/terminal-emulators/syncterm/0001-use-sched-yield-53264f2b.patch diff --git a/pkgs/applications/terminal-emulators/syncterm/0001-use-sched-yield-53264f2b.patch b/pkgs/applications/terminal-emulators/syncterm/0001-use-sched-yield-53264f2b.patch new file mode 100644 index 000000000000..d4e6eb130cad --- /dev/null +++ b/pkgs/applications/terminal-emulators/syncterm/0001-use-sched-yield-53264f2b.patch @@ -0,0 +1,38 @@ +diff --git a/3rdp/build/GNUmakefile b/3rdp/build/GNUmakefile +index fdf54565834a6a418f7267f4f8bf2269b80eab41..804dd76feb1a2d3b0278686f5326f7c2302e5fde 100644 +--- a/3rdp/build/GNUmakefile ++++ b/3rdp/build/GNUmakefile +@@ -67,7 +67,7 @@ + $(CRYPT_IDIR): | $(3RDPODIR) + $(QUIET)$(IFNOTEXIST) mkdir $(CRYPT_IDIR) + +-$(CRYPTLIB_BUILD): $(3RDP_ROOT)$(DIRSEP)dist/cryptlib.zip $(3RDP_ROOT)$(DIRSEP)build/terminal-params.patch $(3RDP_ROOT)$(DIRSEP)build/cl-mingw32-static.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ranlib.patch $(3RDP_ROOT)$(DIRSEP)build/cl-win32-noasm.patch $(3RDP_ROOT)$(DIRSEP)build/cl-zz-country.patch $(3RDP_ROOT)$(DIRSEP)build/cl-algorithms.patch $(3RDP_ROOT)$(DIRSEP)build/cl-allow-duplicate-ext.patch $(3RDP_ROOT)$(DIRSEP)build/cl-macosx-minver.patch $(3RDP_ROOT)$(DIRSEP)build/cl-endian.patch $(3RDP_ROOT)$(DIRSEP)build/cl-cryptodev.patch $(3RDP_ROOT)$(DIRSEP)build/cl-posix-me-gently.patch $(3RDP_ROOT)$(DIRSEP)build/cl-tpm-linux.patch $(3RDP_ROOT)$(DIRSEP)build/cl-PAM-noprompts.patch $(3RDP_ROOT)$(DIRSEP)build/cl-zlib.patch $(3RDP_ROOT)$(DIRSEP)build/Dynamic-linked-static-lib.patch $(3RDP_ROOT)$(DIRSEP)build/SSL-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-bigger-maxattribute.patch $(3RDP_ROOT)$(DIRSEP)build/cl-vcxproj.patch $(3RDP_ROOT)$(DIRSEP)build/cl-mingw-vcver.patch $(3RDP_ROOT)$(DIRSEP)build/cl-win32-build-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-gcc-non-const-time-val.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-odbc.patch $(3RDP_ROOT)$(DIRSEP)build/cl-noasm-defines.patch $(3RDP_ROOT)$(DIRSEP)build/cl-bn-noasm64-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-RSA-suites.patch $(3RDP_ROOT)$(DIRSEP)build/cl-fix-ECC-RSA.patch $(3RDP_ROOT)$(DIRSEP)build/cl-prefer-ECC.patch $(3RDP_ROOT)$(DIRSEP)build/cl-prefer-ECC-harder.patch $(3RDP_ROOT)$(DIRSEP)build/cl-more-RSA-ECC-fixes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-DH-key-init.patch $(3RDP_ROOT)$(DIRSEP)build/cl-clear-GCM-flag.patch $(3RDP_ROOT)$(DIRSEP)build/cl-use-ssh-ctr.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssh-list-ctr-modes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssh-incCtr.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssl-suite-blocksizes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-tpm.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-via-aes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-fix-ssh-ecc-ephemeral.patch $(3RDP_ROOT)$(DIRSEP)/build/cl-just-use-cc.patch $(3RDP_ROOT)$(DIRSEP)/build/cl-learn-numbers.patch | $(CRYPT_SRC) $(CRYPT_IDIR) ++$(CRYPTLIB_BUILD): $(3RDP_ROOT)$(DIRSEP)dist/cryptlib.zip $(3RDP_ROOT)$(DIRSEP)build/terminal-params.patch $(3RDP_ROOT)$(DIRSEP)build/cl-mingw32-static.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ranlib.patch $(3RDP_ROOT)$(DIRSEP)build/cl-win32-noasm.patch $(3RDP_ROOT)$(DIRSEP)build/cl-zz-country.patch $(3RDP_ROOT)$(DIRSEP)build/cl-algorithms.patch $(3RDP_ROOT)$(DIRSEP)build/cl-allow-duplicate-ext.patch $(3RDP_ROOT)$(DIRSEP)build/cl-macosx-minver.patch $(3RDP_ROOT)$(DIRSEP)build/cl-endian.patch $(3RDP_ROOT)$(DIRSEP)build/cl-cryptodev.patch $(3RDP_ROOT)$(DIRSEP)build/cl-posix-me-gently.patch $(3RDP_ROOT)$(DIRSEP)build/cl-tpm-linux.patch $(3RDP_ROOT)$(DIRSEP)build/cl-PAM-noprompts.patch $(3RDP_ROOT)$(DIRSEP)build/cl-zlib.patch $(3RDP_ROOT)$(DIRSEP)build/Dynamic-linked-static-lib.patch $(3RDP_ROOT)$(DIRSEP)build/SSL-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-bigger-maxattribute.patch $(3RDP_ROOT)$(DIRSEP)build/cl-vcxproj.patch $(3RDP_ROOT)$(DIRSEP)build/cl-mingw-vcver.patch $(3RDP_ROOT)$(DIRSEP)build/cl-win32-build-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-gcc-non-const-time-val.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-odbc.patch $(3RDP_ROOT)$(DIRSEP)build/cl-noasm-defines.patch $(3RDP_ROOT)$(DIRSEP)build/cl-bn-noasm64-fix.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-RSA-suites.patch $(3RDP_ROOT)$(DIRSEP)build/cl-fix-ECC-RSA.patch $(3RDP_ROOT)$(DIRSEP)build/cl-prefer-ECC.patch $(3RDP_ROOT)$(DIRSEP)build/cl-prefer-ECC-harder.patch $(3RDP_ROOT)$(DIRSEP)build/cl-more-RSA-ECC-fixes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-DH-key-init.patch $(3RDP_ROOT)$(DIRSEP)build/cl-clear-GCM-flag.patch $(3RDP_ROOT)$(DIRSEP)build/cl-use-ssh-ctr.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssh-list-ctr-modes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssh-incCtr.patch $(3RDP_ROOT)$(DIRSEP)build/cl-ssl-suite-blocksizes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-tpm.patch $(3RDP_ROOT)$(DIRSEP)build/cl-no-via-aes.patch $(3RDP_ROOT)$(DIRSEP)build/cl-fix-ssh-ecc-ephemeral.patch $(3RDP_ROOT)$(DIRSEP)/build/cl-just-use-cc.patch $(3RDP_ROOT)$(DIRSEP)/build/cl-learn-numbers.patch $(3RDP_ROOT)/build/cl-linux-yield.patch | $(CRYPT_SRC) $(CRYPT_IDIR) + @echo Creating $@ ... + $(QUIET)-rm -rf $(CRYPT_SRC)/* + $(QUIET)unzip -oa $(3RDPDISTDIR)$(DIRSEP)cryptlib.zip -d $(CRYPT_SRC) +@@ -112,6 +112,7 @@ + $(QUIET)patch -p0 -d $(CRYPT_SRC) < cl-fix-ssh-ecc-ephemeral.patch + $(QUIET)patch -p0 -d $(CRYPT_SRC) < cl-just-use-cc.patch + $(QUIET)patch -p0 -d $(CRYPT_SRC) < cl-learn-numbers.patch ++ $(QUIET)patch -p0 -d $(CRYPT_SRC) < cl-linux-yield.patch + ifeq ($(CC),mingw32-gcc) + $(QUIET)cd $(CRYPT_SRC) && env - PATH="$(PATH)" CC="$(CC)" AR="$(AR)" RANLIB="$(RANLIB)" make directories + $(QUIET)cd $(CRYPT_SRC) && env - PATH="$(PATH)" CC="$(CC)" AR="$(AR)" RANLIB="$(RANLIB)" make toolscripts +diff --git a/3rdp/build/cl-linux-yield.patch b/3rdp/build/cl-linux-yield.patch +new file mode 100644 +index 0000000000000000000000000000000000000000..8cdfc8eafd3fd85f39bf0f8b519f25a31078fee4 +--- /dev/null ++++ b/3rdp/build/cl-linux-yield.patch +@@ -0,0 +1,11 @@ ++--- old/thread.h 2021-10-19 12:34:08.766649958 -0700 +++++ kernel/thread.h 2021-10-19 12:34:43.794072316 -0700 ++@@ -3005,7 +3005,7 @@ ++ #endif /* Slowaris 5.7 / 7.x or newer */ ++ #elif defined( _AIX ) || defined( __Android__ ) || defined( __CYGWIN__ ) || \ ++ ( defined( __hpux ) && ( OSVERSION >= 11 ) ) || \ ++- defined( __NetBSD__ ) || defined( __QNX__ ) || defined( __UCLIBC__ ) +++ defined( __NetBSD__ ) || defined( __QNX__ ) || defined( __UCLIBC__ ) || defined(__linux__) ++ #define THREAD_YIELD() sched_yield() ++ #elif defined( __XMK__ ) ++ /* The XMK underlying scheduling object is the process context, for which diff --git a/pkgs/applications/terminal-emulators/syncterm/default.nix b/pkgs/applications/terminal-emulators/syncterm/default.nix index 59e0b3a735e0..05e521b24a32 100644 --- a/pkgs/applications/terminal-emulators/syncterm/default.nix +++ b/pkgs/applications/terminal-emulators/syncterm/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, pkg-config, perl, unzip, autoPatchelfHook, ncurses, SDL2, alsa-lib }: +{ lib, stdenv, fetchurl, fetchpatch, pkg-config, perl, unzip, autoPatchelfHook, ncurses, SDL2, alsa-lib }: stdenv.mkDerivation rec { pname = "syncterm"; @@ -8,7 +8,18 @@ stdenv.mkDerivation rec { url = "mirror://sourceforge/${pname}/${pname}-${version}-src.tgz"; sha256 = "19m76bisipp1h3bc8mbq83b851rx3lbysxb0azpbr5nbqr2f8xyi"; }; - sourceRoot = "${pname}-${version}/src/syncterm"; + + patches = [ + # Cherry-picks from the upstream Synchronet tree, removing calls to `pthread_yield`. + # See upstream issue: https://gitlab.synchro.net/main/sbbs/-/issues/299 + (fetchpatch { + url = "https://gitlab.synchro.net/main/sbbs/-/commit/851627df99f48d8eaad33d3a98ef309b4371f359.patch"; + hash = "sha256-DbFAeJnrwFyfEpZgZFN8etqX6vQ3ca2TJwaqp0aHeo4="; + }) + ./0001-use-sched-yield-53264f2b.patch + ]; + # We can't use sourceRoot, as the cherry-picked patches apply to files outside of it. + postPatch = ''cd src/syncterm''; CFLAGS = [ "-DHAS_INTTYPES_H" @@ -32,8 +43,7 @@ stdenv.mkDerivation rec { meta = with lib; { # error: unsupported option '-fsanitize=safe-stack' for target 'x86_64-apple-darwin' - # broken = (stdenv.isLinux && stdenv.isAarch64) || stdenv.isDarwin; - broken = true; # sendmsg.c:(.text+0x1099): undefined reference to `pthread_yield' + broken = (stdenv.isLinux && stdenv.isAarch64) || stdenv.isDarwin; homepage = "https://syncterm.bbsdev.net/"; description = "BBS terminal emulator"; maintainers = with maintainers; [ embr ];