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