# Copyright © 2016 IBM Corporation12# This program is free software; you can redistribute it and/or3# modify it under the terms of the GNU General Public License4# as published by the Free Software Foundation; either version5# 2 of the License, or (at your option) any later version.67# This script checks the head of a vmlinux for linker stubs that8# break our placement of fixed-location code for 64-bit.910# based on relocs_check.pl11# Copyright © 2009 IBM Corporation1213# NOTE!14#15# If the build dies here, it's likely code in head_64.S/exception-64*.S or16# nearby, is branching to labels it can't reach directly, which results in the17# linker inserting branch stubs. This can move code around in ways that break18# the fixed section calculations (head-64.h). To debug this, disassemble the19# vmlinux and look for branch stubs (long_branch, plt_branch, etc.) in the20# fixed section region (0 - 0x8000ish). Check what code is calling those stubs,21# and perhaps change so a direct branch can reach.22#23# A ".linker_stub_catch" section is used to catch some stubs generated by24# early .text code, which tend to get placed at the start of the section.25# If there are too many such stubs, they can overflow this section. Expanding26# it may help (or reducing the number of stub branches).27#28# Linker stubs use the TOC pointer, so even if fixed section code could29# tolerate them being inserted into head code, they can't be allowed in low30# level entry code (boot, interrupt vectors, etc) until r2 is set up. This31# could cause the kernel to die in early boot.3233# Allow for verbose output34if [ "$V" = "1" ]; then35set -x36fi3738if [ $# -lt 2 ]; then39echo "$0 [path to nm] [path to vmlinux]" 1>&240exit 141fi4243# Have Kbuild supply the path to nm so we handle cross compilation.44nm="$1"45vmlinux="$2"4647# gcc-4.6-era toolchain make _stext an A (absolute) symbol rather than T48$nm "$vmlinux" | grep -e " [TA] _stext$" -e " t start_first_256B$" -e " a text_start$" -e " t start_text$" > .tmp_symbols.txt495051vma=$(grep -e " [TA] _stext$" .tmp_symbols.txt | cut -d' ' -f1)5253expected_start_head_addr="$vma"5455start_head_addr=$(grep " t start_first_256B$" .tmp_symbols.txt | cut -d' ' -f1)5657if [ "$start_head_addr" != "$expected_start_head_addr" ]; then58echo "ERROR: head code starts at $start_head_addr, should be $expected_start_head_addr" 1>&259echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&260echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&26162exit 163fi6465top_vma=$(echo "$vma" | cut -d'0' -f1)6667expected_start_text_addr=$(grep " a text_start$" .tmp_symbols.txt | cut -d' ' -f1 | sed "s/^0/$top_vma/")6869start_text_addr=$(grep " t start_text$" .tmp_symbols.txt | cut -d' ' -f1)7071if [ "$start_text_addr" != "$expected_start_text_addr" ]; then72echo "ERROR: start_text address is $start_text_addr, should be $expected_start_text_addr" 1>&273echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&274echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&27576exit 177fi7879rm -f .tmp_symbols.txt808182