Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: [PATCH] Give --gc-sections to the linker

Re: [PATCH] Give --gc-sections to the linker

From: Boris Gjenero <boris.gjenero_at_gmail.com>
Date: Sun, 04 Dec 2011 18:08:30 -0500

On 04/12/11 02:11 PM, Rafaël Carré wrote:
> For function removal I had this testcase:
>
> % cat Makefile
> CFLAGS += -O3 -Wl,--gc-sections
>
> OBJS=a.o b.o
>
> all: a.out
> objdump -d -j .rodata $<
> # You should only see DCBA == 44 43 42 41
> # 41 42 43 44 is not used and should be removed
>
> a.out: $(OBJS)
> $(CC) $(CFLAGS) $(OBJS) -o $@
> % cat a.c
> void f(void) { puts("DCBA"); }
> int main() {f();}
> % cat b.c
> __attribute__((weak)) void f(void)
> {
> puts("ABCD");
> }
> %

Your test case removes "ABCD" because there is nothing else in the same
section in b.o. If there was something else (for example due to another
function in b.c that's like f() but actually used by main()), then
"ABCD" remains.

I don't know how to remove "ABCD" via --gc-sections. If I use
-ffunction-sections -fdata-sections -Wl,--gc-sections, it's still there.
Strings go to .rodata.str1.1 in Linux and .rodata.str1.4 on the 5G iPod.
They don't get split up. Does anyone know how to split them up?

If I use -flto (link-time optimization), then "ABCD" is indeed gone.
With -flto, you don't need any other switches to remove "ABCD". I've
already been able to produce a working Archos Recorder V2 binary with
link-time optimization, saving over 7k. However, I'm not really
interested in trying to convince other developers that it should be
used. Switching toolchains can lead to problems, -flto could make
debugging much harder, and there's a *big* increase in link time.

> I can see some linker scripts have something like that already:
> KEEP(*(.vectors));// otherwise there are no references to it and the linker strip it

Yes. For example, the firmware/target/sh/archos/app.lds has it, and so
-Wl,--gc-sections can be used without problems on Archos hwcodec targets.

> Btw the reason for the lcd_blit_yuv() commit was to avoid some #ifdef
> hell (to remove the default C function from the sources when there is
> an optimized version)

I wonder if you could use a #define in lcd-target.h. For example there
are generic copy_read_sectors() and copy_write_sectors() functions in
firmware/drivers/ata.c. A target can supply its own functions and
prevent the generic functions from being compiled by defining
ATA_OPTIMIZED_READING and/or ATA_OPTIMIZED_WRITING in its own ata-target.h.

Regards,

Boris
Received on 2011-12-05


Page was last modified "Jan 10 2012" The Rockbox Crew
aaa