Github messages for voidlinux
 help / color / mirror / Atom feed
From: oreo639 <oreo639@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: [PR PATCH] [RFC] gobject-introspection: used elfutils lldwraper instead of prelink-cross
Date: Sat, 23 Mar 2024 00:56:49 +0100	[thread overview]
Message-ID: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-49468@inbox.vuxu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1576 bytes --]

There is a new pull request by oreo639 against master on the void-packages repository

https://github.com/oreo639/void-packages gi-cross
https://github.com/void-linux/void-packages/pull/49468

[RFC] gobject-introspection: used elfutils lldwraper instead of prelink-cross
Replace lldwraper with one maintained by Debian using elfutils. elfutils is already a dependency of glib.

https://salsa.debian.org/gnome-team/gobject-introspection/-/blob/debian/latest/debian/elf-get-needed.c
https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/482

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **briefly**

<!--
#### New package
- This new package conforms to the [package requirements](https://github.com/void-linux/void-packages/blob/master/CONTRIBUTING.md#package-requirements): **YES**|**NO**
-->

<!-- Note: If the build is likely to take more than 2 hours, please add ci skip tag as described in
https://github.com/void-linux/void-packages/blob/master/CONTRIBUTING.md#continuous-integration
and test at least one native build and, if supported, at least one cross build.
Ignore this section if this PR is not skipping CI.
-->
<!--
#### Local build testing
- I built this PR locally for my native architecture, (ARCH-LIBC)
- I built this PR locally for these architectures (if supported. mark crossbuilds):
  - aarch64-musl
  - armv7l
  - armv6l-musl
-->


A patch file from https://github.com/void-linux/void-packages/pull/49468.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-gi-cross-49468.patch --]
[-- Type: text/x-diff, Size: 9034 bytes --]

From 6d9428a001f7870e69735e51c41c689c1c72d454 Mon Sep 17 00:00:00 2001
From: oreo639 <oreo6391@gmail.com>
Date: Fri, 22 Mar 2024 16:47:54 -0700
Subject: [PATCH] gobject-introspection: used elfutils lldwraper instead of
 prelink-cross

Replace lldwraper with one maintained by Debian using elfutils.
elfutils is already a dependency of glib.

https://salsa.debian.org/gnome-team/gobject-introspection/-/blob/debian/latest/debian/elf-get-needed.c
https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/482
---
 .../files/elf-get-needed.c                    | 156 ++++++++++++++++++
 .../files/g-ir-scanner-lddwrapper             |   2 -
 ...-error-return-codes-from-ldd-wrapper.patch |  27 ---
 srcpkgs/gobject-introspection/template        |  14 +-
 4 files changed, 165 insertions(+), 34 deletions(-)
 create mode 100644 srcpkgs/gobject-introspection/files/elf-get-needed.c
 delete mode 100755 srcpkgs/gobject-introspection/files/g-ir-scanner-lddwrapper
 delete mode 100644 srcpkgs/gobject-introspection/patches/0006-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch

diff --git a/srcpkgs/gobject-introspection/files/elf-get-needed.c b/srcpkgs/gobject-introspection/files/elf-get-needed.c
new file mode 100644
index 00000000000000..be78f3bdf2a925
--- /dev/null
+++ b/srcpkgs/gobject-introspection/files/elf-get-needed.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright © 2019-2023 Collabora Ltd.
+ * SPDX-License-Identifier: MIT
+ *
+ * Use libelf to parse ELF headers for DT_NEEDED, and fake the output
+ * format of ldd closely enough that GObject-Introspection can parse it.
+ *
+ * Limitations when compared with real ldd:
+ * - Only direct dependencies are output: unlike ldd, this is not recursive.
+ *   For GObject-Introspection this is what we ideally want anyway.
+ * - Only bare SONAMEs are output, no paths or other extraneous information.
+ *
+ * https://salsa.debian.org/gnome-team/gobject-introspection/-/blob/debian/latest/debian/elf-get-needed.c
+ * https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/482
+ */
+
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <elf.h>
+#include <gelf.h>
+
+#if 0
+#define trace(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define trace(...) do {} while (0)
+#endif
+
+int
+main (int argc,
+      char **argv)
+{
+  const char *library;
+  Elf *elf = NULL;
+  Elf_Scn *scn = NULL;
+  GElf_Shdr shdr_mem;
+  GElf_Shdr *shdr = NULL;
+  size_t phnum;
+  size_t i;
+  Elf_Data *data;
+  uintptr_t needed_offset = (uintptr_t) -1;
+  const char *needed;
+  size_t sh_entsize;
+  int fd;
+
+  if (argc != 2)
+    {
+      fprintf (stderr, "Usage: %s LIBRARY\n", argv[0]);
+      return 2;
+    }
+
+  library = argv[1];
+
+  if (elf_version (EV_CURRENT) == EV_NONE)
+    {
+      perror ("elf_version(EV_CURRENT)");
+      return 1;
+    }
+
+  if ((fd = open (library, O_RDONLY | O_CLOEXEC, 0)) < 0)
+    {
+      perror (library);
+      return 1;
+    }
+
+  if ((elf = elf_begin (fd, ELF_C_READ, NULL)) == NULL)
+    {
+      fprintf (stderr, "Error reading library %s: %s",
+               library, elf_errmsg (elf_errno ()));
+      return 1;
+    }
+
+  if (elf_getphdrnum (elf, &phnum) < 0)
+    {
+
+      fprintf (stderr, "Unable to determine the number of program headers: %s\n",
+               elf_errmsg (elf_errno ()));
+
+      return 1;
+    }
+
+  trace ("phnum=%zu\n", phnum);
+
+  for (i = 0; i < phnum; i++)
+    {
+      GElf_Phdr phdr_mem;
+      GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
+
+      if (phdr != NULL && phdr->p_type == PT_DYNAMIC)
+        {
+          scn = gelf_offscn (elf, phdr->p_offset);
+          trace ("scn=%p\n", scn);
+
+          if (scn == NULL)
+            {
+              fprintf (stderr, "Unable to get the section: %s\n",
+
+                       elf_errmsg (elf_errno ()));
+
+              return 1;
+            }
+
+          shdr = gelf_getshdr (scn, &shdr_mem);
+          trace ("shdr=%p, shdr_mem=%p\n", shdr, &shdr_mem);
+
+          if (shdr == NULL)
+            {
+              fprintf (stderr, "Unable to get the section header: %s\n",
+
+                       elf_errmsg (elf_errno ()));
+
+              return 1;
+            }
+          break;
+        }
+    }
+
+  if (shdr == NULL)
+    {
+      fprintf (stderr, "Unable to find the section header\n");
+      return 1;
+    }
+
+  data = elf_getdata (scn, NULL);
+
+  if (data == NULL)
+    {
+      fprintf (stderr, "Unable to get the dynamic section data: %s\n",
+               elf_errmsg (elf_errno ()));
+
+      return 1;
+    }
+
+  trace ("data=%p\n", data);
+
+  sh_entsize = gelf_fsize (elf, ELF_T_DYN, 1, EV_CURRENT);
+  trace ("sh_entsize=%zu\n", sh_entsize);
+
+  for (i = 0; i < shdr->sh_size / sh_entsize; i++)
+    {
+      GElf_Dyn dyn_mem;
+      GElf_Dyn *dyn = gelf_getdyn (data, i, &dyn_mem);
+
+      if (dyn == NULL)
+        break;
+
+      if (dyn->d_tag == DT_NEEDED)
+        printf ("%s\n", elf_strptr (elf, shdr->sh_link, dyn->d_un.d_ptr));
+    }
+
+  elf_end (elf);
+  close (fd);
+  return 0;
+}
diff --git a/srcpkgs/gobject-introspection/files/g-ir-scanner-lddwrapper b/srcpkgs/gobject-introspection/files/g-ir-scanner-lddwrapper
deleted file mode 100755
index b969836b66422a..00000000000000
--- a/srcpkgs/gobject-introspection/files/g-ir-scanner-lddwrapper
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-/usr/bin/prelink-rtld --root=${XBPS_CROSS_BASE} "$@"
diff --git a/srcpkgs/gobject-introspection/patches/0006-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch b/srcpkgs/gobject-introspection/patches/0006-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch
deleted file mode 100644
index 9167f042e5b4e4..00000000000000
--- a/srcpkgs/gobject-introspection/patches/0006-giscanner-ignore-error-return-codes-from-ldd-wrapper.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From f128cbeead687bfc6532cc1f2cc3e2dc5a2b5b30 Mon Sep 17 00:00:00 2001
-From: Alexander Kanavin <alex.kanavin@gmail.com>
-Date: Wed, 5 Sep 2018 16:46:52 +0200
-Subject: [PATCH] giscanner: ignore error return codes from ldd-wrapper
-
-prelink-rtld, which we use instead of ldd returns 127 when it can't find a library.
-It is not an error per se, but it breaks subprocess.check_output().
-
-Upstream-Status: Inappropriate [oe-core specific]
-Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
----
- giscanner/shlibs.py | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/giscanner/shlibs.py b/giscanner/shlibs.py
-index 01d21a3..3bd3250 100644
---- a/giscanner/shlibs.py
-+++ b/giscanner/shlibs.py
-@@ -108,7 +108,7 @@ def _resolve_non_libtool(options, binary, libraries):
-             args.extend(['otool', '-L', binary.args[0]])
-         else:
-             args.extend(['ldd', binary.args[0]])
--        output = subprocess.check_output(args)
-+        output = subprocess.run(args, check=False, stdout=subprocess.PIPE).stdout
-         if isinstance(output, bytes):
-             output = output.decode("utf-8", "replace")
- 
diff --git a/srcpkgs/gobject-introspection/template b/srcpkgs/gobject-introspection/template
index 356646ced3117f..ed284572fc3f45 100644
--- a/srcpkgs/gobject-introspection/template
+++ b/srcpkgs/gobject-introspection/template
@@ -1,13 +1,13 @@
 # Template file for 'gobject-introspection'
 pkgname=gobject-introspection
 version=1.76.1
-revision=3
+revision=4
 build_style=meson
 pycompile_dirs="usr/lib/${pkgname}/giscanner"
 hostmakedepends="flex pkg-config"
 # won't run tests with cairo to avoid cyclical deps
-makedepends="libffi-devel libglib-devel python3-devel python3-Mako
- python3-Markdown"
+makedepends="libffi-devel libglib-devel python3-devel elfutils-devel
+ python3-Mako python3-Markdown"
 depends="libgirepository-devel python3-Mako python3-Markdown python3-setuptools"
 short_desc="Introspection system for GObject-based libraries"
 maintainer="Enno Boland <gottox@voidlinux.org>"
@@ -18,20 +18,24 @@ checksum=196178bf64345501dcdc4d8469b36aa6fe80489354efe71cb7cb8ab82a3738bf
 python_version=3
 
 if [ "$CROSS_BUILD" ]; then
-	hostmakedepends+=" gobject-introspection qemu-user-static prelink-cross"
+	hostmakedepends+=" gobject-introspection qemu-user-static"
 	configure_args+=" -Dgi_cross_use_prebuilt_gi=true
 	 -Dgi_cross_binary_wrapper=/usr/bin/g-ir-scanner-qemuwrapper
 	 -Dgi_cross_ldd_wrapper=/usr/bin/g-ir-scanner-lddwrapper
 	 -Dgi_cross_pkgconfig_sysroot_path=${XBPS_CROSS_BASE}"
 fi
 
+post_build() {
+	$CC $CFLAGS $LDFLAGS ${FILESDIR}/elf-get-needed.c -lelf -o elf-get-needed
+}
+
 post_install() {
 	rm ${DESTDIR}/usr/lib/gobject-introspection/giscanner/doctemplates/*/meson.build
 
 	# Install our wrappers system-wide, they are required for building all other
 	# gobject-based packages.
 	vbin ${FILESDIR}/g-ir-scanner-qemuwrapper
-	vbin ${FILESDIR}/g-ir-scanner-lddwrapper
+	vbin elf-get-needed g-ir-scanner-lddwrapper
 
 	# Install g-ir-scanner-wrapper as g-ir-scanner, we need it with that name since
 	# we can't expect people to just not hardcode /usr/bin/g-ir-scanner, some packages

             reply	other threads:[~2024-03-22 23:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 23:56 oreo639 [this message]
2024-03-22 23:57 ` [PR PATCH] [Updated] " oreo639
2024-03-23  0:06 ` [PR PATCH] [Updated] [RFC] gobject-introspection: use " oreo639
2024-03-24  9:06 ` oreo639
2024-04-10  7:06 ` [PR PATCH] [Updated] [RFC] gobject-introspection: use elfutils lddwraper " oreo639
2024-04-16  9:17 ` oreo639
2024-05-15 20:01 ` [PR PATCH] [Updated] " oreo639
2024-05-15 20:25 ` oreo639
2024-05-15 20:25 ` oreo639

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-49468@inbox.vuxu.org \
    --to=oreo639@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).