1*4882a593Smuzhiyun# Copyright © 2016 IBM Corporation 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun# This program is free software; you can redistribute it and/or 4*4882a593Smuzhiyun# modify it under the terms of the GNU General Public License 5*4882a593Smuzhiyun# as published by the Free Software Foundation; either version 6*4882a593Smuzhiyun# 2 of the License, or (at your option) any later version. 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun# This script checks the head of a vmlinux for linker stubs that 9*4882a593Smuzhiyun# break our placement of fixed-location code for 64-bit. 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun# based on relocs_check.pl 12*4882a593Smuzhiyun# Copyright © 2009 IBM Corporation 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun# NOTE! 15*4882a593Smuzhiyun# 16*4882a593Smuzhiyun# If the build dies here, it's likely code in head_64.S/exception-64*.S or 17*4882a593Smuzhiyun# nearby, is branching to labels it can't reach directly, which results in the 18*4882a593Smuzhiyun# linker inserting branch stubs. This can move code around in ways that break 19*4882a593Smuzhiyun# the fixed section calculations (head-64.h). To debug this, disassemble the 20*4882a593Smuzhiyun# vmlinux and look for branch stubs (long_branch, plt_branch, etc.) in the 21*4882a593Smuzhiyun# fixed section region (0 - 0x8000ish). Check what code is calling those stubs, 22*4882a593Smuzhiyun# and perhaps change so a direct branch can reach. 23*4882a593Smuzhiyun# 24*4882a593Smuzhiyun# A ".linker_stub_catch" section is used to catch some stubs generated by 25*4882a593Smuzhiyun# early .text code, which tend to get placed at the start of the section. 26*4882a593Smuzhiyun# If there are too many such stubs, they can overflow this section. Expanding 27*4882a593Smuzhiyun# it may help (or reducing the number of stub branches). 28*4882a593Smuzhiyun# 29*4882a593Smuzhiyun# Linker stubs use the TOC pointer, so even if fixed section code could 30*4882a593Smuzhiyun# tolerate them being inserted into head code, they can't be allowed in low 31*4882a593Smuzhiyun# level entry code (boot, interrupt vectors, etc) until r2 is set up. This 32*4882a593Smuzhiyun# could cause the kernel to die in early boot. 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun# Allow for verbose output 35*4882a593Smuzhiyunif [ "$V" = "1" ]; then 36*4882a593Smuzhiyun set -x 37*4882a593Smuzhiyunfi 38*4882a593Smuzhiyun 39*4882a593Smuzhiyunif [ $# -lt 2 ]; then 40*4882a593Smuzhiyun echo "$0 [path to nm] [path to vmlinux]" 1>&2 41*4882a593Smuzhiyun exit 1 42*4882a593Smuzhiyunfi 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun# Have Kbuild supply the path to nm so we handle cross compilation. 45*4882a593Smuzhiyunnm="$1" 46*4882a593Smuzhiyunvmlinux="$2" 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun# gcc-4.6-era toolchain make _stext an A (absolute) symbol rather than T 49*4882a593Smuzhiyun$nm "$vmlinux" | grep -e " [TA] _stext$" -e " t start_first_256B$" -e " a text_start$" -e " t start_text$" > .tmp_symbols.txt 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun 52*4882a593Smuzhiyunvma=$(cat .tmp_symbols.txt | grep -e " [TA] _stext$" | cut -d' ' -f1) 53*4882a593Smuzhiyun 54*4882a593Smuzhiyunexpected_start_head_addr=$vma 55*4882a593Smuzhiyun 56*4882a593Smuzhiyunstart_head_addr=$(cat .tmp_symbols.txt | grep " t start_first_256B$" | cut -d' ' -f1) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyunif [ "$start_head_addr" != "$expected_start_head_addr" ]; then 59*4882a593Smuzhiyun echo "ERROR: head code starts at $start_head_addr, should be $expected_start_head_addr" 60*4882a593Smuzhiyun echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 61*4882a593Smuzhiyun echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun exit 1 64*4882a593Smuzhiyunfi 65*4882a593Smuzhiyun 66*4882a593Smuzhiyuntop_vma=$(echo $vma | cut -d'0' -f1) 67*4882a593Smuzhiyun 68*4882a593Smuzhiyunexpected_start_text_addr=$(cat .tmp_symbols.txt | grep " a text_start$" | cut -d' ' -f1 | sed "s/^0/$top_vma/") 69*4882a593Smuzhiyun 70*4882a593Smuzhiyunstart_text_addr=$(cat .tmp_symbols.txt | grep " t start_text$" | cut -d' ' -f1) 71*4882a593Smuzhiyun 72*4882a593Smuzhiyunif [ "$start_text_addr" != "$expected_start_text_addr" ]; then 73*4882a593Smuzhiyun echo "ERROR: start_text address is $start_text_addr, should be $expected_start_text_addr" 74*4882a593Smuzhiyun echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 75*4882a593Smuzhiyun echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun exit 1 78*4882a593Smuzhiyunfi 79*4882a593Smuzhiyun 80*4882a593Smuzhiyunrm -f .tmp_symbols.txt 81