[cfe-dev] ThinLTO and removal of hidden visibility code

Damjan Marion via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 22 05:01:02 PDT 2020


Hi Teresa,

Thank you for detailed explanation.

I come to gc-sections solution before, but I was not sure what are the implications of using it.

Thanks,

Damjan

> On 21.10.2020., at 17:53, Teresa Johnson <tejohnson at google.com> wrote:
> 
> Hi Damjan,
> 
> Try building with function/data sections and linker gc enabled. I.e. "-ffunction-sections -fdata-sections -Wl,--gc-sections". If that doesn't help, then please post a test case.
> 
> If those hidden symbols were only referenced within the same translation unit aka module, then there shouldn't be a difference between full and thin LTO (the linker will tell the post-link compilation in both cases that there are no references outside the module and it could then be internalized and removed as long as all references in the module were inlined.
> 
> Assuming there are cross-module references initially:
> 
> With full LTO all objects are compiled post link in a monolithic blob, which means that if all references to a hidden symbol are inlined, it knows that there can be no additional references and the symbol can be removed.
> 
> With ThinLTO, each object is still compiled post link independently, while ThinLTO enables cross-module importing and inlining the defining module does not know whether those inlines were successful and therefore whether any cross-module references remain, so it needs to leave the outlined definition in place. If you enable function sections and linker GC, then the linker, when it links together the final native objects produced by the ThinLTO post-link compilations into the final native .so, can remove the symbols that were fully inlined across modules and no longer have any references.
> 
> Teresa
> 
> On Mon, Oct 19, 2020 at 6:49 AM Damjan Marion via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi,
> 
> I noticed that only when I use -flto=full functions which have hidden visibility are removed
> from code when I link it into .so file.
> 
> Is this expected behaviour? Is there a way to achieve same with —flto=thin?
> 
> Thanks
> 
>> Damjan
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> 
> 
> -- 
> Teresa Johnson |	 Software Engineer |	 tejohnson at google.com |	



More information about the cfe-dev mailing list