blob: 3f46e8b9c56d7b51e045a48679ac46d26c7c67f3 [file] [log] [blame]
Tony Breeds144ef902009-09-14 19:57:02 +00001#!/usr/bin/perl
2
3# Copyright © 2009 IBM Corporation
4
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version
8# 2 of the License, or (at your option) any later version.
9
Paul Bolle8b055372013-05-29 09:18:28 +020010# This script checks the relocations of a vmlinux for "suspicious"
Tony Breeds144ef902009-09-14 19:57:02 +000011# relocations.
12
13use strict;
14use warnings;
15
16if ($#ARGV != 1) {
17 die "$0 [path to objdump] [path to vmlinux]\n";
18}
19
20# Have Kbuild supply the path to objdump so we handle cross compilation.
21my $objdump = shift;
22my $vmlinux = shift;
23my $bad_relocs_count = 0;
24my $bad_relocs = "";
25my $old_binutils = 0;
26
27open(FD, "$objdump -R $vmlinux|") or die;
28while (<FD>) {
29 study $_;
30
Paul Bolle8b055372013-05-29 09:18:28 +020031 # Only look at relocation lines.
Tony Breeds144ef902009-09-14 19:57:02 +000032 next if (!/\s+R_/);
33
34 # These relocations are okay
Suzuki Poulose9c5f7d32011-12-14 22:58:12 +000035 # On PPC64:
36 # R_PPC64_RELATIVE, R_PPC64_NONE, R_PPC64_ADDR64
37 # On PPC:
38 # R_PPC_RELATIVE, R_PPC_ADDR16_HI,
39 # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
40 # R_PPC_NONE
41
42 next if (/\bR_PPC64_RELATIVE\b/ or /\bR_PPC64_NONE\b/ or
43 /\bR_PPC64_ADDR64\s+mach_/);
44 next if (/\bR_PPC_ADDR16_LO\b/ or /\bR_PPC_ADDR16_HI\b/ or
45 /\bR_PPC_ADDR16_HA\b/ or /\bR_PPC_RELATIVE\b/ or
46 /\bR_PPC_NONE\b/);
Tony Breeds144ef902009-09-14 19:57:02 +000047
Paul Bolle8b055372013-05-29 09:18:28 +020048 # If we see this type of relocation it's an idication that
Tony Breeds144ef902009-09-14 19:57:02 +000049 # we /may/ be using an old version of binutils.
50 if (/R_PPC64_UADDR64/) {
51 $old_binutils++;
52 }
53
54 $bad_relocs_count++;
55 $bad_relocs .= $_;
56}
57
58if ($bad_relocs_count) {
59 print "WARNING: $bad_relocs_count bad relocations\n";
60 print $bad_relocs;
61}
62
63if ($old_binutils) {
Paul Bolle8b055372013-05-29 09:18:28 +020064 print "WARNING: You need at least binutils >= 2.19 to build a ".
65 "CONFIG_RELOCATABLE kernel\n";
Tony Breeds144ef902009-09-14 19:57:02 +000066}