; Alpine 3.21 binutils source and patches, producing native Vinix ELF tools. selected := get-environment-variable("VPAC_TARGET_ARCH") host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } arch := if string?(selected) { selected } else { host-arch } libc := if string=?(arch, "aarch64") { "musl>=1.2.6-4" } else { "musl" } ; Libtool leaves a shell launcher in the build tree for dynamically linked ; programs. Invoke the underlying target ELF with its freshly built DSOs. tool := fn(dir, name) { binary := string-append(dir, "/.libs/", name) if file-exists?(binary) { binary } else { string-append(dir, "/", name) } } check-tool := fn(dir, name, args) { apply(run, append(list("vinix-run", "--library-path", "bfd/.libs:opcodes/.libs:libctf/.libs:libsframe/.libs", tool(dir, name)), args)) } defpkgbuild(binutils, #:pkgname, "binutils", #:pkgver, "2.43.1", #:pkgrel, if string=?(arch, "aarch64") { 4 } else { 3 }, #:pkgdesc, "GNU assembler, linker, and binary utilities for Vinix", #:arch, [#:x86-64, #:aarch64], #:url, "https://www.gnu.org/software/binutils/", #:license, ["GPL-2.0-or-later", "LGPL-2.1-or-later", "BSD-3-Clause"], #:depends, list(libc, "zlib", "zstd", "jansson", "gcc-libs"), #:source, ["https://distfiles.alpinelinux.org/distfiles/v3.21/binutils-2.43.1.tar.xz", "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/binutils/0001-Revert-PR25882-.gnu.attributes-are-not-checked-for-s.patch", "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/binutils/binutils-ld-fix-static-linking.patch", "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/binutils/CVE-2025-0840.patch", "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/binutils/CVE-2025-1153.patch", "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/binutils/CVE-2025-3198.patch"], #:sha256sums, ["13f74202a3c4c51118b797a39ea4200d3f6cfbe224da6d1d95bb938480132dfd", "faba7b07cf02de228fa383bcaca339f8e7b70dec10ee3a5e08af5a8b82bc2ae6", "d5c5581d0ba04ef2e3690f6fb57435bf7ce343f2376fe972a2a693c5429eec9c", "2ab7a15b40dc7da6b93da96d9ba28b65be89db3338d4481c056a4e98a6be7aa1", "395450d49cc0059100d33622bc4e22f4c56f9313fd0c8a81c4facb6514536483", "ffe8d968ef8bfc682421756d24ad465636a359bb0a10a66943647e726f780640"], #:prepare, fn() { if string=?(arch, "aarch64") { ; The native Vinix AArch64 MMU uses 16 KiB pages. Set both BFD and ; gold defaults so direct linker users produce loadable segments. run("sed", "-i", "/^#define ELF_MAXPAGESIZE/s/0x10000/0x4000/; /^#define ELF_COMMONPAGESIZE/s/0x1000/0x4000/", "binutils-2.43.1/bfd/elfnn-aarch64.c") run("sed", "-i", "/abi_pagesize (overridable/s/0x10000/0x4000/; /common_pagesize (overridable/s/0x1000/0x4000/", "binutils-2.43.1/gold/aarch64.cc") } for-each(fn(p) { run("patch", "--batch", "--fuzz=1", "-p1", "-d", "binutils-2.43.1", "-i", string-append("../", p)) }, list("0001-Revert-PR25882-.gnu.attributes-are-not-checked-for-s.patch", "binutils-ld-fix-static-linking.patch", "CVE-2025-0840.patch", "CVE-2025-1153.patch", "CVE-2025-3198.patch")) }, #:build, fn() { prefix := get-environment-variable("CROSS_COMPILE") tools := if string?(prefix) { prefix } else { "" } ; When --target is omitted GNU configure uses --host, producing a ; native assembler and linker for the requested Vinix architecture. formats := if string=?(arch, "x86_64") { list("--enable-targets=x86_64-pep") } else { list() } apply(run, append(list("env", string-append("AR=", tools, "ar"), string-append("RANLIB=", tools, "ranlib"), string-append("NM=", tools, "nm"), string-append("AS=", tools, "as"), string-append("LD=", tools, "ld"), "CC_FOR_BUILD=gcc", "CFLAGS=-O2 -std=gnu17", "CXXCPP=vinix-cc -E -x c++", "vinix-configure", "binutils-2.43.1/configure", "--with-sysroot=/", "--with-system-zlib", "--with-zstd", "--enable-jansson", "--enable-gold", "--enable-ld=default", "--disable-gdb", "--disable-gprofng", "--disable-sim", "--disable-nls", "--disable-werror", "--disable-multilib", "--enable-libctf", "--enable-shared", "--enable-plugins", "--enable-install-libiberty", "--enable-64-bit-bfd", "--enable-deterministic-archives", "--enable-colored-disassembly", "--enable-default-execstack=no", "--enable-threads", "--with-pic", "--with-mmap", "--enable-new-dtags", "--enable-relro", "--enable-default-hash-style=gnu"), formats)) ; Binutils configures its subdirectories during make. Use the same SDK ; pkg-config paths that vinix-configure sets for the top-level script. root := get-environment-variable("VPAC_MAKEPKG_ROOT") run("env", string-append("PKG_CONFIG_SYSROOT_DIR=", root), string-append("PKG_CONFIG_LIBDIR=", root, "/usr/lib/pkgconfig:", root, "/usr/share/pkgconfig"), "PKG_CONFIG_PATH=", "make") }, #:check, fn() { call-with-output-file("debug-fixture.c", fn(port) { display("struct record { int number; };\nint twice(struct record r) { return r.number * 2; }\n", port) }) run("vinix-cc", "-gdwarf-4", "-gsplit-dwarf", "-c", "debug-fixture.c", "-o", "fixture.o") check-tool("gold", "dwp", list("fixture.dwo", "-o", "fixture.dwp")) check-tool("binutils", "objcopy", list("--dump-section", ".debug_cu_index=fixture.index", "fixture.dwp")) run("test", "-s", "fixture.index") run("vinix-cc", "-gctf", "-c", "debug-fixture.c", "-o", "ctf.o") check-tool("binutils", "objdump", list("--ctf=.ctf", "ctf.o")) check-tool("binutils", "objcopy", list("--compress-debug-sections=zstd", "fixture.o", "compressed.o")) if string=?(arch, "x86_64") { call-with-output-file("pe-start.s", fn(port) { display(".text\n.globl _start\n_start:\n xorl %eax, %eax\n ret\n", port) }) for-each(fn(bits, format, emulation) { check-tool("gas", "as-new", list(string-append("--", bits), "-o", "pe-start.o", "pe-start.s")) check-tool("binutils", "objcopy", list("-O", format, "pe-start.o", "pe-start.obj")) script := string-append("ld/ldscripts/", emulation, ".x") check-tool("ld", "ld-new", list("-m", emulation, "-T", script, "--entry", "_start", "-o", "pe-start.exe", "pe-start.obj")) check-tool("binutils", "objdump", list("-f", "pe-start.exe")) }, list("32", "64"), list("pe-i386", "pe-x86-64"), list("i386pe", "i386pep")) } else { call-with-output-file("abi-start.s", fn(port) { display(".text\n.global _start\n_start:\n mov x0, #0\n mov x8, #93\n svc #0\n", port) }) check-tool("gas", "as-new", list("-o", "abi-start.o", "abi-start.s")) for-each(fn(dir, name) { check-tool(dir, name, list("-o", "abi-start", "abi-start.o")) run("vinix-elf-pages", "aarch64", "abi-start") }, list("ld", "gold"), list("ld-new", "ld-new")) } }, #:package, fn() { run("make", string-append("DESTDIR=", pkgdir()), "install") run("rm", "-f", string-append(pkgdir(), "/usr/share/info/dir")) for-each(fn(la) { run("rm", la) }, glob(string-append(pkgdir(), "/usr/lib/*.la"))) for-each(fn(lib) { run("test", "-f", string-append(pkgdir(), "/usr/lib/", lib)) }, list("bfd-plugins/libdep.so", "libbfd-2.43.1.so", "libctf-nobfd.so.0", "libctf-nobfd.so.0.0.0", "libctf.so.0", "libctf.so.0.0.0", "libopcodes-2.43.1.so", "libsframe.so.1", "libsframe.so.1.0.0")) run("test", "-x", string-append(pkgdir(), "/usr/bin/dwp")) if string=?(arch, "x86_64") { for-each(fn(emulation) { for-each(fn(suffix) { run("test", "-s", string-append(pkgdir(), "/usr/x86_64-linux-musl/lib/ldscripts/", emulation, suffix)) }, list(".x", ".xa", ".xbn", ".xe", ".xer", ".xn", ".xr", ".xu")) }, list("i386pe", "i386pep")) } run("install", "-Dm644", "binutils-2.43.1/COPYING3", string-append(pkgdir(), "/usr/share/licenses/binutils/COPYING3")) })