^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # Based on the vmlinux file create the System.map file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # System.map is used by module-init tools and some debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # tools to retrieve the actual addresses of symbols in the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # Usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # mksysmap vmlinux System.map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #####
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # Generate System.map (actual filename passed as second argument)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # $NM produces the following output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # f0081e80 T alloc_vfsmnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) # The second row specify the type of the symbol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # A = Absolute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) # B = Uninitialised data (.bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # C = Common symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # D = Initialised data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) # G = Initialised data for small objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # I = Indirect reference to another symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # N = Debugging symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # R = Read only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # S = Uninitialised data for small objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) # T = Text code symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) # U = Undefined symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) # V = Weak symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) # W = Weak symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # Corresponding small letters are local symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) # For System.map filter away:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) # a - local absolute symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) # U - undefined global symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # N - debugging symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) # w - local weak symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) # readprofile starts reading symbols when _stext is found, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) # continue until it finds a symbol which is not either of 'T', 't',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) # 'W' or 'w'. __crc_ are 'A' and placed in the middle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) # so we just ignore them to let readprofile continue to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) # (At least sparc64 has __crc_ in the middle).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) $NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( \.L\)' > $2