2 XCOMM $TOG: elistgen.sun /main/9 1999/09/07 17:54:17 mgreess $
4 XCOMM ########################################################################
5 XCOMM Construct shared-library scoping mapfile for Solaris based on standardized
6 XCOMM export list description file
8 XCOMM Usage: exportlistgen libfoo.so libfoo.elist > mapfile.scope
10 XCOMM libfoo.so => shared library of interest
11 XCOMM libfoo.elist => Meta description of necessary export list.
13 XCOMM The output file, "mapfile.scope" may then be passed to the Solaris
14 XCOMM linker to reconstruct the shared library, libfoo.so.
16 XCOMM ########################################################################
18 XCOMM Utility programs
19 FILTER=CXXFILT # C++ symbol demangler
22 XCOMM For nm, cat, pr, expand, awk, c++filt
23 PATH=/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/opt/SUNWspro/bin
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
31 echo "# ERROR: no working $FILTER available."
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
41 XCOMM Print useful information at the top of the output
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`
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 XCOMM nm stopped working on Solaris 2.5, use dump instead.
52 XCOMM nm -p $1 | $AWK '/ [ TDBS] /{print $3}' > $NMLIST
53 /usr/ccs/bin/dump -t -v $1 | egrep "(FUNC|OBJT).(GLOB|WEAK)" | egrep -v "(FUNC|OBJT).(GLOB|WEAK). *[0-9]. *UNDEF" | $AWK '{print $8}' > $NMLIST
55 XCOMM Extract the globally visible symbols from target library
56 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
57 ${FILTER:-cat} $NMLIST > $FILTLIST
59 XCOMM Clean up the export-list description file. Sort the directives.
62 csyms = 0; # C public symbols in libfoo.list
63 cplusplus = 0; # C++ public symbols in libfoo.list
64 isyms = 0; # C internal symbols in libfoo.list
65 iplusplus = 0; # C++ internal symbols in libfoo.list
66 implicit = ""; # Handling of implicit symbols
69 # A default clause suppresses warnings about implicit symbols.
70 if ($2 != "" && $2 != "force" && $2 != "public" && $2 != "private" && $2 != "internal") {
71 print "# Warning: illegal default clause:", $2 | "cat 1>&2";
75 print "# Warning: multiple default clauses." | "cat 1>&2";
92 for (n = 3; n <= NF; n++)
93 string = string " " $n;
105 for (n = 3; n <= NF; n++)
106 string = string " " $n;
107 print $1 ";;" string;
115 $1 == "internalC++" {
118 for (n = 3; n <= NF; n++)
119 string = string " " $n;
120 print $1 ";;" string;
123 $1 == "#line" || $1 == "#" {
124 # cpp will have removed comments, but may have added other stuff.
128 print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
132 printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n", csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
133 if (implicit != "") {
134 print "# Unspecified symbols are " implicit "." | "cat 1>&2";
135 print "default;;" implicit;
141 XCOMM Read in the above files and write result to stdout. The contents
142 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
143 XCOMM The contents of EXPORTLIST are converted with the help of this table.
144 XCOMM Use ";" as a delimiter in the symbol lookup table.
145 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
151 # This is "pr" output, i.e., symbol translation table
153 gsub(/static /,"",r2); # remove keyword "static" as above
154 gsub(/ /,"",r2); # Remove spaces because c++filt is unpredictable
158 mangled[r1] = 1; # Save the mangling because the export lists
159 # sometimes use it instead of a prototype.
162 NF == 3 && $1 == "default" {
163 # Treatment of unspecified symbols.
164 if ($3 == "internal" || $3 == "internalC++")
166 else if ($3 == "private" || $3 == "privateC++")
168 else if ($3 == "public" || $3 == "publicC++")
175 # Generate canonical demangled form as an alternate symbol.
177 gsub(/ \.\.\./,",...",alt); # change " ..." to ",..." to match c++filt
178 gsub(/ /,"",alt); # remove all spaces
180 # An export directive. Parse our instructions for this symbol.
181 if ($1 == "internal" || $1 == "internalC++")
183 else if ($3 == "private" || $3 == "privateC++")
185 else if ($3 == "public" || $3 == "publicC++")
191 if ((length(syms[alt]) > 0) || mangled[alt]) {
192 # This symbol is present in the library.
194 print "# Warning: Duplicate entry for", $3,
195 "in export list" | "cat 1>&2";
196 if (donelist[alt] < export) {
197 donelist[alt] = export;
200 # Print forced-export symbols without complaining.
202 donelist[alt] = export;
204 print "# Warning:", $3,
205 "was not in the nm list for this library" | "cat 1>&2";
212 # Ignore magic linker symbols.
214 if (!donelist["_DYNAMIC"])
215 donelist["_DYNAMIC"] = 1;
216 if (!donelist["_GLOBAL_OFFSET_TABLE_"])
217 donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
218 if (!donelist["_PROCEDURE_LINKAGE_TABLE_"])
219 donelist["_PROCEDURE_LINKAGE_TABLE_"] = 1;
220 if (!donelist["_edata"])
221 donelist["_edata"] = 1;
222 if (!donelist["_end"])
223 donelist["_end"] = 1;
224 if (!donelist["_etext"])
225 donelist["_etext"] = 1;
228 # Process implicit symbols.
230 if (donelist[i] == 0 && length(syms[i]) > 0) {
232 # Ignore magic symbols introduced by the C++ compiler.
233 if ((syms[i] !~ /[_a-zA-Z0-9]*__vtbl$/) &&
234 (syms[i] !~ /libC_errors/) &&
235 (syms[i] !~ /_ex_/) &&
236 (syms[i] !~ /__rt/) &&
237 (syms[i] !~ /__RT/) &&
238 (syms[i] !~ /^__ptbl_vec__/))
239 print "# Warning:", syms[i], "was not in the export list" | "cat 1>&2";
241 donelist[i] = implicit;
246 # Generate the linker file.
251 if (donelist[i] >= 2 && length(syms[i]) > 0)
252 print " " syms[i] ";";
258 print "SUNW_private.1.1 {";
261 if (donelist[i] == 1 && length(syms[i]) > 0)
262 print " " syms[i] ";";
267 XCOMM Clean up temporary files