diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 694a805..fbfa668 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,7 +20,7 @@ jobs: analyzer: off sanitizer: address,undefined - os: macos-14 - packages: automake + packages: autoconf automake libtool build_type: Debug build_tool_options: -j 4 analyzer: off @@ -127,6 +127,6 @@ jobs: run: | set -e -x echo $PATH - autoreconf -i + autoreconf -fi ./configure make -j 2 diff --git a/.gitignore b/.gitignore index 32c9c17..437f81f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ *.o +*.lo *.d +/.libs/ +/aclocal.m4 /autom4te.cache /build /config.guess @@ -11,7 +14,11 @@ /config.sub /configure /configure~ +/install-sh +/libtool /libzone.a +/libzone.la +/ltmain.sh /make.dep /.depend /Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index f28d224..eb352a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,8 +218,8 @@ if(architecture STREQUAL "x86_64" OR architecture STREQUAL "amd64") unset(CMAKE_REQUIRED_FLAGS) if (HAVE_WESTMERE) set_source_files_properties( - src/westmere/parser.c PROPERTIES COMPILE_FLAGS "-march=westmere") - target_sources(zone PRIVATE src/westmere/parser.c) + src/westmere/wmparser.c PROPERTIES COMPILE_FLAGS "-march=westmere") + target_sources(zone PRIVATE src/westmere/wmparser.c) set_source_files_properties( src/westmere/bench.c PROPERTIES COMPILE_FLAGS "-march=westmere") target_sources(zone-bench PRIVATE src/westmere/bench.c) @@ -233,8 +233,8 @@ if(architecture STREQUAL "x86_64" OR architecture STREQUAL "amd64") unset(CMAKE_REQUIRED_FLAGS) if (HAVE_HASWELL) set_source_files_properties( - src/haswell/parser.c PROPERTIES COMPILE_FLAGS "-march=haswell") - target_sources(zone PRIVATE src/haswell/parser.c) + src/haswell/hwparser.c PROPERTIES COMPILE_FLAGS "-march=haswell") + target_sources(zone PRIVATE src/haswell/hwparser.c) set_source_files_properties( src/haswell/bench.c PROPERTIES COMPILE_FLAGS "-march=haswell") target_sources(zone-bench PRIVATE src/haswell/bench.c) diff --git a/Makefile.in b/Makefile.in index 51aa1bc..f27d07c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,17 +12,25 @@ CC = @CC@ CPPFLAGS = @CPPFLAGS@ -Iinclude -I$(SOURCE)/include -I$(SOURCE)/src -I. CFLAGS = @CFLAGS@ DEPFLAGS = @DEPFLAGS@ +LDFLAGS=@LDFLAGS@ +LIBS=@LIBS@ VPATH = @srcdir@ - +libtool=@libtool@ +LIBTOOL=$(libtool) +srcdir=@srcdir@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ SOURCE = @srcdir@ +version_info=@version_info@ SOURCES = src/zone.c src/fallback/parser.c OBJECTS = $(SOURCES:.c=.o) -WESTMERE_SOURCES = src/westmere/parser.c +WESTMERE_SOURCES = src/westmere/wmparser.c WESTMERE_OBJECTS = $(WESTMERE_SOURCES:.c=.o) -HASWELL_SOURCES = src/haswell/parser.c +HASWELL_SOURCES = src/haswell/hwparser.c HASWELL_OBJECTS = $(HASWELL_SOURCES:.c=.o) NO_OBJECTS = @@ -36,13 +44,13 @@ DEPENDS = $(SOURCES:.c=.d) $(WESTMERE_SOURCES:.c=.d) $(HASWELL_SOURCES:.c=.d) # macros for compatibility. EXPORT_HEADER = include/zone/export.h -.PHONY: all clean +.PHONY: all clean lib -all: libzone.a +all: lib clean: @rm -f .depend - @rm -f libzone.a $(OBJECTS) $(EXPORT_HEADER) + @rm -f libzone.a libzone.la $(OBJECTS) $(EXPORT_HEADER) @rm -f $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) distclean: clean @@ -56,8 +64,22 @@ maintainer-clean: realclean devclean: realclean @rm -rf config.h.in configure -libzone.a: $(OBJECTS) $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) Makefile - $(AR) rcs libzone.a $(OBJECTS) $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) +#libzone.a: $(OBJECTS) $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) Makefile + #$(AR) rcs libzone.a $(OBJECTS) $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) + +libzone.la: $(OBJECTS) $($(WESTMERE)_OBJECTS) $($(HASWELL)_OBJECTS) Makefile + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -version-info $(version_info) -no-undefined -export-symbols $(srcdir)/lzonesyms.def -o $@ $(OBJECTS:.o=.lo) $($(WESTMERE)_OBJECTS:.o=.lo) $($(HASWELL)_OBJECTS:.o=.lo) $(LIBS) -rpath $(libdir) + if test -f .libs/libzone.a; then cp .libs/libzone.a .; fi + +libzone.a: libzone.la + +# The copy to the main directory is because that is where (NSD) picks up +# the static library to link to. +# The shared object files are listed to link with. +lib: libzone.la + +list_objs: + @echo $(OBJECTS:.o=.lo) $($(WESTMERE)_OBJECTS:.o=.lo) $($(HASWELL)_OBJECTS:.o=.lo) $(EXPORT_HEADER): @mkdir -p include/zone @@ -65,15 +87,15 @@ $(EXPORT_HEADER): $(WESTMERE_OBJECTS): $(EXPORT_HEADER) .depend Makefile @mkdir -p src/westmere - $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -march=westmere -o $@ -c $(SOURCE)/$(@:.o=.c) + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -march=westmere -o $@ -c $(SOURCE)/$(@:.o=.c) $(HASWELL_OBJECTS): $(EXPORT_HEADER) .depend Makefile @mkdir -p src/haswell - $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -march=haswell -o $@ -c $(SOURCE)/$(@:.o=.c) + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -march=haswell -o $@ -c $(SOURCE)/$(@:.o=.c) $(OBJECTS): $(EXPORT_HEADER) .depend Makefile @mkdir -p src/fallback - $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ -c $(SOURCE)/$(@:.o=.c) + $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ -c $(SOURCE)/$(@:.o=.c) @touch $@ .depend: diff --git a/acx_nlnetlabs.m4 b/acx_nlnetlabs.m4 index 6a01dc5..c8195f5 100644 --- a/acx_nlnetlabs.m4 +++ b/acx_nlnetlabs.m4 @@ -2,7 +2,10 @@ # Copyright 2009, Wouter Wijngaards, NLnet Labs. # BSD licensed. # -# Version 48 +# Version 50 +# 2025-09-29 add ac_cv_func_malloc_0_nonnull as a cache value for the malloc(0) +# check by ACX_FUNC_MALLOC. +# 2025-09-29 add ACX_CHECK_NONSTRING_ATTRIBUTE, AHX_CONFIG_NONSTRING_ATTRIBUTE. # 2024-01-16 fix to add -l:libssp.a to -lcrypto link check. # and check for getaddrinfo with only header. # 2024-01-15 fix to add crypt32 to -lcrypto link check when checking for gdi32. @@ -71,6 +74,7 @@ # ACX_DEPFLAG - find cc dependency flags. # ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. # ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. +# ACX_CHECK_NONSTRING_ATTRIBUTE - find cc nonstring attribute syntax. # ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. # ACX_CHECK_FLTO - see if cc supports -flto and use it if so. # ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. @@ -92,6 +96,7 @@ # ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. # ACX_FUNC_MALLOC - check malloc, define replacement . # AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. +# AHX_CONFIG_NONSTRING_ATTRIBUTE - config.h text for nonstring. # AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. # AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. # AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. @@ -490,7 +495,7 @@ AC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], ]) dnl Check how to mark function arguments as unused. -dnl result in HAVE_ATTR_UNUSED. +dnl result in HAVE_ATTR_UNUSED. dnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. AC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], [AC_REQUIRE([AC_PROG_CC]) @@ -525,6 +530,45 @@ if test $ac_cv_c_unused_attribute = yes; then fi ])dnl +dnl Check how to mark function arguments as nonstring. +dnl result in HAVE_ATTR_NONSTRING. +dnl Make sure you include AHX_CONFIG_NONSTRING_ATTRIBUTE also. +AC_DEFUN([ACX_CHECK_NONSTRING_ATTRIBUTE], +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "nonstring" attribute) +AC_CACHE_VAL(ac_cv_c_nonstring_attribute, +[ac_cv_c_nonstring_attribute=no +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +struct test { + char __attribute__((nonstring)) s[1]; +}; +]], [[ + struct test t = { "1" }; + (void) t; +]])],[ac_cv_c_nonstring_attribute="yes"],[ac_cv_c_nonstring_attribute="no"]) +]) + +dnl Setup ATTR_NONSTRING config.h parts. +dnl make sure you call ACX_CHECK_NONSTRING_ATTRIBUTE also. +AC_DEFUN([AHX_CONFIG_NONSTRING_ATTRIBUTE], +[ +#if defined(DOXYGEN) +# define ATTR_NONSTRING(x) x +#elif defined(__cplusplus) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#elif defined(HAVE_ATTR_NONSTRING) +# define ATTR_NONSTRING(x) __attribute__((nonstring)) x +#else /* !HAVE_ATTR_NONSTRING */ +# define ATTR_NONSTRING(x) x +#endif /* !HAVE_ATTR_NONSTRING */ +]) + +AC_MSG_RESULT($ac_cv_c_nonstring_attribute) +if test $ac_cv_c_nonstring_attribute = yes; then + AC_DEFINE(HAVE_ATTR_NONSTRING, 1, [Whether the C compiler accepts the "nonstring" attribute]) +fi +])dnl + dnl Pre-fun for ACX_LIBTOOL_C_ONLY AC_DEFUN([ACX_LIBTOOL_C_PRE], [ # skip these tests, we do not need them. @@ -1190,8 +1234,9 @@ dnl detect malloc and provide malloc compat prototype. dnl $1: unique name for compat code AC_DEFUN([ACX_FUNC_MALLOC], [ - AC_MSG_CHECKING([for GNU libc compatible malloc]) - AC_RUN_IFELSE([AC_LANG_PROGRAM( + AC_CACHE_CHECK([for GNU libc compatible malloc],[ac_cv_func_malloc_0_nonnull], + [ + AC_RUN_IFELSE([AC_LANG_PROGRAM( [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H #include #else @@ -1199,14 +1244,16 @@ char *malloc (); #endif ]], [ if(malloc(0) != 0) return 1;]) ], - [AC_MSG_RESULT([no]) - AC_LIBOBJ(malloc) - AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] , - [AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], - [AC_MSG_RESULT([no (crosscompile)]) - AC_LIBOBJ(malloc) - AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ) + [ac_cv_func_malloc_0_nonnull=no], + [ac_cv_func_malloc_0_nonnull=yes], + [ac_cv_func_malloc_0_nonnull="no (crosscompile)"]) + ]) + AS_IF([test "$ac_cv_func_malloc_0_nonnull" = yes], + [AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], + [ + AC_LIBOBJ(malloc) + AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.]) + ]) ]) dnl Define fallback for fseeko and ftello if needed. diff --git a/configure.ac b/configure.ac index 1a3c034..c45d04d 100644 --- a/configure.ac +++ b/configure.ac @@ -15,12 +15,52 @@ AC_INIT([simdzone],[0.2.4],[https://github.com/NLnetLabs/simdzone/issues]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) +version_info=0:1:0 +# This is current:revision:age +# 0.2.4 had 0:1:0 +# +# +# Current -- the number of the binary API that we're implementing +# Revision -- which iteration of the implementation of the binary +# API are we supplying? +# Age -- How many previous binary API versions do we also +# support? +# +# If we release a new version that does not change the binary API, +# increment Revision. +# +# If we release a new version that changes the binary API, but does +# not break programs compiled against the old binary API, increment +# Current and Age. Set Revision to 0, since this is the first +# implementation of the new API. +# +# Otherwise, we're changing the binary API and breaking backward +# compatibility with old binaries. Increment Current. Set Age to 0, +# since we're backward compatible with no previous APIs. Set Revision +# to 0 too. +AC_SUBST(version_info) + sinclude(acx_nlnetlabs.m4) m4_include(m4/ax_check_compile_flag.m4) CFLAGS="$CFLAGS" m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC]) +# are we on MinGW? +if uname -s 2>&1 | grep MINGW >/dev/null; then on_mingw="yes" +else + if echo $host | grep mingw >/dev/null; then on_mingw="yes" + else on_mingw="no"; fi +fi +if test "$on_mingw" = "yes"; then + if echo "$host" | $GREP -i -e linux >/dev/null; then + # link with libssp for the stack protector functions on the windows + # compile, for the static compile -l:libssp.a could be used. + # But there is no static option right now for simdzone. + if test -z "$LIBS"; then LIBS="-lssp"; else LIBS="$LIBS -lssp"; fi + fi +fi + # allow user to override the -g -O2 flags. if test "x$CFLAGS" = "x" ; then ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"]) @@ -28,6 +68,8 @@ ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"]) ACX_CHECK_PIE fi +ACX_LIBTOOL_C_ONLY + AC_CHECK_HEADERS([endian.h sys/endian.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_DECLS([bswap16,bswap32,bswap64], [], [], [ AC_INCLUDES_DEFAULT @@ -140,7 +182,11 @@ int main(int argc, char *argv[]) fi fi -AC_CHECK_FUNCS([realpath],,[AC_MSG_ERROR([realpath is not available])]) +AC_CHECK_FUNCS([realpath],,[ + AC_CHECK_FUNCS([_fullpath],,[ + AC_MSG_ERROR([realpath and _fullpath are not available]) + ]) +]) AC_SUBST([HAVE_ENDIAN_H]) AC_SUBST([HAVE_WESTMERE]) diff --git a/lzonesyms.def b/lzonesyms.def new file mode 100644 index 0000000..645a1d4 --- /dev/null +++ b/lzonesyms.def @@ -0,0 +1,3 @@ +zone_log +zone_parse +zone_parse_string diff --git a/src/haswell/parser.c b/src/haswell/hwparser.c similarity index 100% rename from src/haswell/parser.c rename to src/haswell/hwparser.c diff --git a/src/westmere/parser.c b/src/westmere/wmparser.c similarity index 100% rename from src/westmere/parser.c rename to src/westmere/wmparser.c