1*c87b03e5Sespie# Generate an ELF symbol version map a-la Solaris and GNU ld. 2*c87b03e5Sespie# Contributed by Richard Henderson <rth@cygnus.com> 3*c87b03e5Sespie# 4*c87b03e5Sespie# This file is part of GCC. 5*c87b03e5Sespie# 6*c87b03e5Sespie# GCC is free software; you can redistribute it and/or modify it under 7*c87b03e5Sespie# the terms of the GNU General Public License as published by the Free 8*c87b03e5Sespie# Software Foundation; either version 2, or (at your option) any later 9*c87b03e5Sespie# version. 10*c87b03e5Sespie# 11*c87b03e5Sespie# GCC is distributed in the hope that it will be useful, but WITHOUT 12*c87b03e5Sespie# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13*c87b03e5Sespie# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14*c87b03e5Sespie# License for more details. 15*c87b03e5Sespie# 16*c87b03e5Sespie# You should have received a copy of the GNU General Public License 17*c87b03e5Sespie# along with GCC; see the file COPYING. If not, write to the Free 18*c87b03e5Sespie# Software Foundation, 59 Temple Place - Suite 330, Boston MA 19*c87b03e5Sespie# 02111-1307, USA. 20*c87b03e5Sespie 21*c87b03e5SespieBEGIN { 22*c87b03e5Sespie state = "nm"; 23*c87b03e5Sespie sawsymbol = 0; 24*c87b03e5Sespie} 25*c87b03e5Sespie 26*c87b03e5Sespie# Remove comment and blank lines. 27*c87b03e5Sespie/^ *#/ || /^ *$/ { 28*c87b03e5Sespie next; 29*c87b03e5Sespie} 30*c87b03e5Sespie 31*c87b03e5Sespie# We begin with nm input. Collect the set of symbols that are present 32*c87b03e5Sespie# so that we can not emit them into the final version script -- Solaris 33*c87b03e5Sespie# complains at us if we do. 34*c87b03e5Sespie 35*c87b03e5Sespiestate == "nm" && /^%%/ { 36*c87b03e5Sespie state = "ver"; 37*c87b03e5Sespie next; 38*c87b03e5Sespie} 39*c87b03e5Sespie 40*c87b03e5Sespiestate == "nm" && ($1 == "U" || $2 == "U") { 41*c87b03e5Sespie next; 42*c87b03e5Sespie} 43*c87b03e5Sespie 44*c87b03e5Sespiestate == "nm" && NF == 3 { 45*c87b03e5Sespie def[$3] = 1; 46*c87b03e5Sespie sawsymbol = 1; 47*c87b03e5Sespie next; 48*c87b03e5Sespie} 49*c87b03e5Sespie 50*c87b03e5Sespiestate == "nm" { 51*c87b03e5Sespie next; 52*c87b03e5Sespie} 53*c87b03e5Sespie 54*c87b03e5Sespie# Now we process a simplified variant of the Solaris symbol version 55*c87b03e5Sespie# script. We have one symbol per line, no semicolons, simple markers 56*c87b03e5Sespie# for beginning and ending each section, and %inherit markers for 57*c87b03e5Sespie# describing version inheritence. A symbol may appear in more than 58*c87b03e5Sespie# one symbol version, and the last seen takes effect. 59*c87b03e5Sespie 60*c87b03e5SespieNF == 3 && $1 == "%inherit" { 61*c87b03e5Sespie inherit[$2] = $3; 62*c87b03e5Sespie next; 63*c87b03e5Sespie} 64*c87b03e5Sespie 65*c87b03e5SespieNF == 2 && $2 == "{" { 66*c87b03e5Sespie libs[$1] = 1; 67*c87b03e5Sespie thislib = $1; 68*c87b03e5Sespie next; 69*c87b03e5Sespie} 70*c87b03e5Sespie 71*c87b03e5Sespie$1 == "}" { 72*c87b03e5Sespie thislib = ""; 73*c87b03e5Sespie next; 74*c87b03e5Sespie} 75*c87b03e5Sespie 76*c87b03e5Sespie{ 77*c87b03e5Sespie ver[$1] = thislib; 78*c87b03e5Sespie next; 79*c87b03e5Sespie} 80*c87b03e5Sespie 81*c87b03e5SespieEND { 82*c87b03e5Sespie if (!sawsymbol) 83*c87b03e5Sespie { 84*c87b03e5Sespie print "No symbols seen -- broken or mis-installed nm?" | "cat 1>&2"; 85*c87b03e5Sespie exit 1; 86*c87b03e5Sespie } 87*c87b03e5Sespie for (l in libs) 88*c87b03e5Sespie output(l); 89*c87b03e5Sespie} 90*c87b03e5Sespie 91*c87b03e5Sespiefunction output(lib) { 92*c87b03e5Sespie if (done[lib]) 93*c87b03e5Sespie return; 94*c87b03e5Sespie done[lib] = 1; 95*c87b03e5Sespie if (inherit[lib]) 96*c87b03e5Sespie output(inherit[lib]); 97*c87b03e5Sespie 98*c87b03e5Sespie empty=1 99*c87b03e5Sespie for (sym in ver) 100*c87b03e5Sespie if ((ver[sym] == lib) && (sym in def)) 101*c87b03e5Sespie { 102*c87b03e5Sespie if (empty) 103*c87b03e5Sespie { 104*c87b03e5Sespie printf("%s {\n", lib); 105*c87b03e5Sespie printf(" global:\n"); 106*c87b03e5Sespie empty = 0; 107*c87b03e5Sespie } 108*c87b03e5Sespie printf("\t%s;\n", sym); 109*c87b03e5Sespie if (dotsyms) 110*c87b03e5Sespie printf("\t.%s;\n", sym); 111*c87b03e5Sespie } 112*c87b03e5Sespie 113*c87b03e5Sespie if (empty) 114*c87b03e5Sespie { 115*c87b03e5Sespie for (l in libs) 116*c87b03e5Sespie if (inherit[l] == lib) 117*c87b03e5Sespie inherit[l] = inherit[lib]; 118*c87b03e5Sespie } 119*c87b03e5Sespie else if (inherit[lib]) 120*c87b03e5Sespie printf("} %s;\n", inherit[lib]); 121*c87b03e5Sespie else 122*c87b03e5Sespie printf ("\n local:\n\t*;\n};\n"); 123*c87b03e5Sespie} 124