Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring a static tcpdump build fails, with a misleading error, on platforms where libpcap does not support static linking #947

Open
brycekottke opened this issue Oct 15, 2021 · 17 comments

Comments

@brycekottke
Copy link

when compiling i recieve the following error:

checking for pcap-config... /usr/bin/pcap-config
checking for pcap_loop... no
configure: error: This is a bug, please follow the guidelines in CONTRIBUTING and include the
config.log file in your report.  If you have downloaded libpcap from
tcpdump.org, and built it yourself, please also include the config.log
file from the libpcap source directory, the Makefile from the libpcap
source directory, and the output of the make process for libpcap, as
this could be a problem with the libpcap that was built, and we will
not be able to determine why this is happening, and thus will not be
able to fix it, without that information, as we have not been able to
reproduce this problem ourselves.
make: *** [Makefile:39: static-tcpdump] Error 1

Things to note

  • wanted to report this since the message stated you were not able to reproduce it
  • I am using the latest version on tcpdump from the debian 11 (bullseye) repo
  • I actually came across this bug by trying to compile a program called ksniff via there Makefile
  • url to ksniff: https://github.com/eldadru/ksniff

current installed versions Debian (bullseye)

$ tcpdump --version
tcpdump version 4.99.0
libpcap version 1.10.0 (with TPACKET_V3)
OpenSSL 1.1.1k  25 Mar 2021

more information CFLAGS, etc. in the Makefile here:
https://github.com/eldadru/ksniff/blob/master/Makefile#L36

Steps to Reproduce

Anyways. I hope this helps. or at least provides some more information to go off. There could be some more information and code in that ksniff project that may help pinpoint what the cause is as well.

@guyharris
Copy link
Member

when compiling i recieve the following error:

Is that the output of "make linux" or of "make static-tcpdump"?

To quote the configure error message:

include the config.log file in your report

Please attach the config.log file in the sniff directory to this bug.

@brycekottke
Copy link
Author

It is the output for make static-tcpdump. Sorry about that, was very tired when i reported this. Forgot to include the config.log

config.log

@guyharris
Copy link
Member

What does /usr/bin/pcap-config --static --libs print?

@brycekottke
Copy link
Author

~ $ /usr/bin/pcap-config --static --libs
-lpcap  -ldbus-1

@guyharris guyharris changed the title Problems Compiling tcpdup tcpdump configure script doesn't correctly handle static builds Oct 19, 2021
@guyharris
Copy link
Member

Unfortunately, in the general case, the pcap-config script needs to be run with the --static flag when configuring a static build; the same is the case with pkg-config.

One reason why those commands are used by configure scripts is to determine what linker flags are necessary in order to link with a given library, such as libpcap. pkg-config can be used with any library that provides configuration files for that command; pcap-config exists for the benefit of systems that don't provide pkg-config, and only provides information about libpcap.

On most UN*X platforms, a shared library can be linked with other shared libraries that it requires, and linking a program using that static library does not need to link with those other libraries.

