mapnik-org/mapnik — Issue #673: Avoid relocation error with 64 bit libs on solaris with -shared flag
Author: artemp
Created: 2011-10-11 08:07:35+00:00
State: open
Labels: Scons_Build_Scripts

fully PIC (position independent) 64bit dynamic libraries on solaris (at least when built with g++ 4.4) appear to need to be linked with -shared.

SCons uses only -G, so even for code properly built with -fPIC you'll get runtime errors like:

{{{
$ ./demo/c++/rundemo
ld.so.1: rundemo: fatal: relocation error: R_AMD64_PC32: file /usr/local/lib/libmapnik.so: symbol main: value 0x2800beb1534 does not fit
Killed
}}}

And diagnostic indication that the code is not fully PIC is seen with:

{{{
$ elfdump -d src/libmapnik.so | grep TEX
[35] TEXTREL 0
[43] FLAGS 0x4 [ TEXTREL ]
}}}

For more info see: http://blogs.sun.com/rie/entry/my_relocations_don_t_fit

So, how to make sure that -shared is passed to all dynamic libraries, instead of -G?

Oddly it appears that this is what is needed:
{{{
#!diff

Index: scons/scons-local-1.2.0/SCons/Tool/sunar.py
===================================================================
--- scons/scons-local-1.2.0/SCons/Tool/sunar.py (revision 2437)
+++ scons/scons-local-1.2.0/SCons/Tool/sunar.py (working copy)
@@ -52,7 +52,7 @@
env['ARCOM'] = '$AR $ARFLAGS $TARGET $SOURCES'

env['SHLINK'] = '$LINK'
- env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -G')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['LIBPREFIX'] = 'lib'
env['LIBSUFFIX'] = '.a'
}}}

As this patch (the more intuative) has no effect (pollution of env?):
{{{
#!diff

Index: scons/scons-local-1.2.0/SCons/Tool/sunlink.py
===================================================================
--- scons/scons-local-1.2.0/SCons/Tool/sunlink.py (revision 2437)
+++ scons/scons-local-1.2.0/SCons/Tool/sunlink.py (working copy)
@@ -60,7 +60,7 @@
"""Add Builders and construction variables for Forte to an Environment."""
link.generate(env)

- env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -G')
+ env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')

env.Append(LINKFLAGS=['$__RPATH'])
env['RPATHPREFIX'] = '-R'
}}}