check-initfini.awk 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2018-2019 Free Software Foundation, Inc.
  2. # This file is part of the GNU C Library.
  3. # The GNU C Library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Lesser General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2.1 of the License, or (at your option) any later version.
  7. # The GNU C Library is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. # Lesser General Public License for more details.
  11. # You should have received a copy of the GNU Lesser General Public
  12. # License along with the GNU C Library; if not, see
  13. # <http://www.gnu.org/licenses/>.
  14. # This awk script expects to get command-line files that are each
  15. # the output of 'readelf -W --dyn-syms' on a single shared object.
  16. # It exits successfully (0) if none contained _init nor _fini in dynamic
  17. # symbol table.
  18. # It fails (1) if any did contain _init or _fini in dynamic symbol table.
  19. # It fails (2) if the input did not take the expected form.
  20. BEGIN { result = _init = _fini = sanity = 0 }
  21. function check_one(name) {
  22. if (!sanity) {
  23. print name ": *** input did not look like readelf -d output";
  24. result = 2;
  25. } else {
  26. ok = 1;
  27. if (_init) {
  28. print name ": *** _init is in dynamic symbol table";
  29. result = result ? result : 1;
  30. ok = 0;
  31. }
  32. if (_fini) {
  33. print name ": *** _fini is in dynamic symbol table";
  34. result = result ? result : 1;
  35. ok = 0;
  36. }
  37. if (ok)
  38. print name ": OK";
  39. }
  40. _init = _fini = sanity = 0
  41. }
  42. FILENAME != lastfile {
  43. if (lastfile)
  44. check_one(lastfile);
  45. lastfile = FILENAME;
  46. }
  47. $1 == "Symbol" && $2 == "table" && $3 == "'.dynsym'" { sanity = 1 }
  48. $8 == "_init" { _init = 1 }
  49. $8 == "_fini" { _fini = 1 }
  50. END {
  51. check_one(lastfile);
  52. exit(result);
  53. }