Skip to content

Commit

Permalink
Check for required alignment by testing CPU types.
Browse files Browse the repository at this point in the history
Use the same test that extract.h does for processors whose load (and,
for CISC processors, memory-to-register arithmetic) instructions support
unaligned operands.

This gets rid of the last place where we used LBL_ALIGN, so get rid of
it.  (We weren't setting it with CMake in any case.)
  • Loading branch information
guyharris committed Aug 4, 2018
1 parent fbd4c58 commit 90afc76
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 205 deletions.
100 changes: 0 additions & 100 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -752,106 +752,6 @@ AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
AC_MSG_RESULT($ac_cv_lbl_have_run_path)
])

dnl
dnl Checks to see if unaligned memory accesses fail
dnl
dnl usage:
dnl
dnl AC_LBL_UNALIGNED_ACCESS
dnl
dnl results:
dnl
dnl LBL_ALIGN (DEFINED)
dnl
AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
[AC_MSG_CHECKING(if unaligned accesses fail)
AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
[case "$host_cpu" in
#
# These are CPU types where:
#
# the CPU faults on an unaligned access, but at least some
# OSes that support that CPU catch the fault and simulate
# the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
# the simulation is slow, so we don't want to use it;
#
# the CPU, I infer (from the old
#
# XXX: should also check that they don't do weird things (like on arm)
#
# comment) doesn't fault on unaligned accesses, but doesn't
# do a normal unaligned fetch, either (e.g., presumably, ARM);
#
# for whatever reason, the test program doesn't work
# (this has been claimed to be the case for several of those
# CPUs - I don't know what the problem is; the problem
# was reported as "the test program dumps core" for SuperH,
# but that's what the test program is *supposed* to do -
# it dumps core before it writes anything, so the test
# for an empty output file should find an empty output
# file and conclude that unaligned accesses don't work).
#
# This run-time test won't work if you're cross-compiling, so
# in order to support cross-compiling for a particular CPU,
# we have to wire in the list of CPU types anyway, as far as
# I know, so perhaps we should just have a set of CPUs on
# which we know it doesn't work, a set of CPUs on which we
# know it does work, and have the script just fail on other
# cpu types and update it when such a failure occurs.
#
alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
ac_cv_lbl_unaligned_fail=yes
;;
*)
cat >conftest.c <<EOF
# include <sys/types.h>
# include <sys/wait.h>
# include <stdio.h>
unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
main() {
unsigned int i;
pid_t pid;
int status;
/* avoid "core dumped" message */
pid = fork();
if (pid < 0)
exit(2);
if (pid > 0) {
/* parent */
pid = waitpid(pid, &status, 0);
if (pid < 0)
exit(3);
exit(!WIFEXITED(status));
}
/* child */
i = *(unsigned int *)&a[[1]];
printf("%d\n", i);
exit(0);
}
EOF
${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
conftest.c $LIBS >/dev/null 2>&1
if test ! -x conftest ; then
dnl failed to compile for some reason
ac_cv_lbl_unaligned_fail=yes
else
./conftest >conftest.out
if test ! -s conftest.out ; then
ac_cv_lbl_unaligned_fail=yes
else
ac_cv_lbl_unaligned_fail=no
fi
fi
rm -f -r conftest* core core.conftest
;;
esac])
AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
if test $ac_cv_lbl_unaligned_fail = yes ; then
AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
fi])

dnl
dnl If the file .devel exists:
dnl Add some warning flags if the compiler supports them
Expand Down
3 changes: 0 additions & 3 deletions cmakeconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@
/* IPv6 */
#cmakedefine INET6 1

/* if unaligned access fails */
#cmakedefine LBL_ALIGN 1

/* path for device for USB sniffing */
#cmakedefine LINUX_USB_MON_DEV "@LINUX_USB_MON_DEV@"

Expand Down
3 changes: 0 additions & 3 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@
/* IPv6 */
#undef INET6

/* if unaligned access fails */
#undef LBL_ALIGN

/* path for device for USB sniffing */
#undef LINUX_USB_MON_DEV

Expand Down
95 changes: 0 additions & 95 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -9948,101 +9948,6 @@ _ACEOF
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if unaligned accesses fail" >&5
$as_echo_n "checking if unaligned accesses fail... " >&6; }
if ${ac_cv_lbl_unaligned_fail+:} false; then :
$as_echo_n "(cached) " >&6
else
case "$host_cpu" in

