[U-Boot] [PATCH] Enable garbage collection of unused input sections.

Hi ML,
This patch has been moved out from the previous "[PATCH 0/6 v2] Support for Bootstrap Code" patchset.
The change adds the support of linker sections garbage collector that allows to isolate and discard the unused functions. The patch has been tested (compilation and run) on the qemu_mips board (and an another real proprietary mips board) and on P4080DS target (just the compilation). The change seems to be safe because only dead code has been discarded during my tests. Of course, better test should be performed on all archs/boards to be sure that no any side-effect will be shown.
For the testing I used the following toolchains from CodeSourcery:
for MIPS:
mips-linux-gnu-gcc (Sourcery G++ Lite 4.4-203) 4.4.1 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOS
GNU ld (Sourcery G++ Lite 4.4-203) 2.19.51.20090709 Copyright 2008 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
for PowerPC:
powerpc-linux-gnu-gcc (Sourcery G++ Lite 4.4-194) 4.4.1 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GNU ld (Sourcery G++ Lite 4.4-194) 2.19.51.20090709 Copyright 2008 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
*Test results (adding also --print-gc-sections option to the linker command line)*
QEMU MIPS board.
u-boot.bin size reduced from 191672 bytes to 177240 bytes.
Discarded code on MIPS (qemu_mips):
mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'arch/mips/cpu/start.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'arch/mips/cpu/start.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.flush_dcache_range' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.invalidate_dcache_range' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.write_one_tlb' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.cpu_eth_init' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'arch/mips/cpu/libmips.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'arch/mips/lib/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.set_timer' in file 'arch/mips/lib/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.get_ticks' in file 'arch/mips/lib/libmips.o' mips-linux-gnu-ld: Removing unused section '.text.get_tbclk' in file 'arch/mips/lib/libmips.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'arch/mips/lib/libmips.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.disable_ctrlc' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.dbg' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.serial_printf' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.malloc_usable_size' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.mallopt' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.cfree' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.memalign' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.pvalloc' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.valloc' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.simple_itoa' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.unset_local_var' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.get_table_entry_id' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.genimg_get_comp_id' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.genimg_get_type_id' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.genimg_get_arch_id' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.genimg_get_os_id' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.getenv_bootm_low' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.getenv_bootm_size' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.parse_line' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.run_command' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.get_ram_size' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.hex2_bin' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.srec_decode' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.parse_num' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_error' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_stream_close' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.CYGACC_COMM_IF_PUTC' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.CYGACC_COMM_IF_GETC_TIMEOUT' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_stream_terminate' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_get_hdr' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_stream_read' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.text.xyzModem_stream_open' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.rodata.srec_decode' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.rodata.xyzModem_error' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.data.mmap_threshold' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.bss.n_mmaps_max' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.bss.local.3309' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.bss.xyz' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'common/libcommon.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'disk/libdisk.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'disk/libdisk.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'drivers/mtd/libmtd.o' mips-linux-gnu-ld: Removing unused section '.text.flash_sector_size' in file 'drivers/mtd/libmtd.o' mips-linux-gnu-ld: Removing unused section '.text.flash_set_verbose' in file 'drivers/mtd/libmtd.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'drivers/mtd/libmtd.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'drivers/net/libnet.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'drivers/net/libnet.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'drivers/pcmcia/libpcmcia.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'drivers/rtc/librtc.o' mips-linux-gnu-ld: Removing unused section '.text.mktime' in file 'drivers/rtc/librtc.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'drivers/rtc/librtc.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'drivers/serial/libserial.o' mips-linux-gnu-ld: Removing unused section '.text._serial_putc_raw' in file 'drivers/serial/libserial.o' mips-linux-gnu-ld: Removing unused section '.text.serial_putc_raw' in file 'drivers/serial/libserial.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'drivers/serial/libserial.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'fs/ext2/libext2fs.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'fs/ext2/libext2fs.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.text.file_getfsname' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.text.file_read' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.text.file_ls' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.text.file_detectfs' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.text.file_cd' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.data.file_cwd' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.data.current_filesystem' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.data.rel.ro.filesystems' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'fs/fat/libfat.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.cyg_crc16' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.display_options' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.hdestroy' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.hcreate' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.ldiv' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strrchr' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strspn' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strpbrk' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strtok' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strsep' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strswab' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.bcopy' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.memscan' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strstr' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.memchr' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.strmhz' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.ustrtoul' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.simple_strtoull' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.panic' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.text.inflateInit_' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.rodata.crc16_tab' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.data.rel.ro.local.z_errmsg' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'lib/libgeneric.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'lib/lzma/liblzma.o' mips-linux-gnu-ld: Removing unused section '.text.LzmaDec_Free' in file 'lib/lzma/liblzma.o' mips-linux-gnu-ld: Removing unused section '.text.LzmaDec_Allocate' in file 'lib/lzma/liblzma.o' mips-linux-gnu-ld: Removing unused section '.text.LzmaDec_DecodeToBuf' in file 'lib/lzma/liblzma.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'lib/lzma/liblzma.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.text.eth_setenv_enetaddr' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.text.eth_getenv_enetaddr_by_index' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.text.VLAN_to_string' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.text.random_port' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.data.TftpRRQTimeoutMSecs' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'net/libnet.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file 'board/qemu-mips/libqemu-mips.o' mips-linux-gnu-ld: Removing unused section '.pdr' in file 'board/qemu-mips/libqemu-mips.o' mips-linux-gnu-ld: Removing unused section '.reginfo' in file '../lib/gcc/mips-linux-gnu/4.4.1/soft-float/libgcc.a(_lshrdi3.o)' mips-linux-gnu-ld: Removing unused section '.pdr' in file '../lib/gcc/mips-linux-gnu/4.4.1/soft-float/libgcc.a(_lshrdi3.o)' mips-linux-gnu-ld: Removing unused section '.reginfo' in file '../lib/gcc/mips-linux-gnu/4.4.1/soft-float/libgcc.a(_ashldi3.o)' mips-linux-gnu-ld: Removing unused section '.pdr' in file '../lib/gcc/mips-linux-gnu/4.4.1/soft-float/libgcc.a(_ashldi3.o)'
P4080DS
u-boot.bin size unchanged because the code has an entry point int the last 4k and the rest of code is aligned to the last 512K...
Discarded code on P4080DS:
powerpc-linux-gnu-ld: Removing unused section '.text.mpc85xx_reginfo' in file 'arch/powerpc/cpu/mpc85xx/libmpc85xx.o' powerpc-linux-gnu-ld: Removing unused section '.text.print_tlbcam' in file 'arch/powerpc/cpu/mpc85xx/libmpc85xx.o' powerpc-linux-gnu-ld: Removing unused section '.text.addr_probe' in file 'arch/powerpc/cpu/mpc85xx/libmpc85xx.o' powerpc-linux-gnu-ld: Removing unused section '.text.PITException' in file 'arch/powerpc/cpu/mpc85xx/libmpc85xx.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_fixup_phy_connection' in file 'arch/powerpc/cpu/mpc8xxx/lib8xxx.o' powerpc-linux-gnu-ld: Removing unused section '.text.print_lbc_regs' in file 'arch/powerpc/cpu/mpc8xxx/lib8xxx.o' powerpc-linux-gnu-ld: Removing unused section '.text.upmconfig' in file 'arch/powerpc/cpu/mpc8xxx/lib8xxx.o' powerpc-linux-gnu-ld: Removing unused section '.text.__board_add_ram_info' in file 'arch/powerpc/lib/libpowerpc.o' powerpc-linux-gnu-ld: Removing unused section '.text.ticks2usec' in file 'arch/powerpc/lib/libpowerpc.o' powerpc-linux-gnu-ld: Removing unused section '.sdata.ex_tab_message' in file 'arch/powerpc/lib/libpowerpc.o' powerpc-linux-gnu-ld: Removing unused section '.text.get_board_ddr_clk' in file 'board/freescale/common/libfreescale.o' powerpc-linux-gnu-ld: Removing unused section '.text.__arch_preboot_os' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.__def_i2c_get_bus_speed' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.__def_i2c_set_bus_speed' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.disable_ctrlc' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.dbg' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.fprintf' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.serial_printf' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.spd_check' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.ddr2_spd_check' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.ddr1_spd_check' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.malloc_usable_size' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.mallopt' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.cfree' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.memalign' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.pvalloc' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.valloc' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_increase_size' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_add_edid' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.do_fixup_by_path_u32' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.simple_itoa' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.unset_local_var' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.hwconfig_arg' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.hwconfig_arg_cmp' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_get_timestamp' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_set_timestamp' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.parse_line' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.run_command' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.get_ram_size' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.miiphy_reset' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.miiphy_register' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_submit_int_msg' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_clear_hub_feature' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_get_class_descriptor' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_get_report' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_set_idle' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.usb_set_protocol' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.sdata.ShortPCIListing' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.sdata.cpu_hwconfig' in file 'common/libcommon.o' powerpc-linux-gnu-ld: Removing unused section '.text.BE_mapRealPointer' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.BE_getVESABuf' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.BE_int86x' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.BE_int86' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.x86emuOp2_bts_R' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.x86emu_dump_xregs' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.x86emu_dump_regs' in file 'drivers/bios_emulator/libatibiosemu.o' powerpc-linux-gnu-ld: Removing unused section '.text.print_laws' in file 'drivers/misc/libmisc.o' powerpc-linux-gnu-ld: Removing unused section '.text.flash_set_verbose' in file 'drivers/mtd/libmtd.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_read_config_byte_via_dword' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_read_config_word_via_dword' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_write_config_byte_via_dword' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_write_config_word_via_dword' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_last_busno' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_config_device' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_cfgfunc_config_device' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_cfgfunc_do_nothing' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_find_device' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text.pci_hose_scan' in file 'drivers/pci/libpci.o' powerpc-linux-gnu-ld: Removing unused section '.text._serial_putc_raw' in file 'drivers/serial/libserial.o' powerpc-linux-gnu-ld: Removing unused section '.text.serial_putc_raw' in file 'drivers/serial/libserial.o' powerpc-linux-gnu-ld: Removing unused section '.text.__video_set_lut' in file 'drivers/video/libvideo.o' powerpc-linux-gnu-ld: Removing unused section '.text.file_getfsname' in file 'fs/fat/libfat.o' powerpc-linux-gnu-ld: Removing unused section '.text.file_read' in file 'fs/fat/libfat.o' powerpc-linux-gnu-ld: Removing unused section '.text.file_ls' in file 'fs/fat/libfat.o' powerpc-linux-gnu-ld: Removing unused section '.text.file_detectfs' in file 'fs/fat/libfat.o' powerpc-linux-gnu-ld: Removing unused section '.text.file_cd' in file 'fs/fat/libfat.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_get_path' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_get_alias' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_pack' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_add_reservemap_entry' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_finish_reservemap' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_end_node' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_finish' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_begin_node' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_property' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_create' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_nop_node' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_nop_property' in file 'lib/libfdt/libfdt.o' powerpc-linux-gnu-ld: Removing unused section '.text.hdestroy' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.hcreate' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.lmb_dump_all' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.lmb_is_reserved' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.__board_lmb_reserve' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.__arch_lmb_reserve' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.ldiv' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.md5' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.sha1_self_test' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.sha1_hmac' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.sha1_csum' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.strspn' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.strtok' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.strsep' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.strswab' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.memscan' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.strrchr' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.ustrtoul' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.inflateInit_' in file 'lib/libgeneric.o' powerpc-linux-gnu-ld: Removing unused section '.text.eth_get_dev_by_index' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.text.eth_get_dev_by_name' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.text.eth_setenv_enetaddr' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.text.VLAN_to_string' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.text.random_port' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.sdata.TftpRRQTimeoutMSecs' in file 'net/libnet.o' powerpc-linux-gnu-ld: Removing unused section '.text.post_info_single' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.post_info' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.arch_memory_test_prepare' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.arch_memory_test_advance' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.arch_memory_test_cleanup' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.arch_memory_failure_handle' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_ffs' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_fls' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_hweight32' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_hweight16' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_hweight8' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.___arch__swab16' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.___arch__swab32' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__fswab16' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab16p' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab16s' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__fswab32' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab32p' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab32s' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__fswab64' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fls' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fls64' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__ilog2_u64' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.ffs64' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.ext2_find_next_zero_bit' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_set_bit' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.generic_clear_bit' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__FD_SET' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__FD_CLR' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__FD_ISSET' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__FD_ZERO' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.eieio' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.sync' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.isync' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_readb' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_readw' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_readl' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_writeb' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_writew' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__raw_writel' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.unmap_physmem' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.lmb_size_bytes' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_magic' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_totalsize' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_off_dt_struct' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_off_dt_strings' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_off_mem_rsvmap' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_version' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_last_comp_version' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_boot_cpuid_phys' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_size_dt_strings' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_set_size_dt_struct' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_fixup_dr_usb' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_header_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_magic' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_hcrc' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_time' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_load' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_ep' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_dcrc' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_os' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_arch' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_type' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_comp' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_name' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_data_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_data' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_image_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_get_image_end' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_magic' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_hcrc' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_time' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_load' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_ep' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_dcrc' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_os' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_arch' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_type' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_comp' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_check_magic' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_check_type' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_check_arch' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_check_os' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_check_target_arch' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_get_size' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_get_end' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.is_zero_ether_addr' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.is_multicast_ether_addr' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.is_broadcast_ether_addr' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.is_valid_ether_addr' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.post_word_load' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.post_word_store' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.getenv_IPaddr' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.NetCopyLong' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.NetCopyIP' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.NetWriteIP' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.NetReadLong' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.NetReadIP' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_image_check_target_arch' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fit_get_name' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.image_set_name' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_setprop_cell' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_property_cell' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_setprop_inplace_cell' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_getprop_w' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_get_property_w' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.fdt_offset_ptr_w' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.virt_to_phys' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.map_physmem' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab64p' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.text.__swab64s' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.sdata.otherpattern' in file 'post/libpost.o' powerpc-linux-gnu-ld: Removing unused section '.eh_frame' in file '../lib/gcc/powerpc-linux-gnu/4.4.1/nof/libgcc.a(_udivdi3.o)' powerpc-linux-gnu-ld: Removing unused section '.eh_frame' in file '../lib/gcc/powerpc-linux-gnu/4.4.1/nof/libgcc.a(_umoddi3.o)'
Any comments is welcome.
best regards,
luigi
Luigi 'Comio' Mantellini (1): Enable garbage collection of unused input sections.
config.mk | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)

