bug-libtool
[Top][All Lists]
Advanced

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

bug#27722: libtool makes it impossible to build a package statically


From: Bruno Haible
Subject: bug#27722: libtool makes it impossible to build a package statically
Date: Sun, 16 Jul 2017 00:42:58 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-83-generic; KDE/5.18.0; x86_64; ; )

Hi,

Summary
-------

The processing of the '-static' option by "libtool --mode=link" makes it
impossible to build a package in such a way that
  1) all libraries are static,
  2) all binaries are statically linked (ldd reports "not a dynamic 
executable").

Motivation
----------

There are many use-cases of statically linked binaries. In my case it's
because I want to run programs under qemu in "user mode", and for big-endian
CPUs currently only statically linked binaries work. [1]

Details
-------

In packages that don't create shared libraries and therefore don't use libtool,
the way to achieve statically linked binaries (assuming GCC) is simple:

  $ ./configure LDFLAGS="-static"

For packages that create *only* shared libraries, the GNU libtool manual
provides a solution [2][3]:

  $ ./configure --enable-static --disable-shared LDFLAGS="-all-static"

But this is not a general solution: Some packages, like GNU libffcall,
create shared libraries AND static libraries. But there is only 1 LDFLAGS
parameter that can be passed to 'configure'.

'configure' (thankfully!) does not take 2 different variables LDFLAGS
(for non-libtool linking) and LTLDFLAGS (for libtool linking), because
the use of libtool is an internal detail of a package, and the user who
wants to install it should not see added complexity because of libtool.

So,
1) $ ./configure --enable-static --disable-shared LDFLAGS="-static"
   does not work for producing statically linked binaries because libtool
   intercepts the 'static' option. The result (according to 'ldd') is
   a binary that is linked against the *shared* libc.
2) $ ./configure --enable-static --disable-shared LDFLAGS="-all-static"
   does not work because GCC does not understand a '-all-static' option.
3) The hint given in [4]
   $ ./configure --enable-static --disable-shared LDFLAGS="-Xcompiler -static"
   does not work because GCC does not understand a '-Xcompiler' option.

How to reproduce
----------------

$ wget https://haible.de/bruno/gnu/libiconv-20170715.tar.gz

1) $ tar xvfz libiconv-20170715.tar.gz
   $ cd libiconv-20170715
   $ ./configure --enable-static --disable-shared LDFLAGS="-static"
   $ make
   $ make install DESTDIR=/tmp/inst
   $ LC_ALL=C ldd /tmp/inst/usr/local/bin/iconv
           linux-vdso.so.1 =>  (0x00007fff1a74d000)
           libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fddde90b000)
           /lib64/ld-linux-x86-64.so.2 (0x00005580e2f6c000)

2) $ tar xvfz libiconv-20170715.tar.gz
   $ cd libiconv-20170715
   $ ./configure --enable-static --disable-shared LDFLAGS="-all-static"
   ...
   checking whether the C compiler works... no
   configure: error: in `/tmp/libiconv-20170715':
   configure: error: C compiler cannot create executables
   See `config.log' for more details

3) $ tar xvfz libiconv-20170715.tar.gz
   $ cd libiconv-20170715
   $ ./configure --enable-static --disable-shared LDFLAGS="-Xcompiler -static"
   ...
   checking whether the C compiler works... no
   configure: error: in `/tmp/libiconv-20170715':
   configure: error: C compiler cannot create executables
   See `config.log' for more details

Past reports
------------

In 2004, this was discussed here: [5] already gave the solution, namely to
rename libtool's options. [6] gives the rationale.

For the specific case of GNU binutils, it was reported in 2011: [7][8]

Reported again in 2012: [9][10]

My workaround
-------------

I work around it with the solution from [5]. Instead of '-lt-static'
I chose '-static-uninstalled-libs', in order to reduce the confusion
with the existing option '-static-libtool-libs'.

Patch attached. It touches only the *link* mode of libtool. I don't
see a reason for touching the *compile* mode of libtool, since the
right place for the '-static' option is LDFLAGS, not CFLAGS. [11]

With this patch, it works as expected:

   $ tar xvfz libiconv-20170715.tar.gz
   $ cd libiconv-20170715
   $ patch -p1 < /tmp/libtool-allow-static.diff
   $ ./configure --enable-static --disable-shared LDFLAGS="-static"
   $ make
   $ make install DESTDIR=/tmp/inst
   $ LC_ALL=C ldd /tmp/inst/usr/local/bin/iconv
           not a dynamic executable


Best regards,

         Bruno


[1] https://bugs.launchpad.net/qemu/+bug/1701798
[2] https://www.gnu.org/software/libtool/manual/html_node/LT_005fINIT.html
[3] 
https://www.sourceware.org/autobook/autobook/autobook_59.html#Linking-against-Libtool-Libraries-with-Automake
[4] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=11064
[5] https://lists.gnu.org/archive/html/libtool/2004-11/msg00017.html
[6] https://lists.gnu.org/archive/html/libtool/2004-11/msg00024.html
[7] https://sourceware.org/ml/binutils/2011-08/msg00159.html
[8] https://sourceware.org/bugzilla/show_bug.cgi?id=13891
[9] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=11064
[10] https://lists.gnu.org/archive/html/bug-libtool/2012-03/msg00011.html
[11] 
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Preset-Output-Variables.html

Attachment: libtool-allow-static.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]