vlib: add cgo-friendly plugin registration support 73/29473/1
authorDave Barach <dave@barachs.net>
Thu, 15 Oct 2020 21:07:03 +0000 (17:07 -0400)
committerDave Barach <dave@barachs.net>
Thu, 15 Oct 2020 21:08:23 +0000 (17:08 -0400)
commit500ba9fcc59b7f27aec5e4b9122754fe035f0628
tree6fa6014f016eb8d6f6541524d077ad0354a8d663
parent2a65804259e8c139c2d556f1c3e95f435280b4d2
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
src/vlib/unix/plugin.c
src/vlib/unix/plugin.h