[cfe-dev] ThinLTO and removal of hidden visibility code
Teresa Johnson via cfe-dev
cfe-dev at lists.llvm.org
Wed Oct 21 08:53:33 PDT 2020
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
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
On Mon, Oct 19, 2020 at 6:49 AM Damjan Marion via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> 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?
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
Teresa Johnson | Software Engineer | tejohnson at google.com |
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev