diff --git a/ANNOUNCE b/ANNOUNCE index 76de5d111..bfcfdf83d 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.7.0beta14 - June 6, 2013 +Libpng 1.7.0beta14 - June 8, 2013 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -304,7 +304,7 @@ Version 1.7.0beta13 [May 12, 2013] Added information in the documentation about problems with and fixes for the bad CRC and bad iTXt chunk situations. -Version 1.7.0beta14 [June 6, 2013] +Version 1.7.0beta14 [June 8, 2013] Removed a redundant test in png_set_IHDR(). Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt) Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt @@ -312,6 +312,21 @@ Version 1.7.0beta14 [June 6, 2013] Make ARM NEON support work at compile time (not just configure time). This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when using a compiler that compiles for multiple architectures at one time. + Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from + pnglibconf.h, allowing more of the decisions to be made internally + (pngpriv.h) during the compile. Without this, symbol prefixing is broken + under certain circumstances on ARM platforms. Now only the API parts of + the optimizations ('check' vs 'api') are exposed in the public header files + except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the + decision about whether or not to use the optimizations. + Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage. + Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test + on __ARM_NEON__ from configure time to compile time. This breaks symbol + prefixing because the definition of the special png_init_filter_functions + call was hidden at configure time if the relevant compiler arguments are + passed in CFLAGS as opposed to CC. This change attempts to avoid all + the confusion that would result by declaring the init function even when + it is not used, so that it will always get prefixed. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index de1286320..42bec0548 100644 --- a/CHANGES +++ b/CHANGES @@ -4592,7 +4592,7 @@ Version 1.7.0beta13 [May 12, 2013] Added information in the documentation about problems with and fixes for the bad CRC and bad iTXt chunk situations. -Version 1.7.0beta14 [June 6, 2013] +Version 1.7.0beta14 [June 8, 2013] Removed a redundant test in png_set_IHDR(). Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt) Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt @@ -4600,6 +4600,21 @@ Version 1.7.0beta14 [June 6, 2013] Make ARM NEON support work at compile time (not just configure time). This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when using a compiler that compiles for multiple architectures at one time. + Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from + pnglibconf.h, allowing more of the decisions to be made internally + (pngpriv.h) during the compile. Without this, symbol prefixing is broken + under certain circumstances on ARM platforms. Now only the API parts of + the optimizations ('check' vs 'api') are exposed in the public header files + except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the + decision about whether or not to use the optimizations. + Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage. + Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test + on __ARM_NEON__ from configure time to compile time. This breaks symbol + prefixing because the definition of the special png_init_filter_functions + call was hidden at configure time if the relevant compiler arguments are + passed in CFLAGS as opposed to CC. This change attempts to avoid all + the confusion that would result by declaring the init function even when + it is not used, so that it will always get prefixed. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/arm/arm_init.c b/arm/arm_init.c index c24b2a083..dbde0ac6a 100644 --- a/arm/arm_init.c +++ b/arm/arm_init.c @@ -16,7 +16,7 @@ #include "../pngpriv.h" -#ifdef PNG_ARM_NEON_SUPPORTED +#if PNG_ARM_NEON_OPT > 0 #ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */ #include /* for sig_atomic_t */ @@ -216,4 +216,4 @@ png_init_filter_functions_neon(png_structp pp, unsigned int bpp) png_read_filter_row_paeth4_neon; } } -#endif /* PNG_ARM_NEON_SUPPORTED */ +#endif /* PNG_ARM_NEON_OPT > 0 */ diff --git a/arm/filter_neon.S b/arm/filter_neon.S index 827d1a390..f3053201d 100644 --- a/arm/filter_neon.S +++ b/arm/filter_neon.S @@ -11,7 +11,7 @@ */ /* This is required to get the symbol renames, which are #defines, and also - * includes the definition (or not) of PNG_ARM_NEON_SUPPORTED. + * includes the definition (or not) of PNG_ARM_NEON_OPT. */ #define PNG_VERSION_INFO_ONLY #include "../pngpriv.h" @@ -20,7 +20,7 @@ .section .note.GNU-stack,"",%progbits /* mark stack as non-executable */ #endif -#ifdef PNG_ARM_NEON_SUPPORTED +#if PNG_ARM_NEON_OPT > 0 #ifdef __ELF__ # define ELF @@ -232,4 +232,4 @@ func png_read_filter_row_paeth3_neon, export=1 pop {r4,pc} endfunc -#endif /* PNG_ARM_NEON_SUPPORTED */ +#endif /* PNG_ARM_NEON_OPT > 0 */ diff --git a/configure.ac b/configure.ac index 9950ba4b0..c28ac93ad 100644 --- a/configure.ac +++ b/configure.ac @@ -352,7 +352,7 @@ AC_ARG_ENABLE([arm-neon], [case "$enableval" in no|off) # disable the default enabling on __ARM_NEON__ systems: - AC_DEFINE([PNG_ARM_NEON_NOT_SUPPORTED], [], + AC_DEFINE([PNG_ARM_NEON_OPT], [0], [Disable ARM Neon optimizations]) # Prevent inclusion of the assembler files below: enable_arm_neon=no;; @@ -363,8 +363,11 @@ AC_ARG_ENABLE([arm-neon], AC_DEFINE([PNG_ARM_NEON_API_SUPPORTED], [], [Turn on ARM Neon optimizations at run-time]);; yes|on) - AC_DEFINE([PNG_ARM_NEON_SUPPORTED], [], - [Enable ARM Neon optimizations]);; + AC_DEFINE([PNG_ARM_NEON_OPT], [2], + [Enable ARM Neon optimizations]) + AC_MSG_WARN([--enable-arm-neon: please specify 'check' or 'api', if] + [you want the optimizations unconditionally pass -mfpu=neon] + [to the compiler.]);; *) AC_MSG_ERROR([--enable-arm-neon=${enable_arm_neon}: invalid value]) esac]) diff --git a/pngconf.h b/pngconf.h index ededd1404..d41faf72f 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.7.0beta14 - June 6, 2013 + * libpng version 1.7.0beta14 - June 8, 2013 * * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -194,30 +194,6 @@ * PNG_USE_DLL is set. */ -/* Compile time options. - * ===================== - * In a multi-arch build the compiler may compile the code several times for the - * same object module, producing different codes for different architectures. - * When this happens configure-time setting of the target host options cannot be - * done and this interferes with the handling of the ARM NEON optimizations, and - * possibly other similiar optimizations. Put additional tests here; in general - * this is needed when the same option can be changed at both compile time and - * run time depending on the target OS (i.e. iOS vs Android.) - */ -#ifdef __ARM_NEON__ - /* If the default below causes problems set PNG_ARM_NEON_NOT_SUPPORTED either - * by passing --enable-arm-neon=no to configure or setting it in some other - * way when pnglibconf.h is built. - */ -# if (!defined PNG_ARM_NEON_SUPPORTED) && (!defined PNG_ARM_NEON_NOT_SUPPORTED) -# define PNG_ARM_NEON_SUPPORTED -# endif -#endif - -#if (defined PNG_ARM_NEON_SUPPORTED) && (defined PNG_ARM_NEON_NOT_SUPPORTED) -# error configuration: ARM_NEON cannot both be supported and disabled -#endif - /* System specific discovery. * ========================== * This code is used at build time to find PNG_IMPEXP, the API settings diff --git a/pngpriv.h b/pngpriv.h index b6725d223..658e1623e 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -125,6 +125,46 @@ #endif /* VERSION_INFO_ONLY */ +/* Compile time options. + * ===================== + * In a multi-arch build the compiler may compile the code several times for the + * same object module, producing different binaries for different architectures. + * When this happens configure-time setting of the target host options cannot be + * done and this interferes with the handling of the ARM NEON optimizations, and + * possibly other similiar optimizations. Put additional tests here; in general + * this is needed when the same option can be changed at both compile time and + * run time depending on the target OS (i.e. iOS vs Android.) + * + * NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because + * this is not possible with certain compilers (Oracle SUN OS CC), as a result + * it is necessary to ensure that all extern functions that *might* be used + * regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON__ + * below is one example of this behavior because it is controlled by the + * presence or not of -mfpu=neon on the GCC command line, it is possible to do + * this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely + * do this. + */ +#ifndef PNG_ARM_NEON_OPT + /* ARM NEON optimizations are being controlled by the compiler settings, + * typically the target FPU. If the FPU has been set to NEON (-mfpu=neon + * with GCC) then the compiler will define __ARM_NEON__ and we can rely + * unconditionally on NEON instructions not crashing, otherwise we must + * disable use of NEON instructions: + */ +# ifdef __ARM_NEON__ +# define PNG_ARM_NEON_OPT 2 +# else +# define PNG_ARM_NEON_OPT 0 +# endif +#endif + +#if PNG_ARM_NEON_OPT > 0 + /* NEON optimizations are to be at least considered by libpng, enable the + * callbacks to do this. + */ +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon +#endif + /* Is this a build of a DLL where compilation of the object modules requires * different preprocessor settings to those required for a simple library? If * so PNG_BUILD_DLL must be set. @@ -1848,14 +1888,22 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY); #endif /* SIMPLIFIED READ/WRITE */ +/* These are initialization functions for hardware specific PNG filter + * optimizations; list these here then select the appropriate one at compile + * time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined + * the generic code is used. + */ #ifdef PNG_FILTER_OPTIMIZATIONS PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structrp png_ptr, - unsigned int bpp), PNG_EMPTY); - /* This is the initialization function for hardware specific optimizations, - * one implementation (for ARM NEON machines) is contained in - * arm/filter_neon.c. It need not be defined - the generic code will be used - * if not. + unsigned int bpp), PNG_EMPTY); + /* Just declare the optimization that will be used */ +#else + /* List *all* the possible optimizations here - this branch is required if + * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in + * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing. */ +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); #endif /* Maintainer: Put new private prototypes here ^ */ diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa index 2efac5ca7..5282180ab 100644 --- a/scripts/pnglibconf.dfa +++ b/scripts/pnglibconf.dfa @@ -126,7 +126,7 @@ logunsupported = 1 # # If you create a private DLL you need to define the following # macros in the file 'pngusr.h' and set -DPNG_USER_CONFIG for -# compilation (i.e. in CFLAGS.) +# compilation (i.e. in CPPFLAGS.) # #define PNG_USER_PRIVATEBUILD \ # # e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons." @@ -216,35 +216,41 @@ setting ZLIB_HEADER default # include the file too, so that the defaults below are known @# include -# This setting allows a hardware or configuration specific filter optimization -# function to be specified, the argument is the name of the filter initializaion -# function to use. - -setting FILTER_OPTIMIZATIONS - # Implementation specific control of the optimizations, enabled by those # hardware or software options that need it (typically when run-time choices # must be made by the user) option SET_OPTION disabled -# These options are specific to the ARM NEON hardware optimizations: +# These options are specific to the ARM NEON hardware optimizations. At present +# these optimizations depend on GCC specific pre-processing of an assembler (.S) +# file so they probably won't work with other compilers. # -# ARM_NEON: the optimization itself -# ARM_NEON_NOT: disable the optimization even on systems that apparently support -# it (where the compiler defines __ARM_NEON__). -# ARM_NEON_API: allow the optimization to be switched on with png_set_hardware -# ARM_NEON_CHECK: compile a run-time check to see if Neon extensions are -setting ZLIB_VERNUM default @ZLIB_VERNUM -# supported, this is poorly supported and deprectated - use the -# png_set_hardware API. -option ARM_NEON disabled, - sets FILTER_OPTIMIZATIONS png_init_filter_functions_neon -option ARM_NEON_NOT disabled -option ARM_NEON_API disabled enables SET_OPTION ARM_NEON -option ARM_NEON_CHECK disabled enables ARM_NEON +# ARM_NEON_OPT: unset: check at compile time (__ARM_NEON__ must be defined by +# the compiler, typically as a result of specifying +# CC="gcc -mfpu=neon".) +# 0: disable (even if the CPU has a NEON FPU.) +# 1: check at run time (via ARM_NEON_{API,CHECK}) +# 2: switch on unconditionally (inadvisable - instead pass +# -mfpu=neon to GCC in CC) +# When building libpng avoid using any setting other than '0'; '1' is +# set automatically when either 'API' or 'CHECK' are configured in, +# '2' should not be necessary as -mfpu=neon will achieve the same +# effect as well as applying NEON optimizations to the rest of the +# libpng code. +# NOTE: any setting other than '0' requires ALIGNED_MEMORY +# ARM_NEON_API: (PNG_ARM_NEON == 1) allow the optimization to be switched on +# with png_set_option +# ARM_NEON_CHECK: (PNG_ARM_NEON == 1) compile a run-time check to see if Neon +# extensions are supported, this is poorly supported and +# deprectated - use the png_set_option API. +setting ARM_NEON_OPT +option ARM_NEON_API disabled requires ALIGNED_MEMORY enables SET_OPTION, + sets ARM_NEON_OPT 1 +option ARM_NEON_CHECK disabled requires ALIGNED_MEMORY, + sets ARM_NEON_OPT 1 # These settings configure the default compression level (0-9) and 'strategy'; -# strategy is as defined by the implementors of zlib, it describes the input +# strategy is as defined by the implementors of zlib. It describes the input # data and modifies the zlib parameters in an attempt to optimize the balance # between search and huffman encoding in the zlib algorithms. The defaults are # the zlib.h defaults - the apparently recursive definition does not arise @@ -253,6 +259,7 @@ option ARM_NEON_CHECK disabled enables ARM_NEON # The TEXT values are the defaults when writing compressed text (all forms) # The '@' here means to substitute the value when pnglibconf.h is built +setting ZLIB_VERNUM default @ZLIB_VERNUM setting Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION # TODO: why aren't these Z_RLE; zlib.h says that Z_RLE, specifically, is # appropriate for PNG images, maybe it doesn't exist in all versions? diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt index 334a444ec..550b14faf 100644 --- a/scripts/pnglibconf.h.prebuilt +++ b/scripts/pnglibconf.h.prebuilt @@ -2,7 +2,7 @@ /* pnglibconf.h - library build configuration */ -/* Libpng version 1.7.0beta14 - May 13, 2013 */ +/* Libpng version 1.7.0beta14 - June 8, 2013 */ /* Copyright (c) 1998-2013 Glenn Randers-Pehrson */ @@ -20,7 +20,6 @@ #define PNG_ALIGNED_MEMORY_SUPPORTED /*#undef PNG_ARM_NEON_API_SUPPORTED*/ /*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ -/*#undef PNG_ARM_NEON_SUPPORTED*/ #define PNG_BENIGN_ERRORS_SUPPORTED #define PNG_BENIGN_READ_ERRORS_SUPPORTED /*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/