[json-glib/wip/smcv/default-symver] build: Add a symbol version to all exported symbols



commit 847d8da72d8794c4d7983000c5561af3527ee7f0
Author: Simon McVittie <smcv collabora com>
Date:   Mon Jun 29 17:56:23 2020 +0100

    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.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 json-glib/meson.build | 2 +-
 meson.build           | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/json-glib/meson.build b/json-glib/meson.build
index e77f818..80a48c4 100644
--- a/json-glib/meson.build
+++ b/json-glib/meson.build
@@ -78,7 +78,7 @@ json_lib = library(
   include_directories: root_dir,
   dependencies: [gio_dep],
   c_args: json_c_args + common_cflags,
-  link_args: common_ldflags,
+  link_args: common_ldflags + lib_ldflags,
   install: true,
 )
 
diff --git a/meson.build b/meson.build
index f84d865..6a76e57 100644
--- a/meson.build
+++ b/meson.build
@@ -147,6 +147,15 @@ if host_system == 'darwin'
   ]
 endif
 
+lib_ldflags = []
+
+if host_system == 'linux'
+  # Version symbols with the SONAME to avoid clashing with json-c, libjansson
+  lib_ldflags += [
+    '-Wl,--default-symver',
+  ]
+endif
+
 root_dir = include_directories('.')
 
 gnome = import('gnome')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]