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