relocs_check.pl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/perl
  2. # Copyright © 2009 IBM Corporation
  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. # This script checks the relcoations of a vmlinux for "suspicious"
  8. # relocations.
  9. use strict;
  10. use warnings;
  11. if ($#ARGV != 1) {
  12. die "$0 [path to objdump] [path to vmlinux]\n";
  13. }
  14. # Have Kbuild supply the path to objdump so we handle cross compilation.
  15. my $objdump = shift;
  16. my $vmlinux = shift;
  17. my $bad_relocs_count = 0;
  18. my $bad_relocs = "";
  19. my $old_binutils = 0;
  20. open(FD, "$objdump -R $vmlinux|") or die;
  21. while (<FD>) {
  22. study $_;
  23. # Only look at relcoation lines.
  24. next if (!/\s+R_/);
  25. # These relocations are okay
  26. # On PPC64:
  27. # R_PPC64_RELATIVE, R_PPC64_NONE, R_PPC64_ADDR64
  28. # On PPC:
  29. # R_PPC_RELATIVE, R_PPC_ADDR16_HI,
  30. # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
  31. # R_PPC_NONE
  32. next if (/\bR_PPC64_RELATIVE\b/ or /\bR_PPC64_NONE\b/ or
  33. /\bR_PPC64_ADDR64\s+mach_/);
  34. next if (/\bR_PPC_ADDR16_LO\b/ or /\bR_PPC_ADDR16_HI\b/ or
  35. /\bR_PPC_ADDR16_HA\b/ or /\bR_PPC_RELATIVE\b/ or
  36. /\bR_PPC_NONE\b/);
  37. # If we see this type of relcoation it's an idication that
  38. # we /may/ be using an old version of binutils.
  39. if (/R_PPC64_UADDR64/) {
  40. $old_binutils++;
  41. }
  42. $bad_relocs_count++;
  43. $bad_relocs .= $_;
  44. }
  45. if ($bad_relocs_count) {
  46. print "WARNING: $bad_relocs_count bad relocations\n";
  47. print $bad_relocs;
  48. }
  49. if ($old_binutils) {
  50. print "WARNING: You need at binutils >= 2.19 to build a ".
  51. "CONFIG_RELCOATABLE kernel\n";
  52. }