|
Rockbox mail archiveSubject: Removing unused code via --gc-sectionsRemoving unused code via --gc-sections
From: Boris Gjenero <boris.gjenero_at_gmail.com>
Date: Sat, 17 Dec 2011 13:26:02 -0500 It seems there's interest in automatically removing unused code via --gc-sections. Theoretically, the requirements are easy: --gc-sections requires KEEP() in linker scripts around things that need to be kept but are not directly referenced. This only seems to affect vectors, because they're only accessed by the CPU. -ffunction-sections requires wildcards for .text, because it puts functions in sections like ".text.functionname". -fdata-sections similarly requires wildcards for .data, .rodata and .bss. I don't see a benefit from -fdata-sections due to very little removed data and added alignment padding. However, I think adding what's required to allow it to work is a good idea because it's simple. Here's a patch which does all that: http://www.rockbox.org/tracker/task/12378?getfile=24520 . I'm not certain that it's wise to touch linker scripts that aren't used for regular target and bootloader builds, but KEEP() shouldn't cause any harm. I only added wildcards to firmware/rom.lds, because only that is required to make this work with normal builds. When something is explicitly put into a particular section, it won't be automatically moved into a subsection. For example, this includes things put into .icode via ICODE_ATTR. Such things will only be removed if nothing else in the same section in the same object file is referenced. Wildcards for such sections aren't required unless something has been explicitly moved into a sub-section. Maybe it's a good idea to use something like ICODE_ATTR("functionname") in the future? I could add wildcards for that if desired. Builds using these switches shouldn't significantly increase load for the build infrastructure. However, when the switches are first enabled, all object files should be re-created to ensure they all use -ffunction-sections. I don't have a patch to add -ffunction-sections to GCCOPTS and -Wl,--gc-sections to GLOBAL_LDOPTS because I'm not sure how they should be added. My results at https://docs.google.com/spreadsheet/ccc?key=0AsEpnuZKewlIdHMteloydnV2eERmWjZsTV9OT2w0UWc imply that it should work for all those targets. However, it may be better to be cautious and only enable it for selected tested targets. I think the linker scripts could use some cleanup and merging. I didn't get around to that, and I don't think making these changes will make future cleanup and merging harder. Regards, Boris Received on 2011-12-17 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |