vlib: add cgo-friendly plugin registration support
Allows us to declare plugin registrations in a non-disgusting way:
var plugin_reg = vpp.PluginRegistration{
Description: "The CGO plugin",
Version: "My Version",
Overrides: "sample_plugin.so",
}
It turns out that the specific compiler setup generates (.data section
offset, length) pairs in the .vlib_plugin_r2 section:
Contents of section .vlib_plugin_r2:
1ba9d0 00000000 00000000 50a81800 00000000 ........P.......
1ba9e0 0a000000 00000000 00000000 00000000 ................
1ba9f0 00000000 00000000 00000000 00000000 ................
1baa00 00000000 00000000 00000000 00000000 ................
1baa10 00000000 00000000 70a81800 00000000 ........p.......
1baa20 0e000000 00000000 ........
Contents of section .data:
18a800 00a81800 00000000 00000000 00000000 ................
18a810 00000000 00000000 00000000 00000000 ................
18a820 00000000 00000000 00000000 00000000 ................
18a830 00000000 00000000 00000000 00000000 ................
18a840 00000000 00000000 14000000 00000000 ................
18a850 4d792056 65727369 6f6e0000 00000000 My Version......
18a860 00000000 00000000 14000000 00000000 ................
18a870 54686520 45474f20 706c7567 696e0000 The CGO plugin..
18a880 00000000 00000000 0c000000 00000000 ................
<etc>
Unfortunately, it seems impossible to torture clang / gcc into
producing anything like this. This patch fabricates a plausible
vlib_plugin_registration_t from the so-called vlib_plugin_r2_t.
Type: improvement
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I8c0c5a24f3b7bfea07d5181a7250b3d9685e8446
diff --git a/src/vlib/unix/plugin.h b/src/vlib/unix/plugin.h
index c9a33cc..4beae43 100644
--- a/src/vlib/unix/plugin.h
+++ b/src/vlib/unix/plugin.h
@@ -67,6 +67,33 @@
}) vlib_plugin_registration_t;
/* *INDENT-ON* */
+/*
+ * Plugins may also use this registration format, which is
+ * easy enough to emit from e.g. a golang compiler.
+ */
+typedef struct
+{
+ uword data_segment_offset;
+ uword length;
+} vlib_r2_string_t;
+
+typedef struct
+{
+ int default_disabled;
+ vlib_r2_string_t version;
+ vlib_r2_string_t version_required;
+ vlib_r2_string_t overrides;
+ vlib_r2_string_t early_init;
+ vlib_r2_string_t description;
+} vlib_plugin_r2_t;
+
+#define foreach_r2_string_field \
+_(version) \
+_(version_required) \
+_(overrides) \
+_(early_init) \
+_(description)
+
typedef struct
{
u8 *name;