tcpdump icon indicating copy to clipboard operation
tcpdump copied to clipboard

Haiku build is broken in various ways

Open infrastation opened this issue 3 years ago • 1 comments

Tested using the current master branches and the most up to date Haiku R1/beta3:

Haiku shredder 1 hrev55181+66 Jul  6 2022 08:03: x86_64 x86_64 Haiku

Compiling tcpdump with local libpcap does not work due to the-tcpdump-group/libpcap#1114.

Compiling tcpdump with system libpcap does not work because GCC linker does not seem to use Haiku directories for shared libraries and Clang seems to use the GCC linker. The system libpcap includes the following files (in Haiku /boot is the boot volume and roughly an equivalent of / in Unix-like systems; there is no /usr):

~/gitrepos/tcpdump> find /boot/system/ -name '*pcap*'
/boot/system/package-links/libpcap-1.8.1-4
/boot/system/package-links/tcpdump-4.99.1-1/lib~libpcap
/boot/system/packages/libpcap-1.8.1-4-x86_64.hpkg
/boot/system/lib/libpcap.so.1.8.1
/boot/system/lib/libpcap.so.1
/boot/system/documentation/man/man5/pcap-savefile.5
/boot/system/documentation/man/man1/pcap-config.1
/boot/system/documentation/man/man7/pcap-tstamp.7
/boot/system/documentation/man/man7/pcap-linktype.7
/boot/system/documentation/man/man7/pcap-filter.7
/boot/system/documentation/man/man3/pcap_tstamp_type_val_to_name.3pcap
/boot/system/documentation/man/man3/pcap_tstamp_type_val_to_description.3pcap
/boot/system/documentation/man/man3/pcap_tstamp_type_name_to_val.3pcap
/boot/system/documentation/man/man3/pcap_strerror.3pcap
/boot/system/documentation/man/man3/pcap_statustostr.3pcap
/boot/system/documentation/man/man3/pcap_stats.3pcap
/boot/system/documentation/man/man3/pcap_snapshot.3pcap
/boot/system/documentation/man/man3/pcap_setnonblock.3pcap
/boot/system/documentation/man/man3/pcap_setfilter.3pcap
/boot/system/documentation/man/man3/pcap_setdirection.3pcap
/boot/system/documentation/man/man3/pcap_set_tstamp_type.3pcap
/boot/system/documentation/man/man3/pcap_set_tstamp_precision.3pcap
/boot/system/documentation/man/man3/pcap_set_timeout.3pcap
/boot/system/documentation/man/man3/pcap_set_snaplen.3pcap
/boot/system/documentation/man/man3/pcap_set_rfmon.3pcap
/boot/system/documentation/man/man3/pcap_set_promisc.3pcap
/boot/system/documentation/man/man3/pcap_set_immediate_mode.3pcap
/boot/system/documentation/man/man3/pcap_set_datalink.3pcap
/boot/system/documentation/man/man3/pcap_set_buffer_size.3pcap
/boot/system/documentation/man/man3/pcap_sendpacket.3pcap
/boot/system/documentation/man/man3/pcap_perror.3pcap
/boot/system/documentation/man/man3/pcap_open_offline_with_tstamp_precision.3pcap
/boot/system/documentation/man/man3/pcap_open_offline.3pcap
/boot/system/documentation/man/man3/pcap_open_live.3pcap
/boot/system/documentation/man/man3/pcap_open_dead_with_tstamp_precision.3pcap
/boot/system/documentation/man/man3/pcap_open_dead.3pcap
/boot/system/documentation/man/man3/pcap_offline_filter.3pcap
/boot/system/documentation/man/man3/pcap_next_ex.3pcap
/boot/system/documentation/man/man3/pcap_next.3pcap
/boot/system/documentation/man/man3/pcap_minor_version.3pcap
/boot/system/documentation/man/man3/pcap_major_version.3pcap
/boot/system/documentation/man/man3/pcap_loop.3pcap
/boot/system/documentation/man/man3/pcap_lookupnet.3pcap
/boot/system/documentation/man/man3/pcap_lookupdev.3pcap
/boot/system/documentation/man/man3/pcap_list_tstamp_types.3pcap
/boot/system/documentation/man/man3/pcap_list_datalinks.3pcap
/boot/system/documentation/man/man3/pcap_lib_version.3pcap
/boot/system/documentation/man/man3/pcap_is_swapped.3pcap
/boot/system/documentation/man/man3/pcap_inject.3pcap
/boot/system/documentation/man/man3/pcap_getnonblock.3pcap
/boot/system/documentation/man/man3/pcap_geterr.3pcap
/boot/system/documentation/man/man3/pcap_get_tstamp_precision.3pcap
/boot/system/documentation/man/man3/pcap_get_selectable_fd.3pcap
/boot/system/documentation/man/man3/pcap_freecode.3pcap
/boot/system/documentation/man/man3/pcap_freealldevs.3pcap
/boot/system/documentation/man/man3/pcap_free_tstamp_types.3pcap
/boot/system/documentation/man/man3/pcap_free_datalinks.3pcap
/boot/system/documentation/man/man3/pcap_fopen_offline_with_tstamp_precision.3pcap
/boot/system/documentation/man/man3/pcap_fopen_offline.3pcap
/boot/system/documentation/man/man3/pcap_findalldevs.3pcap
/boot/system/documentation/man/man3/pcap_fileno.3pcap
/boot/system/documentation/man/man3/pcap_file.3pcap
/boot/system/documentation/man/man3/pcap_dump_open.3pcap
/boot/system/documentation/man/man3/pcap_dump_ftell.3pcap
/boot/system/documentation/man/man3/pcap_dump_fopen.3pcap
/boot/system/documentation/man/man3/pcap_dump_flush.3pcap
/boot/system/documentation/man/man3/pcap_dump_file.3pcap
/boot/system/documentation/man/man3/pcap_dump_close.3pcap
/boot/system/documentation/man/man3/pcap_dump.3pcap
/boot/system/documentation/man/man3/pcap_dispatch.3pcap
/boot/system/documentation/man/man3/pcap_datalink_val_to_name.3pcap
/boot/system/documentation/man/man3/pcap_datalink_val_to_description.3pcap
/boot/system/documentation/man/man3/pcap_datalink_name_to_val.3pcap
/boot/system/documentation/man/man3/pcap_datalink.3pcap
/boot/system/documentation/man/man3/pcap_create.3pcap
/boot/system/documentation/man/man3/pcap_compile.3pcap
/boot/system/documentation/man/man3/pcap_close.3pcap
/boot/system/documentation/man/man3/pcap_can_set_rfmon.3pcap
/boot/system/documentation/man/man3/pcap_breakloop.3pcap
/boot/system/documentation/man/man3/pcap_activate.3pcap
/boot/system/documentation/man/man3/pcap.3pcap
/boot/system/data/vim/vim82/syntax/pcap.vim
~/gitrepos/tcpdump> 

