2020-10-23 15:40:56

by Vasily Gorbik

[permalink] [raw]
Subject: [PATCH 0/2] add option to save vmlinux link map

Linker -Map option allows to save detailed link map which provides far
more information then the objdump tool might extract.

Discarded input sections
.text.__s390_indirect_jump_r14
0x0000000000000000 0xc arch/s390/kernel/process.o

Detailed information on sections, objects and symbols.
.init.data 0x0000000001276000 0x671f0
*(SORT_BY_NAME(___kentry+*))
*(.init.data init.data.*)
.init.data 0x0000000001276000 0x31b8 init/main.o
0x0000000001276128 late_time_init
0x00000000012781b8 boot_command_line
.init.data 0x00000000012791b8 0x60 init/do_mounts.o
.init.data 0x0000000001279218 0x4 init/do_mounts_rd.o
0x0000000001279218 rd_image_start
*fill* 0x000000000127921c 0x4
.init.data 0x0000000001279220 0x18 init/do_mounts_initrd.o
0x0000000001279228 phys_initrd_start
0x0000000001279230 phys_initrd_size

It helps to bring the light on linker decisions and debug linker scripts.
FILL mask 0xff
0x000000000082f000 . = ALIGN (0x1000)
*fill* 0x000000000082e3fa 0xc06 ff
0x000000000082f000 _end = .

Resulting vmlinux.map is currently 8.8M for s390.
And 48K for the decompressor's arch/s390/boot/compressed/vmlinux.map

- First patch introduces CONFIG_SAVE_LINK_MAP option, which enables
link map and is arch independent.
- Second patch is s390 specific and additionally enables decompressor's
link map saving if CONFIG_SAVE_LINK_MAP is enabled.

It is probably better if both changes would go via kbuild tree.

Vasily Gorbik (2):
kbuild: add config option to save link map file(s)
s390/decompressor: support link map saving

.gitignore | 1 +
Makefile | 6 +++++-
arch/s390/boot/compressed/Makefile | 4 +++-
lib/Kconfig.debug | 13 +++++++++++++
4 files changed, 22 insertions(+), 2 deletions(-)

--
2.25.4


2020-10-23 18:07:16

by Vasily Gorbik

[permalink] [raw]
Subject: [PATCH 2/2] s390/decompressor: support link map saving

Produce arch/s390/boot/compressed/vmlinux.map link map for the
decompressor, when CONFIG_SAVE_LINK_MAP option is enabled.

Signed-off-by: Vasily Gorbik <[email protected]>
---
arch/s390/boot/compressed/Makefile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/s390/boot/compressed/Makefile b/arch/s390/boot/compressed/Makefile
index b235ed95a3d8..859a5c7c9ca7 100644
--- a/arch/s390/boot/compressed/Makefile
+++ b/arch/s390/boot/compressed/Makefile
@@ -21,7 +21,9 @@ OBJCOPYFLAGS :=

OBJECTS := $(addprefix $(obj)/,$(obj-y))

-LDFLAGS_vmlinux := --oformat $(LD_BFD) -e startup -T
+clean-files += vmlinux.map
+
+LDFLAGS_vmlinux := --oformat $(LD_BFD) -e startup $(if $(CONFIG_SAVE_LINK_MAP),-Map=$(obj)/vmlinux.map) -T
$(obj)/vmlinux: $(obj)/vmlinux.lds $(objtree)/arch/s390/boot/startup.a $(OBJECTS) FORCE
$(call if_changed,ld)

--
2.25.4

2020-10-23 18:07:28

by Vasily Gorbik

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

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 <[email protected]>
---
.gitignore | 1 +
Makefile | 6 +++++-
lib/Kconfig.debug | 13 +++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)

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
--
2.25.4