debian/liblzma: Drop liblzma.so.2 compatibility

liblzma.so.2 was a Debian-specific ABI that has not been in Debian
since Debian 6.0, which reached its end of support in February, 2016.
Simplify by removing support for processes making use of that ABI and
the current upstream ABI at the same time.

Requested-by: Josh Triplett <josh@joshtriplett.org>
diff --git a/configure.ac b/configure.ac
index 9697fbd..211e0e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -555,40 +555,6 @@
 esac
 AM_CONDITIONAL([COND_THREADS], [test "x$enable_threads" != xno])
 
-# As a Debian-specific hack, liblzma can use dlopen() to check if extra
-# paranoia is needed because unversioned symbols from liblzma.so.2 are
-# present in the same process.  See src/liblzma/common/common.c.
-AC_MSG_CHECKING([if lzma_code checks should be relaxed for compatibility])
-AC_ARG_ENABLE([liblzma2-compat], [AC_HELP_STRING([--enable-liblzma2-compat],
-		[Relax run-time checks to accomodate old binaries built
-		with smaller sizeof(lzma_stream).  The default is "dynamic",
-		which means to only use the relaxed checks when the dynamic
-		loader reports that liblzma.so.2 is loaded in the same process.])],
-	[], [enable_liblzma2_compat=dynamic])
-case $enable_liblzma2_compat in
-dynamic)
-	AC_SEARCH_LIBS([dlopen], [dl])
-	AC_DEFINE([LIBLZMA2_COMPAT_DYNAMIC], [1],
-		[Define to 1 to use dlopen() to check if lzma_code() checks
-		should be more tolerant because the process is also linked to
-		liblzma from Debian 6.0.])
-	AC_MSG_RESULT([auto])
-	;;
-yes)
-	AC_DEFINE([LIBLZMA2_COMPAT], [1],
-		[Define to 1 to unconditionally make lzma_code() checks tolerant
-		to accomodate callers built against liblzma from Debian 6.0.])
-	AC_MSG_RESULT([yes])
-	;;
-no)
-	AC_MSG_RESULT([no])
-	;;
-*)
-	AC_MSG_RESULT([])
-	AC_MSG_ERROR([--enable-liblzma2: unrecognized value $enable_liblzma2_compat])
-	;;
-esac
-
 echo
 echo "Initializing Libtool:"
 LT_PREREQ([2.2])
diff --git a/debian/changelog b/debian/changelog
index 3649dd4..bd09238 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
+xz-utils (5.2.2-1.4) unstable; urgency=low
+
+  * liblzma:
+    - Remove compatibility tricks that permit sharing a process with
+      liblzma.so.2.  This means liblzma.a no longer depends on libdl
+      at run time.
+      Closes: #919950.  Thanks to Josh Triplett.
+    - Breaks: liblzma2 versions without symbol versioning.
+  * xz-utils:
+    - README.Debian: Remove notes about liblzma.so.2 compatibility.
+
+ -- Jonathan Nieder <jrnieder@gmail.com>  Sun, 27 Jan 2019 15:02:13 -0800
+
 xz-utils (5.2.2-1.3) unstable; urgency=medium
 
   * Non-maintainer upload.
diff --git a/debian/control b/debian/control
index 7e91b73..1f61f53 100644
--- a/debian/control
+++ b/debian/control
@@ -18,6 +18,7 @@
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Pre-Depends: ${misc:Pre-Depends}
+Breaks: liblzma2 (<< 5.1.1alpha+20110809-3~)
 Multi-Arch: same
 Description: XZ-format compression library
  XZ is the successor to the Lempel-Ziv/Markov-chain Algorithm