Autoconf 2.71 tests fail trying to link with system libpcap with the following output:

checking whether to look for a local libpcap... no
checking for pkg-config... /bin/pkg-config
checking whether there are .pc files for libpcap... no
checking for pcap-config... no
checking for main in -lpcap... no
configure: error: see the INSTALL doc for more info

In the config.log file this looks as follows:

configure:5389: checking whether to look for a local libpcap
configure:5401: result: no
configure:5503: checking for pkg-config
configure:5521: found /bin/pkg-config
configure:5533: result: /bin/pkg-config
configure:5563: checking whether there are .pc files for libpcap
configure:5578: result: no
configure:5654: checking for pcap-config
configure:5687: result: no
configure:5839: checking for main in -lpcap
configure:5858: gcc -o conftest -g -O2   conftest.c -lpcap   >&5
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: cannot find -lpcap
collect2: error: ld returned 1 exit status

CMake 3.23.0 tests fail trying to link with libnsl with the following output:

$ cmake -DWITH_CRYPTO=no -DENABLE_SMB=no -DEXTRA_CFLAGS=-Werror -DCMAKE_INSTALL_PREFIX=/tmp/tcpdump_build_matrix.qDsQ1KBm ..
CMake Deprecation Warning at CMakeLists.txt:19 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking C compiler flag -std=gnu99
-- Performing Test std-gnu99
-- Performing Test std-gnu99 - Success
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for rpc/rpc.h
-- Looking for rpc/rpc.h - not found
-- Looking for net/if.h
-- Looking for net/if.h - found
-- Looking for strlcat
-- Looking for strlcat - found
-- Looking for strlcpy
-- Looking for strlcpy - found
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strsep
-- Looking for strsep - not found
-- Looking for gethostbyaddr
-- Looking for gethostbyaddr - not found
-- Looking for gethostbyaddr in socket
-- Looking for gethostbyaddr in socket - not found
-- Looking for gethostbyaddr in nsl
-- Looking for gethostbyaddr in nsl - not found
CMake Error at CMakeLists.txt:317 (message):
  gethostbyaddr is required, but wasn't found


