mkmap-symver.awk 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Generate an ELF symbol version map a-la Solaris and GNU ld.
  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. BEGIN {
  21. state = "nm";
  22. sawsymbol = 0;
  23. if (leading_underscore)
  24. prefix = "_";
  25. else
  26. prefix = "";
  27. }
  28. # Remove comment and blank lines.
  29. /^ *#/ || /^ *$/ {
  30. next;
  31. }
  32. # We begin with nm input. Collect the set of symbols that are present
  33. # so that we can not emit them into the final version script -- Solaris
  34. # complains at us if we do.
  35. state == "nm" && /^%%/ {
  36. state = "ver";
  37. next;
  38. }
  39. state == "nm" && ($1 == "U" || $2 == "U") {
  40. next;
  41. }
  42. state == "nm" && NF == 3 {
  43. split ($3, s, "@")
  44. def[s[1]] = 1;
  45. sawsymbol = 1;
  46. next;
  47. }
  48. state == "nm" {
  49. next;
  50. }
  51. # Now we process a simplified variant of the Solaris symbol version
  52. # script. We have one symbol per line, no semicolons, simple markers
  53. # for beginning and ending each section, and %inherit markers for
  54. # describing version inheritance. A symbol may appear in more than
  55. # one symbol version, and the last seen takes effect.
  56. # The magic version name '%exclude' causes all the symbols given that
  57. # version to be dropped from the output (unless a later version overrides).
  58. NF == 3 && $1 == "%inherit" {
  59. inherit[$2] = $3;
  60. next;
  61. }
  62. NF == 2 && $2 == "{" {
  63. if ($1 != "%exclude")
  64. libs[$1] = 1;
  65. thislib = $1;
  66. next;
  67. }
  68. $1 == "}" {
  69. thislib = "";
  70. next;
  71. }
  72. {
  73. sym = prefix $1;
  74. symbols[sym] = 1
  75. if (thislib != "%exclude")
  76. ver[sym, thislib] = 1;
  77. else {
  78. for (l in libs)
  79. ver[sym, l] = 0;
  80. }
  81. next;
  82. }
  83. END {
  84. if (!sawsymbol)
  85. {
  86. print "No symbols seen -- broken or mis-installed nm?" | "cat 1>&2";
  87. exit 1;
  88. }
  89. for (l in libs)
  90. output(l);
  91. }
  92. function output(lib) {
  93. if (done[lib])
  94. return;
  95. done[lib] = 1;
  96. if (inherit[lib])
  97. output(inherit[lib]);
  98. empty=1
  99. for (sym in symbols)
  100. if ((ver[sym, lib] != 0) && (sym in def))
  101. {
  102. if (empty)
  103. {
  104. printf("%s {\n", lib);
  105. printf(" global:\n");
  106. empty = 0;
  107. }
  108. printf("\t%s;\n", sym);
  109. }
  110. if (empty)
  111. {
  112. for (l in libs)
  113. if (inherit[l] == lib)
  114. inherit[l] = inherit[lib];
  115. }
  116. else if (inherit[lib])
  117. printf("} %s;\n", inherit[lib]);
  118. else
  119. printf ("\n local:\n\t*;\n};\n");
  120. }