[PATCH 1/2] Gold: Skip zero-sized sections for ICF

H.J. Lu hjl.tools@gmail.com
Mon Oct 12 01:56:10 GMT 2020


On Sun, Oct 11, 2020 at 5:02 PM Fangrui Song <i@maskray.me> wrote:
>
> On 2020-10-11, H.J. Lu via Binutils wrote:
> >Skip zero-sized sections since there is no need to do ICF on them.
> >
> >       * icf.cc (Icf::find_identical_sections): Skip zero-sized sections.
> >---
> > gold/icf.cc | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> >diff --git a/gold/icf.cc b/gold/icf.cc
> >index a60db7abc8d..54af4126696 100644
> >--- a/gold/icf.cc
> >+++ b/gold/icf.cc
> >@@ -973,6 +973,8 @@ Icf::find_identical_sections(const Input_objects* input_objects,
> >
> >       for (unsigned int i = 0; i < (*p)->shnum(); ++i)
> >         {
> >+          if ((*p)->section_size(i) == 0)
> >+            continue;
> >         const std::string section_name = (*p)->section_name(i);
> >           if (!is_section_foldable_candidate(section_name))
> >           {
> >--
> >2.26.2
> >
>
> Does anything break without the special case? ld.lld --icf={all,safe} does not
> special case st_size=0
>
>
> .section .text.1,"ax"; .globl foo; foo:
> .section .text.2,"ax"; .globl bar; bar:
>
> % ld.lld a.o --icf=all --print-icf-sections
> selected section a.o:(.text)
>    removing identical section a.o:(.text.1)
>    removing identical section a.o:(.text.2)
> ld.lld: warning: cannot find entry symbol _start; defaulting to 0x201158

The zero-sized input functions should have no impact on output,
ICF or not.

-- 
H.J.


More information about the Binutils mailing list