Archived
1
0

reductions, build fixes

This commit is contained in:
Emil 2023-09-06 23:57:21 +00:00
parent ff11966791
commit 12f03e20c4
No known key found for this signature in database
GPG Key ID: 5432DB986FDBCF8A
4 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,4 @@
CFLAGS += -shared -fPIE
CFLAGS += -shared -fPIC
libplug.so: plug.o
${LINK.c} $+ -o $@

View File

@ -1,10 +1,12 @@
#ifndef PLUG_H_
#define _QUOTE(name) #name
#define QUOTE(name) _QUOTE(name)
#define BIND(lib, func, func_name) *(void **) (&func) = dlsym(lib, func_name)
#define PLUGIN(lib, x) BIND(lib, x, QUOTE(x))
typedef void (*plug_t)(void);
static plug_t plug;
plug_t plug;
#define PLUG_H_
#endif

View File

@ -1,4 +1,5 @@
CPPFLAGS += -I../plug -L../plug
LDLIBS += -ldl
plugin: main.o
${LINK.c} $+ -o $@ ${LDLIBS}

View File

@ -12,19 +12,18 @@ main (void)
void * libplug = NULL;
while (1)
{
if (libplug) { dlclose(libplug); }
libplug = dlopen(libplug_fn, RTLD_NOW);
BIND(libplug, plug, "plug");
if (!libplug)
{ fprintf(stderr, "ERR: Cannot load dynamic library %s: %s\n", libplug_fn, dlerror()); }
else
{
*(void **) (&plug) = dlsym(libplug, "plug");
PLUGIN(libplug, plug);
printf("frame %d: ", x++);
if (plug)
{ plug(); }
else
{ fprintf(stderr, "ERR: Cannot find %s symbol in %s: %s\n", "plug", libplug_fn, dlerror()); }
dlclose(libplug);
}
sleep(2);
}