Bug 273479 - devel/glib20: silent grab libelf.so.1 from devel/elfutils
Summary: devel/glib20: silent grab libelf.so.1 from devel/elfutils
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
: 273800 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-08-31 13:43 UTC by Vladimir Druzenko
Modified: 2025-04-24 08:49 UTC (History)
6 users (show)

See Also:
arrowd: maintainer-feedback+


Attachments
patch (1.15 KB, patch)
2023-12-26 03:28 UTC, Ivan Rozhuk
no flags Details | Diff
patch too stop looking for libelf.pc (1.03 KB, patch)
2024-07-08 15:17 UTC, Baptiste Daroussin
no flags Details | Diff
patch (1.15 KB, patch)
2025-04-03 13:38 UTC, Ivan Rozhuk
rozhuk.im: maintainer-approval?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Druzenko freebsd_committer freebsd_triage 2023-08-31 13:43:28 UTC
13.2 amd64.
devel/glib20 silent grab libelf.so.1 if devel/elfutils installed.
MESON_ARGS+= -Dlibelf=disabled didn't help.

This upstream issue look like it's related:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3335
Comment 1 Vladimir Druzenko freebsd_committer freebsd_triage 2023-09-15 01:32:54 UTC
*** Bug 273800 has been marked as a duplicate of this bug. ***
Comment 2 Ivan Rozhuk 2023-09-15 21:08:28 UTC
Why not cut this out, like: https://bugs.freebsd.org/bugzilla/attachment.cgi?id=244903&action=diff ?
Comment 4 Ivan Rozhuk 2023-12-26 03:28:17 UTC
Created attachment 247253 [details]
patch
Comment 5 Ivan Rozhuk 2023-12-26 03:29:14 UTC
(In reply to Vladimir Druzenko from comment #0)
Try this.
I do not disable libelf linking, but force use system libelf.
Comment 6 Vladimir Druzenko freebsd_committer freebsd_triage 2023-12-26 14:34:52 UTC
(In reply to Ivan Rozhuk from comment #5)
[ 84% 503/592] cc -Igio/gresource.p -Igio -I../gio -I. -I.. -Iglib -I../glib -Igmodule -I../gmodule -Igobject -I../gobject -fdiagnostics-color=never -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -DG_ENABLE_DEBUG -Wimplicit-fallthrough -Wmisleading-indentation -Wmissing-field-initializers -Wnonnull -Wunused -Wno-unused-parameter -Wno-cast-function-type -Wno-pedantic -Wno-format-zero-length -Wno-variadic-macros -Werror=format=2 -Werror=init-self -Werror=missing-include-dirs -Werror=pointer-arith -Werror=unused-result -Wstrict-prototypes -Wno-bad-function-cast -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=pointer-sign -Wno-string-plus-int -O2 -pipe -march=core2 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -isystem /usr/local/include -MD -MQ gio/gresource.p/gresource-tool.c.o -MF gio/gresource.p/gresource-tool.c.o.d -o gio/gresource.p/gresource-tool.c.o -c ../gio/gresource-tool.c
FAILED: gio/gresource.p/gresource-tool.c.o
cc -Igio/gresource.p -Igio -I../gio -I. -I.. -Iglib -I../glib -Igmodule -I../gmodule -Igobject -I../gobject -fdiagnostics-color=never -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -DG_ENABLE_DEBUG -Wimplicit-fallthrough -Wmisleading-indentation -Wmissing-field-initializers -Wnonnull -Wunused -Wno-unused-parameter -Wno-cast-function-type -Wno-pedantic -Wno-format-zero-length -Wno-variadic-macros -Werror=format=2 -Werror=init-self -Werror=missing-include-dirs -Werror=pointer-arith -Werror=unused-result -Wstrict-prototypes -Wno-bad-function-cast -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=pointer-sign -Wno-string-plus-int -O2 -pipe -march=core2 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -isystem /usr/local/include -MD -MQ gio/gresource.p/gresource-tool.c.o -MF gio/gresource.p/gresource-tool.c.o.d -o gio/gresource.p/gresource-tool.c.o -c ../gio/gresource-tool.c
../gio/gresource-tool.c:176:38: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
typedef gboolean (*SectionCallback) (GElf_Shdr   *shdr,
                                     ^~~~~~~~~
                                     Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
../gio/gresource-tool.c:189:3: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
  GElf_Shdr *shdr, shdr_mem;
  ^~~~~~~~~
  Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
../gio/gresource-tool.c:204:14: error: implicit declaration of function 'gelf_getshdr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      shdr = gelf_getshdr (scn, &shdr_mem);
             ^
../gio/gresource-tool.c:204:12: warning: incompatible integer to pointer conversion assigning to 'Elf_Nhdr *' (aka 'Elf_Note *') from 'int' [-Wint-conversion]
      shdr = gelf_getshdr (scn, &shdr_mem);
           ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gio/gresource-tool.c:208:17: error: no member named 'sh_type' in 'Elf_Note'; did you mean 'n_type'?
      if (shdr->sh_type != SHT_PROGBITS)
                ^~~~~~~
                n_type
/usr/include/sys/elf_common.h:53:12: note: 'n_type' declared here
        u_int32_t       n_type;         /* Type of this note. */
                        ^
../gio/gresource-tool.c:211:55: error: no member named 'sh_name' in 'Elf_Note'
      section_name = elf_strptr (elf, shstrndx, shdr->sh_name);
                                                ~~~~  ^
../gio/gresource-tool.c:222:24: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
resource_from_section (GElf_Shdr *shdr,
                       ^~~~~~~~~
                       Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
../gio/gresource-tool.c:232:23: error: no member named 'sh_offset' in 'Elf_Note'
  page_offset = shdr->sh_offset % page_size;
                ~~~~  ^
../gio/gresource-tool.c:233:33: error: no member named 'sh_size' in 'Elf_Note'
  contents = mmap (NULL,  shdr->sh_size + page_offset,
                          ~~~~  ^
../gio/gresource-tool.c:234:54: error: no member named 'sh_offset' in 'Elf_Note'
                   PROT_READ, MAP_PRIVATE, fd, shdr->sh_offset - page_offset);
                                               ~~~~  ^
../gio/gresource-tool.c:240:65: error: no member named 'sh_size' in 'Elf_Note'
      bytes = g_bytes_new_static (contents + page_offset, shdr->sh_size);
                                                          ~~~~  ^
../gio/gresource-tool.c:267:20: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
list_resources_cb (GElf_Shdr   *shdr,
                   ^~~~~~~~~
                   Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
../gio/gresource-tool.c:314:22: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
extract_resource_cb (GElf_Shdr   *shdr,
                     ^~~~~~~~~
                     Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
../gio/gresource-tool.c:356:21: error: unknown type name 'GElf_Shdr'; did you mean 'Elf_Nhdr'?
print_section_name (GElf_Shdr   *shdr,
                    ^~~~~~~~~
                    Elf_Nhdr
/usr/include/sys/elf_common.h:55:18: note: 'Elf_Nhdr' declared here
typedef Elf_Note Elf_Nhdr;
                 ^
1 warning and 13 errors generated.
Comment 7 Vladimir Druzenko freebsd_committer freebsd_triage 2023-12-26 14:43:42 UTC
Ignore last message - it was without 1st patch of the patch.

But why do you need 2nd part of the patch if 1st part turns off libelf completely?
Comment 8 Ivan Rozhuk 2023-12-30 16:36:23 UTC
(In reply to Vladimir Druzenko from comment #7)

It does not.
gio/meson.build:
============================================================================================
# Dependencies used by executables below
have_libelf = false
libelf = dependency('libelf', version : '>= 0.8.12', required : false)
if libelf.found() and get_option('libelf').allowed()
  have_libelf = true
else
  # This fallback is necessary on *BSD. elfutils isn't the only libelf
  # implementation, and *BSD usually includes their own libelf as a system
  # library which doesn't have a corresponding .pc file.
  libelf = cc.find_library('elf', required : get_option ('libelf'))
  have_libelf = libelf.found()
  have_libelf = have_libelf and cc.has_function('elf_begin', dependencies : libelf)
  have_libelf = have_libelf and cc.has_function('elf_getshdrstrndx', dependencies : libelf)
  have_libelf = have_libelf and cc.has_function('elf_getshdrnum', dependencies : libelf)
  have_libelf = have_libelf and cc.has_header('libelf.h')
endif

if have_libelf
  glib_conf.set('HAVE_LIBELF', 1)
else
  libelf = []
endif
============================================================================================
Comment 9 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-03 19:48:14 UTC
Look like it fixed - maybe by upstream.
Comment 10 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-08 11:05:48 UTC
It's still grab libelf silently, but build without errors.
Comment 11 Ivan Rozhuk 2024-07-08 14:15:43 UTC
Just use attached patch :)
Comment 12 Baptiste Daroussin freebsd_committer freebsd_triage 2024-07-08 15:17:49 UTC
Created attachment 251937 [details]
patch too stop looking for libelf.pc
Comment 13 Ivan Rozhuk 2024-07-08 15:25:57 UTC
(In reply to Baptiste Daroussin from comment #12)
Are you sure that glib will use includes from base libelf with this patch?
As far I understand this patch do same as: -Dlibelf=disabled in makrfile.
Comment 14 Baptiste Daroussin freebsd_committer freebsd_triage 2024-07-08 15:50:04 UTC
this patch does not do the same as -Dlibelf=disabled it probably continues readying at the elf.h headers due to the use (which seems useless to me here) of USES=localbase:ldflags
Uses=localbase will force -isystem /usr/local/include which will put this path in the first path to look for headers, meaning libelf.h will be taken from there if found.

Removing the USES=localbase:ldflags works fine for me locally and this way I am sure elf.h is picked up from base.
Comment 15 Gleb Popov freebsd_committer freebsd_triage 2024-07-08 16:26:56 UTC
USES=localbase:ldflags is needed to locate libintl (NLS option support) and can't be taken out.
Comment 16 Ivan Rozhuk 2024-07-08 16:58:19 UTC
(In reply to Baptiste Daroussin from comment #14)
get_option('libelf').allowed() - reads -Dlibelf=disabled and return FALSE.


> Removing the USES=localbase:ldflags works fine for me locally and this way I am sure elf.h is picked up from base.

Did you check this?
Change /usr/local/include/libelf.h to it became invalid and try to build glib20.
Do not remove or move it, only change.
Comment 17 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-09 13:43:09 UTC
(In reply to Baptiste Daroussin from comment #12)
Build with your patch:
====> Compressing man pages (compress-man)
====> Running Q/A tests (stage-qa)
Error: /usr/local/bin/gresource is linked to /usr/local/lib/libelf.so.1 from devel/elfutils but it is not declared as a dependency
Warning: you need LIB_DEPENDS+=libelf.so:devel/elfutils
Comment 18 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-09 14:19:59 UTC
(In reply to Ivan Rozhuk from comment #4)
This patch prevent silent grab libelf from ports for me.
Comment 19 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-19 22:25:51 UTC
If the patch didn’t look like such a workaround (hack), then I would have already committed it as “maintainer timeout”. But at the same time, the current situation is also not satisfactory. Let's make a decision.
Comment 20 Ivan Rozhuk 2024-07-19 22:31:45 UTC
No matter how it look (it is not tech metric), it work - only this is important.
Comment 21 Gleb Popov freebsd_committer freebsd_triage 2024-07-20 07:48:49 UTC
If I understand it right, the problem does not manifest itself when building in Poudriere (in a clean env)? If so, I'd restrain from committing hacks that fix on-host builds.
Comment 22 Ivan Rozhuk 2024-07-21 00:13:40 UTC
(In reply to Gleb Popov from comment #21)
1. Some peoples wont use Poudriere to build ports.
2. There is no rule to always use only Poudriere to build ports.
3. Calling a patch a hack is not an argument in the discussion.
Comment 23 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-21 11:27:02 UTC
But if we approach the question from the other side: does the patch break anything for those who build glib in poudriere? If not, then I see no reason not to use it. At least until a more “beautiful” patch or fixes appear in upstream.
Comment 24 Gleb Popov freebsd_committer freebsd_triage 2024-07-21 14:48:31 UTC
(In reply to Ivan Rozhuk from comment #22)
> 1. Some peoples wont use Poudriere to build ports.
> 2. There is no rule to always use only Poudriere to build ports.

Building on host is unsupported means that committers are not obliged to make sure the port compiles outside of Poudriere. They are as well not required to do any works towards this goal. At the same time working build in Poudriere is a requirement - a committer is not allowed to push a change that doesn't build cleanly in a jail.

Actually, putting an absolute path into #include might work, I'll look into it. But why pass -Dlibelf=false to Meson? This effectively disables libelf.h inclusion, so all other patching is useless.
Comment 25 Ivan Rozhuk 2024-07-21 14:57:04 UTC
(In reply to Gleb Popov from comment #24)

> Building on host is unsupported means that committers are not obliged to make sure the port compiles outside of Poudriere. They are as well not required to do any works towards this goal.

Is there any document to proof this?


> But why pass -Dlibelf=false to Meson?

See comment #7, it was discussed.
Comment 26 Vladimir Druzenko freebsd_committer freebsd_triage 2024-07-21 15:01:30 UTC
(In reply to Gleb Popov from comment #24)
> Building on host is unsupported means that committers are not obliged to make sure the port compiles outside of Poudriere. They are as well not required to do any works towards this goal.
Disagree. Problems when building a port on a live system are a maintainer error.
Comment 27 Gleb Popov freebsd_committer freebsd_triage 2024-07-21 15:18:45 UTC
(In reply to Ivan Rozhuk from comment #25)
> Is there any document to proof this?

None I'm aware of, but you can ask portmgr@ about this, they stated it multiple times.

> See comment #7, it was discussed.

Just copying the code block does not answer it. I found this code as well and it is still not clear to me why the option should be turned off.

(In reply to Vladimir Druzenko from comment #26)
You are free to fix ports you maintain to build on live system (I also do that for some extent), but you can't request it from another committer. This is again what portmgr@ says, it is not just my opinion.
Comment 28 Ivan Rozhuk 2024-07-21 15:49:12 UTC
(In reply to Gleb Popov from comment #27)

I do not care what some persons may say in portmgr@, if this is project official position - update handbook.


Than it turned off then code always go to "# This fallback is necessary on *BSD. elfutils isn't the only libelf" code path.
I do not remember details, I just fix and forget as not important to me.
Comment 29 Ivan Rozhuk 2025-04-03 13:38:25 UTC
Created attachment 259295 [details]
patch
Comment 30 Gleb Popov freebsd_committer freebsd_triage 2025-04-03 14:33:15 UTC
(In reply to Ivan Rozhuk from comment #29)
Why not also do s|gelf.h|/usr/include/gelf.h| ?
Comment 31 Ivan Rozhuk 2025-04-03 19:47:57 UTC
(In reply to Gleb Popov from comment #30)

As pointed in comment: "gelf.h includes <libelf.h> so remove it to avoid conflict between </usr/include/libelf.h> and <libelf.h>=/usr/local/include/libelf.h."

So if I keep /usr/include/gelf.h - I must also patch it to force include </usr/include/libelf.h>.
Comment 32 commit-hook freebsd_committer freebsd_triage 2025-04-24 08:47:16 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8107e8e7cb0b549bdc4789a52e69015cd64b7b8d

commit 8107e8e7cb0b549bdc4789a52e69015cd64b7b8d
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2025-04-24 08:12:15 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2025-04-24 08:45:47 +0000

    devel/glib20: Prevent the silent grabbing of libelf from ports

    PR:             273479

 devel/glib20/Makefile                               |  3 ++-
 devel/glib20/files/patch-gio_gresource-tool.c (new) | 15 +++++++++++++++
 devel/glib20/files/patch-gio_meson.build (new)      | 11 +++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)