[PATCH-next v2] arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION

liuyuntao (F) liuyuntao12 at huawei.com
Fri Mar 8 22:56:46 PST 2024



On 2024/3/8 22:27, Ard Biesheuvel wrote:
> On Fri, 8 Mar 2024 at 14:16, Arnd Bergmann <arnd at arndb.de> wrote:
>>
>> On Thu, Mar 7, 2024, at 16:12, Yuntao Liu wrote:
>>> The current arm32 architecture does not yet support the
>>> HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. arm32 is widely used in
>>> embedded scenarios, and enabling this feature would be beneficial for
>>> reducing the size of the kernel image.
>>>
>>> In order to make this work, we keep the necessary tables by annotating
>>> them with KEEP, also it requires further changes to linker script to KEEP
>>> some tables and wildcard compiler generated sections into the right place.
>>>
>>> It boots normally with defconfig, vexpress_defconfig and tinyconfig.
>>>
>>> The size comparison of zImage is as follows:
>>> defconfig       vexpress_defconfig      tinyconfig
>>> 5137712         5138024                 424192          no dce
>>> 5032560         4997824                 298384          dce
>>> 2.0%            2.7%                    29.7%           shrink
>>>
>>> When using smaller config file, there is a significant reduction in the
>>> size of the zImage.
>>>
>>> We also tested this patch on a commercially available single-board
>>> computer, and the comparison is as follows:
>>> a15eb_config
>>> 2161384         no dce
>>> 2092240         dce
>>> 3.2%            shrink
>>>
>>> The zImage size has been reduced by approximately 3.2%, which is 70KB on
>>> 2.1M.
>>>
>>> Signed-off-by: Yuntao Liu <liuyuntao12 at huawei.com>
>>
>> I've retested with both gcc-13 and clang-18, and so no
>> more build issues. Your previous version already worked
>> fine for me.
>>
>> I did some tests combining this with CONFIG_TRIM_UNUSED_KSYMS,
>> which showed a significant improvement as expected. I also
>> tried combining it with an experimental CONFIG_LTO_CLANG
>> patch, but that did not show any further improvements.
>>
>> Tested-by: Arnd Bergmann <arnd at arndb.de>
>> Reviewed-by: Arnd Bergmann <arnd at arndb.de>
>>
>> Adding Ard Biesheuvel and Fangrui Song to Cc, so they can comment
>> on the ARM_VECTORS_TEXT workaround. I don't understand enough of
>> the details of what is going on here.
>>
> 
> Thanks for the cc
> 
>> Full quote of the patch below so they can see the whole thing.
>>
>> If they are also happy with the patch, I think you can send it
>> into Russell's patch tracker at
>> https://www.armlinux.org.uk/developer/patches/info.php
>>
> 
> No, not happy at all :-)
> 
> The resulting kernel does not boot (built with GCC or Clang). And the
> patch is buggy (see below)
> 
After applying .reloc .text, R_ARM_NONE, ., the resulting kernel boots 
well in QEMU. I tested it with the latest linux-next master branch and 
the mainline master branch.
By the way, I used vexpress_defconfig for testing, it worked.




More information about the linux-arm-kernel mailing list