Skip to content

Commit 5cc1247

Browse files
Villemoesmasahir0y
authored andcommitted
kbuild: add CONFIG_VMLINUX_MAP expert option
It can be quite useful to have ld emit a link map file, in order to debug or verify that special sections end up where they are supposed to, and to see what LD_DEAD_CODE_DATA_ELIMINATION manages to get rid of. The only reason I'm not just adding this unconditionally is that the .map file can be rather large (several MB), and that's a waste of space when one isn't interested in these things. Also make it depend on CONFIG_EXPERT. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 609bbb4 commit 5cc1247

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ modules.order
5959
/linux
6060
/vmlinux
6161
/vmlinux.32
62+
/vmlinux.map
6263
/vmlinux.symvers
6364
/vmlinux-gdb.py
6465
/vmlinuz

Documentation/dontdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ vmlinux-*
252252
vmlinux.aout
253253
vmlinux.bin.all
254254
vmlinux.lds
255+
vmlinux.map
255256
vmlinux.symvers
256257
vmlinuz
257258
voffset.h

lib/Kconfig.debug

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ config VMLINUX_VALIDATION
449449
depends on STACK_VALIDATION && DEBUG_ENTRY && !PARAVIRT
450450
default y
451451

452+
config VMLINUX_MAP
453+
bool "Generate vmlinux.map file when linking"
454+
depends on EXPERT
455+
help
456+
Selecting this option will pass "-Map=vmlinux.map" to ld
457+
when linking vmlinux. That file can be useful for verifying
458+
and debugging magic section games, and for seeing which
459+
pieces of code get eliminated with
460+
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION.
461+
452462
config DEBUG_FORCE_WEAK_PER_CPU
453463
bool "Force weak per-cpu definitions"
454464
depends on DEBUG_KERNEL

scripts/link-vmlinux.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ vmlinux_link()
155155
local output=${1}
156156
local objects
157157
local strip_debug
158+
local map_option
158159

159160
info LD ${output}
160161

@@ -166,6 +167,10 @@ vmlinux_link()
166167
strip_debug=-Wl,--strip-debug
167168
fi
168169

170+
if [ -n "${CONFIG_VMLINUX_MAP}" ]; then
171+
map_option="-Map=${output}.map"
172+
fi
173+
169174
if [ "${SRCARCH}" != "um" ]; then
170175
if [ -n "${CONFIG_LTO_CLANG}" ]; then
171176
# Use vmlinux.o instead of performing the slow LTO
@@ -187,6 +192,7 @@ vmlinux_link()
187192
${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \
188193
${strip_debug#-Wl,} \
189194
-o ${output} \
195+
${map_option} \
190196
-T ${lds} ${objects}
191197
else
192198
objects="-Wl,--whole-archive \
@@ -200,6 +206,7 @@ vmlinux_link()
200206
${CC} ${CFLAGS_vmlinux} \
201207
${strip_debug} \
202208
-o ${output} \
209+
${map_option:+-Wl,${map_option}} \
203210
-Wl,-T,${lds} \
204211
${objects} \
205212
-lutil -lrt -lpthread
@@ -303,6 +310,7 @@ cleanup()
303310
rm -f .tmp_vmlinux*
304311
rm -f System.map
305312
rm -f vmlinux
313+
rm -f vmlinux.map
306314
rm -f vmlinux.o
307315
}
308316

0 commit comments

Comments
 (0)