diff mbox series

[RFC,2/4] tcg/plugins: Automatically define CURRENT_PLUGIN

Message ID 20220901182734.2987337-3-fasano@mit.edu
State New
Headers show
Series Support interactions between TCG plugins | expand

Commit Message

Andrew Fasano Sept. 1, 2022, 6:27 p.m. UTC
Use plugin filenames to set the preprocessor variable CURRENT_PLUGIN
as a string during plugin compilation.

Signed-off-by: Andrew Fasano <fasano@mit.edu>
---
 contrib/plugins/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Bennée Sept. 21, 2022, 2 p.m. UTC | #1
Andrew Fasano <fasano@mit.edu> writes:

> Use plugin filenames to set the preprocessor variable CURRENT_PLUGIN
> as a string during plugin compilation.
>
> Signed-off-by: Andrew Fasano <fasano@mit.edu>
> ---
>  contrib/plugins/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
> index df3499f4f2..b7720fea0f 100644
> --- a/contrib/plugins/Makefile
> +++ b/contrib/plugins/Makefile
> @@ -34,7 +34,7 @@ CFLAGS += -I$(SRC_PATH)/include/qemu
>  all: $(SONAMES)
>  
>  %.o: %.c
> -	$(CC) $(CFLAGS) -c -o $@ $<
> +	$(CC) $(CFLAGS) -DCURRENT_PLUGIN=\"$(basename $@)\" -c -o $@ $<

While all plugins are currently single files this seems a little clumsy.

We can already check exported plugin symbols in loader.c (see
qemu_plugin_version) so maybe it would be better to declare an API
update and mandate any plugin object also needs to define a
qemu_plugin_name with a null terminated string?

>  
>  lib%.so: %.o
>  	$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
Andrew Fasano Sept. 26, 2022, 9:37 p.m. UTC | #2
From: Alex Bennée <alex.bennee@linaro.org>
> Andrew Fasano <fasano@mit.edu> writes:
> 
> > Use plugin filenames to set the preprocessor variable CURRENT_PLUGIN
> > as a string during plugin compilation.
> >
> > Signed-off-by: Andrew Fasano <fasano@mit.edu>
> > ---
> >  contrib/plugins/Makefile | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
> > index df3499f4f2..b7720fea0f 100644
> > --- a/contrib/plugins/Makefile
> > +++ b/contrib/plugins/Makefile
> > @@ -34,7 +34,7 @@ CFLAGS += -I$(SRC_PATH)/include/qemu
> >  all: $(SONAMES)
> > 
> >  %.o: %.c
> > -     $(CC) $(CFLAGS) -c -o $@ $<
> > +     $(CC) $(CFLAGS) -DCURRENT_PLUGIN=\"$(basename $@)\" -c -o $@ $<
> 
> While all plugins are currently single files this seems a little clumsy.
> 
> We can already check exported plugin symbols in loader.c (see
> qemu_plugin_version) so maybe it would be better to declare an API
> update and mandate any plugin object also needs to define a
> qemu_plugin_name with a null terminated string?

That design sounds good to me and would be good for multi-file plugins. Perhaps
plugins could also (optionally?) specify their own API versioning here.

> 
> > 
> >  lib%.so: %.o
> >        $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
> 
> 
> --
> Alex Bennée
diff mbox series

Patch

diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
index df3499f4f2..b7720fea0f 100644
--- a/contrib/plugins/Makefile
+++ b/contrib/plugins/Makefile
@@ -34,7 +34,7 @@  CFLAGS += -I$(SRC_PATH)/include/qemu
 all: $(SONAMES)
 
 %.o: %.c
-	$(CC) $(CFLAGS) -c -o $@ $<
+	$(CC) $(CFLAGS) -DCURRENT_PLUGIN=\"$(basename $@)\" -c -o $@ $<
 
 lib%.so: %.o
 	$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)