libtiff: Merge branch 'elf-symbol-export' into 'master'

From 3791130d2113de9f423d09ae6b7c55b0dfde9123 Mon Sep 17 00:00:00 2001
From: Roger Leigh <[EMAIL REDACTED]>
Date: Fri, 24 Jun 2022 10:28:17 +0100
Subject: [PATCH 1/7] build: Enable symbol versioning by default

---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index a0c50b52..3df6521f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -121,8 +121,8 @@ AC_PATH_PROG(CMAKE, cmake)
 # constrained to compilers using GNU ld on ELF systems or systems
 # which provide an adequate emulation thereof.
 AC_ARG_ENABLE([ld-version-script],
-  AS_HELP_STRING([--enable-ld-version-script],
-    [enable linker version script (default is disabled)]),
+  AS_HELP_STRING([--disable-ld-version-script],
+    [disable linker version script (default is enabled if supported)]),
     [have_ld_version_script=$enableval], [have_ld_version_script=no])
 if test "$have_ld_version_script" != no; then
   AC_MSG_CHECKING([if LD -Wl,--version-script works])

From 23cbc6086306ddcd62f0764bf1a0e3560c867285 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 10:30:19 +0100
Subject: [PATCH 2/7] libtiff: Add symbol versioning of all exported symbols

---
 libtiff/libtiff.map | 199 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 199 insertions(+)