Given that a program linked with, for example, a shared-library version of libpcap should be able to work regardless of whether it's running on a system where the installed version of libpcap is, or isn't, linked with the D-Bus library (the only difference is whether it'll be able to capture D-Bus traffic or not), that program shouldn't be linked with the D-Bus shared library unless it directly uses that library, so that it can run on a system without that shared library; the program should not itself be given a dependency on a library that it does not directly use, merely because, on the system on which it's compiled, a library it does directly use happens to itself directly use some other library.

Therefore, when either pcap-config or pkg-config is run without the --static flag, they normally list only the flag necessary to link with the library being asked about; they don't list the libraries on which that library depends.

On most if not all UN*X platforms, however, static libraries don't have a way to record in the library the libraries on which that library depends. Furthermore, linking with a static library requires linking with those dependencies; finding those routines cannot be deferred until run time, as can happen when linking with a shared library. Therefore, there needs to be a way to ask pcap-config or pkg-config to provide all the linker flags needed for static linking, which means providing linker flags to link with all of the libraries on which the library being asked about depends.

Supporting static linking would thus require that the configure script for a program determine whether the program is being statically linked and, if so, pass --static to all of the pcap-config and pkg-config calls - but not do so if the program is not being statically linked.

Unfortunately, it's a bit of a pain to determine whether the program is being statically linked, as that might be specified by the setting of the CFLAGS or LDFLAGS environment variable, and not all compilers use the same flags to specify a static build (the original SunOS 4.0 flag was -Bstatic, not the GCC -static). So the script might either have to check both environment variables for any of the flags, or might have to build a small test program using those flags and test whether it's a statically-linked or dynamically-linked binary, which might be tricky when doing a cross-compile.

So this may require some work to fix. Then you'd have to wait for the fix to show up in a release, as it appears that the ksniff build downloads a tcpdump source tarball and compiles it. (Either that, or you'd have to, as per ksniff's README.md file, use "kubectl debug", once that feature is available.)

@guyharris
Copy link
Member

I'll look at fixing this as best I can, but there's nothing I can do about the lack of a static version of libsystemd in Debian. Debian have chosen to build libpcap with support for D-Bus sniffing, which means it links with -ldbus-1, and libdbus in Debian 11.1.0 requires libsystemd, and there's no static libsystemd so you can't link statically with -lsystemd, so even if I have tcpdump use --static when running pkg-config, and even if I have libpcap generate a .pc file that specifies dbus-1 in a Requires.private line, attempting to configure tcpdump with CFLAGS=-static fails because the attempt to link with -lpcap (to see whether it can link with the library - all versions of libpcap have pcap_loop(), so the test isn't necessary to determine whether tcpdump can use it, but it's done to check whether we can link with -lpcap at all - for a static build on Debian 11.1.0, at least, the answer is "no") fails.

So I'll close this when I've changed tcpdump's configure script - and CMake scripts - to try to determine whether a static link is being done and, if so, pass --static whenever pcap-config or pkg-config is being run. I'l also fix libpcap so that its .pc file uses Requires.private when appropriate, and to include all the necessary libraries in `pcap-config --static``.

So the options that I can see are:

  1. wait for kubectl debug to be implemented;
  2. download the libpcap 1.10.1 source, configure it without D-Bus capture support or any other capture support that requires additional libraries (pass --disable-dbus, --without-libnl, --without-dpdk, and --disable-rdma to ./configure), build and install that version of libpcap, and then try building ksniff, doing whatever is necessary to make sure that it finds the libpcap you've installed rather than the system libpcap;
  3. wait for Debian to fix the "no static libsystemd" issue, wait for a tcpdump 4.99 release to include the changes to detect static builds and pass --static to pkg-config, wait for a libpcap-1.10 release to include the changes to set Requires.private, wait for Debian to update to that release of libpcap, and then make sure you're running the version of Debian that includes those changes, or a later version, and try building ksniff.

Option 2 is probably the one most likely to work in the short term, as it doesn't include the phrase "wait for". It involves some work.

Option 1 is probably the one with the shortest "wait for" time, as it involves only one change.

Option 3 is involves convincing Debian to provide a static libsystemd, as well as requiring you to wait for several things to happen, both on the part of the tcpdump/libpcap developers (including producing releases of both tcpdump and libpcap) and on the part of Debian once the updated libpcap has been released.

@mj41-gdc
Copy link

I'm here with the similar motivation but on Fedora .

Where I get

> CFLAGS=-static ./configure --without-crypto 
# ...
checking for library containing getrpcbynumber... none required
checking whether to look for a local libpcap... yes
checking for local pcap library... not found
checking for pkg-config... /usr/bin/pkg-config
checking whether there are .pc files for libpcap... yes
checking for pcap_loop... no
configure: error: This is a bug, please follow the guidelines in CONTRIBUTING and include the
config.log file in your report.  If you have downloaded libpcap from
tcpdump.org, and built it yourself, please also include the config.log
file from the libpcap source directory, the Makefile from the libpcap
source directory, and the output of the make process for libpcap, as
this could be a problem with the libpcap that was built, and we will
not be able to determine why this is happening, and thus will not be
able to fix it, without that information, as we have not been able to
reproduce this problem ourselves.
> /usr/bin/pcap-config --static --libs
-lpcap -libverbs 

Offtopic: To somebody googling ksniff problem:

INFO[0000] start sniffing on remote container           
INFO[0000] executing command: '[/tmp/static-tcpdump -i any -U -w - ]' on container: 'laptop-mydev', pod: 'chart-laptop-mydev-8475fb6f98-kbcz7', namespace: 'ws-ops-tooling' 
INFO[0000] command: '[/tmp/static-tcpdump -i any -U -w - ]' executing successfully exitCode: '139', stdErr :'' 
ERRO[0000] failed to start remote sniffing, stopping wireshark  error="executing sniffer failed, exit code: '139'"
INFO[0000] starting sniffer cleanup                     
INFO[0000] sniffer cleanup completed successfully       
Error: signal: killed

static-tcpdump binary provided by ksniff segment faults:

[root@chart-laptop-mydev-7df9bcfd4c-98pt2 tmp]# ./static-tcpdump --version
static-tcpdump version 4.9.2
libpcap version 1.9.1 (with TPACKET_V3)
[root@chart-laptop-mydev-7df9bcfd4c-98pt2 tmp]# ./static-tcpdump 
Segmentation fault (core dumped)

@infrastation
Copy link
Member

Is this the problem that pcap-config --libs --static-pcap-only addresses?

@guyharris
Copy link
Member

Is this the problem that pcap-config --libs --static-pcap-only addresses?

It's a problem that, in some cases, would require that pcap-config --libs --static-pcap-only work.

Furthermore, if "static build" means a build that produces a guaranteed-to-be-completely-statically-linked binary, rather than a possibly dynamically-linked binary that's guaranteed to be statically linked with libpcap, it would also require that pkg-config be the first mechanism used to test for the presence of libraries, so that, for a static build, --static could passed to pkg-config, it would also require that either:

  1. the configure script and CMakeLists.txt file be able to recognize that a static build is being done;
  2. that a configure-script flag/CMake option be the only way to request a static build;
  3. an environment variable be used to specify whether to pass additional flags to pkg-config and pcap-config;

so that the right flag can be passed to pkg-config and pcap-config.

(It would also require that libpcap not include DPDK support unless all of the libraries that pkg-config --libs --static libdpdk have static versions. At least with some versions of Ubuntu, that is not the case, as 1) that list of libraries includes libsystemd and 2) no static version of libsystemd is provided.)

@infrastation
Copy link
Member

Static builds are clearly complicated enough to deserve a detailed FAQ entry.

@hi-unc1e
Copy link

FROM alpine:3.9.2
RUN sed -i "s|http://dl-cdn.alpinelinux.org|https://mirrors.aliyun.com|g" /etc/apk/repositories \
    && apk add gcc g++ make automake libpcap-dev
#ADD tcpdump-4.9.2.tar.gz /opt
WORKDIR /opt
RUN wget http://www.tcpdump.org/release/tcpdump-4.9.2.tar.gz \
    && tar -xvf tcpdump-4.9.2.tar.gz
RUN cd tcpdump-4.9.2 && CFLAGS=-static ./configure --without-crypto && make
RUN mv tcpdump-4.9.2/tcpdump /static-tcpdump \
        && rm -rf tcpdump-4.9.2 tcpdump-4.9.2.tar.gz

@johanneskastl
Copy link

Running into this issue on openSUSE:

[   83s] checking whether printf(3) supports the z length modifier... yes
[   83s] checking for main in -lrpc... no
[   84s] checking for library containing getrpcbynumber... none required
[   84s] checking whether to look for a local libpcap... yes
[   84s] checking for local pcap library... not found
[   84s] checking for pkg-config... /usr/bin/pkg-config
[   84s] checking whether there are .pc files for libpcap... yes
[   84s] checking for pcap_loop... no
[   84s] configure: error: This is a bug, please follow the guidelines in CONTRIBUTING.md and include the
[   84s] config.log file in your report.  If you have downloaded libpcap from
[   84s] tcpdump.org, and built it yourself, please also include the config.log
[   84s] file from the libpcap source directory, the Makefile from the libpcap
[   84s] source directory, and the output of the make process for libpcap, as
[   84s] this could be a problem with the libpcap that was built, and we will
[   84s] not be able to determine why this is happening, and thus will not be
[   84s] able to fix it, without that information, as we have not been able to
[   84s] reproduce this problem ourselves.
[   84s] error: Bad exit status from /var/tmp/rpm-tmp.i7mSY6 (%build)
$ pcap-config --libs --static-pcap-only
 -lpcap -lnl-genl-3 -lnl-3   -ldbus-1  
$ /usr/bin/pcap-config --static --libs
 -lpcap -lnl-genl-3 -lnl-3 -lpthread   -ldbus-1 -lsystemd
$

@guyharris
Copy link
Member

So what was the full command you ran to do the configuration, what is the output of env before running the configure script, and what are the contents of the config.log file (or, at least, a snipped that begins with the "checking for pcap_loop" message and proceeds until it quits)?

@johanneskastl
Copy link

johanneskastl commented Sep 27, 2023

Thanks for the quick reply. Here are the logs you wanted, if you need anything else speak reach out to me.

So what was the full command you ran to do the configuration, what is the output of env before running the configure script, and what are the contents of the config.log file (or, at least, a snipped that begins with the "checking for pcap_loop" message and proceeds until it quits)?

Full command was:

CFLAGS="-static"
export CFLAGS                                                                                                                                                                                          
./configure --without-crypto

Part of the config.log:

configure:6042: checking for pcap_loop
configure:6042: gcc -o conftest -static   conftest.c -lpcap   >&5
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoaddrinfo':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:207: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoaddr':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:181: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametonetaddr':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:270: warning: Using 'getnetbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoproto':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:527: warning: Using 'getprotobyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `nl80211_init':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:485: undefined reference to `nl_socket_alloc'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:492: undefined reference to `genl_connect'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:498: undefined reference to `genl_ctrl_alloc_cache'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:506: undefined reference to `genl_ctrl_search_by_name'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:518: undefined reference to `nl_socket_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:500: undefined reference to `nl_geterror'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:516: undefined reference to `nl_cache_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `del_mon_if':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:651: undefined reference to `nlmsg_alloc'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:658: undefined reference to `genl_family_get_id'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:658: undefined reference to `genlmsg_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:660: undefined reference to `nla_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:662: undefined reference to `nl_send_auto_complete'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:670: undefined reference to `nl_wait_for_ack'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:682: undefined reference to `nlmsg_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:667: undefined reference to `nlmsg_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:664: undefined reference to `nl_geterror'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:672: undefined reference to `nl_geterror'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `nl80211_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:525: undefined reference to `genl_family_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:526: undefined reference to `nl_cache_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:527: undefined reference to `nl_socket_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `add_mon_if':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:547: undefined reference to `nlmsg_alloc'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:554: undefined reference to `genl_family_get_id'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:554: undefined reference to `genlmsg_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:556: undefined reference to `nla_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:558: undefined reference to `nla_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:560: undefined reference to `nla_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:562: undefined reference to `nl_send_auto_complete'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:579: undefined reference to `nl_geterror'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:606: undefined reference to `nlmsg_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `nl80211_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:525: undefined reference to `genl_family_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:526: undefined reference to `nl_cache_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:527: undefined reference to `nl_socket_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `add_mon_if':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:586: undefined reference to `nl_wait_for_ack'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:603: undefined reference to `nl_geterror'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:596: undefined reference to `nlmsg_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:614: undefined reference to `nlmsg_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `nl80211_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:525: undefined reference to `genl_family_put'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:526: undefined reference to `nl_cache_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-linux.c:527: undefined reference to `nl_socket_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_write':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:114: undefined reference to `dbus_message_demarshal'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:120: undefined reference to `dbus_connection_send'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:121: undefined reference to `dbus_connection_flush'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:123: undefined reference to `dbus_message_unref'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:116: undefined reference to `dbus_error_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_read':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:66: undefined reference to `dbus_connection_pop_message'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:80: undefined reference to `dbus_connection_pop_message'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:70: undefined reference to `dbus_connection_read_write'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:83: undefined reference to `dbus_message_is_signal'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:88: undefined reference to `dbus_message_marshal'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:100: undefined reference to `dbus_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:143: undefined reference to `dbus_connection_unref'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_activate':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:207: undefined reference to `dbus_connection_open'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:213: undefined reference to `dbus_bus_register'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:285: undefined reference to `dbus_bus_add_match'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:286: undefined reference to `dbus_error_is_set'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:198: undefined reference to `dbus_bus_get'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:287: undefined reference to `dbus_error_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:290: undefined reference to `dbus_bus_add_match'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:291: undefined reference to `dbus_error_is_set'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:293: undefined reference to `dbus_error_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:143: undefined reference to `dbus_connection_unref'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_activate':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:191: undefined reference to `dbus_bus_get'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:200: undefined reference to `dbus_error_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:282: undefined reference to `dbus_connection_set_max_received_size'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_cleanup':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:143: undefined reference to `dbus_connection_unref'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-dbus.o): in function `dbus_activate':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:215: undefined reference to `dbus_error_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./pcap-dbus.c:209: undefined reference to `dbus_error_free'
collect2: error: ld returned 1 exit status
configure:6042: $? = 1

env output:

[    7s] + echo 'env start -----------------'                                                                                                                                     [111/74140]
[    7s] env start -----------------      
[    7s] + env                                                                                
[    7s] SHELL=/bin/bash               
[    7s] RPM_SOURCE_DIR=/home/abuild/rpmbuild/SOURCES
[    7s] XDG_CONFIG_DIRS=/etc/xdg:/usr/local/etc/xdg:/usr/etc/xdg
[    7s] LESS=-M -I -R                                                                        
[    7s] MACHTYPE=x86_64-suse-linux                                                           
[    7s] PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig                           
[    7s] HISTSIZE=1000                                                                        
[    7s] HOSTNAME=laptop                                                                      
[    7s] MINICOM=-c on                                                                        
[    7s] PYTHONHASHSEED=0                                                                     
[    7s] CPU=x86_64
[    7s] GPG_TTY=not a tty
[    7s] PWD=/home/abuild/rpmbuild/BUILD/ksniff-1.6.2/tcpdump-4.99.4
[    7s] SOURCE_DATE_EPOCH=1695513600
[    7s] LOGNAME=abuild
[    7s] SUSE_ZNOW=1
[    7s] RPM_ARCH=x86_64
[    7s] XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB 
[    7s] XNLSPATH=/usr/X11R6/lib/X11/nls
[    7s] HOME=/home/abuild
[    7s] LANG=C
[    7s] OSTYPE=linux
[    7s] LESS_ADVANCED_PREPROCESSOR=no
[    7s] RPM_PACKAGE_RELEASE=0
[    7s] PERL_HASH_SEED=42
[    7s] RPM_OS=linux
[    7s] SUSE_IGNORED_RPATHS=/etc/suse-ignored-rpaths.conf
[    7s] MALLOC_PERTURB_=69
[    7s] LESSCLOSE=lessclose.sh %s %s
[    7s] TERM=screen-256color
[    7s] HOST=laptop
[    7s] LESSOPEN=lessopen.sh %s
[    7s] USER=abuild
[    7s] SUSE_ASNEEDED=1
[    7s] MORE=-sl
[    7s] CSHEDIT=emacs
[    7s] SHLVL=1
[    7s] RPM_BUILD_DIR=/home/abuild/rpmbuild/BUILD
[    7s] WINDOWMANAGER=xterm
[    7s] PAGER=less
[    7s] MALLOC_CHECK_=3
[    7s] FORCE_SOURCE_DATE=1
[    7s] RPM_OPT_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -fl
to=auto -g
[    7s] RPM_DOC_DIR=/usr/share/doc/packages
[    7s] QT_HASH_SEED=0
[    7s] RPM_PACKAGE_VERSION=1.6.2
[    7s] VENDOR=suse
[    7s] PATH=/usr/local/bin:/usr/bin:/bin
[    7s] CFLAGS=-static
[    7s] PROFILEREAD=true
[    7s] MAIL=/var/mail/abuild
[    7s] HOSTTYPE=x86_64
[    7s] RPM_BUILD_NCPUS=4
[    7s] RPM_PACKAGE_NAME=kubectl-sniff
[    7s] LESSKEY=/usr/etc/lesskey.bin
[    7s] RPM_BUILD_ROOT=/home/abuild/rpmbuild/BUILDROOT/kubectl-sniff-1.6.2-0.x86_64
[    7s] OLDPWD=/home/abuild/rpmbuild/BUILD/ksniff-1.6.2
[    7s] _=/usr/bin/env
[    7s] + echo 'env stop  -----------------'
[    7s] env stop  -----------------

@guyharris
Copy link
Member

guyharris commented Sep 27, 2023

CFLAGS="-static"

UN*X systems have, over time, grown less friendly towards fully-static builds of executables.

Linux distributions happen to be less unfriendly, than, say, macOS or Solaris (neither of them support statically linking with the system library at all), but it's still not 100% friendly; see, for example:

/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoaddrinfo':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:207: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoaddr':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:181: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametonetaddr':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:270: warning: Using 'getnetbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(nametoaddr.o): in function `pcap_nametoproto':
/home/abuild/rpmbuild/BUILD/libpcap-1.10.4/./nametoaddr.c:527: warning: Using 'getprotobyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/libpcap.a(pcap-linux.o): in function `nl80211_init':