-- Configuring incomplete, errors occurred!
See also "/boot/home/gitrepos/tcpdump/build/CMakeFiles/CMakeOutput.log".
See also "/boot/home/gitrepos/tcpdump/build/CMakeFiles/CMakeError.log".

In the CMakeError.log file this looks as follows:

Determining if the function gethostbyaddr exists in the nsl failed with the following output:
Change Dir: /boot/home/gitrepos/tcpdump/build/CMakeFiles/CMakeTmp

Run Build Command(s):/bin/make -f Makefile cmTC_5d0b3/fast && /bin/make  -f CMakeFiles/cmTC_5d0b3.dir/build.make CMakeFiles/cmTC_5d0b3.dir/build
make[1]: Entering directory '/boot/home/gitrepos/tcpdump/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5d0b3.dir/CheckFunctionExists.c.o
/bin/gcc   -DCHECK_FUNCTION_EXISTS=gethostbyaddr -o CMakeFiles/cmTC_5d0b3.dir/CheckFunctionExists.c.o -c /boot/system/data/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_5d0b3
/boot/system/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5d0b3.dir/link.txt --verbose=1
/bin/gcc  -DCHECK_FUNCTION_EXISTS=gethostbyaddr CMakeFiles/cmTC_5d0b3.dir/CheckFunctionExists.c.o -o cmTC_5d0b3  -lnsl 
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: cannot find -lnsl
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_5d0b3.dir/build.make:98: recipe for target 'cmTC_5d0b3' failed
make[1]: *** [cmTC_5d0b3] Error 1
make[1]: Leaving directory '/boot/home/gitrepos/tcpdump/build/CMakeFiles/CMakeTmp'
Makefile:127: recipe for target 'cmTC_5d0b3/fast' failed
make: *** [cmTC_5d0b3/fast] Error 2

infrastation avatar Jul 08 '22 15:07 infrastation

With GCC (which now enables local libpcap) Autoconf now fails in a different way:

~/gitrepos/tcpdump> MATRIX_BUILD_LIBPCAP=yes ./build_matrix.sh 
[...]
===== SETUP 1: BUILD_LIBPCAP=yes REMOTE=no CC=gcc CMAKE=no CRYPTO=no SMB=no =====
[...]
In file included from ./addrtoname.c:101:
./getservent.h:42:2: error: #error netdb.h and getservent.h are incompatible
   42 | #error netdb.h and getservent.h are incompatible
      |  ^~~~~
$ make -s clean
$ make -s CFLAGS=-Werror
In file included from ./addrtoname.c:101:
./getservent.h:42:2: error: #error netdb.h and getservent.h are incompatible
   42 | #error netdb.h and getservent.h are incompatible
      |  ^~~~~
Makefile:71: recipe for target 'addrtoname.o' failed
make: *** [addrtoname.o] Error 1

infrastation avatar Jul 09 '22 12:07 infrastation

