Back to home page

OSCL-LXR

 
 

    


0001 # Copyright © 2016 IBM Corporation
0002 
0003 # This program is free software; you can redistribute it and/or
0004 # modify it under the terms of the GNU General Public License
0005 # as published by the Free Software Foundation; either version
0006 # 2 of the License, or (at your option) any later version.
0007 
0008 # This script checks the head of a vmlinux for linker stubs that
0009 # break our placement of fixed-location code for 64-bit.
0010 
0011 # based on relocs_check.pl
0012 # Copyright © 2009 IBM Corporation
0013 
0014 # NOTE!
0015 #
0016 # If the build dies here, it's likely code in head_64.S/exception-64*.S or
0017 # nearby, is branching to labels it can't reach directly, which results in the
0018 # linker inserting branch stubs. This can move code around in ways that break
0019 # the fixed section calculations (head-64.h). To debug this, disassemble the
0020 # vmlinux and look for branch stubs (long_branch, plt_branch, etc.) in the
0021 # fixed section region (0 - 0x8000ish). Check what code is calling those stubs,
0022 # and perhaps change so a direct branch can reach.
0023 #
0024 # A ".linker_stub_catch" section is used to catch some stubs generated by
0025 # early .text code, which tend to get placed at the start of the section.
0026 # If there are too many such stubs, they can overflow this section. Expanding
0027 # it may help (or reducing the number of stub branches).
0028 #
0029 # Linker stubs use the TOC pointer, so even if fixed section code could
0030 # tolerate them being inserted into head code, they can't be allowed in low
0031 # level entry code (boot, interrupt vectors, etc) until r2 is set up. This
0032 # could cause the kernel to die in early boot.
0033 
0034 # Allow for verbose output
0035 if [ "$V" = "1" ]; then
0036         set -x
0037 fi
0038 
0039 if [ $# -lt 2 ]; then
0040         echo "$0 [path to nm] [path to vmlinux]" 1>&2
0041         exit 1
0042 fi
0043 
0044 # Have Kbuild supply the path to nm so we handle cross compilation.
0045 nm="$1"
0046 vmlinux="$2"
0047 
0048 # gcc-4.6-era toolchain make _stext an A (absolute) symbol rather than T
0049 $nm "$vmlinux" | grep -e " [TA] _stext$" -e " t start_first_256B$" -e " a text_start$" -e " t start_text$" > .tmp_symbols.txt
0050 
0051 
0052 vma=$(grep -e " [TA] _stext$" .tmp_symbols.txt | cut -d' ' -f1)
0053 
0054 expected_start_head_addr="$vma"
0055 
0056 start_head_addr=$(grep " t start_first_256B$" .tmp_symbols.txt | cut -d' ' -f1)
0057 
0058 if [ "$start_head_addr" != "$expected_start_head_addr" ]; then
0059         echo "ERROR: head code starts at $start_head_addr, should be $expected_start_head_addr" 1>&2
0060         echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&2
0061         echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&2
0062 
0063         exit 1
0064 fi
0065 
0066 top_vma=$(echo "$vma" | cut -d'0' -f1)
0067 
0068 expected_start_text_addr=$(grep " a text_start$" .tmp_symbols.txt | cut -d' ' -f1 | sed "s/^0/$top_vma/")
0069 
0070 start_text_addr=$(grep " t start_text$" .tmp_symbols.txt | cut -d' ' -f1)
0071 
0072 if [ "$start_text_addr" != "$expected_start_text_addr" ]; then
0073         echo "ERROR: start_text address is $start_text_addr, should be $expected_start_text_addr" 1>&2
0074         echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&2
0075         echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&2
0076 
0077         exit 1
0078 fi
0079 
0080 rm -f .tmp_symbols.txt