Fixing the remaining issues (which would be a problem even if you only wanted to link statically with libpcap) would require the configure script to determine that it's being asked to configure a fully-static build and then use --static when running either pkg-config or pcap-config.

That would probably involve looking at CFLAGS to see whether it contains the either --static or, at least on some platforms, other flags, such as -dn on Solaris (perhaps -Bstatic as well, but that's not necessarily a "link everything statically", as it's a positional argument - and it's ignored for -lc on Solaris).

If it detects that on macOS, Solaris, or any other "sorry, no fully-static linking" platforms, it should probably just print an error message explaining that and quit.

If it detects that on Linux, it should warn of various problems, arrange to use --static, and continue.

(Fill in other actions for various *BSDs and AIX. Don't do anything for HP-UX, Tru64 UNIX, or IRIX until somebody complains about them.)

Note, though, that:

$ /usr/bin/pcap-config --static --libs
 -lpcap -lnl-genl-3 -lnl-3 -lpthread   -ldbus-1 -lsystemd

there may not be a static libsystemd on your machine; I think the libsystemd developers were asked for static libraries and they responded "sorry, no". If so, you will not have any luck linking with what I presume is your system libpcap, as I think libdbus requires libsystemd, and they configured it to included libdbus (to support D-Bus snooping), so it might be impossible to link a program fully statically with your system's libpcap.

Try, for example, compiling this program (after renaming it from "dbtest.c.txt" to "dbtest.c"; the ".txt" is an annoying requirement due to GitHub rules)

dbtest.c.txt

with

cc -c `pkg-config --cflags dbus-1` dbtest.c

and then try linking dbtest.o with

cc --static -o dbtest dbtest.o `pkg-config --libs --static dbus-1`

If you get a message such as "/bin/ld: cannot find -lsystemd: No such file or directory", you are probably doomed in any attempt to have a fully statically linked tcpdump, unless you build your own libpcap, without D-Bus support, and link with that.

That may reduce the problems to just "warning: Using '{routine to do IP address <-> host name translation' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking". (I don't know what that means you need to do if you plan to run this program on another machine; it probably means it'll work on the same machine, or a machine running the same version of the distribution you're using, but I don't know enough to guarantee that.)

It might be possible to link statically with your system's libpcap but dynamically with everything else. That would be trickier, as the configure script would need to determine what command-line flags can be used to say "link statically with this library, but link however is the default with all other libraries". The right mix of -Bstatic and -Bdynamic might work, although I don't know whether the GCC driver program will treat those as global options for all libraries, requiring -Wl, hackery to force them to be passed directly on to the linker, rather than as the positional options that they were on SunOS 4.0, which is the ur-system for the dynamic linking mechanism used on many UN*xes (the SVR4 mechanism, adopted by most if not all of the free-software UN*Xes).

@johanneskastl
Copy link

Sorry for the late reply, @guyharris
Thanks for the detailled explanation, I'll test the file you supplied next week (this week is crazy... ;-( )

@guyharris guyharris changed the title tcpdump configure script doesn't correctly handle static builds Configuring a static tcpdump build fails, with a misleading error, on platforms where libpcap does not support static linking Apr 16, 2024
@guyharris
Copy link
Member

See also Wireshark issue #19765 - same underlying problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants