Building: Build Unix static libraries one object file at a time
authorRichard Levitte <levitte@openssl.org>
Sun, 23 Aug 2020 16:33:57 +0000 (18:33 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 7 Sep 2020 07:23:49 +0000 (09:23 +0200)
We're hitting problems that the 'ar' command line becomes too long for
some 'make' versions, or the shell it uses.

We therefore change the way we create a static library by doing so one
object file at a time.  This is slower, but has better guarantees to
work properly on limited systems.

Fixes #12116

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/12706)

Configurations/00-base-templates.conf
Configurations/unix-Makefile.tmpl

index 821a211cc873b824e066f4d92f1a07f90914c0b0..340e7893264ed6b59ebf406fcf83d1e4313e9d8a 100644 (file)
@@ -66,7 +66,7 @@ my %targets=(
         template        => 1,
 
         AR              => "ar",
-        ARFLAGS         => "r",
+        ARFLAGS         => "qc",
         CC              => "cc",
         lflags          =>
             sub { $withargs{zlib_lib} ? "-L".$withargs{zlib_lib} : () },
index ff4803be747d570bf396b640ae1b2d7288aca71f..ff37aa0290219a184f710f54aa3ab2087d244f2f 100644 (file)
@@ -1508,11 +1508,16 @@ EOF
       my %args = @_;
       my $lib = platform->staticlib($args{lib});
       my @objs = map { platform->obj($_) } @{$args{objs}};
-      my $objs = join(" \\\n" . ' ' x (length($lib) + 2),
+      my $deps = join(" \\\n" . ' ' x (length($lib) + 2),
                       fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
+      my $max_per_call = 250;
+      my @objs_grouped;
+      push @objs_grouped, join(" ", splice @objs, 0, $max_per_call) while @objs;
+      my $fill_lib =
+          join("\n\t", (map { "\$(AR) \$(ARFLAGS) $lib $_" } @objs_grouped));
       return <<"EOF";
-$lib: $objs
-       \$(AR) \$(ARFLAGS) \$\@ \$\?
+$lib: $deps
+       $fill_lib
        \$(RANLIB) \$\@ || echo Never mind.
 EOF
   }