This is the mail archive of the libc-alpha@sourceware.org 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]

Re: Support bits/syscall.h build for triarch systems


On Mon, 19 Dec 2011, Roland McGrath wrote:

> It seems like it should be doable.  What I have in mind is something like a
> standard variable that lists the flavor names (32 and 64 for the common
> bi-arch case).  Then variables with names derived from that can contain the
> predefines needing -U treatment.  Another variable can list the headers
> used to distinguish, or probably better a command sequence to emit the
> preamble (what's now "echo '#include <bits/wordsize.h>'; echo '';").  It
> will be some fiddly work today to get the rule to work right for the
> uniarch, biarch, and triarch examples we have at hand.  But thereafter, any
> changes will be in the common place, and new ports won't have to cargo-cult
> the big hairy rule across.

This patch implements the general approach along the lines you describe.  
The generated header looks right for x86_64 and (with an associated ports 
patch that eliminates the custom makefile rule, and the custom MIPS 
configure code to deal with preprocessing asm/unistd.h, and the custom 
MIPS version of sys/syscall.h) for MIPS.  On x86_64 I've also verified 
that the glibc build completes OK; the testsuite runs OK up until a 
failure of timezone/test-tz that probably results from the issue for which 
a patch was posted in 
<http://sourceware.org/ml/libc-alpha/2011-12/msg00054.html> (I have not 
investigated the failure or studied that patch, but this seems the most 
likely cause of that failure).

(This patch doesn't keep the optimization in the biarch code of emitting 
most definitions only once and only conditioning individual definitions 
that are only present on one architecture variant; it simply conditions 
the full set of syscalls for each architecture variant, which is certainly 
simpler to implement and reduces the risk of some bugs only affecting a 
subset of the uniarch/biarch/triarch cases.)

2011-12-21  Joseph Myers  <joseph@codesourcery.com>

	* sysdeps/unix/sysv/linux/Makefile (syscall-list-variants)
	(syscall-list-default-options, syscall-list-default-condition)
	(syscall-list-includes): Define.
	($(objpfx)syscall-%.h $(objpfx)syscall-%.d): Support arbitrary
	list of ABIs and options and #if conditions for each ABI.  Do not
	handle common syscalls between ABIs specially.
	* sysdeps/unix/sysv/linux/powerpc/Makefile (64bit-predefine):
	Remove.
	(syscall-list-variants, syscall-list-32bit-options)
	(syscall-list-32bit-condition, syscall-list-64bit-options)
	(syscall-list-64bit-condition): Define.
	* sysdeps/unix/sysv/linux/s390/Makefile (64bit-predefine): Remove.
	(syscall-list-variants, syscall-list-32bit-options)
	(syscall-list-32bit-condition, syscall-list-64bit-options)
	(syscall-list-64bit-condition): Define.
	* sysdeps/unix/sysv/linux/sparc/Makefile (64bit-predefine):
	Remove.
	(syscall-list-variants, syscall-list-32bit-options)
	(syscall-list-32bit-condition, syscall-list-64bit-options)
	(syscall-list-64bit-condition): Define.
	* sysdeps/unix/sysv/linux/x86_64/Makefile (64bit-predefine):
	Remove.
	(syscall-list-variants, syscall-list-32bit-options)
	(syscall-list-32bit-condition, syscall-list-64bit-options)
	(syscall-list-64bit-condition): Define.

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 3032026..3ae1207 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -39,8 +39,27 @@ install-others += $(inst_includedir)/bits/syscall.h
 tests += tst-clone
 
 # Generate the list of SYS_* macros for the system calls (__NR_* macros).
-# For bi-arch platforms, the CPU/Makefile defines {32,64}bit-predefine and
-# we generate a file that uses <bits/wordsize.h>.
+
+# If there is more than one syscall list for different architecture
+# variants, the CPU/Makefile defines syscall-list-variants to be a
+# list of names for those variants (e.g. 32bit 64bit), and, for each
+# variant, defines syscall-list-$(variant)-options to be compiler
+# options to cause <asm/unistd.h> to define the desired list of
+# syscalls and syscall-list-$(variant)-condition to be the condition
+# for those options to use in a C #if condition.
+# syscall-list-includes may be defined to a list of headers to include
+# in the generated header, if the default does not suffice.
+
+ifndef syscall-list-variants
+syscall-list-variants := default
+syscall-list-default-options :=
+syscall-list-default-condition := 1
+endif
+
+ifndef syscall-list-includes
+syscall-list-includes := bits/wordsize.h
+endif
+
 $(objpfx)syscall-%.h $(objpfx)syscall-%.d: ../sysdeps/unix/sysv/linux/sys/syscall.h
 	$(make-target-directory)
 	{ \
@@ -50,37 +69,29 @@ $(objpfx)syscall-%.h $(objpfx)syscall-%.d: ../sysdeps/unix/sysv/linux/sys/syscal
 	 echo '# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."'; \
 	 echo '#endif'; \
 	 echo ''; \
-	 $(CC) -E -MD -MP -MF $(@:.h=.d)-t1 -MT '$(@:.d=.h) $(@:.h=.d)' \
-	       -x c $(sysincludes) $< $(addprefix -U,$(64bit-predefine)) \
-	       $(addprefix -D,$(32bit-predefine)) -D_LIBC -dM | \
-	 sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
-	 LC_ALL=C sort > $(@:.d=.h).new32; \
-	 $(CC) -E -MD -MP -MF $(@:.h=.d)-t2 -MT '$(@:.d=.h) $(@:.h=.d)' \
-	       -x c $(sysincludes) $< $(addprefix -U,$(32bit-predefine)) \
-	       $(addprefix -D,$(64bit-predefine)) -D_LIBC -dM | \
+	 $(foreach h,$(syscall-list-includes), echo '#include <$(h)>';) \
+	 echo ''; \
+	 $(foreach v,$(syscall-list-variants),\
+	 $(CC) -E -MD -MP -MF $(@:.h=.d)-t$(v) -MT '$(@:.d=.h) $(@:.h=.d)' \
+	       -x c $(sysincludes) $< $(syscall-list-$(v)-options) \
+	       -D_LIBC -dM | \
 	 sed -n 's@^#define __NR_\([^ ]*\) .*$$@#define SYS_\1 __NR_\1@p' | \
-	 LC_ALL=C sort > $(@:.d=.h).new64; \
-	 if cmp -s $(@:.d=.h).new32 $(@:.d=.h).new64; then \
-	   cat $(@:.d=.h).new32; \
-	 else \
-	   echo '#include <bits/wordsize.h>'; \
-	   echo ''; \
-	   LC_ALL=C comm -12 $(@:.d=.h).new32 $(@:.d=.h).new64; \
-	   echo '#if __WORDSIZE == 64'; \
-	   LC_ALL=C comm -13 $(@:.d=.h).new32 $(@:.d=.h).new64; \
-	   echo '#else'; \
-	   LC_ALL=C comm -23 $(@:.d=.h).new32 $(@:.d=.h).new64; \
-	   echo '#endif'; \
-	 fi; \
-	 rm -f $(@:.d=.h).new32 $(@:.d=.h).new64; \
+	 LC_ALL=C sort > $(@:.d=.h).new$(v); \
+	 echo '#if $(syscall-list-$(v)-condition)'; \
+	 cat $(@:.d=.h).new$(v); \
+	 echo '#endif'; \
+	 rm -f $(@:.d=.h).new$(v); \
+	 ) \
 	} > $(@:.d=.h).new
 	mv -f $(@:.d=.h).new $(@:.d=.h)
 ifneq (,$(objpfx))
