changeset 561:8dc7e099309e

Update the perl removal patches for 2.6.28 to the versions I'm submitting to the linux-kernel list.
author Rob Landley <rob@landley.net>
date Sat, 03 Jan 2009 17:19:16 -0600
parents 0d34d9e16892
children 0dd6089867c1
files sources/patches/alt-linux-noperl-out-out-damned-perl.patch sources/patches/alt-linux-noperl-yesreally.patch sources/patches/alt-linux-noperl.patch
diffstat 3 files changed, 274 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- a/sources/patches/alt-linux-noperl-out-out-damned-perl.patch	Fri Jan 02 00:13:42 2009 -0600
+++ b/sources/patches/alt-linux-noperl-out-out-damned-perl.patch	Sat Jan 03 17:19:16 2009 -0600
@@ -1,8 +1,23 @@
-The perl infestation spread in the 2.6.28 kernel.
+From: Rob Landley <rob@landley.net>
+
+Convert kernel/cpu/mkcapflags.pl to kernel/cpu/mkcapflags.sh.
+
+This script generates kernel/cpu/capflags.c from include/asm/cpufeature.h.
+
+Changes from last time: changed shebang to #!/bin/sh and tested under bash
+and dash.
 
-diff -ruN alt-linux/arch/x86/kernel/cpu/Makefile alt-linux2/arch/x86/kernel/cpu/Makefile
---- alt-linux/arch/x86/kernel/cpu/Makefile	2008-12-24 17:26:37.000000000 -0600
-+++ alt-linux2/arch/x86/kernel/cpu/Makefile	2008-12-28 18:10:51.000000000 -0600
+Signed-off-by: Rob Landley <rob@landley.net>
+---
+
+ arch/x86/kernel/cpu/Makefile      |    4 +--
+ arch/x86/kernel/cpu/mkcapflags.pl |   32 ----------------------------
+ arch/x86/kernel/cpu/mkcapflags.sh |   28 ++++++++++++++++++++++++
+ 3 files changed, 30 insertions(+), 34 deletions(-)
+
+diff -ruN linux-2.6.28/arch/x86/kernel/cpu/Makefile linux-2.6.28-new/arch/x86/kernel/cpu/Makefile
+--- linux-2.6.28/arch/x86/kernel/cpu/Makefile	2008-12-24 17:26:37.000000000 -0600
++++ linux-2.6.28-new/arch/x86/kernel/cpu/Makefile	2009-01-02 01:10:00.000000000 -0600
 @@ -23,10 +23,10 @@
  obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o
  
