aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2023-10-30 16:55:19 -0700
committerGuy Harris <gharris@sonic.net>2023-10-30 16:55:19 -0700
commitd300f3046932c2b6e4f26c1dc8aa432b24aaf8a1 (patch)
treef9a9171826183ecb5f9bb2fe1cb85264e0c33b8d /cmake/modules
parent6f4a9a9c92a03629433c6b1228689141c38c5040 (diff)
cmake: work around a mysterious macOS dyld problem.
For some reason, there appears to be no way to build Wireshark on macOS Ventura with Xcode 15 and have the resulting program run without getting an error due to failing to find pcap_createsrcstr() at startup. In particular, there appears to be no way to use __builtin_available() to protect accesses to the routines that showed up in Sonoma, so that the run-time linker doesn't fail if the routine in question isn't present. Perhaps it requires more compiler command-line arguments. So, instead, only check for pcap_open() if 1) this isn't macOS or 2) the pcap library pathname doesn't begin with /usr/lib/ or /Application/Xcode.app/, i.e. if it's not the system libpcap. That way, we won't every try to use those APIs for a built with the system libpcap. Fixes #19436.
Diffstat (limited to 'cmake/modules')
-rw-r--r--cmake/modules/FindPCAP.cmake45
1 files changed, 44 insertions, 1 deletions
diff --git a/cmake/modules/FindPCAP.cmake b/cmake/modules/FindPCAP.cmake
index 7e5f4fce1c..c8a24167c4 100644
--- a/cmake/modules/FindPCAP.cmake
+++ b/cmake/modules/FindPCAP.cmake
@@ -218,7 +218,50 @@ if(PCAP_FOUND)
check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
- check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
+ #
+ # macOS Sonoma's libpcap includes stub versions of the remote-
+ # capture APIs. They are exported as "weakly linked symbols".
+ #
+ # Xcode 15 offers only a macOS Sonoma SDK, which has a .tbd
+ # file for libpcap that claims it includes those APIs. (Newer
+ # versions of macOS don't provide the system shared libraries,
+ # they only provide the dyld shared cache containing those
+ # libraries, so the OS provides SDKs that include a .tbd file
+ # to use when linking.)
+ #
+ # This means that check_function_exists() will think that
+ # the remote-capture APIs are present, including pcap_open().
+ #
+ # However, they are *not* present in macOS Ventura and earlier,
+ # which means that building on Ventura with Xcode 15 produces
+ # executables that fail to start because one of those APIs
+ # isn't found in the system libpcap.
+ #
+ # Protecting calls to those APIs with __builtin_available()
+ # does not appear to prevent this, for some unknown reason,
+ # and it doesn't even allow the program to compile with
+ # versions of Xcode prior to Xcode 15, as the pcap.h file
+ # doesn't specify minimum OS versions for those functions.
+ #
+ # Given all that, and given that the versions of the
+ # remote-capture APIs in Sonoma are stubs that always fail,
+ # there doesn't seem to be any point in checking for pcap_open()
+ # if we're linking against the Apple libpcap.
+ #
+ # However, if we're *not* linking against the Apple libpcap,
+ # we should check for it, so that we can use it if it's present.
+ #
+ # So we check for pcap_open if 1) this isn't macOS or 2) the
+ # the libpcap we found is not a system library, meaning that
+ # its path begins neither with /usr/lib (meaning it's a system
+ # dylib) nor /Application/Xcode.app (meaning it's a file in
+ # the Xcode SDK).
+ #
+ if( NOT APPLE OR NOT
+ (PCAP_LIBRARY MATCHES "/usr/lib/.*" OR
+ PCAP_LIBRARY MATCHES "/Application/Xcode.app/.*"))
+ check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
+ endif()
if( HAVE_PCAP_OPEN )
#
# XXX - this *should* be checked for independently of checking