me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Package and cold-test the ELF library required by Mesa

diviocity committed 5 days ago · 140a984310f42610162369496206636cb61e3298 View patch
Unverified signature 2 files changed +75 -0
libelf/PKGBUILD.vile new file +49 -0

@@ -0,0 +1,49 @@

1+defpkgbuild(libelf,

2+ #:pkgname, "libelf",

3+ #:pkgver, "0.191",

4+ #:pkgrel, 2,

5+ #:pkgdesc, "Read, create and modify ELF objects with the elfutils library",

6+ #:arch, [#:x86-64, #:aarch64],

7+ #:url, "https://sourceware.org/elfutils/",

8+ #:license, "GPL-3.0-or-later AND (GPL-2.0-or-later OR LGPL-3.0-or-later)",

9+ #:depends, ["musl", "bzip2", "xz", "zlib", "zstd"],

10+ #:makedepends, ["argp-standalone", "bsd-compat-headers", "linux-headers", "musl-fts", "musl-obstack", "musl-legacy-error"],

11+ #:source, ["https://sourceware.org/elfutils/ftp/0.191/elfutils-0.191.tar.bz2",

12+ "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/fix-aarch64_fregs.patch",

13+ "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/fix-uninitialized.patch",

14+ "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/musl-macros.patch",

15+ "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/elfutils/musl-asm-ptrace-h.patch", "check.v"],

16+ #:sha256sums, ["df76db71366d1d708365fc7a6c60ca48398f14367eb2b8954efc8897147ad871",

17+ "a5b131c65927da751aae47a476f26e59ce53300777d54aef6c65c1eceef1a12d",

18+ "ee94f9ab26049f8100db1b6bfc760454f5a220190a5eb907faee65129ec9e962",

19+ "8e3924f08d4af34a45d0059224ea42b7afdc43837d053243e855cdaf295dde67",

20+ "f03d703dc76002413f4cd04e82c1da79365885df65fbd4eb660f1de42ee41ba9",

21+ "f7274e98c3813baabf0bcdbe57c6c85ba1dbfc3dd73654b827c61f7cc5e7de20"],

22+ #:prepare, fn() {

23+ for-each(fn(file) {

24+ run("patch", "--batch", "-d", "elfutils-0.191", "-p1", "-i", string-append("../", file))

25+ }, list("fix-aarch64_fregs.patch", "fix-uninitialized.patch", "musl-macros.patch", "musl-asm-ptrace-h.patch"))

26+ },

27+ #:build, fn() {

28+ run("env", "CFLAGS=-O2 -D_GNU_SOURCE -Wno-error -Wno-null-dereference", "vinix-configure", "elfutils-0.191/configure",

29+ "--disable-nls", "--disable-demangler", "--disable-libdebuginfod", "--disable-debuginfod", "--with-zstd")

30+ run("make", "-C", "lib")

31+ run("make", "-C", "libelf")

32+ },

33+ #:check, fn() {

34+ target := get-environment-variable("VPAC_TARGET_ARCH")

35+ arch := if string?(target) {

36+ if string=?("aarch64", target) { "arm64" } else { "amd64" }

37+ } else if memq(string->symbol("aarch64"), features()) { "arm64" } else { "amd64" }

38+ run("v", "-os", "linux", "-arch", arch, "-d", "musl", "-d", "no_backtrace", "-d", "no_segfault_handler", "-gc", "none", "-o", "check.c", "check.v")

39+ run("vinix-cc", "-Ielfutils-0.191/libelf", "check.c", "-Llibelf", "-lelf",

40+ string-append("-Wl,-rpath-link,", get-environment-variable("VPAC_MAKEPKG_ROOT"), "/usr/lib"), "-o", "check")

41+ run("vinix-run", "--library-path", "libelf", "check", "libelf/libelf.so")

42+ },

43+ #:package, fn() {

44+ run("make", "-C", "libelf", "install", string-append("DESTDIR=", pkgdir()))

45+ run("install", "-Dm644", "config/libelf.pc", string-append(pkgdir(), "/usr/lib/pkgconfig/libelf.pc"))

46+ for-each(fn(file) {

47+ run("install", "-Dm644", string-append("elfutils-0.191/", file), string-append(pkgdir(), "/usr/share/licenses/libelf/", file))

48+ }, list("COPYING", "COPYING-GPLV2", "COPYING-LGPLV3"))

49+ })

libelf/check.v new file +26 -0

@@ -0,0 +1,26 @@

1+module main

2+

3+import os

4+

5+#include <libelf.h>

6+#include <gelf.h>

7+

8+fn C.elf_version(u32) u32

9+fn C.elf_memory(&char, usize) voidptr

10+fn C.elf_kind(voidptr) int

11+fn C.gelf_getclass(voidptr) int

12+fn C.elf_getshdrnum(voidptr, &usize) int

13+fn C.elf_end(voidptr) int

14+

15+fn main() {

16+ bytes := os.read_bytes(os.args[1]) or { panic(err) }

17+ assert C.elf_version(C.EV_CURRENT) == C.EV_CURRENT

18+ elf := C.elf_memory(unsafe { &char(bytes.data) }, usize(bytes.len))

19+ assert !isnil(elf)

20+ defer { C.elf_end(elf) }

21+ assert C.elf_kind(elf) == C.ELF_K_ELF

22+ assert C.gelf_getclass(elf) == C.ELFCLASS64

23+ mut sections := usize(0)

24+ assert C.elf_getshdrnum(elf, &sections) == 0 && sections > 0

25+ println('libelf read ${sections} section headers from ${os.args[1]}')

26+}