Skip to contentSkip to conversation

Partial fix for compat build non-portability

PATCH Applied [email protected] 5 participants 11 messages Jan 10, 2007 – Jan 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Partial fix for compat build non-portability

# HG changeset patch
# User [email protected]
# Date 1168450090 28800
# Node ID 09c345f40063806e220e7f2ebf90c4e7371eefe0 # Parent 9865145e53eb02ddc2e2792f80bb7d54bc754a65 Partial fix for compat build non-portability.

xen/include/Makefile +27 -23
@@ -2,8 +2,28 @@ ifneq ($(CONFIG_COMPAT),)
 
 compat-arch-$(CONFIG_X86) := x86_32
 
-headers-y                 := $(shell echo public/*.h | sed -e 's,[^[:space:]]*-[^[:space:]]*,,g' -e 's,public/,compat/,g')
-headers-y                 := $(filter-out %/dom0_ops.h,$(headers-y))
+headers-y := \
+    compat/acm.h \
+    compat/acm_ops.h \
+    compat/callback.h \
+    compat/domctl.h \
+    compat/elfnote.h \
+    compat/event_channel.h \
+    compat/features.h \
+    compat/grant_table.h \
+    compat/kexec.h \
+    compat/memory.h \
+    compat/nmi.h \
+    compat/physdev.h \
+    compat/platform.h \
+    compat/sched.h \
+    compat/sysctl.h \
+    compat/trace.h \
+    compat/vcpu.h \
+    compat/version.h \
+    compat/xen.h \
+    compat/xencomm.h \
+    compat/xenoprof.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
 headers-y                 += compat/arch-$(compat-arch-y).h compat/xlat.h
@@ -21,24 +41,14 @@ all: $(headers-y)
 all: $(headers-y)
 
 compat/%.h: compat/%.i Makefile
-	id=_$$(echo $@ | sed 'y,abcdefghijklmnopqrstuvwxyz-/.,ABCDEFGHIJKLMNOPQRSTUVWXYZ___,'); \
+	id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
 	echo "#ifndef $$id" >[email protected]; \
 	echo "#define $$id" >>[email protected]; \
 	echo "#include <xen/compat.h>" >>[email protected]; \
 	$(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>[email protected];) \
 	$(if $(prefix-y),echo "$(prefix-y)" >>[email protected];) \
-	grep -v '^# [[:digit:]]' $< | \
-	sed -e 's,__InClUdE__,#include,' \
-	    -e 's,"xen-compat.h",<public/xen-compat.h>,' \
-	    -e 's,\(struct\|union\|enum\)[[:space:]]\+\(xen_\?\)\?\([[:alpha:]_]\),\1 compat_\3,g' \
-	    -e 's,@KeeP@,,g' \
-	    -e 's,_t\([^[:alnum:]_]\|$$\),_compat_t\1,g' \
-	    -e 's,\(8\|16\|32\|64\)_compat_t\([^[:alnum:]_]\|$$\),\1_t\2,g' \
-	    -e 's,\(^\|[^[:alnum:]_]\)xen_\?\([[:alnum:]_]*\)_compat_t\([^[:alnum:]_]\|$$\),\1compat_\2_t\3,g' \
-	    -e 's,\(^\|[^[:alnum:]_]\)XEN_\?,\1COMPAT_,' \
-	    -e 's,\(^\|[^[:alnum:]_]\)Xen_\?,\1Compat_,' \
-	    -e 's,\(^\|[^[:alnum:]]\)long\([^[:alnum:]]\|$$\),\1int\2,g' | \
-	uniq >>[email protected]; \
+	grep -v '^# [0-9]' $< | \
+	$(BASEDIR)/tools/compat-build-header.py | uniq >>[email protected]; \
 	$(if $(suffix-y),echo "$(suffix-y)" >>[email protected];) \
 	echo "#endif /* $$id */" >>[email protected]
 	mv -f [email protected] $@
@@ -49,17 +59,11 @@ compat/%.c: public/%.h xlat.lst Makefile
 compat/%.c: public/%.h xlat.lst Makefile
 	mkdir -p $(@D)
 	grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \
-	sed -e 's,^[[:space:]]*#[[:space:]]*include[[:space:]]\+,__InClUdE__ ,' \
-	    -e 's,^[[:space:]]*#[[:space:]]*define[[:space:]]\+\([[:upper:]_]*_GUEST_HANDLE\),#define HIDE_\1,' \
-	    -e 's,^[[:space:]]*#[[:space:]]*define[[:space:]]\+\([[:lower:]_]*_guest_handle\),#define hide_\1,' \
-	    -e 's,XEN_GUEST_HANDLE\(_[[:xdigit:]]\+\)\?,COMPAT_HANDLE,g' \
-	    $(foreach n,$(shell sed -n 's,^[[:space:]]*?[[:space:]]\+\([[:alnum:]_]*\)[[:space:]].*,\1,p' xlat.lst), \
-	                -e 's,\(struct\|union\)[[:space:]]\+\(xen_\?\)\?$n[[:space:]]\+\([[:alpha:]_]\),\1 @KeeP@\2$n \3,g') \
-	    >[email protected]
+        $(BASEDIR)/tools/compat-build-source.py >[email protected]
 	mv -f [email protected] $@
 
 compat/xlat.h: xlat.lst $(filter-out compat/xlat.h,$(headers-y)) $(BASEDIR)/tools/get-fields.sh Makefile
-	grep -v '^[[:space:]]*#' xlat.lst | \
+	grep -v '^[	 ]*#' xlat.lst | \
 	while read what name hdr; do \
 		$(SHELL) $(BASEDIR)/tools/get-fields.sh "$$what" compat_$$name $$(echo compat/$$hdr | sed 's,@arch@,$(compat-arch-y),g') || exit $$?; \
 	done >[email protected]
xen/tools/compat-build-header.py new file +21 -0
new file mode 100755
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+
+import re,sys
+
+pats = [
+ [ r"__InClUdE__", r"#include" ],
+ [ r"\"xen-compat.h\"", r"<public/xen-compat.h>" ],
+ [ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ],
+ [ r"@KeeP@", r"" ],
+ [ r"_t([^\w]|$)", r"_compat_t\1" ],
+ [ r"(8|16|32|64)_compat_t([^\w]|$)", r"\1_t\2" ],
+ [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
+ [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ],
+ [ r"(^|[^\w])Xen_?", r"\1Compat_" ],
+ [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ]
+];
+
+for line in sys.stdin.readlines():
+    for pat in pats:
+        line = re.subn(pat[0], pat[1], line)[0]
+    print line.rstrip()
xen/tools/compat-build-source.py new file +27 -0
new file mode 100755
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import re,sys
+
+pats = [
+ [ r"^\s*#\s*include\s+", r"__InClUdE__ " ],
+ [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
+ [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
+ [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
+];
+
+xlats = []
+
+xlatf = open('xlat.lst', 'r')
+for line in xlatf.readlines():
+    match = re.subn(r"^\s*\?\s+(\w*)\s.*", r"\1", line.rstrip())
+    if match[1]:
+        xlats.append(match[0])
+xlatf.close()
+
+for line in sys.stdin.readlines():
+    for pat in pats:
+        line = re.subn(pat[0], pat[1], line)[0]
+    for xlat in xlats:
+        line = re.subn(r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (xlat, xlat),
+            r"\1 @KeeP@\2 \3", line.rstrip())[0]
+    print line.rstrip()
xen/tools/get-fields.sh +22 -15
@@ -1,6 +1,9 @@
-#!/bin/sh
+#!/bin/bash
 test -n "$1" -a -n "$2" -a -n "$3"
 set -ef
+
+SED=sed
+[ -x /usr/xpg4/bin/sed ] && SED=/usr/xpg4/bin/sed
 
 get_fields() {
 	local level=1 aggr=0 name= fields=
@@ -90,11 +93,15 @@ handle_field() {
 		then
 			echo -n "$1(_d_)->$3 = (_s_)->$3;"
 		else
-			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | sed 's,\.,_,g')(_d_, _s_);"
+			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
 		fi
-	elif [ -z "$(echo "$5" | sed 's,[^{}],,g')" ]
+	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
 	then
-		local tag=$(echo "$5" | sed 's,[[:space:]]*\(struct\|union\)[[:space:]]\+\(compat_\)\?\([[:alnum:]_]\+\)[[:space:]].*,\3,')
+		local tag=$(echo "$5" | python -c '
+import re,sys
+for line in sys.stdin.readlines():
+    print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3", line)[0].rstrip()
+')
 		echo " \\"
 		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
 	else
@@ -110,7 +117,7 @@ handle_field() {
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}switch ($(echo $3 | sed 's,\.,_,g')) {"
+						echo -n "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
 					fi
 				fi
 				;;
@@ -158,12 +165,12 @@ handle_field() {
 				id=$token
 				;;
 			[\,\;])
-				if [ $level == 2 -a -n "$(echo $id | sed 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level == 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}case XLAT_${2}_$(echo $3.$id | sed 's,\.,_,g'):"
+						echo -n "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
 						handle_field "$1    " $2 $3.$id "$type" "$fields"
 					elif [ -z "$array" -a -z "$array_type" ]
 					then
@@ -202,7 +209,7 @@ copy_array() {
 }
 
 handle_array() {
-	local i="i$(echo $4 | sed 's,[^;], ,g' | wc -w)"
+	local i="i$(echo $4 | $SED 's,[^;], ,g' | wc -w | $SED 's,[[:space:]]*,,g')"
 	echo " \\"
 	echo "$1{ \\"
 	echo "$1    unsigned int $i; \\"
@@ -272,7 +279,7 @@ build_body() {
 			fi
 			;;
 		[\,\;])
-			if [ $level == 2 -a -n "$(echo $id | sed 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level == 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				if [ -z "$array" -a -z "$array_type" ]
 				then
@@ -300,10 +307,10 @@ build_body() {
 }
 
 check_field() {
-	if [ -z "$(echo "$4" | sed 's,[^{}],,g')" ]
+	if [ -z "$(echo "$4" | $SED 's,[^{}],,g')" ]
 	then
 		echo "; \\"
-		local n=$(echo $3 | sed 's,[^.], ,g' | wc -w)
+		local n=$(echo $3 | $SED 's,[^.], ,g' | wc -w | $SED 's,[[:space:]]*,,g')
 		if [ -n "$4" ]
 		then
 			for n in $4
@@ -325,7 +332,7 @@ check_field() {
 		then
 			echo -n "    CHECK_FIELD_($1, $2, $3)"
 		else
-			echo -n "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | sed 's!\.!, !g'))"
+			echo -n "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
 		fi
 	else
 		local level=1 fields= id= token
@@ -345,7 +352,7 @@ check_field() {
 				id=$token
 				;;
 			[\,\;])
-				if [ $level == 2 -a -n "$(echo $id | sed 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level == 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					check_field $1 $2 $3.$id "$fields"
 					test "$token" != ";" || fields= id=
@@ -390,7 +397,7 @@ build_check() {
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
 		[\,\;])
-			if [ $level == 2 -a -n "$(echo $id | sed 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level == 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				check_field $kind $1 $id "$fields"
 				test "$token" != ";" || fields= id=
@@ -402,7 +409,7 @@ build_check() {
 	echo ""
 }
 
-fields="$(get_fields $(echo $2 | sed 's,^compat_xen,compat_,') "$(sed -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)")"
+fields="$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') "$($SED -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)")"
 if [ -z "$fields" ]
 then
 	echo "Fields of '$2' not found in '$3'" >&2
#1 lore raw
Quoted 1 line · On Wed, Jan 10, 2007 at 09:29:21AM -0700, [email protected] wrote:

Partial fix for compat build non-portability.

This at least fixes all the compat gook to work on non-Linux, and I've checked that the contents of compat/ are the same on both Linux and Solaris.

Still to be resolved is the pragma pack push issue; this is non-portable pragma only enabled on some targets, as it's intended for win32 compatibility not something for general use. We should be wrapping each structure in a pragma pack(4) / pragma pack() pair, but trying to fix that makes my head hurt, and Jan isn't interested.

regards
john

#2 lore raw

Applied.

Thanks,
Emmanuel.

Quoted 22 lines · John Levon
Quoted 1 line · On Wed, Jan 10, 2007 at 09:29:21AM -0700, [email protected] wrote:

Partial fix for compat build non-portability.

This at least fixes all the compat gook to work on non-Linux, and I've checked that the contents of compat/ are the same on both Linux and Solaris.

Still to be resolved is the pragma pack push issue; this is non-portable pragma only enabled on some targets, as it's intended for win32 compatibility not something for general use. We should be wrapping each structure in a pragma pack(4) / pragma pack() pair, but trying to fix that makes my head hurt, and Jan isn't interested.

regards
john

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
In reply to John Levon
Quoted 5 lines · John Levon

Still to be resolved is the pragma pack push issue; this is non-portable pragma only enabled on some targets, as it's intended for win32 compatibility not something for general use. We should be wrapping each structure in a pragma pack(4) / pragma pack() pair, but trying to fix that makes my head hurt, and Jan isn't interested.

We only care about it working for the x86/64 target since that's the only one that asserts CONFIG_COMPAT. Why would wrapping structs individually be better than wrapping whole header files?

-- Keir

#4 lore raw
Quoted 9 lines · Keir Fraser
Quoted 5 lines

Still to be resolved is the pragma pack push issue; this is non-portable pragma only enabled on some targets, as it's intended for win32 compatibility not something for general use. We should be wrapping each structure in a pragma pack(4) / pragma pack() pair, but trying to fix that makes my head hurt, and Jan isn't interested.

We only care about it working for the x86/64 target since that's the only one that asserts CONFIG_COMPAT. Why would wrapping structs individually be better than wrapping whole header files?

Jan was concerned that just using

#pragma pack(4)
...
#pragma pack()

wouldn't work if an included header file used pragma. From the docs it seems that #pragma pack() will reset to the default rather than what was last pushed.

One simple thing might just to be follow every #include in the compat headers with another #pragma pack(4)?

regards
john

#5 lore raw
In reply to Keir Fraser
Quoted 3 lines · Keir Fraser

We only care about it working for the x86/64 target since that's the only one that asserts CONFIG_COMPAT. Why would wrapping structs individually be better than wrapping whole header files?

I've been building with the below, but haven't verified it's correct.

regards
john

# HG changeset patch
# User [email protected]
# Date 1168532284 28800
# Node ID 30f9b54e54d444fa1f897257b6a35d8caabc8b6e # Parent cf35b1e695d68c4503784506ee62ceffcff69452 Enforce pragma pack(4) for the compat headers.

xen/include/Makefile +2 -2
@@ -32,8 +32,8 @@ cppflags-$(CONFIG_X86)    += -m32
 cppflags-$(CONFIG_X86)    += -m32
 
 # 8-byte types are 4-byte aligned on x86_32 ...
-prefix-$(CONFIG_X86)      := \#pragma pack(push, 4)
-suffix-$(CONFIG_X86)      := \#pragma pack(pop)
+prefix-$(CONFIG_X86)      := \#pragma pack(4)
+suffix-$(CONFIG_X86)      := \#pragma pack()
 
 endif
 
xen/tools/compat-build-header.py +1 -1
@@ -3,7 +3,7 @@ import re,sys
 import re,sys
 
 pats = [
- [ r"__InClUdE__", r"#include" ],
+ [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ],
  [ r"\"xen-compat.h\"", r"<public/xen-compat.h>" ],
  [ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ],
  [ r"@KeeP@", r"" ],
#6 lore raw
Quoted 5 lines · John Levon
Quoted 3 lines

We only care about it working for the x86/64 target since that's the only one that asserts CONFIG_COMPAT. Why would wrapping structs individually be better than wrapping whole header files?

I've been building with the below, but haven't verified it's correct.

I'm confused about the purpose of changing this. Does pragma push/pop not work properly for some reason, or break the build?

-- Keir

#7 lore raw
Quoted 8 lines · Keir Fraser
Quoted 5 lines
Quoted 3 lines

We only care about it working for the x86/64 target since that's the only one that asserts CONFIG_COMPAT. Why would wrapping structs individually be better than wrapping whole header files?

I've been building with the below, but haven't verified it's correct.

I'm confused about the purpose of changing this. Does pragma push/pop not work properly for some reason, or break the build?

For some reason it's target specific in gcc, and specifically not enabled for sysv targets like Solaris.

regards
john

#8 lore raw
In reply to [email protected]
Quoted 7 lines
xen/include/Makefile +0 -0
@@ -2,8 +2,28 @@ ifneq ($(CONFIG_COMPAT),)
 

compat-arch-$(CONFIG_X86) := x86_32

-headers-y := $(shell echo public/*.h | sed -e 's,[^[:space:]]*-[^[:space:]]*,,g' -e

's,public/,compat/,g')

Quoted 23 lines
xen/include/Makefile +22 -1
-headers-y                 := $(filter-out %/dom0_ops.h,$(headers-y))
+headers-y := \
+    compat/acm.h \
+    compat/acm_ops.h \
+    compat/callback.h \
+    compat/domctl.h \
+    compat/elfnote.h \
+    compat/event_channel.h \
+    compat/features.h \
+    compat/grant_table.h \
+    compat/kexec.h \
+    compat/memory.h \
+    compat/nmi.h \
+    compat/physdev.h \
+    compat/platform.h \
+    compat/sched.h \
+    compat/sysctl.h \
+    compat/trace.h \
+    compat/vcpu.h \
+    compat/version.h \
+    compat/xen.h \
+    compat/xencomm.h \
+    compat/xenoprof.h
Quoted 3 lines
headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
headers-y                 += compat/arch-$(compat-arch-y).h compat/xlat.h

I certainly dislike this hunk - I intentionally didn't do it this way, as I wanted to prevent having to touch this Makefile every time a header gets added/removed. If the current mechanism is too ugly (which I tend to agree) let's just do it by more explicit filtering, i.e. add xen-compat.h along with dom0_ops.h and remove all arch-*.h items via sed as is currently being done.

Jan

#9 lore raw
Quoted 1 line · Jan Beulich

I certainly dislike this hunk - I intentionally didn't do it this way

globs in makefiles are a horrible idea.

Quoted 2 lines

, as I wanted to prevent having to touch this Makefile every time a header gets added/removed.

That argument applies to every single source file in the tree.

john

#10 lore raw
Quoted 5 lines · John Levon
Quoted 1 line · Jan Beulich

I certainly dislike this hunk - I intentionally didn't do it this way

globs in makefiles are a horrible idea.

Well, I would agree when it comes to filtered globs at least. If the file list has particular constraints I think a white list is clearer than a pattern-based black list.

While we're on the subject of the compat code, I wonder whether some of it might not better belong under arch/x86 (and even arch/x86/x86_64). The concept of what 'compat' means in an architecture-neutral sense isn't well defined, I believe. For example, the particular structs and headers that need special treatment will surely be different between platforms that choose to use CONFIG_COMPAT (if indeed any other than pae-on-x86-64 ever materialises, which is itself quite a doubtful assumption). Something to think about at least...

-- Keir