diff mbox series

[1/2] kbuild: add config option to save link map file(s)

Message ID patch-1.thread-ba6b03.git-dec2f0b867da.your-ad-here.call-01603453670-ext-0242@work.hours (mailing list archive)
State New, archived
Headers show
Series add option to save vmlinux link map | expand

Commit Message

Vasily Gorbik Oct. 23, 2020, 11:57 a.m. UTC
Add CONFIG_SAVE_LINK_MAP config option, which would make linker to save
link map to vmlinux.map file. Link map is quite useful during making
kernel changes related to how the kernel is composed and debugging
linker scripts. It also provides information about discarded sections
and symbols.

Architectures supporting compressed kernel images might respect
CONFIG_SAVE_LINK_MAP option and produce arch/*/boot/compressed/vmlinux.map
for the decompressor code as well.

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 .gitignore        |  1 +
 Makefile          |  6 +++++-
 lib/Kconfig.debug | 13 +++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index d01cda8e1177..81ba7416a0b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,6 +48,7 @@ 
 Module.symvers
 modules.builtin
 modules.order
+vmlinux.map
 
 #
 # Top-level generic files
diff --git a/Makefile b/Makefile
index e71979882e4f..d35a59f98e83 100644
--- a/Makefile
+++ b/Makefile
@@ -984,6 +984,10 @@  ifeq ($(CONFIG_RELR),y)
 LDFLAGS_vmlinux	+= --pack-dyn-relocs=relr
 endif
 
+ifeq ($(CONFIG_SAVE_LINK_MAP),y)
+LDFLAGS_vmlinux	+= -Map=vmlinux.map
+endif
+
 # Align the bit size of userspace programs with the kernel
 KBUILD_USERCFLAGS  += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
 KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
@@ -1461,7 +1465,7 @@  endif # CONFIG_MODULES
 # make distclean Remove editor backup files, patch leftover files and the like
 
 # Directories & files removed with 'make clean'
-CLEAN_FILES += include/ksym vmlinux.symvers \
+CLEAN_FILES += include/ksym vmlinux.symvers vmlinux.map \
 	       modules.builtin modules.builtin.modinfo modules.nsdeps \
 	       compile_commands.json
 
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d7a7bc3b6098..1ac4234ad879 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -363,6 +363,19 @@  config SECTION_MISMATCH_WARN_ONLY
 
 	  If unsure, say Y.
 
+config SAVE_LINK_MAP
+	bool "Save vmlinux link map file(s)"
+	default n
+	help
+	  If you say Y here, vmlinux link map will be saved into
+	  vmlinux.map. The link map is quite useful during making kernel
+	  changes related to how the kernel is composed and linker
+	  scripts debugging.
+
+	  In addition to that architectures supporting compressed kernel
+	  images might also produce arch/*/boot/compressed/vmlinux.map
+	  for the decompressor code as well.
+
 config DEBUG_FORCE_FUNCTION_ALIGN_32B
 	bool "Force all function address 32B aligned" if EXPERT
 	help