Haiku R1/beta4 has been published in December, so this issue (and the-tcpdump-group/libpcap#1114) will have to be re-tested using the new OS release before spending any time on it.

infrastation avatar Jan 07 '23 22:01 infrastation

Compiling tcpdump with system libpcap does not work because GCC linker does not seem to use Haiku directories for shared libraries and Clang seems to use the GCC linker.

So what are the "native" compiler and linker for Haiku? I did a quick search or "linker" in all the section 1 man pages on my Haiku VM, and "ld" appears to be the only linker - and that's the GNU linker. If that's the "native" linker, and it doesn't use Haiku directories for shared libraries, that would appear to be a colossal botch that the Haiku developers need to fix.

guyharris avatar Jan 14 '23 10:01 guyharris

For now I do not have any new information regarding Haiku builds. It would be great to have a competent volunteer to drive this (and the libpcap counterpart) to a completion.

The ideal outcome would be to see the upstream code buildable to a specified standard (full/partial build matrix) and documented in respective README.

infrastation avatar Jan 14 '23 21:01 infrastation

Current map of this problem space on Haiku R1/beta4 64-bit with GCC 11.2.0 and Clang 12.0.1:

  • MATRIX_CC=gcc ./build_matrix.sh passes
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=no MATRIX_CMAKE=no ./build_matrix.sh fails due to libnetdissect linking failures
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=no MATRIX_CMAKE=yes ./build_matrix.sh ditto
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=yes MATRIX_CMAKE=no ./build_matrix.sh fails early trying to build libpcap (currently pending the C++ amnesty, the linker failure would be the next)
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=yes MATRIX_CMAKE=yes ./build_matrix.sh ditto

infrastation avatar Feb 11 '23 21:02 infrastation

MATRIX_CC=gcc ./build_matrix.sh passes

So how does one install libpcap on Haiku such that its header files are installed? HaikuDepot's libpcap package installs libpcap but no headers.

guyharris avatar Feb 11 '23 23:02 guyharris

pkgman update
# (possibly a reboot)
pkgman install libpcap_devel cmake llvm12_clang

(You do not need to become root because you are root by default. My Haiku VM is notably slow, so it helps to run it on all CPU cores with MAKEFLAGS=-j4.)

infrastation avatar Feb 11 '23 23:02 infrastation

To edit text files, you can use Koder <filename> (after pkgman install koder) or lpe <filename> if you don't need line numbers and syntax highlighting. Most hotkeys are different from PC and Mac. You might prefer to resort to the mouse.

It seems you can also install the latest release of Wireshark from the same package repository.

infrastation avatar Feb 12 '23 00:02 infrastation

Most hotkeys are different from PC and Mac.

Alt appears to be the equivalent of Ctrl on Windows and UN*X desktops not named "macOS" and of Command in macOS. At least in my VMware Fusion VM, the Mac Option key is the Alt key.

guyharris avatar Feb 12 '23 00:02 guyharris

pkgman install libpcap_devel cmake llvm12_clang

HaikuDepot doesn't seem to acknowledge the existence of libpcap_devel. Not sure how I have to hit it upside the head to get it to do so.

guyharris avatar Feb 12 '23 00:02 guyharris

"Repositories" -> "HaikuPorts", "Show" -> "Develop packages" (or just run pkgman from a terminal as above).

infrastation avatar Feb 12 '23 00:02 infrastation

"Show" -> "Develop packages"

Yup, that's the trick; they're not shown by default. I just installed it with pkgman.

guyharris avatar Feb 12 '23 00:02 guyharris

MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=no MATRIX_CMAKE=no ./build_matrix.sh fails due to libnetdissect linking failures

/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: tcpdump.o: relocation R_X86_64_32S against symbol `program_name' can not be used when making a shared object; recompile with -fPIC

tcpdump is a program, not a shared library, so the problem appears to be that, somehow, it's trying to build it as a shared object.

But maybe that's what executables are on Haiku:

~/src/cmd/tcpdump.org/work/tcpdump> file `which cat`
/bin/cat: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

Unlike, for example, Linux:

ubu22-04$ file `which cat`
/bin/cat: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=44af8b317775373b1a7783fbd0d83c2fe7f21f6e, for GNU/Linux 3.2.0, stripped

guyharris avatar Feb 12 '23 01:02 guyharris

Yes, Haiku executables are shared objects so that "they can be loaded using load_add_on for use as replicants".

On Haiku:

gcc (2021_07_28) 11.2.0 appears to produce the same code whether -fPIC is specified or not.

clang version 12.0.1 does not produce the same code whether -fPIC is specified or not.

So you get that error with Clang builds but not with GCC builds. Perhaps the Clang port to Haiku should be changed to produce PIC by default, just as GCC has been changed.

Meanwhile, we should probably force the use of -fPICon Haiku in the autotools configure script for tcpdump, either if the compiler isn't GCC or unconditionally (the latter is simpler, and shouldn't do any harm).

guyharris avatar Feb 12 '23 07:02 guyharris

Meanwhile, we should probably force the use of -fPICon Haiku in the autotools configure script for tcpdump, either if the compiler isn't GCC or unconditionally (the latter is simpler, and shouldn't do any harm).

Done in 64f81903ba4bbee414776b2884f8e88d3c9ae24f.

guyharris avatar Feb 12 '23 08:02 guyharris

That's grand, thank you. Let me produce an updated pass/fail map...

infrastation avatar Feb 12 '23 12:02 infrastation

  • MATRIX_CC=gcc ./build_matrix.sh passes
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=no MATRIX_CMAKE=no ./build_matrix.sh passes
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=no MATRIX_CMAKE=yes ./build_matrix.sh fails (failure to link)
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=yes MATRIX_CMAKE=no ./build_matrix.sh fails (C/C++ pointer size clash)
  • MATRIX_CC=clang MATRIX_BUILD_LIBPCAP=yes MATRIX_CMAKE=yes ./build_matrix.sh ditto

I tried to add -fPIC in CMake, but it seems to require a bit more than that (does not seem to have the expected effect on the failing vsnprintf() test, also there are complaints about -lnsl). It might be more convenient to look at this again after libpcap is good.

infrastation avatar Feb 12 '23 14:02 infrastation

tcpdump now has a small README file for Haiku.

infrastation avatar Feb 12 '23 14:02 infrastation

I tried to add -fPIC in CMake, but it seems to require a bit more than that (does not seem to have the expected effect on the failing vsnprintf() test, also there are complaints about -lnsl).

This one's tricky. It turns out the way to force a flag to be used in ALL uses of a compiler, including uses of it in CMake script tests, is to add it to CMAKE_<LANG>_FLAGS, so f37c5e563973d66a243271558914d5873b8c1e6f adds it to f37c5e563973d66a243271558914d5873b8c1e6f.

(C/C++ pointer size clash)

...This is causing another problem, in the tcpdump build:

CMake Error (dev) at /boot/system/data/cmake/Modules/GNUInstallDirs.cmake:243 (message):
  Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
  target architecture is known.  Please enable at least one language before
  including GNUInstallDirs.
Call Stack (most recent call first):
  CMakeLists.txt:1344 (include)

Cmake couldn't "determine default CMAKE_INSTALL_LIBDIR directory" because CMAKE_SIZEOF_VOID_P is undefined. That happens with Clang but not GCC; hopefully this isn't another consequence of Clang, by default, not producing, on Haiku, object files fit to link into an executable.

guyharris avatar Feb 12 '23 22:02 guyharris

I've filed Haiku issue 18258 on Clang not defaulting to generating PIC. Clang not behaving like GCC renders it painful to use with software that uses autotools or CMake.

guyharris avatar Feb 12 '23 22:02 guyharris

Thank you. Let's give Clang some time then.

infrastation avatar Feb 12 '23 23:02 infrastation

Let's give Clang some time then.

"Give Clang some time" as in "time to get issue 18258 fixed", presumably.

In 21f46b9600c4886b83dd2dbc4db1efb2bfdc722d I added a check, on Haiku, for whether the early configuration process succeeded in determining the compiler ABI; if it doesn't, I just say "sorry, this compiler doesn't work well with CMake on Haiku" and fail.

I will do that in libpcap and tcpslice as well, and will probably make similar changes to replace the -fPIC workarounds for CLang with autotools.

guyharris avatar Feb 13 '23 00:02 guyharris

That's fine. Half the matrix is much better than it used to be, and what cannot be fixed can be documented to make this good enough to be resolved.

infrastation avatar Feb 13 '23 00:02 infrastation

With the latest changes the master branch of tcpdump passes a full build matrix on 64-bit R1/beta4.

infrastation avatar Feb 14 '23 23:02 infrastation

Haiku issue 18258 now appears to be fixed with llvm12_clang-12.0.1-5, so I removed the -fPIC hacks. The entire build matrix ran, at least on my VM, after updating the compiler with pkgman full-sync (which also updated tcpdump on my VM).

guyharris avatar Feb 15 '23 00:02 guyharris

Thank you for your help, this problem looks resolved now.

infrastation avatar Feb 15 '23 00:02 infrastation