Re: Bug: build is broken on FreeBSD if libsysinfo is installed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 01/07/2025 17:05, Renato Botelho wrote:
> On 23/06/25 11:09, Renato Botelho wrote:
>> FreeBSD has a libsysinfo package which contains GNU libc's sysinfo port.   Some users reported git 2.50.0 was failing to build when this port is installed and it happened because configure script detected libsysinfo but -lsysinfo was not added to LDFLAGS, ending up with following error:
>>
>> scalar.o common-main.o libgit.a xdiff/lib.a reftable/libreftable.a libgit.a -lz -pthread
>> ld: error: undefined symbol: sysinfo
>>
>> This patch [1] was added to git port adding a user option to enable/ disable libsysinfo dependency and fix LDFLAGS when it's enabled.
>>
>> I'm not sure about what is best approach for git project in this case.
>>
>> [1] https://github.com/freebsd/freebsd-ports/blob/main/devel/git/files/ patch-configure.ac
> 
> If someone let me know what would be the desired approach here I can work on a patch.  Would you like to make that option conditional as the patch did?  Or detect if OS is FreeBSD and do something different?
> 

Ah, Sorry for the late reply, but I was away ... :)

Hmm, I can think of several approaches we could take, but I can't test any
of them (since I don't have access to a FreeBSD system).

- it would not be difficult to add a 'library-check' to the configure.ac
  file, so that '-lsysinfo' would be added to the link. (We would also
  have to make a similar change to meson.build). However, I don't think
  this is the right solution; I'm guessing that the compat sysinfo library
  is implemented in terms of sysctl() anyway, so ...

- we could simply change the order of the preprocessor conditionals in
  'builtin/gc.c' L530-541 so that the 'HAVE_SYSINFO' block comes after
  the 'HAVE_BSD_SYSCTL' block. (BTW, I assume that the HW_ symbols are
  defined whenever the 'sysinfo compat library' is installed; i.e. old
  versions of FreeBSD which don't define them are also too old to support
  the compat library).

- we could suppress the setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL has
  been defined (in both configure.ac and meson.build).

I very quickly knocked up a patch to do the last option above (I moved
the setting of HAVE_SYSINFO down the file rather that HAVE_BSD_SYSCTL
up. I guess it doesn't matter, but I gave it *no* thought!).

The patch is below. (I didn't write a commit message ;) ).

Does this work for you?

ATB,
Ramsay Jones

---- >8 ----
From: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 1 Jul 2025 20:33:44 +0100
Subject: [PATCH] build: fix FreeBSD sysinfo build failure

Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
---
 configure.ac | 61 ++++++++++++++++++++++++++++++----------------------
 meson.build  | 10 +++++----
 2 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/configure.ac b/configure.ac
index f6caab919a..bf710ac91a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1067,32 +1067,6 @@ AC_CHECK_LIB([iconv], [locale_charset],
                      [CHARSET_LIB=-lcharset])])
 GIT_CONF_SUBST([CHARSET_LIB])
 
-#
-# Define HAVE_SYSINFO=YesPlease if sysinfo is available.
-#
-AC_DEFUN([HAVE_SYSINFO_SRC], [
-AC_LANG_PROGRAM([[
-#include <stdint.h>
-#include <sys/sysinfo.h>
-]], [[
-struct sysinfo si;
-uint64_t t = 0;
-if (!sysinfo(&si)) {
-	t = si.totalram;
-	if (si.mem_unit > 1)
-		t *= (uint64_t)si.mem_unit;
-}
-return t;
-]])])
-
-AC_MSG_CHECKING([for sysinfo])
-AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],
-	[AC_MSG_RESULT([yes])
-	HAVE_SYSINFO=YesPlease],
-	[AC_MSG_RESULT([no])
-	HAVE_SYSINFO=])
-GIT_CONF_SUBST([HAVE_SYSINFO])
-
 #
 # Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.
 GIT_CHECK_FUNC(clock_gettime,
@@ -1221,6 +1195,41 @@ AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],
 	HAVE_BSD_SYSCTL=])
 GIT_CONF_SUBST([HAVE_BSD_SYSCTL])
 
+#
+# Define HAVE_SYSINFO=YesPlease if sysinfo is available.
+#
+
+HAVE_SYSINFO=
+# on a *BSD system, sysctl() takes precedence over the
+# sysinfo() compatibility library (if installed).
+
+if test -z "$HAVE_BSD_SYSCTL"; then
+
+  AC_DEFUN([HAVE_SYSINFO_SRC], [
+  AC_LANG_PROGRAM([[
+  #include <stdint.h>
+  #include <sys/sysinfo.h>
+  ]], [[
+  struct sysinfo si;
+  uint64_t t = 0;
+  if (!sysinfo(&si)) {
+	t = si.totalram;
+	if (si.mem_unit > 1)
+		t *= (uint64_t)si.mem_unit;
+  }
+  return t;
+  ]])])
+
+  AC_MSG_CHECKING([for sysinfo])
+  AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],
+	[AC_MSG_RESULT([yes])
+	HAVE_SYSINFO=YesPlease],
+	[AC_MSG_RESULT([no])
+	HAVE_SYSINFO=])
+  GIT_CONF_SUBST([HAVE_SYSINFO])
+
+fi
+
 ## Other checks.
 # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
 # Enable it on Windows.  By default, symrefs are still used.
diff --git a/meson.build b/meson.build
index 7fea4a34d6..355cad730c 100644
--- a/meson.build
+++ b/meson.build
@@ -1331,10 +1331,6 @@ if host_machine.system() != 'windows'
   endif
 endif
 
-if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')
-  libgit_c_args += '-DHAVE_SYSINFO'
-endif
-
 if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include <sys/stat.h>')
   libgit_c_args += '-DUSE_ST_TIMESPEC'
 elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include <sys/stat.h>')
@@ -1449,6 +1445,12 @@ if compiler.has_header('sys/sysctl.h')
   endif
 endif
 
+if not has_bsd_sysctl
+  if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')
+    libgit_c_args += '-DHAVE_SYSINFO'
+  endif
+endif
+
 if not meson.is_cross_build() and compiler.run('''
   #include <stdio.h>
 
-- 
2.50.0






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux