diff mbox series

Honor DEAD_CODE_ELIMINATION flag

Message ID 20200227171447.1793041-1-maurosr@linux.vnet.ibm.com
State Accepted
Headers show
Series Honor DEAD_CODE_ELIMINATION flag | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (82aed17a5468aff6b600ee1694a10a60f942c018)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Mauro S. M. Rodrigues Feb. 27, 2020, 5:14 p.m. UTC
While trying to reduce the size of the final binary I found
DEAD_CODE_ELIMINATION=1 but it didn't change the binary size and
known ununsed functions were seen when inspecting the elf with nm.

Even though the necessary parameters for compiler, -ffunction-sections
and -fdata-sections, are set, ld's --gc-sections wasn't, so add it in
order to honor the flag.

Signed-off-by: Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>
---
 Makefile.main | 1 +
 1 file changed, 1 insertion(+)

Comments

Nicholas Piggin Feb. 28, 2020, 2 a.m. UTC | #1
Mauro S. M. Rodrigues's on February 28, 2020 3:14 am:
> While trying to reduce the size of the final binary I found
> DEAD_CODE_ELIMINATION=1 but it didn't change the binary size and
> known ununsed functions were seen when inspecting the elf with nm.
> 
> Even though the necessary parameters for compiler, -ffunction-sections
> and -fdata-sections, are set, ld's --gc-sections wasn't, so add it in
> order to honor the flag.
> 
> Signed-off-by: Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>
> ---
>  Makefile.main | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Makefile.main b/Makefile.main
> index 7ff2d21be..52251aa7e 100644
> --- a/Makefile.main
> +++ b/Makefile.main
> @@ -171,6 +171,7 @@ endif
>  
>  ifeq ($(DEAD_CODE_ELIMINATION),1)
>  LDFLAGS += -Wl,--gc-sections
> +LDFLAGS_FINAL += --gc-sections
>  endif
>  
>  AFLAGS := -D__ASSEMBLY__ -m64

Obviously required, I got the same thing lying around.

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>

Did you get much savings? It wasn't a great deal when I last tried.

Thanks,
Nick
Mauro S. M. Rodrigues Feb. 28, 2020, 2:54 p.m. UTC | #2
On Fri, Feb 28, 2020 at 12:00:44PM +1000, Nicholas Piggin wrote:
> 
> Obviously required, I got the same thing lying around.
> 
> Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
> 
> Did you get much savings? It wasn't a great deal when I last tried.
> 

Thanks for your review Nick!

In my last test I was able to save 55KiB out of 479KiB, so ~11%. But
please bear in mind that this was achieved testing on top of some TSS
changes we're developing - including mbedtls and ibmtpm20tss libraries
as subtrees.

Testing at v6.0.21 it is indeed irrelevant, I was able to save just
1KiB.

Thanks,
Mauro

> Thanks,
> Nick
Nicholas Piggin Feb. 29, 2020, 9:51 a.m. UTC | #3
Mauro Rodrigues's on February 29, 2020 12:54 am:
> On Fri, Feb 28, 2020 at 12:00:44PM +1000, Nicholas Piggin wrote:
>> 
>> Obviously required, I got the same thing lying around.
>> 
>> Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
>> 
>> Did you get much savings? It wasn't a great deal when I last tried.
>> 
> 
> Thanks for your review Nick!
> 
> In my last test I was able to save 55KiB out of 479KiB, so ~11%. But
> please bear in mind that this was achieved testing on top of some TSS
> changes we're developing - including mbedtls and ibmtpm20tss libraries
> as subtrees.
> 
> Testing at v6.0.21 it is indeed irrelevant, I was able to save just
> 1KiB.

Re-tested with upstream plus your patch

   text	   data	    bss	    dec	 filename
1486029	 259992	  48552	1794573	 skiboot.elf
1409501	 270736	  40080	1720317	 skiboot.elf.dce    ( -4.1%)
1302629	 246784	  48552	1597965	 skiboot.elf.le     ( -9.6%)
1243629	 239928	  40080	1523637	 skiboot.elf.le.dce (-15.1%)

Not too bad with LE :)

Interesting how the data section gets a bit larger with DCE with BE, I
didn't look why that is.

Thanks,
Nick
Oliver O'Halloran June 5, 2020, 7:03 a.m. UTC | #4
On Fri, Feb 28, 2020 at 4:15 AM Mauro S. M. Rodrigues
<maurosr@linux.vnet.ibm.com> wrote:
>
> While trying to reduce the size of the final binary I found
> DEAD_CODE_ELIMINATION=1 but it didn't change the binary size and
> known ununsed functions were seen when inspecting the elf with nm.
>
> Even though the necessary parameters for compiler, -ffunction-sections
> and -fdata-sections, are set, ld's --gc-sections wasn't, so add it in
> order to honor the flag.
>
> Signed-off-by: Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>

Thanks, merged as 22817f8d563a069fa9be5202095fd88ddadb21f6
diff mbox series

Patch

diff --git a/Makefile.main b/Makefile.main
index 7ff2d21be..52251aa7e 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -171,6 +171,7 @@  endif
 
 ifeq ($(DEAD_CODE_ELIMINATION),1)
 LDFLAGS += -Wl,--gc-sections
+LDFLAGS_FINAL += --gc-sections
 endif
 
 AFLAGS := -D__ASSEMBLY__ -m64