]> git.sesse.net Git - rdpsrv/blob - Xserver/config/util/elistgen.hp
Support RDP5 logon packets.
[rdpsrv] / Xserver / config / util / elistgen.hp
1 XCOMM!/bin/sh
2 XCOMM $XConsortium: elistgen.hp /main/2 1996/12/04 10:13:14 swick $
3 XCOMM
4 XCOMM #########################################################################
5 XCOMM Construct shared-library export lists for HP-UX based on standardized
6 XCOMM export list description file
7 XCOMM
8 XCOMM Usage: exportlistgen libfoo.sl libfoo.elist > libfoo.lopt
9 XCOMM
10 XCOMM   libfoo.sl    => shared library of interest
11 XCOMM   libfoo.elist => Meta description of necessary export list.
12 XCOMM
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.
19 XCOMM
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.
28 XCOMM
29 XCOMM #########################################################################
30
31 XCOMM Utility programs
32 FILTER=CXXFILT                  # C++ symbol demangler
33 AWK=awk                         # awk
34 PATH=/usr/bin:/bin:/usr/ucb     # For nm, cat, pr, expand, awk, c++filt
35
36 XCOMM Temporary files
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
40
41 XCOMM Print useful information at the top of the output
42 echo "#" `date`
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`
47 echo "# "
48
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.
52 XCOMM
53 nm -p $1 | $AWK '
54     / [cCTDB][S ] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
55 ' > $NMLIST
56
57 XCOMM Demangle the global library symbols. This operation is necessary to
58 XCOMM convert mangled C++ symbols into their C++ notation.
59 ${FILTER:-cat} $NMLIST > $FILTLIST
60
61 XCOMM
62 XCOMM Cleanup the export-list description file.
63 XCOMM Note that C++ symbols may have embedded spaces in them.
64 XCOMM
65 cat $2 | $AWK '
66     BEGIN           {
67         csyms      = 0;         # C   language symbols in libfoo.list
68         cplusplus  = 0;         # C++ language symbols in libfoo.list
69         isyms      = 0;         # C   internal symbols in libfoo.elist
70         icplusplus = 0;         # C++ internal symbols in libfoo.elist
71         implicit = "";          # Handling of implicit symbols.
72     }
73     $1 == "default" {
74         # A default clause suppresses warnings about implicit symbols.
75         if ($2 != "" && $2 != "force" && $2 != "public" && 
76             $2 != "private" && $2 != "internal") {
77             print "# Warning: illegal default clause:", $2 | "cat 1>&2";
78             next;
79         }
80         if (implicit != "")
81             print "# Warning: multiple default clauses." | "cat 1>&2";
82         implicit = $2;
83         next;
84     }
85     $1 == "force" || $1 == "public" || $1 == "private" {
86         csyms ++;
87         print $1 ";;" $2;
88         next;
89     }
90     $1 == "publicC++" || $1 == "privateC++" {
91         cplusplus ++;
92         string = $2;
93         for (n = 3; n <= NF; n++)
94             string = string " " $n;
95         print $1 ";;" string;
96         next;
97     }
98     $1 == "internal" {
99         isyms ++;
100         print $1 ";;" $2;
101         next;
102     }
103     $1 == "internalC++" {
104         icplusplus ++;
105         string = $2;
106         for (n = 3; n <= NF; n++)
107             string = string " " $n;
108         print $1 ";;" string;
109         next;
110     }
111     END  {
112         printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
113                 csyms, cplusplus, isyms, icplusplus) | "cat 1>&2";
114         if (implicit != "") {
115             print "# Unspecified symbols are " implicit "." | "cat 1>&2";
116             print "default;;" implicit;
117         }
118     }
119 ' > $EXPORTLIST
120
121 XCOMM Read in the above files and write result to stdout.  The contents
122 XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
123 XCOMM The contents of EXPORTLIST are converted with the help of this table.
124 XCOMM Use ";" as a delimiter in the symbol lookup table.
125 XCOMM
126 (pr -m -s";" -t -w1024 $NMLIST $FILTLIST| expand -t 1;cat $EXPORTLIST ) | $AWK '
127     BEGIN {
128         FS = ";";
129         implicit = 0;
130     }
131     NF == 2 {
132         # This is "pr" output, i.e., symbol translation table.
133         syms[$2] = $1;
134         next;
135     }
136     NF == 3 && $1 == "default" {
137         # Treatment of unspecified symbols.
138         if ($3 == "internal" || $3 == "internalC++")
139             implicit = 1;
140         else if ($3 == "private" || $3 == "privateC++")
141             implicit = 2;
142         else if ($3 == "public" || $3 == "publicC++")
143             implicit = 3;
144         else # $3 == "force"
145             implicit = 4;
146         next;
147     }
148     NF == 3 {
149         # Parse our instructions for this symbol.
150         if ($1 == "internal" || $1 == "internalC++")
151             export = 1;
152         else if ($1 == "private" || $1 == "privateC++")
153             export = 2;
154         else if ($1 == "public" || $1 == "publicC++")
155             export = 3;
156         else # $1 == "force"
157             export = 4;
158
159         # Process it.
160         if (length(syms[$3]) > 0) {
161             if (donelist[$3])
162                 print "# Warning: Duplicate entry for", $3,
163                         "in export list" | "cat 1>&2";
164             if (donelist[$3] < export)
165                 donelist[$3] = export;
166         } else {
167             if (export == 4)
168                 donelist[$3] = export;
169             else
170                 print "# Warning:", $3,
171                     "was not in the nm list for this library" | "cat 1>&2";
172         }
173         next;
174     }
175     END {
176         # Force implicit exporting of errno.
177         if (! donelist["errno"])
178             donelist["errno"] = 4;
179
180         # Complain about some implicit symbols.
181         for (i in syms) {
182             if (!donelist[i] && (length(syms[i]) > 0)) {
183                 # Ignore automatic symbols generated by the C++ compiler.
184                 if (implicit == 0 && 
185                     (syms[i] !~ /^__noperfopt__/) &&
186                     (syms[i] !~ /^__ptbl_vec__/) &&
187                     (syms[i] !~ /^__vtbl__[0-9]*_/) &&
188                     (syms[i] !~ /^__cfront_version_[0-9]*_xxxxxxxx$/))
189                     print "# Warning:", syms[i],
190                           "was not in the export list" | "cat 1>&2";
191                 donelist[i] = implicit;
192             }
193             if ((donelist[i] > 1) && (length(syms[i]) > 0))
194                 print "-e", syms[i];
195         }
196     }
197 '
198
199 XCOMM Clean up temporary files
200 rm $EXPORTLIST
201 rm $NMLIST
202 rm $FILTLIST