From: Guy Harris Date: Sun, 8 Aug 2021 07:36:42 +0000 (-0700) Subject: On Solaris, for 64-bit builds, use the 64-bit pcap-config. X-Git-Tag: tcpdump-4.99.2~216 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/15d7577dcac1fbd8b991f78712c61965aa5f48c0 On Solaris, for 64-bit builds, use the 64-bit pcap-config. There are two versions of pcap-config supplied on Solaris (or, at least, on 64-bit Solaris) - a version that has the right --libs output to find the 32-bit libraries and a version that has the right --libs output to find the 64-bit libraries. Try to figure out whether we're doing a 32-bit or 64-bit build (based on the pointer size) and, for 64-bit builds, run the 64-bit version of pcap-config. (cherry picked from commit c39d40a767a1ae36171e5bcbf6f157ff3e80fb6c) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 95da37bc..edd5fd19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,36 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) project(tcpdump) +# +# OK, this is a royal pain. +# +# CMake will try to determine the sizes of some data types, including +# void *, early in the process of configuration; apparently, it's done +# as part of processing the project() command. +# +# At least as of CMake 2.8.6, it does so by checking the size of +# "void *" in C, setting CMAKE_C_SIZEOF_DATA_PTR based on that, +# setting CMAKE_SIZEOF_VOID_P to that, and then checking the size +# of "void *" in C++, setting CMAKE_CXX_SIZEOF_DATA_PTR based on +# that, and then setting CMAKE_SIZEOF_VOID_P to *that*. +# +# The compile tests include whatever C flags may have been provided +# to CMake in the CFLAGS and CXXFLAGS environment variables. +# +# If you set an architecture flag such as -m32 or -m64 in CFLAGS +# but *not* in CXXFLAGS, the size for C++ will win, and hilarity +# will ensue. +# +# Make sure CMAKE_C_SIZEOF_DATA_PTR and CMAKE_CXX_SIZEOF_DATA_PTR +# have the same value, and warn if they don't. +# +# Yes, we have to do this even though there is currently *NO* C++ +# code in tcpdump.... +# +if(NOT "${CMAKE_C_SIZEOF_DATA_PTR}" EQUAL "${CMAKE_CXX_SIZEOF_DATA_PTR}") + message(FATAL_ERROR "Architecture flags must be set in both CFLAGS and CXXFLAGS") +endif() + # # For checking if a compiler flag works and adding it if it does. # diff --git a/aclocal.m4 b/aclocal.m4 index a042d9c3..3c864269 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -575,13 +575,16 @@ AC_DEFUN(AC_LBL_LIBPCAP, # Found - use it to get the include flags for # libpcap and the flags to link with libpcap. # - # If this is a system-supplied pcap-config, which - # we define as being "a pcap-config in /usr/bin", - # there are some issues. Work around them. + # If this is a vendor-supplied pcap-config, which + # we define as being "a pcap-config in /usr/bin + # or /usr/ccs/bin" (the latter is for Solaris and + # Sun/Oracle Studio), there are some issues. Work + # around them. # - if test "$PCAP_CONFIG" = "/usr/bin/pcap-config" ; then + if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \ + \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then # - # It's /usr/bin/pcap-config. + # It's vendor-supplied. # case "$host_os" in @@ -598,6 +601,37 @@ AC_DEFUN(AC_LBL_LIBPCAP, # _broken_apple_pcap_config=yes ;; + + solaris*) + # + # This is Solaris 2 or later, i.e. SunOS 5.x. + # + # At least on Solaris 11; there's /usr/bin/pcap-config, + # which reports -L/usr/lib with --libs, causing + # the 32-bit libraries to be found, and there's + # /usr/bin/{64bitarch}/pcap-config, where {64bitarch} + # is a name for the 64-bit version of the instruction + # set, which reports -L /usr/lib/{64bitarch}, causing + # the 64-bit libraries to be found. + # + # So if we're building 64-bit targets, we replace + # PCAP_CONFIG with /usr/bin/{64bitarch}; we get + # {64bitarch} as the output of "isainfo -n". + # + # Are we building 32-bit or 64-bit? Get the + # size of void *, and check that. + # + AC_CHECK_SIZEOF([void *]) + if test ac_cv_sizeof_void_p -eq 8 ; then + isainfo_output=`isainfo -n` + if test ! -z "$isainfo_output" ; then + # + # Success - change PCAP_CONFIG. + # + PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"` + fi + fi + ;; esac fi # diff --git a/cmake/Modules/FindPCAP.cmake b/cmake/Modules/FindPCAP.cmake index 44a994e7..220ab95c 100644 --- a/cmake/Modules/FindPCAP.cmake +++ b/cmake/Modules/FindPCAP.cmake @@ -194,17 +194,57 @@ else(WIN32) endif() # - # if this is macOS or some other Darwin-based OS, check whether - # it's the system-supplied one. + # If this is a vendor-supplied pcap-config, which we define as + # being "a pcap-config in /usr/bin or /usr/ccs/bin" (the latter + # is for Solaris and Sun/Oracle Studio), there are some issues. + # Work around them. # - if(APPLE AND "${PCAP_CONFIG}" STREQUAL /usr/bin/pcap-config) + if("${PCAP_CONFIG}" STREQUAL /usr/bin/pcap-config OR + "${PCAP_CONFIG}" STREQUAL /usr/ccs/bin/pcap-config) # - # It is - remember that, so that if it provides -I/usr/local/include - # with --cflags, or -L/usr/local/lib with --libs, we ignore it; - # the macOS pcap-config does that even though the headers aren't - # under /usr/local/include and the library isn't in /usr/local/lib. + # It's vendor-supplied. # - set(_broken_apple_pcap_config TRUE) + if(APPLE) + # + # This is macOS or another Darwin-based OS. + # + # That means that /usr/bin/pcap-config it may provide + # -I/usr/local/include with --cflags and -L/usr/local/lib + # with --libs; if there's no pcap installed under /usr/local, + # that will cause the build to fail, and if there is a pcap + # installed there, you'll get that pcap even if you don't + # want it. Remember that, so we ignore those values. + # + set(_broken_apple_pcap_config TRUE) + elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*") + # + # This is Solaris 2 or later, i.e. SunOS 5.x. + # + # At least on Solaris 11; there's /usr/bin/pcap-config, which + # reports -L/usr/lib with --libs, causing the 32-bit libraries + # to be found, and there's /usr/bin/{64bitarch}/pcap-config, + # where {64bitarch} is a name for the 64-bit version of the + # instruction set, which reports -L /usr/lib/{64bitarch}, + # causing the 64-bit libraries to be found. + # + # So if we're building 64-bit targets, we replace PCAP_CONFIG + # with /usr/bin/{64bitarch}; we get {64bitarch} as the + # output of "isainfo -n". + # + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + execute_process(COMMAND "isainfo" "-n" + RESULT_VARIABLE ISAINFO_RESULT + OUTPUT_VARIABLE ISAINFO_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(ISAINFO_RESULT EQUAL 0) + # + # Success - change PCAP_CONFIG. + # + string(REPLACE "/bin/" "/bin/${ISAINFO_OUTPUT}/" PCAP_CONFIG "${PCAP_CONFIG}") + endif() + endif() + endif() endif() # diff --git a/config.h.in b/config.h.in index 5c37b1dc..6bec1150 100644 --- a/config.h.in +++ b/config.h.in @@ -252,6 +252,9 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* The size of `void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS diff --git a/configure b/configure index 02fcab8e..e0947594 100755 --- a/configure +++ b/configure @@ -1789,6 +1789,189 @@ $as_echo "$ac_res" >&6; } } # ac_fn_c_check_func +# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES +# -------------------------------------------- +# Tries to find the compile-time value of EXPR in a program that includes +# INCLUDES, setting VAR accordingly. Returns whether the value could be +# computed +ac_fn_c_compute_int () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) >= 0)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_lo=0 ac_mid=0 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=$ac_mid; break +else + as_fn_arith $ac_mid + 1 && ac_lo=$as_val + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) < 0)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=-1 ac_mid=-1 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) >= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_lo=$ac_mid; break +else + as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + ac_lo= ac_hi= +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_hi=$ac_mid +else + as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in #(( +?*) eval "$3=\$ac_lo"; ac_retval=0 ;; +'') ac_retval=1 ;; +esac + else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +static long int longval () { return $2; } +static unsigned long int ulongval () { return $2; } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (($2) < 0) + { + long int i = longval (); + if (i != ($2)) + return 1; + fprintf (f, "%ld", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ($2)) + return 1; + fprintf (f, "%lu", i); + } + /* Do not output a trailing newline, as this causes \r\n confusion + on some platforms. */ + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + echo >>conftest.val; read $3 = 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5 +$as_echo_n "checking size of void *... " >&6; } +if ${ac_cv_sizeof_void_p+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default"; then : + +else + if test "$ac_cv_type_void_p" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (void *) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_void_p=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5 +$as_echo "$ac_cv_sizeof_void_p" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_VOID_P $ac_cv_sizeof_void_p +_ACEOF + + + if test ac_cv_sizeof_void_p -eq 8 ; then + isainfo_output=`isainfo -n` + if test ! -z "$isainfo_output" ; then + # + # Success - change PCAP_CONFIG. + # + PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"` + fi + fi + ;; esac fi #