This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

preprocess mips64 asm/unistd.h


The mips64 kernel header unistd.h defines macros __NR_<syscall> for
N64, __NR_N32_<syscall> or N32 and __NR_O32_<syscall>.  This is not
suitable for use in glibc for two reasons: (i) glibc only tests for
__NR_<syscall> in a number of files, and (ii) we can't just arrange to
define __NR_<syscall> to __NR_<abi>_<syscall> because this might give
false positives in case a syscall is defined on N64 but not for the
ABI in effect.  The solution is to preprocess asm/unistd.h into a
header that defines not only __NR_<abi>_<syscall>, but also
__NR_<syscall> if <abi> is in effect.  We might just drop __NR_<abi>_
entirely if we didn't actually test for __NR_<abi>_<syscall> in
certain cases, and if we didn't use this processed header to build a
single syscall list containing not only SYS_<syscall>, but also
SYS_<abi>_<syscall>.  This enables us to have a single /usr/include
tree containing headers that work for all 3 ABIs.  Ok?

Index: ChangeLog
2003-03-14  Alexandre Oliva  <aoliva at redhat dot com>

	* sysdeps/unix/sysv/linux/mips/configure.in: New.  Pre-process
	asm/unistd.h into asm-unistd.h.
	* sysdeps/unix/sysv/linux/mips/configure: Generated.
	* sysdeps/unix/sysv/linux/mips/Makefile: Do custom processing
	of syscall list.
	* sysdeps/unix/sysv/linux/mips/sys/syscall.h: New file.
	* sysdeps/unix/sysv/linux/mips/clone.S: Don't include
	asm/unistd.h.

Index: sysdeps/unix/sysv/linux/mips/Makefile
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- sysdeps/unix/sysv/linux/mips/Makefile 24 Mar 2002 01:55:17 -0000 1.7
+++ sysdeps/unix/sysv/linux/mips/Makefile 14 Mar 2003 15:11:31 -0000
@@ -8,4 +8,43 @@ ifeq ($(subdir),misc)
 sysdep_routines += cachectl cacheflush sysmips _test_and_set
 
 sysdep_headers += sys/cachectl.h sys/sysmips.h sys/tas.h
+
+no_syscall_list_h = 1
+
+# Generate the list of SYS_* macros for the system calls (__NR_* macros).
+# We generate not only SYS_<syscall>, pointing at SYS_<abi>_<syscall> if
+# it exists, but also define SYS_<abi>_<syscall> for all ABIs.
+$(objpfx)syscall-%.h $(objpfx)syscall-%.d: ../sysdeps/unix/sysv/linux/mips/sys/syscall.h
+	rm -f $(@:.h=.d)-t
+	{ \
+	 echo '/* Generated at libc build time from kernel syscall list.  */';\
+	 echo ''; \
+	 echo '#ifndef _SYSCALL_H'; \
+	 echo '# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."'; \
+	 echo '#endif'; \
+	 echo ''; \
+	 rm -f $(@:.d=.h).newt; \
+	 SUNPRO_DEPENDENCIES='$(@:.h=.d)-t $@' \
+	 $(CC) -E -x c -I $(common-objdir) $(sysincludes) $< -D_LIBC -dM | \
+	 sed -n 's at ^#define __NR_\([^ ]*\)  dot *$$ at #define SYS_\1 __NR_\1 at p' > $(@:.d=.h).newt; \
+	 if grep SYS_O32_ $(@:.d=.h).newt > /dev/null; then \
+	   echo '#if defined _ABI64 && _MIPS_SIM == _ABI64'; \
+	   sed -n 's/^\(#define SYS_\)N64_/\1/p' < $(@:.d=.h).newt; \
+	   echo '#elif defined _ABIN32 && _MIPS_SIM == _ABIN32'; \
+	   sed -n 's/^\(#define SYS_\)N32_/\1/p' < $(@:.d=.h).newt; \
+	   echo '#else'; \
+	   sed -n 's/^\(#define SYS_\)O32_/\1/p' < $(@:.d=.h).newt; \
+	   echo '#endif'; \
+	   sed -n '/^#define SYS_\([ON]32\|N64\)_/p' < $(@:.d=.h).newt; \
+	 else \
+	   cat $(@:.d=.h).newt; \
+	 fi; \
+	 rm $(@:.d=.h).newt; \
+	} > $(@:.d=.h).new
+	mv -f $(@:.d=.h).new $(@:.d=.h)
+	sed < $(@:.h=.d)-t > $(@:.h=.d)-t2 \
+	    -e 's,$(subst .,\.,$@),$(patsubst $(objpfx)%,$$(objpfx)%,\
+					      $(@:.d=.h) $(@:.h=.d)),'
+	rm -f $(@:.h=.d)-t
+	mv -f $(@:.h=.d)-t2 $(@:.h=.d)
 endif
