2 XCOMM $TOG: elistgen.hp /main/5 1999/04/16 13:54:01 mgreess $
4 XCOMM #########################################################################
5 XCOMM Construct shared-library export lists for HP-UX based on standardized
6 XCOMM export list description file
8 XCOMM Usage: exportlistgen libfoo.sl libfoo.elist > libfoo.lopt
10 XCOMM libfoo.sl => shared library of interest
11 XCOMM libfoo.elist => Meta description of necessary export list.
13 XCOMM The output may then be passed to the linker to reconstruct the
14 XCOMM shared library. For unknown reasons naming only exported symbols
15 XCOMM with "+e" does not work for debuggable C++ code, even though "nm"
16 XCOMM reports no difference between the resulting libraries. The linker
17 XCOMM complains that "first non-inline virtual function" is not defined for
18 XCOMM vtables. We instead hide internal symbols with "-h" as a work-around.
20 XCOMM Author: Aloke Gupta 5/25/94.
21 XCOMM (c) Copyright 1996 Digital Equipment Corporation.
22 XCOMM (c) Copyright 1994,1996 Hewlett-Packard Company.
23 XCOMM (c) Copyright 1996 International Business Machines Corp.
24 XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
25 XCOMM (c) Copyright 1996 Novell, Inc.
26 XCOMM (c) Copyright 1996 FUJITSU LIMITED.
27 XCOMM (c) Copyright 1996 Hitachi.
29 XCOMM #########################################################################
31 XCOMM Utility programs
32 FILTER=CXXFILT # C++ symbol demangler
34 PATH=/usr/bin:/bin:/usr/ucb # For nm, cat, pr, expand, awk, c++filt
37 EXPORTLIST=/tmp/elistgen1.$$ # list of export symbols from "libfoo.elist"
38 NMLIST=/tmp/elistgen2.$$ # name list from libfoo.sl
39 FILTLIST=/tmp/elistgen3.$$ # demangled (C++) version of NMLIST
41 XCOMM Print useful information at the top of the output
43 echo "# This linker options list was produced by" $0
44 echo "# Input 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 supplied export-list.
54 / [cCTDB][S ] [^\$]/{print $3} # Text, Data, BSS, or Secondary symbols
55 ' | uniq > $NMLIST.all
58 / [uU][S ] [^\$]/{print $3} # Text, Data, BSS, or Secondary symbols
59 ' | uniq > $NMLIST.undef
61 cat $NMLIST.all $NMLIST.undef $NMLIST.undef | sort | uniq -c | $AWK '{if ($1=="1") print $2}' > $NMLIST
64 XCOMM nm -p $1 | $AWK '
65 XCOMM / [cCTDB][S ] [^\$]/{print $3} # Text, Data, BSS, or Secondary symbols
68 XCOMM Demangle the global library symbols. This operation is necessary to
69 XCOMM convert mangled C++ symbols into their C++ notation.
70 ${FILTER:-cat} $NMLIST > $FILTLIST
73 XCOMM Cleanup the export-list description file.
74 XCOMM Note that C++ symbols may have embedded spaces in them.
78 csyms = 0; # C language symbols in libfoo.list
79 cplusplus = 0; # C++ language symbols in libfoo.list
80 isyms = 0; # C internal symbols in libfoo.elist
81 icplusplus = 0; # C++ internal symbols in libfoo.elist
82 implicit = ""; # Handling of implicit symbols.
85 # A default clause suppresses warnings about implicit symbols.
86 if ($2 != "" && $2 != "force" && $2 != "public" &&
87 $2 != "private" && $2 != "internal") {
88 print "# Warning: illegal default clause:", $2 | "cat 1>&2";
92 print "# Warning: multiple default clauses." | "cat 1>&2";
96 $1 == "force" || $1 == "public" || $1 == "private" {
101 $1 == "publicC++" || $1 == "privateC++" {
104 for (n = 3; n <= NF; n++)
105 string = string " " $n;
106 print $1 ";;" string;
114 $1 == "internalC++" {
117 for (n = 3; n <= NF; n++)
118 string = string " " $n;
119 print $1 ";;" string;
123 printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
124 csyms, cplusplus, isyms, icplusplus) | "cat 1>&2";
125 if (implicit != "") {
126 print "# Unspecified symbols are " implicit "." | "cat 1>&2";
127 print "default;;" implicit;
132 XCOMM Read in the above files and write result to stdout. The contents
133 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
134 XCOMM The contents of EXPORTLIST are converted with the help of this table.
135 XCOMM Use ";" as a delimiter in the symbol lookup table.
137 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST| expand -t 1;cat $EXPORTLIST ) | $AWK '
143 # This is "pr" output, i.e., symbol translation table.
147 NF == 3 && $1 == "default" {
148 # Treatment of unspecified symbols.
149 if ($3 == "internal" || $3 == "internalC++")
151 else if ($3 == "private" || $3 == "privateC++")
153 else if ($3 == "public" || $3 == "publicC++")
160 # Parse our instructions for this symbol.
161 if ($1 == "internal" || $1 == "internalC++")
163 else if ($1 == "private" || $1 == "privateC++")
165 else if ($1 == "public" || $1 == "publicC++")
171 if (length(syms[$3]) > 0) {
173 print "# Warning: Duplicate entry for", $3,
174 "in export list" | "cat 1>&2";
175 if (donelist[$3] < export)
176 donelist[$3] = export;
179 donelist[$3] = export;
181 print "# Warning:", $3,
182 "was not in the nm list for this library" | "cat 1>&2";
187 # Force implicit exporting of errno.
188 if (! donelist["errno"])
189 donelist["errno"] = 4;
191 # Complain about some implicit symbols.
193 if (!donelist[i] && (length(syms[i]) > 0)) {
194 # Ignore automatic symbols generated by the C++ compiler.
196 (syms[i] !~ /^__noperfopt__/) &&
197 (syms[i] !~ /^__ptbl_vec__/) &&
198 (syms[i] !~ /^__vtbl__[0-9]*_/) &&
199 (syms[i] !~ /^__cfront_version_[0-9]*_xxxxxxxx$/))
200 print "# Warning:", syms[i],
201 "was not in the export list" | "cat 1>&2";
202 donelist[i] = implicit;
204 if ((donelist[i] > 1) && (length(syms[i]) > 0))
210 XCOMM Clean up temporary files