aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/config/util/elistgen.usl
blob: f17bcdb22ba796966d63658a7fcf0d852bb1b561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
XCOMM!/bin/sh
XCOMM $Xorg: elistgen.usl,v 1.3 2000/08/17 19:41:52 cpqbld Exp $
XCOMM
XCOMM #########################################################################
XCOMM Construct shared-library export lists for Novell based on standardized
XCOMM export list description file
XCOMM
XCOMM Usage: exportlistgen libFoo.so libFoo.elist > libFoo.lopt
XCOMM
XCOMM	libFoo.so    => shared library of interest
XCOMM	libFoo.elist => Meta description of necessary export list.
XCOMM
XCOMM    The output file, "libFoo.lopt" may then be passed to the linker to 
XCOMM    reconstruct the shared library.
XCOMM
XCOMM (c) Copyright 1996 Digital Equipment Corporation.
XCOMM (c) Copyright 1996 Hewlett-Packard Company.
XCOMM (c) Copyright 1996 International Business Machines Corp.
XCOMM (c) Copyright 1996 Sun Microsystems, Inc.
XCOMM (c) Copyright 1996 Novell, Inc. 
XCOMM (c) Copyright 1996 FUJITSU LIMITED.
XCOMM (c) Copyright 1996 Hitachi.
XCOMM
XCOMM #########################################################################
XCOMM
XCOMM $XFree86$

XCOMM Utility programs
FILTER=CXXFILT			# C++ symbol demangler
AWK=awk				# awk

XCOMM For nm, cat, pr, sed, awk, c++filt
PATH=/usr/bin:/bin:/usr/ucb:/usr/ccs/bin

XCOMM Temporary files
EXPORTLIST=/tmp/elistgen1.$$	# list of export symbols from "libfoo.elist"
NMLIST=/tmp/elistgen2.$$	# name list from libfoo.sl
FILTLIST=/tmp/elistgen3.$$	# demangled (C++) version of NMLIST

XCOMM Print useful information at the top of the output
echo "#" `date`
echo "# This linker options list was produced by" $0
echo "# Input export list description taken from:" $2
echo "# Target library:" $1
echo "# Target Operating System:" `uname -msrv`
echo "# "

XCOMM Extract the globally visible symbols from target library.
XCOMM The NMLIST generated here is later used to cross-check the symbols in the
XCOMM supplied export-list.
nm -p $1 | $AWK '
    / [TD] [^\$]/{print $3}   # Text, Data, BSS, or Secondary symbols
' > $NMLIST

XCOMM Demangle the global library symbols. This operation is necessary to convert
XCOMM mangled C++ symbols into their C++ notation.
${FILTER:-cat} $NMLIST > $FILTLIST

XCOMM Clean up the export-list description file.
XCOMM Note that C++ symbols may have embedded spaces in them.
cat $2 | $AWK '
    BEGIN           {
	csyms     = 0;		# C   language symbols in libfoo.list
	cplusplus = 0;		# C++ language symbols in libfoo.list
	isyms     = 0;		# C   internal symbols in libfoo.elist
	iplusplus = 0;		# C++ internal symbols in libfoo.elist
	implicit  = "";		# Handling of implicit symbols
    }
    $1 == "default" {
	# A default clause suppresses warnings about implicit symbols.
	if ($2 != "" && $2 != "force" && $2 != "public" && 
	    $2 != "private" && $2 != "internal") {
	    print "# Warning: illegal default clause:", $2 | "cat 1>&2";
	    next;
	}
	if (implicit != "")
	    print "# Warning: multiple default clauses." | "cat 1>&2";
        implicit = $2;
	next;
    }
    $1 == "force" || $1 == "public" || $1 == "private" {
	csyms ++;
	print $1 ";;" $2;
	next;
    }
    $1 == "publicC++" || $1 == "privateC++" {
	cplusplus ++;
	string = $2;
	for (n = 3; n <= NF; n++) {
	    string = string " " $n;
	}
	print $1 ";;" string;
	next;
    }
    $1 == "internal" {
	isyms ++;
	print $1 ";;" $2;
	next;
    }
    $1 == "internalC++" {
	iplusplus ++;
	string = $2;
	for (n = 3; n <= NF; n++) {
	    string = string " " $n;
	}
	print $1 ";;" string;
	next;
    }
    $1 == "#line" || $1 == "#" {
	# cpp will have removed comments, but may have added other stuff.
	next;
    }
    NF > 0 {
	print "# Warning: unrecognized directive:", $0 | "cat 1>&2";
	next;
    }
    END  {
	printf("# Exporting %d C and %d C++ symbols, hiding %d and %d.\n",
			    csyms, cplusplus, isyms, iplusplus) | "cat 1>&2";
	if (implicit != "") {
	    print "# Unspecified symbols are " implicit "." | "cat 1>&2";
	    print "default;;" implicit;
	}
    }
