NetBSD Problem Report #56186

From www@netbsd.org  Tue May 18 12:37:28 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B79931A92B3
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 18 May 2021 12:37:28 +0000 (UTC)
Message-Id: <20210518123727.59D531A92B4@mollari.NetBSD.org>
Date: Tue, 18 May 2021 12:37:27 +0000 (UTC)
From: lehel.bernadt@oneidentity.com
Reply-To: lehel.bernadt@oneidentity.com
To: gnats-bugs@NetBSD.org
Subject: libarchive: fix dirfd() check
X-Send-Pr-Version: www-1.0

>Number:         56186
>Category:       pkg
>Synopsis:       libarchive: fix dirfd() check
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 18 12:40:00 +0000 2021
>Last-Modified:  Sun May 23 21:00:01 +0000 2021
>Originator:     Lehel Bernadt
>Release:        2021Q1
>Organization:
One Identity
>Environment:
AIX 6.1
>Description:
I was trying to build software on AIX 6.1 that pulled in archivers/libarchive, for which the linking failed with undefined symbol .dirfd. It turns out AIX 6.1 is missing some of the POSIX.2008 functionality, including the dirfd() call. This would be handled by libarchive, but the feature is misdetected by the configure script:
========================
configure:18166: gcc -c -maix64 -pthread -Wall -Wformat -Wformat-security -I/usr/pkgsrc/archivers/bsdtar/work/bzip2 -I/usr/pkgsrc/archivers/bsdtar/work/zlib conftest.c >&5
conftest.c: In function 'main':
conftest.c:174:8: warning: implicit declaration of function 'dirfd' [-Wimplicit-function-declaration]
 return(dirfd(dir));
        ^~~~~
configure:18166: $? = 0
========================

This is because configure.ac calls AC_COMPILE_IFELSE, which attempts only a compilation where the lack of declaration results in just a warning.
If I replace this with AC_LINK_IFELSE which does the linking phase as well, the detection becomes correct:
========================
configure:19228: gcc -o conftest -maix64 -pthread -Wall -Wformat -Wformat-security -I/usr/pkgsrc/archivers/bsdtar/work/bzip2 -I/usr/pkgsrc/archivers/bsdtar/work/zlib -maix64
-pthread -Wl,-bsvr4 -Wl,-bnoexpfull -L/usr/pkgsrc/archivers/bsdtar/work/bzip2 -L/usr/pkgsrc/archivers/bsdtar/work/zlib -Wl,-R/usr/pkg/lib conftest.c -lbz2 -lz  >&5
conftest.c: In function 'main':
conftest.c:186:8: warning: implicit declaration of function 'dirfd' [-Wimplicit-function-declaration]
 return(dirfd(dir));
        ^~~~~
ld: 0711-317 ERROR: Undefined symbol: .dirfd
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
configure:19228: $? = 1
========================

In CMakeLists.txt this seems to be handled correctly, as it calls CHECK_C_SOURCE_COMPILES which according to the cmake documentation compiles & links the test program.
>How-To-Repeat:

>Fix:
The patch:
=========================
diff --git a/archivers/libarchive/files/configure.ac b/archivers/libarchive/files/configure.ac
index e73985846c7..2e6d65a0ce7 100644
--- a/archivers/libarchive/files/configure.ac
+++ b/archivers/libarchive/files/configure.ac
@@ -670,7 +670,7 @@ AC_COMPILE_IFELSE(
  [AC_DEFINE(HAVE_READDIR_R,1,[Define to 1 if you have a POSIX compatible readdir_r])]
 )
 # dirfd can be either a function or a macro.
