On Mi, 2010-11-24 at 14:07 +0000, Andris Pavenis wrote:
> libsynthesissdk.a can be linked into external libsynthesis plugins, but
> is built without -fPIC. It works OK for 32 bit Linux but not 64 bit Linux.
> 
> I'm getting error message:
> /usr/bin/ld: 
> /usr/lib64/libsynthesissdk.a(libsynthesissdk_la-SDK_support.o): 
> relocation R_X86_64_32 against `a local symbol' can not be used when 
> making a shared object; recompile with -fPIC
> /usr/lib64/libsynthesissdk.a: could not read symbols: Bad value
> collect2: ld returned 1 exit status

I'm aware of the need for -fPIC on 64 bit. What I don't quite understand
is that I'm not seeing that problem when compiling on it myself and that
we haven't heard of the problem elsewhere before. libsyncevolution.so
links fine against a libsynthesissdk.a.

What I see is that libtool invokes g++ with -fPIC -DPIC when compiling
libsynthesissdk.a source files. This is with libtool 2.2.6b on Debian
Testing, with --enable-shared --enable-static. Also works in other
combinations, expect with an explicit --disable-shared, but then also
libsynthesis.a is compiled without PIC mode.

In that case I wouldn't expect libsynthesissdk.a to work inside a shared
library, although I don't know whether that is formally defined anywhere
in libtool or what the common way of handling these configure flags is.
PIC mode causes a slight performance degradation, so it makes sense to
not use it in static libs which are meant to be used in executables.

> I added following patch when building own RPM package 
> (libsynthesis-3.4.0.16)
> 
> --- libsynthesis_3.4.0.16/src/Makefile.am.in.orig       2010-11-24 
> 15:52:52.000000000 +0200
> +++ libsynthesis_3.4.0.16/src/Makefile.am.in    2010-11-24 
> 15:53:24.000000000 +0200
> @@ -115,6 +115,7 @@ else
>   libsynthesissdk_la_SOURCES += @LIBSYNTHESISSDK_SOURCES_BOTH@
>   endif
>   libsynthesissdk_la_CPPFLAGS = \
> +       -fPIC \
>          -D_GNU_SOURCE=1 \
>          -include $(top_builddir)/config.h \
>          -I$(srcdir)/Targets/ReleasedProducts/SDK \

I'm a bit reluctant to hard-code -fPIC in the makefile - what if the
compiler doesn't support it? Unlikely, but not impossible.

Does the attached patch work for you? If it does, then I can include it
in the next Linux libsynthesis update (which usually happens via
SyncEvolution) and it trickle into upstream libsynthesis the next time
Lukas merges back changes.


-- 
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.

>From 8c8c2b243de4e1a3f013881eef48369c437156eb Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.o...@intel.com>
Date: Mon, 6 Dec 2010 10:43:49 +0100
Subject: [PATCH] autotools: always enforce PIC mode for libsynthesissdk.a

Some versions of libtool use PIC mode automatically for static
libraries, others don't (?!). See the "[os-libsynthesis]
libsynthesissdk.a built without -fPIC" for a problem report.

This patch extracts PIC flags from libtool configure flags and
uses them for the two static libraries (libsynthesissdk.a and
libsynthesisstubs.a). This is a bit more portable than hard-coding
the -fPIC flag, albeit making an assumption about the naming
of libtool internal variables.
---
 configure.in       |    7 +++++++
 src/Makefile.am.in |    2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/configure.in b/configure.in
index b0ee64a..e2a0c14 100644
--- a/configure.in
+++ b/configure.in
@@ -12,6 +12,13 @@ AC_PROG_LIBTOOL
 AC_PROG_MAKE_SET
 AM_PROG_CC_C_O
 
+dnl Extract PIC flags from libtool configure for libsynthesissdk.a
+dnl (makes assumptions about libtool var naming!). Some versions
+dnl of libtool use PIC mode automatically for static libraries,
+dnl others don't (?!). See "[os-libsynthesis] libsynthesissdk.a built without -fPIC".
+PIC_CXXFLAGS="$lt_prog_compiler_pic_CXX"
+AC_SUBST(PIC_CXXFLAGS)
+
 AC_ARG_ENABLE(debug-logs,
               AS_HELP_STRING([--debug-logs],
                              [For developers: add links to call location to HTML log files. Depends on Doxygen (for HTML version of source) and g++ (for __PRETTY_FUNCTION__).]),
diff --git a/src/Makefile.am.in b/src/Makefile.am.in
index e412171..7be4a00 100644
--- a/src/Makefile.am.in
+++ b/src/Makefile.am.in
@@ -108,6 +108,7 @@ XMLPARSE_CFLAGS_BUILTIN = -I$(srcdir)/Targets/ReleasedProducts/clientEngine_auto
 endif
 
 libsynthesissdk_la_LDFLAGS = -static
+libsynthesissdk_la_CXXFLAGS = $(PIC_CXXFLAGS)
 libsynthesissdk_la_SOURCES = @LIBSYNTHESISSDK_HEADERS@
 if COND_STATIC
 libsynthesissdk_la_SOURCES += @LIBSYNTHESISSDK_SOURCES_SDK_ONLY@
@@ -128,6 +129,7 @@ libsynthesissdk_la_CPPFLAGS = \
 	-I$(srcdir)/syncml_tk/src/sml/mgr/inc/ 
 
 libsynthesisstubs_la_LDFLAGS = -static
+libsynthesisstubs_la_CXXFLAGS = $(libsynthesissdk_la_CXXFLAGS)
 libsynthesisstubs_la_SOURCES = sysync_SDK/Sources/enginestubs.c
 libsynthesisstubs_la_CPPFLAGS = $(libsynthesissdk_la_CPPFLAGS)
 
-- 
1.7.2.3

_______________________________________________
os-libsynthesis mailing list
os-libsynthesis@synthesis.ch
http://lists.synthesis.ch/mailman/listinfo/os-libsynthesis

Reply via email to