From: Jiahao XU <Jiahao_XU@outlook.com>
To: Fangrui Song <emacsray@gmail.com>
Cc: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: Re: [musl] Can’t build musl with lto=thin
Date: Mon, 1 Feb 2021 21:20:16 +0000 [thread overview]
Message-ID: <SYBP282MB0202D46911C4058C288E08B18AB69@SYBP282MB0202.AUSP282.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAN30aBE-+Wi2uSS+ayMvuEWpwRoBvLfEg3xjYxCP1OPwfkaQnw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2249 bytes --]
My hello.c:
#include <stdio.h>
int main()
{
puts(“Hello, world!”);
return 0;
}
And if I changed puts to printf and uses -fno-builtin, it also generates a 16KB executable.
Jiahao XU
________________________________
From: Fangrui Song <emacsray@gmail.com>
Sent: Tuesday, February 2, 2021 5:06:26 AM
To: Jiahao XU <Jiahao_XU@outlook.com>
Cc: musl@lists.openwall.com <musl@lists.openwall.com>
Subject: Re: [musl] Can’t build musl with lto=thin
On Mon, Feb 1, 2021 at 9:53 AM Rich Felker <dalias@libc.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.
[-- Attachment #2: Type: text/html, Size: 4339 bytes --]
next prev parent reply other threads:[~2021-02-01 21:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 12:19 Jiahao XU
2021-01-29 20:04 ` Szabolcs Nagy
2021-01-29 20:53 ` Fangrui Song
2021-01-30 20:12 ` Rich Felker
2021-01-30 20:59 ` Леонид Юрьев (Leonid Yuriev)
[not found] ` <SYBP282MB020277E08EB49C9AC9BF90888AB89@SYBP282MB0202.AUSP282.PROD.OUTLOOK.COM>
2021-01-30 23:30 ` Rich Felker
[not found] ` <SYBP282MB0202BF16DD08A2F1537FD5428AB89@SYBP282MB0202.AUSP282.PROD.OUTLOOK.COM>
2021-01-31 5:01 ` Rich Felker
2021-01-31 5:32 ` Jiahao XU
2021-01-31 21:01 ` Rich Felker
2021-01-31 22:29 ` Jiahao XU
2021-02-01 0:22 ` Jiahao XU
2021-02-01 0:31 ` Jiahao XU
2021-02-01 0:44 ` Jiahao XU
2021-02-01 0:50 ` Jiahao XU
2021-02-01 13:20 ` Jiahao XU
2021-02-01 16:55 ` Nick Bray
2021-02-01 17:53 ` Rich Felker
2021-02-01 18:06 ` Fangrui Song
2021-02-01 21:20 ` Jiahao XU [this message]
2021-02-13 17:54 ` Tim Tassonis
2021-02-14 5:59 ` Markus Wichmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SYBP282MB0202D46911C4058C288E08B18AB69@SYBP282MB0202.AUSP282.PROD.OUTLOOK.COM \
--to=jiahao_xu@outlook.com \
--cc=emacsray@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).