Date: Mon, 1 Feb 2021 10:06:26 -0800 From: Fangrui Song <emacsray@...il.com> To: Jiahao XU <Jiahao_XU@...look.com> Cc: musl@...ts.openwall.com Subject: Re: Can’t build musl with lto=thin On Mon, Feb 1, 2021 at 9:53 AM Rich Felker <dalias@...c.org> wrote: > > On Mon, Feb 01, 2021 at 12:31:47AM +0000, Jiahao XU wrote: > > Interesting enough, I found —gc-section used along with -flto can cut the size of final hello_world executable from 48KB to 5KB. > > > > After investigating with bloaty, I found that —gc-section along with -flto is able to cut .text from 25.4 KiB to 3.04 KiB, and cut the .rodata from 19.5 KiB to 120 bytes. > > ..data section however, seen an increase from 316 bytes to 372 bytes, but the VM size is cut from 252 to 244 bytes. > > > > > > $ bloaty gc-section-a.out -- no-gc-section.a.out > > > > FILE SIZE VM SIZE > > > > -------------- -------------- > > > > +18% +56 -3.2% -8 .data > > > > [NEW] +6 [NEW] +6 [LOAD #2 [RX]] > > > > [DEL] -4 -66.7% -8 [LOAD #4 [RW]] > > > > -72.7% -8 [ = ] 0 [Unmapped] > > > > -32.0% -64 [ = ] 0 .comment > > > > -99.4% -19.4Ki -99.7% -19.4Ki .rodata > > > > -88.0% -22.3Ki -88.2% -22.3Ki .text > > > > -89.4% -41.8Ki -88.5% -41.8Ki TOTAL > > What is included in your hello world? Mine, static linked normally (no > LTO) is around 4k of text and virtually no rodata. (This is with GCC; > I'm not using clang.) If I compile with -fno-builtin so printf doesn't > get transformed to puts, there's about 16k of text and 3k of rodata, > but still nowhere near the ~20k you saw. > > Rich In LLD and LLVMgold.so's LTO configuration, -ffunction-sections & -fdata-sections are automatically enabled. Without them --gc-sections is not useful. -ffunction-sections & -fdata-sections are code generation options and not encoded in bitcode files.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.