-AC_COMPILE_IFELSE(
+AC_LINK_IFELSE(
  [AC_LANG_PROGRAM([[#include <dirent.h>
                     DIR *dir;]],
                   [[return(dirfd(dir));]])],
=========================
I also needed to run autoconf to regenerate the configure script.

>Audit-Trail:
From: nia <nia@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/56186: libarchive: fix dirfd() check
Date: Wed, 19 May 2021 18:01:38 +0000

 On Tue, May 18, 2021 at 12:40:00PM +0000, lehel.bernadt@oneidentity.com wrote:
 > I was trying to build software on AIX 6.1 that pulled in archivers/libarchive, for which the linking failed with undefined symbol .dirfd. It turns out AIX 6.1 is missing some of the POSIX.2008 functionality, including the dirfd() call. This would be handled by libarchive, but the feature is misdetected by the configure script:

 I think we'd rather avoid diffs against libarchive because we don't
 maintain it. This could likely also be fixed with a
 CONFIGURE_ENV.AIX override.

From: David Holland <dholland-pbugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/56186: libarchive: fix dirfd() check
Date: Wed, 19 May 2021 18:09:21 +0000

 On Wed, May 19, 2021 at 06:05:01PM +0000, nia wrote:
  > 
  >  On Tue, May 18, 2021 at 12:40:00PM +0000, lehel.bernadt@oneidentity.com wrote:
  >  > I was trying to build software on AIX 6.1 that pulled in archivers/liba$
  >  
  >  I think we'd rather avoid diffs against libarchive because we don't
  >  maintain it. This could likely also be fixed with a
  >  CONFIGURE_ENV.AIX override.

 I think it's reasonable for cases like this to carry patches in
 patches/ against the sources in files/, unless there's some
 infrastructure reason not to that I'm not aware of.

 (anyway also please send the fix upstream)

 -- 
 David A. Holland
 dholland@netbsd.org

From: "Lehel Bernadt (lbernadt)" <Lehel.Bernadt@oneidentity.com>
To: "gnats-bugs@netbsd.org" <gnats-bugs@netbsd.org>
Cc: "pkg-manager@netbsd.org" <pkg-manager@netbsd.org>,
	"gnats-admin@netbsd.org" <gnats-admin@netbsd.org>, "pkgsrc-bugs@netbsd.org"
	<pkgsrc-bugs@netbsd.org>
Subject: Re: pkg/56186: libarchive: fix dirfd() check
Date: Thu, 20 May 2021 14:21:05 +0000

 On Wed, May 19, 2021 at 06:10:03PM +0000, David Holland wrote:
 > On Wed, May 19, 2021 at 06:05:01PM +0000, nia wrote:
 >  >
 >  >  On Tue, May 18, 2021 at 12:40:00PM +0000, lehel.bernadt@oneidentity.c=
 om wrote:
 >  >  > I was trying to build software on AIX 6.1 that pulled in archivers/=
 liba$
 >  >
 >  >  I think we'd rather avoid diffs against libarchive because we don't
 >  >  maintain it. This could likely also be fixed with a
 >  >  CONFIGURE_ENV.AIX override.
 >
 > I think it's reasonable for cases like this to carry patches in
 > patches/ against the sources in files/, unless there's some
 > infrastructure reason not to that I'm not aware of.
 >
 > (anyway also please send the fix upstream)

 My impression was that this is a pkgsrc/NetBSD helper lib, that's why I did=
 =20
 report the issue here and not upstream. I have a few workarounds in mk.conf=
 ,=20
 so it's not a problem to add another one; this just seemed a trivial change=
  to=20
 the configure script.

 Regards,
 Lehel=

From: nia <nia@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/56186: libarchive: fix dirfd() check
Date: Fri, 21 May 2021 06:41:31 +0000

 On Thu, May 20, 2021 at 08:05:01PM +0000, Lehel Bernadt (lbernadt) wrote:
 >  My impression was that this is a pkgsrc/NetBSD helper lib, that's why I did=
 >  =20
 >  report the issue here and not upstream. I have a few workarounds in mk.conf=
 >  ,=20
 >  so it's not a problem to add another one; this just seemed a trivial change=
 >   to=20
 >  the configure script.
 >  
 >  Regards,
 >  Lehel=

 You don't need to add anything to mk.conf, we can add it to the
 pkgsrc Makefile.

 autotools allows overriding the result of configure tests, that's
 one of its advantages.

 In pkgsrc, we can also add OS-specific overrides, e.g.

 CONFIGURE_ENV.SunOS+=   ac_cv_func_epoll_create=no
 CONFIGURE_ENV.SunOS+=   ac_cv_func_epoll_ctl=no
 CONFIGURE_ENV.SunOS+=   ac_cv_func_epoll_wait=no

 This sets a specific variable in the generated ./configure script
 so its result will be "cached" (already set).

 This _should_ be fixed in pkgsrc, IMO, libarchive is an essential
 library. My reply did not mean "fix it locally yourself", but rather
 that it should be fixed in pkgsrc in a different way.

From: "Lehel Bernadt (lbernadt)" <Lehel.Bernadt@oneidentity.com>
To: "gnats-bugs@netbsd.org" <gnats-bugs@netbsd.org>
Cc: "pkg-manager@netbsd.org" <pkg-manager@netbsd.org>,
	"gnats-admin@netbsd.org" <gnats-admin@netbsd.org>, "pkgsrc-bugs@netbsd.org"
	<pkgsrc-bugs@netbsd.org>
Subject: Re: pkg/56186: libarchive: fix dirfd() check
Date: Sun, 23 May 2021 19:14:01 +0000

 On Fri, May 21, 2021 at 06:45:01AM +0000, nia wrote:
 >
 > You don't need to add anything to mk.conf, we can add it to the
 > pkgsrc Makefile.
 >
 > autotools allows overriding the result of configure tests, that's
 > one of its advantages.
 >
 > In pkgsrc, we can also add OS-specific overrides, e.g.
 >
 > CONFIGURE_ENV.SunOS+=3D   ac_cv_func_epoll_create=3Dno
 > CONFIGURE_ENV.SunOS+=3D   ac_cv_func_epoll_ctl=3Dno
 > CONFIGURE_ENV.SunOS+=3D   ac_cv_func_epoll_wait=3Dno
 >
 > This sets a specific variable in the generated ./configure script
 > so its result will be "cached" (already set).
 >
 > This _should_ be fixed in pkgsrc, IMO, libarchive is an essential
 > library. My reply did not mean "fix it locally yourself", but rather
 > that it should be fixed in pkgsrc in a different way.

 I have some workarounds like this in my mk.conf:

 .if ${PKGPATH} =3D=3D converters/libiconv
 CFLAGS+=3D                -fgnu89-inline
 .endif

 that's why my first thought was to add the configure override here for myse=
 lf=20
 (I didn't know about the OS-specific part).

 But having it in the pkgsrc Makefile is completely fine by me of course.

 I will report the issue upstream as well though to have it permanently fixe=
 d.

 Regards,
 Lehel=

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.