diff --git a/debian/patches/liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch b/debian/patches/liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch
deleted file mode 100644
index 54617d9..0000000
--- a/debian/patches/liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch
+++ /dev/null
@@ -1,197 +0,0 @@
-From e284cfe27457239e932038fb90084c91f4229c36 Mon Sep 17 00:00:00 2001
-From: Jonathan Nieder <jrnieder@gmail.com>
-Date: Sat, 16 Jun 2012 05:57:42 -0500
-Subject: liblzma: make dlopen()-based liblzma2 compatibility optional
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-Suppose I want to build a statically linked program:
-
-	gcc -static -o app app.c -lrpm -llzma
-
-Suppose further that librpm.a was built against a pre-5.0 version of
-liblzma so it does not allocate as much space for reserved fields at
-the end of lzma_stream as the current API requires.
-
-(This is a hypothetical scenario --- Debian librpm does not provide a
-static library.)
-
-If liblzma uses unpatched lzma_code() from XZ Utils >= 5.0, then
-during calls to librpm that try to compress or decompress an
-xz-compressed RPM, lzma_code’s reserved field checks will overflow the
-buffer and segfault.
-
-If liblzma uses the modified version of lzma_code() which asks libdl
-if liblzma.so.2 is resident and refrains from checking reserved fields
-past the end of the old lzma_stream struct when the answer is "yes",
-the behavior is no better.  The dynamic library liblzma.so.2 is _not_
-resident, so lzma_code() dutifully reads reserved fields past the end
-of the buffer --- segfault.
-
-So the only safe behavior in the static library is to unconditionally
-disable checks that might break for callers we want to continue to
-support.
-
-The new "./configure --enable-liblzma2-compat" option implements all
-three sets of semantics:
-
- - "./configure --disable-liblzma2-compat" means to check the full set
-   of reserved fields unconditionally.  You can use this to check how
-   your application would behave with the unpatched library.
-
- - "./configure --enable-liblzma2-compat=auto" means to skip checks of
-   reserved fields past the old end of struct lzma_stream when
-   liblzma.so.2 is resident.  If a DSO built against liblzma2 shares
-   the process image, the ABI-incompatible checks are skipped for
-   safety, whereas in the usual case when no such DSO is resident, the
-   full set of checks is run to help application developers remember
-   to zero all reserved fields.
-
- - "./configure --enable-liblzma2-compat" makes liblzma skip the
-   ABI-incompatible checks unconditionallty.  You can use this if you
-   want your copy of liblzma to be usable by static libraries that
-   were built against the old library.
-
-Patch-Name: liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch
-Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
----
- configure.ac                | 33 +++++++++++++++++++++++++++++++--
- src/liblzma/common/common.c | 40 +++++++++++++++++++++++++++++++++++-----
- src/liblzma/common/common.h |  2 ++
- 3 files changed, 68 insertions(+), 7 deletions(-)
-
-diff --git a/configure.ac b/configure.ac
-index 6dae0b9756d6..d17629e0e7f6 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -548,10 +548,39 @@ case $enable_threads in
- esac
- AM_CONDITIONAL([COND_THREADS], [test "x$enable_threads" != xno])
- 
--# As a Debian-specific hack, liblzma uses dlopen() to check if extra
-+# As a Debian-specific hack, liblzma can use dlopen() to check if extra
- # paranoia is needed because unversioned symbols from liblzma.so.2 are
- # present in the same process.  See src/liblzma/common/common.c.
--AC_SEARCH_LIBS([dlopen], [dl])
-+AC_MSG_CHECKING([if lzma_code checks should be relaxed for compatibility])
-+AC_ARG_ENABLE([liblzma2-compat], [AC_HELP_STRING([--enable-liblzma2-compat],
-+		[Relax run-time checks to accomodate old binaries built
-+		with smaller sizeof(lzma_stream).  The default is "dynamic",
-+		which means to only use the relaxed checks when the dynamic
-+		loader reports that liblzma.so.2 is loaded in the same process.])],
-+	[], [enable_liblzma2_compat=dynamic])
-+case $enable_liblzma2_compat in
-+dynamic)
-+	AC_SEARCH_LIBS([dlopen], [dl])
-+	AC_DEFINE([LIBLZMA2_COMPAT_DYNAMIC], [1],
-+		[Define to 1 to use dlopen() to check if lzma_code() checks
-+		should be more tolerant because the process is also linked to
-+		liblzma from Debian 6.0.])
-+	AC_MSG_RESULT([auto])
-+	;;
-+yes)
-+	AC_DEFINE([LIBLZMA2_COMPAT], [1],
-+		[Define to 1 to unconditionally make lzma_code() checks tolerant
-+		to accomodate callers built against liblzma from Debian 6.0.])
-+	AC_MSG_RESULT([yes])
-+	;;
-+no)
-+	AC_MSG_RESULT([no])
-+	;;
-+*)
-+	AC_MSG_RESULT([])
-+	AC_MSG_ERROR([--enable-liblzma2: unrecognized value $enable_liblzma2_compat])
-+	;;
-+esac
- 
- echo
- echo "Initializing Libtool:"
-diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
-index 5474211cf0ca..79427b005b4b 100644
---- a/src/liblzma/common/common.c
-+++ b/src/liblzma/common/common.c
-@@ -164,16 +164,46 @@ lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
- // External to internal API wrapper //
- //////////////////////////////////////
- 
--static bool
--liblzma2_loaded(void)
-+#ifdef LIBLZMA2_COMPAT_DYNAMIC
-+
-+static void
-+init_liblzma2_compat(lzma_stream *strm)
- {
- 	void *handle = dlopen("liblzma.so.2", RTLD_LAZY | RTLD_NOLOAD);
- 	if (handle) {
- 		dlclose(handle);
--		return true;
-+		strm->internal->liblzma2_compat = true;
-+		return;
- 	}
-+	strm->internal->liblzma2_compat = false;
-+}
-+
-+static bool
-+liblzma2_loaded(lzma_stream *strm)
-+{
-+	return strm->internal->liblzma2_compat;
-+}
-+
-+#else
-+
-+static void
-+init_liblzma2_compat(lzma_stream *strm)
-+{
-+}
-+
-+#ifdef LIBLZMA2_COMPAT
-+static bool liblzma2_loaded(lzma_stream *strm)
-+{
-+	return true;
-+}
-+#else
-+static bool liblzma2_loaded(lzma_stream *strm)
-+{
- 	return false;
- }
-+#endif
-+
-+#endif
- 
- extern lzma_ret
- lzma_strm_init(lzma_stream *strm)
-@@ -188,7 +218,7 @@ lzma_strm_init(lzma_stream *strm)
- 			return LZMA_MEM_ERROR;
- 
- 		strm->internal->next = LZMA_NEXT_CODER_INIT;
--		strm->internal->liblzma2_compat = liblzma2_loaded();
-+		init_liblzma2_compat(strm);
- 	}
- 
- 	memzero(strm->internal->supported_actions,
-@@ -241,7 +271,7 @@ lzma_code(lzma_stream *strm, lzma_action action)
- 			|| strm->reserved_ptr4 != NULL)
- 		return LZMA_OPTIONS_ERROR;
- 
--	if (strm->internal->liblzma2_compat)
-+	if (liblzma2_loaded(strm))
- 		; /* Enough checks. */
- 	else if (strm->reserved_int1 != 0
- 			|| strm->reserved_int2 != 0
-diff --git a/src/liblzma/common/common.h b/src/liblzma/common/common.h
-index b056e417a29e..eb1d0525c07d 100644
---- a/src/liblzma/common/common.h
-+++ b/src/liblzma/common/common.h
-@@ -227,9 +227,11 @@ struct lzma_internal_s {
- 	/// made (no input consumed and no output produced by next.code).
- 	bool allow_buf_error;
- 
-+#ifdef LIBLZMA2_COMPAT_DYNAMIC
- 	/// Indicates whether we are sharing a process image with
- 	/// liblzma.so.2 and need to tread carefully.
- 	bool liblzma2_compat;
-+#endif
- };
- 
- 
diff --git a/debian/patches/liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch b/debian/patches/liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch
deleted file mode 100644
index 066d260..0000000
--- a/debian/patches/liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch
+++ /dev/null
@@ -1,211 +0,0 @@
-From 7e228a81c1aa330de9289f579f768c7c9a686db2 Mon Sep 17 00:00:00 2001
-From: Jonathan Nieder <jrnieder@gmail.com>
-Date: Thu, 17 May 2012 18:49:00 -0500
-Subject: liblzma: skip ABI-incompatible check when liblzma.so.2 is loaded
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-When liblzma started using ELF symbol versioning at the same time
-as a soname bump (2 → 5) and a small increase in the reserved space at
-the end of the lzma_stream structure checked by lzma_code, introducing
-an unversioned compatibility symbol to ease the transition seemed like
-a great idea.  After all:
-
- - most applications only use one version of the library (liblzma.so.2
-   or liblzma.so.5) and would obviously work fine
-
- - applications linking to the new version of the library
-   (liblzma.so.5) should use the default, versioned lzma_code symbol so
-   errors initializing the reserved space can be noticed
-
- - symbol versioning should ensure application/library mixtures
-   independently making use of both versions of the library also
-   work.  Calls using the unversioned symbol names would be resolved
-   using the old symbol from liblzma.so.2 or the compatibility symbol
-   from liblzma.so.5, avoiding segfaults and spurious
-   LZMA_OPTIONS_ERROR errors.
-
- - application/library mixtures using both versions of the library and
-   passing lzma_stream objects between the two would break, but that
-   was never supposed to be supported, anyway.
-
-Three toolchain bugs dash that plan.
-
-Current (2.22) versions of the gold linker cannot be used to build
-libraries providing versioned and unversioned symbols with the same
-name.  On the other hand, BFD ld doesn't mind.  So GNU gold refuses to
-link versions of liblzma including the compatibility symbol (PR12261):
-
-	/usr/bin/ld: error: symbol lzma_code has undefined version
-
-Annoying, but livable.  liblzma with the compatibility symbol just
-has to be built with BFD ld.
-
-More importantly, gold does not support linking to libraries providing
-versioned and unversioned symbols with the same name.  If I link some
-code to a version of liblzma with the compatibility symbol:
-
-	ld -o demo demo.o -llzma
-
-then the documented behavior, implemented by BFD ld, is to interpret
-calls to lzma_code as referring to the default version
-(lzma_code@XZ_5.0).  Current versions of GNU gold treat such calls as
-referring to whichever symbol comes first in liblzma.so.5's symbol
-table.  If the unversioned symbol comes first (and in Debian liblzma5
-5.1.1alpha+20110809-3 it does), GNU gold will mislink new applications
-to use the unversioned compatibility symbol (PR13521):
-
-	$ ld.gold -o test.gold test.o -llzma
-	$ eu-readelf -s test.gold | grep lzma_code
-	    1: 0000000000000000      0 FUNC    GLOBAL DEFAULT    UNDEF lzma_code
-	    5: 0000000000000000      0 FUNC    GLOBAL DEFAULT    UNDEF lzma_code
-
-There is no warning.
-
-Worse, ld.so from glibc unpredictably will sometimes use the versioned
-symbol to resolve references to the unversioned base version when both
-are present (PR12977).
-
-Clearly no one has been testing mixtures of versioned and
-unversioned symbols at all, and we cannot trust the symbol resolution
-process to do anything in particular for them.
-
-This patch implements an alternative method to implement the same
-compatibility goals described above.
-
- - No more compatibility symbol.  liblzma.so.5 will define lzma_code
-   only once, with version XZ_5.0.
-
- - When initializing an lzma_stream object, use dlopen("liblzma.so.2",
-   RTLD_NOLOAD) to detect whether the caller might have been expecting
-   the old ABI, and store that information in the private
-   stream->internal->liblzma2_compat field.
-
- - In lzma_code, when checking reserved fields, skip fields past the
-   old end of the lzma_stream structure ifying reserved fields if and
-   only if this->internal->liblzma2_compat is false.
-
-That's it.  Hopefully this time it will work reliably.
-
-Thanks to Eduard Bloch for noticing PR13521 and to Ian Lance Taylor
-for PR12977.
-
-Patch-Name: liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch
-Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
----
- configure.ac                |  5 +++++
- src/liblzma/common/common.c | 40 ++++++++++++++++++++++++++++++++++++++--
- src/liblzma/common/common.h |  4 ++++
- 3 files changed, 47 insertions(+), 2 deletions(-)
-
-diff --git a/configure.ac b/configure.ac
-index 53ae7bef7472..6dae0b9756d6 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -548,6 +548,11 @@ case $enable_threads in
- esac
- AM_CONDITIONAL([COND_THREADS], [test "x$enable_threads" != xno])
- 
-+# As a Debian-specific hack, liblzma uses dlopen() to check if extra
-+# paranoia is needed because unversioned symbols from liblzma.so.2 are
-+# present in the same process.  See src/liblzma/common/common.c.
-+AC_SEARCH_LIBS([dlopen], [dl])
-+
- echo
- echo "Initializing Libtool:"
- LT_PREREQ([2.2])
-diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
-index 28aa2b7142f4..5474211cf0ca 100644
---- a/src/liblzma/common/common.c
-+++ b/src/liblzma/common/common.c
-@@ -12,6 +12,8 @@
- 
- #include "common.h"
- 
-+#include <dlfcn.h>
-+
- 
- /////////////
- // Version //
-@@ -162,6 +164,17 @@ lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
- // External to internal API wrapper //
- //////////////////////////////////////
- 
-+static bool
-+liblzma2_loaded(void)
-+{
-+	void *handle = dlopen("liblzma.so.2", RTLD_LAZY | RTLD_NOLOAD);
-+	if (handle) {
-+		dlclose(handle);
-+		return true;
-+	}
-+	return false;
-+}
-+
- extern lzma_ret
- lzma_strm_init(lzma_stream *strm)
- {
-@@ -175,6 +188,7 @@ lzma_strm_init(lzma_stream *strm)
- 			return LZMA_MEM_ERROR;
- 
- 		strm->internal->next = LZMA_NEXT_CODER_INIT;
-+		strm->internal->liblzma2_compat = liblzma2_loaded();
- 	}
- 
- 	memzero(strm->internal->supported_actions,
-@@ -189,6 +203,24 @@ lzma_strm_init(lzma_stream *strm)
- }
- 
- 
-+// Before v5.0.0~6 (liblzma: A few ABI tweaks to reserve space in
-+// structures, 2010-10-23), the reserved fields in lzma_stream were:
-+//
-+//	void *reserved_ptr1;
-+//	void *reserved_ptr2;
-+//	uint64_t reserved_int1;
-+//	uint64_t reserved_int2;
-+//	lzma_reserved_enum reserved_enum1;
-+//	lzma_reserved_enum reserved_enum2;
-+//
-+// Nowadays there are two more pointers between reserved_ptr2 and
-+// reserved_int1 and two size_t fields between reserved_int2 and
-+// reserved_enum1.
-+//
-+// When strm->internal->liblzma2_compat is set, limit the checks of
-+// reserved fields to fields that were present in the old ABI to avoid
-+// segfaults and spurious "Unsupported options" from callers sharing
-+// the process image that expect the old ABI.
- extern LZMA_API(lzma_ret)
- lzma_code(lzma_stream *strm, lzma_action action)
- {
-@@ -206,8 +238,12 @@ lzma_code(lzma_stream *strm, lzma_action action)
- 	if (strm->reserved_ptr1 != NULL
- 			|| strm->reserved_ptr2 != NULL
- 			|| strm->reserved_ptr3 != NULL
--			|| strm->reserved_ptr4 != NULL
--			|| strm->reserved_int1 != 0
-+			|| strm->reserved_ptr4 != NULL)
-+		return LZMA_OPTIONS_ERROR;
-+
-+	if (strm->internal->liblzma2_compat)
-+		; /* Enough checks. */
-+	else if (strm->reserved_int1 != 0
- 			|| strm->reserved_int2 != 0
- 			|| strm->reserved_int3 != 0
- 			|| strm->reserved_int4 != 0
-diff --git a/src/liblzma/common/common.h b/src/liblzma/common/common.h
-index 955d784a5b6a..b056e417a29e 100644
---- a/src/liblzma/common/common.h
-+++ b/src/liblzma/common/common.h
-@@ -226,6 +226,10 @@ struct lzma_internal_s {
- 	/// If true, lzma_code will return LZMA_BUF_ERROR if no progress was
- 	/// made (no input consumed and no output produced by next.code).
- 	bool allow_buf_error;
-+
-+	/// Indicates whether we are sharing a process image with
-+	/// liblzma.so.2 and need to tread carefully.
-+	bool liblzma2_compat;
- };
- 
- 
diff --git a/debian/patches/series b/debian/patches/series
index 2236e2a..b5a37ef 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1 @@
-liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch
-liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch
 kfreebsd-link-against-libfreebsd-glue.patch
diff --git a/debian/xz-utils.README.Debian b/debian/xz-utils.README.Debian
index e1c7b97..7a06d2b 100644
--- a/debian/xz-utils.README.Debian
+++ b/debian/xz-utils.README.Debian
@@ -19,9 +19,7 @@
 ----------------------------------
 
 XZ Utils 5.1.y has some experimental features which are disabled in
-Debian to allow interfaces to evolve.  Debian liblzma is also modified
-to avoid breakage when the same process loads liblzma2 from Debian 6.0
-(squeeze) and liblzma5.
+Debian to allow interfaces to evolve.
 
 abi-threaded-encoder
   Disable threaded compression in liblzma and xz.
@@ -29,12 +27,6 @@
 abi-version-script
   liblzma: Do not pretend to satisfy dependencies on XZ_5.1.1alpha.
 
-abi-liblzma2-compat, configure-liblzma2-compat
-  Do not check reserved fields past the historical end of the
-  lzma_stream structure if liblzma.so.2 is loaded in the same
-  process image.  Likewise when linked statically.
-  (See bug #649522.)
-
 man-date, man-xz-lvv-minver (from upstream)
   Document the "Minimum version required to decompress" field of
   "xz --robot -v -v --list" output.
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
index 79427b0..28aa2b7 100644
--- a/src/liblzma/common/common.c
+++ b/src/liblzma/common/common.c
@@ -12,8 +12,6 @@
 
 #include "common.h"
 
-#include <dlfcn.h>
-
 
 /////////////
 // Version //
@@ -164,47 +162,6 @@
 // External to internal API wrapper //
 //////////////////////////////////////
 
-#ifdef LIBLZMA2_COMPAT_DYNAMIC
-
-static void
-init_liblzma2_compat(lzma_stream *strm)
-{
-	void *handle = dlopen("liblzma.so.2", RTLD_LAZY | RTLD_NOLOAD);
-	if (handle) {
-		dlclose(handle);
-		strm->internal->liblzma2_compat = true;
-		return;
-	}
-	strm->internal->liblzma2_compat = false;
-}
-
-static bool
-liblzma2_loaded(lzma_stream *strm)
-{
-	return strm->internal->liblzma2_compat;
-}
-
-#else
-
-static void
-init_liblzma2_compat(lzma_stream *strm)
-{
-}
-
-#ifdef LIBLZMA2_COMPAT
-static bool liblzma2_loaded(lzma_stream *strm)
-{
-	return true;
-}
-#else
-static bool liblzma2_loaded(lzma_stream *strm)
-{
-	return false;
-}
-#endif
-
-#endif
-
 extern lzma_ret
 lzma_strm_init(lzma_stream *strm)
 {
@@ -218,7 +175,6 @@
 			return LZMA_MEM_ERROR;
 
 		strm->internal->next = LZMA_NEXT_CODER_INIT;
-		init_liblzma2_compat(strm);
 	}
 
 	memzero(strm->internal->supported_actions,
@@ -233,24 +189,6 @@
 }
 
 
-// Before v5.0.0~6 (liblzma: A few ABI tweaks to reserve space in
-// structures, 2010-10-23), the reserved fields in lzma_stream were:
-//
-//	void *reserved_ptr1;
-//	void *reserved_ptr2;
-//	uint64_t reserved_int1;
-//	uint64_t reserved_int2;
-//	lzma_reserved_enum reserved_enum1;
-//	lzma_reserved_enum reserved_enum2;
-//
-// Nowadays there are two more pointers between reserved_ptr2 and
-// reserved_int1 and two size_t fields between reserved_int2 and
-// reserved_enum1.
-//
-// When strm->internal->liblzma2_compat is set, limit the checks of
-// reserved fields to fields that were present in the old ABI to avoid
-// segfaults and spurious "Unsupported options" from callers sharing
-// the process image that expect the old ABI.
 extern LZMA_API(lzma_ret)
 lzma_code(lzma_stream *strm, lzma_action action)
 {
@@ -268,12 +206,8 @@
 	if (strm->reserved_ptr1 != NULL
 			|| strm->reserved_ptr2 != NULL
 			|| strm->reserved_ptr3 != NULL
-			|| strm->reserved_ptr4 != NULL)
-		return LZMA_OPTIONS_ERROR;
-
-	if (liblzma2_loaded(strm))
-		; /* Enough checks. */
-	else if (strm->reserved_int1 != 0
+			|| strm->reserved_ptr4 != NULL
+			|| strm->reserved_int1 != 0
 			|| strm->reserved_int2 != 0
 			|| strm->reserved_int3 != 0
 			|| strm->reserved_int4 != 0
diff --git a/src/liblzma/common/common.h b/src/liblzma/common/common.h
index eb1d052..955d784 100644
--- a/src/liblzma/common/common.h
+++ b/src/liblzma/common/common.h
@@ -226,12 +226,6 @@
 	/// If true, lzma_code will return LZMA_BUF_ERROR if no progress was
 	/// made (no input consumed and no output produced by next.code).
 	bool allow_buf_error;
-
-#ifdef LIBLZMA2_COMPAT_DYNAMIC
-	/// Indicates whether we are sharing a process image with
-	/// liblzma.so.2 and need to tread carefully.
-	bool liblzma2_compat;
-#endif
 };