diff --git a/libtiff/libtiff.map b/libtiff/libtiff.map
index 2fc177fd..18bbfc35 100644
--- a/libtiff/libtiff.map
+++ b/libtiff/libtiff.map
@@ -1,4 +1,203 @@
 LIBTIFF_4.0 {
   global:
+    TIFFAccessTagMethods;
+    TIFFCIELabToRGBInit;
+    TIFFCIELabToXYZ;
+    TIFFCheckTile;
+    TIFFCheckpointDirectory;
+    TIFFCleanup;
+    TIFFClientOpen;
+    TIFFClientdata;
+    TIFFClose;
+    TIFFComputeStrip;
+    TIFFComputeTile;
+    TIFFCreateDirectory;
+    TIFFCurrentDirOffset;
+    TIFFCurrentDirectory;
+    TIFFCurrentRow;
+    TIFFCurrentStrip;
+    TIFFCurrentTile;
+    TIFFDataWidth;
+    TIFFDefaultStripSize;
+    TIFFDefaultTileSize;
+    TIFFError;
+    TIFFErrorExt;
+    TIFFFdOpen;
+    TIFFFieldWithName;
+    TIFFFieldWithTag;
+    TIFFFileName;
+    TIFFFileno;
+    TIFFFindCODEC;
+    TIFFFindField;
+    TIFFFlush;
+    TIFFFlushData;
+    TIFFFreeDirectory;
+    TIFFGetBitRevTable;
+    TIFFGetClientInfo;
+    TIFFGetCloseProc;
+    TIFFGetConfiguredCODECs;
+    TIFFGetField;
+    TIFFGetFieldDefaulted;
+    TIFFGetMapFileProc;
+    TIFFGetMode;
+    TIFFGetReadProc;
+    TIFFGetSeekProc;
+    TIFFGetSizeProc;
+    TIFFGetTagListCount;
+    TIFFGetTagListEntry;
+    TIFFGetUnmapFileProc;
+    TIFFGetVersion;
+    TIFFGetWriteProc;
+    TIFFIsBigEndian;
+    TIFFIsByteSwapped;
+    TIFFIsCODECConfigured;
+    TIFFIsMSB2LSB;
+    TIFFIsTiled;
+    TIFFIsUpSampled;
+    TIFFLastDirectory;
+    TIFFMergeFieldInfo;
+    TIFFNumberOfDirectories;
+    TIFFNumberOfStrips;
+    TIFFNumberOfTiles;
+    TIFFOpen;
+    TIFFOpenW;
+    TIFFPrintDirectory;
+    TIFFRGBAImageBegin;
+    TIFFRGBAImageEnd;
+    TIFFRGBAImageGet;
+    TIFFRGBAImageOK;
+    TIFFRasterScanlineSize;
+    TIFFRasterScanlineSize64;
+    TIFFRawStripSize;
+    TIFFRawStripSize64;
+    TIFFReadBufferSetup;
+    TIFFReadCustomDirectory;
+    TIFFReadDirectory;
+    TIFFReadEXIFDirectory;
+    TIFFReadEncodedStrip;
+    TIFFReadEncodedTile;
+    TIFFReadRGBAImage;
+    TIFFReadRGBAImageOriented;
+    TIFFReadRGBAStrip;
+    TIFFReadRGBATile;
+    TIFFReadRawStrip;
+    TIFFReadRawTile;
+    TIFFReadScanline;
+    TIFFReadTile;
+    TIFFRegisterCODEC;
+    TIFFReverseBits;
+    TIFFRewriteDirectory;
+    TIFFScanlineSize;
+    TIFFScanlineSize64;
+    TIFFSetClientInfo;
+    TIFFSetClientdata;
+    TIFFSetDirectory;
+    TIFFSetErrorHandler;
+    TIFFSetErrorHandlerExt;
+    TIFFSetField;
+    TIFFSetFileName;
+    TIFFSetFileno;
+    TIFFSetMode;
+    TIFFSetSubDirectory;
+    TIFFSetTagExtender;
+    TIFFSetWarningHandler;
+    TIFFSetWarningHandlerExt;
+    TIFFSetWriteOffset;
+    TIFFSetupStrips;
+    TIFFStripSize;
+    TIFFStripSize64;
+    TIFFSwabArrayOfDouble;
+    TIFFSwabArrayOfFloat;
+    TIFFSwabArrayOfLong;
+    TIFFSwabArrayOfLong8;
+    TIFFSwabArrayOfShort;
+    TIFFSwabArrayOfTriples;
+    TIFFSwabDouble;
+    TIFFSwabFloat;
+    TIFFSwabLong;
+    TIFFSwabLong8;
+    TIFFSwabShort;
+    TIFFTileRowSize;
+    TIFFTileRowSize64;
+    TIFFTileSize;
+    TIFFTileSize64;
+    TIFFUnRegisterCODEC;
+    TIFFUnlinkDirectory;
+    TIFFUnsetField;
+    TIFFVGetField;
+    TIFFVGetFieldDefaulted;
+    TIFFVSetField;
+    TIFFVStripSize;
+    TIFFVStripSize64;
+    TIFFVTileSize;
+    TIFFVTileSize64;
+    TIFFWarning;
+    TIFFWarningExt;
+    TIFFWriteBufferSetup;
+    TIFFWriteCheck;
+    TIFFWriteDirectory;
+    TIFFWriteEncodedStrip;
+    TIFFWriteEncodedTile;
+    TIFFWriteRawStrip;
+    TIFFWriteRawTile;
+    TIFFWriteScanline;
+    TIFFWriteTile;
+    TIFFXYZToRGB;
+    TIFFYCbCrToRGBInit;
+    TIFFYCbCrtoRGB;
+    _TIFFClampDoubleToUInt32;
+    _TIFFfree;
+    _TIFFmalloc;
+    _TIFFmemcmp;
+    _TIFFmemcpy;
+    _TIFFmemset;
+    _TIFFrealloc;
+
+
+  local:
     *;
 };
