blob: 1770d1df983448c4b2a070cebce26ab329e22e5a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001# Copyright (C) 1991-2015 Free Software Foundation, Inc.
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
8
9# The GNU C Library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# Lesser General Public License for more details.
13
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, see
16# <http://www.gnu.org/licenses/>.
17
18ifndef inhibit-unix-syscalls
19
20# Sysdep dirs unix/... can contain a file syscalls.list,
21# which specifies objects to be compiled as simple Unix system calls.
22
23-include $(common-objpfx)sysd-syscalls
24
25ifeq (misc,$(subdir))
26sysdep_routines += $(unix-extra-syscalls)
27
28ifdef unix-stub-syscalls
29# The system call entry points in this list are supposed to be additional
30# functions not overriding any other sysdeps/.../call.c implementation, but
31# their system call numbers are unavailable in the kernel headers we're
32# using. Instead of a system call stub, these get a function that fails
33# with ENOSYS. We just generate a single module defining one function and
34# making all these entry point names aliases for it.
35sysdep_routines += stub-syscalls
36$(objpfx)stub-syscalls.c: $(common-objpfx)sysd-syscalls \
37 $(..)sysdeps/unix/Makefile
38 $(make-target-directory)
39 (for call in $(unix-stub-syscalls); do \
40 call=$${call%%@*}; \
41 echo "#define $$call RENAMED_$$call"; \
42 done; \
43 echo '#include <errno.h>'; \
44 echo '#include <shlib-compat.h>'; \
45 for call in $(unix-stub-syscalls); do \
46 call=$${call%%@*}; \
47 echo "#undef $$call"; \
48 done; \
49 echo 'long int _no_syscall (void)'; \
50 echo '{ __set_errno (ENOSYS); return -1L; }'; \
51 for call in $(unix-stub-syscalls); do \
52 case $$call in \
53 *@@*) \
54 ver=$${call##*@}; call=$${call%%@*}; \
55 ver=`echo "$$ver" | sed 's/\./_/g'`; \
56 echo "strong_alias (_no_syscall, __$${call}_$${ver})"; \
57 echo "versioned_symbol (libc, __$${call}_$${ver}, $$call, $$ver);"\
58 ;; \
59 *@*) \
60 ver=$${call##*@}; call=$${call%%@*}; \
61 ver=`echo "$$ver" | sed 's/\./_/g'`; \
62 echo "strong_alias (_no_syscall, __$${call}_$${ver})"; \
63 echo "compat_symbol (libc, __$${call}_$${ver}, $$call, $$ver);" \
64 ;; \
65 *) echo "weak_alias (_no_syscall, $$call)"; \
66 echo "stub_warning ($$call)"; \
67 echo "weak_alias (_no_syscall, __GI_$$call)" ;; \
68 esac; \
69 done) > $@T
70 mv -f $@T $@
71generated += stub-syscalls.c
72endif
73endif
74
75# This is the end of the pipeline for compiling the syscall stubs.
76# The stdin is assembler with cpp using sysdep.h macros.
77compile-syscall = $(COMPILE.S) -o $@ -x assembler-with-cpp - \
78 $(compile-mkdep-flags)
79
80ifndef avoid-generated
81$(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
82 $(wildcard $(+sysdep_dirs:%=%/syscalls.list)) \
83 $(common-objpfx)libc-modules.stmp
84 for dir in $(+sysdep_dirs); do \
85 test -f $$dir/syscalls.list && \
86 { sysdirs='$(sysdirs)' \
87 asm_CPP='$(COMPILE.S) -E -x assembler-with-cpp' \
88 $(SHELL) $(dir $<)$(notdir $<) $$dir || exit 1; }; \
89 test $$dir = $(..)sysdeps/unix && break; \
90 done > $@T
91 mv -f $@T $@
92endif
93
94$(common-objpfx)s-%.d: $(..)sysdeps/unix/s-%.S \
95 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
96 $(+make-deps)
97
98postclean-generated += sysd-syscalls
99
100endif