' > $EXPORTLIST

XCOMM Read in the above files and write result to stdout.  The contents
XCOMM of NMLIST and FILTLIST are used to construct a symbol lookup table.
XCOMM The contents of EXPORTLIST are converted with the help of this table.
XCOMM Use ";" as a delimiter in the symbol lookup table.
(pr -m -s";" -t -w1024 $NMLIST $FILTLIST | sed 's/      / /g'; cat $EXPORTLIST) | $AWK '
    BEGIN {
	FS = ";";
	implicit = 0;
    }
    NF == 2 {
	# This is "pr" output, i.e., symbol translation table
	syms[$2] = $1;
	next;
    }
    NF == 3 && $1 == "default" {
	# Treatment of unspecified symbols.
	if ($3 == "internal")
	    implicit = 1;
	else if ($3 == "private" || $3 == "privateC++")
	    implicit = 2;
	else if ($3 == "public" || $3 == "publicC++")
	    implicit = 3;
	else # $3 == "force"
	    implicit = 4;
        next;
    }
    NF == 3 {
	# Parse our instructions for this symbol.
	if ($1 == "internal" || $1 == "internalC++")
	    export = 1;
	else if ($1 == "private" || $1 == "privateC++")
	    export = 2;
	else if ($1 == "public" || $1 == "publicC++")
	    export = 3;
	else # $1 == "force"
	    export = 4;

	# Process it.
	if (length(syms[$3]) > 0) {
	    # This symbol is present in the library.
	    if (donelist[$3])
		print "# Warning: Duplicate entry for", $3, 
		    "in export list" | "cat 1>&2";
	    if (donelist[$3] < export) {
		if (export > 1)
		    print syms[$3];
		donelist[$3] = export;
	    }
	} else { 
	    # Do not complain about unknown forced-export symbols.
	    if (export == 4) {
		print $3;
		donelist[$3] = export;
	    } else
		print "# Warning:", $3,
		    "was not in the nm list for this library" | "cat 1>&2";
	}

	next;
    }
    END { 
	# Ignore built-in linker symbols.
	if (implicit == 0) {
	    if (!donelist["_DYNAMIC"])
		donelist["_DYNAMIC"] = 1;
	    if (!donelist["_GLOBAL_OFFSET_TABLE_"])
		donelist["_GLOBAL_OFFSET_TABLE_"] = 1;
	    if (!donelist["_edata"])
		donelist["_edata"] = 1;
	    if (!donelist["_end"])
		donelist["_end"] = 1;
	    if (!donelist["_etext"])
		donelist["_etext"] = 1;
	}

	# Process implicit symbols.
	for (i in syms) {
	    if (!donelist[i] && (length(syms[i]) > 0)) {
		# Ignore C++ compiler symbols
		if (implicit == 0 &&
		    (syms[i] !~ /^__vtbl__[0-9]*_/) &&
		    (syms[i] !~ /^__cpp_unixware_[0-9]*$/))
		    print "# Warning:", syms[i],
		          "was not in the export list" | "cat 1>&2";
	        if (implicit > 1)
		    print syms[i];
	    }
	}
    }
'

XCOMM Clean up temporary files
rm $EXPORTLIST
rm $NMLIST
rm $FILTLIST