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

Re: Linking a static library with -fPIC for flex



On Tue, Sep 05, 2006 at 04:50:24PM -0500, Manoj Srivastava wrote:
> 
>         Starting with version 2.5.31-18 of flex we have started
>  providing a static library compiled with position independent code,
>  namely, libfl_pic.a, in addition to the normal libfl.a library. This
>  is my mail, in accordance to §10.2 of the Debian policy.

>         The problem is with packages that contain shared libraries
>  with a flex scanner compiled in. Since flex generates code 
>  that is not self contained, and the missing symbols live in
>  libfl.a. However, since linking a shared library with a object
>  containing non position independent code stopped working with gcc 4.1
>  (apparently, it was sheer luck that it worked at all). So now we also
>  provide libfla_pic.a for shared library packages to link with.

>         I was initially going to just provide libfl.a with position
>  independent code, which would have prevented the FTBS breakage for
>  scanner containing shared libraries, at the expense of a register
>  lost for binaries that were otherwise statically linked, and perhaps
>  slower execution speeds. When I broached this on IRC, people
>  commented that I could provide libfl_pic.a in addition to libfl.a ,
>  but compile them both with -fPIC, and transition back at some later
>  point to having a non position independent static libfl.a

>         Then I realized I was falling into the trap of preferring
>  convenience to correctness; the right thing to identify and fix
>  packages building shared objects linked to non relocatable code. So,
>  now these packages can link to  libfl_pic.a, and binaries can
>  continue to link with  libfl.a.

> 	An alternative would have been to provide a full fledged
>  shared library,

The other alternative discussed on IRC was to make /usr/lib/libfl.so a
linker script, à la libc.so.  I think the below should be sufficient, giving
you PIC code when shared linking is requested by the linker and non-PIC code
when static linking is requested:


/* GNU ld script
   When shared linking is requested, map the request to the PIC static
   library, which is the closest we come to a shared library here. */
INPUT( /usr/lib/libfl_pic.a )


Untested, though; it may actually be better to use GROUP() instead of
INPUT(), I'm not sure if ld will treat the two commands the same for
reduction of unused symbols.

Cheers,
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
vorlon@debian.org                                   http://www.debian.org/



Reply to: