Re: [PATCH] x86: Avoid relocation information in final vmlinux
From: Petr Pavlu
Date: Tue Sep 20 2022 - 05:01:50 EST
On 9/14/22 01:40, Nathan Chancellor wrote:
> [...]
>> diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink
>> new file mode 100644
>> index 000000000000..4650aaf6d8b3
>> --- /dev/null
>> +++ b/arch/x86/Makefile.postlink
>> @@ -0,0 +1,41 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +# ===========================================================================
>> +# Post-link x86 pass
>> +# ===========================================================================
>> +#
>> +# 1. Separate relocations from vmlinux into vmlinux.relocs.
>> +# 2. Strip relocations from vmlinux.
>> +
>> +PHONY := __archpost
>> +__archpost:
>> +
>> +-include include/config/auto.conf
>> +include scripts/Kbuild.include
>> +
>> +CMD_RELOCS = arch/x86/tools/relocs
>> +quiet_cmd_relocs = RELOCS $@.relocs
>> + cmd_relocs = $(CMD_RELOCS) $@ > $@.relocs;$(CMD_RELOCS) --abs-relocs $@
>> +
>> +quiet_cmd_strip_relocs = RSTRIP $@
>> + cmd_strip_relocs = objcopy --remove-relocations='*' $@
>
> Just a small drive by comment, prefer $(OBJCOPY) over objcopy so that
> the user's choice of objcopy is respected (such as llvm-objcopy).
Ok.
> Unfortunately, llvm-objcopy does not appear to support
> '--remove-relocations'. We can certainly file a feature request for this
> upstream but is there a way to accomplish this in a different way? Or
> perhaps this could be something that is controlled via Kconfig so it
> is only selectable with GNU objcopy??
An alternative is to use use --remove-section='.rel*' which has the same
effect.. or to be more careful, something as:
--remove-section='.rel.*' --remove-section='.rel__*' --remove-section='.rela.*' --remove-section='.rela__*'
Thanks,
Petr