]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/make-syscalls.sh
Remove PREPARE_VERSION and PREPARE_VERSION_KNOW
[thirdparty/glibc.git] / sysdeps / unix / make-syscalls.sh
1 #!/bin/sh
2
3 # Usage: make-syscalls.sh ../sysdeps/unix/common
4 # Expects $sysdirs in environment.
5
6 ##############################################################################
7 #
8 # This script is used to process the syscall data encoded in the various
9 # syscalls.list files to produce thin assembly syscall wrappers around the
10 # appropriate OS syscall. See syscall-template.S for more details on the
11 # actual wrapper.
12 #
13 # Syscall Signature Prefixes:
14 #
15 # E: errno and return value are not set by the call
16 # V: errno is not set, but errno or zero (success) is returned from the call
17 #
18 # Syscall Signature Key Letters:
19 #
20 # a: unchecked address (e.g., 1st arg to mmap)
21 # b: non-NULL buffer (e.g., 2nd arg to read; return value from mmap)
22 # B: optionally-NULL buffer (e.g., 4th arg to getsockopt)
23 # f: buffer of 2 ints (e.g., 4th arg to socketpair)
24 # F: 3rd arg to fcntl
25 # i: scalar (any signedness & size: int, long, long long, enum, whatever)
26 # I: 3rd arg to ioctl
27 # n: scalar buffer length (e.g., 3rd arg to read)
28 # N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
29 # p: non-NULL pointer to typed object (e.g., any non-void* arg)
30 # P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
31 # s: non-NULL string (e.g., 1st arg to open)
32 # S: optionally-NULL string (e.g., 1st arg to acct)
33 # v: vararg scalar (e.g., optional 3rd arg to open)
34 # V: byte-per-page vector (3rd arg to mincore)
35 # W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)
36 #
37
38 ##############################################################################
39
40 thisdir=$1; shift
41
42 echo ''
43 echo \#### DIRECTORY = $thisdir
44 # Check each sysdep dir with higher priority than this one,
45 # and remove from $calls all the functions found in other dirs.
46 # Punt when we reach the directory defining these syscalls.
47 sysdirs=`for dir in $sysdirs; do
48 test $dir = $thisdir && break; echo $dir; done`
49 echo \#### SYSDIRS = $sysdirs
50
51 # Get the list of system calls for this directory.
52 calls=`sed 's/#.*$//
53 /^[ ]*$/d' $thisdir/syscalls.list`
54
55 calls=`echo "$calls" |
56 while read file caller rest; do
57 # Remove each syscall that is implemented by a file in $dir.
58 # If a syscall specified a "caller", then only compile that syscall
59 # if the caller function is also implemented in this directory.
60 srcfile=-;
61 for dir in $sysdirs; do
62 { test -f $dir/$file.c && srcfile=$dir/$file.c; } ||
63 { test -f $dir/$file.S && srcfile=$dir/$file.S; } ||
64 { test x$caller != x- &&
65 { { test -f $dir/$caller.c && srcfile=$dir/$caller.c; } ||
66 { test -f $dir/$caller.S && srcfile=$dir/$caller.S; }; }; } && break;
67 done;
68 echo $file $srcfile $caller $rest;
69 done`
70
71 # Any calls left?
72 test -n "$calls" || exit 0
73
74 # This uses variables $weak, $strong, and $any_versioned.
75 emit_weak_aliases()
76 {
77 # A shortcoming in the current gas is that it will only allow one
78 # version-alias per symbol. So we create new strong aliases as needed.
79 vcount=""
80
81 # We use the <shlib-compat.h> macros to generate the versioned aliases
82 # so that the version sets can be mapped to the configuration's
83 # minimum version set as per shlib-versions DEFAULT lines. If an
84 # entry point is specified in the form NAME@VERSION:OBSOLETED, a
85 # SHLIB_COMPAT conditional is generated.
86 if [ $any_versioned = t ]; then
87 echo " echo '#include <shlib-compat.h>'; \\"
88 fi
89
90 for name in $weak; do
91 case $name in
92 *@@*)
93 base=`echo $name | sed 's/@@.*//'`
94 ver=`echo $name | sed 's/.*@@//;s/\./_/g'`
95 echo " echo '#if IS_IN (libc)'; \\"
96 if test -z "$vcount" ; then
97 source=$strong
98 vcount=1
99 else
100 source="${strong}_${vcount}"
101 vcount=`expr $vcount + 1`
102 echo " echo 'strong_alias ($strong, $source)'; \\"
103 fi
104 echo " echo 'versioned_symbol (libc, $source, $base, $ver)'; \\"
105 echo " echo '#else'; \\"
106 echo " echo 'weak_alias ($strong, $base)'; \\"
107 echo " echo '#endif'; \\"
108 ;;
109 *@*)
110 base=`echo $name | sed 's/@.*//'`
111 ver=`echo $name | sed 's/.*@//;s/\./_/g'`
112 case $ver in
113 *:*)
114 compat_ver=${ver#*:}
115 ver=${ver%%:*}
116 compat_cond=" && SHLIB_COMPAT (libc, $ver, $compat_ver)"
117 ;;
118 *)
119 compat_cond=
120 ;;
121 esac
122 echo " echo '#if defined SHARED && IS_IN (libc)$compat_cond'; \\"
123 if test -z "$vcount" ; then
124 source=$strong
125 vcount=1
126 else
127 source="${strong}_${vcount}"
128 vcount=`expr $vcount + 1`
129 echo " echo 'strong_alias ($strong, $source)'; \\"
130 fi
131 echo " echo 'compat_symbol (libc, $source, $base, $ver)'; \\"
132 echo " echo '#endif'; \\"
133 ;;
134 !*)
135 name=`echo $name | sed 's/.//'`
136 echo " echo 'strong_alias ($strong, $name)'; \\"
137 echo " echo 'hidden_def ($name)'; \\"
138 ;;
139 *)
140 echo " echo 'weak_alias ($strong, $name)'; \\"
141 echo " echo 'hidden_weak ($name)'; \\"
142 ;;
143 esac
144 done
145 }
146
147
148 # Emit rules to compile the syscalls remaining in $calls.
149 echo "$calls" |
150 while read file srcfile caller syscall args strong weak; do
151
152 vdso_syscall=
153 case x"$syscall" in
154 *:*@*)
155 vdso_syscall="${syscall#*:}"
156 syscall="${syscall%:*}"
157 ;;
158 esac
159
160 case x"$syscall" in
161 x-) callnum=_ ;;
162 *)
163 # Figure out if $syscall is defined with a number in syscall.h.
164 callnum=-
165 eval `{ echo "#include <sysdep.h>";
166 echo "callnum=SYS_ify ($syscall)"; } |
167 $asm_CPP -D__OPTIMIZE__ - |
168 sed -n -e "/^callnum=.*$syscall/d" \
169 -e "/^\(callnum=\)[ ]*\(.*\)/s//\1'\2'/p"`
170 ;;
171 esac
172
173 noerrno=0
174 errval=0
175 case $args in
176 E*) noerrno=1; args=`echo $args | sed 's/E:\?//'`;;
177 V*) errval=1; args=`echo $args | sed 's/V:\?//'`;;
178 esac
179
180 # Derive the number of arguments from the argument signature
181 case $args in
182 [0-9]) nargs=$args;;
183 ?:) nargs=0;;
184 ?:?) nargs=1;;
185 ?:??) nargs=2;;
186 ?:???) nargs=3;;
187 ?:????) nargs=4;;
188 ?:?????) nargs=5;;
189 ?:??????) nargs=6;;
190 ?:???????) nargs=7;;
191 ?:????????) nargs=8;;
192 ?:?????????) nargs=9;;
193 esac
194
195 # Make sure only the first syscall rule is used, if multiple dirs
196 # define the same syscall.
197 echo ''
198 echo "#### CALL=$file NUMBER=$callnum ARGS=$args SOURCE=$srcfile"
199
200 # If there are versioned aliases the entry is only generated for the
201 # shared library, unless it is a default version.
202 any_versioned=f
203 shared_only=f
204 case $weak in
205 *@@*) any_versioned=t ;;
206 *@*) any_versioned=t shared_only=t ;;
207 esac
208
209 case x$srcfile"$callnum" in
210 x--)
211 # Undefined callnum for an extra syscall.
212 if [ x$caller != x- ]; then
213 if [ $noerrno != 0 ]; then
214 echo >&2 "$0: no number for $fileno, no-error syscall ($strong $weak)"
215 exit 2
216 fi
217 echo "unix-stub-syscalls += $strong $weak"
218 fi
219 ;;
220 x*-) ;; ### Do nothing for undefined callnum
221 x-*)
222 echo "ifeq (,\$(filter $file,\$(unix-syscalls)))"
223
224 if test $shared_only = t; then
225 # The versioned symbols are only in the shared library.
226 echo "ifneq (,\$(filter .os,\$(object-suffixes)))"
227 fi
228 # Accumulate the list of syscall files for this directory.
229 echo "unix-syscalls += $file"
230 test x$caller = x- || echo "unix-extra-syscalls += $file"
231
232 # Emit a compilation rule for this syscall.
233 if test $shared_only = t; then
234 # The versioned symbols are only in the shared library.
235 echo "shared-only-routines += $file"
236 test -n "$vdso_syscall" || echo "\$(objpfx)${file}.os: \\"
237 else
238 object_suffixes='$(object-suffixes)'
239 test -z "$vdso_syscall" || object_suffixes='$(object-suffixes-noshared)'
240 echo "\
241 \$(foreach p,\$(sysd-rules-targets),\
242 \$(foreach o,${object_suffixes},\$(objpfx)\$(patsubst %,\$p,$file)\$o)): \\"
243 fi
244
245 echo " \$(..)sysdeps/unix/make-syscalls.sh"
246 case x"$callnum" in
247 x_)
248 echo "\
249 \$(make-target-directory)
250 (echo '/* Dummy module requested by syscalls.list */'; \\"
251 ;;
252 x*)
253 echo "\
254 \$(make-target-directory)
255 (echo '#define SYSCALL_NAME $syscall'; \\
256 echo '#define SYSCALL_NARGS $nargs'; \\
257 echo '#define SYSCALL_SYMBOL $strong'; \\
258 echo '#define SYSCALL_NOERRNO $noerrno'; \\
259 echo '#define SYSCALL_ERRVAL $errval'; \\
260 echo '#include <syscall-template.S>'; \\"
261 ;;
262 esac
263
264 # Append any weak aliases or versions defined for this syscall function.
265 emit_weak_aliases
266
267 # And finally, pipe this all into the compiler.
268 echo ' ) | $(compile-syscall) '"\
269 \$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))"
270
271 if test -n "$vdso_syscall"; then
272 # In the shared library, we're going to emit an IFUNC using a vDSO function.
273 # $vdso_syscall looks like "name@KERNEL_X.Y" where "name" is the symbol
274 # name in the vDSO and KERNEL_X.Y is its symbol version.
275 vdso_symbol="${vdso_syscall%@*}"
276 vdso_symver="${vdso_syscall#*@}"
277 vdso_symver=`echo "$vdso_symver" | sed 's/\./_/g'`
278 cat <<EOF
279
280 \$(foreach p,\$(sysd-rules-targets),\$(objpfx)\$(patsubst %,\$p,$file).os): \\
281 \$(..)sysdeps/unix/make-syscalls.sh
282 \$(make-target-directory)
283 (echo '#define ${strong} __redirect_${strong}'; \\
284 echo '#include <dl-vdso.h>'; \\
285 echo '#undef ${strong}'; \\
286 echo '#define vdso_ifunc_init()'; \\
287 echo '__ifunc (__redirect_${strong}, ${strong},'; \\
288 echo ' get_vdso_symbol ("${vdso_symbol}"), void,'; \\
289 echo ' vdso_ifunc_init)'; \\
290 EOF
291 # This is doing "hidden_def (${strong})", but the compiler
292 # doesn't know that we've defined ${strong} in the same file, so
293 # we can't do it the normal way.
294 cat <<EOF
295 echo 'asm (".globl __GI_${strong}");'; \\
296 echo 'asm ("__GI_${strong} = ${strong}");'; \\
297 EOF
298 emit_weak_aliases
299 cat <<EOF
300 ) | \$(compile-stdin.c) \
301 \$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))
302 EOF
303 fi
304
305 if test $shared_only = t; then
306 # The versioned symbols are only in the shared library.
307 echo endif
308 fi
309
310 echo endif
311 ;;
312 esac
313
314 done