[PATCH v3] elf: Cache full internal symbol table for relocatable input

H.J. Lu hjl.tools@gmail.com
Fri Oct 17 22:23:46 GMT 2025


On Fri, Oct 17, 2025 at 8:48 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 11.10.2025 08:37, H.J. Lu wrote:
> > On Sat, Oct 11, 2025 at 9:08 AM Sam James <sam@gentoo.org> wrote:
> >>
> >> "H.J. Lu" <hjl.tools@gmail.com> writes:
> >>
> >>> Add bfd_elf_get_elf_syms_cached to cache internal symbol table for
> >>> relocatable input and use the internal symbol table cache for both local
> >>> and global symbols to avoid swapping in the same symbol table repeatedly
> >>> for --gc-sections.  This improves linker --gc-sections speed by ~2x for
> >>> PR ld/33530.
> >>>
> >>> elf_link_input_bfd is updated to not to pass preallocated buffers to
> >>> bfd_elf_get_elf_syms_cache.
> >>
> >> All tests pass now for me, including:
> >>
> >>                 === libctf Summary ===
> >>
> >> # of expected passes            39
> >> # of unsupported tests          1
> >>
> >> I'll test it more in the wild tonight and tomorrow.
> >
> > Here is the v2 patch to keep bfd_elf_get_elf_syms interface unchanged.
>
> What I can't spot are provisions towards systems with little memory available,
> like possibly 32-bit ones. (I'm sure you're aware of ld's --no-keep-memory
> option.)
>
> In the 2nd hunk altering the body of what was bfd_elf_get_elf_syms(), may I
> ask that in the body of the outermost if() you use an if/else-if/else chain,
> to reduce indentation some?

The only indentation change is

-  if (intsym_buf == NULL)
+  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
     {
-      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
-  {
-    bfd_set_error (bfd_error_file_too_big);
-    goto out1;
-  }
-      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
-      intsym_buf = alloc_intsym;
-      if (intsym_buf == NULL)
-  goto out1;
+      bfd_set_error (bfd_error_file_too_big);
+      goto out1;
+    }
+  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
+  if (alloc_intsym == NULL)
+    {
+      intsym_buf = NULL;
+      goto out1;
     }

Since we always allocate a full symbol table buffer even if intsym_buf != NULL,
I don't see how I can avoid it.

> The patch also could do with splitting up some. At the first glance it looks
> as if e.g. the reloc-cookie related changes could as well be a separate,
> follow-on change.

The reloc-cookie related changes aren't needed anymore.

Here is the v3 patch.

Thanks.


-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v3-0001-elf-Cache-full-internal-symbol-table-for-relocata.patch
Type: text/x-patch
Size: 28831 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20251018/ae49a012/attachment-0001.bin>


More information about the Binutils mailing list