-	sed $(sed-remove-objpfx) $(@:.h=.d)-t1 $(@:.h=.d)-t2 > $(@:.h=.d)-t3
+	sed $(sed-remove-objpfx) \
+	 $(foreach v,$(syscall-list-variants),$(@:.h=.d)-t$(v)) > $(@:.h=.d)-t3
 else
-	cat $(@:.h=.d)-t1 $(@:.h=.d)-t2 > $(@:.h=.d)-t3
+	cat $(foreach v,$(syscall-list-variants),$(@:.h=.d)-t$(v)) \
+	 > $(@:.h=.d)-t3
 endif
-	rm -f $(@:.h=.d)-t1 $(@:.h=.d)-t2
+	rm -f $(foreach v,$(syscall-list-variants),$(@:.h=.d)-t$(v))
 	mv -f $(@:.h=.d)-t3 $(@:.h=.d)
 
 $(inst_includedir)/bits/syscall.h: $(objpfx)syscall-list.h $(+force)
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
index d1281cf..55311a4 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -1,4 +1,9 @@
-64bit-predefine = __powerpc64__
+syscall-list-variants := 32bit 64bit
+syscall-list-32bit-options := -U__powerpc64__
+syscall-list-32bit-condition := __WORDSIZE == 32
+syscall-list-64bit-options := -D__powerpc64__
+syscall-list-64bit-condition := __WORDSIZE == 64
+
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
 endif
diff --git a/sysdeps/unix/sysv/linux/s390/Makefile b/sysdeps/unix/sysv/linux/s390/Makefile
index 72eae68..fb20fb0 100644
--- a/sysdeps/unix/sysv/linux/s390/Makefile
+++ b/sysdeps/unix/sysv/linux/s390/Makefile
@@ -1,4 +1,9 @@
-64bit-predefine = __s390x__
+syscall-list-variants := 32bit 64bit
+syscall-list-32bit-options := -U__s390x__
+syscall-list-32bit-condition := __WORDSIZE == 32
+syscall-list-64bit-options := -D__s390x__
+syscall-list-64bit-condition := __WORDSIZE == 64
+
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
 endif
diff --git a/sysdeps/unix/sysv/linux/sparc/Makefile b/sysdeps/unix/sysv/linux/sparc/Makefile
index 9cb2a63..96bf0bb 100644
--- a/sysdeps/unix/sysv/linux/sparc/Makefile
+++ b/sysdeps/unix/sysv/linux/sparc/Makefile
@@ -1,4 +1,8 @@
-64bit-predefine = __sparc_v9__ __arch64__
+syscall-list-variants := 32bit 64bit
+syscall-list-32bit-options := -U__sparc_v9__ -U__arch64__
+syscall-list-32bit-condition := __WORDSIZE == 32
+syscall-list-64bit-options := -D__sparc_v9__ -D__arch64__
+syscall-list-64bit-condition := __WORDSIZE == 64
 
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
diff --git a/sysdeps/unix/sysv/linux/x86_64/Makefile b/sysdeps/unix/sysv/linux/x86_64/Makefile
index 6e2741a..9c9e615 100644
--- a/sysdeps/unix/sysv/linux/x86_64/Makefile
+++ b/sysdeps/unix/sysv/linux/x86_64/Makefile
@@ -1,5 +1,8 @@
-32bit-predefine = __i386__
-64bit-predefine = __x86_64__
+syscall-list-variants := 32bit 64bit
+syscall-list-32bit-options := -D__i386__ -U__x86_64__
+syscall-list-32bit-condition := __WORDSIZE == 32
+syscall-list-64bit-options := -U__i386__ -D__x86_64__
+syscall-list-64bit-condition := __WORDSIZE == 64
 
 ifeq ($(subdir),misc)
 sysdep_routines += ioperm iopl

-- 
Joseph S. Myers
joseph@codesourcery.com


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