Skip to content

Commit

Permalink
Merge tag 'x86_build_for_v6.5' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/tip/tip

Pull x86 build update from Borislav Petkov:

 - Remove relocation information from vmlinux as it is not needed by
   other tooling and thus a slimmer binary is generated.

   This is important for distros who have to distribute vmlinux blobs
   with their kernel packages too and that extraneous unnecessary data
   bloats them for no good reason

* tag 'x86_build_for_v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/build: Avoid relocation information in final vmlinux
  • Loading branch information
torvalds committed Jun 26, 2023
2 parents 8c69e7a + 9d9173e commit 5903513
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
47 changes: 47 additions & 0 deletions arch/x86/Makefile.postlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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 $(srctree)/scripts/Kbuild.include

CMD_RELOCS = arch/x86/tools/relocs
OUT_RELOCS = arch/x86/boot/compressed
quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs
cmd_relocs = \
mkdir -p $(OUT_RELOCS); \
$(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \
$(CMD_RELOCS) --abs-relocs $@

quiet_cmd_strip_relocs = RSTRIP $@
cmd_strip_relocs = \
$(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
--remove-section='.rela.*' --remove-section='.rela__*' $@

# `@true` prevents complaint when there is nothing to be done

vmlinux: FORCE
@true
ifeq ($(CONFIG_X86_NEED_RELOCS),y)
$(call cmd,relocs)
$(call cmd,strip_relocs)
endif

%.ko: FORCE
@true

clean:
@rm -f $(OUT_RELOCS)/vmlinux.relocs

PHONY += FORCE clean

FORCE:

.PHONY: $(PHONY)
8 changes: 3 additions & 5 deletions arch/x86/boot/compressed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ $(obj)/vmlinux.bin: vmlinux FORCE

targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs

CMD_RELOCS = arch/x86/tools/relocs
quiet_cmd_relocs = RELOCS $@
cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
$(obj)/vmlinux.relocs: vmlinux FORCE
$(call if_changed,relocs)
# vmlinux.relocs is created by the vmlinux postlink step.
$(obj)/vmlinux.relocs: vmlinux
@true

vmlinux.bin.all-y := $(obj)/vmlinux.bin
vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
Expand Down

0 comments on commit 5903513

Please sign in to comment.