From 140a984310f42610162369496206636cb61e3298 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 04:07:17 +0100 Subject: [PATCH] Package and cold-test the ELF library required by Mesa --- libelf/PKGBUILD.vile | 49 ++++++++++++++++++++++++++++++++++++++++++++ libelf/check.v | 26 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 libelf/PKGBUILD.vile create mode 100644 libelf/check.v diff --git a/libelf/PKGBUILD.vile b/libelf/PKGBUILD.vile new file mode 100644 index 0000000..32e5741 --- /dev/null +++ b/libelf/PKGBUILD.vile @@ -0,0 +1,49 @@ +defpkgbuild(libelf, + #:pkgname, "libelf", + #:pkgver, "0.191", + #:pkgrel, 2, + #:pkgdesc, "Read, create and modify ELF objects with the elfutils library", + #:arch, [#:x86-64, #:aarch64], + #:url, "https://sourceware.org/elfutils/", + #:license, "GPL-3.0-or-later AND (GPL-2.0-or-later OR LGPL-3.0-or-later)", + #:depends, ["musl", "bzip2", "xz", "zlib", "zstd"], + #:makedepends, ["argp-standalone", "bsd-compat-headers", "linux-headers", "musl-fts", "musl-obstack", "musl-legacy-error"], + #:source, ["https://sourceware.org/elfutils/ftp/0.191/elfutils-0.191.tar.bz2", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/fix-aarch64_fregs.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/fix-uninitialized.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/musl-macros.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/musl-asm-ptrace-h.patch", "check.v"], + #:sha256sums, ["df76db71366d1d708365fc7a6c60ca48398f14367eb2b8954efc8897147ad871", + "a5b131c65927da751aae47a476f26e59ce53300777d54aef6c65c1eceef1a12d", + "ee94f9ab26049f8100db1b6bfc760454f5a220190a5eb907faee65129ec9e962", + "8e3924f08d4af34a45d0059224ea42b7afdc43837d053243e855cdaf295dde67", + "f03d703dc76002413f4cd04e82c1da79365885df65fbd4eb660f1de42ee41ba9", + "f7274e98c3813baabf0bcdbe57c6c85ba1dbfc3dd73654b827c61f7cc5e7de20"], + #:prepare, fn() { + for-each(fn(file) { + run("patch", "--batch", "-d", "elfutils-0.191", "-p1", "-i", string-append("../", file)) + }, list("fix-aarch64_fregs.patch", "fix-uninitialized.patch", "musl-macros.patch", "musl-asm-ptrace-h.patch")) + }, + #:build, fn() { + run("env", "CFLAGS=-O2 -D_GNU_SOURCE -Wno-error -Wno-null-dereference", "vinix-configure", "elfutils-0.191/configure", + "--disable-nls", "--disable-demangler", "--disable-libdebuginfod", "--disable-debuginfod", "--with-zstd") + run("make", "-C", "lib") + run("make", "-C", "libelf") + }, + #:check, fn() { + target := get-environment-variable("VPAC_TARGET_ARCH") + arch := if string?(target) { + if string=?("aarch64", target) { "arm64" } else { "amd64" } + } else if memq(string->symbol("aarch64"), features()) { "arm64" } else { "amd64" } + run("v", "-os", "linux", "-arch", arch, "-d", "musl", "-d", "no_backtrace", "-d", "no_segfault_handler", "-gc", "none", "-o", "check.c", "check.v") + run("vinix-cc", "-Ielfutils-0.191/libelf", "check.c", "-Llibelf", "-lelf", + string-append("-Wl,-rpath-link,", get-environment-variable("VPAC_MAKEPKG_ROOT"), "/usr/lib"), "-o", "check") + run("vinix-run", "--library-path", "libelf", "check", "libelf/libelf.so") + }, + #:package, fn() { + run("make", "-C", "libelf", "install", string-append("DESTDIR=", pkgdir())) + run("install", "-Dm644", "config/libelf.pc", string-append(pkgdir(), "/usr/lib/pkgconfig/libelf.pc")) + for-each(fn(file) { + run("install", "-Dm644", string-append("elfutils-0.191/", file), string-append(pkgdir(), "/usr/share/licenses/libelf/", file)) + }, list("COPYING", "COPYING-GPLV2", "COPYING-LGPLV3")) + }) diff --git a/libelf/check.v b/libelf/check.v new file mode 100644 index 0000000..98c780c --- /dev/null +++ b/libelf/check.v @@ -0,0 +1,26 @@ +module main + +import os + +#include +#include + +fn C.elf_version(u32) u32 +fn C.elf_memory(&char, usize) voidptr +fn C.elf_kind(voidptr) int +fn C.gelf_getclass(voidptr) int +fn C.elf_getshdrnum(voidptr, &usize) int +fn C.elf_end(voidptr) int + +fn main() { + bytes := os.read_bytes(os.args[1]) or { panic(err) } + assert C.elf_version(C.EV_CURRENT) == C.EV_CURRENT + elf := C.elf_memory(unsafe { &char(bytes.data) }, usize(bytes.len)) + assert !isnil(elf) + defer { C.elf_end(elf) } + assert C.elf_kind(elf) == C.ELF_K_ELF + assert C.gelf_getclass(elf) == C.ELFCLASS64 + mut sections := usize(0) + assert C.elf_getshdrnum(elf, §ions) == 0 && sections > 0 + println('libelf read ${sections} section headers from ${os.args[1]}') +} -- 2.56.1