From f40310fddfc361d5ed24ec1fb5043ce211179e35 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 5 Feb 2024 20:24:27 -0600
Subject: [PATCH v2 3/4] Add libpgbincommon

This library is supposed to be linked wholly into executables. It
defines a function which turns leak detection off when using the
AddressSanitizer.
---
 src/bin/common/asan.c      | 12 ++++++++++++
 src/bin/common/meson.build |  8 ++++++++
 src/bin/meson.build        |  1 +
 3 files changed, 21 insertions(+)
 create mode 100644 src/bin/common/asan.c
 create mode 100644 src/bin/common/meson.build

diff --git a/src/bin/common/asan.c b/src/bin/common/asan.c
new file mode 100644
index 0000000000..d2739b2ad7
--- /dev/null
+++ b/src/bin/common/asan.c
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2024, PostgreSQL Global Development Group
+ *
+ * src/bin/common/asan.c
+ */
+
+const char *__asan_default_options(void);
+
+const char *__asan_default_options(void)
+{
+	return "detect_leaks=0";
+}
diff --git a/src/bin/common/meson.build b/src/bin/common/meson.build
new file mode 100644
index 0000000000..f63b9d664b
--- /dev/null
+++ b/src/bin/common/meson.build
@@ -0,0 +1,8 @@
+# Copyright (c) 2024, PostgreSQL Global Development Group
+
+libpgbincommon = static_library(
+  'pgbincommon',
+  'asan.c',
+)
+
+libpgbincommon_dep = declare_dependency(link_whole: libpgbincommon)
diff --git a/src/bin/meson.build b/src/bin/meson.build
index aa60ebaa30..fb18d618be 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -1,5 +1,6 @@
 # Copyright (c) 2022-2024, PostgreSQL Global Development Group
 
+subdir('common')
 subdir('initdb')
 subdir('pg_amcheck')
 subdir('pg_archivecleanup')
-- 
Tristan Partin
Neon (https://neon.tech)

