vinix-ports / ports / musl / PKGBUILD.vile
80 lines · 78 sloc · 5.22 KB · c33d8afc2906b8dd9a8b905224eccd49a44f7ad5
Raw
1; Source and patch order follow Vinix build-support/musl at a58255423ede.
2selected-arch := get-environment-variable("VPAC_TARGET_ARCH")
3native-arm := memq(string->symbol("aarch64"), features())
4target-arch := if string?(selected-arch) { selected-arch } else if native-arm { "aarch64" } else { "x86_64" }
5cross-prefix := get-environment-variable("CROSS_COMPILE")
6prefix := if string?(cross-prefix) { cross-prefix } else { "" }
7page-flags := if string=?(target-arch, "aarch64") { " -Wl,-z,max-page-size=16384" } else { "" }
8release := if string=?(target-arch, "aarch64") { 4 } else { 3 }
9
10defpkgbuild(musl,
11 #:pkgname, "musl",
12 #:pkgver, "1.2.6",
13 #:pkgrel, release,
14 #:pkgdesc, "Vinix C runtime, development headers and GCC specs",
15 #:arch, [#:x86-64, #:aarch64],
16 #:url, "https://musl.libc.org/",
17 #:license, "MIT",
18 #:source, ["https://musl.libc.org/releases/musl-1.2.6.tar.gz",
19 "patches/handle-aux-at_base.patch",
20 "patches/0001-add-stub-for-pthread_mutexattr_setprioceiling.patch",
21 "patches/fix-loongarch64-zero-len-extcontext.patch",
22 "patches/CVE-2026-6042.patch",
23 "patches/CVE-2026-40200.patch",
24 "patches/malloc-retain.patch",
25 "https://raw.githubusercontent.com/alpinelinux/aports/284d827a2793963e6dcf88324bd1eb81adff579c/main/musl/__stack_chk_fail_local.c"],
26 #:sha256sums, ["d585fd3b613c66151fc3249e8ed44f77020cb5e6c1e635a616d3f9f82460512a",
27 "2a65e03b94217063d72fe998e5fb2e25cd01716078a3ba1b0ab574ab205111e6",
28 "b2067680c66af9eb9f4fdc1fa5d9337a9fd62bdab2c437b416aa97d79eb884ee",
29 "92c8e965798ed516c15cb2a4e7c4ac45ec1eb68b6abff16c73adff2a3bae1b14",
30 "1d0be2e72b9d5bd16546b923aa8af861d271322f01644716a81823bec4065c99",
31 "1ee29f64f9ca8e8ad7c349779d661ff6b52126a27575d3586981357a52c406fb",
32 "ec459e48e5c3c9946c91e805428149802d0ab1835c64e5e023811ab54a48af1d",
33 "299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da"],
34
35 #:prepare, fn() {
36 for-each(fn(patch) {
37 run("patch", "--batch", "--fuzz=0", "-d", "musl-1.2.6", "-p1", "-i", string-append("../", patch))
38 }, list("handle-aux-at_base.patch", "0001-add-stub-for-pthread_mutexattr_setprioceiling.patch",
39 "fix-loongarch64-zero-len-extcontext.patch", "CVE-2026-6042.patch",
40 "CVE-2026-40200.patch", "malloc-retain.patch"))
41 ; Match the x86-64 string routines selected by the Vinix system libc.
42 run("rm", "musl-1.2.6/src/string/x86_64/memcpy.s", "musl-1.2.6/src/string/x86_64/memmove.s")
43 },
44 #:build, fn() {
45 run("env", string-append("CC=", prefix, "gcc"), string-append("AR=", prefix, "ar"),
46 string-append("RANLIB=", prefix, "ranlib"), "CFLAGS=-fstack-protector-strong -DVINIX_MALLOC_RETAIN=1",
47 string-append("LDFLAGS=-Wl,-soname,libc.musl-", target-arch, ".so.1", page-flags), "musl-1.2.6/configure",
48 string-append("--target=", target-arch, "-linux-musl"), "--prefix=/usr", "--syslibdir=/lib", "--enable-wrapper=gcc",
49 "--enable-optimize=internal,malloc,malloc/mallocng/*.c,string")
50 run("make", "WRAPCC_GCC=gcc")
51 run(string-append(prefix, "gcc"), "-Os", "-fPIC", "-fno-stack-protector", "-c", "__stack_chk_fail_local.c", "-o", "__stack_chk_fail_local.o")
52 run(string-append(prefix, "ar"), "rcsD", "libssp_nonshared.a", "__stack_chk_fail_local.o")
53 },
54 #:package, fn() {
55 run("make", "install", string-append("DESTDIR=", pkgdir()))
56 run("install", "-m644", "libssp_nonshared.a", string-append(pkgdir(), "/usr/lib/libssp_nonshared.a"))
57 ; The SONAME, ELF interpreter and development linker name refer to one file.
58 loader-name := string-append("ld-musl-", target-arch, ".so.1")
59 loader := string-append(pkgdir(), "/lib/", loader-name)
60 devlib := string-append(pkgdir(), "/usr/lib/libc.so")
61 run("rm", loader)
62 run("mv", devlib, loader)
63 run("ln", "-s", loader-name, string-append(pkgdir(), "/lib/libc.musl-", target-arch, ".so.1"))
64 run("ln", "-s", string-append("../../lib/", loader-name), devlib)
65 ; Pass the sysroot to GNU ld as well, so absolute paths in target linker
66 ; scripts resolve inside the SDK. Keep the interpreter path guest-absolute.
67 specs := string-append(pkgdir(), "/usr/lib/musl-gcc-sysroot.specs")
68 native-specs := string-append(pkgdir(), "/usr/lib/musl-gcc.specs")
69 run("cp", string-append(pkgdir(), "/usr/lib/musl-gcc.specs"), specs)
70 run("sed", "-i", "-e", "s|/usr/include|%R/usr/include|g", "-e", "s|/usr/lib|%R/usr/lib|g",
71 "-e", "s|^-dynamic-linker |--sysroot=%R -dynamic-linker |", specs)
72 run("grep", "-F", "--", string-append("--sysroot=%R -dynamic-linker /lib/", loader-name), specs)
73 ; The arm64 kernel maps executable segments on 16 KiB pages.
74 if string=?(target-arch, "aarch64") {
75 ; Bootlin places a 4 KiB -Wl option after *link. A self spec appends the
76 ; target link option after those driver arguments, including -nostdlib.
77 run("sed", "-i", "1i%rename self_spec vinix_original_self_spec\\n\\n*self_spec:\\n%(vinix_original_self_spec) %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:-Wl,-z,max-page-size=16384}}}}}}\\n", native-specs, specs)
78 }
79 run("install", "-Dm644", "musl-1.2.6/COPYRIGHT", string-append(pkgdir(), "/usr/share/licenses/musl/COPYRIGHT"))
80 })
81