Unverified Commit 78442918 authored by Emily's avatar Emily Committed by GitHub
Browse files

[staging-next] systemd: new musl patchset for 258 (#451274)

parents c1956e94 4b1c77fd
Loading
Loading
Loading
Loading
+34 −49
Original line number Diff line number Diff line
@@ -262,55 +262,39 @@ stdenv.mkDerivation (finalAttrs: {
  ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isGnu) [
    ./0020-timesyncd-disable-NSCD-when-DNSSEC-validation-is-dis.patch
  ]
  ++ lib.optionals stdenv.hostPlatform.isMusl (
    let
      # NOTE: the master-next branch does not have stable URLs.
      # If we need patches that aren't in master yet, they'll have to be
      # vendored.
      oe-core = fetchzip {
        url = "https://git.openembedded.org/openembedded-core/snapshot/openembedded-core-4891f47cdaf919033bf1c02cc12e4805e5db99a0.tar.gz";
        hash = "sha256-YKL/oC+rPZ2EEVNidEV+pJihZgUv7vLb0OASplgktn4=";
      };
    in
    map (patch: "${oe-core}/meta/recipes-core/systemd/systemd/${patch}") [
      "0003-missing_type.h-add-comparison_fn_t.patch"
      "0004-add-fallback-parse_printf_format-implementation.patch"
      "0005-don-t-fail-if-GLOB_BRACE-and-GLOB_ALTDIRFUNC-is-not-.patch"
      "0006-add-missing-FTW_-macros-for-musl.patch"
      "0007-Use-uintmax_t-for-handling-rlim_t.patch"
      "0008-Define-glibc-compatible-basename-for-non-glibc-syste.patch"
      "0009-Do-not-disable-buffering-when-writing-to-oom_score_a.patch"
      "0010-distinguish-XSI-compliant-strerror_r-from-GNU-specif.patch"
      "0011-avoid-redefinition-of-prctl_mm_map-structure.patch"
      "0012-do-not-disable-buffer-in-writing-files.patch"
      "0013-Handle-__cpu_mask-usage.patch"
      "0014-Handle-missing-gshadow.patch"
      "0015-missing_syscall.h-Define-MIPS-ABI-defines-for-musl.patch"
      "0016-pass-correct-parameters-to-getdents64.patch"
      "0017-Adjust-for-musl-headers.patch"
      "0018-test-bus-error-strerror-is-assumed-to-be-GNU-specifi.patch"
      "0019-errno-util-Make-STRERROR-portable-for-musl.patch"
      "0020-sd-event-Make-malloc_trim-conditional-on-glibc.patch"
      "0021-shared-Do-not-use-malloc_info-on-musl.patch"
      "0022-avoid-missing-LOCK_EX-declaration.patch"
      "0023-include-signal.h-to-avoid-the-undeclared-error.patch"
      "0024-undef-stdin-for-references-using-stdin-as-a-struct-m.patch"
      "0025-adjust-header-inclusion-order-to-avoid-redeclaration.patch"
      "0026-build-path.c-avoid-boot-time-segfault-for-musl.patch"
    ]
    ++ [
      # add a missing include
      (fetchpatch {
        url = "https://github.com/systemd/systemd/commit/34fcd3638817060c79e1186b370e46d9b3a7409f.patch";
        hash = "sha256-Uaewo3jPrZGJttlLcqO6cCj1w3IGZmvbur4+TBdIPxc=";
        excludes = [ "src/udev/udevd.c" ];
      })
      (fetchpatch {
        url = "https://gitlab.postmarketos.org/postmarketOS/systemd/-/commit/5760be33bd26d7e7c66a7294c5f6fd6c7044683f.patch";
        hash = "sha256-Om+OhGyZJfZNpbtMInm3vGagLbbtOY71fDMZXj6pbPY=";
      })
    ]
  );
  ++ lib.optionals stdenv.hostPlatform.isMusl [
    # Patchset to build with musl by an upstream systemd contributor:
    # https://github.com/systemd/systemd/pull/37788
    # This is vendored here because of the lack of permanent patch urls for the unmerged PR
    ./musl/0001-musl-meson-allow-to-choose-libc-implementation.patch
    ./musl/0002-musl-meson-do-not-use-libcrypt-libxcrypt.patch
    ./musl/0003-musl-meson-explicitly-link-with-libintl-when-necessa.patch
    ./musl/0004-musl-meson-explicitly-set-_LARGEFILE64_SOURCE.patch
    ./musl/0005-musl-meson-make-musl-not-define-wchar_t-in-their-hea.patch
    ./musl/0006-musl-meson-check-existence-of-renameat2.patch
    ./musl/0007-musl-meson-gracefully-disable-gshadow-idn-nss-and-ut.patch
    ./musl/0008-musl-introduce-dummy-gshadow-header-file-for-userdb.patch
    ./musl/0009-musl-add-fallback-parse_printf_format-implementation.patch
    ./musl/0010-musl-introduce-GNU-specific-version-of-strerror_r.patch
    ./musl/0011-musl-make-strptime-accept-z.patch
    ./musl/0012-musl-make-strtoll-accept-strings-start-with-dot.patch
    ./musl/0013-musl-introduce-strerrorname_np.patch
    ./musl/0014-musl-introduce-dummy-functions-for-mallinfo-malloc_i.patch
    ./musl/0015-musl-introduce-dummy-function-for-gnu_get_libc_versi.patch
    ./musl/0016-musl-define-__THROW-when-not-defined.patch
    ./musl/0017-musl-replace-sys-prctl.h-with-our-own-implementation.patch
    ./musl/0018-musl-replace-netinet-if_ether.h-with-our-own-impleme.patch
    ./musl/0019-musl-add-missing-FTW_CONTINUE-macro.patch
    ./musl/0020-musl-add-several-missing-statx-macros.patch
    ./musl/0021-musl-avoid-conflict-between-fcntl.h-and-our-forward..patch
    ./musl/0022-musl-redefine-HOST_NAME_MAX-as-64.patch
    ./musl/0023-musl-avoid-multiple-evaluations-in-CPU_ISSET_S-macro.patch
    ./musl/0024-musl-core-there-is-one-less-usable-signal-when-built.patch
    ./musl/0025-musl-build-path-fix-reading-DT_RUNPATH-or-DT_RPATH.patch
    ./musl/0026-musl-format-util-use-llu-for-formatting-rlim_t.patch
    ./musl/0027-musl-time-util-skip-tm.tm_wday-check.patch
    ./musl/0028-musl-glob-util-filter-out-.-and-.-even-if-GLOB_ALTDI.patch
  ];

  postPatch = ''
    substituteInPlace src/basic/path-util.h --replace "@defaultPathNormal@" "${placeholder "out"}/bin/"
@@ -622,6 +606,7 @@ stdenv.mkDerivation (finalAttrs: {
    (lib.mesonOption "zshcompletiondir" "no")
  ]
  ++ lib.optionals stdenv.hostPlatform.isMusl [
    (lib.mesonOption "libc" "musl")
    (lib.mesonBool "gshadow" false)
    (lib.mesonBool "idn" false)
  ];
+96 −0
Original line number Diff line number Diff line
From 0e2b9909fed24a682c8566f9df8bbac4e9347186 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 7 Jul 2025 14:11:19 +0900
Subject: [PATCH 01/30] musl: meson: allow to choose libc implementation

This also introduces skelton directories for storing musl specific code.
---
 meson.build               | 17 +++++++++++++++--
 meson_options.txt         |  2 ++
 src/libc/meson.build      |  2 ++
 src/libc/musl/meson.build |  5 +++++
 4 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 src/libc/musl/meson.build

diff --git a/meson.build b/meson.build
index 238b935372..bea62f0eb6 100644
--- a/meson.build
+++ b/meson.build
@@ -72,7 +72,10 @@ conf.set10('SD_BOOT', false)
 
 # Create a title-less summary section early, so it ends up first in the output.
 # More items are added later after they have been detected.
-summary({'build mode' : get_option('mode')})
+summary({
+        'libc'       : get_option('libc'),
+        'build mode' : get_option('mode'),
+})
 
 #####################################################################
 
@@ -2042,7 +2045,14 @@ dbus_programs = []
 boot_stubs = []
 
 # This is similar to system_includes below, but for passing custom_target().
-system_include_args = [
+system_include_args = []
+if get_option('libc') == 'musl'
+        system_include_args += [
+                '-isystem', meson.project_build_root()  / 'src/include/musl',
+                '-isystem', meson.project_source_root() / 'src/include/musl',
+        ]
+endif
+system_include_args += [
         '-isystem', meson.project_build_root()  / 'src/include/override',
         '-isystem', meson.project_source_root() / 'src/include/override',
         '-isystem', meson.project_build_root()  / 'src/include/uapi',
@@ -2060,6 +2070,9 @@ system_includes = [
                 is_system : true,
         ),
 ]
+if get_option('libc') == 'musl'
+        system_includes += include_directories('src/include/musl', is_system : true)
+endif
 
 basic_includes = [
         include_directories(
diff --git a/meson_options.txt b/meson_options.txt
index d8dec33ec4..ad203ba301 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -397,6 +397,8 @@ option('ima', type : 'boolean',
 option('ipe', type : 'boolean',
        description : 'IPE support')
 
+option('libc', type : 'combo', choices : ['glibc', 'musl'],
+       description : 'libc implementation to be used')
 option('acl', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' },
        description : 'libacl support')
 option('audit', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' },
diff --git a/src/libc/meson.build b/src/libc/meson.build
index eeee98c9d6..306512ffd7 100644
--- a/src/libc/meson.build
+++ b/src/libc/meson.build
@@ -16,6 +16,8 @@ libc_wrapper_sources = files(
         'xattr.c',
 )
 
+subdir('musl')
+
 sources += libc_wrapper_sources
 
 libc_wrapper_static = static_library(
diff --git a/src/libc/musl/meson.build b/src/libc/musl/meson.build
new file mode 100644
index 0000000000..a876230c67
--- /dev/null
+++ b/src/libc/musl/meson.build
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+if get_option('libc') != 'musl'
+        subdir_done()
+endif
-- 
2.51.0
+38 −0
Original line number Diff line number Diff line
From 03010a0716f509b448c84a35bc2723a6f08e0c09 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 23 Jul 2025 10:24:14 +0900
Subject: [PATCH 02/30] musl: meson: do not use libcrypt/libxcrypt

Otherwise, when both glibc and musl are installed, libxcrypt or glibc's
libcrypt may be picked even when we are building systemd with musl.
Let's not use libcrypt/libxcrypt in that case.
---
 meson.build | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/meson.build b/meson.build
index bea62f0eb6..06be36409f 100644
--- a/meson.build
+++ b/meson.build
@@ -1013,10 +1013,14 @@ else
         libatomic = []
 endif
 
-libcrypt = dependency('libcrypt', 'libxcrypt', required : false)
-if not libcrypt.found()
-        # fallback to use find_library() if libcrypt is provided by glibc, e.g. for LibreELEC.
-        libcrypt = cc.find_library('crypt')
+if get_option('libc') == 'musl'
+        libcrypt = []
+else
+        libcrypt = dependency('libcrypt', 'libxcrypt', required : false)
+        if not libcrypt.found()
+                # fallback to use find_library() if libcrypt is provided by glibc, e.g. for LibreELEC.
+                libcrypt = cc.find_library('crypt')
+        endif
 endif
 
 foreach func : [
-- 
2.51.0
+56 −0
Original line number Diff line number Diff line
From bf4cb5aeeef23c5f12e6d2258bb8f3d12059f59f Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sat, 6 Sep 2025 16:25:41 +0900
Subject: [PATCH 03/30] musl: meson: explicitly link with libintl when
 necessary

On some musl based distributions provides dgettext() by libintl.so.
Hence, we need to add dependency in that case.
---
 meson.build          | 17 +++++++++++++++++
 src/home/meson.build |  1 +
 2 files changed, 18 insertions(+)

diff --git a/meson.build b/meson.build
index 06be36409f..054752c339 100644
--- a/meson.build
+++ b/meson.build
@@ -1002,6 +1002,23 @@ libm = cc.find_library('m')
 libdl = cc.find_library('dl')
 libcap = dependency('libcap')
 
+# On some distributions that uses musl (e.g. Alpine), libintl.h may be provided by gettext rather than musl.
+# In that case, we need to explicitly link with libintl.so.
+if get_option('libc') == 'musl'
+        if cc.has_function('dgettext', prefix : '''#include <libintl.h>''', args : '-D_GNU_SOURCE')
+                libintl = []
+        else
+                libintl = cc.find_library('intl')
+                if not cc.has_function('dgettext', prefix : '''#include <libintl.h>''', args : '-D_GNU_SOURCE',
+                                       dependencies : libintl)
+                        error('dgettext() not found.')
+                endif
+        endif
+else
+        # When building with glibc, we assume that libintl.h is provided by glibc.
+        libintl = []
+endif
+
 # On some architectures, libatomic is required. But on some installations,
 # it is found, but actual linking fails. So let's try to use it opportunistically.
 # If it is installed, but not needed, it will be dropped because of --as-needed.
diff --git a/src/home/meson.build b/src/home/meson.build
index 1937e6f56c..3305334707 100644
--- a/src/home/meson.build
+++ b/src/home/meson.build
@@ -115,6 +115,7 @@ modules += [
                 'sources' : pam_systemd_home_sources,
                 'dependencies' : [
                         libcrypt,
+                        libintl,
                         libpam_misc,
                         libpam,
                         threads,
-- 
2.51.0
+32 −0
Original line number Diff line number Diff line
From 59f993d1acb069f3f2b7d6c71b91696388692702 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 10 Jun 2025 00:29:46 +0900
Subject: [PATCH 04/30] musl: meson: explicitly set _LARGEFILE64_SOURCE

glibc sets it when _GNU_SOURCE is defined, however, musl does not.
Let's explicitly define it to make getdents64() and struct dirent64
available even when building with musl.
---
 meson.build | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/meson.build b/meson.build
index 054752c339..37fb1c2765 100644
--- a/meson.build
+++ b/meson.build
@@ -560,6 +560,12 @@ conf.set10('HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT', have)
 conf.set('_GNU_SOURCE', 1)
 conf.set('__SANE_USERSPACE_TYPES__', true)
 
+if get_option('libc') == 'musl'
+        # glibc always defines _LARGEFILE64_SOURCE when _GNU_SOURCE is set, but musl does not do that,
+        # and it is necessary for making getdents64() and struct dirent64 exist.
+        conf.set('_LARGEFILE64_SOURCE', 1)
+endif
+
 conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include <sys/types.h>'))
 conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include <sys/types.h>'))
 conf.set('SIZEOF_RLIM_T', cc.sizeof('rlim_t', prefix : '#include <sys/resource.h>'))
-- 
2.51.0
Loading