olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1439165.patch

00db10
Posted upstream at:
00db10
00db10
  https://sourceware.org/ml/libc-alpha/2017-04/msg00082.html
00db10
00db10
sysdeps/unix/sysv/linux/syscall-names.list is stored as a separate patch
00db10
(glibc-rh1439165-syscall-names.patch) in the source RPM, and is the
00db10
baseline for subsequent changes.
00db10
00db10
Author: Florian Weimer <fweimer@redhat.com>
00db10
00db10
    <bits/syscall.h>: Use an arch-independent system call list on Linux
00db10
00db10
    This commit changes the way the list of SYS_* system call macros
00db10
    is created on Linux.  glibc now contains a list of all known system
00db10
    calls, and the generated <bits/syscall.h> file defines the SYS_
00db10
    macro only if the correspnding __NR_ macro is defined by the kernel
00db10
    headers.
00db10
00db10
    As a result, there glibc does not have to be rebuilt to pick up
00db10
    system calls if the glibc sources already know about them.  This
00db10
    means that glibc can be built with older kernel headers, and if
00db10
    the installed kernel headers are upgraded afterwards, additional
00db10
    SYS_ macros become available as long as glibc has a record for
00db10
    those system calls.
00db10
00db10
The explicit system call list for system call management was not
00db10
accepted upstream.
00db10
00db10
Fedora bug: https://bugzilla.redhat.com/show_bug.cgi?id=1484729
00db10
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
00db10
index 366b1d7..95cff0e 100644
00db10
--- a/sysdeps/unix/sysv/linux/Makefile
00db10
+++ b/sysdeps/unix/sysv/linux/Makefile
00db10
@@ -39,75 +39,46 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
00db10
 
00db10
 tests += tst-clone
00db10
 
00db10
-# Generate the list of SYS_* macros for the system calls (__NR_* macros).
00db10
-
00db10
-# If there is more than one syscall list for different architecture
00db10
-# variants, the CPU/Makefile defines abi-variants to be a list of names
00db10
-# for those variants (e.g. 32 64), and, for each variant, defines
00db10
-# abi-$(variant)-options to be compiler options to cause <asm/unistd.h>
00db10
-# to define the desired list of syscalls and abi-$(variant)-condition to
00db10
-# be the condition for those options to use in a C #if condition.
00db10
-# abi-includes may be defined to a list of headers to include
00db10
-# in the generated header, if the default does not suffice.
00db10
-#
00db10
-# The generated header is compiled with `-ffreestanding' to avoid any
00db10
-# circular dependencies against the installed implementation headers.
00db10
-# Such a dependency would require the implementation header to be
00db10
-# installed before the generated header could be built (See bug 15711).
00db10
-# In current practice the generated header dependencies do not include
00db10
-# any of the implementation headers removed by the use of `-ffreestanding'.
00db10
-
00db10
-$(objpfx)bits/syscall%h $(objpfx)bits/syscall%d: ../sysdeps/unix/sysv/linux/sys/syscall.h
00db10
+# Generate the list of SYS_* macros for the system calls (__NR_*
00db10
+# macros).  The file syscall-names.list contains all possible system
00db10
+# call names, and the generated header file produces SYS_* macros for
00db10
+# the __NR_* macros which are actually defined.
00db10
+
00db10
+generated += bits/syscall.h
00db10
+$(objpfx)bits/syscall.h: \
00db10
+  ../sysdeps/unix/sysv/linux/gen-syscall-h.awk \
00db10
+  ../sysdeps/unix/sysv/linux/syscall-names.list
00db10
 	$(make-target-directory)