@@ -16,9 +31,9 @@
 -$(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.pl FORCE
 +$(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE
  	$(call if_changed,mkcapflags)
-diff -ruN alt-linux/arch/x86/kernel/cpu/mkcapflags.pl alt-linux2/arch/x86/kernel/cpu/mkcapflags.pl
---- alt-linux/arch/x86/kernel/cpu/mkcapflags.pl	2008-12-24 17:26:37.000000000 -0600
-+++ alt-linux2/arch/x86/kernel/cpu/mkcapflags.pl	1969-12-31 18:00:00.000000000 -0600
+diff -ruN linux-2.6.28/arch/x86/kernel/cpu/mkcapflags.pl linux-2.6.28-new/arch/x86/kernel/cpu/mkcapflags.pl
+--- linux-2.6.28/arch/x86/kernel/cpu/mkcapflags.pl	2008-12-24 17:26:37.000000000 -0600
++++ linux-2.6.28-new/arch/x86/kernel/cpu/mkcapflags.pl	1969-12-31 18:00:00.000000000 -0600
 @@ -1,32 +0,0 @@
 -#!/usr/bin/perl
 -#
@@ -52,9 +67,9 @@
 -
 -close(IN);
 -close(OUT);
-diff -ruN alt-linux/arch/x86/kernel/cpu/mkcapflags.sh alt-linux2/arch/x86/kernel/cpu/mkcapflags.sh
---- alt-linux/arch/x86/kernel/cpu/mkcapflags.sh	1969-12-31 18:00:00.000000000 -0600
-+++ alt-linux2/arch/x86/kernel/cpu/mkcapflags.sh	2008-12-28 18:08:50.000000000 -0600
+diff -ruN linux-2.6.28/arch/x86/kernel/cpu/mkcapflags.sh linux-2.6.28-new/arch/x86/kernel/cpu/mkcapflags.sh
+--- linux-2.6.28/arch/x86/kernel/cpu/mkcapflags.sh	1969-12-31 18:00:00.000000000 -0600
++++ linux-2.6.28-new/arch/x86/kernel/cpu/mkcapflags.sh	2009-01-02 01:10:00.000000000 -0600
 @@ -0,0 +1,28 @@
 +#!/bin/sh
 +#
@@ -76,7 +91,7 @@
 +		# Name is everything up to the first whitespace
 +		NAME="$(echo "$i" | sed 's/ .*//')"
 +
-+		# If the /* comment */ starts with a quote string, grab that. */
++		# If the /* comment */ starts with a quote string, grab that.
 +		VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
 +		[ -z "$VALUE" ] && VALUE="\"$(echo "$NAME" | tr A-Z a-z)\""
 +
--- a/sources/patches/alt-linux-noperl-yesreally.patch	Fri Jan 02 00:13:42 2009 -0600
+++ b/sources/patches/alt-linux-noperl-yesreally.patch	Sat Jan 03 17:19:16 2009 -0600
@@ -1,11 +1,47 @@
-You should not need perl to build the kernel.  Honestly.  For 17 years, you
-could build the kernel without perl.  Don't let perl metasticize throughout
-the kernel, BURN IT OUT.
+From: Rob Landley <rob@landley.net>
+
+Remove perl from make headers_install by replacing a perl script (doing
+a simple regex search and replace) with a smaller and faster shell script
+implementation.  The new shell script is a single for loop calling sed and
+piping its output through unifdef to produce the target file.
+
+Changes from previous version: Added help text and a check for the right
+number of arguments.  Removed unused ARCH input from script and makefile
+(the makefile incorporates ARCH into INDIR, so the script doesn't care),
+fixed a whitespace mistake in the makefile pointed out by Sam Ravnborg,
+changed the shebang to #!/bin/sh and tested under bash and dash.
+
+
+put_changelog_here
+
+Signed-off-by: Rob Landley <rob@landley.net>
+---
 
---- /dev/null	2008-11-21 04:46:41.000000000 -0600
-+++ b/scripts/headers_install.sh	2008-12-15 22:09:45.000000000 -0600
-@@ -0,0 +1,23 @@
-+#!/bin/bash
+ scripts/Makefile.headersinst |    6 ++--
+ scripts/headers_install.pl   |   46 ---------------------------------
+ scripts/headers_install.sh   |   36 +++++++++++++++++++++++++
+ 3 files changed, 39 insertions(+), 49 deletions(-)
+
+diff -ruN linux-2.6.28/scripts/headers_install.sh linux-2.6.28-new/scripts/headers_install.sh
+--- linux-2.6.28/scripts/headers_install.sh	1969-12-31 18:00:00.000000000 -0600
++++ linux-2.6.28-new/scripts/headers_install.sh	2009-01-02 22:35:17.000000000 -0600
+@@ -0,0 +1,36 @@
++#!/bin/sh
++
++if [ $# -lt 2 ]
++then
++	echo "Usage: headers_install.sh INDIR OUTDIR [FILES...]
++	echo
++	echo "Prepares kernel header files for use by user space, by removing"
++	echo "all compiler.h definitions and #includes, and removing any"
++	echo "#ifdef __KERNEL__ sections."
++	echo
++	echo "INDIR:  directory to read each kernel header FILE from."
++	echo "OUTDIR: directory to write each userspace header FILE to."
++	echo "FILES:  list of header files to operate on."
++
++	exit 1
++fi
 +
 +# Grab arguments
 +
@@ -13,32 +49,30 @@
 +shift
 +OUTDIR="$1"
 +shift
-+ARCH="$1"
-+shift
 +
 +# Iterate through files listed on command line
 +
 +for i in "$@"
 +do
-+  sed -r \
-+    -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
-+    -e 's/__attribute_const__([ \t]|$)/\1/g' \
-+    -e 's@^#include <linux/compiler.h>@@' "$INDIR/$i" |
-+  scripts/unifdef -U__KERNEL__ - > "$OUTDIR/$i"
++	sed -r \
++		-e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
++		-e 's/__attribute_const__([ \t]|$)/\1/g' \
++		-e 's@^#include <linux/compiler.h>@@' "$INDIR/$i" |
++	scripts/unifdef -U__KERNEL__ - > "$OUTDIR/$i"
 +done
 +
 +exit 0
-diff -r d9b501c91442 scripts/Makefile.headersinst
---- a/scripts/Makefile.headersinst	Sun Dec 14 16:25:19 2008 -0800
-+++ b/scripts/Makefile.headersinst	Mon Dec 15 23:30:15 2008 -0600
+diff -ruN linux-2.6.28/scripts/Makefile.headersinst linux-2.6.28-new/scripts/Makefile.headersinst
+--- linux-2.6.28/scripts/Makefile.headersinst	2008-12-24 17:26:37.000000000 -0600
++++ linux-2.6.28-new/scripts/Makefile.headersinst	2009-01-02 22:36:42.000000000 -0600
 @@ -44,8 +44,8 @@
  quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                              file$(if $(word 2, $(all-files)),s))
        cmd_install = \
 -        $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
 -        $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
-+		$(CONFIG_SHELL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
-+		$(CONFIG_SHELL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
++      $(CONFIG_SHELL) $< $(srctree)/$(obj) $(install) $(header-y); \
++      $(CONFIG_SHELL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \
          touch $@
  
  quiet_cmd_remove = REMOVE  $(unwanted)
@@ -51,8 +85,9 @@
  	$(if $(unwanted),$(call cmd,remove),)
  	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  	$(call if_changed,install)
---- hg/scripts/headers_install.pl	2008-11-22 19:09:21.000000000 -0600
-+++ /dev/null	1970-01-01 00:00:00 -0600
+diff -ruN linux-2.6.28/scripts/headers_install.pl linux-2.6.28-new/scripts/headers_install.pl
+--- linux-2.6.28/scripts/headers_install.pl	2008-12-24 17:26:37.000000000 -0600
++++ linux-2.6.28-new/scripts/headers_install.pl	1969-12-31 18:00:00.000000000 -0600
 @@ -1,46 +0,0 @@
 -#!/usr/bin/perl -w
 -#
--- a/sources/patches/alt-linux-noperl.patch	Fri Jan 02 00:13:42 2009 -0600
+++ b/sources/patches/alt-linux-noperl.patch	Sat Jan 03 17:19:16 2009 -0600
@@ -1,112 +1,33 @@
-diff -r d0c7611dcfd6 kernel/Makefile
---- a/kernel/Makefile	Tue Dec 30 17:48:25 2008 -0800
-+++ b/kernel/Makefile	Fri Jan 02 00:10:44 2009 -0600
-@@ -115,7 +115,7 @@
- $(obj)/time.o: $(obj)/timeconst.h
- 
- quiet_cmd_timeconst  = TIMEC   $@
--      cmd_timeconst  = $(PERL) $< $(CONFIG_HZ) > $@
-+      cmd_timeconst  = $(CONFIG_SHELL) $< $(CONFIG_HZ) > $@
- targets += timeconst.h
--$(obj)/timeconst.h: $(src)/timeconst.pl FORCE
-+$(obj)/timeconst.h: $(src)/timeconst.sh FORCE
- 	$(call if_changed,timeconst)
---- /dev/null	1969-12-31 00:00:00.000000000 -0600
-+++ hg/kernel/timeconst.sh	2009-01-01 23:53:17.000000000 -0600
-@@ -0,0 +1,91 @@
-+#!/bin/bash
-+
-+if [ $# -ne 1 ]
-+then
-+	echo "Usage: timeconst.sh HZ"
-+	exit 1
-+fi
-+
-+HZ=$1
-+
-+# Sanity test: even the shell in Red Hat 9 (circa 2003) supported 64 bit math.
-+
-+[ $((1<<32)) -lt 0 ] && exit 1
-+
-+# Output start of header file
-+
-+cat << EOF
-+/* Automatically generated by kernel/timeconst.sh */
-+/* Conversion constants for HZ == $HZ */
-+
-+#ifndef KERNEL_TIMECONST_H
-+#define KERNEL_TIMECONST_H
-+
-+#include <linux/param.h>
-+#include <linux/types.h>
-+
-+#if HZ != $HZ
-+#error "kernel/timeconst.h has the wrong HZ value!"
-+#endif
-+
-+EOF
-+
-+# For both Miliseconds and Microseconds
-+
-+for i in "MSEC 1000" "USEC 1000000"
-+do
-+	NAME=$(echo $i | awk '{print $1}')
-+	PERIOD=$(echo $i | awk '{print $2}')
-+
-+	# Find greatest common denominator (using Euclid's algorithm)
-+
-+	A=$HZ
-+	B=$PERIOD
-+
-+	while [ $B -ne 0 ]
-+	do
-+		C=$(($A%$B))
-+		A=$B
-+		B=$C
-+	done
-+
-+	GCD=$A
-+
-+	# Do this for each direction (HZ_TO_PERIOD and PERIOD_TO_HZ)
-+
-+	for DIRECTION in 0 1
-+	do
-+		if [ $DIRECTION -eq 0 ]
-+		then
-+			CONVERT="HZ_TO_${NAME}"
-+			FROM=$HZ
-+			TO=$PERIOD
-+		else
-+			CONVERT="${NAME}_TO_HZ"
-+			FROM=$PERIOD
-+			TO=$HZ
-+		fi
-+
-+		# How many shift bits give 32 bits of significant data?
-+
-+		SHIFT=0
-+		while [ $(( (($TO<<$SHIFT)+$FROM-1)/$FROM )) -lt $((1<<31)) ]
-+		do
-+			SHIFT=$(( $SHIFT+1 ))
-+		done
-+
-+		MUL32=$(( (($TO<<$SHIFT)+$FROM-1)/$FROM ))
-+		MUL32=$(printf %x $MUL32)
-+		echo "#define ${CONVERT}_MUL32	U64_C(0x$MUL32)"
-+		ADJ32=$(($FROM/$GCD))
-+		ADJ32=$(( (($ADJ32-1)<<$SHIFT)/$ADJ32 ))
-+		ADJ32=$(printf %x $ADJ32)
-+		echo "#define ${CONVERT}_ADJ32	U64_C(0x$ADJ32)"
-+		echo "#define ${CONVERT}_SHR32	$SHIFT"
-+		echo "#define ${CONVERT}_NUM		U64_C($(($TO/$GCD)))"
-+		echo "#define ${CONVERT}_DEN		U64_C($(($FROM/$GCD)))"
-+	done
-+done
-+
-+echo
-+echo "#endif /* KERNEL_TIMECHONST_H */"
---- hg/kernel/timeconst.pl	2008-11-22 19:09:13.000000000 -0600
-+++ /dev/null	1969-12-31 00:00:00.000000000 -0600
+From: Rob Landley <rob@landley.net>
+
+Replace kernel/timeconst.pl with kernel/timeconst.sh.  The new shell script
+is much simpler, about 1/4 the size, and runs on Red Hat 9 from 2003.
+
+It requires a shell which can do 64 bit math, such as bash, busybox ash,
+or dash running on a 64 bit host.
+
+Changes from previous version:
+
+Redo ADJ32 math to avoid integer overflow for small HZ sizes (such as 24 or
+122).  In the pathological case (HZ=1) both versions now produce
+USEC_TO_HZ_ADJ32 of 0x7ffff79c842fa.  (See source comments for details.)
+
+Also expand usage message, add error message when no 64 bit math available in
+shell (and suggest some shells that support it), add whitespace around
+operators in equations, added underscores before __KERNEL_TIMECONST_H, change
+makefile so script is responsible for creating output file, make script delete 
+output file on error, change shebang to #!/bin/sh and test with dash and bash.
+
+Signed-off-by: Rob Landley <rob@landley.net>
+---
+
+ kernel/Makefile     |    4 
+ kernel/timeconst.pl |  378 ------------------------------------------
+ kernel/timeconst.sh |  149 ++++++++++++++++
+ 3 files changed, 151 insertions(+), 380 deletions(-)
+
+--- linux-2.6.28/kernel/timeconst.pl	2008-12-24 17:26:37.000000000 -0600
++++ /dev/null	2008-11-21 04:46:41.000000000 -0600
 @@ -1,378 +0,0 @@
 -#!/usr/bin/perl
 -# -----------------------------------------------------------------------
@@ -486,3 +407,165 @@
 -	output($hz, @val);
 -}
 -exit 0;
+--- /dev/null	2008-11-21 04:46:41.000000000 -0600
++++ linux-2.6.28-new/kernel/timeconst.sh	2009-01-03 15:24:01.000000000 -0600
+@@ -0,0 +1,147 @@
++#!/bin/sh
++
++if [ $# -ne 2 ]
++then
++	echo "Usage: timeconst.sh HZ FILENAME"
++	echo
++	echo "Generate a header file with constants for coverting between"
++	echo "decimal HZ timer ticks and milisecond or microsecond delays."
++	echo
++	exit 1
++fi
++
++HZ=$1
++shift
++FILENAME=$1
++
++# Sanity test: even the shell in Red Hat 9 (circa 2003) supported 64 bit math.
++
++if [ $((1 << 32)) -lt 0 ]
++then
++	echo "timeconst.sh needs a shell with 64 bit math, such as bash,"
++	echo "busybox ash, or dash running on a 64 bit host."
++	exit 1
++fi
++
++# If this script exits for any reason before this trap is removed,
++# delete the output file so a partial file won't confuse the build.
++
++trap "rm $FILENAME" EXIT
++
++# Output start of header file
++
++cat > $FILENAME << EOF || exit 1
++/* Automatically generated by kernel/timeconst.sh */
++/* Conversion constants for HZ == $HZ */
++
++#ifndef __KERNEL_TIMECONST_H
++#define __KERNEL_TIMECONST_H
++
++#include <linux/param.h>
++#include <linux/types.h>
++
++#if HZ != $HZ
++#error "kernel/timeconst.h has the wrong HZ value!"
++#endif
++
++EOF
++
++# For both Miliseconds and Microseconds
++
++for i in "MSEC 1000" "USEC 1000000"
++do
++	NAME=$(echo $i | awk '{print $1}')
++	PERIOD=$(echo $i | awk '{print $2}')
++
++	# Find greatest common denominator (using Euclid's algorithm)
++
++	A=$HZ
++	B=$PERIOD
++
++	while [ $B -ne 0 ]
++	do
++		C=$(( $A % $B ))
++		A=$B
++		B=$C
++	done
++
++	GCD=$A
++
++	# Do this for each direction (HZ_TO_PERIOD and PERIOD_TO_HZ)
++
++	for DIRECTION in 0 1
++	do
++		if [ $DIRECTION -eq 0 ]
++		then
++			CONVERT="HZ_TO_${NAME}"
++			FROM=$HZ
++			TO=$PERIOD
++		else
++			CONVERT="${NAME}_TO_HZ"
++			FROM=$PERIOD
++			TO=$HZ
++		fi
++
++		# Calculate 32 significant bits of MUL32 data.
++
++		SHIFT=0
++		while true
++		do
++			# This can't overflow 64 bit math.  Pathological case
++			# (TO=1, FROM=1000000) uses around 32+20=52 bits.
++
++			MUL32=$(( ( ( $TO << $SHIFT ) + $FROM - 1 ) / $FROM ))
++
++			# Keep increasing $SHIFT until we've got 32 bits.
++
++			[ $MUL32 -gt $(( 1 << 31 )) ] && break
++			SHIFT=$(( $SHIFT + 1 ))
++		done
++		MUL32=$( printf %x $MUL32 )
++
++		# ADJ32 is just (((FROM/GCD)-1)<<SHIFT)/(FROM/GCD) but this
++		# can overflow 64 bit math (examples, HZ=24 or HZ=122).
++		# Pathological case could use 32+20+20=72 bits.  (And this is
++		# the pathological case because a larger $HZ results in a
++		# smaller $SHIFT, so even insane HZ>USEC cases should be ok.)
++
++		# To get around this, we chop the bottom 32 bits off the
++		# calculation and then reassemble it to avoid overflow:
++		# 32+64=96, which is > 72.
++
++		ADJ32=$(( $FROM / $GCD ))
++		if [ $SHIFT -gt 32 ]
++		then
++			UPPER=$(( ( $ADJ32 - 1 ) << ( $SHIFT - 32 ) ))
++			LOWER=$(( ( $UPPER % $ADJ32 ) << 32 ))
++			ADJ32=$(( ( ( $UPPER / $ADJ32 ) << 32 ) + ( $LOWER / $ADJ32 )))
++		else
++			ADJ32=$(( ( ( $ADJ32 - 1 ) << $SHIFT) / $ADJ32 ))
++		fi
++		ADJ32=$( printf %x $ADJ32 )
++
++		NUM=$(( $TO / $GCD ))
++		DEN=$(( $FROM / $GCD ))
++
++		# Output next chunk of header data to file
++
++		(
++			echo "#define ${CONVERT}_MUL32	U64_C(0x$MUL32)" &&
++			echo "#define ${CONVERT}_ADJ32	U64_C(0x$ADJ32)" &&
++			echo "#define ${CONVERT}_SHR32	$SHIFT" &&
++			echo "#define ${CONVERT}_NUM		U64_C($NUM)" &&
++			echo "#define ${CONVERT}_DEN		U64_C($DEN)"
++		) >> $FILENAME || exit 1
++	done
++done
++
++(
++	echo
++	echo "#endif /* __KERNEL_TIMECHONST_H */"
++) >> $FILENAME || exit 1
++
++# Don't rm $FILENAME on exit anymore.
++
++trap "" EXIT
++
++exit 0
+--- linux-2.6.28/kernel/Makefile	2008-12-24 17:26:37.000000000 -0600
++++ linux-2.6.28-new/kernel/Makefile	2009-01-03 00:40:21.000000000 -0600
+@@ -116,7 +116,7 @@
+ $(obj)/time.o: $(obj)/timeconst.h
+ 
+ quiet_cmd_timeconst  = TIMEC   $@
+-      cmd_timeconst  = $(PERL) $< $(CONFIG_HZ) > $@
++      cmd_timeconst  = $(CONFIG_SHELL) $< $(CONFIG_HZ) $@
+ targets += timeconst.h
+-$(obj)/timeconst.h: $(src)/timeconst.pl FORCE
++$(obj)/timeconst.h: $(src)/timeconst.sh FORCE
+ 	$(call if_changed,timeconst)