2 XCOMM $XConsortium: exportlistgen.sun /main/3 1996/10/11 13:54:11 swick $
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 nm -p $1 | $AWK '/ [ TDBS] /{print $3}' > $NMLIST
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
57 XCOMM Clean up the export-list description file. Sort the directives.
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
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";
73 print "# Warning: multiple default clauses." | "cat 1>&2";
90 for (n = 3; n <= NF; n++)
91 string = string " " $n;
103 for (n = 3; n <= NF; n++)
104 string = string " " $n;
105 print $1 ";;" string;
113 $1 == "internalC++" {
116 for (n = 3; n <= NF; n++)
117 string = string " " $n;
118 print $1 ";;" string;
121 $1 == "#line" || $1 == "#" {
122 # cpp will have removed comments, but may have added other stuff.
126 print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
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;
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 '
149 # This is "pr" output, i.e., symbol translation table
153 NF == 3 && $1 == "default" {
154 # Treatment of unspecified symbols.
155 if ($3 == "internal" || $3 == "internalC++")
157 else if ($3 == "private" || $3 == "privateC++")
159 else if ($3 == "public" || $3 == "publicC++")
166 # An export directive. Parse our instructions for this symbol.
167 if ($1 == "internal" || $1 == "internalC++")
169 else if ($3 == "private" || $3 == "privateC++")
171 else if ($3 == "public" || $3 == "publicC++")
176 if (length(syms[$3]) > 0) {
178 print "# Warning: Duplicate entry for", $3, "in export list" | "cat 1>&2";
179 if (donelist[$3] < export)
180 donelist[$3] = export;
183 donelist[$3] = export;
185 print "# Warning:", $3, "was not in the nm list for this library" | "cat 1>&2";
190 # Ignore magic linker symbols.
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;
206 # Process implicit symbols.
208 if (donelist[i] == 0 && length(syms[i]) > 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";
214 donelist[i] = implicit;
219 # Generate the linker file.
224 if (donelist[i] >= 2 && length(syms[i]) > 0)
225 print " " syms[i] ";";
231 print "SUNW_private.1.1 {";
234 if (donelist[i] == 1 && length(syms[i]) > 0)
235 print " " syms[i] ";";
240 XCOMM Clean up temporary files