Skip to content

Commit

Permalink
wafsamba: the symbol version string of private libraries should be ba…
Browse files Browse the repository at this point in the history
…sed on the toplevel project

If we build a private library all symbols should be made private based
on a unique suffix.

When we use a unique soname and a unique symbol version suffix it's very unlikely
to hit conflicts due to inherited libraries.

For the abi checking we still use the original vnum as abi_vnum.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14780

Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
  • Loading branch information
metze-samba committed Nov 30, 2021
1 parent da7c41e commit 33e6949
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
23 changes: 19 additions & 4 deletions buildtools/wafsamba/samba_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def abi_check(self):
abi_gen = os.path.join(topsrc, 'buildtools/scripts/abi_gen.sh')

abi_file = "%s/%s-%s.sigs" % (self.abi_directory, self.version_libname,
self.vnum)
self.abi_vnum)

tsk = self.create_task('abi_check', self.link_task.outputs[0])
tsk.ABI_FILE = abi_file
Expand Down Expand Up @@ -214,21 +214,32 @@ def abi_build_vscript(task):

symmap = {}
versions = []
abi_match = list(task.env.ABI_MATCH)
for f in task.inputs:
fname = f.abspath(task.env)
basename = os.path.basename(fname)
version = basename[len(task.env.LIBNAME)+1:-len(".sigs")]
versions.append(version)
abi_process_file(fname, version, symmap)
if task.env.PRIVATE_LIBRARY:
# For private libraries we need to inject
# each public symbol explicitly into the
# abi match array and remove all explicit
# versioning so that each exported symbol
# is tagged with the private library tag.
for s in symmap:
abi_match.append(s)
symmap = {}
versions = []
f = open(tgt, mode='w')
try:
abi_write_vscript(f, task.env.LIBNAME, task.env.VERSION, versions,
symmap, task.env.ABI_MATCH)
symmap, abi_match)
finally:
f.close()


def ABI_VSCRIPT(bld, libname, abi_directory, version, vscript, abi_match=None):
def ABI_VSCRIPT(bld, libname, abi_directory, version, vscript, abi_match=None, private_library=False):
'''generate a vscript file for our public libraries'''
if abi_directory:
source = bld.path.ant_glob('%s/%s-[0-9]*.sigs' % (abi_directory, libname), flat=True)
Expand All @@ -238,6 +249,9 @@ def abi_file_key(path):
else:
source = ''

if private_library is None:
private_library = False

libname = os.path.basename(libname)
version = os.path.basename(version)
libname = libname.replace("-", "_").replace("+","_").upper()
Expand All @@ -255,5 +269,6 @@ def abi_file_key(path):
t.env.ABI_MATCH = abi_match
t.env.VERSION = version
t.env.LIBNAME = libname
t.vars = ['LIBNAME', 'VERSION', 'ABI_MATCH']
t.env.PRIVATE_LIBRARY = private_library
t.vars = ['LIBNAME', 'VERSION', 'ABI_MATCH', 'PRIVATE_LIBRARY']
Build.BuildContext.ABI_VSCRIPT = ABI_VSCRIPT
8 changes: 6 additions & 2 deletions buildtools/wafsamba/wafsamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def SAMBA_LIBRARY(bld, libname, source,
raise Errors.WafError("public library '%s' must have header files" %
libname)

abi_vnum = vnum

if bundled_name is not None:
pass
elif target_type == 'PYTHON' or realname or not private_library:
Expand All @@ -232,6 +234,7 @@ def SAMBA_LIBRARY(bld, libname, source,
else:
assert (private_library == True and realname is None)
bundled_name = PRIVATE_NAME(bld, libname.replace('_', '-'))
vnum = None

ldflags = TO_LIST(ldflags)
if bld.env['ENABLE_RELRO'] is True:
Expand All @@ -258,15 +261,15 @@ def SAMBA_LIBRARY(bld, libname, source,
vscript = None
if bld.env.HAVE_LD_VERSION_SCRIPT:
if private_library:
version = "%s_%s" % (Context.g_module.APPNAME, Context.g_module.VERSION)
version = bld.env.PRIVATE_VERSION
elif vnum:
version = "%s_%s" % (libname, vnum)
else:
version = None
if version:
vscript = "%s.vscript" % libname
bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
abi_match)
abi_match, private_library)
fullname = apply_pattern(bundled_name, bld.env.cshlib_PATTERN)
fullpath = bld.path.find_or_declare(fullname)
vscriptpath = bld.path.find_or_declare(vscript)
Expand Down Expand Up @@ -303,6 +306,7 @@ def SAMBA_LIBRARY(bld, libname, source,
samba_install = install,
abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
abi_match = abi_match,
abi_vnum = abi_vnum,
private_library = private_library,
grouping_library=grouping_library,
allow_undefined_symbols=allow_undefined_symbols
Expand Down
2 changes: 2 additions & 0 deletions buildtools/wafsamba/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def configure(conf):

conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
conf.env.PRIVATE_EXTENSION_EXCEPTION = Options.options.PRIVATE_EXTENSION_EXCEPTION.split(',')
conf.env.PRIVATE_VERSION = "%s_%s_%s" % (Context.g_module.APPNAME,
Context.g_module.VERSION, conf.env.PRIVATE_EXTENSION)

conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
Expand Down

0 comments on commit 33e6949

Please sign in to comment.