mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Tim Tassonis <stuff@decentral.ch>
To: musl@lists.openwall.com
Subject: Re: [musl] Can’t build musl with lto=thin
Date: Sat, 13 Feb 2021 18:54:24 +0100	[thread overview]
Message-ID: <65ed0ffa-fd55-da6f-fa34-001939ed36ce@decentral.ch> (raw)
In-Reply-To: <SYBP282MB0202D46911C4058C288E08B18AB69@SYBP282MB0202.AUSP282.PROD.OUTLOOK.COM>



On 2/1/21 10:20 PM, Jiahao XU wrote:
> 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.

Strange, I get 19k without -fno-builtin and 28K with it:

timtas@lfsda0:~$ cat hello.c
#include <stdio.h>

int main(int arc, char **argv)
{
	printf("Hello World!\n");
	return 0;
}
timtas@lfsda0:~$ musl-gcc -c hello.c -o hello.o
timtas@lfsda0:~$ musl-gcc  -o hello hello.o
timtas@lfsda0:~$ ls -lh hello
-rwxr-xr-x 1 timtas timtas 19K Feb 13 18:49 hello

timtas@lfsda0:~$ musl-gcc -fno-builtin -c hello.c -o hello.o
timtas@lfsda0:~$ musl-gcc -fno-builtin -o hello hello.o
timtas@lfsda0:~$ ls -lh hello
-rwxr-xr-x 1 timtas timtas 28K Feb 13 18:50 hello


This is musl 1.2.1 with gcc 10.2.0

Bye
Tim




> 
> 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.

-- 
decentral.ch - IT Stuff
Tim Tassonis
Hohlstrasse 400
c/o Baubüro Insitu
8048 Zürich

stuff@decentral.ch
+41 79 229 36 17

  reply	other threads:[~2021-02-13 17:54 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
2021-02-13 17:54                         ` Tim Tassonis [this message]
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=65ed0ffa-fd55-da6f-fa34-001939ed36ce@decentral.ch \
    --to=stuff@decentral.ch \
    --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).