]> git.sesse.net Git - rdpsrv/blob - Xserver/config/util/elistgen.usl
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / config / util / elistgen.usl
1 XCOMM!/bin/sh
2 XCOMM $XConsortium: elistgen.usl /main/2 1996/12/04 10:13:26 swick $
3 XCOMM
4 XCOMM #########################################################################
5 XCOMM Construct shared-library export lists for Novell based on standardized
6 XCOMM export list description file
7 XCOMM
8 XCOMM Usage: exportlistgen libFoo.so libFoo.elist > libFoo.lopt
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, "libFoo.lopt" may then be passed to the linker to 
14 XCOMM    reconstruct the shared library.
15 XCOMM
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.
23 XCOMM
24 XCOMM #########################################################################
25
26 XCOMM Utility programs
27 FILTER=CXXFILT                  # C++ symbol demangler
28 AWK=awk                         # awk
29
30 XCOMM For nm, cat, pr, expand, awk, c++filt
31 PATH=/usr/bin:/bin:/usr/ucb:/usr/ccs/bin
32
33 XCOMM Temporary files
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
37
38 XCOMM Print useful information at the top of the output
39 echo "#" `date`
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`
44 echo "# "
45
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.
49 nm -p $1 | $AWK '
50     / [TD] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
51 ' > $NMLIST
52
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
56
57 XCOMM Clean up the export-list description file.
58 XCOMM Note that C++ symbols may have embedded spaces in them.
59 cat $2 | $AWK '
60     BEGIN           {
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
66     }
67     $1 == "default" {
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";
72             next;
73         }
74         if (implicit != "")
75             print "# Warning: multiple default clauses." | "cat 1>&2";
76         implicit = $2;
77         next;
78     }
79     $1 == "force" || $1 == "public" || $1 == "private" {
80         csyms ++;
81         print $1 ";;" $2;
82         next;
83     }
84     $1 == "publicC++" || $1 == "privateC++" {
85         cplusplus ++;
86         string = $2;
87         for (n = 3; n <= NF; n++) {
88             string = string " " $n;
89         }
90         print $1 ";;" string;
91         next;
92     }
93     $1 == "internal" {
94         isyms ++;
95         print $1 ";;" $2;
96         next;
97     }
98     $1 == "internalC++" {
99         iplusplus ++;
100         string = $2;
101         for (n = 3; n <= NF; n++) {
102             string = string " " $n;
103         }
104         print $1 ";;" string;
105         next;
106     }
107     $1 == "#line" || $1 == "#" {
108         # cpp will have removed comments, but may have added other stuff.
109         next;
110     }
111     NF > 0 {
112         print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
113         next;
114     }
115     END  {
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;
121         }
122     }
123 ' > $EXPORTLIST
124
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 '
130     BEGIN {
131         FS = ";";
132         implicit = 0;
133     }
134     NF == 2 {
135         # This is "pr" output, i.e., symbol translation table
136         syms[$2] = $1;
137         next;
138     }
139     NF == 3 && $1 == "default" {
140         # Treatment of unspecified symbols.
141         if ($3 == "internal")
142             implicit = 1;
143         else if ($3 == "private" || $3 == "privateC++")
144             implicit = 2;
145         else if ($3 == "public" || $3 == "publicC++")
146             implicit = 3;
147         else # $3 == "force"
148             implicit = 4;
149         next;
150     }
151     NF == 3 {
152         # Parse our instructions for this symbol.
153         if ($1 == "internal" || $1 == "internalC++")
154             export = 1;
155         else if ($1 == "private" || $1 == "privateC++")
156             export = 2;
157         else if ($1 == "public" || $1 == "publicC++")
158             export = 3;
159         else # $1 == "force"
160             export = 4;
161
162         # Process it.
163         if (length(syms[$3]) > 0) {
164             # This symbol is present in the library.
165             if (donelist[$3])
166                 print "# Warning: Duplicate entry for", $3, 
167                     "in export list" | "cat 1>&2";
168             if (donelist[$3] < export) {
169                 if (export > 1)
170                     print syms[$3];
171                 donelist[$3] = export;
172             }
173         } else { 
174             # Do not complain about unknown forced-export symbols.
175             if (export == 4) {
176                 print $3;
177                 donelist[$3] = export;
178             } else
179                 print "# Warning:", $3,
180                     "was not in the nm list for this library" | "cat 1>&2";
181         }
182
183         next;
184     }
185     END { 
186         # Ignore built-in linker symbols.
187         if (implicit == 0) {
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;
198         }
199
200         # Process implicit symbols.
201         for (i in syms) {
202             if (!donelist[i] && (length(syms[i]) > 0)) {
203                 # Ignore C++ compiler symbols
204                 if (implicit == 0 &&
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";
209                 if (implicit > 1)
210                     print syms[i];
211             }
212         }
213     }
214 '
215
216 XCOMM Clean up temporary files
217 rm $EXPORTLIST
218 rm $NMLIST
219 rm $FILTLIST