00db10
-	{ \
00db10
-	 echo '/* Generated at libc build time from kernel syscall list.  */';\
00db10
-	 echo ''; \
00db10
-	 echo '#ifndef _SYSCALL_H'; \
00db10
-	 echo '# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."'; \
00db10
-	 echo '#endif'; \
00db10
-	 echo ''; \
00db10
-	 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
00db10
-	 echo ''; \
00db10
-	 $(if $(abi-variants), \
00db10
-	 $(foreach v,$(abi-variants),\
00db10
-	 $(CC) -ffreestanding -E -MD -MP -MF $(@:.h=.d)-t$(v) -MT '$(@:.d=.h) $(@:.h=.d)' \
00db10
-	       -x c $(sysincludes) $< $(abi-$(v)-options) \
00db10
-	       -D_LIBC -dM | \
00db10
-	 sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
00db10
-	 LC_ALL=C sort > $(@:.d=.h).new$(v); \
00db10
-	 $(if $(abi-$(v)-condition),\
00db10
-	 echo '#if $(abi-$(v)-condition)';) \
00db10
-	 cat $(@:.d=.h).new$(v); \
00db10
-	 $(if $(abi-$(v)-condition),echo '#endif';) \
00db10
-	 rm -f $(@:.d=.h).new$(v); \
00db10
-	 ), \
00db10
-	 $(CC) -ffreestanding -E -MD -MP -MF $(@:.h=.d)-t$(v) -MT '$(@:.d=.h) $(@:.h=.d)' \
00db10
-	       -x c $(sysincludes) $< \
00db10
-	       -D_LIBC -dM | \
00db10
-	 sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
00db10
-	 LC_ALL=C sort;) \
00db10
-	} > $(@:.d=.h).new
00db10
-	mv -f $(@:.d=.h).new $(@:.d=.h)
00db10
-ifdef abi-variants
00db10
-ifneq (,$(objpfx))
00db10
-	sed $(sed-remove-objpfx) \
00db10
-	 $(foreach v,$(abi-variants),$(@:.h=.d)-t$(v)) > $(@:.h=.d)-t3
00db10
-else
00db10
-	cat $(foreach v,$(abi-variants),$(@:.h=.d)-t$(v)) \
00db10
-	 > $(@:.h=.d)-t3
00db10
-endif
00db10
-	rm -f $(foreach v,$(abi-variants),$(@:.h=.d)-t$(v))
00db10
-	mv -f $(@:.h=.d)-t3 $(@:.h=.d)
00db10
-else
00db10
-	mv -f $(@:.h=.d)-t $(@:.h=.d)
00db10
-endif
00db10
-
00db10
-ifndef no_deps
00db10
-# Get the generated list of dependencies (probably /usr/include/asm/unistd.h).
00db10
--include $(objpfx)bits/syscall.d
00db10
-endif
00db10
-generated += bits/syscall.h bits/syscall.d
00db10
-endif
00db10
+	$(AWK) -f $^ > $@-tmp
00db10
+	$(move-if-change) $@-tmp $@
00db10
+
00db10
+# All macros defined by <sys/syscall.h>.  Include <bits/syscall.h>
00db10
+# explicitly because <sys/sycall.h> skips it if _LIBC is defined.
00db10
+$(objpfx)tst-syscall-list-macros.list: \
00db10
+  $(objpfx)bits/syscall.h ../sysdeps/unix/sysv/linux/sys/syscall.h
00db10
+	printf '#include <sys/syscall.h>\n#include <bits/syscall.h>\n' | \
00db10
+	  $(CC) -E -o $@-tmp $(CFLAGS) $(CPPFLAGS) -x c - -dM
00db10
+	$(move-if-change) $@-tmp $@
00db10
+
00db10
+# __NR_* system call names.  Used by the test below.
00db10
+$(objpfx)tst-syscall-list-nr.list: \
00db10
+  ../sysdeps/unix/sysv/linux/filter-nr-syscalls.awk \
00db10
+  $(objpfx)tst-syscall-list-macros.list
00db10
+	$(AWK) -f $^ > $@-tmp
00db10
+	$(move-if-change) $@-tmp $@
00db10
+
00db10
+# SYS_* system call names.  Used by the test below.
00db10
+$(objpfx)tst-syscall-list-sys.list: $(objpfx)tst-syscall-list-macros.list
00db10
+	$(AWK) '/^#define SYS_/ { print substr($$2, 5) }' $< > $@-tmp
00db10
+	$(move-if-change) $@-tmp $@
00db10
+
00db10
+tests: $(objpfx)tst-syscall-list.out
00db10
+$(objpfx)tst-syscall-list.out: \
00db10
+  ../sysdeps/unix/sysv/linux/tst-syscall-list.sh \
00db10
+  $(objpfx)tst-syscall-list-nr.list $(objpfx)tst-syscall-list-sys.list
00db10
+	$(BASH) $^ > $@
00db10
+
00db10
+endif # $(subdir) == misc
00db10
 
00db10
 ifeq ($(subdir),time)
00db10
 sysdep_headers += sys/timex.h bits/timex.h