When available, enable the CC -ffunction-sections/-fdata-sections options and the LD --gc-sections in order to isolate and remove from final executable the unused functions.
From ld manpages:
--gc-sections --no-gc-sections
Enable garbage collection of unused input sections. It is ignored on targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying --no-gc-sections on the command line.
--gc-sections decides which input sections are used by examining symbols and relocations. The section containing the entry symbol and all sections containing symbols undefined on the command-line will be kept, as will sections containing symbols referenced by dynamic objects. Note that when building shared libraries, the linker must assume that any visible symbol is referenced. Once this initial set of sections has been determined, the linker recursively marks as used any section referenced by their relocations. See --entry and --undefined.
From gcc manpages:
-ffunction-sections -fdata-sections
Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file.
Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. Most systems using the ELF object format and SPARC processors running Solaris 2 have linkers with such optimizations. AIX may have these optimizations in the future.
Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker will create larger object and executable files and will also be slower. You will not be able to use "gprof" on all systems if you specify this option and you may have problems with debugging if you specify both this option and -g.
Signed-off-by: Luigi 'Comio' Mantellini luigi.mantellini@idf-hit.com --- config.mk | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/config.mk b/config.mk index c6d6f7b..94ca033 100644 --- a/config.mk +++ b/config.mk @@ -97,6 +97,8 @@ HOSTCFLAGS += -pedantic # cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) +ld-option = $(shell if $(CC) -Wl,$(1) -nostdlib -xc /dev/null -o /dev/null \ + > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
# # Include the make variables (CC, etc...) @@ -191,6 +193,13 @@ endif
CFLAGS += $(call cc-option,-fno-stack-protector)
+# Create a section for each function or data (useful for sections garbage collector) +CFLAGS += $(call cc-option,-ffunction-sections) +CFLAGS += $(call cc-option,-fdata-sections) + +# Enable sections garbage collector +LDFLAGS += $(call ld-option,--gc-sections) + # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> # option to the assembler. AFLAGS_DEBUG :=

