2 XCOMM $XConsortium: elistgen.usl /main/2 1996/12/04 10:13:26 swick $
4 XCOMM #########################################################################
5 XCOMM Construct shared-library export lists for Novell based on standardized
6 XCOMM export list description file
8 XCOMM Usage: exportlistgen libFoo.so libFoo.elist > libFoo.lopt
10 XCOMM libFoo.so => shared library of interest
11 XCOMM libFoo.elist => Meta description of necessary export list.
13 XCOMM The output file, "libFoo.lopt" may then be passed to the linker to
14 XCOMM reconstruct the shared library.
16 XCOMM (c) Copyright 1996 Digital Equipment Corporation.
17 XCOMM (c) Copyright 1996 Hewlett-Packard Company.
18 XCOMM (c) Copyright 1996 International Business Machines Corp.
19 XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
20 XCOMM (c) Copyright 1996 Novell, Inc.
21 XCOMM (c) Copyright 1996 FUJITSU LIMITED.
22 XCOMM (c) Copyright 1996 Hitachi.
24 XCOMM #########################################################################
26 XCOMM Utility programs
27 FILTER=CXXFILT # C++ symbol demangler
30 XCOMM For nm, cat, pr, expand, awk, c++filt
31 PATH=/usr/bin:/bin:/usr/ucb:/usr/ccs/bin
34 EXPORTLIST=/tmp/elistgen1.$$ # list of export symbols from "libfoo.elist"
35 NMLIST=/tmp/elistgen2.$$ # name list from libfoo.sl
36 FILTLIST=/tmp/elistgen3.$$ # demangled (C++) version of NMLIST
38 XCOMM Print useful information at the top of the output
40 echo "# This linker options list was produced by" $0
41 echo "# Input export list description taken from:" $2
42 echo "# Target library:" $1
43 echo "# Target Operating System:" `uname -msrv`
46 XCOMM Extract the globally visible symbols from target library.
47 XCOMM The NMLIST generated here is later used to cross-check the symbols in the
48 XCOMM supplied export-list.
50 / [TD] [^\$]/{print $3} # Text, Data, BSS, or Secondary symbols
53 XCOMM Demangle the global library symbols. This operation is necessary to convert
54 XCOMM mangled C++ symbols into their C++ notation.
55 ${FILTER:-cat} $NMLIST > $FILTLIST
57 XCOMM Clean up the export-list description file.
58 XCOMM Note that C++ symbols may have embedded spaces in them.
61 csyms = 0; # C language symbols in libfoo.list
62 cplusplus = 0; # C++ language symbols in libfoo.list
63 isyms = 0; # C internal symbols in libfoo.elist
64 iplusplus = 0; # C++ internal symbols in libfoo.elist
65 implicit = ""; # Handling of implicit symbols
68 # A default clause suppresses warnings about implicit symbols.
69 if ($2 != "" && $2 != "force" && $2 != "public" &&
70 $2 != "private" && $2 != "internal") {
71 print "# Warning: illegal default clause:", $2 | "cat 1>&2";
75 print "# Warning: multiple default clauses." | "cat 1>&2";
79 $1 == "force" || $1 == "public" || $1 == "private" {
84 $1 == "publicC++" || $1 == "privateC++" {
87 for (n = 3; n <= NF; n++) {
88 string = string " " $n;
101 for (n = 3; n <= NF; n++) {
102 string = string " " $n;
104 print $1 ";;" string;
107 $1 == "#line" || $1 == "#" {
108 # cpp will have removed comments, but may have added other stuff.
112 print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
116 printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
117 csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
118 if (implicit != "") {
119 print "# Unspecified symbols are " implicit "." | "cat 1>&2";
120 print "default;;" implicit;
125 XCOMM Read in the above files and write result to stdout. The contents
126 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
127 XCOMM The contents of EXPORTLIST are converted with the help of this table.
128 XCOMM Use ";" as a delimiter in the symbol lookup table.
129 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST | expand -1; cat $EXPORTLIST) | $AWK '
135 # This is "pr" output, i.e., symbol translation table
139 NF == 3 && $1 == "default" {
140 # Treatment of unspecified symbols.
141 if ($3 == "internal")
143 else if ($3 == "private" || $3 == "privateC++")
145 else if ($3 == "public" || $3 == "publicC++")
152 # Parse our instructions for this symbol.
153 if ($1 == "internal" || $1 == "internalC++")
155 else if ($1 == "private" || $1 == "privateC++")
157 else if ($1 == "public" || $1 == "publicC++")
163 if (length(syms[$3]) > 0) {
164 # This symbol is present in the library.
166 print "# Warning: Duplicate entry for", $3,
167 "in export list" | "cat 1>&2";
168 if (donelist[$3] < export) {
171 donelist[$3] = export;
174 # Do not complain about unknown forced-export symbols.
177 donelist[$3] = export;
179 print "# Warning:", $3,
180 "was not in the nm list for this library" | "cat 1>&2";
186 # Ignore built-in linker symbols.
188 if (!donelist["_DYNAMIC"])
189 donelist["_DYNAMIC"] = 1;
190 if (!donelist["_GLOBAL_OFFSET_TABLE_"])
191 donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
192 if (!donelist["_edata"])
193 donelist["_edata"] = 1;
194 if (!donelist["_end"])
195 donelist["_end"] = 1;
196 if (!donelist["_etext"])
197 donelist["_etext"] = 1;
200 # Process implicit symbols.
202 if (!donelist[i] && (length(syms[i]) > 0)) {
203 # Ignore C++ compiler symbols
205 (syms[i] !~ /^__vtbl__[0-9]*_/) &&
206 (syms[i] !~ /^__cpp_unixware_[0-9]*$/))
207 print "# Warning:", syms[i],
208 "was not in the export list" | "cat 1>&2";
216 XCOMM Clean up temporary files