+
+LIBTIFF_4.1 {
+    _TIFFCheckMalloc;
+    _TIFFCheckRealloc;
+    _TIFFMultiply32;
+    _TIFFMultiply64;
+    _TIFFRewriteField;
+    TIFFCreateCustomDirectory;
+    TIFFCreateEXIFDirectory;
+    TIFFDeferStrileArrayWriting;
+    TIFFFieldDataType;
+    TIFFFieldName;
+    TIFFFieldPassCount;
+    TIFFFieldReadCount;
+    TIFFFieldTag;
+    TIFFFieldWriteCount;
+    TIFFForceStrileArrayWriting;
+    TIFFGetStrileByteCount;
+    TIFFGetStrileByteCountWithErr;
+    TIFFGetStrileOffset;
+    TIFFGetStrileOffsetWithErr;
+    TIFFReadFromUserBuffer;
+    TIFFReadRGBAStripExt;
+    TIFFReadRGBATileExt;
+    TIFFSetCompressionScheme;
+    TIFFWriteCustomDirectory;
+} LIBTIFF_4.0;
+
+LIBTIFF_4.2 {
+    TIFFCreateGPSDirectory;
+    TIFFReadGPSDirectory;
+    _TIFFGetExifFields;
+    _TIFFGetGpsFields;
+} LIBTIFF_4.1;
+
+LIBTIFF_4.3 {
+} LIBTIFF_4.2;
+
+LIBTIFF_4.4 {
+    TIFFFieldIsAnonymous;
+    TIFFFieldSetGetSize;
+    TIFFFieldSetGetCountSize;
+    TIFFIsBigTIFF;
+} LIBTIFF_4.3;

From d3057d85683614a5475c3d704757a72cf81b0a61 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 10:54:52 +0100
Subject: [PATCH 3/7] libtiff: Update version script documentation

---
 doc/build.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/build.rst b/doc/build.rst
index 96b3af5f..4ada472a 100644
--- a/doc/build.rst
+++ b/doc/build.rst
@@ -506,7 +506,7 @@ Static/Shared Objects Support
 
 .. option:: --enable-ld-version-script
 
-    Enable linker version script [no]
+    Enable linker version script [yes]
 
     Add shared library symbol versioning on ELF-based systems (e.g.
     Linux and FreeBSD) which use the GNU linker. This is needed if

From a6cc522a4c1c29d1d73a7d77d84b6db2ed52cc06 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 10:55:13 +0100
Subject: [PATCH 4/7] libtiff: Correct version script for changes since v4.4.0

---
 libtiff/libtiff.map | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libtiff/libtiff.map b/libtiff/libtiff.map
index 18bbfc35..3dcefe3a 100644
--- a/libtiff/libtiff.map
+++ b/libtiff/libtiff.map
@@ -145,7 +145,6 @@ LIBTIFF_4.0 {
     TIFFXYZToRGB;
     TIFFYCbCrToRGBInit;
     TIFFYCbCrtoRGB;
-    _TIFFClampDoubleToUInt32;
     _TIFFfree;
     _TIFFmalloc;
     _TIFFmemcmp;
@@ -153,7 +152,6 @@ LIBTIFF_4.0 {
     _TIFFmemset;
     _TIFFrealloc;
 
-
   local:
     *;
 };
@@ -201,3 +199,7 @@ LIBTIFF_4.4 {
     TIFFFieldSetGetCountSize;
     TIFFIsBigTIFF;
 } LIBTIFF_4.3;
+
+LIBTIFF_4.5 {
+    _TIFFClampDoubleToUInt32;
+} LIBTIFF_4.4;

From 276c34252e5cf24fef4a8bee49e948de00e428bf Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 11:43:59 +0100
Subject: [PATCH 5/7] build: Update autoconf ld-version-script default

---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 3df6521f..1549253e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,7 +123,7 @@ AC_PATH_PROG(CMAKE, cmake)
 AC_ARG_ENABLE([ld-version-script],
   AS_HELP_STRING([--disable-ld-version-script],
     [disable linker version script (default is enabled if supported)]),
-    [have_ld_version_script=$enableval], [have_ld_version_script=no])
+    [have_ld_version_script=$enableval], [have_ld_version_script=yes])
 if test "$have_ld_version_script" != no; then
   AC_MSG_CHECKING([if LD -Wl,--version-script works])
   save_LDFLAGS="$LDFLAGS"

From dc73ae317e8ea3407bc15f8adfc8d9faa909b6f3 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 11:44:19 +0100
Subject: [PATCH 6/7] build: Update autoconf version to 4.5.0 and soname to
 6.0.0

