mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: mcgrof@kernel.org, rostedt@goodmis.org, masahiroy@kernel.org
Cc: linux-trace-kernel@vger.kernel.org,
	linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
	arnd@arndb.de, akpm@linux-foundation.org, eugene.loh@oracle.com,
	kris.van.hees@oracle.com
Subject: [PATCH v9 3/8] kbuild: generate an address ranges map at vmlinux link time
Date: Thu, 27 Oct 2022 20:57:49 +0100	[thread overview]
Message-ID: <20221027195754.100039-4-nick.alcock@oracle.com> (raw)
In-Reply-To: <20221027195754.100039-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>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
---

Notes:
    v6: use ${wl} where appropriate to avoid failure on UML

 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 918470d768e9..287a2b2c4d46 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -101,7 +101,7 @@ vmlinux_link()
 	${ld} ${ldflags} -o ${output}					\
 		${wl}--whole-archive ${objs} ${wl}--no-whole-archive	\
 		${wl}--start-group ${libs} ${wl}--end-group		\
-		$@ ${ldlibs}
+		${wl}-Map=.tmp_vmlinux.map $@ ${ldlibs}
 }
 
 # generate .BTF typeinfo from DWARF debuginfo
@@ -144,6 +144,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 is_enabled CONFIG_KALLSYMS_ALL; then
 		kallsymopt="${kallsymopt} --all-symbols"
 	fi
-- 
2.38.0.266.g481848f278


  parent reply	other threads:[~2022-10-27 19:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 19:57 [PATCH v9] kallsyms: reliable symbol->address lookup with /proc/kallmodsyms Nick Alcock
2022-10-27 19:57 ` [PATCH v9 1/8] kbuild: bring back tristate.conf Nick Alcock
2022-10-27 19:57 ` [PATCH v9 2/8] kbuild: add modules_thick.builtin Nick Alcock
2022-10-27 19:57 ` Nick Alcock [this message]
2022-10-27 19:57 ` [PATCH v9 4/8] kallsyms: introduce sections needed to map symbols to built-in modules Nick Alcock
2022-10-27 19:57 ` [PATCH v9 5/8] kallsyms: optimize .kallsyms_modules* Nick Alcock
2022-10-27 19:57 ` [PATCH v9 6/8] kallsyms: distinguish text symbols fully using object file names Nick Alcock
2022-10-27 19:57 ` [PATCH v9 7/8] kallsyms: add /proc/kallmodsyms for text symbol disambiguation Nick Alcock
2022-10-27 19:57 ` [PATCH v9 8/8] perf: proof-of-concept kallmodsyms support Nick Alcock
2022-11-09 13:41 [PATCH PING v9] kallsyms: reliable symbol->address lookup with /proc/kallmodsyms Nick Alcock
2022-11-09 13:41 ` [PATCH v9 3/8] kbuild: generate an address ranges map at vmlinux link time Nick Alcock
2022-11-13  3:02   ` Luis Chamberlain
2022-11-14 16:48     ` Nick Alcock
2022-11-15 21:22       ` Luis Chamberlain
2022-11-16 16:06         ` 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=20221027195754.100039-4-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=eugene.loh@oracle.com \
    --cc=kris.van.hees@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®