Note that this probably isn't testing anything because at least on
Linux the -undefined/-no-undefined flags appear to have no effect on
linking.
I'm using the -undefined flag here, but this is not actually a flag
documented anywhere in the libtool documentation, but I assume it's
fine because libtool doesn't complain.
---
tests/Makefile.am | 28 ++++++++++++++
tests/test-undefined.sh | 36 ++++++++++++++++++
tests/test-undefined-plugin.c | 70 +++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f9c6b8ad..901dca7e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -208,6 +208,7 @@ EXTRA_DIST = \
test-truncate3.sh \
test-truncate4.sh \
test-truncate-extents.sh \
+ test-undefined.sh \
test-vddk.sh \
test-vddk-real.sh \
test-version.sh \
@@ -351,6 +352,33 @@ test_just_filter_header_CPPFLAGS = \
$(NULL)
test_just_filter_header_CFLAGS = $(WARNINGS_CFLAGS)
+# Build a plugin with libtool -undefined flag. This is how plugins
+# were built before libnbdkit.so existed.
+TESTS += \
+ test-undefined.sh \
+ $(NULL)
+# check_LTLIBRARIES won't build a shared library (see automake manual).
+# So we have to do this and add a dependency.
+noinst_LTLIBRARIES += test-undefined-plugin.la
+test-undefined.sh: test-undefined-plugin.la
+
+test_undefined_plugin_la_SOURCES = \
+ test-undefined-plugin.c \
+ $(top_srcdir)/include/nbdkit-plugin.h \
+ $(NULL)
+test_undefined_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir)/include \
+ $(NULL)
+test_undefined_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+# For use of the -rpath option, see:
+#
https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
+test_undefined_plugin_la_LDFLAGS = \
+ -module -avoid-version -shared \
+ -undefined \
+ $(SHARED_LDFLAGS) \
+ -rpath /nowhere \
+ $(NULL)
+
if CAN_TEST_ANSI_C
# This builds a plugin using an ANSI (ISO C90) compiler to ensure that
# the header file is compatible. The plugin does nothing very
diff --git a/tests/test-undefined.sh b/tests/test-undefined.sh
new file mode 100755
index 00000000..db6c8eb8
--- /dev/null
+++ b/tests/test-undefined.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# nbdkit
+# Copyright (C) 2017-2020 Red Hat Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+source ./functions.sh
+set -e
+
+nbdkit .libs/test-undefined-plugin.so --version
diff --git a/tests/test-undefined-plugin.c b/tests/test-undefined-plugin.c
new file mode 100644
index 00000000..42683047
--- /dev/null
+++ b/tests/test-undefined-plugin.c
@@ -0,0 +1,70 @@
+/* nbdkit
+ * Copyright (C) 2013-2020 Red Hat Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Red Hat nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <nbdkit-plugin.h>
+
+static void *
+undefined_open (int readonly)
+{
+ return NBDKIT_HANDLE_NOT_NEEDED;
+}
+
+static int64_t
+undefined_get_size (void *handle)
+{
+ return 0;
+}
+
+#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
+
+static int
+undefined_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
+{
+ memset (buf, 0, count);
+ return 0;
+}
+
+static struct nbdkit_plugin plugin = {
+ .name = "testundefined",
+ .version = PACKAGE_VERSION,
+ .open = undefined_open,
+ .get_size = undefined_get_size,
+ .pread = undefined_pread,
+};
+
+NBDKIT_REGISTER_PLUGIN(plugin)
--
2.25.0