check-textrel.awk 952 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # This awk script expects to get command-line files that are each
  2. # the output of 'readelf -d' on a single shared object.
  3. # It exits successfully (0) if none contained any TEXTREL markers.
  4. # It fails (1) if any did contain a TEXTREL marker.
  5. # It fails (2) if the input did not take the expected form.
  6. BEGIN { result = textrel = sanity = 0 }
  7. function check_one(name) {
  8. if (!sanity) {
  9. print name ": *** input did not look like readelf -d output";
  10. result = 2;
  11. } else if (textrel) {
  12. print name ": *** text relocations used";
  13. result = result ? result : 1;
  14. } else {
  15. print name ": OK";
  16. }
  17. textrel = sanity = 0;
  18. }
  19. FILENAME != lastfile {
  20. if (lastfile)
  21. check_one(lastfile);
  22. lastfile = FILENAME;
  23. }
  24. $1 == "Tag" && $2 == "Type" { sanity = 1 }
  25. $2 == "(TEXTREL)" { textrel = 1 }
  26. $2 == "(FLAGS)" {
  27. for (i = 3; i <= NF; ++i) {
  28. if ($i == "TEXTREL")
  29. textrel = 1;
  30. }
  31. }
  32. END {
  33. check_one(lastfile);
  34. exit(result);
  35. }