mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
	Linus Torvalds <torvalds@osdl.org>
Subject: [1/12] kbuild: Check for undefined symbols in vmlinux
Date: Fri, 13 Aug 2004 21:45:14 +0200	[thread overview]
Message-ID: <20040813194514.GA10556@mars.ravnborg.org> (raw)
In-Reply-To: <20040813192804.GA10486@mars.ravnborg.org>

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/08/07 21:35:44+02:00 sam@mars.ravnborg.org 
#   kbuild: Check for undefined symbols in vmlinux
#   
#   At least one bin-utils version for ARM is know to ignore undefined
#   symbols when performing the final link of vmlinux.
#   Add an explicit check for undefined symbols to catch this.
#   The check is made in combination with generating the System.map file
#   and the actual algorithm is moved to a small shell script - mksysmap.
#   
#   External symbols with three leading underscores are ignored - sparc
#   uses them for the BTFIXUP logic.
#   
#   Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
# 
# scripts/mksysmap
#   2004/08/07 21:35:27+02:00 sam@mars.ravnborg.org +54 -0
# 
# scripts/mksysmap
#   2004/08/07 21:35:27+02:00 sam@mars.ravnborg.org +0 -0
#   BitKeeper file /home/sam/bk/kbuild/scripts/mksysmap
# 
# Makefile
#   2004/08/07 21:35:27+02:00 sam@mars.ravnborg.org +18 -7
#   Use new mksysmap script when generating System.map
#   Also make nice printout when executing in non-verbose mode.
# 
diff -Nru a/Makefile b/Makefile
--- a/Makefile	2004-08-13 21:09:35 +02:00
+++ b/Makefile	2004-08-13 21:09:35 +02:00
@@ -538,8 +538,9 @@
 	echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
 endef
 
-do_system_map = $(NM) $(1) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > $(2)
-
+quiet_cmd_sysmap = SYSMAP 
+      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
+		   
 LDFLAGS_vmlinux += -T arch/$(ARCH)/kernel/vmlinux.lds.s
 
 #	Generate section listing all symbols and add it into vmlinux
@@ -570,8 +571,10 @@
 kallsyms.o := .tmp_kallsyms$(last_kallsyms).o
 
 define rule_verify_kallsyms
-	@$(call do_system_map, .tmp_vmlinux$(last_kallsyms), .tmp_System.map)
-	@cmp -s System.map .tmp_System.map || \
+	$(Q)$(if $($(quiet)cmd_sysmap),                       \
+	  echo '  $($(quiet)cmd_sysmap) .tmp_System.map' &&)  \
+	  $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
+	$(Q)cmp -s System.map .tmp_System.map || \
 		(echo Inconsistent kallsyms data, try setting CONFIG_KALLSYMS_EXTRA_PASS ; rm .tmp_kallsyms* ; false)
 endef
 
@@ -595,11 +598,19 @@
 
 endif
 
-#	Finally the vmlinux rule
+# Finally the vmlinux rule
+# This rule is also used to generate System.map
+# and to verify that the content of kallsyms are consistent
 
 define rule_vmlinux
-	$(rule_vmlinux__); \
-	$(call do_system_map, $@, System.map)
+	$(rule_vmlinux__);
+	$(Q)$(if $($(quiet)cmd_sysmap),          \
+	  echo '  $($(quiet)cmd_sysmap) $@' &&)  \
+	$(cmd_sysmap) $@ System.map;             \
+	if [ $$? -ne 0 ]; then                   \
+		rm -f $@;                        \
+		/bin/false;                      \
+	fi;
 	$(rule_verify_kallsyms)
 endef
 
diff -Nru a/scripts/mksysmap b/scripts/mksysmap
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/scripts/mksysmap	2004-08-13 21:09:35 +02:00
@@ -0,0 +1,54 @@
+#!/bin/sh -x
+# Based on the vmlinux file create the System.map file
+# System.map is used by module-init tools and some debugging
+# tools to retreive the actual addresses of symbols in the kernel.
+#
+# Before creating the System.map file as a sideeffect check for
+# undefined symbols.
+# At least one version of the ARM bin-utils did not error out on
+# undefined symbols, so catch them here instead.
+
+# Usage
+# mksysmap vmlinux System.map
+
+
+#####
+# Check for undefined symbols.
+# Undefined symbols with three leading underscores are ignored since
+# they are used by the sparc BTFIXUP logic - and is assumed to be undefined.
+
+
+if [ "`$NM -u $1 | grep -v ' ____'`" != "" ]; then
+	echo "$1: error: undefined symbol(s) found:"
+	$NM -u $1 | grep -v ' ___'
+	exit 1
+fi
+
+#####
+# Generate System.map (actual filename passed as second argument)
+
+# $NM produces the following output:
+# f0081e80 T alloc_vfsmnt
+
+#   The second row specify the type of the symbol:
+#   A = Absolute
+#   B = Uninitialised data (.bss)
+#   C = Comon symbol
+#   D = Initialised data
+#   G = Initialised data for small objects
+#   I = Indirect reference to another symbol
+#   N = Debugging symbol
+#   R = Read only
+#   S = Uninitialised data for small objects
+#   T = Text code symbol
+#   U = Undefined symbol
+#   V = Weak symbol
+#   W = Weak symbol
+#   Corresponding small letters are local symbols
+
+# For System.map filter away:
+#   a - local absolute symbols
+#   U - undefined global symbols
+#   w - local weak symbols
+
+nm $1 | grep -v ' [aUw] ' > $2

  reply	other threads:[~2004-08-13 19:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-13 19:28 kbuild updates Sam Ravnborg
2004-08-13 19:45 ` Sam Ravnborg [this message]
2004-08-13 19:45 ` [2/12] kbuild/sparc: Use new generic mksysmap script to generate System.map Sam Ravnborg
2004-08-13 19:46 ` [3/12] kconfig: save kernel version in .config file Sam Ravnborg
2004-08-13 19:47 ` [4/12] kbuild: Selective compile of targets in scripts/ Sam Ravnborg
2004-08-13 19:47 ` [5/12] kbuild: Use LINUXINCLUDE to specify include/ directory Sam Ravnborg
2004-08-13 19:48 ` [6/12] kbuild: Accept absolute paths in clean-files and introduce clean-dirs Sam Ravnborg
2004-08-13 19:49 ` [7/12] kbuild: Separate out host-progs handling Sam Ravnborg
2004-08-14  8:04   ` Coywolf Qi Hunt
2004-08-13 19:50 ` [8/12] kbuild: Introduce hostprogs-y, deprecate host-progs Sam Ravnborg
2004-08-13 19:51 ` [9/12] kbuild: Replace host-progs with hostprogs-y Sam Ravnborg
2004-08-13 19:51 ` [10/12] kbuild: Fix hostprogs-y Sam Ravnborg
2004-08-13 19:52 ` [11/12] kbuild: Use POSIX headers for ntoh functions Sam Ravnborg
2004-08-13 19:52 ` [12/12] kbuild: __crc_* symbols in System.map Sam Ravnborg

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=20040813194514.GA10556@mars.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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®