summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2020-06-29 17:56:23 +0100
committerSimon McVittie <smcv@collabora.com>2020-07-01 17:49:39 +0100
commitef7fb78a5370a5e36272e3bbe91e1864b766a565 (patch)
tree4850f43fef176dcf94214da658a57659580c4314
parent761de0f50a9954392ede2337c55e59adb28df97e (diff)
downloadjson-glib-ef7fb78a5370a5e36272e3bbe91e1864b766a565.tar.gz
build: Add a symbol version to all exported symbols
The --default-symver linker option attaches a default version definition (the SONAME) to every exported symbol. It is supported since at least GNU binutils 2.22 in 2011 (older versions not tested). With this version definition, newly-linked binaries that depend on the json-glib shared library will refer to its symbols in a versioned form, preventing their references from being resolved to a symbol of the same name exported by json-c or libjansson if those libraries appear in dependency search order before json-glib, which will usually result in a crash. This is necessary because ELF symbol resolution normally uses a single flat namespace, not a tree like Windows symbol resolution. At least one symbol (json_object_iter_next()) is exported by all three JSON libraries. Linking with -Bsymbolic is not enough to have this effect in all cases, because -Bsymbolic only affects symbol lookup within a shared object, for example when json_from_string() calls json_parser_new(). It does not affect symbol lookup when external code calls into json-glib, for example when libedataserver calls json_parser_new(). This change will also not prevent code that depends on json-c or libjansson from finding json-glib's symbols and crashing; to prevent that, a corresponding change in json-c or libjansson would be needed. Adding a symbol-version is a backwards-compatible change, but once added, removing or changing the symbol-version would be an incompatible change that requires a SONAME bump. Partially resolves https://gitlab.gnome.org/GNOME/json-glib/-/issues/33 and https://gitlab.gnome.org/GNOME/glib/-/issues/2147. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--meson.build1
1 files changed, 1 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index f84d865..67d2a5e 100644
--- a/meson.build
+++ b/meson.build
@@ -136,6 +136,7 @@ if host_system == 'linux'
'-Wl,-Bsymbolic',
'-Wl,-z,relro',
'-Wl,-z,now',
+ '-Wl,--default-symver',
])
endif