linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: jeyu@kernel.org, masahiroy@kernel.org
Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
	arnd@arndb.de, eugene.loh@oracle.com, kris.van.hees@oracle.com
Subject: [PATCH v5 3/7] kbuild: generate an address ranges map at vmlinux link time
Date: Wed, 27 Oct 2021 18:47:02 +0100	[thread overview]
Message-ID: <20211027174706.31010-4-nick.alcock@oracle.com> (raw)
In-Reply-To: <20211027174706.31010-1-nick.alcock@oracle.com>

This emits a new file, .tmp_vmlinux.ranges, which maps address
range/size pairs in vmlinux to the object files which make them up,
e.g., in part:

0x0000000000000000 0x30 arch/x86/kernel/cpu/common.o
0x0000000000001000 0x1000 arch/x86/events/intel/ds.o
0x0000000000002000 0x4000 arch/x86/kernel/irq_64.o
0x0000000000006000 0x5000 arch/x86/kernel/process.o
0x000000000000b000 0x1000 arch/x86/kernel/cpu/common.o
0x000000000000c000 0x5000 arch/x86/mm/cpu_entry_area.o
0x0000000000011000 0x10 arch/x86/kernel/espfix_64.o
0x0000000000011010 0x2 arch/x86/kernel/cpu/common.o
[...]

In my simple tests this seems to work with clang too, but if I'm not
sure how stable the format of clang's linker mapfiles is: if it turns
out not to work in some versions, the mapfile-massaging awk script added
here might need some adjustment.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
 scripts/link-vmlinux.sh | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index d74cee5c4326..a30075c14a25 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -196,7 +196,7 @@ vmlinux_link()
 	${ld} ${ldflags} -o ${output}					\
 		${wl}--whole-archive ${objs} ${wl}--no-whole-archive	\
 		${wl}--start-group ${libs} ${wl}--end-group		\
-		$@ ${ldlibs}
+		-Map=.tmp_vmlinux.map $@ ${ldlibs}
 }
 
 # generate .BTF typeinfo from DWARF debuginfo
@@ -248,6 +248,19 @@ kallsyms()
 {
 	local kallsymopt;
 
+	# read the linker map to identify ranges of addresses:
+	#   - for each *.o file, report address, size, pathname
+	#       - most such lines will have four fields
+	#       - but sometimes there is a line break after the first field
+	#   - start reading at "Linker script and memory map"
+	#   - stop reading at ".brk"
+	${AWK} '
+	    /\.o$/ && start==1 { print $(NF-2), $(NF-1), $NF }
+	    /^Linker script and memory map/ { start = 1 }
+	    /^\.brk/ { exit(0) }
+	' .tmp_vmlinux.map | sort > .tmp_vmlinux.ranges
+
+	# get kallsyms options
 	if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
 		kallsymopt="${kallsymopt} --all-symbols"
 	fi
-- 
2.33.0.256.gb827f06fa9


  parent reply	other threads:[~2021-10-27 17:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 21:51 [PATCH v5] kallsyms: new /proc/kallmodsyms with builtin modules Nick Alcock
2021-09-29 21:51 ` [PATCH v5 1/7] kbuild: bring back tristate.conf Nick Alcock
2021-09-29 21:51 ` [PATCH v5 2/7] kbuild: add modules_thick.builtin Nick Alcock
2021-09-29 21:51 ` [PATCH v5 3/7] kbuild: generate an address ranges map at vmlinux link time Nick Alcock
2021-09-29 21:51 ` [PATCH v5 4/7] kallsyms: introduce sections needed to map symbols to built-in modules Nick Alcock
2021-09-29 21:51 ` [PATCH v5 5/7] kallsyms: optimize .kallsyms_modules* Nick Alcock
2021-09-29 21:51 ` [PATCH v5 6/7] kallsyms: add /proc/kallmodsyms Nick Alcock
2021-09-29 21:51 ` [PATCH v5 7/7] kallsyms: add reliable symbol size info Nick Alcock
2021-09-29 23:34 ` [PATCH v5] kallsyms: new /proc/kallmodsyms with builtin modules Kees Cook
2021-09-30 17:19   ` Nick Alcock
2021-09-30 17:53     ` Kees Cook
2021-10-27 17:46 ` [PING PATCH " Nick Alcock
2021-10-27 17:47   ` [PATCH v5 1/7] kbuild: bring back tristate.conf Nick Alcock
2021-10-27 17:47   ` [PATCH v5 2/7] kbuild: add modules_thick.builtin Nick Alcock
2021-10-27 17:47   ` Nick Alcock [this message]
2021-10-30 16:49     ` [PATCH v5 3/7] kbuild: generate an address ranges map at vmlinux link time kernel test robot
2021-10-27 17:47   ` [PATCH v5 4/7] kallsyms: introduce sections needed to map symbols to built-in modules Nick Alcock
2021-10-27 17:47   ` [PATCH v5 5/7] kallsyms: optimize .kallsyms_modules* Nick Alcock
2021-10-27 17:47   ` [PATCH v5 6/7] kallsyms: add /proc/kallmodsyms Nick Alcock
2021-10-28 11:36     ` kernel test robot
2021-10-28 21:52       ` Nick Alcock
2021-10-27 17:47   ` [PATCH v5 7/7] kallsyms: add reliable symbol size info Nick Alcock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211027174706.31010-4-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=arnd@arndb.de \
    --cc=eugene.loh@oracle.com \
    --cc=jeyu@kernel.org \
    --cc=kris.van.hees@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).