diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-03 20:13:41 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-09 12:57:15 +0200 |
commit | ca7bb15591bb585156bcf17aa3c43817605b05ee (patch) | |
tree | 1099ecbc315ea9e152723f2010a9fc4fdd77d384 /shared | |
parent | 18692faa9fddf2a1208ad593195d794710eeea03 (diff) | |
download | NetworkManager-ca7bb15591bb585156bcf17aa3c43817605b05ee.tar.gz |
shared: cleanup dlopening libjansson depending on configure options
- assert that WITH_JANSSON and JANSSON_SONAME are defined consistently.
This check ensures that we can check at compile time that nm_json_vt()
will always fail (because JANSSON_SONAME) is undefined.
That is interesting, because this means you can do a compile time
for !WITH_JANSSON, and know if nm_json_vt() will *never* succeed.
With that, we could let the linker know when the code is unused
and remove all uses of nm_json_vt(), without using the traditional
conditional compilation with "#if WITH_JANSSON". But of course, we
currently don't do this micro optimization to remove defunct code.
- drop the "mode" helper variable and pass the flags directly to
dlopen().
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-json-aux.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/shared/nm-glib-aux/nm-json-aux.c b/shared/nm-glib-aux/nm-json-aux.c index 6844ebcbfb..e9816d7781 100644 --- a/shared/nm-glib-aux/nm-json-aux.c +++ b/shared/nm-glib-aux/nm-json-aux.c @@ -147,24 +147,31 @@ static NMJsonVtInternal * _nm_json_vt_internal_load (void) { NMJsonVtInternal *v; - void *handle = NULL; - int mode; + const char *soname; + void *handle; v = g_new0 (NMJsonVtInternal, 1); -#ifndef JANSSON_SONAME -#define JANSSON_SONAME "" +#if WITH_JANSSON && defined (JANSSON_SONAME) + G_STATIC_ASSERT_EXPR (NM_STRLEN (JANSSON_SONAME) > 0); + nm_assert (strlen (JANSSON_SONAME) > 0); + soname = JANSSON_SONAME; +#elif !WITH_JANSSON && !defined (JANSSON_SONAME) + soname = NULL; +#else +#error "WITH_JANSON and JANSSON_SONAME are defined inconsistently." #endif - mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE | RTLD_DEEPBIND; -#if defined (ASAN_BUILD) - /* Address sanitizer is incompatible with RTLD_DEEPBIND. */ - mode &= ~RTLD_DEEPBIND; -#endif - - if (strlen (JANSSON_SONAME) > 0) - handle = dlopen (JANSSON_SONAME, mode); + if (!soname) + return v; + handle = dlopen (soname, RTLD_LAZY + | RTLD_LOCAL + | RTLD_NODELETE +#if !defined (ASAN_BUILD) + | RTLD_DEEPBIND +#endif + | 0); if (!handle) return v; |