#
# These are CPU types where:
#
# the CPU faults on an unaligned access, but at least some
# OSes that support that CPU catch the fault and simulate
# the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
# the simulation is slow, so we don't want to use it;
#
# the CPU, I infer (from the old
#
# XXX: should also check that they don't do weird things (like on arm)
#
# comment) doesn't fault on unaligned accesses, but doesn't
# do a normal unaligned fetch, either (e.g., presumably, ARM);
#
# for whatever reason, the test program doesn't work
# (this has been claimed to be the case for several of those
# CPUs - I don't know what the problem is; the problem
# was reported as "the test program dumps core" for SuperH,
# but that's what the test program is *supposed* to do -
# it dumps core before it writes anything, so the test
# for an empty output file should find an empty output
# file and conclude that unaligned accesses don't work).
#
# This run-time test won't work if you're cross-compiling, so
# in order to support cross-compiling for a particular CPU,
# we have to wire in the list of CPU types anyway, as far as
# I know, so perhaps we should just have a set of CPUs on
# which we know it doesn't work, a set of CPUs on which we
# know it does work, and have the script just fail on other
# cpu types and update it when such a failure occurs.
#
alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
ac_cv_lbl_unaligned_fail=yes
;;

*)
cat >conftest.c <<EOF
# include <sys/types.h>
# include <sys/wait.h>
# include <stdio.h>
unsigned char a[5] = { 1, 2, 3, 4, 5 };
main() {
unsigned int i;
pid_t pid;
int status;
/* avoid "core dumped" message */
pid = fork();
if (pid < 0)
exit(2);
if (pid > 0) {
/* parent */
pid = waitpid(pid, &status, 0);
if (pid < 0)
exit(3);
exit(!WIFEXITED(status));
}
/* child */
i = *(unsigned int *)&a[1];
printf("%d\n", i);
exit(0);
}
EOF
${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
conftest.c $LIBS >/dev/null 2>&1
if test ! -x conftest ; then
ac_cv_lbl_unaligned_fail=yes
else
./conftest >conftest.out
if test ! -s conftest.out ; then
ac_cv_lbl_unaligned_fail=yes
else
ac_cv_lbl_unaligned_fail=no
fi
fi
rm -f -r conftest* core core.conftest
;;
esac
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lbl_unaligned_fail" >&5
$as_echo "$ac_cv_lbl_unaligned_fail" >&6; }
if test $ac_cv_lbl_unaligned_fail = yes ; then

$as_echo "#define LBL_ALIGN 1" >>confdefs.h

fi




Expand Down
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,6 @@ AC_CHECK_MEMBERS([dl_hp_ppa_info_t.dl_module_id_1],,,
#include <sys/dlpi_ext.h>
])

AC_LBL_UNALIGNED_ACCESS

AC_SUBST(V_CCOPT)
AC_SUBST(V_DEFS)
AC_SUBST(V_FINDALLDEVS)
Expand Down
18 changes: 16 additions & 2 deletions dlpisubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
return (0);
}

/*
* Does the processor for which we're compiling this support aligned loads?
*/
#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
(defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
(defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
(defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
(defined(__s390__) || defined(__s390x__) || defined(__zarch__))
/* Yes, it does. */
#else
/* No, it doesn't. */
#define REQUIRE_ALIGNMENT
#endif

/*
* Loop through the packets and call the callback for each packet.
* Return the number of packets read.
Expand All @@ -127,7 +141,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
struct pcap_pkthdr pkthdr;
#ifdef HAVE_SYS_BUFMOD_H
struct sb_hdr *sbp;
#ifdef LBL_ALIGN
#ifdef REQUIRE_ALIGNMENT
struct sb_hdr sbhdr;
#endif
#endif
Expand Down Expand Up @@ -157,7 +171,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
return (n);
}
}
#ifdef LBL_ALIGN
#ifdef REQUIRE_ALIGNMENT
if ((long)bufp & 3) {
sbp = &sbhdr;
memcpy(sbp, bufp, sizeof(*sbp));
Expand Down

0 comments on commit 90afc76

Please sign in to comment.