From ddd46d4ba47b0604ece6510849d03a638249fa98 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Sat, 19 Jul 2025 11:06:09 +0300 Subject: [PATCH] initial import from Debian version 1.2.5-3 --- debian/changelog | 460 ++++++ debian/clean | 5 + debian/control | 73 + debian/copyright | 287 ++++ debian/docs | 1 + debian/gbp.conf | 2 + debian/man/ld-musl-config.8 | 33 + debian/man/musl-gcc.1 | 34 + debian/man/musl-ldd.1 | 20 + debian/musl-dev.install | 3 + debian/musl-dev.lintian-overrides | 14 + debian/musl-dev.postinst.in | 10 + debian/musl-dev.postrm.in | 10 + debian/musl-fts/config.h | 2 + debian/musl-fts/fts.c | 1255 +++++++++++++++++ debian/musl-fts/fts.h | 155 ++ debian/musl-tools.links | 2 + debian/musl-tools.manpages | 2 + debian/musl.install | 4 + debian/musl.links | 1 + debian/musl.lintian-overrides | 11 + debian/musl.manpages | 1 + debian/not-installed | 1 + ...ous_input_validation_in_EUC_KR_decod.patch | 39 + ..._8_output_code_path_against_input_de.patch | 39 + debian/patches/renameat2.patch | 57 + debian/patches/series | 4 + debian/patches/static-pie.patch | 99 ++ debian/rules | 99 ++ debian/scripts/config.path.in | 2 + debian/scripts/ld-musl-config | 15 + debian/source/format | 1 + debian/tests/build | 64 + debian/tests/control | 2 + debian/upstream/metadata | 6 + debian/upstream/signing-key.asc | 30 + debian/watch | 3 + 37 files changed, 2846 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/clean create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/docs create mode 100644 debian/gbp.conf create mode 100644 debian/man/ld-musl-config.8 create mode 100644 debian/man/musl-gcc.1 create mode 100644 debian/man/musl-ldd.1 create mode 100644 debian/musl-dev.install create mode 100644 debian/musl-dev.lintian-overrides create mode 100644 debian/musl-dev.postinst.in create mode 100644 debian/musl-dev.postrm.in create mode 100644 debian/musl-fts/config.h create mode 100644 debian/musl-fts/fts.c create mode 100644 debian/musl-fts/fts.h create mode 100644 debian/musl-tools.links create mode 100644 debian/musl-tools.manpages create mode 100644 debian/musl.install create mode 100644 debian/musl.links create mode 100644 debian/musl.lintian-overrides create mode 100644 debian/musl.manpages create mode 100644 debian/not-installed create mode 100644 debian/patches/CVE-2025-26519-0001_iconv_fix_erroneous_input_validation_in_EUC_KR_decod.patch create mode 100644 debian/patches/CVE-2025-26519-0002_iconv_harden_UTF_8_output_code_path_against_input_de.patch create mode 100644 debian/patches/renameat2.patch create mode 100644 debian/patches/series create mode 100644 debian/patches/static-pie.patch create mode 100755 debian/rules create mode 100644 debian/scripts/config.path.in create mode 100755 debian/scripts/ld-musl-config create mode 100644 debian/source/format create mode 100644 debian/tests/build create mode 100644 debian/tests/control create mode 100644 debian/upstream/metadata create mode 100644 debian/upstream/signing-key.asc create mode 100644 debian/watch diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..43e22a3 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,460 @@ +musl (1.2.5-3) unstable; urgency=medium + + * Provide renameat2 syscall wrapper. (Closes: #1105007) + * Bump copyright year. + * Bump Standards-Version to 4.7.2. + + -- Reiner Herrmann Sat, 17 May 2025 13:21:34 +0200 + +musl (1.2.5-2) unstable; urgency=medium + + * Import upstream fix for out-of-bounds write vulnerability. (CVE-2025-26519) + (Closes: #1098238) + * Bump Standards-Version to 4.7.1. + + -- Reiner Herrmann Sat, 22 Feb 2025 12:21:36 +0100 + +musl (1.2.5-1.1) unstable; urgency=medium + + * Non-maintainer upload. + * Install ld-musl-*so* and libc.so into /usr (DEP17 M2). (Closes: #1073676) + + -- Chris Hofstaedtler Tue, 13 Aug 2024 20:37:19 +0200 + +musl (1.2.5-1) unstable; urgency=medium + + * New upstream release. + * New supported architecture: loong64. + * Fix watch file. + + -- Reiner Herrmann Mon, 25 Mar 2024 20:14:54 +0100 + +musl (1.2.4-2) unstable; urgency=medium + + * Fix typo in autopkgtest. + + -- Reiner Herrmann Fri, 10 Nov 2023 20:30:40 +0100 + +musl (1.2.4-1) unstable; urgency=medium + + [ Reiner Herrmann ] + * New upstream release. + * Set option to disable building with LTO, as it is not supported. + (Closes: #1015552) + * Stop recommending non-existing linux-musl-dev. (Closes: #1041559) + * Apply patch from Harald Hoyer to allow linking with static-pie. + (Closes: #996326) + * Add autopkgtest for static-pie linking. + * Update lintian overrides to new format. + * Bump Standards-Version to 4.6.2. + + [ Helmut Grohne ] + * Restore crypt functionality in libc.{a,so} for ABI compatibility. + (Closes: #1022027) + + -- Reiner Herrmann Thu, 09 Nov 2023 23:26:24 +0100 + +musl (1.2.3-1) unstable; urgency=medium + + * New upstream release. + * Add lintian override for 'no-code-sections' as these libraries are + intentionally empty. + + -- Reiner Herrmann Thu, 07 Apr 2022 22:48:37 +0200 + +musl (1.2.2-4) unstable; urgency=medium + + * Import musl-fts. (Closes: #989746) + - musl-dev provides musl-fts + - document copyright + - test compilation in autopkgtest + * Revert "Point to experimental branch in Vcs-Git". + * Bump Standards-Version to 4.6.0. + + -- Reiner Herrmann Sat, 21 Aug 2021 12:49:23 +0200 + +musl (1.2.2-3) experimental; urgency=medium + + * musl-dev on musl-any-any: + - drop gcc dependency, which does not exist while bootstrapping + - don't install musl-gcc wrapper, which is not useful on this arch + + -- Reiner Herrmann Fri, 30 Apr 2021 00:26:14 +0200 + +musl (1.2.2-2) experimental; urgency=medium + + [ Helmut Grohne ] + * Remove crypt functionality and drop crypt.h header. (Closes: #947193) + + [ Josh Triplett ] + * Provide cross-compilation versions of musl-gcc. (Closes: #873364) + + [ Reiner Herrmann ] + * Add Breaks and Replaces to musl-dev, as it has taken over specs file. + * Replace override_dh_clean with d/clean. + * Drop usage of dh-exec. + Thanks to Nicolas Boulenguez for initial idea, Niels Thykier for hint + about debhelper's built-in substitution. (Closes: #982782) + * wrap-and-sort + * Point to experimental branch in Vcs-Git. + + -- Reiner Herrmann Thu, 29 Apr 2021 19:26:09 +0200 + +musl (1.2.2-1) unstable; urgency=medium + + * New upstream release. + - fix wcsnrtombs destination buffer overflow (CVE-2020-28928) + (Closes: #975365) + * Fix MUSL_ARCH/MUSL_TRIPLE on sh4 (-> sh). (Closes: #977130) + * Update copyrights. + * Update watch file to version 4. + * Bump Standards-Version to 4.5.1. + + -- Reiner Herrmann Fri, 15 Jan 2021 19:03:01 +0100 + +musl (1.2.1-1) unstable; urgency=medium + + * New upstream release. + - new malloc implementation (mallocng) + * Update copyrights, bump copyright years and reorder sections. + + -- Reiner Herrmann Tue, 04 Aug 2020 20:05:24 +0200 + +musl (1.2.0-1) unstable; urgency=medium + + * New upstream release. + - 64-bit time_t on all archs + * Update upstream homepage. + * Bump Standards-Version to 4.5.0. + * Bump debhelper compat level to 13. + * Update lintian-overrides with changed tag name. + * Update Vcs-* URLs. + + -- Reiner Herrmann Fri, 03 Jul 2020 20:38:19 +0200 + +musl (1.1.24-1) unstable; urgency=medium + + * New upstream release. + - drop cherry-picked patch + * Bump Standards-Version to 4.4.1. + + -- Reiner Herrmann Mon, 14 Oct 2019 00:56:01 +0200 + +musl (1.1.23-2) unstable; urgency=high + + * Cherry-pick patch to fix x87 stack imbalance in corner cases of + i386 math asm (CVE-2019-14697). + + -- Reiner Herrmann Tue, 06 Aug 2019 19:56:45 +0200 + +musl (1.1.23-1) unstable; urgency=medium + + * New upstream release. + * New supported architecture: riscv64 + * Revert "Point to experimental branch in Vcs-Git". + * Update debian/copyright. + * Bump Standards-Version to 4.4.0; no changes needed. + + -- Reiner Herrmann Wed, 17 Jul 2019 19:27:50 +0200 + +musl (1.1.22-1) experimental; urgency=medium + + * New upstream release. + * Point to experimental branch in Vcs-Git. + + -- Reiner Herrmann Thu, 11 Apr 2019 18:41:58 +0200 + +musl (1.1.21-2) unstable; urgency=medium + + * Revert "Install ld.so symlink with dh_install instead of dh_link". + The upstream symlink was pointing to /usr/lib/${TRIPLE}/libc.so, which + is part of a different package (musl-dev). + * Add /lib/ld-musl-*.so.1 symlink to debian/not-installed, to tell + dh_missing that it is deliberately not installed. + + -- Reiner Herrmann Wed, 23 Jan 2019 20:32:39 +0100 + +musl (1.1.21-1) unstable; urgency=medium + + * New upstream release. + * Bump Standards-Version to 4.3.0. + * Depend on debhelper-compat and bump compat level to 12. + * Install ld.so symlink with dh_install instead of dh_link. + dh_missing was confused by symlink that was also installed by + upstream Makefile. + * Declare that debian/rules does not require root. + * Update debian/copyright and bump years. + + -- Reiner Herrmann Tue, 22 Jan 2019 20:23:18 +0100 + +musl (1.1.20-1) unstable; urgency=medium + + * New upstream release. + * New supported architecture: m68k + * Bump Standards-Version to 4.2.1. + * Drop patch for working around binutils static linking bug. + binutils fix is included in 2.31.1-2 (with a follow up in 2.31.1-3). + * Drop patch with musl-gcc workaround for linking with default-pie + toolchains, as the upstream specs file now includes a better solution. + + -- Reiner Herrmann Tue, 04 Sep 2018 22:31:55 +0200 + +musl (1.1.19-2) unstable; urgency=medium + + * Workaround binutils 2.31 bug that broke static linking. + Thanks to Szabolcs Nagy for the analysis and workaround. + * Bump Standards-Version to 4.1.5. + * Add binutils to test dependencies to trigger autopkgtest runs when + they are updated. + + -- Reiner Herrmann Thu, 19 Jul 2018 18:52:03 +0200 + +musl (1.1.19-1) unstable; urgency=medium + + * New upstream release. + * Move packaging VCS to salsa. + * Bump Standards-Version to 4.1.3. + * Bump debhelper compat/dependency to 11. + * Fix spelling error found by lintian. + * Override lintian warning application-in-library-section for musl. + * Add upstream metadata file. + + -- Reiner Herrmann Sun, 25 Feb 2018 18:54:30 +0100 + +musl (1.1.18-1) unstable; urgency=medium + + * New upstream release. + * Drop patch applied upstream. + * Remove trailing whitespace in d/changelog and d/rules. + + -- Reiner Herrmann Tue, 31 Oct 2017 21:57:13 +0100 + +musl (1.1.17-2) unstable; urgency=medium + + * Fix build failure on armel because of unsupported instruction. + Thanks to Adrian Bunk for providing the patch. (Closes: #879190) + + -- Reiner Herrmann Fri, 20 Oct 2017 18:19:33 +0200 + +musl (1.1.17-1) unstable; urgency=high + + * New upstream release. + - Fixes security issue: buffer overflow in dns response parsing + (CVE-2017-15650) + * Drop patches applied upstream. + * Update Standards-Version to 4.1.1. + - change priority to optional + * Switch http URLs to https. + * Bump copyright years for 2017. + * Mark musl-dev as Multi-Arch: same (Closes: #873363) + - add lintian override for musl-specific directory unknown to lintian + + -- Reiner Herrmann Thu, 19 Oct 2017 23:08:39 +0200 + +musl (1.1.16-3) unstable; urgency=medium + + * Import upstream fix for PPC64 crash. + Thanks to Breno Leitao for investigating. (Closes: #857078) + + -- Reiner Herrmann Thu, 09 Mar 2017 19:19:31 +0100 + +musl (1.1.16-2) unstable; urgency=medium + + [ Breno Leitao ] + * Enable building on ppc64el. (Closes: #851686) + + [ Reiner Herrmann ] + * Fix build failure on armhf with newer binutils. (Closes: #852214) + + -- Reiner Herrmann Sun, 22 Jan 2017 18:18:26 +0100 + +musl (1.1.16-1) unstable; urgency=low + + * New upstream release. + * New supported architecture: s390x + * Remove patch cve-2016-8859.diff (applied upstream). + * Bump debhelper compatibility to 10. + - drop --parallel, which is now default. + * Use Debian buildflags and enable all hardening options. + * Remove ancient version restrictions on gcc and dh-exec. + * Disable PIE linking in musl-gcc wrapper to workaround linking issues + (Closes: #847776). + + -- Reiner Herrmann Tue, 03 Jan 2017 22:38:49 +0100 + +musl (1.1.15-2) unstable; urgency=high + + * Cherry-pick upstream fix for regex integer overflow in buffer size + computations; CVE-2016-8859 (Closes: #842171) + + -- Reiner Herrmann Thu, 27 Oct 2016 18:53:49 +0200 + +musl (1.1.15-1) unstable; urgency=low + + * New upstream release. + * New supported architectures: mips64el, sh4 + * debian/control: + - Adopt package, update maintainer. (Closes: #830176) + - Remove unneeded XS-Testsuite field + - Change Vcs-* fields to point to collab-maint. + - Bump Standards-Version to 3.9.8. + * Add upstream's signing key. + * Check PGP signature when importing upstream releases. + * Move musl-ldd symlink from musl to musl-tools. (Closes: #803577) + * Drop ARM thumb compatibility patch (applied upstream). + * Install upstream changelog. + * postinst/postrm: Set -e in body instead of shebang. + * Fix manpage typos found by lintian. + * Remove duplicate mdoc manpages. + * Build with debugging symbols to support dbgsym packages. + * Update copyrights; remove trailing whitespace. + * Amend autopkgtest to test dynamic linking. + + -- Reiner Herrmann Fri, 08 Jul 2016 14:38:17 +0200 + +musl (1.1.9-1.2) unstable; urgency=medium + + * Non-maintainer upload. + * Always enable gcc wrapper, as it is no longer required for gcc6, + but is still useful for older gcc versions. (Closes: #812278) + + -- Reiner Herrmann Wed, 06 Jul 2016 21:07:23 +0200 + +musl (1.1.9-1.1) unstable; urgency=medium + + * Non-maintainer upload. + * Create /usr/lib/$MUSL_TRIPLE/libc.so in postinst to support merged /usr + systems. (Closes: #766812) + + -- Marco d'Itri Sat, 06 Feb 2016 01:12:33 +0100 + +musl (1.1.9-1) unstable; urgency=low + + [ Kevin Bortis ] + * Import upstream version 1.1.9 + * Provide linux-libc-dev on musl-linux-any + + [ Helmut Grohne ] + * Build musl for the corresponding musl-linux-any (Closes: #783078) + * Provide libc-dev on musl-linux-any + + -- Kevin Bortis Wed, 29 Apr 2015 18:16:36 +0200 + +musl (1.1.8-1~exp1) experimental; urgency=low + + * Import upstream version 1.1.8 + * Fixes possible stack-based buffer overflow CVE-2015-1817 + * Includes new aarch64 port + + -- Kevin Bortis Tue, 31 Mar 2015 19:49:20 +0200 + +musl (1.1.5-1) unstable; urgency=low + + [ Kevin Bortis ] + * Import upstream version 1.1.5 + * New library-level C11 support + + [ Anton Gladky ] + * Set Standards-Version: 3.9.6. No changes. + + -- Kevin Bortis Tue, 14 Oct 2014 21:13:35 +0200 + +musl (1.1.4-1) unstable; urgency=low + + * Import upstream version 1.1.4. (Closes: #754758) + * Fixes possible stack-based buffer overflow CVE-2014-3484 (Closes: #750815) + * Includes fix for build regression on armhf and armel + + -- Kevin Bortis Mon, 26 May 2014 22:45:52 +0200 + +musl (1.1.0-1) unstable; urgency=low + + [ Kevin Bortis ] + * Import upstream version 1.1.0 + + [ Anton Gladky ] + * Add autopkgtest according to DEP-8 + + -- Kevin Bortis Fri, 25 Apr 2014 19:49:40 +0000 + +musl (1.0.0-1) unstable; urgency=medium + + * Import upstream version 1.0.0 + * Provide musl-ldd (Closes: #732169) + * Arch independent ld-musl-config (Closes: #739205) + + -- Kevin Bortis Sat, 22 Mar 2014 09:39:56 +0100 + +musl (0.9.15-1) unstable; urgency=low + + * Import upstream version 0.9.15 + * Do no longer provide libc-dev (Closes: #725376) + * Make runtime package multi-arch (Closes: #732170) + + -- Kevin Bortis Sun, 05 Jan 2014 20:11:11 +0100 + +musl (0.9.14-2) unstable; urgency=low + + * Make musl-tools depend on musl-dev (Closes: #725060) + * Place each package in the correct section (Closes: #725148) + + -- Kevin Bortis Fri, 04 Oct 2013 21:45:54 +0200 + +musl (0.9.14-1) unstable; urgency=low + + * Import upstream version 0.9.14 + * Only build on fully supported architectures + * Point to new homepage in control file (Closes: #724277) + * Revorked debian/rules + * Solved possible problem with postrm script (Closes: #724247) + + -- Kevin Bortis Fri, 27 Sep 2013 23:47:18 +0200 + +musl (0.9.13-3) unstable; urgency=low + + * Ready for Debian upload (Closes: #713072) + * Respect user set CC + * Reworked package according to feedback given + by Anton Gladky. See #721839 for reference. + * Reworked debian/copyright file according to + feedback given by Paul Richards Tagliamonte + + -- Kevin Bortis Fri, 20 Sep 2013 20:54:14 +0200 + +musl (0.9.13-2) unstable; urgency=low + + * Added preliminary manpages for ld-musl-config and musl-gcc + + -- Kevin Bortis Fri, 20 Sep 2013 19:20:33 +0200 + +musl (0.9.13-1) unstable; urgency=low + + * Import upstream version 0.9.13 + + -- Kevin Bortis Sun, 01 Sep 2013 22:20:46 +0200 + +musl (0.9.12-2) unstable; urgency=low + + * Corrected lintian error "description-starts-with-package-name" + * Corrected lintian warning "shared-lib-without-dependency-information" + + -- Kevin Bortis Fri, 02 Aug 2013 15:22:17 +0200 + +musl (0.9.12-1) unstable; urgency=low + + * Import upstream version 0.9.12 + * New LDSO_PATHNAME for armhf (/etc/ld-musl-armhf.path) + + -- Kevin Bortis Mon, 29 Jul 2013 15:46:21 +0000 + +musl (0.9.11-1) unstable; urgency=low + + * Import upstream version 0.9.11 + + -- Kevin Bortis Sun, 30 Jun 2013 18:16:00 +0200 + +musl (0.9.10-1) unstable; urgency=low + + * Initial release (Closes: #713072) + + -- Kevin Bortis Fri, 21 Jun 2013 17:12:20 +0200 diff --git a/debian/clean b/debian/clean new file mode 100644 index 0000000..610da96 --- /dev/null +++ b/debian/clean @@ -0,0 +1,5 @@ +debian/musl-dev.postinst +debian/musl-dev.postrm +debian/scripts/*.path +include/fts.h +src/fts/ diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..4f67778 --- /dev/null +++ b/debian/control @@ -0,0 +1,73 @@ +Source: musl +Section: libs +Priority: optional +Maintainer: Reiner Herrmann +Build-Depends: debhelper-compat (= 13), + gcc-aarch64-linux-gnu [arm64], + gcc-arm-linux-gnueabi [armel], + gcc-arm-linux-gnueabihf [armhf], + gcc-i686-linux-gnu [i386], + gcc-loongarch64-linux-gnu [loong64], + gcc-m68k-linux-gnu [m68k], + gcc-mips-linux-gnu [mips], + gcc-mips64el-linux-gnuabi64 [mips64el], + gcc-mipsel-linux-gnu [mipsel], + gcc-powerpc64le-linux-gnu [ppc64el], + gcc-riscv64-linux-gnu [riscv64], + gcc-s390x-linux-gnu [s390x], + gcc-sh4-linux-gnu [sh4], + gcc-x86-64-linux-gnu [amd64] +Standards-Version: 4.7.2 +Homepage: https://musl.libc.org/ +Vcs-Git: https://salsa.debian.org/reiner/musl.git +Vcs-Browser: https://salsa.debian.org/reiner/musl +Rules-Requires-Root: no + +Package: musl +Architecture: arm64 musl-linux-arm64 armel armhf musl-linux-armhf i386 musl-linux-i386 amd64 musl-linux-amd64 loong64 musl-linux-loong64 m68k musl-linux-m68k mips musl-linux-mips mipsel musl-linux-mipsel mips64el musl-linux-mips64el s390x musl-linux-s390x sh4 musl-linux-sh4 ppc64el musl-linux-ppc64el riscv64 musl-linux-riscv64 +Multi-Arch: same +Depends: ${misc:Depends} +Description: standard C library + musl is lightweight, fast, simple, free and strives + to be correct in the sense of standards-conformance + and safety. + . + This package contains the shared objects + +Package: musl-dev +Section: libdevel +Architecture: arm64 musl-linux-arm64 armel armhf musl-linux-armhf i386 musl-linux-i386 amd64 musl-linux-amd64 loong64 musl-linux-loong64 m68k musl-linux-m68k mips musl-linux-mips mipsel musl-linux-mipsel mips64el musl-linux-mips64el s390x musl-linux-s390x sh4 musl-linux-sh4 ppc64el musl-linux-ppc64el riscv64 musl-linux-riscv64 +Multi-Arch: same +Provides: ${libc-dev:Provides}, musl-fts +Depends: musl (= ${binary:Version}), + ${gcc:Depends}, + ${linux-libc-dev:Depends}, + ${misc:Depends} +Replaces: musl-tools (<< 1.2.2-2) +Breaks: musl-tools (<< 1.2.2-2) +Description: standard C library development files + musl is lightweight, fast, simple, free and strives + to be correct in the sense of standards-conformance + and safety. + . + This package contains the static linked libraries + and the include files. + . + This package also contains the specs file and gcc + wrapper script for cross-compilation. For the native + musl-gcc script, install the musl-tools package. + +Package: musl-tools +Section: devel +Architecture: amd64 arm64 armel armhf i386 loong64 m68k mips mips64el mipsel ppc64el riscv64 s390x sh4 +Depends: musl-dev (= ${binary:Version}), ${misc:Depends} +Replaces: musl (<< 1.1.15-1) +Breaks: musl (<< 1.1.15-1) +Description: standard C library tools + musl is lightweight, fast, simple, free and strives + to be correct in the sense of standards-conformance + and safety. + . + This package contains the musl-gcc wrapper script for + the native architecture, to make easy-to-deploy static + and minimal dynamically linked programs. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..d70b156 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,287 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: musl +Source: https://musl.libc.org/releases/ + +Files: * +Copyright: 2005-2020 Rich Felker + 2005-2020 Many other contributors +License: MIT + +Files: debian/* +Copyright: 2013-2015 Kevin Bortis + 2016-2025 Reiner Herrmann +License: MIT + +Files: arch/mips64/* + src/*/mips64/* +Copyright: 2016 Mahesh Bodapati + 2016 Jaydeep Patil + 2016 Imagination Technologies +License: MIT + +Files: arch/riscv64/* + src/*/riscv64/* +Copyright: Alex Suykov + Aric Belsito + Drew DeVault + Michael Clark + Michael Forney + Stefan O'Rear + Rich Felker +License: MIT + +Files: include/* + arch/*/bits/* + arch/*/crt_arch.h + crt/* + ldso/dlstart.c +Copyright: 2005-2014 Rich Felker +License: public-domain + In addition, permission is hereby granted for all public header files + (include/* and arch/*/bits/*) and crt files intended to be linked into + applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit + the copyright notice and permission notice otherwise required by the + license, and to use these files without any requirement of + attribution. These files include substantial contributions from: + . + Bobby Bingham + John Spencer + Nicholas J. Kain + Rich Felker + Richard Pennington + Stefan Kristiansson + Szabolcs Nagy + . + all of whom have explicitly granted such permission. + +Files: src/regex/reg* + src/regex/tre* +Copyright: 2001-2008 Ville Laurikari + 2012 Rich Felker +License: BSD-2-clause + +Files: src/math/tgammal.c + src/math/lgammal.c + src/math/powl.c + src/math/logl.c + src/math/log2l.c + src/math/log1pl.c + src/math/log10l.c + src/math/erfl.c + src/math/expm1l.c + src/math/expl.c + src/math/__polevll.c +Copyright: 2008 Stephen L. Moshier + 1993 Sun Microsystems, Inc. +License: ISC + +Files: src/math/fmal.c + src/math/fmaf.c + src/math/fma.c + src/math/exp2l.c +Copyright: 2005-2011 David Schultz + 1993 Sun Microsystems, Inc. +License: BSD-2-clause + +Files: src/math/tanf.c + src/math/tan.c + src/math/sinf.c + src/math/sincosf.c + src/math/sincos.c + src/math/sin.c + src/math/scalbf.c + src/math/scalb.c + src/math/log1pf.c + src/math/log1p.c + src/math/log10f.c + src/math/log10.c + src/math/lgammaf_r.c + src/math/lgamma_r.c + src/math/j*.c + src/math/expm1f.c + src/math/expm1.c + src/math/erf.c + src/math/erff.c + src/math/cosf.c + src/math/cos.c + src/math/cbrt*.c + src/math/atanl.c + src/math/atanf.c + src/math/atan2*.c + src/math/atan.c + src/math/asinl.c + src/math/asinf.c + src/math/asin.c + src/math/acosl.c + src/math/acosf.c + src/math/acos.c + src/math/__tan*.c + src/math/__sin*.c + src/math/__rem*.c + src/math/__cos*.c +Copyright: 1993, 2004 Sun Microsystems, Inc. + 2008, 2009-2011 Bruce D. Evans + 2008, 2009-2011 Steven G. Kargl + 2008, 2009-2011 David Schultz +License: permissive + Developed at SunPro, a Sun Microsystems, Inc. business. + Permission to use, copy, modify, and distribute this + software is freely granted, provided that this notice + is preserved. + +Files: src/math/logf.c + src/math/logf_data.* + src/math/log2.c + src/math/log2_data.* + src/math/log2f.c + src/math/log2f_data.* + src/math/log.c + src/math/log_data.* + src/math/exp.c + src/math/exp_data.* + src/math/exp2.c + src/math/expf.c + src/math/exp2f.c + src/math/exp2f_data.* + src/math/pow.c + src/math/pow_data.c + src/math/powf.c + src/math/powf_data.* + src/string/aarch64/* +Copyright: 2012-2018 Arm Limited. +License: MIT + +Files: src/crypt/crypt_blowfish.c +Copyright: 1998-2014 Solar Designer + 2012 Rich Felker +License: public-domain + Written by Solar Designer in 1998-2012. + No copyright is claimed, and the software is hereby placed in the public + domain. In case this attempt to disclaim copyright and place the software + in the public domain is deemed null and void, then the software is + Copyright (c) 1998-2012 Solar Designer and it is hereby released to the + general public under the following terms: + . + Redistribution and use in source and binary forms, with or without + modification, are permitted. + . + There's ABSOLUTELY NO WARRANTY, express or implied. + . + It is my intent that you should be able to use this on your system, + as part of a software package, or anywhere else to improve security, + ensure compatibility, or for any other purpose. I would appreciate + it if you give credit where it is due and keep your modifications in + the public domain as well, but I don't require that in order to let + you place this code and any modifications you make under a license + of your choice. + +Files: src/crypt/crypt_des.c +Copyright: 1994 David Burren + 2000,2002,2010,2012 Solar Designer + 2012 Rich Felker +License: BSD-3-clause + +Files: src/stdlib/qsort.c +Copyright: 2011 Valentin Ochs +License: MIT + +Files: src/setjmp/x32/longjmp.s + src/setjmp/x32/setjmp.s + src/setjmp/x86_64/longjmp.s + src/setjmp/x86_64/setjmp.s + src/thread/x32/__set_thread_area.s + src/thread/x32/__unmapself.s + src/thread/x86_64/__set_thread_area.s + src/thread/x86_64/__unmapself.s +Copyright: 2011-2012 Nicholas J. Kain +License: MIT + +Files: src/string/arm/memcpy.S +Copyright: 2008 The Android Open Source Project +License: BSD-2-clause + +Files: debian/musl-fts/fts.* +Copyright: 1989, 1990, 1993, 1994 The Regents of the University of California +License: BSD-3-clause +Comment: imported from https://github.com/void-linux/musl-fts tag v1.2.7 + +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +License: ISC + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + . + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +License: BSD-2-clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + . + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + . + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + . + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +License: BSD-3-clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the author nor the names of other contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + . + THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e845566 --- /dev/null +++ b/debian/docs @@ -0,0 +1 @@ +README diff --git a/debian/gbp.conf b/debian/gbp.conf new file mode 100644 index 0000000..13bb1a0 --- /dev/null +++ b/debian/gbp.conf @@ -0,0 +1,2 @@ +[DEFAULT] +debian-branch = debian/latest diff --git a/debian/man/ld-musl-config.8 b/debian/man/ld-musl-config.8 new file mode 100644 index 0000000..ac6cb13 --- /dev/null +++ b/debian/man/ld-musl-config.8 @@ -0,0 +1,33 @@ +.TH "ld-musl-config" "8" "September 17, 2013" "Linux" "System Manager's Manual" +.SH "NAME" +\fBld-musl-config\fP +\- configures musl dynamic linker path's +.SH "SYNOPSIS" +\fBld-musl-config\fP +.SH "DESCRIPTION" +\fBld-musl-config\fP +reads in all config files found under +\fI/etc/ld-musl-$ARCH.d,\fP +and creates a concatenated linker path config file in +.sp +\fI/etc/ld-musl-$ARCH.path\fP +This file will be used by the musl dynamic run-time linker. +.sp +Paths can either be separated with a newlines or with a ':' character. +.sp +ld-musl-config can be called at any time to regenerate the linker path config file. The previous config will be overwritten. +.SH "FILES" +.TP +\fI/etc/ld-musl-$ARCH.path\fP +Generated by +\fBld-musl-config\fP +and contains an ordered list of library path's. +.TP +\fI/etc/ld-musl-$ARCH.d/*\fP +Path config files to be read in by ld-musl-config. +.SH "AUTHORS" +Kevin Bortis . +.sp +\fBld-musl-config\fP +was written by +Kevin Bortis . diff --git a/debian/man/musl-gcc.1 b/debian/man/musl-gcc.1 new file mode 100644 index 0000000..2993c43 --- /dev/null +++ b/debian/man/musl-gcc.1 @@ -0,0 +1,34 @@ +.TH "musl-gcc" "1" "August 23, 2013" "Linux" "General Commands Manual" +.nh +.if n .ad l +.SH "NAME" +\fBmusl-gcc\fR +\- musl wrapper for gcc +.SH "SYNOPSIS" +.HP 9n +\fBmusl-gcc\fR +[OPTION...] +\fIFILENAME...\fR +.SH "DESCRIPTION" +\fBmusl-gcc\fR +acts as a wrapper around +gcc(1) +which sets the correct system include paths for linking with musl libc library. +.sp +Since +\fBmusl-gcc\fR +is a simple wrapper around +gcc(1) +it uses the same command line arguments. +.SH "FILES" +\fI/usr/lib/$ARCH-linux-musl/musl-gcc.specs\fR +musl-gcc spec file that defines new/overwritten include paths. +.SH "SEE ALSO" +gcc(1) +.SH "AUTHORS" +Kevin Bortis . +.sp +\fBmusl-gcc\fR +was written by +.br +Rich Felker diff --git a/debian/man/musl-ldd.1 b/debian/man/musl-ldd.1 new file mode 100644 index 0000000..ca97230 --- /dev/null +++ b/debian/man/musl-ldd.1 @@ -0,0 +1,20 @@ +.TH "musl-ldd" "1" "February 23, 2014" "Linux" "General Commands Manual" +.nh +.if n .ad l +.SH "NAME" +\fBmusl-ldd\fR +\- print musl shared library dependencies +.SH "SYNOPSIS" +.HP 9n +\fBmusl-ldd\fR +\fIFILENAME...\fR +.SH "DESCRIPTION" +\fBmusl-ldd\fR +prints the shared libraries required by the given program or shared library that is dynamicaly linked to the musl libc. +.SH "AUTHORS" +Kevin Bortis . +.sp +\fBmusl\fR +was written by +.br +Rich Felker diff --git a/debian/musl-dev.install b/debian/musl-dev.install new file mode 100644 index 0000000..9b79532 --- /dev/null +++ b/debian/musl-dev.install @@ -0,0 +1,3 @@ +usr/include/${env:MUSL_TRIPLE}/* +usr/lib/${env:MUSL_TRIPLE}/*.a +usr/lib/${env:MUSL_TRIPLE}/*.o diff --git a/debian/musl-dev.lintian-overrides b/debian/musl-dev.lintian-overrides new file mode 100644 index 0000000..5db9081 --- /dev/null +++ b/debian/musl-dev.lintian-overrides @@ -0,0 +1,14 @@ +# musl needs to use its own namespace to not conflict with other libcs +# The installed files are the same for CPU architecture +musl-dev binary: triplet-dir-and-architecture-mismatch +# musl needs to use its own namespace to not conflict with other libcs +musl-dev binary: arch-dependent-file-not-in-arch-specific-directory +# manpage for musl-gcc lives in musl-tools +musl-dev binary: no-manual-page +musl-dev: no-code-sections [usr/lib/*/libdl.a] +musl-dev: no-code-sections [usr/lib/*/libm.a] +musl-dev: no-code-sections [usr/lib/*/libpthread.a] +musl-dev: no-code-sections [usr/lib/*/libresolv.a] +musl-dev: no-code-sections [usr/lib/*/librt.a] +musl-dev: no-code-sections [usr/lib/*/libutil.a] +musl-dev: no-code-sections [usr/lib/*/libxnet.a] diff --git a/debian/musl-dev.postinst.in b/debian/musl-dev.postinst.in new file mode 100644 index 0000000..d20aec4 --- /dev/null +++ b/debian/musl-dev.postinst.in @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +if [ "$1" = 'configure' -a ! -e /usr/lib/@MUSL_TRIPLE@/libc.so ]; then + ln -s /lib/@MUSL_TRIPLE@/libc.so /usr/lib/@MUSL_TRIPLE@/libc.so +fi + +#DEBHELPER# + diff --git a/debian/musl-dev.postrm.in b/debian/musl-dev.postrm.in new file mode 100644 index 0000000..82a63b0 --- /dev/null +++ b/debian/musl-dev.postrm.in @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +if [ "$1" = 'remove' -a -L /usr/lib/@MUSL_TRIPLE@/libc.so ]; then + rm /usr/lib/@MUSL_TRIPLE@/libc.so +fi + +#DEBHELPER# + diff --git a/debian/musl-fts/config.h b/debian/musl-fts/config.h new file mode 100644 index 0000000..9043da9 --- /dev/null +++ b/debian/musl-fts/config.h @@ -0,0 +1,2 @@ +#define HAVE_DECL_MAX 1 +#define HAVE_DIRFD 1 diff --git a/debian/musl-fts/fts.c b/debian/musl-fts/fts.c new file mode 100644 index 0000000..0f8d05b --- /dev/null +++ b/debian/musl-fts/fts.c @@ -0,0 +1,1255 @@ +/* $NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; +#else +__RCSID("$NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "config.h" + +#include +#include + +#include +#define _DIAGASSERT(e) +#include +#include +#include +#include +#include +#include +#include + +#if !defined(HAVE_DECL_MAX) || (HAVE_DECL_MAX==0) +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + +#if !defined(UINT_MAX) && (HAVE_DECL_UINTMAX_MAX==1) +#define UINT_MAX UINTMAX_MAX +#endif + +#if !defined(HAVE_DIRFD) +#if defined(HAVE_DIR_DD_FD) +#define dirfd(dirp) ((dirp)->dd_fd) +#endif +#if defined(HAVE_DIR_D_FD) +#define dirfd(dirp) ((dirp)->d_fd) +#endif +#endif + +static FTSENT *fts_alloc(FTS *, const char *, size_t); +static FTSENT *fts_build(FTS *, int); +static void fts_free(FTSENT *); +static void fts_lfree(FTSENT *); +static void fts_load(FTS *, FTSENT *); +static size_t fts_maxarglen(char * const *); +static size_t fts_pow2(size_t); +static int fts_palloc(FTS *, size_t); +static void fts_padjust(FTS *, FTSENT *); +static FTSENT *fts_sort(FTS *, FTSENT *, size_t); +static unsigned short fts_stat(FTS *, FTSENT *, int); +static int fts_safe_changedir(const FTS *, const FTSENT *, int, + const char *); + +#if defined(ALIGNBYTES) && defined(ALIGN) +#define FTS_ALLOC_ALIGNED 1 +#else +#undef FTS_ALLOC_ALIGNED +#endif + +#ifndef ftsent_namelen_truncate +#define ftsent_namelen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef fts_pathlen_truncate +#define fts_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef fts_nitems_truncate +#define fts_nitems_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif + +#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) + +#define CLR(opt) (sp->fts_options &= ~(opt)) +#define ISSET(opt) (sp->fts_options & (opt)) +#define SET(opt) (sp->fts_options |= (opt)) + +#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) +#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) + +/* fts_build flags */ +#define BCHILD 1 /* fts_children */ +#define BNAMES 2 /* fts_children, names only */ +#define BREAD 3 /* fts_read */ + +#ifndef DTF_HIDEW +#undef FTS_WHITEOUT +#endif + +FTS * +fts_open(char * const *argv, int options, + int (*compar)(const FTSENT **, const FTSENT **)) +{ + FTS *sp; + FTSENT *p, *root; + size_t nitems; + FTSENT *parent, *tmp = NULL; /* pacify gcc */ + size_t len; + + _DIAGASSERT(argv != NULL); + + /* Options check. */ + if (options & ~FTS_OPTIONMASK) { + errno = EINVAL; + return (NULL); + } + + /* Allocate/initialize the stream */ + if ((sp = malloc(sizeof(FTS))) == NULL) + return (NULL); + memset(sp, 0, sizeof(FTS)); + sp->fts_compar = compar; + sp->fts_options = options; + + /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ + if (ISSET(FTS_LOGICAL)) + SET(FTS_NOCHDIR); + + /* + * Start out with 1K of path space, and enough, in any case, + * to hold the user's paths. + */ + if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) + goto mem1; + + /* Allocate/initialize root's parent. */ + if ((parent = fts_alloc(sp, "", 0)) == NULL) + goto mem2; + parent->fts_level = FTS_ROOTPARENTLEVEL; + + /* Allocate/initialize root(s). */ + for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { + /* Don't allow zero-length paths. */ + if ((len = strlen(*argv)) == 0) { + errno = ENOENT; + goto mem3; + } + + if ((p = fts_alloc(sp, *argv, len)) == NULL) + goto mem3; + p->fts_level = FTS_ROOTLEVEL; + p->fts_parent = parent; + p->fts_accpath = p->fts_name; + p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); + + /* Command-line "." and ".." are real directories. */ + if (p->fts_info == FTS_DOT) + p->fts_info = FTS_D; + + /* + * If comparison routine supplied, traverse in sorted + * order; otherwise traverse in the order specified. + */ + if (compar) { + p->fts_link = root; + root = p; + } else { + p->fts_link = NULL; + if (root == NULL) + tmp = root = p; + else { + tmp->fts_link = p; + tmp = p; + } + } + } + if (compar && nitems > 1) + root = fts_sort(sp, root, nitems); + + /* + * Allocate a dummy pointer and make fts_read think that we've just + * finished the node before the root(s); set p->fts_info to FTS_INIT + * so that everything about the "current" node is ignored. + */ + if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) + goto mem3; + sp->fts_cur->fts_link = root; + sp->fts_cur->fts_info = FTS_INIT; + + /* + * If using chdir(2), grab a file descriptor pointing to dot to ensure + * that we can get back here; this could be avoided for some paths, + * but almost certainly not worth the effort. Slashes, symbolic links, + * and ".." are all fairly nasty problems. Note, if we can't get the + * descriptor we run anyway, just more slowly. + */ +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + if (!ISSET(FTS_NOCHDIR)) { + if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) + SET(FTS_NOCHDIR); + } + + if (nitems == 0) + fts_free(parent); + + return (sp); + +mem3: fts_lfree(root); + fts_free(parent); +mem2: free(sp->fts_path); +mem1: free(sp); + return (NULL); +} + +static void +fts_load(FTS *sp, FTSENT *p) +{ + size_t len; + char *cp; + + _DIAGASSERT(sp != NULL); + _DIAGASSERT(p != NULL); + + /* + * Load the stream structure for the next traversal. Since we don't + * actually enter the directory until after the preorder visit, set + * the fts_accpath field specially so the chdir gets done to the right + * place and the user can access the first node. From fts_open it's + * known that the path will fit. + */ + len = p->fts_pathlen = p->fts_namelen; + memmove(sp->fts_path, p->fts_name, len + 1); + if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { + len = strlen(++cp); + memmove(p->fts_name, cp, len + 1); + p->fts_namelen = ftsent_namelen_truncate(len); + } + p->fts_accpath = p->fts_path = sp->fts_path; + sp->fts_dev = p->fts_dev; +} + +int +fts_close(FTS *sp) +{ + FTSENT *freep, *p; + int saved_errno = 0; + + _DIAGASSERT(sp != NULL); + + /* + * This still works if we haven't read anything -- the dummy structure + * points to the root list, so we step through to the end of the root + * list which has a valid parent pointer. + */ + if (sp->fts_cur) { + if (sp->fts_cur->fts_flags & FTS_SYMFOLLOW) + (void)close(sp->fts_cur->fts_symfd); + for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { + freep = p; + p = p->fts_link ? p->fts_link : p->fts_parent; + fts_free(freep); + } + fts_free(p); + } + + /* Free up child linked list, sort array, path buffer. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + if (sp->fts_array) + free(sp->fts_array); + free(sp->fts_path); + + /* Return to original directory, save errno if necessary. */ + if (!ISSET(FTS_NOCHDIR)) { + if (fchdir(sp->fts_rfd) == -1) + saved_errno = errno; + (void)close(sp->fts_rfd); + } + + /* Free up the stream pointer. */ + free(sp); + if (saved_errno) { + errno = saved_errno; + return -1; + } + + return 0; +} + +#if !defined(__FTS_COMPAT_TAILINGSLASH) + +/* + * Special case of "/" at the end of the path so that slashes aren't + * appended which would cause paths to be written as "....//foo". + */ +#define NAPPEND(p) \ + (p->fts_path[p->fts_pathlen - 1] == '/' \ + ? p->fts_pathlen - 1 : p->fts_pathlen) + +#else /* !defined(__FTS_COMPAT_TAILINGSLASH) */ + +/* + * compatibility with the old behaviour. + * + * Special case a root of "/" so that slashes aren't appended which would + * cause paths to be written as "//foo". + */ + +#define NAPPEND(p) \ + (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \ + p->fts_path[0] == '/' ? 0 : p->fts_pathlen) + +#endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */ + +FTSENT * +fts_read(FTS *sp) +{ + FTSENT *p, *tmp; + int instr; + char *t; + int saved_errno; + + _DIAGASSERT(sp != NULL); + + /* If finished or unrecoverable error, return NULL. */ + if (sp->fts_cur == NULL || ISSET(FTS_STOP)) + return (NULL); + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* Save and zero out user instructions. */ + instr = p->fts_instr; + p->fts_instr = FTS_NOINSTR; + + /* Any type of file may be re-visited; re-stat and re-turn. */ + if (instr == FTS_AGAIN) { + p->fts_info = fts_stat(sp, p, 0); + return (p); + } + + /* + * Following a symlink -- SLNONE test allows application to see + * SLNONE and recover. If indirecting through a symlink, have + * keep a pointer to current location. If unable to get that + * pointer, follow fails. + */ + if (instr == FTS_FOLLOW && + (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0)) + == -1) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + return (p); + } + + /* Directory in pre-order. */ + if (p->fts_info == FTS_D) { + /* If skipped or crossed mount point, do post-order visit. */ + if (instr == FTS_SKIP || + (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { + if (p->fts_flags & FTS_SYMFOLLOW) + (void)close(p->fts_symfd); + if (sp->fts_child) { + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + p->fts_info = FTS_DP; + return (p); + } + + /* Rebuild if only read the names and now traversing. */ + if (sp->fts_child && ISSET(FTS_NAMEONLY)) { + CLR(FTS_NAMEONLY); + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + + /* + * Cd to the subdirectory. + * + * If have already read and now fail to chdir, whack the list + * to make the names come out right, and set the parent errno + * so the application will eventually get an error condition. + * Set the FTS_DONTCHDIR flag so that when we logically change + * directories back to the parent we don't do a chdir. + * + * If haven't read do so. If the read fails, fts_build sets + * FTS_STOP or the fts_info field of the node. + */ + if (sp->fts_child) { + if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { + p->fts_errno = errno; + p->fts_flags |= FTS_DONTCHDIR; + for (p = sp->fts_child; p; p = p->fts_link) + p->fts_accpath = + p->fts_parent->fts_accpath; + } + } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { + if (ISSET(FTS_STOP)) + return (NULL); + return (p); + } + p = sp->fts_child; + sp->fts_child = NULL; + goto name; + } + +next: + /* Move to the next node on this level. */ + tmp = p; + + /* + * We are going to free sp->fts_cur, set it to NULL so + * that fts_close() does not attempt to free it again + * if we exit without setting it to a new value because + * FCHDIR() failed below. + */ + assert(tmp == sp->fts_cur); + sp->fts_cur = NULL; + + if ((p = p->fts_link) != NULL) { + fts_free(tmp); + + /* + * If reached the top, return to the original directory, and + * load the paths for the next root. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + fts_load(sp, p); + return (sp->fts_cur = p); + } + + /* + * User may have called fts_set on the node. If skipped, + * ignore. If followed, get a file descriptor so we can + * get back if necessary. + */ + if (p->fts_instr == FTS_SKIP) + goto next; + if (p->fts_instr == FTS_FOLLOW) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = + open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + p->fts_instr = FTS_NOINSTR; + } + +name: t = sp->fts_path + NAPPEND(p->fts_parent); + *t++ = '/'; + memmove(t, p->fts_name, (size_t)(p->fts_namelen + 1)); + return (sp->fts_cur = p); + } + + /* Move up to the parent node. */ + p = tmp->fts_parent; + fts_free(tmp); + + if (p->fts_level == FTS_ROOTPARENTLEVEL) { + /* + * Done; free everything up and set errno to 0 so the user + * can distinguish between error and EOF. + */ + fts_free(p); + errno = 0; + return (sp->fts_cur = NULL); + } + + /* NUL terminate the pathname. */ + sp->fts_path[p->fts_pathlen] = '\0'; + + /* + * Return to the parent directory. If at a root node or came through + * a symlink, go back through the file descriptor. Otherwise, cd up + * one directory. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + } else if (p->fts_flags & FTS_SYMFOLLOW) { + if (FCHDIR(sp, p->fts_symfd)) { + saved_errno = errno; + (void)close(p->fts_symfd); + errno = saved_errno; + SET(FTS_STOP); + return (NULL); + } + (void)close(p->fts_symfd); + } else if (!(p->fts_flags & FTS_DONTCHDIR) && + fts_safe_changedir(sp, p->fts_parent, -1, "..")) { + SET(FTS_STOP); + return (NULL); + } + p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; + return (sp->fts_cur = p); +} + +/* + * Fts_set takes the stream as an argument although it's not used in this + * implementation; it would be necessary if anyone wanted to add global + * semantics to fts using fts_set. An error return is allowed for similar + * reasons. + */ +/* ARGSUSED */ +int +fts_set(FTS *sp, FTSENT *p, int instr) +{ + + _DIAGASSERT(sp != NULL); + _DIAGASSERT(p != NULL); + + if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && + instr != FTS_NOINSTR && instr != FTS_SKIP) { + errno = EINVAL; + return (1); + } + p->fts_instr = instr; + return (0); +} + +FTSENT * +fts_children(FTS *sp, int instr) +{ + FTSENT *p; + int fd; + + _DIAGASSERT(sp != NULL); + + if (instr && instr != FTS_NAMEONLY) { + errno = EINVAL; + return (NULL); + } + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* + * Errno set to 0 so user can distinguish empty directory from + * an error. + */ + errno = 0; + + /* Fatal errors stop here. */ + if (ISSET(FTS_STOP)) + return (NULL); + + /* Return logical hierarchy of user's arguments. */ + if (p->fts_info == FTS_INIT) + return (p->fts_link); + + /* + * If not a directory being visited in pre-order, stop here. Could + * allow FTS_DNR, assuming the user has fixed the problem, but the + * same effect is available with FTS_AGAIN. + */ + if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) + return (NULL); + + /* Free up any previous child list. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + + if (instr == FTS_NAMEONLY) { + SET(FTS_NAMEONLY); + instr = BNAMES; + } else + instr = BCHILD; + + /* + * If using chdir on a relative path and called BEFORE fts_read does + * its chdir to the root of a traversal, we can lose -- we need to + * chdir into the subdirectory, and we don't know where the current + * directory is, so we can't get back so that the upcoming chdir by + * fts_read will work. + */ + if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || + ISSET(FTS_NOCHDIR)) + return (sp->fts_child = fts_build(sp, instr)); + + if ((fd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) + return (sp->fts_child = NULL); + sp->fts_child = fts_build(sp, instr); + if (fchdir(fd)) { + (void)close(fd); + return (NULL); + } + (void)close(fd); + return (sp->fts_child); +} + +/* + * This is the tricky part -- do not casually change *anything* in here. The + * idea is to build the linked list of entries that are used by fts_children + * and fts_read. There are lots of special cases. + * + * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is + * set and it's a physical walk (so that symbolic links can't be directories), + * we can do things quickly. First, if it's a 4.4BSD file system, the type + * of the file is in the directory entry. Otherwise, we assume that the number + * of subdirectories in a node is equal to the number of links to the parent. + * The former skips all stat calls. The latter skips stat calls in any leaf + * directories and for any files after the subdirectories in the directory have + * been found, cutting the stat calls by about 2/3. + */ +static FTSENT * +fts_build(FTS *sp, int type) +{ + struct dirent *dp; + FTSENT *p, *head; + size_t nitems; + FTSENT *cur, *tail; + DIR *dirp; + void *oldaddr; + size_t dnamlen; + int cderrno, descend, level, nlinks, saved_errno, nostat, doadjust; + size_t len, maxlen; +#ifdef FTS_WHITEOUT + int oflag; +#endif + char *cp = NULL; /* pacify gcc */ + + _DIAGASSERT(sp != NULL); + + /* Set current node pointer. */ + cur = sp->fts_cur; + + /* + * Open the directory for reading. If this fails, we're done. + * If being called from fts_read, set the fts_info field. + */ +#ifdef FTS_WHITEOUT + if (ISSET(FTS_WHITEOUT)) + oflag = DTF_NODUP|DTF_REWIND; + else + oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; +#else +#define __opendir2(path, flag) opendir(path) +#endif + if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { + if (type == BREAD) { + cur->fts_info = FTS_DNR; + cur->fts_errno = errno; + } + return (NULL); + } + + /* + * Nlinks is the number of possible entries of type directory in the + * directory if we're cheating on stat calls, 0 if we're not doing + * any stat calls at all, -1 if we're doing stats on everything. + */ + if (type == BNAMES) { + nlinks = 0; + nostat = 1; + } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { + nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); + nostat = 1; + } else { + nlinks = -1; + nostat = 0; + } + +#ifdef notdef + (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); + (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", + ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); +#endif + /* + * If we're going to need to stat anything or we want to descend + * and stay in the directory, chdir. If this fails we keep going, + * but set a flag so we don't chdir after the post-order visit. + * We won't be able to stat anything, but we can still return the + * names themselves. Note, that since fts_read won't be able to + * chdir into the directory, it will have to return different path + * names than before, i.e. "a/b" instead of "b". Since the node + * has already been visited in pre-order, have to wait until the + * post-order visit to return the error. There is a special case + * here, if there was nothing to stat then it's not an error to + * not be able to stat. This is all fairly nasty. If a program + * needed sorted entries or stat information, they had better be + * checking FTS_NS on the returned nodes. + */ + cderrno = 0; + if (nlinks || type == BREAD) { + if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (nlinks && type == BREAD) + cur->fts_errno = errno; + cur->fts_flags |= FTS_DONTCHDIR; + descend = 0; + cderrno = errno; + } else + descend = 1; + } else + descend = 0; + + /* + * Figure out the max file name length that can be stored in the + * current path -- the inner loop allocates more path as necessary. + * We really wouldn't have to do the maxlen calculations here, we + * could do them in fts_read before returning the path, but it's a + * lot easier here since the length is part of the dirent structure. + * + * If not changing directories set a pointer so that can just append + * each new name into the path. + */ + len = NAPPEND(cur); + if (ISSET(FTS_NOCHDIR)) { + cp = sp->fts_path + len; + *cp++ = '/'; + } + len++; + maxlen = sp->fts_pathlen - len; + +#if defined(__FTS_COMPAT_LEVEL) + if (cur->fts_level == SHRT_MAX) { + (void)closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + errno = ENAMETOOLONG; + return (NULL); + } +#endif + + level = cur->fts_level + 1; + + /* Read the directory, attaching each entry to the `link' pointer. */ + doadjust = 0; + for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) { + + if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) + continue; + +#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) + dnamlen = dp->d_namlen; +#else + dnamlen = strlen(dp->d_name); +#endif + if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL) + goto mem1; + if (dnamlen >= maxlen) { /* include space for NUL */ + oldaddr = sp->fts_path; + if (fts_palloc(sp, dnamlen + len + 1)) { + /* + * No more memory for path or structures. Save + * errno, free up the current structure and the + * structures already allocated. + */ +mem1: saved_errno = errno; + if (p) + fts_free(p); + fts_lfree(head); + (void)closedir(dirp); + errno = saved_errno; + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + return (NULL); + } + /* Did realloc() change the pointer? */ + if (oldaddr != sp->fts_path) { + doadjust = 1; + if (ISSET(FTS_NOCHDIR)) + cp = sp->fts_path + len; + } + maxlen = sp->fts_pathlen - len; + } + +#if defined(__FTS_COMPAT_LENGTH) + if (len + dnamlen >= USHRT_MAX) { + /* + * In an FTSENT, fts_pathlen is an unsigned short + * so it is possible to wraparound here. + * If we do, free up the current structure and the + * structures already allocated, then error out + * with ENAMETOOLONG. + */ + fts_free(p); + fts_lfree(head); + (void)closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + errno = ENAMETOOLONG; + return (NULL); + } +#endif + p->fts_level = level; + p->fts_pathlen = ftsent_pathlen_truncate(len + dnamlen); + p->fts_parent = sp->fts_cur; + +#ifdef FTS_WHITEOUT + if (dp->d_type == DT_WHT) + p->fts_flags |= FTS_ISW; +#endif + + if (cderrno) { + if (nlinks) { + p->fts_info = FTS_NS; + p->fts_errno = cderrno; + } else + p->fts_info = FTS_NSOK; + p->fts_accpath = cur->fts_accpath; + } else if (nlinks == 0 +#ifdef DT_DIR + || (nostat && + dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) +#endif + ) { + p->fts_accpath = + ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; + p->fts_info = FTS_NSOK; + } else { + /* Build a file name for fts_stat to stat. */ + if (ISSET(FTS_NOCHDIR)) { + p->fts_accpath = p->fts_path; + memmove(cp, p->fts_name, + (size_t)(p->fts_namelen + 1)); + } else + p->fts_accpath = p->fts_name; + /* Stat it. */ + p->fts_info = fts_stat(sp, p, 0); + + /* Decrement link count if applicable. */ + if (nlinks > 0 && (p->fts_info == FTS_D || + p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) + --nlinks; + } + + /* We walk in directory order so "ls -f" doesn't get upset. */ + p->fts_link = NULL; + if (head == NULL) + head = tail = p; + else { + tail->fts_link = p; + tail = p; + } + ++nitems; + } + (void)closedir(dirp); + + /* + * If had to realloc the path, adjust the addresses for the rest + * of the tree. + */ + if (doadjust) + fts_padjust(sp, head); + + /* + * If not changing directories, reset the path back to original + * state. + */ + if (ISSET(FTS_NOCHDIR)) { + if (len == sp->fts_pathlen || nitems == 0) + --cp; + *cp = '\0'; + } + + /* + * If descended after called from fts_children or after called from + * fts_read and nothing found, get back. At the root level we use + * the saved fd; if one of fts_open()'s arguments is a relative path + * to an empty directory, we wind up here with no other way back. If + * can't get back, we're done. + */ + if (descend && (type == BCHILD || !nitems) && + (cur->fts_level == FTS_ROOTLEVEL ? + FCHDIR(sp, sp->fts_rfd) : + fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + return (NULL); + } + + /* If didn't find anything, return NULL. */ + if (!nitems) { + if (type == BREAD) + cur->fts_info = FTS_DP; + return (NULL); + } + + /* Sort the entries. */ + if (sp->fts_compar && nitems > 1) + head = fts_sort(sp, head, nitems); + return (head); +} + +static unsigned short +fts_stat(FTS *sp, FTSENT *p, int follow) +{ + FTSENT *t; + dev_t dev; + __fts_ino_t ino; + __fts_stat_t *sbp, sb; + int saved_errno; + + _DIAGASSERT(sp != NULL); + _DIAGASSERT(p != NULL); + + /* If user needs stat info, stat buffer already allocated. */ + sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; + +#ifdef FTS_WHITEOUT + /* check for whiteout */ + if (p->fts_flags & FTS_ISW) { + if (sbp != &sb) { + memset(sbp, '\0', sizeof (*sbp)); + sbp->st_mode = S_IFWHT; + } + return (FTS_W); + } +#endif + + /* + * If doing a logical walk, or application requested FTS_FOLLOW, do + * a stat(2). If that fails, check for a non-existent symlink. If + * fail, set the errno from the stat call. + */ + if (ISSET(FTS_LOGICAL) || follow) { + if (stat(p->fts_accpath, sbp)) { + saved_errno = errno; + if (!lstat(p->fts_accpath, sbp)) { + errno = 0; + return (FTS_SLNONE); + } + p->fts_errno = saved_errno; + goto err; + } + } else if (lstat(p->fts_accpath, sbp)) { + p->fts_errno = errno; +err: memset(sbp, 0, sizeof(*sbp)); + return (FTS_NS); + } + + if (S_ISDIR(sbp->st_mode)) { + /* + * Set the device/inode. Used to find cycles and check for + * crossing mount points. Also remember the link count, used + * in fts_build to limit the number of stat calls. It is + * understood that these fields are only referenced if fts_info + * is set to FTS_D. + */ + dev = p->fts_dev = sbp->st_dev; + ino = p->fts_ino = sbp->st_ino; + p->fts_nlink = sbp->st_nlink; + + if (ISDOT(p->fts_name)) + return (FTS_DOT); + + /* + * Cycle detection is done by brute force when the directory + * is first encountered. If the tree gets deep enough or the + * number of symbolic links to directories is high enough, + * something faster might be worthwhile. + */ + for (t = p->fts_parent; + t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) + if (ino == t->fts_ino && dev == t->fts_dev) { + p->fts_cycle = t; + return (FTS_DC); + } + return (FTS_D); + } + if (S_ISLNK(sbp->st_mode)) + return (FTS_SL); + if (S_ISREG(sbp->st_mode)) + return (FTS_F); + return (FTS_DEFAULT); +} + +static FTSENT * +fts_sort(FTS *sp, FTSENT *head, size_t nitems) +{ + FTSENT **ap, *p; + + _DIAGASSERT(sp != NULL); + _DIAGASSERT(head != NULL); + + /* + * Construct an array of pointers to the structures and call qsort(3). + * Reassemble the array in the order returned by qsort. If unable to + * sort for memory reasons, return the directory entries in their + * current order. Allocate enough space for the current needs plus + * 40 so don't realloc one entry at a time. + */ + if (nitems > sp->fts_nitems) { + FTSENT **new; + + new = realloc(sp->fts_array, sizeof(FTSENT *) * (nitems + 40)); + if (new == 0) + return (head); + sp->fts_array = new; + sp->fts_nitems = fts_nitems_truncate(nitems + 40); + } + for (ap = sp->fts_array, p = head; p; p = p->fts_link) + *ap++ = p; + qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), + (int (*)(const void *, const void *))sp->fts_compar); + for (head = *(ap = sp->fts_array); --nitems; ++ap) + ap[0]->fts_link = ap[1]; + ap[0]->fts_link = NULL; + return (head); +} + +static FTSENT * +fts_alloc(FTS *sp, const char *name, size_t namelen) +{ + FTSENT *p; +#if defined(FTS_ALLOC_ALIGNED) + size_t len; +#endif + + _DIAGASSERT(sp != NULL); + _DIAGASSERT(name != NULL); + +#if defined(FTS_ALLOC_ALIGNED) + /* + * The file name is a variable length array and no stat structure is + * necessary if the user has set the nostat bit. Allocate the FTSENT + * structure, the file name and the stat structure in one chunk, but + * be careful that the stat structure is reasonably aligned. Since the + * fts_name field is declared to be of size 1, the fts_name pointer is + * namelen + 2 before the first possible address of the stat structure. + */ + len = sizeof(FTSENT) + namelen; + if (!ISSET(FTS_NOSTAT)) + len += sizeof(*(p->fts_statp)) + ALIGNBYTES; + if ((p = malloc(len)) == NULL) + return (NULL); + + if (!ISSET(FTS_NOSTAT)) + p->fts_statp = (__fts_stat_t *)ALIGN( + (unsigned long)(p->fts_name + namelen + 2)); +#else + if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL) + return (NULL); + + if (!ISSET(FTS_NOSTAT)) + if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) { + free(p); + return (NULL); + } +#endif + + if (ISSET(FTS_NOSTAT)) + p->fts_statp = NULL; + + /* Copy the name plus the trailing NULL. */ + memmove(p->fts_name, name, namelen + 1); + + p->fts_namelen = ftsent_namelen_truncate(namelen); + p->fts_path = sp->fts_path; + p->fts_errno = 0; + p->fts_flags = 0; + p->fts_instr = FTS_NOINSTR; + p->fts_number = 0; + p->fts_pointer = NULL; + return (p); +} + +static void +fts_free(FTSENT *p) +{ +#if !defined(FTS_ALLOC_ALIGNED) + if (p->fts_statp) + free(p->fts_statp); +#endif + free(p); +} + +static void +fts_lfree(FTSENT *head) +{ + FTSENT *p; + + /* XXX: head may be NULL ? */ + + /* Free a linked list of structures. */ + while ((p = head) != NULL) { + head = head->fts_link; + fts_free(p); + } +} + +static size_t +fts_pow2(size_t x) +{ + + x--; + x |= x>>1; + x |= x>>2; + x |= x>>4; + x |= x>>8; + x |= x>>16; +#if LONG_BIT > 32 + x |= x>>32; +#endif +#if LONG_BIT > 64 + x |= x>>64; +#endif + x++; + return (x); +} + +/* + * Allow essentially unlimited paths; find, rm, ls should all work on any tree. + * Most systems will allow creation of paths much longer than MAXPATHLEN, even + * though the kernel won't resolve them. Round up the new size to a power of 2, + * so we don't realloc the path 2 bytes at a time. + */ +static int +fts_palloc(FTS *sp, size_t size) +{ + char *new; + + _DIAGASSERT(sp != NULL); + +#ifdef __FTS_COMPAT_LENGTH + /* Protect against fts_pathlen overflow. */ + if (size > USHRT_MAX + 1) { + errno = ENAMETOOLONG; + return (1); + } +#endif + size = fts_pow2(size); + new = realloc(sp->fts_path, size); + if (new == 0) + return (1); + sp->fts_path = new; + sp->fts_pathlen = fts_pathlen_truncate(size); + return (0); +} + +/* + * When the path is realloc'd, have to fix all of the pointers in structures + * already returned. + */ +static void +fts_padjust(FTS *sp, FTSENT *head) +{ + FTSENT *p; + char *addr; + + _DIAGASSERT(sp != NULL); + +#define ADJUST(p) do { \ + if ((p)->fts_accpath != (p)->fts_name) \ + (p)->fts_accpath = \ + addr + ((p)->fts_accpath - (p)->fts_path); \ + (p)->fts_path = addr; \ +} while (/*CONSTCOND*/0) + + addr = sp->fts_path; + + /* Adjust the current set of children. */ + for (p = sp->fts_child; p; p = p->fts_link) + ADJUST(p); + + /* Adjust the rest of the tree, including the current level. */ + for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { + ADJUST(p); + p = p->fts_link ? p->fts_link : p->fts_parent; + } +} + +static size_t +fts_maxarglen(char * const *argv) +{ + size_t len, max; + + _DIAGASSERT(argv != NULL); + + for (max = 0; *argv; ++argv) + if ((len = strlen(*argv)) > max) + max = len; + return (max + 1); +} + +/* + * Change to dir specified by fd or p->fts_accpath without getting + * tricked by someone changing the world out from underneath us. + * Assumes p->fts_dev and p->fts_ino are filled in. + */ +static int +fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path) +{ + int oldfd = fd, ret = -1; + __fts_stat_t sb; + + if (ISSET(FTS_NOCHDIR)) + return 0; + + if (oldfd < 0 && (fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) + return -1; + + if (fstat(fd, &sb) == -1) + goto bail; + + if (sb.st_ino != p->fts_ino || sb.st_dev != p->fts_dev) { + errno = ENOENT; + goto bail; + } + + ret = fchdir(fd); + +bail: + if (oldfd < 0) { + int save_errno = errno; + (void)close(fd); + errno = save_errno; + } + return ret; +} diff --git a/debian/musl-fts/fts.h b/debian/musl-fts/fts.h new file mode 100644 index 0000000..aef9e00 --- /dev/null +++ b/debian/musl-fts/fts.h @@ -0,0 +1,155 @@ +/* $NetBSD: fts.h,v 1.19 2009/08/16 19:33:38 christos Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fts.h 8.3 (Berkeley) 8/14/94 + */ + +#ifndef _FTS_H_ +#define _FTS_H_ + +#include +#include + +#ifndef __fts_stat_t +#define __fts_stat_t struct stat +#endif +#ifndef __fts_nlink_t +#define __fts_nlink_t nlink_t +#endif +#ifndef __fts_ino_t +#define __fts_ino_t ino_t +#endif +#ifndef __fts_length_t +#define __fts_length_t unsigned int +#endif +#ifndef __fts_number_t +#define __fts_number_t int64_t +#endif +#ifndef __fts_dev_t +#define __fts_dev_t dev_t +#endif +#ifndef __fts_level_t +#define __fts_level_t int +#endif + +typedef struct { + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + dev_t fts_dev; /* starting device # */ + char *fts_path; /* path for this descent */ + int fts_rfd; /* fd for root */ + unsigned int fts_pathlen; /* sizeof(path) */ + unsigned int fts_nitems; /* elements in the sort array */ + int (*fts_compar) /* compare function */ + (const struct _ftsent **, const struct _ftsent **); + +#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ +#define FTS_LOGICAL 0x002 /* logical walk */ +#define FTS_NOCHDIR 0x004 /* don't change directories */ +#define FTS_NOSTAT 0x008 /* don't get stat info */ +#define FTS_PHYSICAL 0x010 /* physical walk */ +#define FTS_SEEDOT 0x020 /* return dot and dot-dot */ +#define FTS_XDEV 0x040 /* don't cross devices */ +#define FTS_WHITEOUT 0x080 /* return whiteout information */ +#define FTS_OPTIONMASK 0x0ff /* valid user option mask */ + +#define FTS_NAMEONLY 0x100 /* (private) child names only */ +#define FTS_STOP 0x200 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ +} FTS; + +typedef struct _ftsent { + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + __fts_number_t fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access path */ + char *fts_path; /* root path */ + int fts_errno; /* errno for this node */ + int fts_symfd; /* fd for symlink */ + __fts_length_t fts_pathlen; /* strlen(fts_path) */ + __fts_length_t fts_namelen; /* strlen(fts_name) */ + + __fts_ino_t fts_ino; /* inode */ + __fts_dev_t fts_dev; /* device */ + __fts_nlink_t fts_nlink; /* link count */ + +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_ROOTLEVEL 0 + __fts_level_t fts_level; /* depth (-1 to N) */ + +#define FTS_D 1 /* preorder directory */ +#define FTS_DC 2 /* directory that causes cycles */ +#define FTS_DEFAULT 3 /* none of the above */ +#define FTS_DNR 4 /* unreadable directory */ +#define FTS_DOT 5 /* dot or dot-dot */ +#define FTS_DP 6 /* postorder directory */ +#define FTS_ERR 7 /* error; errno is set */ +#define FTS_F 8 /* regular file */ +#define FTS_INIT 9 /* initialized only */ +#define FTS_NS 10 /* stat(2) failed */ +#define FTS_NSOK 11 /* no stat(2) requested */ +#define FTS_SL 12 /* symbolic link */ +#define FTS_SLNONE 13 /* symbolic link without target */ +#define FTS_W 14 /* whiteout object */ + unsigned short fts_info; /* user flags for FTSENT structure */ + +#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ +#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ +#define FTS_ISW 0x04 /* this is a whiteout object */ + unsigned short fts_flags; /* private flags for FTSENT structure */ + +#define FTS_AGAIN 1 /* read node again */ +#define FTS_FOLLOW 2 /* follow symbolic link */ +#define FTS_NOINSTR 3 /* no instructions */ +#define FTS_SKIP 4 /* discard node */ + unsigned short fts_instr; /* fts_set() instructions */ + + __fts_stat_t *fts_statp; /* stat(2) information */ + char fts_name[1]; /* file name */ +} FTSENT; + +#ifdef __cplusplus +extern "C" { +#endif +FTSENT *fts_children(FTS *, int); +int fts_close(FTS *); +FTS *fts_open(char * const *, int, + int (*)(const FTSENT **, const FTSENT **)); +FTSENT *fts_read(FTS *); +int fts_set(FTS *, FTSENT *, int); +#ifdef __cplusplus +} +#endif + + +#endif /* !_FTS_H_ */ diff --git a/debian/musl-tools.links b/debian/musl-tools.links new file mode 100644 index 0000000..de331cb --- /dev/null +++ b/debian/musl-tools.links @@ -0,0 +1,2 @@ +/lib/${env:MUSL_TRIPLE}/libc.so /usr/bin/musl-ldd +/usr/bin/${env:MUSL_TRIPLE}-gcc /usr/bin/musl-gcc diff --git a/debian/musl-tools.manpages b/debian/musl-tools.manpages new file mode 100644 index 0000000..0345036 --- /dev/null +++ b/debian/musl-tools.manpages @@ -0,0 +1,2 @@ +debian/man/musl-gcc.1 +debian/man/musl-ldd.1 diff --git a/debian/musl.install b/debian/musl.install new file mode 100644 index 0000000..9117e6c --- /dev/null +++ b/debian/musl.install @@ -0,0 +1,4 @@ +../scripts/${env:MUSL_TRIPLE}.path etc/ld-musl-${env:MUSL_ARCH}.d +../scripts/ld-musl-${env:MUSL_ARCH}.path etc +../scripts/ld-musl-config usr/bin +usr/lib/${env:MUSL_TRIPLE}/libc.so usr/lib/${env:MUSL_TRIPLE} diff --git a/debian/musl.links b/debian/musl.links new file mode 100644 index 0000000..f61a7c8 --- /dev/null +++ b/debian/musl.links @@ -0,0 +1 @@ +/usr/lib/${env:MUSL_TRIPLE}/libc.so /usr/lib/ld-musl-${env:MUSL_ARCH}.so.1 diff --git a/debian/musl.lintian-overrides b/debian/musl.lintian-overrides new file mode 100644 index 0000000..24874a1 --- /dev/null +++ b/debian/musl.lintian-overrides @@ -0,0 +1,11 @@ +# musl libc.so does not depend on anything +musl binary: shared-library-lacks-prerequisites +# musl needs to use its own namespace to not conflict with other libcs +musl binary: arch-dependent-file-not-in-arch-specific-directory +# musl has no SONAME and version by design +musl binary: sharedobject-in-library-directory-missing-soname +# musl needs to use its own namespace to not conflict with other libcs +# The installed files are the same for CPU architecture +musl binary: triplet-dir-and-architecture-mismatch +# helper script for updating linker path config +musl binary: application-in-library-section libs [usr/bin/ld-musl-config] diff --git a/debian/musl.manpages b/debian/musl.manpages new file mode 100644 index 0000000..588bb3d --- /dev/null +++ b/debian/musl.manpages @@ -0,0 +1 @@ +debian/man/ld-musl-config.8 diff --git a/debian/not-installed b/debian/not-installed new file mode 100644 index 0000000..0f2fd10 --- /dev/null +++ b/debian/not-installed @@ -0,0 +1 @@ +lib/ld-musl-*.so.1 diff --git a/debian/patches/CVE-2025-26519-0001_iconv_fix_erroneous_input_validation_in_EUC_KR_decod.patch b/debian/patches/CVE-2025-26519-0001_iconv_fix_erroneous_input_validation_in_EUC_KR_decod.patch new file mode 100644 index 0000000..f36e04d --- /dev/null +++ b/debian/patches/CVE-2025-26519-0001_iconv_fix_erroneous_input_validation_in_EUC_KR_decod.patch @@ -0,0 +1,39 @@ +>From e5adcd97b5196e29991b524237381a0202a60659 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sun, 9 Feb 2025 10:07:19 -0500 +Bug-Debian: https://bugs.debian.org/1098238 +Subject: [PATCH] iconv: fix erroneous input validation in EUC-KR decoder + +as a result of incorrect bounds checking on the lead byte being +decoded, certain invalid inputs which should produce an encoding +error, such as "\xc8\x41", instead produced out-of-bounds loads from +the ksc table. + +in a worst case, the loaded value may not be a valid unicode scalar +value, in which case, if the output encoding was UTF-8, wctomb would +return (size_t)-1, causing an overflow in the output pointer and +remaining buffer size which could clobber memory outside of the output +buffer. + +bug report was submitted in private by Nick Wellnhofer on account of +potential security implications. +--- + src/locale/iconv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 9605c8e9..008c93f0 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (c >= 93 || d >= 94) { + c += (0xa1-0x81); + d += 0xa1; +- if (c >= 93 || c>=0xc6-0x81 && d>0x52) ++ if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52) + goto ilseq; + if (d-'A'<26) d = d-'A'; + else if (d-'a'<26) d = d-'a'+26; +-- +2.21.0 + diff --git a/debian/patches/CVE-2025-26519-0002_iconv_harden_UTF_8_output_code_path_against_input_de.patch b/debian/patches/CVE-2025-26519-0002_iconv_harden_UTF_8_output_code_path_against_input_de.patch new file mode 100644 index 0000000..02f1359 --- /dev/null +++ b/debian/patches/CVE-2025-26519-0002_iconv_harden_UTF_8_output_code_path_against_input_de.patch @@ -0,0 +1,39 @@ +>From c47ad25ea3b484e10326f933e927c0bc8cded3da Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Wed, 12 Feb 2025 17:06:30 -0500 +Bug-Debian: https://bugs.debian.org/1098238 +Subject: [PATCH] iconv: harden UTF-8 output code path against input decoder + bugs + +the UTF-8 output code was written assuming an invariant that iconv's +decoders only emit valid Unicode Scalar Values which wctomb can encode +successfully, thereby always returning a value between 1 and 4. + +if this invariant is not satisfied, wctomb returns (size_t)-1, and the +subsequent adjustments to the output buffer pointer and remaining +output byte count overflow, moving the output position backwards, +potentially past the beginning of the buffer, without storing any +bytes. +--- + src/locale/iconv.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 008c93f0..52178950 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -545,6 +545,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (*outb < k) goto toobig; + memcpy(*out, tmp, k); + } else k = wctomb_utf8(*out, c); ++ /* This failure condition should be unreachable, but ++ * is included to prevent decoder bugs from translating ++ * into advancement outside the output buffer range. */ ++ if (k>4) goto ilseq; + *out += k; + *outb -= k; + break; +-- +2.21.0 + + diff --git a/debian/patches/renameat2.patch b/debian/patches/renameat2.patch new file mode 100644 index 0000000..e36b43c --- /dev/null +++ b/debian/patches/renameat2.patch @@ -0,0 +1,57 @@ +From 05ce67fea99ca09cd4b6625cff7aec9cc222dd5a Mon Sep 17 00:00:00 2001 +From: Tony Ambardar +Date: Mon, 6 May 2024 20:28:32 -0700 +Subject: [PATCH] add renameat2 linux syscall wrapper + +This syscall is available since Linux 3.15 and also implemented in +glibc from version 2.28. It is commonly used in filesystem or security +contexts. + +Constants RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are +guarded by _GNU_SOURCE as with glibc. +--- + include/stdio.h | 7 +++++++ + src/linux/renameat2.c | 11 +++++++++++ + 2 files changed, 18 insertions(+) + create mode 100644 src/linux/renameat2.c + +Bug-Debian: https://bugs.debian.org/1105007 + +diff --git a/include/stdio.h b/include/stdio.h +index cb858618..4ea4c170 100644 +--- a/include/stdio.h ++++ b/include/stdio.h +@@ -158,6 +158,13 @@ char *ctermid(char *); + #define L_ctermid 20 + #endif + ++#if defined(_GNU_SOURCE) ++#define RENAME_NOREPLACE (1 << 0) ++#define RENAME_EXCHANGE (1 << 1) ++#define RENAME_WHITEOUT (1 << 2) ++ ++int renameat2(int, const char *, int, const char *, unsigned); ++#endif + + #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +diff --git a/src/linux/renameat2.c b/src/linux/renameat2.c +new file mode 100644 +index 00000000..b8060388 +--- /dev/null ++++ b/src/linux/renameat2.c +@@ -0,0 +1,11 @@ ++#define _GNU_SOURCE ++#include ++#include "syscall.h" ++ ++int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned flags) ++{ ++#ifdef SYS_renameat ++ if (!flags) return syscall(SYS_renameat, oldfd, old, newfd, new); ++#endif ++ return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); ++} +-- +2.49.0 + diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..5b2288b --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,4 @@ +static-pie.patch +CVE-2025-26519-0001_iconv_fix_erroneous_input_validation_in_EUC_KR_decod.patch +CVE-2025-26519-0002_iconv_harden_UTF_8_output_code_path_against_input_de.patch +renameat2.patch diff --git a/debian/patches/static-pie.patch b/debian/patches/static-pie.patch new file mode 100644 index 0000000..2b49330 --- /dev/null +++ b/debian/patches/static-pie.patch @@ -0,0 +1,99 @@ +From 0d79e34e6da9d9827cfb7c787e90524176248d67 Mon Sep 17 00:00:00 2001 +From: Harald Hoyer +Date: Mon, 27 Apr 2020 14:32:07 +0200 +Bug-Debian: https://bugs.debian.org/996326 +Origin: https://www.openwall.com/lists/musl/2020/04/27/2 +Subject: [PATCH] Enable linking to a static position independent executable + +This also enables address space layout randomization (ASLR). + +$ cat hello.c + +int main() +{ + printf("main = 0x%lxd\n", main); + return 0; +} + +$ gcc -fPIE -static-pie -o hello hello.c -specs musl-gcc.specs + +$ ldd hello + statically linked + +$ file hello +hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped, too many notes (256) + +$ ./hello +main = 0x7f858c4e72b9d + +$ ./hello +main = 0x7f0854d312b9d + +$ ./hello +main = 0x7f7179a1d2b9d + +$ ./hello +main = 0x7f37f981b2b9d + +$ readelf -l hello + +Elf file type is DYN (Shared object file) +Entry point 0x104f +There are 7 program headers, starting at offset 64 + +Program Headers: + Type Offset VirtAddr PhysAddr + FileSiz MemSiz Flags Align + LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 + 0x0000000000000308 0x0000000000000308 R 0x1000 + LOAD 0x0000000000001000 0x0000000000001000 0x0000000000001000 + 0x0000000000003eb7 0x0000000000003eb7 R E 0x1000 + LOAD 0x0000000000005000 0x0000000000005000 0x0000000000005000 + 0x000000000000136c 0x000000000000136c R 0x1000 + LOAD 0x0000000000006e50 0x0000000000007e50 0x0000000000007e50 + 0x00000000000002e0 0x00000000000009a0 RW 0x1000 + DYNAMIC 0x0000000000006e70 0x0000000000007e70 0x0000000000007e70 + 0x0000000000000180 0x0000000000000180 RW 0x8 + GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 + 0x0000000000000000 0x0000000000000000 RW 0x10 + GNU_RELRO 0x0000000000006e50 0x0000000000007e50 0x0000000000007e50 + 0x00000000000001b0 0x00000000000001b0 R 0x1 + + Section to Segment mapping: + Segment Sections... + 00 .hash .gnu.hash .dynsym .dynstr .rela.dyn + 01 .init .plt .text .fini + 02 .rodata .eh_frame + 03 .init_array .fini_array .data.rel.ro .dynamic .got .got.plt .data .bss + 04 .dynamic + 05 + 06 .init_array .fini_array .data.rel.ro .dynamic .got +--- + tools/musl-gcc.specs.sh | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + mode change 100644 => 100755 tools/musl-gcc.specs.sh + +diff --git a/tools/musl-gcc.specs.sh b/tools/musl-gcc.specs.sh +old mode 100644 +new mode 100755 +index 30492574..ed584ed3 +--- a/tools/musl-gcc.specs.sh ++++ b/tools/musl-gcc.specs.sh +@@ -17,13 +17,13 @@ cat < x86-64 +HOST_GNU_TYPE_PKG=$(subst _,-,$(DEB_HOST_GNU_TYPE)) + +# Calculating musl based architecture +MUSL_ARCH=$(DEB_HOST_GNU_CPU) +MUSL_TRIPLE=$(DEB_HOST_GNU_CPU)-linux-musl + +ifneq (,$(findstring armel,$(DEB_HOST_ARCH))) + MUSL_ARCH=arm + MUSL_TRIPLE=arm-linux-musleabi +endif + +ifneq (,$(findstring armhf,$(DEB_HOST_ARCH))) + MUSL_ARCH=armhf + MUSL_TRIPLE=arm-linux-musleabihf +endif + +ifeq ($(DEB_HOST_ARCH_CPU),i386) + MUSL_ARCH=i386 + MUSL_TRIPLE=i386-linux-musl +endif + +ifeq ($(DEB_HOST_ARCH_CPU),sh4) + MUSL_ARCH=sh + MUSL_TRIPLE=sh-linux-musl +endif + +ifneq (,$(findstring ppc64el,$(DEB_HOST_ARCH))) + export DEB_CFLAGS_MAINT_APPEND += -mlong-double-64 +endif + +export MUSL_ARCH +export MUSL_TRIPLE + +CC=$(DEB_HOST_GNU_TYPE)-gcc +CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)- +export CROSS_COMPILE + +export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=-lto + +# Substitute control file variables depending on the debian libc type +# If musl is the native libc, we can provide libc and depend on linux-libc-dev +ifneq (,$(filter musl-%,$(DEB_HOST_ARCH))) + GENCTRL_OPTIONS = -Vlibc-dev:Provides=libc-dev -Vlinux-libc-dev:Depends=linux-libc-dev + GCC_WRAPPER = no +else + GENCTRL_OPTIONS = -Vgcc:Depends=gcc-$(HOST_GNU_TYPE_PKG) + GCC_WRAPPER = yes +endif + +%: + dh $@ + +debian/scripts/$(MUSL_TRIPLE).path: debian/scripts/config.path.in + sed 's/@MUSL_TRIPLE@/$(MUSL_TRIPLE)/g' $< > $@ + cp debian/scripts/$(MUSL_TRIPLE).path debian/scripts/ld-musl-$(MUSL_ARCH).path + +copy_fts: + mkdir -p src/fts + cp debian/musl-fts/fts.c debian/musl-fts/config.h src/fts/ + cp debian/musl-fts/fts.h include/ + +override_dh_auto_configure: debian/scripts/$(MUSL_TRIPLE).path copy_fts + dh_auto_configure -- --libdir=/usr/lib/$(MUSL_TRIPLE) --includedir=/usr/include/$(MUSL_TRIPLE) --host=$(DEB_HOST_GNU_TYPE) --enable-gcc-wrapper=$(GCC_WRAPPER) --enable-debug + +execute_after_dh_auto_install: + rm debian/tmp/usr/include/$(MUSL_TRIPLE)/crypt.h debian/tmp/usr/lib/$(MUSL_TRIPLE)/libcrypt.a + +execute_after_dh_install: +ifeq ($(GCC_WRAPPER),yes) + mkdir -p debian/musl-dev/usr/bin + mv debian/tmp/usr/bin/musl-gcc debian/musl-dev/usr/bin/$(MUSL_TRIPLE)-gcc + mv debian/tmp/usr/lib/$(MUSL_TRIPLE)/musl-gcc.specs debian/musl-dev/usr/lib/$(MUSL_TRIPLE)/musl-gcc.specs +endif + +override_dh_fixperms: + dh_fixperms --exclude libc.so + +override_dh_gencontrol: + dh_gencontrol -- $(GENCTRL_OPTIONS) + +override_dh_installdeb: + sed 's/@MUSL_TRIPLE@/$(MUSL_TRIPLE)/g' \ + debian/musl-dev.postinst.in > debian/musl-dev.postinst + sed 's/@MUSL_TRIPLE@/$(MUSL_TRIPLE)/g' \ + debian/musl-dev.postrm.in > debian/musl-dev.postrm + dh_installdeb + +override_dh_installchangelogs: + dh_installchangelogs WHATSNEW diff --git a/debian/scripts/config.path.in b/debian/scripts/config.path.in new file mode 100644 index 0000000..926aa63 --- /dev/null +++ b/debian/scripts/config.path.in @@ -0,0 +1,2 @@ +/lib/@MUSL_TRIPLE@ +/usr/lib/@MUSL_TRIPLE@ diff --git a/debian/scripts/ld-musl-config b/debian/scripts/ld-musl-config new file mode 100755 index 0000000..41f4931 --- /dev/null +++ b/debian/scripts/ld-musl-config @@ -0,0 +1,15 @@ +#!/bin/sh +for DIR in $(find /etc -maxdepth 1 -type d -name "ld-musl-*.d") + do + ARCH=$(echo $DIR | sed 's@/etc/ld-musl-@@g' | sed 's@.d@@g') + VALID_ARCH=0 + case ${ARCH} in + aarch64|arm|armhf|amd64|i386|loongarch64|mips|mipsel|mips64el|powerpc64le|riscv64|s390x|sh) + VALID_ARCH=1 + ;; + esac + if [ $VALID_ARCH==1 ] + then + grep -s -v '^#\|^$' /etc/ld-musl-$ARCH.d/* | sort -u > /etc/ld-musl-$ARCH.path + fi +done diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/tests/build b/debian/tests/build new file mode 100644 index 0000000..f2bd435 --- /dev/null +++ b/debian/tests/build @@ -0,0 +1,64 @@ +#!/bin/sh +# autopkgtest check: Build and run a program with the help of musl-gcc +# (C) 2013 Thomas Moulard +# (C) 2014 Anton Gladky +# Author: Thomas Moulard +# Anton Gladky + +set -e + +WORKDIR=$(mktemp -d) +trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM +cd $WORKDIR +cat < hello.c +#include +int main(int argc, char **argv) +{ + printf("hello %d\n", argc); + return 0; +} +EOF + +musl-gcc -static -Os -o hello hello.c +echo "build (static): OK" +[ -x hello ] +file hello | grep "statically linked" +./hello +echo "run (static): OK" +rm hello + +musl-gcc -fPIE -static-pie -Os -o hello hello.c +echo "build (static-pie): OK" +[ -x hello ] +file hello | grep "static-pie linked" +./hello +echo "run (static-pie): OK" +rm hello + +musl-gcc -Os -o hello hello.c +echo "build (dynamic): OK" +[ -x hello ] +file hello | grep "dynamically linked" +./hello +echo "run (dynamic): OK" + + +# test building with imported musl-fts +cat < fts.c +#include +#include +#include +#include +int main(int argc, char **argv) +{ + char *path_argv[] = {"/", NULL}; + FTS *fts = fts_open(path_argv, 0, NULL); + fts_close(fts); + return 0; +} +EOF +musl-gcc -Os -o fts fts.c +echo "build (fts): OK" +[ -x fts ] +./fts +echo "run (fts): OK" diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 0000000..fb10afe --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,2 @@ +Tests: build +Depends: binutils, build-essential, file, musl-tools diff --git a/debian/upstream/metadata b/debian/upstream/metadata new file mode 100644 index 0000000..265d79d --- /dev/null +++ b/debian/upstream/metadata @@ -0,0 +1,6 @@ +Name: musl +Contact: musl@lists.openwall.com +FAQ: https://www.musl-libc.org/faq.html +Repository: git://git.musl-libc.org/musl +Repository-Browse: https://git.musl-libc.org/cgit/musl +Security-Contact: Rich Felker diff --git a/debian/upstream/signing-key.asc b/debian/upstream/signing-key.asc new file mode 100644 index 0000000..7b7a8e9 --- /dev/null +++ b/debian/upstream/signing-key.asc @@ -0,0 +1,30 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) + +mQENBFNcU8EBCAC3g30bXEEh+YzD06JQ+iG+gr5Nb+tjianh8aJ/ql35lqICVj6F +nitol0KgSB1L3T80+EON3IEmic9rb2dw6EQ0rMl/6mSW91jQC1rGkGBZnlPZXOSW +JznNTBeHaK1NlG6m0shZ+wePWXHoFDtxaEoaMqAzR+E3EkSduLQb9tJJ2vtmIC2X +5SFT625DKpRYOpcUxX/d63U+gSQThTitHS9Me0mljcP+qKhP/HIajesx6s5QTBBe +vOlzih5MpI0FHcwSIbPwhPUWRS2RdFKfJRQZQAQ1ZiOJL0W82eFI1uztDgfudPcf +BbgZcSjqvrKiXaeZxHsj3aguaOqaKdRlkyD1ABEBAAG0GW11c2wgbGliYyA8bXVz +bEBsaWJjLm9yZz6JATcEEwECACEFAlNcU8ECGwMGCwkIBwMCBhUIAgkKCwMWAgEC +HgECF4AACgkQVrzbWTAgRQ91FwgAnxSTh6Yjz8Oj3p5hTA/5t/ueGpf3dgbVrOXB +W0dgIkv+JbpJnpNFzLLz+Yi7J0eDGhW2OXMvZ1AEJmwoNsbsXBvd2rQAMQGUdcDT +EhmM+9bRGvWW3hpRT9xFtVJb9bsj0vs6Tpcb9LmmUxwmrguAVo2eOQLQ3UvVWaFh +oqEbvhfEb7kvhDds4iFuHxpAH11GmK5Q6POtfFBhYXZBhXqbcHzs1hs51vdDWPUg +pcHdpeR9NiP1Ch7lVMHaTuiTmvQcOtCvk9K8OMsG+9z8e7BIis7bXbIjHOTLNVBI +IE+kq4I0/Co9shhdqump1pJ0b7R+CfgkFP3n9GpGKkGTgc3djrkBDQRTXFPBAQgA +y1PIPj4GJD8AAgSsNMkGxgT1Q0lV8cUh+qN4+uHjO6XzxyiX2rULnO25AWVSq4X2 +i4LzZxgfFG9wUPEWdeYsJzEzNQYL5JWJREBc1UO73pbVWykvP0zUlxtGKNIKHETx +7D02vBpkTUErlNXbKWw1jpApyBmhWZhRsCa320t2yL6v6lO/1YxxCZ/VkSYYbCZ3 +Rl/uH+l7CfAsOJLczMSHpLNFg+fl9gYy6S/LUZ1kwHWLFbTYbzTdEaPSm9i+iNJ2 +tMHnvkvDv9GhOhIrixENCzfe3muxd8+8/UxAjZdj24AYphIRhvMSxnLSOUsoGjeP +BWhTvKsr6r2MZGQcCiDNjwARAQABiQEeBBgBAgAJBQJTXFPBAhsMAAoJEFa821kw +IEUPz50H93mm0dQVPDJV075V5eySx8kYgQUwc7aP6zSQdoMZ3GDa8+fpta3PQv09 +CqVFeJf8KUTkJwMKbNu5GUUmuA1WbxdmRkOHp81PalLbZS0vAJh62TNntmHU0sFJ +kp+IviwOmAJaAO64BQAy/arH0D8q+LFAnMLdIFEVWiMuULXUCB1P4D8agbltd0rH +KniPwcWR8Sh0PUcVjUPFzdZz1Qpc+9VYp626p2OZ+tlLO41OZAsbJ24+cWB/fkWu +H6g/nw7y9+2xtX8TIi6YBtLCPx/5IcY8LzrSFC+NFYll5V1SoTiGtdhudSfs0Eb2 +RXdP42mK+kMrgynbOn1RP7p/rfpSlA== +=FgKg +-----END PGP PUBLIC KEY BLOCK----- diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..a2e43fa --- /dev/null +++ b/debian/watch @@ -0,0 +1,3 @@ +version=4 +opts="pgpsigurlmangle=s/$/.asc/" \ + https://musl.libc.org/ releases/musl-@ANY_VERSION@@ARCHIVE_EXT@