Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 13 Feb 2021 18:54:24 +0100
From: Tim Tassonis <stuff@...entral.ch>
To: musl@...ts.openwall.com
Subject: Re: Can’t build musl with lto=thin



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@...da0:~$ cat hello.c
#include <stdio.h>

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

timtas@...da0:~$ musl-gcc -fno-builtin -c hello.c -o hello.o
timtas@...da0:~$ musl-gcc -fno-builtin -o hello hello.o
timtas@...da0:~$ 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@...il.com>
> *Sent:* Tuesday, February 2, 2021 5:06:26 AM
> *To:* Jiahao XU <Jiahao_XU@...look.com>
> *Cc:* musl@...ts.openwall.com <musl@...ts.openwall.com>
> *Subject:* Re: [musl] 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.

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

stuff@...entral.ch
+41 79 229 36 17

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.