check-localplt.awk 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # This is an awk script to process the output of elf/check-localplt.
  2. # The first file argument is the file of expected results.
  3. # Each line is either a comment starting with # or it looks like:
  4. # libfoo.so: function
  5. # or
  6. # libfoo.so: function + {RELA|REL} RELOC
  7. # or
  8. # libfoo.so: function ?
  9. # The first entry means that one is required.
  10. # The second entry means that one is required and relocation may also be
  11. # {RELA|REL} RELOC.
  12. # The third entry means that a PLT entry for function is optional in
  13. # libfoo.so.
  14. # The second file argument is - and this (stdin) receives the output
  15. # of the check-localplt program.
  16. BEGIN { result = 0 }
  17. FILENAME != "-" && /^#/ { next }
  18. FILENAME != "-" {
  19. if (NF == 5 && $3 == "+" && ($4 == "RELA" || $4 == "REL")) {
  20. accept_type[$1 " " $2] = $4;
  21. accept_reloc[$1 " " $2] = $5;
  22. } else if (NF != 2 && !(NF == 3 && $3 == "?")) {
  23. printf "%s:%d: bad data line: %s\n", FILENAME, FNR, $0 > "/dev/stderr";
  24. result = 2;
  25. } else {
  26. accept[$1 " " $2] = NF == 2;
  27. }
  28. next;
  29. }
  30. NF != 2 && !(NF == 4 && ($3 == "RELA" || $3 == "REL")) {
  31. print "Unexpected output from check-localplt:", $0 > "/dev/stderr";
  32. result = 2;
  33. next
  34. }
  35. {
  36. key = $1 " " $2
  37. if ($3 == "RELA" || $3 == "REL") {
  38. # Entries like:
  39. # libc.so: free + RELA R_X86_64_GLOB_DAT
  40. # may be ignored.
  41. if (key in accept_type && accept_type[key] == $3 && accept_reloc[key] == $4) {
  42. # Match
  43. # libc.so: free + RELA R_X86_64_GLOB_DAT
  44. delete accept_type[key]
  45. }
  46. } else if (NF == 2 && key in accept_reloc) {
  47. # Match
  48. # libc.so: free
  49. # against
  50. # libc.so: free + RELA R_X86_64_GLOB_DAT
  51. if (key in accept_type)
  52. delete accept_type[key]
  53. } else if (key in accept) {
  54. delete accept[key]
  55. } else {
  56. print "Extra PLT reference:", $0;
  57. if (result == 0)
  58. result = 1;
  59. }
  60. }
  61. END {
  62. for (key in accept) {
  63. if (accept[key]) {
  64. # It's mandatory.
  65. print "Missing required PLT reference:", key;
  66. result = 1;
  67. }
  68. }
  69. for (key in accept_type) {
  70. # It's mandatory.
  71. print "Missing required PLT or " accept_reloc[key] " reference:", key;
  72. result = 1;
  73. }
  74. exit(result);
  75. }