[Scons-dev] [PATCH] scons soname on OpenBSD

Stefan Sperling stsp at openbsd.org
Mon Sep 9 13:45:50 EDT 2013


On Sat, Sep 07, 2013 at 04:24:41PM -0400, Gary Oberbrunner wrote:

> > > If you can submit this as a mercurial patch, ideally with a testcase

> > (SCons

> > > uses TDD), we should be able to work it in.

> >

> > Pardon my ignorance: I sent the output of 'hg diff'.

> > Is a "mercurial patch" something else?

> >

>

> The ideal way to contribute to SCons is to fork the mercurial repo at

> https://bitbucket.org/scons/scons, make your change, then submit a pull

> request. Patches sent to the mailing list can get lost.


If possible I'd like to ask someone on this list to commit
the patch for me. I don't have an account on bitbucket.
I used the time it would take me to read through atlassian's
terms of services to write a unit test instead :)


> What kind of test case do you expect? Something that checks linker

> > invokation command lines and fails if a soname is used on OpenBSD?

>

>

> Yes -- TDD says that the best test case is one that fails before your

> change (on OpenBSD in this case) and succeeds afterward.


Thanks, does the below look ok? It fails without my patch and
succeeds with it.

Note that sys.platform in Python currently returns 'openbsd5', hence
the startswith() to keep things working when OpenBSD's version number
reaches 6.0 (which given OpenBSD's release cycle and numbering will
happen in about 3 years).

diff -r 05db74dca43c src/engine/SCons/Tool/__init__.py
--- a/src/engine/SCons/Tool/__init__.py Sun Mar 03 19:34:10 2013 -0500
+++ b/src/engine/SCons/Tool/__init__.py Mon Sep 09 19:38:58 2013 +0200
@@ -257,6 +257,10 @@
print "VersionShLibLinkNames: linkname = ",linkname
linknames.append(linkname)
elif platform == 'posix':
+ if sys.platform.startswith('openbsd'):
+ # OpenBSD uses x.y shared library versioning numbering convention
+ # and doesn't use symlinks to backwards-compatible libraries
+ return []
# For libfoo.so.x.y.z, linknames libfoo.so libfoo.so.x.y libfoo.so.x
suffix_re = re.escape(shlib_suffix + '.' + version)
# First linkname has no version number
@@ -302,13 +306,17 @@
if version:
# set the shared library link flags
if platform == 'posix':
- suffix_re = re.escape(shlib_suffix + '.' + version)
- (major, age, revision) = version.split(".")
- # soname will have only the major version number in it
- soname = re.sub(suffix_re, shlib_suffix, libname) + '.' + major
- shlink_flags += [ '-Wl,-Bsymbolic', '-Wl,-soname=%s' % soname ]
- if Verbose:
- print " soname ",soname,", shlink_flags ",shlink_flags
+ shlink_flags += [ '-Wl,-Bsymbolic' ]
+ if sys.platform.startswith('openbsd'):
+ pass # OpenBSD doesn't usually use SONAME for libraries
+ else:
+ suffix_re = re.escape(shlib_suffix + '.' + version)
+ (major, age, revision) = version.split(".")
+ # soname will have only the major version number in it
+ soname = re.sub(suffix_re, shlib_suffix, libname) + '.' + major
+ shlink_flags += [ '-Wl,-soname=%s' % soname ]
+ if Verbose:
+ print " soname ",soname,", shlink_flags ",shlink_flags
elif platform == 'cygwin':
shlink_flags += [ '-Wl,-Bsymbolic',
'-Wl,--out-implib,${TARGET.base}.a' ]
diff -r 05db74dca43c test/Libs/SharedLibrary.py
--- a/test/Libs/SharedLibrary.py Sun Mar 03 19:34:10 2013 -0500
+++ b/test/Libs/SharedLibrary.py Mon Sep 09 19:38:58 2013 +0200
@@ -60,6 +60,13 @@
Default(env.Library(target = 'foo', source = obj))
""")

+test.write('SConstructBaz', """
+env=Environment()
+env['SHLIBVERSION'] = '1.0.0'
+obj = env.SharedObject('baz', 'foo.c')
+Default(env.SharedLibrary(target = 'baz', source = obj))
+""")
+
test.write('foo.c', r"""
#include <stdio.h>

@@ -280,6 +287,12 @@
test.run(program = test.workpath('progbar'),
stdout = "f4.c\nprogbar.c\n")

+if sys.platform.startswith('openbsd'):
+ # Make sure we don't link libraries with -Wl,-soname on OpenBSD.
+ test.run(arguments = '-f SConstructBaz')
+ for line in test.stdout().split('\n'):
+ test.fail_test(line.find('-Wl,-soname=libbaz.so') != -1)
+
test.pass_test()

# Local Variables:


More information about the Scons-dev mailing list