RFC: LD: Changing the size of the delta used when growing merge offset maps

H.J. Lu hjl.tools@gmail.com
Mon Mar 16 16:44:17 GMT 2026


On Mon, Mar 16, 2026 at 9:37 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi Guys,
>
>   Running the linker under sysprof shows that the append_offsetmap()
>   function in merge.c is responsible for a large amount of the memory
>   allocated during a link, and a lot of those allocations are calls to
>   bfd_realloc().  Since reallocating memory takes time, and represents
>   an inefficiency it seems to me that we can do better than having a
>   fixed delta for increasing the size of the offset maps.
>
>   So I am proposing the attached patch.  It creates a new static
>   variable called map_delta which is used for the array increments.  The
>   value of map_delta is selected based upon whether
>   --reduce-memory-overheads or -O have been specified on the command
>   line.  (I am not sure about the use of the -O flag here, but I could
>   not find a more relevant flag to indicate 'this is a big link').
>
>   The results are underwhelming, but still do still make a small amount
>   of difference.  For example linking LLVM's ld.llc executable on my
>   machine uses 7,121,480 Kb of memory by default and takes around 14.97
>   seconds.  But with the patch applied and adding -O to the link command
>   line this changes to 7,120,196 Kb and 14.89 seconds.  Not a lot I know

Is bfd_realloc really the bottleneck? If yes, why are the execution times almost
the same? It looks like that the memory usage doesn't change much.  If we can't
improve both execution time and memory usage at the same time, shouldn't we
focus on one of them?

>   but maybe a step in the right direction.
>
>   Thoughts / comments ?
>
> Cheers
>   Nick
>


-- 
H.J.


More information about the Binutils mailing list