From ee91f1f9ab66c16f3f902ad21713fac4100193f5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 31 Aug 2021 13:27:41 +0200 Subject: [PATCH 1/3] build: define WITH_OPENVSWITCH in "config.h" It will be used next. --- config.h.meson | 4 ++++ configure.ac | 5 +++++ meson.build | 1 + 3 files changed, 10 insertions(+) diff --git a/config.h.meson b/config.h.meson index 5979793e5c..901535cf9f 100644 --- a/config.h.meson +++ b/config.h.meson @@ -224,6 +224,9 @@ /* Define if you have oFono support (experimental) */ #mesondefine WITH_OFONO +/* Whether we build with OVS plugin */ +#mesondefine WITH_OPENVSWITCH + /* Define if you have PPP support */ #mesondefine WITH_PPP @@ -261,3 +264,4 @@ /* Define to 1 if you have history support from -lreadline. */ #mesondefine HAVE_READLINE_HISTORY + diff --git a/configure.ac b/configure.ac index 3fc92d0892..a5e59514b0 100644 --- a/configure.ac +++ b/configure.ac @@ -851,6 +851,11 @@ if test "${enable_ovs}" != "no"; then fi fi AM_CONDITIONAL(WITH_OPENVSWITCH, test "${enable_ovs}" = "yes") +if test "${enable_ovs}" = "yes" ; then + AC_DEFINE(WITH_OPENVSWITCH, 1, [Whether we build with OVS plugin]) +else + AC_DEFINE(WITH_OPENVSWITCH, 0, [Whether we build with OVS plugin]) +fi # DHCP client support AC_ARG_WITH([dhclient], diff --git a/meson.build b/meson.build index 3c4be61509..40337b0e1b 100644 --- a/meson.build +++ b/meson.build @@ -644,6 +644,7 @@ enable_ovs = get_option('ovs') if enable_ovs assert(jansson_dep.found(), 'jansson is needed for Open vSwitch integration. Use -Dovs=false to disable it') endif +config_h.set10('WITH_OPENVSWITCH', enable_ovs) # DNS resolv.conf managers config_dns_rc_manager_default = get_option('config_dns_rc_manager_default') From 6bd506dfb8fb713f84941a6f036af3519a15e038 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 31 Aug 2021 13:20:59 +0200 Subject: [PATCH 2/3] core: use nm-sudo symbols in NetworkManager binary for plugin The two nm-sudo helper functions are only used by the OVS device plugin, but they are part of NetworkManager core binary. This is done commonly, where the NetworkManager binary has symbols that are used by the plugins. But in this case, NetworkManager itself doesn't use the symbols. That will case the linker to drop them. A previous solution for that was commit 684f2acffea3 ('build: add way to keep unused symbols when linking NetworkManager'), but that doesn't seem to work with clang 3.4 (rhel-7). Instead, actually use the symbol so that it cannot be dropped. --- src/core/nm-manager.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index d2ac7185f0..49c56bf68f 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -44,6 +44,7 @@ #include "nm-rfkill-manager.h" #include "nm-session-monitor.h" #include "nm-sleep-monitor.h" +#include "nm-sudo-call.h" #include "settings/nm-settings-connection.h" #include "settings/nm-settings.h" #include "vpn/nm-vpn-manager.h" @@ -212,6 +213,13 @@ struct _NMManager { typedef struct { NMDBusObjectClass parent; + +#if WITH_OPENVSWITCH + /* these fields only serve the purpose to use the symbols.*/ + void (*_use_symbol_nm_sudo_call_get_fd)(void); + void (*_use_symbol_nm_sudo_utils_open_fd)(void); +#endif + } NMManagerClass; G_DEFINE_TYPE(NMManager, nm_manager, NM_TYPE_DBUS_OBJECT) @@ -8528,6 +8536,14 @@ nm_manager_class_init(NMManagerClass *manager_class) GObjectClass * object_class = G_OBJECT_CLASS(manager_class); NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(manager_class); +#if WITH_OPENVSWITCH + /* Use the symbols. These symbols are in NetworkManager binary but will be + * used by the OVS device plugin. If we don't use the symbol here, it will + * be wrongly dropped. */ + manager_class->_use_symbol_nm_sudo_call_get_fd = (void (*)(void)) nm_sudo_call_get_fd; + manager_class->_use_symbol_nm_sudo_utils_open_fd = (void (*)(void)) nm_sudo_utils_open_fd; +#endif + dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_STATIC(NM_DBUS_PATH); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_manager); From a8929bbfc3682df3091865aceb7410f38bbb5357 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 31 Aug 2021 13:31:27 +0200 Subject: [PATCH 3/3] Revert "build: add way to keep unused symbols when linking NetworkManager" This approach does not seem to work with clang 3.4 (rhel-7). Instead, make sure we actually use the symbol in NetworkManager so that it gets preserved for the OVS device plugin. This reverts commit 684f2acffea3ed5704330bff05b87acbf371ccdd. --- Makefile.am | 10 ---------- src/core/meson.build | 17 ++--------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/Makefile.am b/Makefile.am index 25ea649484..bb59bf8354 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2662,14 +2662,6 @@ $(src_core_libNetworkManagerTest_la_OBJECTS): $(src_libnm_core_public_mkenums_h) ############################################################################### -# NetworkManager binary also must contain symbols that are not used by the binary -# itself, but by the plugins (that are dlopened). We need to explicitly include -# them during linking. -networkmanager_undefined_symbols = \ - nm_sudo_call_get_fd \ - nm_sudo_utils_open_fd \ - $(NULL) - noinst_PROGRAMS += src/core/NetworkManager-all-sym src_core_NetworkManager_all_sym_CPPFLAGS = $(src_core_cppflags) @@ -2684,7 +2676,6 @@ src_core_NetworkManager_all_sym_LDADD = \ src_core_NetworkManager_all_sym_LDFLAGS = \ -rdynamic \ - $(networkmanager_undefined_symbols:%=-u %) \ $(SANITIZER_EXEC_LDFLAGS) \ $(NULL) @@ -2711,7 +2702,6 @@ src_core_NetworkManager_LDADD = \ src_core_NetworkManager_LDFLAGS = \ -rdynamic \ -Wl,--version-script="src/core/NetworkManager.ver" \ - $(networkmanager_undefined_symbols:%=-u %) \ $(SANITIZER_EXEC_LDFLAGS) \ $(NULL) diff --git a/src/core/meson.build b/src/core/meson.build index f935ed1606..1a3f334fd8 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -271,17 +271,6 @@ endif subdir('devices') subdir('settings/plugins') -# NetworkManager binary also must contain symbols that are not used by the binary -# itself, but by the plugins (that are dlopened). We need to explicitly include -# them during linking. -networkmanager_undefined_symbols_args = [] -foreach s: [ - 'nm_sudo_call_get_fd', - 'nm_sudo_utils_open_fd', - ] - networkmanager_undefined_symbols_args += ['-u', s] -endforeach - # NetworkManager binary # libNetworkManager.a, as built by meson doesn't contain all symbols @@ -296,9 +285,7 @@ NetworkManager_all_sym = executable( nm_deps, libudev_dep, ], - link_args: [ - '-Wl,--no-gc-sections', - ] + networkmanager_undefined_symbols_args, + link_args: '-Wl,--no-gc-sections', link_whole: [ libNetworkManager, libNetworkManagerBase, @@ -359,7 +346,7 @@ NetworkManager = executable( link_args: [ '-rdynamic', '-Wl,--version-script,@0@'.format(ver_script.full_path()), - ] + networkmanager_undefined_symbols_args, + ], link_depends: ver_script, install: true, install_dir: nm_sbindir,