[v2] build: skip detecting libpcap via pcap-config

Message ID 20201009141914.205284-1-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2] build: skip detecting libpcap via pcap-config |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Bruce Richardson Oct. 9, 2020, 2:19 p.m. UTC
  When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
systems using CFLAGS rather than a cross-file, the pcap-config utility can
often return parameters that are unusable for the build in question, i.e.
providing the native 64-bit library paths rather than checking for 32-bit
equivalent.

Since many distros now include a version of libpcap with a
pkg-config file, and for those that don't find-library should work ok as a
fallback, we can explicitly just use pkg-config in the dependency search,
causing meson to skip trying to use pcap-config.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 config/meson.build | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
  

Comments

Luca Boccassi Oct. 9, 2020, 2:54 p.m. UTC | #1
On Fri, 2020-10-09 at 15:19 +0100, Bruce Richardson wrote:
> When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
> systems using CFLAGS rather than a cross-file, the pcap-config utility can
> often return parameters that are unusable for the build in question, i.e.
> providing the native 64-bit library paths rather than checking for 32-bit
> equivalent.
> 
> Since many distros now include a version of libpcap with a
> pkg-config file, and for those that don't find-library should work ok as a
> fallback, we can explicitly just use pkg-config in the dependency search,
> causing meson to skip trying to use pcap-config.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  config/meson.build | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/config/meson.build b/config/meson.build
> index 69f2aeb60..9fb903c9b 100644
> --- a/config/meson.build
> +++ b/config/meson.build
> @@ -163,11 +163,9 @@ if libbsd.found()
>  endif
>  
>  # check for pcap
> -pcap_dep = dependency('pcap', required: false)
> -if pcap_dep.found()
> -	# pcap got a pkg-config file only in 1.9.0 and before that meson uses
> -	# an internal pcap-config finder, which is not compatible with
> -	# cross-compilation, so try to fallback to find_library
> +pcap_dep = dependency('libpcap', required: false, method: 'pkg-config')
> +if not pcap_dep.found()
> +	# pcap got a pkg-config file only in 1.9.0
>  	pcap_dep = cc.find_library('pcap', required: false)
>  endif
>  if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)

Reviewed-by: Luca Boccassi <bluca@debian.org>
  
David Marchand Oct. 12, 2020, 12:02 p.m. UTC | #2
On Fri, Oct 9, 2020 at 4:19 PM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
> systems using CFLAGS rather than a cross-file, the pcap-config utility can
> often return parameters that are unusable for the build in question, i.e.
> providing the native 64-bit library paths rather than checking for 32-bit
> equivalent.
>
> Since many distros now include a version of libpcap with a
> pkg-config file, and for those that don't find-library should work ok as a
> fallback, we can explicitly just use pkg-config in the dependency search,
> causing meson to skip trying to use pcap-config.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

I also hit (this?) issue on a fc32 with both 32-bit and 64-bit pcap installed.
Can you confirm?

If so, we might want to backport this as I get the same problem with v19.11.4.


# rpm -q libpcap
libpcap-1.9.1-3.fc32.x86_64
libpcap-1.9.1-3.fc32.i686
# rpm -q meson
meson-0.55.3-1.fc32.noarch