Dear Luigi 'Comio' Mantellini,
In message 1291545952-26761-2-git-send-email-luigi.mantellini@idf-hit.com you wrote:
When available, enable the CC -ffunction-sections/-fdata-sections options and the LD --gc-sections in order to isolate and remove from final executable the unused functions.
...
config.mk | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
Why do you ignore my previous review comments?
You cannot simply turn this feature on globally for all boards. You will have to make appropriate adjustments more or less everywhere:
- some architectures already have these options set, so these should be removed from the architecture / board specific config files
- other architectures have this NOT set, and they need adjustments to the respective inker scripts.
As is, your patch breaks a zillion of boards.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Sun, Dec 5, 2010 at 1:23 PM, Wolfgang Denk wd@denx.de wrote:
Dear Luigi 'Comio' Mantellini,
In message 1291545952-26761-2-git-send-email-luigi.mantellini@idf-hit.com you wrote:
When available, enable the CC -ffunction-sections/-fdata-sections options and the LD --gc-sections in order to isolate and remove from final executable the unused functions.
...
config.mk | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
Why do you ignore my previous review comments?
Sorry, I'm working essentially on MIPS arch and I haven't checked the presence of this option in the others archs. I'm wrong and I misunderstood your previous comments considering only to split the patches.
I will consider to check just the mips boards.
Sorry again for this noise.
luigi
You cannot simply turn this feature on globally for all boards. You will have to make appropriate adjustments more or less everywhere:
- some architectures already have these options set, so these should
be removed from the architecture / board specific config files
- other architectures have this NOT set, and they need adjustments to
the respective inker scripts.
As is, your patch breaks a zillion of boards.
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de To the systems programmer, users and applications serve only to provide a test load. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
participants (3)
-
Luigi 'Comio' Mantellini
-
Luigi Mantellini
-
Wolfgang Denk