]> git.sesse.net Git - rdpsrv/blob - Xserver/config/util/elistgen.sun
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / config / util / elistgen.sun
1 XCOMM!/bin/sh -f
2 XCOMM $XConsortium: exportlistgen.sun /main/3 1996/10/11 13:54:11 swick $
3 XCOMM
4 XCOMM ########################################################################
5 XCOMM Construct shared-library scoping mapfile for Solaris based on standardized
6 XCOMM export list description file
7 XCOMM
8 XCOMM Usage: exportlistgen libfoo.so libfoo.elist > mapfile.scope
9 XCOMM
10 XCOMM   libfoo.so    => shared library of interest
11 XCOMM   libfoo.elist => Meta description of necessary export list.
12 XCOMM
13 XCOMM    The output file, "mapfile.scope" may then be passed to the Solaris 
14 XCOMM    linker to reconstruct the shared library, libfoo.so.
15 XCOMM
16 XCOMM ########################################################################
17
18 XCOMM Utility programs
19 FILTER=CXXFILT                  # C++ symbol demangler
20 AWK=awk                         # Awk
21
22 XCOMM For nm, cat, pr, expand, awk, c++filt
23 PATH=/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/opt/SUNWspro/bin
24
25 XCOMM Try to detect broken versions of c++filt.
26 if [ `echo _okay | ${FILTER:-cat}` != "_okay" ]; then
27     if [ -x /opt/SUNWspro/bin/c++filt ]; then
28         echo "# Your $FILTER is broken -- using /opt/SUNWspro/bin/c++filt."
29         FILTER=/opt/SUNWspro/bin/c++filt
30     else
31         echo "# ERROR: no working $FILTER available."
32         exit 1
33     fi;
34 fi;
35
36 XCOMM Temporary files
37 EXPORTLIST=/tmp/elistgen1.$$    # export directives from "libfoo.list"
38 NMLIST=/tmp/elistgen2.$$        # name list from libfoo.sl
39 FILTLIST=/tmp/elistgen3.$$      # demangled (C++) version of above
40
41 XCOMM Print useful information at the top of the output
42 echo "#" `date`
43 echo "# This scoping mapfile was produced by" $0
44 echo "# Export list description taken from:" $2
45 echo "# Target library:" $1
46 echo "# Target Operating System:" `uname -msrv`
47 echo "# "
48
49 XCOMM Extract the globally visible symbols from target library
50 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
51 nm -p $1 | $AWK '/ [ TDBS] /{print $3}' > $NMLIST
52
53 XCOMM Extract the globally visible symbols from target library
54 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
55 ${FILTER:-cat} $NMLIST > $FILTLIST
56
57 XCOMM Clean up the export-list description file.  Sort the directives.
58 $AWK '
59     BEGIN {
60         csyms     = 0;  # C   public symbols in libfoo.list
61         cplusplus = 0;  # C++ public symbols in libfoo.list
62         isyms     = 0;  # C   internal symbols in libfoo.list
63         iplusplus = 0;  # C++ internal symbols in libfoo.list
64         implicit  = ""; # Handling of implicit symbols
65     }
66     $1 == "default" {
67         # A default clause suppresses warnings about implicit symbols.
68         if ($2 != "" && $2 != "force" && $2 != "public" && $2 != "private" && $2 != "internal") {
69             print "# Warning: illegal default clause:", $2 | "cat 1>&2";
70             next;
71         }
72         if (implicit != "")
73             print "# Warning: multiple default clauses." | "cat 1>&2";
74         implicit = $2;
75         next;
76     }
77     $1 == "force" {
78         csyms ++;
79         print $1 ";;" $2;
80         next;
81     }
82     $1 == "public" {
83         csyms ++;
84         print $1 ";;" $2;
85         next;
86     }
87     $1 == "publicC++" {
88         cplusplus ++;
89         string = $2;
90         for (n = 3; n <= NF; n++)
91             string = string " " $n;
92         print $1 ";;" string;
93         next;
94     }
95     $1 == "private" {
96         csyms ++;
97         print $1 ";;" $2;
98         next;
99     }
100     $1 == "privateC++" {
101         cplusplus ++;
102         string = $2;
103         for (n = 3; n <= NF; n++)
104             string = string " " $n;
105         print $1 ";;" string;
106         next;
107     }
108     $1 == "internal" {
109         isyms ++;
110         print $1 ";;" $2;
111         next;
112     }
113     $1 == "internalC++" {
114         iplusplus ++;
115         string = $2;
116         for (n = 3; n <= NF; n++)
117             string = string " " $n;
118         print $1 ";;" string;
119         next;
120     }
121     $1 == "#line" || $1 == "#" {
122         # cpp will have removed comments, but may have added other stuff.
123         next;
124     }
125     NF > 0 {
126         print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
127         next;
128     }
129     END {
130         printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n", csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
131         if (implicit != "") {
132             print "# Unspecified symbols are " implicit "." | "cat 1>&2";
133             print "default;;" implicit;
134         }
135     }
136 ' $2 1>$EXPORTLIST
137
138
139 XCOMM Read in the above files and write result to stdout.  The contents
140 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
141 XCOMM The contents of EXPORTLIST are converted with the help of this table.
142 XCOMM Use ";" as a delimiter in the symbol lookup table.
143 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
144     BEGIN {
145         FS = ";";
146         implicit = 0;
147     }
148     NF == 2 {
149         # This is "pr" output, i.e., symbol translation table
150         syms[$2] = $1;
151         next;
152     }
153     NF == 3 && $1 == "default" {
154         # Treatment of unspecified symbols.
155         if ($3 == "internal" || $3 == "internalC++")
156             implicit = 1;
157         else if ($3 == "private" || $3 == "privateC++")
158             implicit = 2;
159         else if ($3 == "public" || $3 == "publicC++")
160             implicit = 3;
161         else # $3 == "force"
162             implicit = 4;
163         next;
164     }
165     NF == 3 {
166         # An export directive.  Parse our instructions for this symbol.
167         if ($1 == "internal" || $1 == "internalC++")
168             export = 1;
169         else if ($3 == "private" || $3 == "privateC++")
170             export = 2;
171         else if ($3 == "public" || $3 == "publicC++")
172             export = 3;
173         else # $3 == "force"
174             export = 4;
175
176         if (length(syms[$3]) > 0) {
177             if (donelist[$3])
178                 print "# Warning: Duplicate entry for", $3, "in export list" | "cat 1>&2";
179             if (donelist[$3] < export)
180                 donelist[$3] = export;
181         } else { 
182             if (export == 4)
183                 donelist[$3] = export;
184             else
185                 print "# Warning:", $3, "was not in the nm list for this library" | "cat 1>&2";
186         }
187         next;
188     }
189     END { 
190         # Ignore magic linker symbols.
191         if (implicit == 0) {
192             if (!donelist["_DYNAMIC"])
193                 donelist["_DYNAMIC"] = 1;
194             if (!donelist["_GLOBAL_OFFSET_TABLE_"])
195                 donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
196             if (!donelist["_PROCEDURE_LINKAGE_TABLE_"])
197                 donelist["_PROCEDURE_LINKAGE_TABLE_"] = 1;
198             if (!donelist["_edata"])
199                 donelist["_edata"] = 1;
200             if (!donelist["_end"])
201                 donelist["_end"] = 1;
202             if (!donelist["_etext"])
203                 donelist["_etext"] = 1;
204         }
205
206         # Process implicit symbols.
207         for (i in syms) {
208             if (donelist[i] == 0 && length(syms[i]) > 0) {
209                 if (implicit == 0) {
210                     # Ignore magic symbols introduced by the C++ compiler.
211                     if ((syms[i] !~ /^__vtbl__[0-9]*_/) && (syms[i] !~ /^__ptbl_vec__/))
212                         print "# Warning:", syms[i], "was not in the export list" | "cat 1>&2";
213                 } else {
214                     donelist[i] = implicit;
215                 }
216             }
217         }
218
219         # Generate the linker file.
220         print "";
221         print "SUNW.1.1 {";
222         print "    global:";
223         for (i in syms)
224             if (donelist[i] >= 2 && length(syms[i]) > 0)
225                 print "        " syms[i] ";";
226         print "    local:";
227         print "        *;";
228         print "};";
229
230         print "";
231         print "SUNW_private.1.1 {";
232         print "    global:";
233         for (i in syms)
234             if (donelist[i] == 1 && length(syms[i]) > 0)
235                 print "        " syms[i] ";";
236         print "} SUNW.1.1;"
237     }
238 '
239
240 XCOMM Clean up temporary files
241 rm $EXPORTLIST
242 rm $NMLIST
243 rm $FILTLIST