---
 configure.ac | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1549253e..7b295fa1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ dnl OF THIS SOFTWARE.
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.64)
-AC_INIT([LibTIFF Software],[4.4.0],[tiff@lists.maptools.org],[tiff])
+AC_INIT([LibTIFF Software],[4.5.0],[tiff@lists.maptools.org],[tiff])
 AC_CONFIG_AUX_DIR(config)
 AC_CONFIG_MACRO_DIR(m4)
 AC_LANG(C)
@@ -40,7 +40,7 @@ AM_MAINTAINER_MODE
 dnl Versioning.
 dnl Don't fill the ALPHA_VERSION field, if not applicable.
 LIBTIFF_MAJOR_VERSION=4
-LIBTIFF_MINOR_VERSION=4
+LIBTIFF_MINOR_VERSION=5
 LIBTIFF_MICRO_VERSION=0
 LIBTIFF_ALPHA_VERSION=
 LIBTIFF_VERSION=$LIBTIFF_MAJOR_VERSION.$LIBTIFF_MINOR_VERSION.$LIBTIFF_MICRO_VERSION$LIBTIFF_ALPHA_VERSION
@@ -76,9 +76,9 @@ dnl  5. If any interfaces have been added since the last public release, then
 dnl     increment age.
 dnl  6. If any interfaces have been removed since the last public release,
 dnl     then set age to 0.                                
-LIBTIFF_CURRENT=13
+LIBTIFF_CURRENT=6
 LIBTIFF_REVISION=0
-LIBTIFF_AGE=8
+LIBTIFF_AGE=0
 LIBTIFF_VERSION_INFO=$LIBTIFF_CURRENT:$LIBTIFF_REVISION:$LIBTIFF_AGE
 
 # This is a special hack for OpenBSD and MirOS systems. The dynamic linker

From 38f67894cdece5880317434823b56eb33f58fecf Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@codelibre.net>
Date: Fri, 24 Jun 2022 12:57:54 +0100
Subject: [PATCH 7/7] build: Make rational2double static only for automake

This copies the same logic as used by CMake.
---
 configure.ac     |  2 ++
 test/Makefile.am | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7b295fa1..1ae5573c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -163,6 +163,8 @@ AC_SUBST(tiff_libs_private)
 tiff_requires_private=
 AC_SUBST(tiff_requires_private)
 
+AM_CONDITIONAL(BUILD_STATIC, test "$enable_static" = "yes")
+
 dnl We don't need to add math library to all targets
 case "${host_os}" in
     cygwin* | mingw32* | beos* | darwin*)
diff --git a/test/Makefile.am b/test/Makefile.am
index 6df12122..2da13dbf 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -67,12 +67,16 @@ JPEG_DEPENDENT_CHECK_PROG=
 JPEG_DEPENDENT_TESTSCRIPTS=
 endif
 
+if BUILD_STATIC
+STATIC_CHECK_PROGS=rational_precision2double
+endif
+
 # Executable programs which need to be built in order to support tests
 if TIFF_TESTS
 check_PROGRAMS = \
 	ascii_tag long_tag short_tag strip_rw rewrite custom_dir custom_dir_EXIF_231 \
-	rational_precision2double defer_strile_loading defer_strile_writing test_directory \
-	testtypes test_signed_tags $(JPEG_DEPENDENT_CHECK_PROG)
+	defer_strile_loading defer_strile_writing test_directory \
+	testtypes test_signed_tags $(JPEG_DEPENDENT_CHECK_PROG) $(STATIC_CHECK_PROGS)
 endif
 
 # Test scripts to execute
@@ -226,8 +230,13 @@ raw_decode_SOURCES = raw_decode.c
 raw_decode_LDADD = $(LIBTIFF)
 custom_dir_SOURCES = custom_dir.c
 custom_dir_LDADD = $(LIBTIFF)
+
+if BUILD_STATIC
 rational_precision2double_SOURCES = rational_precision2double.c
 rational_precision2double_LDADD = $(LIBTIFF)
+rational_precision2double_LDFLAGS = -static
+endif
+
 custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c
 custom_dir_EXIF_231_LDADD = $(LIBTIFF)
 defer_strile_loading_SOURCES = defer_strile_loading.c