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