[PATCH] Cygwin: Speed up mkimport
Jon Turney
jon.turney@dronecode.org.uk
Wed Dec 16 14:29:49 GMT 2020
On 26/11/2020 09:56, Mark Geisert wrote:
> Cut mkimport elapsed time in half by forking each iteration of the two
> time-consuming loops within. Only do this if more than one CPU is
> present. In the second loop, combine the two 'objdump' calls into one
> system() invocation to avoid a system() invocation per iteration.
Nice. Thanks for looking into this.
> @@ -86,8 +94,18 @@ for my $f (keys %text) {
> if (!$text{$f}) {
> unlink $f;
> } else {
> - system $objcopy, '-R', '.text', $f and exit 1;
> - system $objcopy, '-R', '.bss', '-R', '.data', "t-$f" and exit 1;
> + if ($forking && fork) {
> + # Testing shows parent does need to sleep a short time here,
> + # otherwise system is inundated with hundreds of objcopy processes
> + # and the forked perl processes that launched them.
> + my $delay = 0.01; # NOTE: Slower systems may need to raise this
> + select(undef, undef, undef, $delay); # Supports fractional seconds
> + } else {
> + # Do two objcopy calls at once to avoid one system() call overhead
> + system '(', $objcopy, '-R', '.text', $f, ')', '||',
> + $objcopy, '-R', '.bss', '-R', '.data', "t-$f" and exit 1;
> + exit 0 if $forking;
> + }
> }
> }
>
Hmm... not so sure about this. This seems racy, as nothing ensures that
these objcopies have finished before we combine all the produced .o
files into a library.
I'm pretty sure with more understanding, this whole thing could be done
better: For example, from a brief look, it seems that the t-*.o files
are produced by gas, and then we remove .bss and .data sections. Could
we not arrange to assemble these objects without those sections in the
first place?
More information about the Cygwin-patches
mailing list