00db10
diff --git a/sysdeps/unix/sysv/linux/filter-nr-syscalls.awk b/sysdeps/unix/sysv/linux/filter-nr-syscalls.awk
00db10
new file mode 100644
00db10
index 0000000..15b052a
00db10
--- /dev/null
00db10
+++ b/sysdeps/unix/sysv/linux/filter-nr-syscalls.awk
00db10
@@ -0,0 +1,35 @@
00db10
+# Filter preprocessor __NR_* macros and extract system call names.
00db10
+# Copyright (C) 2017 Free Software Foundation, Inc.
00db10
+# This file is part of the GNU C Library.
00db10
+#
00db10
+# The GNU C Library is free software; you can redistribute it and/or
00db10
+# modify it under the terms of the GNU Lesser General Public
00db10
+# License as published by the Free Software Foundation; either
00db10
+# version 2.1 of the License, or (at your option) any later version.
00db10
+#
00db10
+# The GNU C Library is distributed in the hope that it will be useful,
00db10
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+# Lesser General Public License for more details.
00db10
+#
00db10
+# You should have received a copy of the GNU Lesser General Public
00db10
+# License along with the GNU C Library; if not, see
00db10
+# <http://www.gnu.org/licenses/>.
00db10
+
00db10
+# Skip reserved system calls.
00db10
+/^#define __NR_(unused|reserved)[0-9]+ / {
00db10
+    next;
00db10
+}
00db10
+
00db10
+# Skip pseudo-system calls which describe ranges.
00db10
+/^#define __NR_(syscalls|arch_specific_syscall|(OABI_)?SYSCALL_BASE) / {
00db10
+    next;
00db10
+}
00db10
+/^#define __NR_(|64_|[NO]32_)Linux(_syscalls)? / {
00db10
+    next;
00db10
+}
00db10
+
00db10
+# Print the remaining _NR_* macros as system call names.
00db10
+/^#define __NR_/ {
00db10
+    print substr($2, 6);
00db10
+}
00db10
diff --git a/sysdeps/unix/sysv/linux/gen-syscall-h.awk b/sysdeps/unix/sysv/linux/gen-syscall-h.awk
00db10
new file mode 100644
00db10
index 0000000..0a27b3c
00db10
--- /dev/null
00db10
+++ b/sysdeps/unix/sysv/linux/gen-syscall-h.awk
00db10
@@ -0,0 +1,75 @@
00db10
+# Generate SYS_* macros from a list in a text file.
00db10
+# Copyright (C) 2017 Free Software Foundation, Inc.
00db10
+# This file is part of the GNU C Library.
00db10
+#
00db10
+# The GNU C Library is free software; you can redistribute it and/or
00db10
+# modify it under the terms of the GNU Lesser General Public
00db10
+# License as published by the Free Software Foundation; either
00db10
+# version 2.1 of the License, or (at your option) any later version.
00db10
+#
00db10
+# The GNU C Library is distributed in the hope that it will be useful,
00db10
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+# Lesser General Public License for more details.
00db10
+#
00db10
+# You should have received a copy of the GNU Lesser General Public
00db10
+# License along with the GNU C Library; if not, see
00db10
+# <http://www.gnu.org/licenses/>.
00db10
+
00db10
+# Emit a conditional definition for SYS_NAME.
00db10
+function emit(name) {
00db10
+    print "#ifdef __NR_" name;
00db10
+    print "# define SYS_" name " __NR_" name;
00db10
+    print "#endif";
00db10
+    print "";
00db10
+}
00db10
+
00db10
+# Bail out with an error.
00db10
+function fatal(message) {
00db10
+    print FILENAME ":" FNR ": " message > "/dev/stderr";
00db10
+    exit 1;
00db10
+}
00db10
+
00db10
+BEGIN {
00db10
+    name = "";
00db10
+    kernel = "";
00db10
+}
00db10
+
00db10
+# Skip empty lines and comments.
00db10
+/^\s*(|#.*)$/ {
00db10
+    next;
00db10
+}
00db10
+
00db10
+# Kernel version.  Used for documentation purposes only.
00db10
+/^kernel [0-9.]+$/ {
00db10
+    if (kernel != "") {
00db10
+        fatal("duplicate kernel directive");
00db10
+    }
00db10
+    kernel = $2;
00db10
+    print "/* Generated at libc build time from syscall list.  */";
00db10
+    print "/* The system call list corresponds to kernel " kernel ".  */";
00db10
+    print "";
00db10
+    print "#ifndef _SYSCALL_H"
00db10
+    print "# error \"Never use <bits/syscall.h> directly; include <sys/syscall.h> instead.\"";
00db10
+    print "#endif";
00db10
+    print "";
00db10
+    next;
00db10
+}
00db10
+
00db10
+# If there is just one word, it is a system call.
00db10
+/^[a-zA-Z_][a-zA-Z0-9_]+$/ {
00db10
+    if (kernel == "") {
00db10
+        fatal("expected kernel directive before this line");
00db10
+    }
00db10
+    if ($1 <= name) {
00db10
+        fatal("name " name " violates ordering");
00db10
+    }
00db10
+    emit($1);
00db10
+    name = $1;
00db10
+    next;
00db10
+}
00db10
+
00db10
+# The rest has to be syntax errors.
00db10
+// {
00db10
+    fatal("unrecognized syntax");
00db10
+}
00db10
diff --git a/sysdeps/unix/sysv/linux/tst-syscall-list.sh b/sysdeps/unix/sysv/linux/tst-syscall-list.sh
00db10
new file mode 100644
00db10
index 0000000..f48b7cd
00db10
--- /dev/null
00db10
+++ b/sysdeps/unix/sysv/linux/tst-syscall-list.sh
00db10
@@ -0,0 +1,72 @@
00db10
+#!/bin/bash
00db10
+# Consistency checks for the system call list
00db10
+# Copyright (C) 2017 Free Software Foundation, Inc.
00db10
+# This file is part of the GNU C Library.
00db10
+#
00db10
+# The GNU C Library is free software; you can redistribute it and/or
00db10
+# modify it under the terms of the GNU Lesser General Public
00db10
+# License as published by the Free Software Foundation; either
00db10
+# version 2.1 of the License, or (at your option) any later version.
00db10
+#
00db10
+# The GNU C Library is distributed in the hope that it will be useful,
00db10
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+# Lesser General Public License for more details.
00db10
+#
00db10
+# You should have received a copy of the GNU Lesser General Public
00db10
+# License along with the GNU C Library; if not, see
00db10
+# <http://www.gnu.org/licenses/>.
00db10
+
00db10
+export LC_ALL=C
00db10
+set -e
00db10
+set -o pipefail
00db10
+
00db10
+if test $# != 2 ; then
00db10
+    echo "error: wrong number of arguments: $#"
00db10
+    exit 1
00db10
+fi
00db10
+
00db10
+list_nr="$1"
00db10
+list_sys="$2"
00db10
+
00db10
+errors=0
00db10
+
00db10
+# Use getpid as a system call which is expected to be always defined.
00db10
+# alpha uses getxpid instead, so it is permitted as an alternative.
00db10
+if ! grep -E -q '^getx?pid$' -- "$list_nr" ; then
00db10
+    echo "error: __NR_getpid not defined"
00db10
+    errors=1
00db10
+fi
00db10
+if ! grep -E -q '^getx?pid$' -- "$list_sys" ; then
00db10
+    echo "error: SYS_getpid not defined"
00db10
+    errors=1
00db10
+fi
00db10
+
00db10
+comm_1="$(mktemp)"
00db10
+comm_2="$(mktemp)"
00db10
+comm_result="$(mktemp)"
00db10
+cleanup () {
00db10
+    rm -f -- "$comm_1" "$comm_2" "$comm_result"
00db10
+}
00db10
+trap cleanup 0
00db10
+
00db10
+sort -o "$comm_1" -- "$list_nr"
00db10
+sort -o "$comm_2" -- "$list_sys"
00db10
+
00db10
+# Check for missing SYS_* macros.
00db10
+comm --check-order -2 -3 -- "$comm_1" "$comm_2" > "$comm_result"
00db10
+if test -s "$comm_result"; then
00db10
+    echo "error: These system calls need to be added to syscall-names.list:"
00db10
+    cat -- "$comm_result"
00db10
+    errors=1
00db10
+fi
00db10
+
00db10
+# Check for additional SYS_* macros.
00db10
+comm --check-order -1 -3 -- "$comm_1" "$comm_2" > "$comm_result"
00db10
+if test -s "$comm_result"; then
00db10
+    echo "error: The following system calls have unexpected SYS_* macros:"
00db10
+    cat -- "$comm_result"
00db10
+    errors=1
00db10
+fi
00db10
+
00db10
+exit "$errors"