build: use -fcommon when building libnm-core

Building with GCC 10 gives the following error:

 multiple definition of_nm_jansson_json_object_iter_key';
 libnm/.libs/liblibnm.a(libnm_core_la-nm-json.o):/builddir/build/BUILD/NetworkManager-1.23.1/libnm-core/nm-json.c:24: first defined here /usr/bin/ld:
 libnm/.libs/liblibnm.a(libnm_core_la-nm-team-utils.o):/usr/include/jansson.h:202: multiple definition of _nm_jansson_json_object_iter';

This happens because GCC 10 defaults to -fno-common and so multiple
definitions of the same global variable are not merged together.

_nm_jansson_json_* symbols are defined in nm-json.c as void pointers
and, due to the following macros in nm-json.h:

 #define json_object_iter_next   (*_nm_jansson_json_object_iter_next)
 ...

the function declaration in jansson.h:

 void *json_object_iter_next(json_t *object, void *iter);

becomes a global variable as well:

 void *(*_nm_jansson_json_object_iter_next)(json_t *object, void *iter);

So, the symbol is present in nm-json.o and all other object files that
include nm-json.h, and -fcommon is required. Without it, it would be
necessary to define the symbols only in one place (for example,
nm-json.c), but then static inline functions from the jannson.h header
would still refer to the original (missing) jansson functions.

For the moment, just use -fcommon.
This commit is contained in:
Beniamino Galvani 2020-02-01 11:38:25 +01:00
parent c11ac34f4c
commit d2d6a68697
2 changed files with 5 additions and 1 deletions

View file

@ -1084,6 +1084,7 @@ libnm_core_libnm_core_la_CPPFLAGS = \
if WITH_JSON_VALIDATION
libnm_core_libnm_core_la_CPPFLAGS += $(JANSSON_CFLAGS)
libnm_core_libnm_core_la_CFLAGS = -fcommon
endif
libnm_core_libnm_core_la_SOURCES = \

View file

@ -188,9 +188,12 @@ links = [
libnm_libnm_core_intern,
]
libnm_core_c_args = common_c_flags
if enable_json_validation
libnm_core_sources += files('nm-json.c')
deps += jansson_dep
libnm_core_c_args += ['-fcommon']
endif
libnm_core = static_library(
@ -198,7 +201,7 @@ libnm_core = static_library(
sources: libnm_core_sources + libnm_core_enum_sources + nm_meta_setting_source + [nm_version_macro_header],
include_directories: top_inc,
dependencies: deps,
c_args: common_c_flags,
c_args: libnm_core_c_args,
link_with: links,
)