# meson --reconfigure build
The Meson build system
Version: 0.55.3
Source dir: /root/dpdk
Build dir: /root/dpdk/build
Build type: native build
Program cat found: YES
Project name: DPDK
Project version: 20.11.0-rc0
C compiler for the host machine: cc (gcc 10.2.1 "cc (GCC) 10.2.1
20200723 (Red Hat 10.2.1-1)")
C linker for the host machine: cc ld.bfd 2.34-5
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program pkg-config found: YES
Program gen-pmdinfo-cfile.sh found: YES
Program list-dir-globs.py found: YES
Program check-symbols.sh found: YES
Program options-ibverbs-static.sh found: YES
Program binutils-avx512-check.sh found: YES
Program python3 found: YES (/usr/bin/python3)
Program cat found: YES
Program ../buildtools/symlink-drivers-solibs.sh found: YES (/bin/sh
/root/dpdk/config/../buildtools/symlink-drivers-solibs.sh)
Checking for size of "void *" : 8
Library m found: YES
Library numa found: NO
Library libfdt found: NO
Found pkg-config: /usr/bin/pkg-config (1.6.3)
Found CMake: /usr/bin/cmake (3.17.4)
Run-time dependency libbsd found: NO (tried pkgconfig and cmake)
pcap-config found: YES (/usr/bin/pcap-config)

config/meson.build:166:0: ERROR: Could not get return value of
pcap_lib_version()

A full log can be found at /root/dpdk/build/meson-logs/meson-log.txt


# cat /root/dpdk/build/meson-logs/meson-log.txt
[...]
Determining dependency 'libpcap' with pkg-config executable
'/usr/bin/pkg-config'
PKG_CONFIG_PATH:
Called `/usr/bin/pkg-config --modversion libpcap` -> 1

pcap-config binary missing from cross or native file, or env var undefined.
Trying a default pcap-config fallback at pcap-config
pcap-config found: YES (/usr/bin/pcap-config)
None of 'CC_LD' are defined in the environment, not changing global flags.
Running compile:
Working directory:  /root/dpdk/build/meson-private/tmp15ks2yx6
Command line:  cc
/root/dpdk/build/meson-private/tmp15ks2yx6/testfile.c -o
/root/dpdk/build/meson-private/tmp15ks2yx6/output.exe -pipe
-D_FILE_OFFSET_BITS=64 -O0 -Wl,--start-group -lpcap -Wl,--end-group

Code:
 #include <pcap.h>
        #include <stdio.h>
        int main(void) {
            printf ("%s", (char*) pcap_lib_version());
            return 0;
        }
Compiler stdout:

Compiler stderr:
 /usr/bin/ld: skipping incompatible
/usr/lib/gcc/x86_64-redhat-linux/10/../../../libpcap.so when searching
for -lpcap
/usr/bin/ld: skipping incompatible /lib/libpcap.so when searching for -lpcap
/usr/bin/ld: skipping incompatible /usr/lib/libpcap.so when searching for -lpcap
/usr/bin/ld: cannot find -lpcap
collect2: error: ld returned 1 exit status

Could not compile test file
/root/dpdk/build/meson-private/tmp15ks2yx6/testfile.c: 1


config/meson.build:166:0: ERROR: Could not get return value of
pcap_lib_version()
  
Bruce Richardson Oct. 12, 2020, 12:47 p.m. UTC | #3
On Mon, Oct 12, 2020 at 02:02:19PM +0200, David Marchand wrote:
> On Fri, Oct 9, 2020 at 4:19 PM Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> >
> > When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
> > systems using CFLAGS rather than a cross-file, the pcap-config utility can
> > often return parameters that are unusable for the build in question, i.e.
> > providing the native 64-bit library paths rather than checking for 32-bit
> > equivalent.
> >
> > Since many distros now include a version of libpcap with a
> > pkg-config file, and for those that don't find-library should work ok as a
> > fallback, we can explicitly just use pkg-config in the dependency search,
> > causing meson to skip trying to use pcap-config.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> I also hit (this?) issue on a fc32 with both 32-bit and 64-bit pcap installed.
> Can you confirm?
> 

It looks to be the same general issue. Does adding this patch fix things?
When compiling 32-bit on 64-bit you generally need to be sure to set
PKG_CONFIG_LIBDIR in your environment to point to the appropriate path. It
might also serve to fix things in this instance, if not set.

> If so, we might want to backport this as I get the same problem with v19.11.4.
> 

Good idea, I don't think it will break anything.

/Bruce
  
Bruce Richardson Oct. 12, 2020, 12:48 p.m. UTC | #4
+CC stable for consideration

On Fri, Oct 09, 2020 at 03:19:14PM +0100, Bruce Richardson wrote:
> When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
> systems using CFLAGS rather than a cross-file, the pcap-config utility can
> often return parameters that are unusable for the build in question, i.e.
> providing the native 64-bit library paths rather than checking for 32-bit
> equivalent.
> 
> Since many distros now include a version of libpcap with a
> pkg-config file, and for those that don't find-library should work ok as a
> fallback, we can explicitly just use pkg-config in the dependency search,
> causing meson to skip trying to use pcap-config.
> 

CC: stable@dpdk.org

> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  config/meson.build | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/config/meson.build b/config/meson.build
> index 69f2aeb60..9fb903c9b 100644
> --- a/config/meson.build
> +++ b/config/meson.build
> @@ -163,11 +163,9 @@ if libbsd.found()
>  endif
>  
>  # check for pcap
> -pcap_dep = dependency('pcap', required: false)
> -if pcap_dep.found()
> -	# pcap got a pkg-config file only in 1.9.0 and before that meson uses
> -	# an internal pcap-config finder, which is not compatible with
> -	# cross-compilation, so try to fallback to find_library
> +pcap_dep = dependency('libpcap', required: false, method: 'pkg-config')
> +if not pcap_dep.found()
> +	# pcap got a pkg-config file only in 1.9.0
>  	pcap_dep = cc.find_library('pcap', required: false)
>  endif
>  if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
> -- 
> 2.25.1
>
  
David Marchand Oct. 12, 2020, 3:12 p.m. UTC | #5
On Fri, Oct 9, 2020 at 4:54 PM Luca Boccassi <bluca@debian.org> wrote:
>
> On Fri, 2020-10-09 at 15:19 +0100, Bruce Richardson wrote:
> > When compiling for a slightly different architecture, e.g. 32-bit on 64-bit
> > systems using CFLAGS rather than a cross-file, the pcap-config utility can
> > often return parameters that are unusable for the build in question, i.e.
> > providing the native 64-bit library paths rather than checking for 32-bit
> > equivalent.
> >
> > Since many distros now include a version of libpcap with a
> > pkg-config file, and for those that don't find-library should work ok as a
> > fallback, we can explicitly just use pkg-config in the dependency search,
> > causing meson to skip trying to use pcap-config.
> >

CC: stable@dpdk.org

> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> Reviewed-by: Luca Boccassi <bluca@debian.org>
Tested-by: David Marchand <david.marchand@redhat.com>


Applied, thanks.
  

Patch

diff --git a/config/meson.build b/config/meson.build
index 69f2aeb60..9fb903c9b 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -163,11 +163,9 @@  if libbsd.found()
 endif
 
 # check for pcap
-pcap_dep = dependency('pcap', required: false)
-if pcap_dep.found()
-	# pcap got a pkg-config file only in 1.9.0 and before that meson uses
-	# an internal pcap-config finder, which is not compatible with
-	# cross-compilation, so try to fallback to find_library
+pcap_dep = dependency('libpcap', required: false, method: 'pkg-config')
+if not pcap_dep.found()
+	# pcap got a pkg-config file only in 1.9.0
 	pcap_dep = cc.find_library('pcap', required: false)
 endif
 if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)