mkmap-flat.awk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Generate a flat list of symbols to export.
  2. # Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. # Contributed by Richard Henderson <rth@cygnus.com>
  4. #
  5. # This file is part of GCC.
  6. #
  7. # GCC is free software; you can redistribute it and/or modify it under
  8. # the terms of the GNU General Public License as published by the Free
  9. # Software Foundation; either version 3, or (at your option) any later
  10. # version.
  11. #
  12. # GCC is distributed in the hope that it will be useful, but WITHOUT
  13. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  15. # License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GCC; see the file COPYING3. If not see
  19. # <http://www.gnu.org/licenses/>.
  20. # Options:
  21. # "-v leading_underscore=1" : Symbols in map need leading underscore.
  22. # "-v pe_dll=1" : Create .DEF file for Windows PECOFF
  23. # DLL link instead of map file.
  24. BEGIN {
  25. state = "nm";
  26. excluding = 0;
  27. if (leading_underscore)
  28. prefix = "_";
  29. else
  30. prefix = "";
  31. }
  32. # Remove comment and blank lines.
  33. /^ *#/ || /^ *$/ {
  34. next;
  35. }
  36. # We begin with nm input. Collect the set of symbols that are present
  37. # so that we can elide undefined symbols.
  38. state == "nm" && /^%%/ {
  39. state = "ver";
  40. next;
  41. }
  42. state == "nm" && ($1 == "U" || $2 == "U") {
  43. next;
  44. }
  45. state == "nm" && NF == 3 {
  46. def[$3] = 1;
  47. next;
  48. }
  49. state == "nm" {
  50. next;
  51. }
  52. # Now we process a simplified variant of the Solaris symbol version
  53. # script. We have one symbol per line, no semicolons, simple markers
  54. # for beginning and ending each section, and %inherit markers for
  55. # describing version inheritance. A symbol may appear in more than
  56. # one symbol version, and the last seen takes effect.
  57. # The magic version name '%exclude' causes all the symbols given that
  58. # version to be dropped from the output (unless a later version overrides).
  59. NF == 3 && $1 == "%inherit" {
  60. next;
  61. }
  62. NF == 2 && $2 == "{" {
  63. if ($1 == "%exclude")
  64. excluding = 1;
  65. next;
  66. }
  67. $1 == "}" {
  68. excluding = 0;
  69. next;
  70. }
  71. {
  72. sym = prefix $1;
  73. if (excluding)
  74. delete export[sym];
  75. else
  76. export[sym] = 1;
  77. next;
  78. }
  79. END {
  80. if (pe_dll) {
  81. print "LIBRARY " pe_dll;
  82. print "EXPORTS";
  83. }
  84. for (sym in export)
  85. if (def[sym] || (pe_dll && def["_" sym]))
  86. print sym;
  87. }