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
*** Bug 273800 has been marked as a duplicate of this bug. ***
Why not cut this out, like: https://bugs.freebsd.org/bugzilla/attachment.cgi?id=244903&action=diff ?
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273839#c1
Created attachment 247253 [details] patch
(In reply to Vladimir Druzenko from comment #0) Try this. I do not disable libelf linking, but force use system libelf.
(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.
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?
(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 ============================================================================================
Look like it fixed - maybe by upstream.
It's still grab libelf silently, but build without errors.
Just use attached patch :)
Created attachment 251937 [details] patch too stop looking for libelf.pc
(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.
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.
USES=localbase:ldflags is needed to locate libintl (NLS option support) and can't be taken out.
(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.
(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
(In reply to Ivan Rozhuk from comment #4) This patch prevent silent grab libelf from ports for me.
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.
No matter how it look (it is not tech metric), it work - only this is important.
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.
(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.
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.
(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.
(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.
(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.
(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.
(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.
Created attachment 259295 [details] patch
(In reply to Ivan Rozhuk from comment #29) Why not also do s|gelf.h|/usr/include/gelf.h| ?
(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>.
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(-)