mkmap-symver.awk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Generate an ELF symbol version map a-la Solaris and GNU ld.
  2. # Copyright (C) 2007-2022 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 cannot 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. if (skip_underscore && substr(s[1], 1, 1) == "_")
  45. symname = substr(s[1], 2);
  46. else
  47. symname = s[1];
  48. def[symname] = 1;
  49. sawsymbol = 1;
  50. next;
  51. }
  52. state == "nm" {
  53. next;
  54. }
  55. # Now we process a simplified variant of the Solaris symbol version
  56. # script. We have one symbol per line, no semicolons, simple markers
  57. # for beginning and ending each section, and %inherit markers for
  58. # describing version inheritance. A symbol may appear in more than
  59. # one symbol version, and the last seen takes effect.
  60. # The magic version name '%exclude' causes all the symbols given that
  61. # version to be dropped from the output (unless a later version overrides).
  62. NF == 3 && $1 == "%inherit" {
  63. inherit[$2] = $3;
  64. next;
  65. }
  66. NF == 2 && $2 == "{" {
  67. if ($1 != "%exclude")
  68. libs[$1] = 1;
  69. thislib = $1;
  70. next;
  71. }
  72. $1 == "}" {
  73. thislib = "";
  74. next;
  75. }
  76. {
  77. sym = prefix $1;
  78. symbols[sym] = 1
  79. if (thislib != "%exclude")
  80. ver[sym, thislib] = 1;
  81. else {
  82. for (l in libs)
  83. ver[sym, l] = 0;
  84. }
  85. next;
  86. }
  87. END {
  88. if (!sawsymbol)
  89. {
  90. print "No symbols seen -- broken or mis-installed nm?" | "cat 1>&2";
  91. exit 1;
  92. }
  93. for (l in libs)
  94. output(l);
  95. }
  96. function output(lib) {
  97. if (done[lib])
  98. return;
  99. done[lib] = 1;
  100. if (inherit[lib])
  101. output(inherit[lib]);
  102. empty=1
  103. for (sym in symbols)
  104. if ((ver[sym, lib] != 0) && (sym in def))
  105. {
  106. if (empty)
  107. {
  108. printf("%s {\n", lib);
  109. printf(" global:\n");
  110. empty = 0;
  111. }
  112. printf("\t%s;\n", sym);
  113. }
  114. if (empty)
  115. {
  116. for (l in libs)
  117. if (inherit[l] == lib)
  118. inherit[l] = inherit[lib];
  119. }
  120. else if (inherit[lib])
  121. printf("} %s;\n", inherit[lib]);
  122. else
  123. printf ("\n local:\n\t*;\n};\n");
  124. }