Subject: bug#20632: Huge targets lead to E2BIG errors

From: "Daniel Richard G." <[email-masked]>
Date: Fri, 22 May 2015 16:42:24 -0400

Hello Libtool peoples,

I am using the current version of Libtool (2.4.6) for a large, Automake-
based project. At one point, it builds a gigantic static archive library
from well over a thousand object files. On an older AIX system, the link
command fails with

    $ gmake
    /opt/freeware/bin/bash ../../libtool  --tag=CC   --mode=link gcc
      -pipe -fno-common -W -Wall -mcpu=powerpc -O3 -ansi -avoid-version
      -Wl,-bbigtoc -o libfoo.la -rpath /path/to/lib foo.lo bar.lo ...
    /tmp/gmake-e2big.2kpTia: /opt/freeware/bin/bash: The parameter or
      environment lists are too long.
    Makefile:16591: recipe for target 'libfoo.la' failed
    make: *** [libfoo.la] Error 126

This is using a patched version of GNU Make that works around its own
limitations with very long commands, detailed here:

    https://savannah.gnu.org/bugs/index.php?44853

So the Make program is not at issue here; the "libtool --mode=link"
invocation itself is so long that the shell interpreter can't handle it.

Libtool does have an -objectlist argument that seems useful for cases
like this, and indeed with an appropriate edit to the Automake/Libtool-
generated rule, the link works:

     libfoo.la: $(libfoo_la_OBJECTS) $(libfoo_la_DEPENDENCIES) $(EXTRA_libfoo_la_DEPENDENCIES) 
    -        $(AM_V_CCLD)$(libfoo_la_LINK) -rpath $(libdir) $(libfoo_la_OBJECTS) $(libfoo_la_LIBADD) $(LIBS)
    +        for obj in $(libfoo_la_OBJECTS); do echo $$obj; done >$@.list
    +        $(AM_V_CCLD)$(libfoo_la_LINK) -rpath $(libdir) -objectlist $@.list $(libfoo_la_LIBADD) $(LIBS)

Automake/Libtool itself should generate a rule of this form
automatically if a target's list of dependent objects is large, or else
the rule is completely unusable on a system with command-length
limitations.

--Daniel

-- 
Daniel Richard G. || [email-masked]
My ASCII-art .sig got a bad case of Times New Roman.