Index: sysdeps/unix/sysv/linux/mips/configure.in
===================================================================
RCS file: sysdeps/unix/sysv/linux/mips/configure.in
diff -N sysdeps/unix/sysv/linux/mips/configure.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sysdeps/unix/sysv/linux/mips/configure.in 14 Mar 2003 15:11:31 -0000
@@ -0,0 +1,75 @@
+sinclude(./aclocal.m4)dnl Autoconf lossage
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/mips.
+
+case $machine in
+mips*64*)
+  rm -f asm-unistd.h
+  asm_unistd_h=$sysheaders/asm/unistd.h
+  if test ! -f $asm_unistd_h; then
+    # Try to find asm/unistd.h in compiler header search path.
+    try_asm_unistd_h=`echo '#include <asm/unistd.h>' | $CPP - |
+			sed -n '/^# 1 "\(\/[^"]*\)".*/{s,,\1,p;q;}'`
+    if test -n "$try_asm_unistd_h" &&
+       test -f "$try_asm_unistd_h"; then
+      asm_unistd_h=$try_asm_unistd_h
+    fi
+  fi
+  if test ! -f "$asm_unistd_h"; then
+    AC_MSG_WARN([*** asm/unistd.h not found, it will not be pre-processed])
+    echo '#include <asm/unistd.h>' > asm-unistd.h
+  else
+    # The point of this preprocessing is to turn __NR_<syscall> into
+    # __NR_N64_<syscall>, as well as to define __NR_<syscall> to
+    # __NR_<abi>_<syscall>, if __NR_<abi>_<syscall> is defined
+    # and <abi> is the compiler-enabled ABI.
+    cat "$asm_unistd_h" |
+    sed -e 's,__NR_,__NR_N64_,g' \
+        -e 's,__NR_N64_##,__NR_##,g' \
+	-e 's,__NR_N64_O32_,__NR_O32_,g' \
+	-e 's,__NR_N64_N32_,__NR_N32_,g' \
+	-e 's,__NR_N64_N64_,__NR_N64_,g' \
+    | awk > asm-unistd.h '
+/^#define __NR.*unused/ { print; next; }
+/^#define __NR_N64__exit __NR_N64_exit/ {
+	print "#define __NR__exit __NR_exit";
+	print "#define __NR_O32__exit __NR_O32_exit";
+	print "#define __NR_N32__exit __NR_N32_exit";
+	print; next;
+}
+/^#define __NR_O32_/ {
+	name = $2;
+	sub (/_O32_/, "_", name);
+	print;
+	print "#if _MIPS_SIM == _MIPS_SIM_ABI32";
+	print "# define " name " " $2;
+	print "#endif";
+	next;
+}
+/^#define __NR_N32_/ {
+	name = $2;
+	sub (/_N32_/, "_", name);
+	print;
+	print "#if defined _ABIN32 && _MIPS_SIM == _ABIN32";
+	print "# define " name " " $2;
+	print "#endif";
+	next;
+}
+/^#define __NR_N64_/ {
+	name = $2;
+	sub (/_N64_/, "_", name);
+	print;
+	print "#if defined _ABI64 && _MIPS_SIM == _ABI64";
+	print "# define " name " " $2;
+	print "#endif";
+	next;
+}
+{
+	print;
+}'
+  fi ;;
+mips*)
+  rm -f asm-unistd.h
+  echo '#include <asm/unistd.h>' > asm-unistd.h
+  ;;
+esac
Index: sysdeps/unix/sysv/linux/mips/sys/syscall.h
===================================================================
RCS file: sysdeps/unix/sysv/linux/mips/sys/syscall.h
diff -N sysdeps/unix/sysv/linux/mips/sys/syscall.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sysdeps/unix/sysv/linux/mips/sys/syscall.h 14 Mar 2003 15:11:31 -0000
@@ -0,0 +1,42 @@
+/* Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _SYSCALL_H
+#define _SYSCALL_H	1
+
+/* This file should list the numbers of the system the system knows.
+   But instead of duplicating this we use the information available
+   from the kernel sources.  */
+#ifdef _LIBC
+/* Since the kernel doesn't define macro names in a way usable for
+   glibc, we preprocess this header, and use it during the glibc build
+   process.  */
+# include <asm-unistd.h>
+#else
+# include <asm/unistd.h>
+#endif
+
+#ifndef _LIBC
+/* The Linux kernel header file defines macros `__NR_<name>', but some
+   programs expect the traditional form `SYS_<name>'.  So in building libc
+   we scan the kernel's list and produce <bits/syscall.h> with macros for
+   all the `SYS_' names.  */
+# include <bits/syscall.h>
+#endif
+
+#endif
Index: sysdeps/unix/sysv/linux/mips/clone.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/mips/clone.S,v
retrieving revision 1.12
diff -u -p -r1.12 clone.S
--- sysdeps/unix/sysv/linux/mips/clone.S 14 Mar 2003 03:59:37 -0000 1.12
+++ sysdeps/unix/sysv/linux/mips/clone.S 14 Mar 2003 15:11:31 -0000
@@ -21,7 +21,6 @@
    and invokes a function in the right context after its all over.  */
 
 #include <sys/asm.h>
-#include <asm/unistd.h>
 #include <sysdep.h>
 #define _ERRNO_H	1
 #include <bits/errno.h>
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]