summaryrefslogtreecommitdiffstats
path: root/external/firebird
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /external/firebird
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'external/firebird')
-rw-r--r--external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.141
-rw-r--r--external/firebird/0001-Fix-warning-on-Win64-build-231.patch.137
-rw-r--r--external/firebird/0001-Make-comparison-operator-member-functions-const.patch.149
-rw-r--r--external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.141
-rw-r--r--external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.167
-rw-r--r--external/firebird/ExternalPackage_firebird.mk28
-rw-r--r--external/firebird/ExternalProject_firebird.mk107
-rw-r--r--external/firebird/Makefile7
-rw-r--r--external/firebird/Module_firebird.mk18
-rw-r--r--external/firebird/README3
-rw-r--r--external/firebird/UnpackedTarball_firebird.mk82
-rw-r--r--external/firebird/asan.patch252
-rw-r--r--external/firebird/c++17.patch311
-rw-r--r--external/firebird/configure-c99.patch23
-rw-r--r--external/firebird/firebird-307.patch.112
-rw-r--r--external/firebird/firebird-Engine12.patch16
-rw-r--r--external/firebird/firebird-btyacc-add-explicit-rule.patch12
-rw-r--r--external/firebird/firebird-cygwin-msvc-warnings.patch300
-rw-r--r--external/firebird/firebird-cygwin-msvc.patch686
-rw-r--r--external/firebird/firebird-macosx-sandbox.patch.113
-rw-r--r--external/firebird/firebird-macosx.patch.187
-rw-r--r--external/firebird/firebird-rpath.patch.011
-rw-r--r--external/firebird/firebird-tdf125284.patch.127
-rw-r--r--external/firebird/firebird-vs2017.patch.112
-rw-r--r--external/firebird/firebird.disable-ib-util-not-found.patch.117
-rw-r--r--external/firebird/macos-arm64.patch.0109
-rw-r--r--external/firebird/macosx-elcapitan-dyld.patch58
-rw-r--r--external/firebird/msvc.patch11
-rw-r--r--external/firebird/sanitizer.patch63
-rw-r--r--external/firebird/ubsan.patch307
-rw-r--r--external/firebird/wnt-dbgutil.patch63
-rw-r--r--external/firebird/wnt-per-process-trace-storage.patch.118
32 files changed, 2888 insertions, 0 deletions
diff --git a/external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.1 b/external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.1
new file mode 100644
index 000000000..22cc1e119
--- /dev/null
+++ b/external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.1
@@ -0,0 +1,41 @@
+From f4c0aa3ba070e5c3ce996b33a31323a3a6820f0c Mon Sep 17 00:00:00 2001
+From: Stephan Bergmann <sbergman@redhat.com>
+Date: Wed, 2 Dec 2020 10:44:28 +0100
+Subject: Fix checks for null HANDLE in Windows-only code
+
+clang-cl failed with "error: unordered comparison between pointer and zero
+('HANDLE' (aka 'void *') and 'int')" in these two places introduced with
+f219283b72ab537c2b5938222708f35227c1ebde "Sub-task CORE-4463: Windows
+implementation for CORE-4462 (Make it possible to restore compressed .nbk files
+without explicitly decompressing them)" and
+c2cfa7824189ed7c3e5a19721effdf97c07dadfd "Prevent child process hung if it
+writes too much data to the pipe and overflow the pipe buffer".
+---
+ src/utilities/nbackup/nbackup.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/utilities/nbackup/nbackup.cpp b/src/utilities/nbackup/nbackup.cpp
+index 6598b6e331..4703079d67 100644
+--- a/src/utilities/nbackup/nbackup.cpp
++++ b/src/utilities/nbackup/nbackup.cpp
+@@ -385,7 +385,7 @@ FB_SIZE_T NBackup::read_file(FILE_HANDLE &file, void *buffer, FB_SIZE_T bufsize)
+ #ifdef WIN_NT
+ // Read child's stderr often to prevent child process hung if it writes
+ // too much data to the pipe and overflow the pipe buffer.
+- const bool checkChild = (childStdErr > 0 && file == backup);
++ const bool checkChild = (childStdErr != 0 && file == backup);
+ if (checkChild)
+ print_child_stderr();
+
+@@ -790,7 +790,7 @@ void NBackup::close_backup()
+ return;
+ #ifdef WIN_NT
+ CloseHandle(backup);
+- if (childId > 0)
++ if (childId != 0)
+ {
+ const bool killed = (WaitForSingleObject(childId, 5000) != WAIT_OBJECT_0);
+ if (killed)
+--
+2.28.0
+
diff --git a/external/firebird/0001-Fix-warning-on-Win64-build-231.patch.1 b/external/firebird/0001-Fix-warning-on-Win64-build-231.patch.1
new file mode 100644
index 000000000..0e21f9e27
--- /dev/null
+++ b/external/firebird/0001-Fix-warning-on-Win64-build-231.patch.1
@@ -0,0 +1,37 @@
+From 60cb8e07b17ad8533d7d13f52435aa11e48f4659 Mon Sep 17 00:00:00 2001
+From: Dimitry Sibiryakov <sd@ibphoenix.com>
+Date: Tue, 12 Nov 2019 13:42:49 +0100
+Subject: [PATCH] Fix warning on Win64 build (#231)
+
+---
+ src/common/ThreadStart.cpp | 11 +++++++----
+ 1 file changed, 7 insertions(+), 4 deletions(-)
+
+diff --git a/src/common/ThreadStart.cpp b/src/common/ThreadStart.cpp
+index 184c93a32b..758056432f 100644
+--- a/src/common/ThreadStart.cpp
++++ b/src/common/ThreadStart.cpp
+@@ -309,13 +309,16 @@ Thread Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Han
+ * Advanced Windows by Richter pg. # 109. */
+
+ unsigned thread_id;
+- unsigned long real_handle =
+- _beginthreadex(NULL, 0, THREAD_ENTRYPOINT, THREAD_ARG, CREATE_SUSPENDED, &thread_id);
+- if (!real_handle)
++ HANDLE handle =
++ reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, THREAD_ENTRYPOINT, THREAD_ARG, CREATE_SUSPENDED, &thread_id));
++ if (!handle)
+ {
++ // Though MSDN says that _beginthreadex() returns error in errno,
++ // GetLastError() still works because RTL call no other system
++ // functions after CreateThread() in the case of error.
++ // Watch out if it is ever changed.
+ Firebird::system_call_failed::raise("_beginthreadex", GetLastError());
+ }
+- HANDLE handle = reinterpret_cast<HANDLE>(real_handle);
+
+ SetThreadPriority(handle, priority);
+
+--
+2.20.1
+
diff --git a/external/firebird/0001-Make-comparison-operator-member-functions-const.patch.1 b/external/firebird/0001-Make-comparison-operator-member-functions-const.patch.1
new file mode 100644
index 000000000..42c677f7e
--- /dev/null
+++ b/external/firebird/0001-Make-comparison-operator-member-functions-const.patch.1
@@ -0,0 +1,49 @@
+From 15390d75ee6ca429dbbe15ea04214df8a30fbd48 Mon Sep 17 00:00:00 2001
+From: Stephan Bergmann <sbergman@redhat.com>
+Date: Mon, 21 Oct 2019 17:54:18 +0200
+Subject: [PATCH] Make comparison operator member functions const
+
+...which avoids overload resolution ambiguities in C++20, when a synthesized
+candidate of operator == for a reversed-argument rewrite conflicts with the
+actual operator ==, due to the asymmetric const-ness of the implicit object
+parameter and the RHS parameter. (As observed with recent Clang 10 trunk with
+-std=c++2a when building firebird as part of LibreOffice:
+
+> workdir/UnpackedTarball/firebird/src/jrd/inf.cpp:1139:62: error: use of overloaded operator '!=' is ambiguous (with operand types 'RuntimeStatistics::Iterator' and 'Jrd::RuntimeStatistics::Iterator')
+> for (RuntimeStatistics::Iterator iter = stats.begin(); iter != stats.end(); ++iter)
+> ~~~~ ^ ~~~~~~~~~~~
+> workdir/UnpackedTarball/firebird/src/jrd/../dsql/../jrd/RuntimeStatistics.h:283:8: note: candidate function
+> bool operator!=(const Iterator& other)
+> ^
+> workdir/UnpackedTarball/firebird/src/jrd/../dsql/../jrd/RuntimeStatistics.h:278:8: note: candidate function
+> bool operator==(const Iterator& other)
+> ^
+> workdir/UnpackedTarball/firebird/src/jrd/../dsql/../jrd/RuntimeStatistics.h:278:8: note: candidate function (with reversed parameter order)
+
+)
+---
+ src/jrd/RuntimeStatistics.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/jrd/RuntimeStatistics.h b/src/jrd/RuntimeStatistics.h
+index 74a03de2ad..fab286ad1a 100644
+--- a/src/jrd/RuntimeStatistics.h
++++ b/src/jrd/RuntimeStatistics.h
+@@ -290,12 +290,12 @@ public:
+ {}
+
+ public:
+- bool operator==(const Iterator& other)
++ bool operator==(const Iterator& other) const
+ {
+ return (m_counts == other.m_counts);
+ }
+
+- bool operator!=(const Iterator& other)
++ bool operator!=(const Iterator& other) const
+ {
+ return (m_counts != other.m_counts);
+ }
+--
+2.21.0
+
diff --git a/external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.1 b/external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.1
new file mode 100644
index 000000000..a59e70e06
--- /dev/null
+++ b/external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.1
@@ -0,0 +1,41 @@
+From 8305b41bb262b6e249f2551639fa88392e152287 Mon Sep 17 00:00:00 2001
+From: Stephan Bergmann <sbergman@redhat.com>
+Date: Tue, 7 Sep 2021 08:47:32 +0200
+Subject: [PATCH] extern/cloop: Missing dependencies of compilations on output
+ directories
+
+When building Firebird 3.0.7 as part of LibreOffice, we noticed occasional build
+failures like <https://ci.libreoffice.org/job/gerrit_linux_clang_dbgutil/96392/>
+
+> error: unable to open output file '/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/UnpackedTarball/firebird/temp/Debug/cloop/release/tests/test1/CTest.o': 'No such file or directory'
+> 1 error generated.
+> Makefile:72: recipe for target '/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/UnpackedTarball/firebird/temp/Debug/cloop/release/tests/test1/CTest.o' failed
+
+and while target "all" depends on target "mkdirs" (which would create all those
+directories) in extern/cloop/Makefile, there is no order among the dependencies
+of "all", so no guarantee that the directories are already created when the
+compilation recipes are executed.
+---
+ extern/cloop/Makefile | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/extern/cloop/Makefile b/extern/cloop/Makefile
+index 3fca0c7356..c5a2b52628 100644
+--- a/extern/cloop/Makefile
++++ b/extern/cloop/Makefile
+@@ -54,10 +54,10 @@ vpath %.c $(SRC_DIRS)
+ vpath %.cpp $(SRC_DIRS)
+
+ define compile
+-$1/%.o: %.c
++$1/%.o: %.c | $1
+ $(CC) -c $$(C_FLAGS) $$< -o $$@
+
+-$1/%.o: %.cpp
++$1/%.o: %.cpp | $1
+ $(CXX) -c $$(CXX_FLAGS) $$< -o $$@
+ endef
+
+--
+2.31.1
+
diff --git a/external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.1 b/external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.1
new file mode 100644
index 000000000..816f65376
--- /dev/null
+++ b/external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.1
@@ -0,0 +1,67 @@
+From e594cf4c8590bd75a544860b472a5bbf6d5a3d0e Mon Sep 17 00:00:00 2001
+From: Stephan Bergmann <sbergman@redhat.com>
+Date: Thu, 3 Dec 2020 13:56:34 +0100
+Subject: [PATCH] extern/cloop: Missing dependency of $(BIN_DIR)/cloop on
+ $(BIN_DIR)
+
+When building Firebird 3.0.7 as part of LibreOffice, I saw it fail once (at
+<https://ci.libreoffice.org/job/gerrit_linux_clang_dbgutil/74624/>) with
+
+[...]
+> config.status: creating gen/Makefile.extern.editline
+> config.status: creating src/include/gen/autoconfig.auto
+> config.status: executing libtool commands
+>
+>
+> The Firebird3 package has been configured with the following options:
+>
+> Raw devices : enabled
+> Service name : gds_db
+> Service port : 3050
+> GPRE modules : c_cxx.cpp
+>
+> Install Dir : /usr/local/firebird
+>
+> mkpar.c:182:2: warning: add explicit braces to avoid dangling else [-Wdangling-else]
+> else
+> ^
+> 1 warning generated.
+> main.o: In function `create_file_names':
+> main.c:(.text+0x976): warning: the use of `mktemp' is dangerous, better use `mkstemp'
+> /usr/bin/ld: cannot open output file /home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/UnpackedTarball/firebird/gen/Debug/cloop/release/bin/cloop: No such file or directory
+> clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
+> Makefile:84: recipe for target '/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/UnpackedTarball/firebird/gen/Debug/cloop/release/bin/cloop' failed
+> make[6]: *** [/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/UnpackedTarball/firebird/gen/Debug/cloop/release/bin/cloop] Error 1
+> make[6]: Target 'all' not remade because of errors.
+> Makefile:130: recipe for target 'extern' failed
+> make[5]: *** [extern] Error 2
+> Makefile:181: recipe for target 'master_process' failed
+> make[4]: *** [master_process] Error 2
+> Makefile:72: recipe for target 'Debug' failed
+> make[3]: *** [Debug] Error 2
+> Makefile:6: recipe for target 'Debug' failed
+> make[2]: *** [Debug] Error 2
+> /home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/external/firebird/ExternalProject_firebird.mk:29: recipe for target '/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/ExternalProject/firebird/build' failed
+> make[1]: *** [/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/workdir/ExternalProject/firebird/build] Error 1
+[...]
+
+(cherry picked from commit 8e9c48a94659d0c8ac80f716d321b934d47bbed1)
+---
+ extern/cloop/Makefile | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/extern/cloop/Makefile b/extern/cloop/Makefile
+index 6bc6af41a1..811711fcab 100644
+--- a/extern/cloop/Makefile
++++ b/extern/cloop/Makefile
+@@ -80,6 +80,7 @@ $(BIN_DIR)/cloop: \
+ $(OBJ_DIR)/cloop/Lexer.o \
+ $(OBJ_DIR)/cloop/Parser.o \
+ $(OBJ_DIR)/cloop/Main.o \
++ | $(BIN_DIR)
+
+ $(LD) $^ -o $@
+
+--
+2.28.0
+
diff --git a/external/firebird/ExternalPackage_firebird.mk b/external/firebird/ExternalPackage_firebird.mk
new file mode 100644
index 000000000..2416c13d6
--- /dev/null
+++ b/external/firebird/ExternalPackage_firebird.mk
@@ -0,0 +1,28 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_ExternalPackage_ExternalPackage,firebird,firebird))
+
+$(eval $(call gb_ExternalPackage_use_external_project,firebird,firebird))
+
+ifeq ($(OS),WNT)
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/ifbclient.dll,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/bin/ifbclient.dll))
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/Engine12.dll,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/plugins/Engine12.dll))
+else ifeq ($(OS),MACOSX)
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/libfbclient.dylib.3.0.7,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/lib/libfbclient.dylib.3.0.7))
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/libEngine12.dylib,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/plugins/libEngine12.dylib))
+else ifeq ($(DISABLE_DYNLOADING),)
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/libfbclient.so.2,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/lib/libfbclient.so.3.0.7))
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_LIB_FOLDER)/libEngine12.so,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/plugins/libEngine12.so))
+endif
+
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_SHARE_FOLDER)/firebird/firebird.msg,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/firebird.msg))
+$(eval $(call gb_ExternalPackage_add_file,firebird,$(LIBO_SHARE_FOLDER)/firebird/security3.fdb,gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird/security3.fdb))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/firebird/ExternalProject_firebird.mk b/external/firebird/ExternalProject_firebird.mk
new file mode 100644
index 000000000..ccbd69fff
--- /dev/null
+++ b/external/firebird/ExternalProject_firebird.mk
@@ -0,0 +1,107 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_ExternalProject_ExternalProject,firebird))
+
+$(eval $(call gb_ExternalProject_use_autoconf,firebird,build))
+
+$(eval $(call gb_ExternalProject_use_externals,firebird,\
+ boost_headers \
+ icu \
+ libatomic_ops \
+ libtommath \
+))
+
+$(eval $(call gb_ExternalProject_register_targets,firebird,\
+ build \
+))
+
+firebird_BUILDDIR = $(EXTERNAL_WORKDIR)/gen/$(if $(ENABLE_DEBUG),Debug,Release)/firebird
+firebird_VERSION := 3.0.7
+
+$(call gb_ExternalProject_get_state_target,firebird,build):
+ $(call gb_Trace_StartRange,firebird,EXTERNAL)
+ $(call gb_ExternalProject_run,build,\
+ export PKG_CONFIG="" \
+ && export CPPFLAGS=" \
+ $(BOOST_CPPFLAGS) \
+ $(if $(SYSTEM_LIBATOMIC_OPS),$(LIBATOMIC_OPS_CFLAGS), \
+ -I$(call gb_UnpackedTarball_get_dir,libatomic_ops)/src \
+ ) \
+ $(if $(SYSTEM_LIBTOMMATH),$(LIBTOMMATH_CFLAGS), \
+ -I$(call gb_UnpackedTarball_get_dir,libtommath) \
+ ) \
+ $(if $(SYSTEM_ICU),$(ICU_CPPFLAGS), \
+ -I$(call gb_UnpackedTarball_get_dir,icu)/source \
+ -I$(call gb_UnpackedTarball_get_dir,icu)/source/i18n \
+ -I$(call gb_UnpackedTarball_get_dir,icu)/source/common \
+ ) \
+ $(if $(filter GCC-INTEL,$(COM)-$(CPUNAME)),-Di386=1) \
+ " \
+ && export CFLAGS=" \
+ $(if $(filter MSC,$(COM)),$(if $(MSVC_USE_DEBUG_RUNTIME),-DMSVC_USE_DEBUG_RUNTIME)) \
+ $(if $(filter MSC-TRUE-X86_64,$(COM)-$(COM_IS_CLANG)-$(CPUNAME)),-march=x86-64-v2) \
+ $(if $(HAVE_GCC_FNO_SIZED_DEALLOCATION),-fno-sized-deallocation -fno-delete-null-pointer-checks) \
+ $(call gb_ExternalProject_get_build_flags,firebird) \
+ $(if $(ENABLE_DEBUG),$(if $(filter MSC,$(COM)),-Od -Z7)) \
+ " \
+ && export CXXFLAGS=" \
+ $(BOOST_CXXFLAGS) \
+ $(if $(filter MSC,$(COM)),$(if $(MSVC_USE_DEBUG_RUNTIME),-DMSVC_USE_DEBUG_RUNTIME)) \
+ $(if $(filter MSC-TRUE-X86_64,$(COM)-$(COM_IS_CLANG)-$(CPUNAME)),-march=x86-64-v2) \
+ $(if $(HAVE_GCC_FNO_SIZED_DEALLOCATION),-fno-sized-deallocation -fno-delete-null-pointer-checks) \
+ $(CXXFLAGS_CXX11) \
+ $(if $(filter TRUE,$(COM_IS_CLANG)), -Wno-c++11-narrowing) \
+ $(call gb_ExternalProject_get_build_flags,firebird) \
+ $(if $(ENABLE_DEBUG),$(if $(filter MSC,$(COM)),-Od -Z7)) \
+ " \
+ && export LDFLAGS=" \
+ $(call gb_ExternalProject_get_link_flags,firebird) \
+ $(if $(SYSTEM_LIBATOMIC_OPS),$(LIBATOMIC_OPS_LIBS), \
+ -L$(call gb_UnpackedTarball_get_dir,libatomic_ops)/src \
+ ) \
+ $(if $(SYSTEM_LIBTOMMATH),$(LIBTOMMATH_LIBS), \
+ -L$(call gb_UnpackedTarball_get_dir,libtommath) \
+ ) \
+ $(if $(SYSTEM_ICU),$(ICU_LIBS), \
+ -L$(call gb_UnpackedTarball_get_dir,icu)/source/lib \
+ ) \
+ " \
+ && export LIBREOFFICE_ICU_LIB="$(call gb_UnpackedTarball_get_dir,icu)/source/lib" \
+ && export MSVC_USE_INDIVIDUAL_PDBS=TRUE \
+ && MAKE=$(MAKE) $(gb_RUN_CONFIGURE) ./configure \
+ --without-editline \
+ --with-wire-compress=no \
+ $(gb_CONFIGURE_PLATFORMS) \
+ $(if $(DISABLE_DYNLOADING), \
+ --enable-static --disable-shared \
+ , \
+ --enable-shared --disable-static \
+ ) \
+ && LC_ALL=C $(MAKE) \
+ $(if $(ENABLE_DEBUG),Debug) SHELL='$(SHELL)' $(if $(filter LINUX,$(OS)),CXXFLAGS="$$CXXFLAGS -std=gnu++11") \
+ MATHLIB="$(if $(SYSTEM_LIBTOMMATH),$(LIBTOMMATH_LIBS),-L$(call gb_UnpackedTarball_get_dir,libtommath) -ltommath)" \
+ LIBO_TUNNEL_LIBRARY_PATH='$(subst ','\'',$(subst $$,$$$$,$(call gb_Helper_extend_ld_path,$(call gb_UnpackedTarball_get_dir,icu)/source/lib)))' \
+ $(if $(filter MACOSX,$(OS)), \
+ && install_name_tool -id @__________________________________________________OOO/libfbclient.dylib.$(firebird_VERSION) \
+ -delete_rpath @loader_path/.. \
+ $(firebird_BUILDDIR)/lib/libfbclient.dylib.$(firebird_VERSION) \
+ && install_name_tool -id @__________________________________________________OOO/libEngine12.dylib \
+ -delete_rpath @loader_path/.. \
+ $(firebird_BUILDDIR)/plugins/libEngine12.dylib \
+ && install_name_tool -change @rpath/lib/libfbclient.dylib \
+ @loader_path/libfbclient.dylib.$(firebird_VERSION) $(firebird_BUILDDIR)/plugins/libEngine12.dylib \
+ && $(PERL) $(SRCDIR)/solenv/bin/macosx-change-install-names.pl shl OOO \
+ $(firebird_BUILDDIR)/lib/libfbclient.dylib.$(firebird_VERSION) \
+ $(firebird_BUILDDIR)/plugins/libEngine12.dylib \
+ ) \
+ )
+ $(call gb_Trace_EndRange,firebird,EXTERNAL)
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/firebird/Makefile b/external/firebird/Makefile
new file mode 100644
index 000000000..e4968cf85
--- /dev/null
+++ b/external/firebird/Makefile
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+
+module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+include $(module_directory)/../../solenv/gbuild/partial_build.mk
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/firebird/Module_firebird.mk b/external/firebird/Module_firebird.mk
new file mode 100644
index 000000000..d74963f7f
--- /dev/null
+++ b/external/firebird/Module_firebird.mk
@@ -0,0 +1,18 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Module_Module,firebird))
+
+$(eval $(call gb_Module_add_targets,firebird,\
+ ExternalPackage_firebird \
+ ExternalProject_firebird \
+ UnpackedTarball_firebird \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/firebird/README b/external/firebird/README
new file mode 100644
index 000000000..cc7c72743
--- /dev/null
+++ b/external/firebird/README
@@ -0,0 +1,3 @@
+Firebird is an embeddable SQL RDBMS implemented in C++
+
+http://firebirdsql.org/
diff --git a/external/firebird/UnpackedTarball_firebird.mk b/external/firebird/UnpackedTarball_firebird.mk
new file mode 100644
index 000000000..0233ce24d
--- /dev/null
+++ b/external/firebird/UnpackedTarball_firebird.mk
@@ -0,0 +1,82 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_UnpackedTarball_UnpackedTarball,firebird))
+
+$(eval $(call gb_UnpackedTarball_set_tarball,firebird,$(FIREBIRD_TARBALL)))
+
+$(eval $(call gb_UnpackedTarball_set_patchlevel,firebird,0))
+
+$(eval $(call gb_UnpackedTarball_update_autoconf_configs,firebird,\
+ builds/make.new/config \
+ extern/editline \
+))
+
+# * external/firebird/0001-Make-comparison-operator-member-functions-const.patch.1 is upstream at
+# <https://github.com/FirebirdSQL/firebird/pull/227> "Make comparison operator member functions
+# const";
+# * external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.1 is upstream at
+# <https://github.com/FirebirdSQL/firebird/pull/301> "Fix checks for null HANDLE in Windows-only
+# code",
+# * external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.1 is upstream
+# at <https://github.com/FirebirdSQL/firebird/pull/302> "extern/cloop: Missing dependency of
+# $(BIN_DIR)/cloop on $(BIN_DIR)",
+# * external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.1 is upstream
+# at <https://github.com/FirebirdSQL/firebird/pull/6948> "extern/cloop: Missing dependencies of
+# compilations on output directories":
+$(eval $(call gb_UnpackedTarball_add_patches,firebird,\
+ external/firebird/firebird.disable-ib-util-not-found.patch.1 \
+ external/firebird/firebird-Engine12.patch \
+ external/firebird/firebird-rpath.patch.0 \
+ external/firebird/wnt-dbgutil.patch \
+ external/firebird/c++17.patch \
+ external/firebird/ubsan.patch \
+ external/firebird/asan.patch \
+ external/firebird/firebird-tdf125284.patch.1 \
+ external/firebird/0001-Make-comparison-operator-member-functions-const.patch.1 \
+ external/firebird/0001-Fix-warning-on-Win64-build-231.patch.1 \
+ external/firebird/macos-arm64.patch.0 \
+ external/firebird/firebird-btyacc-add-explicit-rule.patch \
+ external/firebird/firebird-307.patch.1 \
+ external/firebird/0001-Fix-checks-for-null-HANDLE-in-Windows-only-code.patch.1 \
+ external/firebird/0001-extern-cloop-Missing-dependency-of-BIN_DIR-cloop-on-.patch.1 \
+ external/firebird/msvc.patch \
+ external/firebird/wnt-per-process-trace-storage.patch.1 \
+ external/firebird/0001-extern-cloop-Missing-dependencies-of-compilations-on.patch.1 \
+ external/firebird/configure-c99.patch \
+))
+
+ifeq ($(OS),WNT)
+$(eval $(call gb_UnpackedTarball_add_patches,firebird,\
+ external/firebird/firebird-cygwin-msvc.patch \
+ external/firebird/firebird-cygwin-msvc-warnings.patch \
+ external/firebird/firebird-vs2017.patch.1 \
+))
+endif
+
+ifeq ($(OS),MACOSX)
+$(eval $(call gb_UnpackedTarball_add_patches,firebird,\
+ external/firebird/firebird-macosx.patch.1 \
+ external/firebird/macosx-elcapitan-dyld.patch \
+))
+endif
+
+ifeq ($(ENABLE_MACOSX_SANDBOX),TRUE)
+$(eval $(call gb_UnpackedTarball_add_patches,firebird,\
+ external/firebird/firebird-macosx-sandbox.patch.1 \
+))
+endif
+
+ifneq ($(filter -fsanitize=%,$(CC)),)
+$(eval $(call gb_UnpackedTarball_add_patches,firebird, \
+ external/firebird/sanitizer.patch \
+))
+endif
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/firebird/asan.patch b/external/firebird/asan.patch
new file mode 100644
index 000000000..2564c54d4
--- /dev/null
+++ b/external/firebird/asan.patch
@@ -0,0 +1,252 @@
+--- builds/posix/Makefile.in
++++ builds/posix/Makefile.in
+@@ -323,8 +323,8 @@
+
+ metadata.fdb: $(RUN_ISQL) $(SRC_ROOT)/dbs/metadata.sql
+ -$(RM) $@
+- $(RUN_ISQL) -q -i $(SRC_ROOT)/dbs/metadata.sql
+- $(RUN_GFIX) -mode read_only $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_ISQL) -q -i $(SRC_ROOT)/dbs/metadata.sql
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_GFIX) -mode read_only $@
+ $(CHMOD) 0444 $@
+
+ $(HELP_FDB): help.fdb
+@@ -333,7 +333,7 @@
+ $(CHMOD) 0444 $@
+
+ help.fdb: $(BLD_ROOT)/misc/help.gbak
+- $(RUN_GBAK) -MODE read_only -R $< $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_GBAK) -MODE read_only -R $< $@
+ $(CHMOD) 0444 $@
+
+ $(SECURITY_FDB): security.fdb
+@@ -343,18 +343,18 @@
+ security.fdb: $(SRC_ROOT)/dbs/security.sql
+ -$(RM) $@
+ -$(RM) $(SECURITY_TMP)
+- echo create database \'$(SECURITY_TMP)\'\; | $(RUN_ISQL)
+- $(RUN_GFIX) -write async $(SECURITY_TMP)
+- $(RUN_ISQL) -i $^ $(SECURITY_TMP)
++ echo create database \'$(SECURITY_TMP)\'\; | $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_ISQL)
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_GFIX) -write async $(SECURITY_TMP)
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_ISQL) -i $^ $(SECURITY_TMP)
+ $(CHMOD) a=rw $(SECURITY_TMP)
+ $(CP) $(SECURITY_TMP) $@
+- $(RUN_GFIX) -write sync $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_GFIX) -write sync $@
+
+ msg.timestamp: $(MSG_FILES)
+ -$(RM) msg.fdb
+- echo create database \'msg.fdb\'\; | $(RUN_ISQL)
+- $(RUN_GFIX) -write async msg.fdb
+- for sql in $(MSG_FILES); do (echo $$sql; $(RUN_ISQL) -i $$sql msg.fdb) || exit; done
++ echo create database \'msg.fdb\'\; | $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_ISQL)
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_GFIX) -write async msg.fdb
++ for sql in $(MSG_FILES); do (echo $$sql; $(LIBO_TUNNEL_LIBRARY_PATH) $(RUN_ISQL) -i $$sql msg.fdb) || exit; done
+ $(TOUCH) $@
+
+
+@@ -560,7 +560,7 @@
+ message_file: $(FIREBIRD_MSG)
+
+ $(FIREBIRD_MSG): $(BUILD_FILE) msg.timestamp
+- $(BUILD_FILE) -d msg.fdb -f $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(BUILD_FILE) -d msg.fdb -f $@
+ $(CHMOD_6) $@
+
+ $(BUILD_FILE): $(BUILD_Objects) $(COMMON_LIB)
+--- builds/posix/Makefile.in.examples
++++ builds/posix/Makefile.in.examples
+@@ -123,8 +123,8 @@
+
+ $(EMPLOYEE_DB): $(EXAMPLES_DEST)/empbuild$(EXEC_EXT) $(INPUT_Sources) $(EXAMPLES_DEST)/isql$(EXEC_EXT)
+ -$(RM) $(EMPLOYEE_DB)
+- ./empbuild $(EMPLOYEE_DB)
+- $(GFIX) -write sync $(EMPLOYEE_DB)
++ $(LIBO_TUNNEL_LIBRARY_PATH) ./empbuild $(EMPLOYEE_DB)
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(GFIX) -write sync $(EMPLOYEE_DB)
+ -$(CHMOD_6) $(EMPLOYEE_DB)
+
+ # To get past the fact isql is called from the programs, we create a local link in this directory
+@@ -140,7 +140,7 @@
+
+ $(EXAMPLES_DEST)/empbuild.fdb : $(EXAMPLES_DEST)/empddl.sql $(EXAMPLES_DEST)/empbld.sql $(EXAMPLES_DEST)/isql$(EXEC_EXT)
+ -$(RM) $(EXAMPLES_DEST)/empbuild.fdb
+- $(EXAMPLES_DEST)/isql$(EXEC_EXT) -i empbld.sql
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(EXAMPLES_DEST)/isql$(EXEC_EXT) -i empbld.sql
+
+ # The chain for intlemp.fdb is the same a script file to create an empty database
+ # to allow a .e program to be compiled, to then create and populate with data
+@@ -158,7 +158,7 @@
+
+ $(EXAMPLES_DEST)/intlbuild.fdb : $(EXAMPLES_DEST)/intlddl.sql $(EXAMPLES_DEST)/intlbld.sql $(EXAMPLES_DEST)/isql$(EXEC_EXT)
+ -$(RM) intlbuild.fdb
+- $(EXAMPLES_DEST)/isql$(EXEC_EXT) -i intlbld.sql
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(EXAMPLES_DEST)/isql$(EXEC_EXT) -i intlbld.sql
+
+
+ $(EXAMPLES_DEST)/%.sql: $(EXAMPLES_SRC)/empbuild/%.sql
+--- builds/posix/make.rules
++++ builds/posix/make.rules
+@@ -68,17 +68,17 @@
+ .SUFFIXES: .c .e .epp .cpp
+
+ .e.c:
+- $(GPRE_CURRENT) $(GPRE_FLAGS) $< $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(GPRE_CURRENT) $(GPRE_FLAGS) $< $@
+
+
+ $(OBJ)/jrd/%.cpp: $(SRC_ROOT)/jrd/%.epp
+- $(GPRE_CURRENT) $(JRD_GPRE_FLAGS) $(firstword $<) $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(GPRE_CURRENT) $(JRD_GPRE_FLAGS) $(firstword $<) $@
+
+ $(OBJ)/isql/%.cpp: $(SRC_ROOT)/isql/%.epp
+- $(GPRE_CURRENT) $(ISQL_GPRE_FLAGS) $< $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(GPRE_CURRENT) $(ISQL_GPRE_FLAGS) $< $@
+
+ $(OBJ)/%.cpp: $(SRC_ROOT)/%.epp
+- $(GPRE_CURRENT) $(GPRE_FLAGS) $(firstword $<) $@
++ $(LIBO_TUNNEL_LIBRARY_PATH) $(GPRE_CURRENT) $(GPRE_FLAGS) $(firstword $<) $@
+
+
+ .SUFFIXES: .lo .o .cpp .c
+--- src/common/classes/alloc.cpp
++++ src/common/classes/alloc.cpp
+@@ -2187,7 +2187,7 @@
+
+ void* MemPool::allocRaw(size_t size)
+ {
+-#ifndef USE_VALGRIND
++#if !(defined USE_VALGRIND || defined USE_ASAN)
+ if (size == DEFAULT_ALLOCATION)
+ {
+ MutexLockGuard guard(*cache_mutex, "MemPool::allocRaw");
+@@ -2267,7 +2267,7 @@
+
+ void MemPool::releaseRaw(bool destroying, void* block, size_t size, bool use_cache) throw ()
+ {
+-#ifndef USE_VALGRIND
++#if !(defined USE_VALGRIND || defined USE_ASAN)
+ if (use_cache && (size == DEFAULT_ALLOCATION))
+ {
+ MutexLockGuard guard(*cache_mutex, "MemPool::releaseRaw");
+@@ -2277,7 +2277,7 @@
+ return;
+ }
+ }
+-#else
++#elif defined USE_VALGRIND
+ // Set access protection for block to prevent memory from deleted pool being accessed
+ int handle = /* //VALGRIND_MAKE_NOACCESS */ VALGRIND_MAKE_MEM_DEFINED(block, size);
+
+--- src/common/classes/alloc.h
++++ src/common/classes/alloc.h
+@@ -295,40 +295,60 @@
+
+ // operators new and delete
+
++#if !defined USE_ASAN
+ inline void* operator new(size_t s ALLOC_PARAMS)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_PASS_ARGS);
+ }
+ inline void* operator new[](size_t s ALLOC_PARAMS)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_PASS_ARGS);
+ }
++#endif
+
+ inline void* operator new(size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS)
+ {
++#if defined USE_ASAN
++ return operator new(s);
++#else
+ return pool.allocate(s ALLOC_PASS_ARGS);
++#endif
+ }
+ inline void* operator new[](size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS)
+ {
++#if defined USE_ASAN
++ return operator new[](s);
++#else
+ return pool.allocate(s ALLOC_PASS_ARGS);
++#endif
+ }
+
++#if !defined USE_ASAN
+ inline void operator delete(void* mem ALLOC_PARAMS) throw()
+ {
+ MemoryPool::globalFree(mem);
+ }
+ inline void operator delete[](void* mem ALLOC_PARAMS) throw()
+ {
+ MemoryPool::globalFree(mem);
+ }
++#endif
+
+ inline void operator delete(void* mem, Firebird::MemoryPool& pool ALLOC_PARAMS) throw()
+ {
++#if defined USE_ASAN
++ return operator delete(mem);
++#else
+ MemoryPool::globalFree(mem);
++#endif
+ }
+ inline void operator delete[](void* mem, Firebird::MemoryPool& pool ALLOC_PARAMS) throw()
+ {
++#if defined USE_ASAN
++ return operator delete[](mem);
++#else
+ MemoryPool::globalFree(mem);
++#endif
+ }
+
+ #ifdef DEBUG_GDS_ALLOC
+--- src/include/firebird.h
++++ src/include/firebird.h
+@@ -38,8 +38,17 @@
+ #include "gen/autoconfig.h"
+ #endif
+
++#if defined __clang__
++//#if __has_feature(address_sanitizer)
++#define USE_ASAN
++//#endif
++#endif
++#if defined __SANITIZE_ADDRESS__
++#define USE_ASAN
++#endif
++
+ // Using our debugging code is pointless when we may use Valgrind features
+-#if defined(DEV_BUILD) && !defined(USE_VALGRIND)
++#if defined(DEV_BUILD) && !(defined(USE_VALGRIND) || defined(USE_ASAN))
+ #define DEBUG_GDS_ALLOC
+ #endif
+
+--- src/jrd/SimilarToMatcher.h
++++ src/jrd/SimilarToMatcher.h
+@@ -338,7 +338,7 @@
+ private:
+ static const unsigned INCREASE_FACTOR = 50;
+ unsigned size;
+- AutoPtr<UCHAR> data;
++ AutoPtr<UCHAR, ArrayDelete> data;
+ T* end;
+ };
+ #endif // RECURSIVE_SIMILAR
+--- configure.orig 2018-06-03 17:44:50.152951348 +0200
++++ configure 2018-06-03 17:45:11.708907807 +0200
+@@ -18479,11 +18479,11 @@
+ #ifdef __cplusplus
+ extern "C"
+ #endif
+-char dlopen ();
++char dlsym ();
+ int
+ main ()
+ {
+-return dlopen ();
++return dlsym ();
+ ;
+ return 0;
+ }
diff --git a/external/firebird/c++17.patch b/external/firebird/c++17.patch
new file mode 100644
index 000000000..4863b89bd
--- /dev/null
+++ b/external/firebird/c++17.patch
@@ -0,0 +1,311 @@
+--- src/common/DynamicStrings.cpp
++++ src/common/DynamicStrings.cpp
+@@ -37,7 +37,7 @@
+
+ namespace Firebird {
+
+-unsigned makeDynamicStrings(unsigned length, ISC_STATUS* const dst, const ISC_STATUS* const src) throw(BadAlloc)
++unsigned makeDynamicStrings(unsigned length, ISC_STATUS* const dst, const ISC_STATUS* const src)
+ {
+ const ISC_STATUS* end = &src[length];
+
+--- src/common/DynamicStrings.h
++++ src/common/DynamicStrings.h
+@@ -34,7 +34,7 @@
+
+ namespace Firebird {
+
+-unsigned makeDynamicStrings(unsigned len, ISC_STATUS* const dst, const ISC_STATUS* const src) throw(BadAlloc);
++unsigned makeDynamicStrings(unsigned len, ISC_STATUS* const dst, const ISC_STATUS* const src);
+ char* findDynamicStrings(unsigned len, ISC_STATUS* ptr) throw();
+
+ } // namespace Firebird
+--- src/common/StatusArg.cpp
++++ src/common/StatusArg.cpp
+@@ -53,7 +53,7 @@
+
+ namespace Arg {
+
+-Base::Base(ISC_STATUS k, ISC_STATUS c) throw(Firebird::BadAlloc) :
++Base::Base(ISC_STATUS k, ISC_STATUS c) :
+ implementation(FB_NEW_POOL(*getDefaultMemoryPool()) ImplBase(k, c))
+ {
+ }
+@@ -94,28 +94,28 @@
+ assign(ex);
+ }
+
+-StatusVector::StatusVector(ISC_STATUS k, ISC_STATUS c) throw(Firebird::BadAlloc) :
++StatusVector::StatusVector(ISC_STATUS k, ISC_STATUS c) :
+ Base(FB_NEW_POOL(*getDefaultMemoryPool()) ImplStatusVector(k, c))
+ {
+ operator<<(*(static_cast<Base*>(this)));
+ }
+
+-StatusVector::StatusVector(const ISC_STATUS* s) throw(Firebird::BadAlloc) :
++StatusVector::StatusVector(const ISC_STATUS* s) :
+ Base(FB_NEW_POOL(*getDefaultMemoryPool()) ImplStatusVector(s))
+ {
+ }
+
+-StatusVector::StatusVector(const IStatus* s) throw(Firebird::BadAlloc) :
++StatusVector::StatusVector(const IStatus* s) :
+ Base(FB_NEW_POOL(*getDefaultMemoryPool()) ImplStatusVector(s))
+ {
+ }
+
+-StatusVector::StatusVector(const Exception& ex) throw(Firebird::BadAlloc) :
++StatusVector::StatusVector(const Exception& ex) :
+ Base(FB_NEW_POOL(*getDefaultMemoryPool()) ImplStatusVector(ex))
+ {
+ }
+
+-StatusVector::StatusVector() throw(Firebird::BadAlloc) :
++StatusVector::StatusVector() :
+ Base(FB_NEW_POOL(*getDefaultMemoryPool()) ImplStatusVector(0, 0))
+ {
+ }
+--- src/common/StatusArg.h
++++ src/common/StatusArg.h
+@@ -87,7 +87,7 @@
+ virtual ~ImplBase() { }
+ };
+
+- Base(ISC_STATUS k, ISC_STATUS c) throw(Firebird::BadAlloc);
++ Base(ISC_STATUS k, ISC_STATUS c);
+ explicit Base(ImplBase* i) throw() : implementation(i) { }
+ ~Base() throw() { delete implementation; }
+
+@@ -144,13 +144,13 @@
+ explicit ImplStatusVector(const Exception& ex) throw();
+ };
+
+- StatusVector(ISC_STATUS k, ISC_STATUS v) throw(Firebird::BadAlloc);
++ StatusVector(ISC_STATUS k, ISC_STATUS v);
+
+ public:
+- explicit StatusVector(const ISC_STATUS* s) throw(Firebird::BadAlloc);
+- explicit StatusVector(const IStatus* s) throw(Firebird::BadAlloc);
+- explicit StatusVector(const Exception& ex) throw(Firebird::BadAlloc);
+- StatusVector() throw(Firebird::BadAlloc);
++ explicit StatusVector(const ISC_STATUS* s);
++ explicit StatusVector(const IStatus* s);
++ explicit StatusVector(const Exception& ex);
++ StatusVector();
+ ~StatusVector() { }
+
+ const ISC_STATUS* value() const throw() { return implementation->value(); }
+--- src/common/classes/alloc.cpp
++++ src/common/classes/alloc.cpp
+@@ -1635,7 +1635,7 @@
+
+ ~FreeObjects();
+
+- FreeObjPtr allocateBlock(MemPool* pool, size_t from, size_t& size) throw (OOM_EXCEPTION)
++ FreeObjPtr allocateBlock(MemPool* pool, size_t from, size_t& size)
+ {
+ size_t full_size = size + (from ? 0 : ListBuilder::MEM_OVERHEAD);
+ if (full_size > Limits::TOP_LIMIT)
+@@ -1705,7 +1705,7 @@
+ ListBuilder listBuilder;
+ Extent* currentExtent;
+
+- MemBlock* newBlock(MemPool* pool, unsigned slot) throw (OOM_EXCEPTION);
++ MemBlock* newBlock(MemPool* pool, unsigned slot);
+ };
+
+
+@@ -1787,26 +1787,26 @@
+ };
+ #endif // VALIDATE_POOL
+
+- MemBlock* alloc(size_t from, size_t& length, bool flagRedirect) throw (OOM_EXCEPTION);
++ MemBlock* alloc(size_t from, size_t& length, bool flagRedirect);
+ void releaseBlock(MemBlock *block, bool flagDecr) throw ();
+
+ public:
+- void* allocate(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION);
+- MemBlock* allocate2(size_t from, size_t& size ALLOC_PARAMS) throw (OOM_EXCEPTION);
++ void* allocate(size_t size ALLOC_PARAMS);
++ MemBlock* allocate2(size_t from, size_t& size ALLOC_PARAMS);
+
+ private:
+- virtual void memoryIsExhausted(void) throw (OOM_EXCEPTION);
+- void* allocRaw(size_t length) throw (OOM_EXCEPTION);
++ virtual void memoryIsExhausted(void);
++ void* allocRaw(size_t length);
+ static void releaseMemory(void* block, bool flagExtent) throw ();
+ static void releaseRaw(bool destroying, void *block, size_t size, bool use_cache = true) throw ();
+- void* getExtent(size_t from, size_t& to) throw (OOM_EXCEPTION);
++ void* getExtent(size_t from, size_t& to);
+
+ public:
+ static void releaseExtent(bool destroying, void *block, size_t size, MemPool* pool) throw ();
+
+ // pass desired size, return actual extent size
+ template <class Extent>
+- void newExtent(size_t& size, Extent** linkedList) throw (OOM_EXCEPTION);
++ void newExtent(size_t& size, Extent** linkedList);
+
+ private:
+ #ifdef USE_VALGRIND
+@@ -1942,7 +1942,7 @@
+
+
+ template <class ListBuilder, class Limits>
+-MemBlock* FreeObjects<ListBuilder, Limits>::newBlock(MemPool* pool, unsigned slot) throw (OOM_EXCEPTION)
++MemBlock* FreeObjects<ListBuilder, Limits>::newBlock(MemPool* pool, unsigned slot)
+ {
+ size_t size = Limits::getSize(slot);
+
+@@ -2151,7 +2151,7 @@
+ }
+
+ template <class Extent>
+-void MemPool::newExtent(size_t& size, Extent** linkedList) throw(OOM_EXCEPTION)
++void MemPool::newExtent(size_t& size, Extent** linkedList)
+ {
+ // No large enough block found. We need to extend the pool
+ void* memory = NULL;
+@@ -2216,7 +2216,7 @@
+ pool->setStatsGroup(newStats);
+ }
+
+-MemBlock* MemPool::alloc(size_t from, size_t& length, bool flagRedirect) throw (OOM_EXCEPTION)
++MemBlock* MemPool::alloc(size_t from, size_t& length, bool flagRedirect)
+ {
+ MutexEnsureUnlock guard(mutex, "MemPool::alloc");
+ guard.enter();
+@@ -2275,7 +2275,7 @@
+ #ifdef DEBUG_GDS_ALLOC
+ , const char* fileName, int line
+ #endif
+-) throw (OOM_EXCEPTION)
++)
+ {
+ size_t length = from ? size : ROUNDUP(size + VALGRIND_REDZONE, roundingSize) + GUARD_BYTES;
+ MemBlock* memory = alloc(from, length, true);
+@@ -2305,7 +2305,7 @@
+ }
+
+
+-void* MemPool::allocate(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION)
++void* MemPool::allocate(size_t size ALLOC_PARAMS)
+ {
+ #ifdef VALIDATE_POOL
+ MutexLockGuard guard(mutex, "MemPool::allocate");
+@@ -2445,12 +2445,12 @@
+ releaseRaw(pool_destroying, hunk, hunk->length, false);
+ }
+
+-void MemPool::memoryIsExhausted(void) throw (OOM_EXCEPTION)
++void MemPool::memoryIsExhausted(void)
+ {
+ Firebird::BadAlloc::raise();
+ }
+
+-void* MemPool::allocRaw(size_t size) throw (OOM_EXCEPTION)
++void* MemPool::allocRaw(size_t size)
+ {
+ #ifndef USE_VALGRIND
+ if (size == DEFAULT_ALLOCATION)
+@@ -2530,7 +2530,7 @@
+ }
+
+
+-void* MemPool::getExtent(size_t from, size_t& to) throw(OOM_EXCEPTION) // pass desired minimum size, return actual extent size
++void* MemPool::getExtent(size_t from, size_t& to) // pass desired minimum size, return actual extent size
+ {
+ #ifdef VALIDATE_POOL
+ MutexLockGuard guard(mutex, "MemPool::getExtent");
+@@ -2653,7 +2653,7 @@
+ deallocate(block);
+ }
+
+-void* MemoryPool::calloc(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION)
++void* MemoryPool::calloc(size_t size ALLOC_PARAMS)
+ {
+ void* block = allocate(size ALLOC_PASS_ARGS);
+ memset(block, 0, size);
+@@ -2800,7 +2800,7 @@
+ }
+
+ #ifdef LIBC_CALLS_NEW
+-void* MemoryPool::globalAlloc(size_t s ALLOC_PARAMS) throw (OOM_EXCEPTION)
++void* MemoryPool::globalAlloc(size_t s ALLOC_PARAMS)
+ {
+ if (!defaultMemoryManager)
+ {
+@@ -2818,7 +2818,7 @@
+ MemPool::globalFree(block);
+ }
+
+-void* MemoryPool::allocate(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION)
++void* MemoryPool::allocate(size_t size ALLOC_PARAMS)
+ {
+ return pool->allocate(size ALLOC_PASS_ARGS);
+ }
+@@ -2876,11 +2876,11 @@
+ // in a case when we actually need "new" only with file/line information
+ // this version should be also present as a pair for "delete".
+ #ifdef DEBUG_GDS_ALLOC
+-void* operator new(size_t s) throw (OOM_EXCEPTION)
++void* operator new(size_t s)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_ARGS);
+ }
+-void* operator new[](size_t s) throw (OOM_EXCEPTION)
++void* operator new[](size_t s)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_ARGS);
+ }
+--- src/common/classes/alloc.h
++++ src/common/classes/alloc.h
+@@ -186,18 +186,18 @@
+ #define ALLOC_PASS_ARGS
+ #endif // DEBUG_GDS_ALLOC
+
+- void* calloc(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION);
++ void* calloc(size_t size ALLOC_PARAMS);
+
+ #ifdef LIBC_CALLS_NEW
+- static void* globalAlloc(size_t s ALLOC_PARAMS) throw (OOM_EXCEPTION);
++ static void* globalAlloc(size_t s ALLOC_PARAMS);
+ #else
+- static void* globalAlloc(size_t s ALLOC_PARAMS) throw (OOM_EXCEPTION)
++ static void* globalAlloc(size_t s ALLOC_PARAMS)
+ {
+ return defaultMemoryManager->allocate(s ALLOC_PASS_ARGS);
+ }
+ #endif // LIBC_CALLS_NEW
+
+- void* allocate(size_t size ALLOC_PARAMS) throw (OOM_EXCEPTION);
++ void* allocate(size_t size ALLOC_PARAMS);
+
+ static void globalFree(void* mem) throw ();
+ void deallocate(void* mem) throw ();
+@@ -289,20 +289,20 @@
+
+ // operators new and delete
+
+-inline void* operator new(size_t s ALLOC_PARAMS) throw (OOM_EXCEPTION)
++inline void* operator new(size_t s ALLOC_PARAMS)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_PASS_ARGS);
+ }
+-inline void* operator new[](size_t s ALLOC_PARAMS) throw (OOM_EXCEPTION)
++inline void* operator new[](size_t s ALLOC_PARAMS)
+ {
+ return MemoryPool::globalAlloc(s ALLOC_PASS_ARGS);
+ }
+
+-inline void* operator new(size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS) throw (OOM_EXCEPTION)
++inline void* operator new(size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS)
+ {
+ return pool.allocate(s ALLOC_PASS_ARGS);
+ }
+-inline void* operator new[](size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS) throw (OOM_EXCEPTION)
++inline void* operator new[](size_t s, Firebird::MemoryPool& pool ALLOC_PARAMS)
+ {
+ return pool.allocate(s ALLOC_PASS_ARGS);
+ }
diff --git a/external/firebird/configure-c99.patch b/external/firebird/configure-c99.patch
new file mode 100644
index 000000000..f582d383e
--- /dev/null
+++ b/external/firebird/configure-c99.patch
@@ -0,0 +1,23 @@
+--- configure
++++ configure
+@@ -21478,8 +21478,9 @@
+ else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
++#include <stdlib.h>
+ #include <semaphore.h>
+-main () {
++int main () {
+ struct s {
+ char a;
+ union { long long x; sem_t y; } b;
+@@ -21514,7 +21515,8 @@
+ else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+-main () {
++#include <stdlib.h>
++int main () {
+ struct s {
+ char a;
+ double b;
diff --git a/external/firebird/firebird-307.patch.1 b/external/firebird/firebird-307.patch.1
new file mode 100644
index 000000000..6af479838
--- /dev/null
+++ b/external/firebird/firebird-307.patch.1
@@ -0,0 +1,12 @@
+diff -ur firebird.org/builds/posix/Makefile.in firebird/builds/posix/Makefile.in
+--- firebird.org/builds/posix/Makefile.in 2020-11-08 15:11:29.262993342 +0100
++++ firebird/builds/posix/Makefile.in 2020-11-08 15:16:53.628545143 +0100
+@@ -264,7 +264,7 @@
+ ODS_TEST:=$(GEN_ROOT)/odstest$(EXEC_EXT)
+
+ preliminaryCheck: $(STD_SIZES) $(RUN_SIZES)
+- diff -u $^
++ diff -u --strip-trailing-cr $^
+
+ $(RUN_SIZES): $(ODS_H) $(ODS_AWK)
+ awk -f $(ODS_AWK) <$(ODS_H) >$(ODS_TEST_CPP)
diff --git a/external/firebird/firebird-Engine12.patch b/external/firebird/firebird-Engine12.patch
new file mode 100644
index 000000000..f6590b300
--- /dev/null
+++ b/external/firebird/firebird-Engine12.patch
@@ -0,0 +1,16 @@
+--- src/common/utils.cpp
++++ src/common/utils.cpp
+@@ -1026,6 +1026,13 @@
+ PathUtils::concatPath(s, configDir[prefType], name);
+ return s;
+ }
++
++ // Set relative path to Engine12 dynamic library
++ if(prefType == Firebird::IConfigManager::DIR_PLUGINS)
++ {
++ s = name;
++ return s;
++ }
+ }
+
+ switch(prefType)
diff --git a/external/firebird/firebird-btyacc-add-explicit-rule.patch b/external/firebird/firebird-btyacc-add-explicit-rule.patch
new file mode 100644
index 000000000..c4d88d911
--- /dev/null
+++ b/external/firebird/firebird-btyacc-add-explicit-rule.patch
@@ -0,0 +1,12 @@
+--- extern/btyacc/Makefile.orig 2020-11-13 18:57:44.831455058 +0100
++++ extern/btyacc/Makefile 2020-11-13 18:59:19.071078333 +0100
+@@ -44,6 +44,9 @@
+ $(PROGRAM): $(OBJS) $(LIBS)
+ $(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
+
++%.o: %.c
++ $(CC) $(CCFLAGS) -c $< -o $@
++
+ clean:; rm -f $(OBJS)
+
+ clobber:; rm -f $(OBJS) $(PROGRAM)
diff --git a/external/firebird/firebird-cygwin-msvc-warnings.patch b/external/firebird/firebird-cygwin-msvc-warnings.patch
new file mode 100644
index 000000000..942522439
--- /dev/null
+++ b/external/firebird/firebird-cygwin-msvc-warnings.patch
@@ -0,0 +1,300 @@
+diff -ur builds/posix/make.defaults builds/posix/make.defaults
+--- builds/posix/make.defaults 2016-07-07 13:56:13.036235166 +0200
++++ builds/posix/make.defaults 2016-07-07 14:29:52.368289242 +0200
+@@ -102,7 +102,7 @@
+ #____________________________________________________________________________
+
+ # Firebird needs no RTTI
+-RTTI_FLAG:= -fno-rtti
++RTTI_FLAG:=
+
+ # If this is defined then we use special rules useful for developers only
+ IsDeveloper = @DEVEL_FLG@
+@@ -175,6 +175,7 @@
+ # Default extensions
+
+ ARCH_EXT= .lib
++OBJ_EXT= obj
+ EXEC_EXT= @EXEEXT@
+ SHRLIB_EXT=@SHRLIB_EXT@
+ LIB_PREFIX=
+--- builds/posix/Makefile.in 2016-07-07 15:56:06.459221300 +0200
++++ builds/posix/Makefile.in 2016-07-13 12:44:57.134217200 +0200
+@@ -665,7 +666,7 @@
+
+ include $(ROOT)/gen/make.shared.targets
+
+-Dependencies = $(AllObjects:.o=.d)
++Dependencies = $(AllObjects:.$(OBJ_EXT)=.d)
+ -include $(Dependencies)
+
+
+@@ -729,14 +730,14 @@
+ -$(MAKE) -C $(ROOT)/extern/libtommath clean
+
+ clean_objects:
+- $(RM) `find $(TMP_ROOT)/ -type f -name '*.o' -print`
++ $(RM) `find $(TMP_ROOT)/ -type f -name '*.$(OBJ_EXT)' -print`
+ $(RM) `find $(TMP_ROOT)/ -type f -name '*.a' -print`
+ $(RM) `find $(TMP_ROOT)/ -type f -name '*.cpp' -print`
+ $(RM) `find $(TMP_ROOT)/ -type f -name '*.pas' -print`
+
+ clean_extern_objects:
+ $(RM) `find $(ROOT)/extern/ -type f -name '*.lo' -print`
+- $(RM) `find $(ROOT)/extern/ -type f -name '*.o' -print`
++ $(RM) `find $(ROOT)/extern/ -type f -name '*.$(OBJ_EXT)' -print`
+
+ # Clear out dependancies files created by the gcc compiler
+ # since when .o and other files are deleted the dependant
+diff -ur builds/posix/make.rules builds/posix/make.rules
+--- builds/posix/make.rules 2016-07-07 13:56:13.036235166 +0200
++++ builds/posix/make.rules 2016-07-07 14:31:16.116291485 +0200
+@@ -92,21 +92,21 @@
+ $(LIBO_TUNNEL_LIBRARY_PATH) $(GPRE_CURRENT) $(GPRE_FLAGS) $(firstword $<) $@
+
+
+-.SUFFIXES: .lo .o .cpp .c
++.SUFFIXES: .lo .$(OBJ_EXT) .cpp .c
+
+-%.o: %.c
++%.$(OBJ_EXT): %.c
+ $(CC) $(WCFLAGS) -c $(firstword $<) -o $@
+
+-$(OBJ)/%.o: $(SRC_ROOT)/%.c
++$(OBJ)/%.$(OBJ_EXT): $(SRC_ROOT)/%.c
+ $(CC) $(WCFLAGS) -c $(firstword $<) -o $@
+
+-$(OBJ)/%.o: $(OBJ)/%.cpp
++$(OBJ)/%.$(OBJ_EXT): $(OBJ)/%.cpp
+ $(CXX) $(WCXXFLAGS) -c $(firstword $<) -o $@
+
+-$(OBJ)/%.o: $(SRC_ROOT)/%.cpp
++$(OBJ)/%.$(OBJ_EXT): $(SRC_ROOT)/%.cpp
+ $(CXX) $(WCXXFLAGS) -c $(firstword $<) -o $@
+
+-$(OBJ)/%.o: $(ROOT)/%.cpp
++$(OBJ)/%.$(OBJ_EXT): $(ROOT)/%.cpp
+ $(CC) $(WCFLAGS) -c $(firstword $<) -o $@
+
+ .SUFFIXES: .epp .e
+--- builds/posix/make.shared.variables.orig 2020-11-12 19:36:29.773409900 +0100
++++ builds/posix/make.shared.variables 2020-11-12 19:37:14.976503300 +0100
+@@ -1,5 +1,5 @@
+ # Helper functions
+-doObjects= $(patsubst %.y,%.o,$(patsubst %.epp,%.o,$(patsubst %.c,%.o,$(1:.cpp=.o))))
++doObjects= $(patsubst %.y,%.$(OBJ_EXT),$(patsubst %.epp,%.$(OBJ_EXT),$(patsubst %.c,%.$(OBJ_EXT),$(1:.cpp=.$(OBJ_EXT)))))
+ makeObjects= $(addprefix $(OBJ)/$(patsubst ../%,%,$(1))/,$(call doObjects,$2))
+ dirFiles= $(notdir $(wildcard ../src/$(1)/*.cpp)) $(notdir $(wildcard ../src/$(1)/*.c)) \
+ $(notdir $(wildcard ../src/$(1)/*.epp)) $(notdir $(wildcard ../src/$(1)/*.y))
+--- src/include/gen/autoconfig.h.in.orig 2020-11-12 20:52:49.835722200 +0100
++++ src/include/gen/autoconfig.h.in 2020-11-12 20:53:18.148311100 +0100
+@@ -773,7 +773,9 @@
+ #pragma warning(disable:4996) // 'identificator' was declared deprecated
+ #endif
+
++#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
++#endif
+
+ //#ifdef _MSC_VER // don't know if this is useful for MinGW
+ #define NOATOM
+--- builds/posix/prefix.mingw.orig 2020-11-12 21:37:39.574461300 +0100
++++ builds/posix/prefix.mingw 2020-11-12 21:37:55.448422500 +0100
+@@ -20,8 +20,8 @@
+ #
+
+ # -Wno-unused-variable is used due to unused gpre generated variables
+-PROD_FLAGS=-O2 -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN
+-DEV_FLAGS=-ggdb -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN
++PROD_FLAGS=-O2 -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN -wd4291 -wd4477
++DEV_FLAGS=-ggdb -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN -wd4291 -wd4477
+
+ PLATFORM_PATH=os/win32
+
+--- extern/btyacc/Makefile.orig 2020-11-12 21:39:13.833012400 +0100
++++ extern/btyacc/Makefile 2020-11-12 21:39:54.861473300 +0100
+@@ -25,8 +25,8 @@
+
+ MAKEFILE = Makefile
+
+-OBJS = closure.o error.o lalr.o lr0.o main.o mkpar.o output.o \
+- mstring.o reader.o readskel.o skeleton.o symtab.o verbose.o warshall.o
++OBJS = closure.obj error.obj lalr.obj lr0.obj main.obj mkpar.obj output.obj \
++ mstring.obj reader.obj readskel.obj skeleton.obj symtab.obj verbose.obj warshall.obj
+
+ PRINT = pr -f -l88
+
+@@ -44,7 +44,7 @@
+ $(PROGRAM): $(OBJS) $(LIBS)
+ $(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
+
+-%.o: %.c
++%.obj: %.c
+ $(CC) $(CCFLAGS) -c $< -o $@
+
+ clean:; rm -f $(OBJS)
+@@ -93,16 +93,16 @@
+ etags *.c *.h
+
+ ###
+-closure.o: defs.h
+-error.o: defs.h
+-lalr.o: defs.h
+-lr0.o: defs.h
+-main.o: defs.h
+-mkpar.o: defs.h
+-mstring.o: mstring.h
+-output.o: defs.h
+-reader.o: defs.h mstring.h
+-skeleton.o: defs.h
+-symtab.o: defs.h
+-verbose.o: defs.h
+-warshall.o: defs.h
++closure.obj: defs.h
++error.obj: defs.h
++lalr.obj: defs.h
++lr0.obj: defs.h
++main.obj: defs.h
++mkpar.obj: defs.h
++mstring.obj: mstring.h
++output.obj: defs.h
++reader.obj: defs.h mstring.h
++skeleton.obj: defs.h
++symtab.obj: defs.h
++verbose.obj: defs.h
++warshall.obj: defs.h
+--- extern/cloop/Makefile.orig 2020-11-13 10:59:53.282923700 +0100
++++ extern/cloop/Makefile 2020-11-13 11:00:24.267079900 +0100
+@@ -24,8 +24,8 @@
+ SRCS_C := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.c))
+ SRCS_CPP := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.cpp))
+
+-OBJS_C := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS_C))
+-OBJS_CPP := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS_CPP))
++OBJS_C := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.obj,$(SRCS_C))
++OBJS_CPP := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.obj,$(SRCS_CPP))
+
+ C_FLAGS := -fPIC
+ CXX_FLAGS := $(C_FLAGS)
+@@ -43,10 +43,10 @@
+ vpath %.cpp $(SRC_DIRS)
+
+ define compile
+-$1/%.o: %.c | $1
++$1/%.obj: %.c | $1
+ $(CC) -c $$(C_FLAGS) $$< -o $$@
+
+-$1/%.o: %.cpp | $1
++$1/%.obj: %.cpp | $1
+ $(CXX) -c $$(CXX_FLAGS) $$< -o $$@
+ endef
+
+@@ -75,11 +75,11 @@
+ -include $(addsuffix .d,$(basename $(OBJS_CPP)))
+
+ $(BIN_DIR)/cloop$(EXE_EXT): \
+- $(OBJ_DIR)/cloop/Expr.o \
+- $(OBJ_DIR)/cloop/Generator.o \
+- $(OBJ_DIR)/cloop/Lexer.o \
+- $(OBJ_DIR)/cloop/Parser.o \
+- $(OBJ_DIR)/cloop/Main.o \
++ $(OBJ_DIR)/cloop/Expr.obj \
++ $(OBJ_DIR)/cloop/Generator.obj \
++ $(OBJ_DIR)/cloop/Lexer.obj \
++ $(OBJ_DIR)/cloop/Parser.obj \
++ $(OBJ_DIR)/cloop/Main.obj \
+ | $(BIN_DIR)
+
+ $(LD) $^ -o $@
+@@ -105,24 +105,24 @@
+ $(SRC_DIR)/tests/test1/CppTest.cpp: $(SRC_DIR)/tests/test1/CalcCppApi.h
+
+ $(BIN_DIR)/test1-c$(SHRLIB_EXT): \
+- $(OBJ_DIR)/tests/test1/CalcCApi.o \
+- $(OBJ_DIR)/tests/test1/CTest.o \
++ $(OBJ_DIR)/tests/test1/CalcCApi.obj \
++ $(OBJ_DIR)/tests/test1/CTest.obj \
+
+ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-c$(EXE_EXT): \
+- $(OBJ_DIR)/tests/test1/CalcCApi.o \
+- $(OBJ_DIR)/tests/test1/CTest.o \
++ $(OBJ_DIR)/tests/test1/CalcCApi.obj \
++ $(OBJ_DIR)/tests/test1/CTest.obj \
+
+ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-cpp$(SHRLIB_EXT): \
+- $(OBJ_DIR)/tests/test1/CppTest.o \
++ $(OBJ_DIR)/tests/test1/CppTest.obj \
+
+ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-cpp$(EXE_EXT): \
+- $(OBJ_DIR)/tests/test1/CppTest.o \
++ $(OBJ_DIR)/tests/test1/CppTest.obj \
+
+ $(LD) $^ -o $@
+
+--- src/include/gen/autoconfig_msvc.h.orig 2020-11-13 12:42:36.231813100 +0100
++++ src/include/gen/autoconfig_msvc.h 2020-11-13 12:43:12.669012900 +0100
+@@ -68,7 +68,9 @@
+ #pragma warning(disable:4996) // 'identificator' was declared deprecated
+
+
++#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
++#endif
+
+ #ifdef _MSC_VER // don't know if this is useful for MinGW
+ #define NOATOM
+diff -ur builds/posix/Makefile.in.examples builds/posix/Makefile.in.examples
+--- builds/posix/Makefile.in.examples 2016-07-07 13:56:13.048235166 +0200
++++ builds/posix/Makefile.in.examples 2016-07-07 14:37:36.904301682 +0200
+@@ -65,9 +65,9 @@
+ EXAMPLES_SRC= $(ROOT)/examples
+
+
+-EMPBLD_Objects= $(EXAMPLES_DEST)/empbuild.o
++EMPBLD_Objects= $(EXAMPLES_DEST)/empbuild.$(OBJ_EXT)
+
+-INTLBLD_Objects= $(EXAMPLES_DEST)/intlbld.o
++INTLBLD_Objects= $(EXAMPLES_DEST)/intlbld.$(OBJ_EXT)
+
+ INPUT_Files = empddl.sql empdml.sql indexoff.sql indexon.sql \
+ job.inp lang.inp proj.inp qtr.inp
+@@ -172,3 +175,6 @@
+
+ $(EXAMPLES_DEST)/%.h: $(EXAMPLES_SRC)/common/%.h
+ $(CP) $^ $@
++
++$(EXAMPLES_DEST)/%.$(OBJ_EXT): $(EXAMPLES_DEST)/%.c
++ $(CC) -c $(firstword $<) -Fo$@ $(WCFLAGS)
+--- src/lock/lock.cpp.orig 2020-11-13 17:57:23.485241200 +0100
++++ src/lock/lock.cpp 2020-11-13 17:57:51.001010600 +0100
+@@ -463,6 +463,7 @@
+
+ LockTableGuard guard(This, FB_FUNCTION, owner_offset);
+
++#undef SRQ_BASE
+ #define SRQ_BASE ((UCHAR*) This->m_sharedMemory->getHeader())
+ own* owner = (own*) SRQ_ABS_PTR(owner_offset);
+ if (!owner->own_count)
+@@ -486,6 +487,7 @@
+ // released before destroying the lock owner. This is not strictly required,
+ // but it enforces the proper object lifetime discipline through the codebase.
+ fb_assert(SRQ_EMPTY(owner->own_requests));
++#undef SRQ_BASE
+ #define SRQ_BASE ((UCHAR*) m_sharedMemory->getHeader())
+
+ This->purge_owner(owner_offset, owner);
+--- builds/posix/Makefile.in.plugins_examples.orig 2020-11-13 20:25:55.865485400 +0100
++++ builds/posix/Makefile.in.plugins_examples 2020-11-13 20:26:13.084191800 +0100
+@@ -104,5 +104,5 @@
+
+ include $(ROOT)/gen/make.shared.targets
+
+-Dependencies = $(AllObjects:.o=.d)
++Dependencies = $(AllObjects:.$(OBJ_EXT)=.d)
+ -include $(Dependencies)
diff --git a/external/firebird/firebird-cygwin-msvc.patch b/external/firebird/firebird-cygwin-msvc.patch
new file mode 100644
index 000000000..c59c614ba
--- /dev/null
+++ b/external/firebird/firebird-cygwin-msvc.patch
@@ -0,0 +1,686 @@
+--- src/include/firebird.h 2016-07-15 11:31:27.151443500 +0200
++++ src/include/firebird.h 2016-07-17 14:50:04.043792400 +0200
+@@ -32,11 +32,7 @@
+ #ifndef INCLUDE_Firebird_H
+ #define INCLUDE_Firebird_H
+
+-#ifdef _MSC_VER
+-#include "gen/autoconfig_msvc.h"
+-#else
+ #include "gen/autoconfig.h"
+-#endif
+
+ #if defined __clang__
+ //#if __has_feature(address_sanitizer)
+--- src/misc/writeBuildNum.sh 2016-07-07 15:57:04.538983200 +0200
++++ src/misc/writeBuildNum.sh 2016-07-13 11:31:18.132820200 +0200
+@@ -95,9 +95,9 @@
+ createMakeVersion() {
+
+ OdsH="${Root}/src/jrd/ods.h"
+-Mini="/tmp/miniods.h"
+-TestCpp="/tmp/test.cpp"
+-AOut="/tmp/a.out"
++Mini=$(cygpath -m "/tmp/miniods.h")
++TestCpp=$(cygpath -m "/tmp/test.cpp")
++AOut=$(cygpath -m "/tmp/a.out")
+
+ grep ODS_VERSION $OdsH | grep -v ENCODE_ODS >$Mini
+
+--- configure 2016-07-07 15:57:04.538983200 +0200
++++ configure 2016-07-13 11:31:18.132820200 +0200
+@@ -21490,13 +21490,12 @@
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <stdlib.h>
+-#include <semaphore.h>
+ int main () {
+ struct s {
+ char a;
+- union { long long x; sem_t y; } b;
++ long long b;
+ };
+ exit((int)&((struct s*)1024)->b - 1024);
+ }
+ _ACEOF
+ if ac_fn_c_try_run "$LINENO"; then :
+--- builds/make.new/config/config.h.in 2016-07-07 15:55:55.693112800 +0200
++++ builds/make.new/config/config.h.in 2016-07-08 13:38:49.994986400 +0200
+@@ -211,7 +211,7 @@
+ #undef HAVE_GETMNTENT
+
+ /* Define to 1 if you have the `getpagesize' function. */
+-#undef HAVE_GETPAGESIZE
++#define HAVE_GETPAGESIZE 1
+
+ /* Define to 1 if you have the `getrlimit' function. */
+ #undef HAVE_GETRLIMIT
+@@ -396,7 +396,7 @@
+ #undef HAVE_SIGSET
+
+ /* Define to 1 if you have the `snprintf' function. */
+-#undef HAVE_SNPRINTF
++#define HAVE_SNPRINTF
+
+ /* Define to 1 if you have the <socket.h> header file. */
+ #undef HAVE_SOCKET_H
+@@ -551,7 +551,7 @@
+ #undef HAVE_VFORK_H
+
+ /* Define to 1 if you have the `vsnprintf' function. */
+-#undef HAVE_VSNPRINTF
++#define HAVE_VSNPRINTF
+
+ /* Define to 1 if you have the <winsock2.h> header file. */
+ #undef HAVE_WINSOCK2_H
+@@ -646,7 +646,7 @@
+ #undef TIME_WITH_SYS_TIME
+
+ /* Define this if OS is Windows NT */
+-#undef WIN_NT
++#define WIN_NT
+
+ /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
+@@ -703,3 +703,20 @@
+ #ifndef HAVE_SOCKLEN_T
+ typedef int socklen_t;
+ #endif
++
++/* taken from src/include/gen/autoconfig_msvc.h */
++#ifndef WIN32_LEAN_AND_MEAN
++#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
++#endif
++/* target architecture */
++#if defined(_M_AMD64)
++#define AMD64
++#endif
++
++#define HAVE_IO_H
++#define HAVE_CTIME_S
++
++#if defined _MSC_VER
++#define isnan _isnan
++#endif
++
+--- src/common/common.h 2016-07-15 11:31:26.366735500 +0200
++++ src/common/common.h 2016-07-17 16:18:39.121579400 +0200
+@@ -551,15 +551,6 @@
+ #endif /* WIN_NT */
+
+
+-#ifndef FB_CPU
+-#error Define FB_CPU for your platform
+-#endif
+-#ifndef FB_OS
+-#error Define FB_OS for your platform
+-#endif
+-#ifndef FB_CC
+-#error Define FB_CC for your platform
+-#endif
+
+
+ /*****************************************************
+diff -ur builds/posix/make.defaults builds/posix/make.defaults
+--- builds/posix/make.defaults 2016-07-07 13:56:13.036235166 +0200
++++ builds/posix/make.defaults 2016-07-07 14:29:52.368289242 +0200
+@@ -56,7 +56,7 @@
+ else
+ FIREBIRD=$(FB_BUILD)
+ endif
+-FIREBIRD_LOCK=$(FIREBIRD)
++FIREBIRD_LOCK=$(shell cygpath -w $(FIREBIRD))
+
+ export FIREBIRD
+ export FIREBIRD_LOCK
+@@ -153,7 +153,7 @@
+ CD= cd
+ CAT= cat
+ AR= ar @AR_OPTIONS@
+-LN= @LN_S@
++LN= cp
+ RANLIB= @RANLIB@
+ BTYACC=$(ROOT)/extern/btyacc/btyacc
+ CLOOP=$(GEN_ROOT)/$(TARGET)/cloop/release/bin/cloop
+@@ -175,10 +175,10 @@
+
+ # Default extensions
+
+-ARCH_EXT= .a
++ARCH_EXT= .lib
+ EXEC_EXT= @EXEEXT@
+ SHRLIB_EXT=@SHRLIB_EXT@
+-LIB_PREFIX= lib
++LIB_PREFIX=
+ SHRLIB_FOREIGN_EXT= $(SHRLIB_EXT)
+
+ #_____________________________________________________________________________
+@@ -201,9 +202,8 @@
+
+ # Search path for libraries
+
+-vpath %.so $(LIB)
+-vpath %.a $(LIB)
+ vpath %.dll $(LIB)
++vpath %.lib $(LIB)
+
+ #_____________________________________________________________________________
+
+@@ -217,9 +217,9 @@
+ #
+
+ #LibraryFileName=libfbclient
+-LibraryFileName=libfbclient
+-LibraryFullName=$(LibraryFileName).${SHRLIB_EXT}.${FirebirdVersion}
+-LibrarySoName=$(LibraryFileName).${SHRLIB_EXT}.2
++LibraryFileName=ifbclient
++LibraryFullName=$(LibraryFileName).${SHRLIB_EXT}
++LibrarySoName=$(LibraryFileName).${SHRLIB_EXT}
+ LibraryBaseName=$(LibraryFileName).${SHRLIB_EXT}
+
+ LIBFIREBIRD_FULLNAME = $(LIB)/$(LibraryFullName)
+@@ -228,7 +228,7 @@
+
+ # The firebird engine library name
+
+-EngineFileName=libEngine${OdsVersion}
++EngineFileName=Engine12
+ EngineSoName=$(EngineFileName).${SHRLIB_EXT}
+ ENGINE_SONAME = $(PLUGINS)/$(EngineSoName)
+
+@@ -242,7 +242,7 @@
+ ifeq ($(STD_EDITLINE), true)
+ LIBEDITLINE := -l$(READLINE)
+ else
+- LIBEDITLINE := $(LIB)/libedit.a
++ LIBEDITLINE := $(LIB)/$(LIB_PREFIX)edit$(ARCH_EXT)
+ endif
+ endif
+
+@@ -313,7 +313,7 @@
+
+ LIB_LINK_SONAME= -Wl,-soname,$(1)
+ LIB_LINK_MAPFILE= -Wl,--version-script,$(1)
+-FIREBIRD_LIBRARY_LINK= -L$(LIB) -lfbclient $(MATHLIB)
++FIREBIRD_LIBRARY_LINK= -L$(LIB) -lifbclient $(MATHLIB)
+
+ EXE_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS) $(LINK_EMPTY_SYMBOLS)
+ LIB_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) -shared
+@@ -355,7 +355,7 @@
+
+ # Pay attention - we place common library into obj, not lib dir
+ # It's just a set of object files, prepared to be used by ld, not an output library
+-COMMON_LIB = $(OBJ)/common.a
++COMMON_LIB = $(OBJ)/$(LIB_PREFIX)common$(ARCH_EXT)
+
+ # From utilities
+ CREATE_DB = $(RBIN)/create_db$(EXEC_EXT)
+--- builds/posix/Makefile.in 2016-07-07 15:56:06.459221300 +0200
++++ builds/posix/Makefile.in 2016-07-13 12:44:57.134217200 +0200
+@@ -33,7 +33,7 @@
+ # Alex Peshkoff - created single makefile based on Mark's files
+ #
+
+-ROOT=$(shell cd ..; pwd)
++ROOT=$(shell cygpath -m '$(shell cd ..; pwd)')
+
+ include make.defaults
+ ifeq ($(CROSS_OUT), Y)
+@@ -178,7 +178,7 @@
+ .PHONY: cross1 cross2 boot yvalve engine fbintl gpre utilities plugins rest codes ids examples cross_rest preliminaryCheck
+
+ master_process:
+- ln -sf $(SRC_ROOT)/include/gen/autoconfig.auto $(SRC_ROOT)/include/gen/autoconfig.h
++ cp -f $(SRC_ROOT)/include/gen/autoconfig.auto $(SRC_ROOT)/include/gen/autoconfig.h
+ $(MAKE) updateBuildNum
+ $(MAKE) export_lists
+ $(MAKE) extern
+@@ -214,7 +215,7 @@
+ $(MAKE) CROSS_OUT=Y cross2
+
+ cross1:
+- ln -sf $(SRC_ROOT)/include/gen/autoconfig.auto $(SRC_ROOT)/include/gen/autoconfig.h
++ cp -f $(SRC_ROOT)/include/gen/autoconfig.auto $(SRC_ROOT)/include/gen/autoconfig.h
+ $(MAKE) updateBuildNum
+ $(MAKE) export_lists
+ $(MAKE) extern
+@@ -239,7 +240,7 @@
+ $(MAKE) -f Makefile.examples -C $(GEN_ROOT)/examples/
+
+ cross2:
+- ln -sf $(SRC_ROOT)/include/cross/$(CROSS_CONFIG) $(SRC_ROOT)/include/gen/autoconfig.h
++ cp -f $(SRC_ROOT)/include/cross/$(CROSS_CONFIG) $(SRC_ROOT)/include/gen/autoconfig.h
+ $(MAKE) prerequisites
+ $(MAKE) tommath
+ $(MAKE) yvalve
+@@ -310,7 +311,7 @@
+
+ # remote redirector is statically linked in main FB library
+ $(LIBFIREBIRD_FULLNAME): $(YValve_Objects) $(Remote_Client_Objects) $(COMMON_LIB)
+- $(LINK_FIREBIRD) -o $@ $^ $(LINK_FIREBIRD_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,lib/libfbclient.$(SHRLIB_EXT))
++ $(LINK_FIREBIRD) $(CPPFLAGS) -o $@ $^ $(LINK_FIREBIRD_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,lib/libfbclient.$(SHRLIB_EXT))
+
+
+ #___________________________________________________________________________
+@@ -320,8 +321,8 @@
+
+ engine: $(ENGINE_SONAME)
+
+-$(ENGINE_SONAME): $(Engine_Objects) $(SVC_Objects) $(COMMON_LIB)
+- $(LINK_ENGINE) -o $@ $^ $(LINK_ENGINE_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/$(EngineSoName))
++$(ENGINE_SONAME): $(Engine_Objects) $(SVC_Objects) $(YValve_Objects) $(Remote_Client_Objects) $(COMMON_LIB)
++ $(LINK_ENGINE) $(CPPFLAGS) -o $@ $^ $(LINK_ENGINE_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/$(EngineSoName))
+
+
+ #___________________________________________________________________________
+@@ -330,8 +331,8 @@
+
+ fbintl: $(LIBFBINTL_SO)
+
+-$(LIBFBINTL_SO): $(INTL_Objects) $(COMMON_LIB)
+- $(LINK_INTL) -o $@ $^ $(LINK_INTL_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,intl/libfbintl.$(SHRLIB_EXT))
++$(LIBFBINTL_SO): $(INTL_Objects) $(YValve_Objects) $(Remote_Client_Objects) $(COMMON_LIB)
++ $(LINK_INTL) $(CPPFLAGS) -o $@ $^ $(LINK_INTL_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,intl/libfbintl.$(SHRLIB_EXT))
+
+
+ #___________________________________________________________________________
+@@ -427,12 +429,13 @@
+
+ .PHONY: firebird_server fb_lock_print fbguard fbsvcmgr fbtracemgr gbak gfix gsec gsplit gstat isql nbackup
+
+-utilities: firebird_server fb_lock_print fbguard fbsvcmgr fbtracemgr gbak gfix gsec gsplit gstat isql nbackup udfsupport
++# fbguard currently fails to link, with missing fork etc, in util.cpp
++utilities: firebird_server fb_lock_print fbsvcmgr fbtracemgr gbak gfix gsec gsplit gstat isql nbackup udfsupport
+
+ firebird_server: $(FB_DAEMON)
+
+-$(FB_DAEMON): $(Remote_Server_Objects) $(COMMON_LIB)
+- $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) $(call LINK_DARWIN_RPATH,..)
++$(FB_DAEMON): $(Remote_Server_Objects) $(Remote_Client_Objects) $(COMMON_LIB)
++ $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) $(LIB_GUI) $(call LINK_DARWIN_RPATH,..)
+
+ fb_lock_print: $(LOCKPRINT)
+
+@@ -633,7 +635,7 @@
+ IBASE_ExtraFiles = include/types_pub.h include/consts_pub.h dsql/sqlda_pub.h common/dsc_pub.h jrd/ibase.h jrd/inf_pub.h jrd/blr.h include/gen/iberror.h
+ SRC_IBASE_ExtraFiles = $(addprefix $(SRC_ROOT)/, $(IBASE_ExtraFiles))
+ MAKE_HEADER_Src = $(addprefix $(SRC_ROOT)/, misc/makeHeader.cpp)
+-MAKE_HEADER_Bin = ./makeHeader
++MAKE_HEADER_Bin = ./makeHeader$(EXEC_EXT)
+
+ $(INCLUDE_DEST)/ibase.h: $(SRC_IBASE_ExtraFiles)
+ $(STATICEXE_LINK) -o $(MAKE_HEADER_Bin) $(MAKE_HEADER_Src)
+diff -ur builds/posix/make.rules builds/posix/make.rules
+--- builds/posix/make.rules 2016-07-07 13:56:13.036235166 +0200
++++ builds/posix/make.rules 2016-07-07 14:31:16.116291485 +0200
+@@ -92,26 +92,23 @@
+
+ $(OBJ)/%.o: $(SRC_ROOT)/%.c
+ $(CC) $(WCFLAGS) -c $(firstword $<) -o $@
+- @sed $(INLINE_EDIT_SED) -e "1,2s/:/: \$$(wildcard/" -e "\$$s/\(.*\)/\\1)/" $(patsubst %.o,%.d,$@)
+
+ $(OBJ)/%.o: $(OBJ)/%.cpp
+ $(CXX) $(WCXXFLAGS) -c $(firstword $<) -o $@
+- @sed $(INLINE_EDIT_SED) -e "1,2s/:/: \$$(wildcard/" -e "\$$s/\(.*\)/\\1)/" $(patsubst %.o,%.d,$@)
+
+ $(OBJ)/%.o: $(SRC_ROOT)/%.cpp
+ $(CXX) $(WCXXFLAGS) -c $(firstword $<) -o $@
+- @sed $(INLINE_EDIT_SED) -e "1,2s/:/: \$$(wildcard/" -e "\$$s/\(.*\)/\\1)/" $(patsubst %.o,%.d,$@)
+
+ $(OBJ)/%.o: $(ROOT)/%.cpp
+ $(CC) $(WCFLAGS) -c $(firstword $<) -o $@
+- @sed $(INLINE_EDIT_SED) -e "1,2s/:/: \$$(wildcard/" -e "\$$s/\(.*\)/\\1)/" $(patsubst %.o,%.d,$@)
+
+ .SUFFIXES: .epp .e
+
+ # Rules for making resource files
+
+ $(GEN_ROOT)/%.res: $(SRC_ROOT)/%.rc
+- windres --output-format=coff --include-dir=$(<D) $< $@
++ mkdir -p $(@D)
++ rc.exe $(SOLARINC) /fo $@ $<
+
+ # Rule for making gbak files when cross-compiling
+
+--- src/common/utils.cpp 2016-07-15 11:31:26.746871100 +0200
++++ src/common/utils.cpp 2016-07-19 19:14:45.370689300 +0200
+@@ -880,15 +880,15 @@
+ FILETIME utime, stime, dummy;
+ if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy, &stime, &utime))
+ {
+- LARGE_INTEGER lint;
++ LARGE_INTEGER myLargeInt;
+
+- lint.HighPart = stime.dwHighDateTime;
+- lint.LowPart = stime.dwLowDateTime;
+- sysTime = lint.QuadPart / 10000;
+-
+- lint.HighPart = utime.dwHighDateTime;
+- lint.LowPart = utime.dwLowDateTime;
+- userTime = lint.QuadPart / 10000;
++ myLargeInt.HighPart = stime.dwHighDateTime;
++ myLargeInt.LowPart = stime.dwLowDateTime;
++ sysTime = myLargeInt.QuadPart / 10000;
++
++ myLargeInt.HighPart = utime.dwHighDateTime;
++ myLargeInt.LowPart = utime.dwLowDateTime;
++ userTime = myLargeInt.QuadPart / 10000;
+ }
+ else
+ {
+diff -ur builds/posix/prefix.mingw builds/posix/prefix.mingw
+--- builds/posix/prefix.mingw 2016-07-07 13:56:13.048235166 +0200
++++ builds/posix/prefix.mingw 2016-07-07 14:50:54.704323046 +0200
+@@ -20,8 +20,8 @@
+ #
+
+ # -Wno-unused-variable is used due to unused gpre generated variables
+-PROD_FLAGS=-O2 -DMINGW -Wall -Wshadow -Wundef -Wno-long-long -Wno-unused-variable -Wno-sign-compare -Wno-parentheses -Wno-switch -fmessage-length=0 -Dlint -DWIN32_LEAN_AND_MEAN -MMD -mthreads -Wno-non-virtual-dtor
+-DEV_FLAGS=-ggdb -DMINGW -Wall -Wshadow -Wundef -Wno-long-long -Wno-unused-variable -Wno-sign-compare -Wno-parentheses -Wno-switch -fmessage-length=0 -Dlint -DWIN32_LEAN_AND_MEAN -MMD -mthreads -Wno-non-virtual-dtor
++PROD_FLAGS=-O2 -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN
++DEV_FLAGS=-ggdb -DMINGW -Dlint -DWIN32_LEAN_AND_MEAN
+
+ PLATFORM_PATH=os/win32
+
+@@ -29,6 +29,7 @@
+ LIB_LINK=$(LD)
+
+ LIB_LINK_OPTIONS+=-Wl,--enable-stdcall-fixup
++LIB_PLATFORM_RPATH=
+
+ # Strip symbols from release versions to decrease size
+ ifeq ($(IsProdTypeBuild),Y)
+@@ -36,6 +37,9 @@
+ LIB_LINK_OPTIONS+=-Wl,-s
+ endif
+
++LIB_LINK_OPTIONS=
++LINK_OPTS=
++
+ # Generation of fbclient_ms.lib
+ LIB_LINK_IMPLIB:=-Wl,--out-implib,firebird/lib/fbclient_ms.lib
+ LIB_GUI:= -mwindows -lcomctl32 -lgdi32
+@@ -55,7 +59,9 @@
+ ClientLibrarySoName := $(ClientLibraryName)
+
+ # Looks like MinGW 3 does not support version scripts but support def-files
+-LINK_FIREBIRD_SYMBOLS = $(BLD_ROOT)/win32/defs/fbclient_s.def $(BLD_ROOT)/win32/defs/fbclient.def
++LINK_FIREBIRD_SYMBOLS = /def:$(BLD_ROOT)/win32/defs/fbclient_s.def /def:$(BLD_ROOT)/win32/defs/firebird.def
++LINK_PLUGIN_SYMBOLS = /def:$(BLD_ROOT)/win32/defs/plugin.def
++LINK_IBUTIL_SYMBOLS = /def:$(BLD_ROOT)/win32/defs/ib_util.def
+
+ # This is required for newly built executable to find newly built shared
+ # libraries because on Win32 there is no such thing as LD_LIBRARY_PATH
+--- builds/posix/make.shared.variables 2016-07-22 17:07:46.650672300 +0200
++++ builds/posix/make.shared.variables 2016-07-23 10:44:41.311454600 +0200
+@@ -62,6 +62,7 @@
+ $(SecDbCache)
+ Remote_Client:= $(call dirObjects,remote/client) $(call dirObjects,auth/SecureRemotePassword/client) \
+ $(call makeObjects,auth/SecurityDatabase,LegacyClient.cpp) \
++ $(call dirObjects,auth/trusted) \
+ $(call dirObjects,plugins/crypt/arc4)
+ Remote_Server_Objects:= $(Remote_Common) $(Remote_Server)
+ Remote_Client_Objects:= $(Remote_Common) $(Remote_Client)
+diff -ur configure configure
+--- configure 2016-07-07 13:55:54.976234682 +0200
++++ configure 2016-07-07 14:54:30.012328812 +0200
+@@ -3337,6 +3337,14 @@
+ SHRLIB_EXT=dll
+ ;;
+
++ *-*-cygwin*)
++ MAKEFILE_PREFIX=mingw
++ PLATFORM=win32
++ EDITLINE_FLG=N
++ RAW_DEVICES_FLG=N
++ SHRLIB_EXT=dll
++ ;;
++
+ *)
+ as_fn_error $? "unsupported platform ${build}" "$LINENO" 5
+ ;;
+@@ -8432,6 +8432,9 @@
+ mingw*)
+ opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+ ;;
++cygwin*)
++ opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
++ ;;
+ esac
+
+ # Try without a prefix underscore, then with it.
+diff -ur extern/btyacc/main.c extern/btyacc/main.c
+--- extern/btyacc/main.c 2016-07-07 13:55:55.448234695 +0200
++++ extern/btyacc/main.c 2016-07-07 14:56:03.560331317 +0200
+@@ -2,7 +2,7 @@
+ #include <signal.h>
+ #include <stdio.h>
+
+-#if defined(WIN32)
++#if defined(WIN32) || defined(_WIN32)
+ #include <io.h>
+ #else
+ #include <unistd.h>
+diff -ur extern/btyacc/Makefile extern/btyacc/Makefile
+--- extern/btyacc/Makefile 2016-07-07 13:55:55.448234695 +0200
++++ extern/btyacc/Makefile 2016-07-07 14:57:42.284333961 +0200
+@@ -30,7 +30,7 @@
+
+ PRINT = pr -f -l88
+
+-PROGRAM = btyacc
++PROGRAM = btyacc.exe
+
+ SRCS = closure.c error.c lalr.c lr0.c main.c mkpar.c output.c \
+ mstring.c reader.c readskel.c skeleton.c symtab.c verbose.c warshall.c
+@@ -58,7 +58,7 @@
+ index:; ctags -wx $(HDRS) $(SRCS)
+
+ install: $(PROGRAM)
+- cp $(PROGRAM).exe /bin
++ cp $(PROGRAM) /bin
+
+ oldinstall: $(PROGRAM)
+ @echo Installing $(PROGRAM) in $(DEST)
+--- extern/cloop/src/tests/test1/CppTest.cpp 2016-07-07 15:56:27.948015300 +0200
++++ extern/cloop/src/tests/test1/CppTest.cpp 2016-07-13 18:58:48.529822600 +0200
+@@ -24,6 +24,7 @@
+ #include <stdio.h>
+ #include <assert.h>
+
++#define WIN32
+ #ifdef WIN32
+ #include <windows.h>
+ #define DLL_EXPORT __declspec(dllexport)
+--- extern/cloop/src/tests/test1/CTest.c 2016-07-07 15:56:27.611791300 +0200
++++ extern/cloop/src/tests/test1/CTest.c 2016-07-13 17:04:22.805090300 +0200
+@@ -23,6 +23,7 @@
+ #include <stdlib.h>
+ #include <stdio.h>
+
++#define WIN32
+ #ifdef WIN32
+ #include <windows.h>
+ #define DLL_EXPORT __declspec(dllexport)
+--- extern/cloop/Makefile 2016-07-07 15:56:28.279136300 +0200
++++ extern/cloop/Makefile 2016-07-13 16:22:38.493479800 +0200
+@@ -11,8 +11,8 @@
+ SRC_DIR := src
+ BUILD_DIR := build
+ OUT_DIR := output
+-SHRLIB_EXT := .so
+-EXE_EXT :=
++SHRLIB_EXT := .dll
++EXE_EXT := .exe
+
+ OBJ_DIR := $(BUILD_DIR)/$(TARGET)
+ BIN_DIR := $(OUT_DIR)/$(TARGET)/bin
+@@ -27,7 +27,7 @@
+ OBJS_C := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS_C))
+ OBJS_CPP := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS_CPP))
+
+-C_FLAGS := -ggdb -fPIC -MMD -MP -W -Wall -Wno-unused-parameter
++C_FLAGS := -fPIC
+ CXX_FLAGS := $(C_FLAGS)
+ FPC_FLAGS := -Mdelphi
+
+@@ -53,7 +53,7 @@
+ .PHONY: all mkdirs clean
+
+ all: mkdirs \
+- $(BIN_DIR)/cloop \
++ $(BIN_DIR)/cloop$(EXE_EXT) \
+ $(BIN_DIR)/test1-c$(SHRLIB_EXT) \
+ $(BIN_DIR)/test1-c$(EXE_EXT) \
+ $(BIN_DIR)/test1-cpp$(SHRLIB_EXT) \
+@@ -63,6 +63,10 @@
+
+ mkdirs: $(OBJ_DIRS) $(BIN_DIR) $(LIB_DIR)
+
++# These files have the same basename, so various conflicting intermediate files break the build
++$(BIN_DIR)/test1-c$(EXE_EXT): | $(BIN_DIR)/test1-c$(SHRLIB_EXT)
++$(BIN_DIR)/test1-cpp$(EXE_EXT): | $(BIN_DIR)/test1-cpp$(SHRLIB_EXT)
++
+ $(OBJ_DIRS) $(BIN_DIR) $(LIB_DIR):
+ @mkdir -p $@
+
+@@ -74,7 +74,7 @@
+ -include $(addsuffix .d,$(basename $(OBJS_C)))
+ -include $(addsuffix .d,$(basename $(OBJS_CPP)))
+
+-$(BIN_DIR)/cloop: \
++$(BIN_DIR)/cloop$(EXE_EXT): \
+ $(OBJ_DIR)/cloop/Expr.o \
+ $(OBJ_DIR)/cloop/Generator.o \
+ $(OBJ_DIR)/cloop/Lexer.o \
+@@ -83,20 +83,20 @@
+
+ $(LD) $^ -o $@
+
+-$(SRC_DIR)/tests/test1/CalcCApi.h: $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl
+- $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl c-header $@ CALC_C_API_H CALC_I
++$(SRC_DIR)/tests/test1/CalcCApi.h: $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl
++ $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl c-header $@ CALC_C_API_H CALC_I
+
+-$(SRC_DIR)/tests/test1/CalcCApi.c: $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl $(SRC_DIR)/tests/test1/CalcCApi.h
+- $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl c-impl $@ CalcCApi.h CALC_I
++$(SRC_DIR)/tests/test1/CalcCApi.c: $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl $(SRC_DIR)/tests/test1/CalcCApi.h
++ $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl c-impl $@ CalcCApi.h CALC_I
+
+-$(SRC_DIR)/tests/test1/CalcCppApi.h: $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl
+- $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl c++ $@ CALC_CPP_API_H calc I
++$(SRC_DIR)/tests/test1/CalcCppApi.h: $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl
++ $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl c++ $@ CALC_CPP_API_H calc I
+
+-$(SRC_DIR)/tests/test1/CalcPascalApi.pas: $(BIN_DIR)/cloop \
++$(SRC_DIR)/tests/test1/CalcPascalApi.pas: $(BIN_DIR)/cloop$(EXE_EXT) \
+ $(SRC_DIR)/tests/test1/Interface.idl \
+ $(SRC_DIR)/tests/test1/CalcPascalApi.interface.pas \
+ $(SRC_DIR)/tests/test1/CalcPascalApi.implementation.pas
+- $(BIN_DIR)/cloop $(SRC_DIR)/tests/test1/Interface.idl pascal $@ CalcPascalApi \
++ $(BIN_DIR)/cloop$(EXE_EXT) $(SRC_DIR)/tests/test1/Interface.idl pascal $@ CalcPascalApi \
+ --uses "SysUtils" \
+ --interfaceFile $(SRC_DIR)/tests/test1/CalcPascalApi.interface.pas \
+ --implementationFile $(SRC_DIR)/tests/test1/CalcPascalApi.implementation.pas \
+@@ -108,23 +108,23 @@
+ $(OBJ_DIR)/tests/test1/CalcCApi.o \
+ $(OBJ_DIR)/tests/test1/CTest.o \
+
+- $(LD) $^ -shared -ldl -o $@
++ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-c$(EXE_EXT): \
+ $(OBJ_DIR)/tests/test1/CalcCApi.o \
+ $(OBJ_DIR)/tests/test1/CTest.o \
+
+- $(LD) $^ -ldl -o $@
++ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-cpp$(SHRLIB_EXT): \
+ $(OBJ_DIR)/tests/test1/CppTest.o \
+
+- $(LD) $^ -shared -ldl -o $@
++ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-cpp$(EXE_EXT): \
+ $(OBJ_DIR)/tests/test1/CppTest.o \
+
+- $(LD) $^ -ldl -o $@
++ $(LD) $^ -o $@
+
+ $(BIN_DIR)/test1-pascal$(SHRLIB_EXT): \
+ $(SRC_DIR)/tests/test1/PascalClasses.pas \
+diff -ur src/common/classes/fb_string.cpp src/common/classes/fb_string.cpp
+--- src/common/classes/fb_string.cpp 2016-07-07 13:55:56.064234711 +0200
++++ src/common/classes/fb_string.cpp 2016-07-07 14:59:01.516336083 +0200
+@@ -32,6 +32,12 @@
+ #include <ctype.h>
+ #include <stdarg.h>
+
++#ifdef WIN_NT
++#pragma comment(lib, "User32.lib")
++#pragma comment(lib, "advapi32")
++#pragma comment(lib, "shell32.lib")
++#endif
++
+ #ifdef HAVE_STRCASECMP
+ #define STRNCASECMP strncasecmp
+ #else
+diff -ur src/misc/makeHeader.cpp src/misc/makeHeader.cpp
+--- src/misc/makeHeader.cpp 2016-07-07 13:56:00.100234819 +0200
++++ src/misc/makeHeader.cpp 2016-07-07 15:00:14.780338045 +0200
+@@ -1,9 +1,9 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <errno.h>
+-//#ifdef HAVE_UNISTD_H
++#ifdef HAVE_UNISTD_H
+ #include <unistd.h>
+-//#endif
++#endif
+
+
+
+--- builds/posix/Makefile.in.plugins_examples.orig 2020-11-13 18:07:52.515550600 +0100
++++ builds/posix/Makefile.in.plugins_examples 2020-11-13 18:08:33.218626500 +0100
+@@ -28,7 +28,7 @@
+ # Adriano dos Santos Fernandes
+ #
+
+-ROOT=$(shell cd ..; pwd)
++ROOT=$(shell cygpath -m '$(shell cd ..; pwd)')
+
+ ifeq ($(IsDeveloper), Y)
+ DefaultTarget := Debug
+--- examples/dbcrypt/CryptApplication.cpp.orig 2020-11-13 20:57:11.222938900 +0100
++++ examples/dbcrypt/CryptApplication.cpp 2020-11-13 21:01:19.332316100 +0100
+@@ -27,6 +27,13 @@
+ #include "../interfaces/ifaceExamples.h"
+ #include <firebird/Message.h>
+
++#include "gen/autoconfig.h"
++
++#ifdef WIN_NT
++#include <windows.h>
++#include <winbase.h>
++#endif
++
+ using namespace Firebird;
+
+ class CryptKey : public ICryptKeyCallbackImpl<CryptKey, CheckStatusWrapper>
+@@ -238,8 +238,15 @@
+ av++;
+ }
+
++#ifdef WIN_NT
++ if (!getenv("ISC_USER"))
++ SetEnvironmentVariable("ISC_USER", "sysdba");
++ if (!getenv("ISC_PASSWORD"))
++ SetEnvironmentVariable("ISC_PASSWORD", "masterkey");
++#else
+ setenv("ISC_USER", "sysdba", 0);
+ setenv("ISC_PASSWORD", "masterkey", 0);
++#endif
+
+ App app;
+ try
diff --git a/external/firebird/firebird-macosx-sandbox.patch.1 b/external/firebird/firebird-macosx-sandbox.patch.1
new file mode 100644
index 000000000..3bf246c68
--- /dev/null
+++ b/external/firebird/firebird-macosx-sandbox.patch.1
@@ -0,0 +1,13 @@
+-*- Mode: Diff -*-
+
+--- firebird/src/common/isc_s_proto.h
++++ firebird/src/common/isc_s_proto.h
+@@ -37,6 +37,8 @@
+ // Firebird platform-specific synchronization data structures
+
+ #if defined(DARWIN)
++#define USE_POSIX_SEMAPHORE
++#define USE_SHARED_FUTEX
+ #define USE_FILELOCKS
+ #endif
+
diff --git a/external/firebird/firebird-macosx.patch.1 b/external/firebird/firebird-macosx.patch.1
new file mode 100644
index 000000000..676f2195a
--- /dev/null
+++ b/external/firebird/firebird-macosx.patch.1
@@ -0,0 +1,87 @@
+--- firebird.org/builds/posix/Makefile.in.examples
++++ firebird/builds/posix/Makefile.in.examples
+@@ -134,7 +134,7 @@
+ $(LN) $(ISQL) $(EXAMPLES_DEST)/isql$(EXEC_EXT)
+
+ $(EXAMPLES_DEST)/empbuild$(EXEC_EXT): $(EMPBLD_Objects) $(COMMON_LIB)
+- $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ -L$(LIB) $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS)
++ $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ -L$(LIB) $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) $(call LINK_DARWIN_RPATH,../$(if $(ENABLE_DEBUG),Debug,Release)/firebird)
+
+ $(EXAMPLES_DEST)/empbuild.c: $(EXAMPLES_DEST)/empbuild.fdb $(EXAMPLES_DEST)/empbuild.e
+
+--- firebird.org/builds/posix/prefix.darwin_x86_64 2016-08-01 20:02:48.000000000 +0200
++++ firebird/builds/posix/prefix.darwin_x86_64 2016-08-01 21:42:45.000000000 +0200
+@@ -27,9 +27,6 @@
+ # configure using --with-builtin-tommath
+ # or add the relevant -I, -L for an installed version of libtommath
+
+-DYLD_LIBRARY_PATH=$(HOME)/icu54/icu/source/lib
+-export DYLD_LIBRARY_PATH
+-
+ #DYLD_PRINT_ENV=1
+ #export DYLD_PRINT_ENV
+
+@@ -31,8 +31,8 @@
+ MACOSX_DEPLOYMENT_TARGET=10.9
+ export MACOSX_DEPLOYMENT_TARGET
+
+-PROD_FLAGS=-DDARWIN -pipe -O2 -MMD -fPIC -fno-common -mmacosx-version-min=10.9
+-DEV_FLAGS=-ggdb -DDARWIN -pipe -MMD -fPIC -fno-omit-frame-pointer -fno-common -Wall -fno-optimize-sibling-calls -mmacosx-version-min=10.9 -Wno-non-virtual-dtor
++PROD_FLAGS=-DDARWIN -pipe -O2 -MMD -fPIC -fno-common
++DEV_FLAGS=-ggdb -DDARWIN -pipe -MMD -fPIC -fno-omit-frame-pointer -fno-common -Wall -fno-optimize-sibling-calls -Wno-non-virtual-dtor
+ CXXFLAGS:=$(CXXFLAGS) -fvisibility-inlines-hidden -fvisibility=hidden -stdlib=libc++ -msse4
+
+ EXE_LINK_OPTIONS:=
+--- firebird.org/src/common/unicode_util.cpp 2016-07-07 13:55:55.992234709 +0200
++++ firebird/src/common/unicode_util.cpp 2016-08-10 11:25:46.422331020 +0200
+@@ -63,8 +63,8 @@
+ const char* const ucTemplate = "icuuc%s.dll";
+ #endif
+ #elif defined(DARWIN)
+-const char* const inTemplate = "lib/libicui18n.%s.dylib";
+-const char* const ucTemplate = "lib/libicuuc.%s.dylib";
++const char* const inTemplate = "libicui18n.dylib.%s";
++const char* const ucTemplate = "libicuuc.dylib.%s";
+ #elif defined(HPUX)
+ const char* const inTemplate = "libicui18n.sl.%s";
+ const char* const ucTemplate = "libicuuc.sl.%s";
+@@ -354,6 +354,16 @@
+ {
+ s.printf(*p, majorVersion, minorVersion);
+ filename.printf(templateName, s.c_str());
++ const char * envpath = getenv("LIBREOFFICE_FIREBIRD_LIB");
++ if(envpath == nullptr)
++ {
++ envpath = getenv("LIBREOFFICE_ICU_LIB");
++ }
++ if(envpath != nullptr)
++ {
++ s = filename.c_str();
++ PathUtils::concatPath(filename, envpath, s.c_str());
++ }
+
+ ModuleLoader::Module* module = ModuleLoader::fixAndLoadModule(NULL, filename);
+ if (module)
+--- firebird.org/src/common/utils.cpp 2016-08-16 10:11:10.000000000 +0200
++++ firebird/src/common/utils.cpp 2016-08-16 11:27:09.000000000 +0200
+@@ -1027,10 +1027,18 @@
+ return s;
+ }
+
+- // Set relative path to Engine12 dynamic library
++ // Set path to Engine12 dynamic library.
+ if(prefType == Firebird::IConfigManager::DIR_PLUGINS)
+ {
+- s = name;
++ const char * const envpath = getenv("LIBREOFFICE_FIREBIRD_LIB");
++ if(envpath != nullptr)
++ {
++ PathUtils::concatPath(s, envpath, name);
++ }
++ else
++ {
++ s = name;
++ }
+ return s;
+ }
+ }
diff --git a/external/firebird/firebird-rpath.patch.0 b/external/firebird/firebird-rpath.patch.0
new file mode 100644
index 000000000..bc9fd3a3f
--- /dev/null
+++ b/external/firebird/firebird-rpath.patch.0
@@ -0,0 +1,11 @@
+--- builds/posix/make.defaults
++++ builds/posix/make.defaults
+@@ -292,7 +292,7 @@
+ LIB_PLATFORM_RPATH = -Wl,-rpath,$(1)
+ ifeq (@USE_RPATH@,1)
+ ifeq ($(strip @BINRELOC_CFLAGS@),)
+- LIB_LINK_RPATH = $(call LIB_PLATFORM_RPATH,$(if $(subst intl,,$(1)),@FB_LIBDIR@,@FB_INTLDIR@))
++ LIB_LINK_RPATH = $(call LIB_PLATFORM_RPATH,'$$ORIGIN')
+ else
+ LIB_LINK_RPATH = $(call LIB_PLATFORM_RPATH,'$$ORIGIN/../$(1)')
+ endif
diff --git a/external/firebird/firebird-tdf125284.patch.1 b/external/firebird/firebird-tdf125284.patch.1
new file mode 100644
index 000000000..a1cb2043e
--- /dev/null
+++ b/external/firebird/firebird-tdf125284.patch.1
@@ -0,0 +1,27 @@
+--- firebird/src/common/config/config_file.cpp 2019-08-23 16:42:26.721439468 +0100
++++ firebird/src/common/config/config_file.cpp 2019-08-23 16:43:07.506579222 +0100
+@@ -521,16 +521,14 @@
+ unsigned code;
+ const char* name;
+ } dirs[] = {
+-#define NMDIR(a) {Firebird::IConfigManager::a, "FB_"#a},
+- NMDIR(DIR_CONF)
+- NMDIR(DIR_SECDB)
+- NMDIR(DIR_PLUGINS)
+- NMDIR(DIR_UDF)
+- NMDIR(DIR_SAMPLE)
+- NMDIR(DIR_SAMPLEDB)
+- NMDIR(DIR_INTL)
+- NMDIR(DIR_MSG)
+-#undef NMDIR
++ {Firebird::IConfigManager::DIR_CONF, "FB_dir_conf"},
++ {Firebird::IConfigManager::DIR_SECDB, "FB_dir_secdb"},
++ {Firebird::IConfigManager::DIR_PLUGINS, "FB_dir_plugins"},
++ {Firebird::IConfigManager::DIR_UDF, "FB_dir_udf"},
++ {Firebird::IConfigManager::DIR_SAMPLE, "FB_dir_sample"},
++ {Firebird::IConfigManager::DIR_SAMPLEDB, "FB_dir_sampledb"},
++ {Firebird::IConfigManager::DIR_INTL, "FB_dir_intl"},
++ {Firebird::IConfigManager::DIR_MSG, "FB_dir_msg"},
+ {Firebird::IConfigManager::DIR_COUNT, NULL}
+ };
+
diff --git a/external/firebird/firebird-vs2017.patch.1 b/external/firebird/firebird-vs2017.patch.1
new file mode 100644
index 000000000..3c7db1874
--- /dev/null
+++ b/external/firebird/firebird-vs2017.patch.1
@@ -0,0 +1,12 @@
+diff -ru firebird.orig/src/common/os/win32/mod_loader.cpp firebird/src/common/os/win32/mod_loader.cpp
+--- firebird.orig/src/common/os/win32/mod_loader.cpp 2017-02-15 22:11:48.939042400 +0100
++++ firebird/src/common/os/win32/mod_loader.cpp 2017-02-15 22:12:30.062262700 +0100
+@@ -101,7 +101,7 @@
+ "msvcr110.dll",
+ #elif _MSC_VER == 1800
+ "msvcr120.dll",
+-#elif _MSC_VER >= 1900 && _MSC_VER < 1920
++#elif _MSC_VER >= 1900 && _MSC_VER < 2000
+ "vcruntime140.dll",
+ #else
+ #error Specify CRT DLL name here !
diff --git a/external/firebird/firebird.disable-ib-util-not-found.patch.1 b/external/firebird/firebird.disable-ib-util-not-found.patch.1
new file mode 100644
index 000000000..86dedd0dd
--- /dev/null
+++ b/external/firebird/firebird.disable-ib-util-not-found.patch.1
@@ -0,0 +1,17 @@
+--- firebird.org/src/jrd/fun.epp 2015-01-23 22:11:26.751475044 +0100
++++ firebird/src/jrd/fun.epp 2015-01-23 22:16:42.507322568 +0100
+@@ -164,10 +164,14 @@
+ if (tryLibrary(LIBNAME, message[3]))
+ return;
+
++ /* fdo#72543: quote from https://bugs.freedesktop.org/show_bug.cgi?id=72543#c8
++ "we don't need UDF support for embedded firebird,
++ hence the lack of ib_util isn't an issue and can safely be ignored"
+ // all failed - log error
+ gds__log("ib_util init failed, UDFs can't be used - looks like firebird misconfigured\n"
+ "\t%s\n\t%s\n\t%s\n\t%s", message[0].c_str(), message[1].c_str(),
+ message[2].c_str(), message[3].c_str());
++ */
+ }
+
+ void* IbUtil::alloc(long size)
diff --git a/external/firebird/macos-arm64.patch.0 b/external/firebird/macos-arm64.patch.0
new file mode 100644
index 000000000..ab2596dbd
--- /dev/null
+++ b/external/firebird/macos-arm64.patch.0
@@ -0,0 +1,109 @@
+-*- Mode: diff -*-
+--- configure
++++ configure
+@@ -2901,6 +2901,22 @@
+ RAW_DEVICES_FLG=N
+ ;;
+
++ aarch64-*-darwin*)
++ MAKEFILE_PREFIX=darwin_arm64
++ MAKEFILE_POSTFIX=darwin
++ PLATFORM=DARWIN
++ INSTALL_PREFIX=darwin
++
++$as_echo "#define DARWIN 1" >>confdefs.h
++
++ LIBS="$LIBS -framework CoreFoundation"
++ EDITLINE_FLG=Y
++ SHRLIB_EXT=dylib
++ CPU_TYPE=arm64
++ EXPORT_SYMBOLS_STYLE=darwin
++ RAW_DEVICES_FLG=N
++ ;;
++
+ i*86-*-darwin*)
+ MAKEFILE_PREFIX=darwin_i386
+ MAKEFILE_POSTFIX=darwin
+--- src/common/common.h
++++ src/common/common.h
+@@ -234,6 +234,12 @@
+ #define DARWINPPC64
+ #define FB_CPU CpuPowerPc64
+ #endif
++#ifdef __aarch64__
++// This means x86_64, but does it matter? There is no arch_arm64, arch_aarch64, arch_darwin_arm64,
++// or arch_darwin_aarch64 in the P_ARCH enum in src/remote/protocol.h.
++#define DARWIN64
++#define FB_CPU CpuArm64
++#endif
+ #define IEEE
+ #define QUADCONST(n) (n##LL)
+ #define QUADFORMAT "q"
+--- src/jrd/license.h
++++ src/jrd/license.h
+@@ -128,6 +128,9 @@
+ #if defined(ARM)
+ #define FB_PLATFORM "UA"
+ #endif
++#if defined(__aarch64__)
++#define FB_PLATFORM "UB"
++#endif
+ #endif
+
+ #ifdef DEV_BUILD
+--- /dev/null
++++ builds/posix/prefix.darwin_arm64
+@@ -0,0 +0,42 @@
++# The contents of this file are subject to the Interbase Public
++# License Version 1.0 (the "License"); you may not use this file
++# except in compliance with the License. You may obtain a copy
++# of the License at http://www.Inprise.com/IPL.html
++#
++# Software distributed under the License is distributed on an
++# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
++# or implied. See the License for the specific language governing
++# rights and limitations under the License.
++#
++# The Original Code was created by Inprise Corporation
++# and its predecessors. Portions created by Inprise Corporation are
++#
++# Copyright (C) 2000 Inprise Corporation
++# All Rights Reserved.
++# Contributor(s): ______________________________________.
++# Start of file prefix.darwin: $(VERSION) @PLATFORM@
++# 2 Oct 2002, Nickolay Samofatov - Major Cleanup
++#
++
++
++#DYLD_PRINT_ENV=1
++#export DYLD_PRINT_ENV
++
++#DYLD_PRINT_LIBRARIES=1
++#export DYLD_PRINT_LIBRARIES
++
++MACOSX_DEPLOYMENT_TARGET=11.0
++export MACOSX_DEPLOYMENT_TARGET
++
++PROD_FLAGS=-DDARWIN -pipe -O2 -MMD -fPIC -fno-common
++DEV_FLAGS=-ggdb -DDARWIN -pipe -MMD -fPIC -fno-omit-frame-pointer -fno-common -Wall -fno-optimize-sibling-calls -Wno-non-virtual-dtor
++CXXFLAGS:=$(CXXFLAGS) -fvisibility-inlines-hidden -fvisibility=hidden
++
++EXE_LINK_OPTIONS:=
++UNDEF_PLATFORM=
++
++LINK_LIBS+=-liconv
++#MATHLIB=$(ROOT)/extern/libtommath/.libs/libtommath.a
++SO_LINK_LIBS+=-liconv
++
++include $(ROOT)/gen/darwin.defaults
+--- src/isql/InputDevices.cpp
++++ src/isql/InputDevices.cpp
+@@ -23,7 +23,7 @@
+
+ #include "firebird.h"
+ #if defined(DARWIN) && !defined(IOS)
+-#if defined(i386) || defined(__x86_64__)
++#if defined(i386) || defined(__x86_64__) || defined(__arm64__)
+ #include <architecture/i386/io.h>
+ #else
+ #include <io.h>
diff --git a/external/firebird/macosx-elcapitan-dyld.patch b/external/firebird/macosx-elcapitan-dyld.patch
new file mode 100644
index 000000000..134cdd974
--- /dev/null
+++ b/external/firebird/macosx-elcapitan-dyld.patch
@@ -0,0 +1,58 @@
+--- examples/empbuild/empbuild.e
++++ examples/empbuild/empbuild.e
+@@ -64,7 +64,7 @@
+ * Functional description
+ *
+ **************************************/
+-TEXT cmd [140];
++TEXT cmd [8000];
+
+ if (argc > 1)
+ strcpy (Db_name, argv[1]);
+@@ -94,7 +94,9 @@
+ }
+
+ printf ("Turning forced writes off\n");
++char const * lp = getenv("DYLD_LIBRARY_PATH");
++if (!lp) lp = "";
+-sprintf (cmd, "gfix -write async %s", Db_name);
++sprintf (cmd, "DYLD_LIBRARY_PATH=%s gfix -write async %s", lp, Db_name);
+ if (system (cmd))
+ {
+ printf ("Couldn't turn forced writes off\n");
+@@ -104,7 +106,7 @@
+ }
+
+ printf ("Creating tables\n");
+-sprintf (cmd, "isql %s -q -i empddl.sql", Db_name);
++sprintf (cmd, "DYLD_LIBRARY_PATH=%s isql %s -q -i empddl.sql", lp, Db_name);
+ if (system (cmd))
+ {
+ printf ("Couldn't create tables \n");
+@@ -120,7 +122,7 @@
+ }
+
+ printf ("Turning off indices and triggers \n");
+-sprintf (cmd, "isql %s -i indexoff.sql", Db_name);
++sprintf (cmd, "DYLD_LIBRARY_PATH=%s isql %s -i indexoff.sql", lp, Db_name);
+ if (system (cmd))
+ {
+ printf ("Couldn't turn off indices and triggers \n");
+@@ -128,7 +130,7 @@
+ }
+
+ printf ("Loading column data\n");
+-sprintf (cmd, "isql %s -i empdml.sql", Db_name);
++sprintf (cmd, "DYLD_LIBRARY_PATH=%s isql %s -i empdml.sql", lp, Db_name);
+ if (system (cmd))
+ {
+ printf ("Couldn't load column data \n");
+@@ -136,7 +138,7 @@
+ }
+
+ printf ("Turning on indices and triggers \n");
+-sprintf (cmd, "isql %s -i indexon.sql", Db_name);
++sprintf (cmd, "DYLD_LIBRARY_PATH=%s isql %s -i indexon.sql", lp, Db_name);
+ if (system (cmd))
+ {
+ printf ("Couldn't turn on indices and triggers \n");
diff --git a/external/firebird/msvc.patch b/external/firebird/msvc.patch
new file mode 100644
index 000000000..3f403b496
--- /dev/null
+++ b/external/firebird/msvc.patch
@@ -0,0 +1,11 @@
+--- src/auth/trusted/AuthSspi.cpp
++++ src/auth/trusted/AuthSspi.cpp
+@@ -109,7 +109,7 @@
+ groupNames(*getDefaultMemoryPool()), sessionKey(*getDefaultMemoryPool())
+ {
+ TimeStamp timeOut;
+- hasCredentials = initEntries() && (fAcquireCredentialsHandle(0, "NTLM",
++ hasCredentials = initEntries() && (fAcquireCredentialsHandle(0, const_cast<char *>("NTLM"),
+ SECPKG_CRED_BOTH, 0, 0, 0, 0,
+ &secHndl, &timeOut) == SEC_E_OK);
+ }
diff --git a/external/firebird/sanitizer.patch b/external/firebird/sanitizer.patch
new file mode 100644
index 000000000..3707b5bf5
--- /dev/null
+++ b/external/firebird/sanitizer.patch
@@ -0,0 +1,63 @@
+--- builds/posix/fbintl.vers
++++ builds/posix/fbintl.vers
+@@ -29,3 +29,4 @@
+ LD_lookup_texttype
+ LD_setup_attributes
+ LD_version
++_ZTI*
+--- builds/posix/fbplugin.vers
++++ builds/posix/fbplugin.vers
+@@ -26,3 +26,4 @@
+ #
+
+ firebird_plugin
++_ZTI*
+--- builds/posix/firebird.vers
++++ builds/posix/firebird.vers
+@@ -367,3 +367,4 @@
+
+ KEYWORD_stringIsAToken
+ KEYWORD_getTokens
++_ZTI*
+--- builds/posix/make.defaults
++++ builds/posix/make.defaults
+@@ -252,7 +252,7 @@
+ # LINKER OPTIONS
+ #
+
+-UNDEF_PLATFORM = -Wl,--no-undefined
++UNDEF_PLATFORM =
+ ifeq ($(TARGET),Debug)
+ UNDEF_FLAGS = $(UNDEF_PLATFORM)
+ endif
+@@ -291,7 +291,7 @@
+ LIB_LINK_MAPFILE= -Wl,--version-script,$(1)
+ FIREBIRD_LIBRARY_LINK= -L$(LIB) -lfbclient $(MATHLIB)
+
+-EXE_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS) $(LINK_EMPTY_SYMBOLS)
++EXE_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS)
+ LIB_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) -shared
+
+ FB_DAEMON = $(BIN)/firebird$(EXEC_EXT)
+--- src/common/classes/alloc.cpp
++++ src/common/classes/alloc.cpp
+@@ -2535,7 +2535,7 @@
+ const char* myStack = &probeVar;
+ const char* thisLocation = (const char*) this;
+ ptrdiff_t distance = thisLocation - myStack;
+- fb_assert(absVal(distance) < 128 * 1024);
++ //fb_assert(absVal(distance) < 128 * 1024);
+ }
+ #endif
+
+--- src/common/os/posix/mod_loader.cpp
++++ src/common/os/posix/mod_loader.cpp
+@@ -92,7 +92,7 @@
+
+ ModuleLoader::Module* ModuleLoader::loadModule(ISC_STATUS* status, const Firebird::PathName& modPath)
+ {
+- void* module = dlopen(modPath.nullStr(), FB_RTLD_MODE);
++ void* module = dlopen(modPath.nullStr(), FB_RTLD_MODE | RTLD_GLOBAL);
+ if (module == NULL)
+ {
+ if (status)
diff --git a/external/firebird/ubsan.patch b/external/firebird/ubsan.patch
new file mode 100644
index 000000000..fa296108d
--- /dev/null
+++ b/external/firebird/ubsan.patch
@@ -0,0 +1,307 @@
+--- configure
++++ configure
+@@ -21506,7 +21468,7 @@
+ char a;
+ union { long long x; sem_t y; } b;
+ };
+- exit((int)&((struct s*)0)->b);
++ exit((int)&((struct s*)1024)->b - 1024);
+ }
+ _ACEOF
+ if ac_fn_c_try_run "$LINENO"; then :
+@@ -21541,7 +21503,7 @@
+ char a;
+ double b;
+ };
+- exit((int)&((struct s*)0)->b);
++ exit((int)&((struct s*)1024)->b - 1024);
+ }
+ _ACEOF
+ if ac_fn_c_try_run "$LINENO"; then :
+--- src/common/classes/array.h
++++ src/common/classes/array.h
+@@ -149,7 +149,7 @@
+ void copyFrom(const Array<T, Storage>& source)
+ {
+ ensureCapacity(source.count, false);
+- memcpy(data, source.data, sizeof(T) * source.count);
++ if (source.count != 0) memcpy(data, source.data, sizeof(T) * source.count);
+ count = source.count;
+ }
+
+@@ -227,7 +227,7 @@
+ fb_assert(count <= FB_MAX_SIZEOF - itemsCount);
+ ensureCapacity(count + itemsCount);
+ memmove(data + index + itemsCount, data + index, sizeof(T) * (count - index));
+- memcpy(data + index, items, sizeof(T) * itemsCount);
++ if (itemsCount != 0) memcpy(data + index, items, sizeof(T) * itemsCount);
+ count += itemsCount;
+ }
+
+@@ -242,7 +242,7 @@
+ {
+ fb_assert(count <= FB_MAX_SIZEOF - itemsCount);
+ ensureCapacity(count + itemsCount);
+- memcpy(data + count, items, sizeof(T) * itemsCount);
++ if (itemsCount != 0) memcpy(data + count, items, sizeof(T) * itemsCount);
+ count += itemsCount;
+ }
+
+@@ -294,7 +294,7 @@
+ {
+ fb_assert(newCount >= count);
+ ensureCapacity(newCount);
+- memset(data + count, 0, sizeof(T) * (newCount - count));
++ if (newCount != count) memset(data + count, 0, sizeof(T) * (newCount - count));
+ count = newCount;
+ }
+
+@@ -328,7 +328,7 @@
+ {
+ fb_assert(count <= FB_MAX_SIZEOF - L.count);
+ ensureCapacity(count + L.count);
+- memcpy(data + count, L.data, sizeof(T) * L.count);
++ if (L.count != 0) memcpy(data + count, L.data, sizeof(T) * L.count);
+ count += L.count;
+ }
+
+@@ -462,7 +462,7 @@
+
+ T* newdata = static_cast<T*>
+ (this->getPool().allocate(sizeof(T) * newcapacity ALLOC_ARGS));
+- if (preserve)
++ if (preserve && count != 0)
+ memcpy(newdata, data, sizeof(T) * count);
+ freeData();
+ data = newdata;
+--- src/common/classes/fb_string.h
++++ src/common/classes/fb_string.h
+@@ -674,7 +674,8 @@
+ }
+ StringType& assign(const void* s, size_type n)
+ {
+- memcpy(baseAssign(n), s, n);
++ auto const p = baseAssign(n);
++ if (n != 0) memcpy(p, s, n);
+ return *this;
+ }
+ StringType& assign(const_pointer s)
+--- src/common/common.h
++++ src/common/common.h
+@@ -1002,6 +1002,5 @@
+ }
+
+ #undef UCHAR_TYPE
+-#define UCHAR_TYPE uint16_t
+
+ #endif /* COMMON_COMMON_H */
+--- src/common/unicode_util.cpp
++++ src/common/unicode_util.cpp
+@@ -187,7 +187,7 @@
+ Mutex ciAiTransCacheMutex;
+ Array<UTransliterator*> ciAiTransCache;
+
+- void (U_EXPORT2 *uVersionToString)(UVersionInfo versionArray, char* versionString);
++ void (U_EXPORT2 *uVersionToString)(UVersionInfo const versionArray, char* versionString);
+
+ int32_t (U_EXPORT2 *ulocCountAvailable)();
+ const char* (U_EXPORT2 *ulocGetAvailable)(int32_t n);
+--- src/dsql/StmtNodes.cpp
++++ src/dsql/StmtNodes.cpp
+@@ -6643,7 +6643,7 @@
+
+ void StoreNode::genBlr(DsqlCompilerScratch* dsqlScratch)
+ {
+- const dsql_msg* message = dsqlGenDmlHeader(dsqlScratch, dsqlRse->as<RseNode>());
++ const dsql_msg* message = dsqlGenDmlHeader(dsqlScratch, dsqlRse == nullptr ? nullptr : dsqlRse->as<RseNode>());
+
+ dsqlScratch->appendUChar(statement2 ? blr_store2 : blr_store);
+ GEN_expr(dsqlScratch, dsqlRelation);
+--- src/gpre/hsh.cpp
++++ src/gpre/hsh.cpp
+@@ -232,7 +232,7 @@
+ {
+ SCHAR c;
+
+- SLONG value = 0;
++ ULONG value = 0;
+
+ while (c = *string++)
+ value = (value << 1) + UPPER(c);
+--- src/jrd/GlobalRWLock.cpp
++++ src/jrd/GlobalRWLock.cpp
+@@ -78,7 +78,7 @@
+
+ cachedLock = FB_NEW_RPT(getPool(), lockLen)
+ Lock(tdbb, lockLen, lckType, this, lockCaching ? blocking_ast_cached_lock : NULL);
+- memcpy(cachedLock->getKeyString(), lockStr, lockLen);
++ if (lockLen != 0) memcpy(cachedLock->getKeyString(), lockStr, lockLen);
+ }
+
+ GlobalRWLock::~GlobalRWLock()
+--- src/jrd/Optimizer.cpp
++++ src/jrd/Optimizer.cpp
+@@ -368,7 +368,7 @@
+
+ // Allocate needed indexScratches
+
+- index_desc* idx = csb_tail->csb_idx->items;
++ index_desc* idx = csb_tail->csb_idx == nullptr ? nullptr : csb_tail->csb_idx->items;
+ for (int i = 0; i < csb_tail->csb_indices; ++i, ++idx)
+ indexScratches.add(IndexScratch(p, tdbb, idx, csb_tail));
+ }
+--- src/jrd/blb.cpp
++++ src/jrd/blb.cpp
+@@ -1786,7 +1786,7 @@
+ arg.slice_base = array->arr_data;
+
+ SLONG variables[64];
+- memcpy(variables, param, MIN(sizeof(variables), param_length));
++ if (param_length != 0) memcpy(variables, param, MIN(sizeof(variables), param_length));
+
+ if (SDL_walk(tdbb->tdbb_status_vector, sdl, array->arr_data, &array_desc->arr_desc,
+ variables, slice_callback, &arg))
+--- src/jrd/btn.cpp
++++ src/jrd/btn.cpp
+@@ -387,7 +387,7 @@
+
+ put_short(pagePointer, offset);
+ pagePointer += sizeof(USHORT);
+- memmove(pagePointer, data, length);
++ if (length != 0) memmove(pagePointer, data, length);
+ pagePointer += length;
+ return pagePointer;
+ }
+@@ -622,7 +622,7 @@
+ }
+
+ // Store data
+- if (withData) {
++ if (withData && length != 0) {
+ memcpy(pagePointer, data, length);
+ }
+ pagePointer += length;
+--- src/jrd/btr.cpp
++++ src/jrd/btr.cpp
+@@ -5206,7 +5206,7 @@
+ // Push node on end in list
+ jumpNodes->add(jumpNode);
+ // Store new data in jumpKey, so a new jump node can calculate prefix
+- memcpy(jumpData + jumpNode.prefix, jumpNode.data, jumpNode.length);
++ if (jumpNode.length != 0) memcpy(jumpData + jumpNode.prefix, jumpNode.data, jumpNode.length);
+ jumpLength = jumpNode.length + jumpNode.prefix;
+
+ // Check if this could be our split point (if we need to split)
+@@ -5391,7 +5391,7 @@
+ // First, store needed data for beforeInsertNode into tempData.
+ HalfStaticArray<UCHAR, MAX_KEY> tempBuf;
+ UCHAR* tempData = tempBuf.getBuffer(newLength);
+- memcpy(tempData, beforeInsertNode.data + newPrefix - beforeInsertNode.prefix, newLength);
++ if (newLength != 0) memcpy(tempData, beforeInsertNode.data + newPrefix - beforeInsertNode.prefix, newLength);
+
+ beforeInsertNode.prefix = newPrefix;
+ beforeInsertNode.length = newLength;
+@@ -5611,7 +5611,7 @@
+ for (size_t i = 0; i < jumpNodes->getCount(); i++, index++)
+ {
+ UCHAR* q = new_key->key_data + walkJumpNode[i].prefix;
+- memcpy(q, walkJumpNode[i].data, walkJumpNode[i].length);
++ if (walkJumpNode[i].length != 0) memcpy(q, walkJumpNode[i].data, walkJumpNode[i].length);
+ if (index == splitJumpNodeIndex)
+ {
+ jn = &walkJumpNode[i];
+@@ -5636,7 +5636,7 @@
+ const USHORT length = walkJumpNode[i].prefix + walkJumpNode[i].length;
+ UCHAR* newData = FB_NEW_POOL(*tdbb->getDefaultPool()) UCHAR[length];
+ memcpy(newData, new_key->key_data, walkJumpNode[i].prefix);
+- memcpy(newData + walkJumpNode[i].prefix, walkJumpNode[i].data,
++ if (walkJumpNode[i].length != 0) memcpy(newData + walkJumpNode[i].prefix, walkJumpNode[i].data,
+ walkJumpNode[i].length);
+ delete[] walkJumpNode[i].data;
+ walkJumpNode[i].prefix = 0;
+--- src/jrd/evl.cpp
++++ src/jrd/evl.cpp
+@@ -415,7 +415,7 @@
+ case dtype_real:
+ case dtype_sql_time:
+ case dtype_sql_date:
+- value->vlu_misc.vlu_long = *((SLONG*) from.dsc_address);
++ memcpy(&value->vlu_misc.vlu_long, from.dsc_address, sizeof (SLONG));
+ return;
+
+ case dtype_int64:
+--- src/jrd/lck.cpp
++++ src/jrd/lck.cpp
+@@ -488,7 +488,7 @@
+ break;
+ }
+
+- dbb->dbb_lock_mgr->shutdownOwner(tdbb, owner_handle_ptr);
++ LockManager::shutdownOwner(dbb->dbb_lock_mgr, tdbb, owner_handle_ptr);
+ }
+
+
+--- src/lock/lock.cpp
++++ src/lock/lock.cpp
+@@ -441,7 +441,7 @@
+ }
+
+
+-void LockManager::shutdownOwner(thread_db* tdbb, SRQ_PTR* owner_handle)
++void LockManager::shutdownOwner(LockManager* This, thread_db* tdbb, SRQ_PTR* owner_handle)
+ {
+ /**************************************
+ *
+@@ -460,8 +460,9 @@
+ if (!owner_offset)
+ return;
+
+- LockTableGuard guard(this, FB_FUNCTION, owner_offset);
++ LockTableGuard guard(This, FB_FUNCTION, owner_offset);
+
++#define SRQ_BASE ((UCHAR*) This->m_sharedMemory->getHeader())
+ own* owner = (own*) SRQ_ABS_PTR(owner_offset);
+ if (!owner->own_count)
+ return;
+@@ -472,7 +473,7 @@
+ while (owner->own_ast_count)
+ {
+ { // checkout scope
+- LockTableCheckout checkout(this, FB_FUNCTION);
++ LockTableCheckout checkout(This, FB_FUNCTION);
+ EngineCheckout cout(tdbb, FB_FUNCTION, true);
+ Thread::sleep(10);
+ }
+@@ -484,8 +485,9 @@
+ // released before destroying the lock owner. This is not strictly required,
+ // but it enforces the proper object lifetime discipline through the codebase.
+ fb_assert(SRQ_EMPTY(owner->own_requests));
++#define SRQ_BASE ((UCHAR*) m_sharedMemory->getHeader())
+
+- purge_owner(owner_offset, owner);
++ This->purge_owner(owner_offset, owner);
+
+ *owner_handle = 0;
+ }
+--- src/lock/lock_proto.h
++++ src/lock/lock_proto.h
+@@ -402,7 +402,7 @@
+ static void destroy(LockManager*);
+
+ bool initializeOwner(Firebird::CheckStatusWrapper*, LOCK_OWNER_T, UCHAR, SRQ_PTR*);
+- void shutdownOwner(thread_db*, SRQ_PTR*);
++ static void shutdownOwner(LockManager* This, thread_db*, SRQ_PTR*);
+
+ SRQ_PTR enqueue(thread_db*, Firebird::CheckStatusWrapper*, SRQ_PTR, const USHORT,
+ const UCHAR*, const USHORT, UCHAR, lock_ast_t, void*, SINT64, SSHORT, SRQ_PTR);
+--- src/yvalve/gds.cpp
++++ src/yvalve/gds.cpp
+@@ -2561,7 +2561,7 @@
+ value += ((SLONG) *ptr++) << shift;
+ shift += 8;
+ }
+- value += ((SLONG)(SCHAR) *ptr) << shift;
++ value += ((ULONG)(SCHAR) *ptr) << shift;
+
+ return value;
+ }
diff --git a/external/firebird/wnt-dbgutil.patch b/external/firebird/wnt-dbgutil.patch
new file mode 100644
index 000000000..94fbd1dff
--- /dev/null
+++ b/external/firebird/wnt-dbgutil.patch
@@ -0,0 +1,63 @@
+--- configure
++++ configure
+@@ -18430,44 +18430,6 @@
+ as_fn_error $? "ICU support not found - please install development ICU package" "$LINENO" 5
+ fi
+
+-
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -licuuc" >&5
+-$as_echo_n "checking for main in -licuuc... " >&6; }
+-if ${ac_cv_lib_icuuc_main+:} false; then :
+- $as_echo_n "(cached) " >&6
+-else
+- ac_check_lib_save_LIBS=$LIBS
+-LIBS="-licuuc $LIBS"
+-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+-/* end confdefs.h. */
+-
+-
+-int
+-main ()
+-{
+-return main ();
+- ;
+- return 0;
+-}
+-_ACEOF
+-if ac_fn_c_try_link "$LINENO"; then :
+- ac_cv_lib_icuuc_main=yes
+-else
+- ac_cv_lib_icuuc_main=no
+-fi
+-rm -f core conftest.err conftest.$ac_objext \
+- conftest$ac_exeext conftest.$ac_ext
+-LIBS=$ac_check_lib_save_LIBS
+-fi
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_icuuc_main" >&5
+-$as_echo "$ac_cv_lib_icuuc_main" >&6; }
+-if test "x$ac_cv_lib_icuuc_main" = xyes; then :
+- ICU_OK=yes
+-else
+- as_fn_error $? "ICU support not found - please install development ICU package" "$LINENO" 5
+-fi
+-
+-
+ if test "$TOMBUILD" = "Y"; then
+ MATHLIB=-ltommath
+ else
+--- src/common/unicode_util.cpp
++++ src/common/unicode_util.cpp
+@@ -55,8 +55,13 @@
+
+ namespace {
+ #if defined(WIN_NT)
++#if defined(MSVC_USE_DEBUG_RUNTIME)
++const char* const inTemplate = "icuind%s.dll";
++const char* const ucTemplate = "icuucd%s.dll";
++#else
+ const char* const inTemplate = "icuin%s.dll";
+ const char* const ucTemplate = "icuuc%s.dll";
++#endif
+ #elif defined(DARWIN)
+ const char* const inTemplate = "lib/libicui18n.%s.dylib";
+ const char* const ucTemplate = "lib/libicuuc.%s.dylib";
diff --git a/external/firebird/wnt-per-process-trace-storage.patch.1 b/external/firebird/wnt-per-process-trace-storage.patch.1
new file mode 100644
index 000000000..46af6c5e5
--- /dev/null
+++ b/external/firebird/wnt-per-process-trace-storage.patch.1
@@ -0,0 +1,18 @@
+diff --git a/src/jrd/trace/TraceConfigStorage.cpp b/src/jrd/trace/TraceConfigStorage.cpp
+index 05fce3211ae7..d267713e85de 100644
+--- a/src/jrd/trace/TraceConfigStorage.cpp
++++ b/src/jrd/trace/TraceConfigStorage.cpp
+@@ -103,11 +103,11 @@ ConfigStorage::ConfigStorage()
+ pfnProcessIdToSessionId(GetCurrentProcessId(), &sesID) == 0 ||
+ sesID == 0)
+ {
+- filename.printf(TRACE_FILE); // TODO: it must be per engine instance
++ filename.printf("%s.0.%u", TRACE_FILE, GetCurrentProcessId()); // TODO: it must be per engine instance
+ }
+ else
+ {
+- filename.printf("%s.%u", TRACE_FILE, sesID);
++ filename.printf("%s.%u.%u", TRACE_FILE, sesID, GetCurrentProcessId());
+ }
+ #else
+ filename.printf(TRACE_FILE); // TODO: it must be per engine instance