Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/Makefile	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -100,10 +100,13 @@
 	-Werror-implicit-function-declaration -wd170
 
+# clang does not support following options but I am not sure whether
+# something won't break because of that:
+# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
 CLANG_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
+	-ffreestanding -fno-builtin -nostdlib -nostdinc \
 	-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
 	-Werror-implicit-function-declaration -Wwrite-strings \
-	-pipe -arch $(CLANG_ARCH)
+	-integrated-as \
+	-pipe -target $(CLANG_TARGET)
 
 ifeq ($(CONFIG_DEBUG),y)
@@ -387,5 +390,5 @@
 
 $(LINK): $(LINK).in $(DEPEND)
-	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
 
 %.o: %.S $(DEPEND)
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/arch/amd64/Makefile.inc	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -31,4 +31,5 @@
 BFD = binary
 CLANG_ARCH = x86_64
+CLANG_TARGET = x86_64-unknown-linux
 
 FPU_NO_CFLAGS = -mno-sse -mno-sse2
@@ -36,4 +37,5 @@
 GCC_CFLAGS += $(CMN1)
 ICC_CFLAGS += $(CMN1)
+CLANG_CFLAGS += $(CMN1)
 
 BITS = 64
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/arch/ia32/Makefile.inc	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -31,4 +31,5 @@
 BFD = binary
 CLANG_ARCH = i386
+CLANG_TARGET = i386-unknown-linux
 
 BITS = 32
Index: kernel/generic/include/debug.h
===================================================================
--- kernel/generic/include/debug.h	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/generic/include/debug.h	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -77,8 +77,20 @@
 	} while (0)
 
+/** Static assert macro
+ *
+ */
+#define STATIC_ASSERT(expr) \
+	_Static_assert(expr, "")
+
+#define STATIC_ASSERT_VERBOSE(expr, msg) \
+	_Static_assert(expr, msg)
+
+
 #else /* CONFIG_DEBUG */
 
 #define ASSERT(expr)
 #define ASSERT_VERBOSE(expr, msg)
+#define STATIC_ASSERT(expr)
+#define STATIC_ASSERT_VERBOSE(expr, msg)
 
 #endif /* CONFIG_DEBUG */
Index: kernel/generic/include/printf/verify.h
===================================================================
--- kernel/generic/include/printf/verify.h	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/generic/include/printf/verify.h	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -38,6 +38,12 @@
 #ifndef NVERIFY_PRINTF
 
+#ifdef __clang__
+#define PRINTF_ATTRIBUTE(start, end) \
+	__attribute__((format(__printf__, start, end)))
+#else
 #define PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(gnu_printf, start, end)))
+#endif
+
 
 #else /* NVERIFY_PRINTF */
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ kernel/generic/src/main/main.c	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -89,4 +89,23 @@
 #include <lib/ra.h>
 
+/* Ensure [u]int*_t types are of correct size.
+ *
+ * Probably, this is not the best place for such tests
+ * but this file is compiled on all architectures.
+ */
+#define CHECK_INT_TYPE_(signness, size) \
+	STATIC_ASSERT_VERBOSE(sizeof(signness##size##_t) * 8 == size, \
+	    #signness #size "_t does not have " #size " bits");
+#define CHECK_INT_TYPE(size) \
+	CHECK_INT_TYPE_(int, size); CHECK_INT_TYPE_(uint, size)
+
+CHECK_INT_TYPE(8);
+CHECK_INT_TYPE(16);
+CHECK_INT_TYPE(32);
+CHECK_INT_TYPE(64);
+
+
+
+
 /** Global configuration structure. */
 config_t config = {
Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ tools/autotool.py	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -181,4 +181,76 @@
 		print_error(["Failed to determine the value %s." % key,
 		             "Please contact the developers of HelenOS."])
+
+def get_target(config, needs_clang = False):
+	target = None
+	gnu_target = None
+	clang_target = None
+	cc_args = []
+	
+	if (config['PLATFORM'] == "abs32le"):
+		check_config(config, "CROSS_TARGET")
+		target = config['CROSS_TARGET']
+		
+		if (config['CROSS_TARGET'] == "arm32"):
+			gnu_target = "arm-linux-gnueabi"
+		
+		if (config['CROSS_TARGET'] == "ia32"):
+			gnu_target = "i686-pc-linux-gnu"
+		
+		if (config['CROSS_TARGET'] == "mips32"):
+			gnu_target = "mipsel-linux-gnu"
+			common['CC_ARGS'].append("-mabi=32")
+	
+	if (config['PLATFORM'] == "amd64"):
+		target = config['PLATFORM']
+		gnu_target = "amd64-linux-gnu"
+		clang_target = "x86_64-uknown-linux"
+	
+	if (config['PLATFORM'] == "arm32"):
+		target = config['PLATFORM']
+		gnu_target = "arm-linux-gnueabi"
+	
+	if (config['PLATFORM'] == "ia32"):
+		target = config['PLATFORM']
+		gnu_target = "i686-pc-linux-gnu"
+		clang_target = "i386-uknown-linux"
+	
+	if (config['PLATFORM'] == "ia64"):
+		target = config['PLATFORM']
+		gnu_target = "ia64-pc-linux-gnu"
+	
+	if (config['PLATFORM'] == "mips32"):
+		check_config(config, "MACHINE")
+		cc_args.append("-mabi=32")
+		
+		if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
+			target = config['PLATFORM']
+			gnu_target = "mipsel-linux-gnu"
+		
+		if ((config['MACHINE'] == "bmalta")):
+			target = "mips32eb"
+			gnu_target = "mips-linux-gnu"
+	
+	if (config['PLATFORM'] == "mips64"):
+		check_config(config, "MACHINE")
+		cc_args.append("-mabi=64")
+		
+		if (config['MACHINE'] == "msim"):
+			target = config['PLATFORM']
+			gnu_target = "mips64el-linux-gnu"
+	
+	if (config['PLATFORM'] == "ppc32"):
+		target = config['PLATFORM']
+		gnu_target = "ppc-linux-gnu"
+	
+	if (config['PLATFORM'] == "sparc64"):
+		target = config['PLATFORM']
+		gnu_target = "sparc64-linux-gnu"
+	
+	if (target is None) or (gnu_target is None) or (clang_target is None and needs_clang):
+		print_error(["Failed to determine target for compiler.",
+		             "Please contact the developers of HelenOS."])
+	
+	return (target, cc_args, gnu_target, clang_target)
 
 def check_app(args, name, details):
@@ -642,62 +714,5 @@
 		common['CC_ARGS'] = []
 		if (config['COMPILER'] == "gcc_cross"):
-			if (config['PLATFORM'] == "abs32le"):
-				check_config(config, "CROSS_TARGET")
-				target = config['CROSS_TARGET']
-				
-				if (config['CROSS_TARGET'] == "arm32"):
-					gnu_target = "arm-linux-gnueabi"
-				
-				if (config['CROSS_TARGET'] == "ia32"):
-					gnu_target = "i686-pc-linux-gnu"
-				
-				if (config['CROSS_TARGET'] == "mips32"):
-					gnu_target = "mipsel-linux-gnu"
-					common['CC_ARGS'].append("-mabi=32")
-			
-			if (config['PLATFORM'] == "amd64"):
-				target = config['PLATFORM']
-				gnu_target = "amd64-linux-gnu"
-			
-			if (config['PLATFORM'] == "arm32"):
-				target = config['PLATFORM']
-				gnu_target = "arm-linux-gnueabi"
-			
-			if (config['PLATFORM'] == "ia32"):
-				target = config['PLATFORM']
-				gnu_target = "i686-pc-linux-gnu"
-			
-			if (config['PLATFORM'] == "ia64"):
-				target = config['PLATFORM']
-				gnu_target = "ia64-pc-linux-gnu"
-			
-			if (config['PLATFORM'] == "mips32"):
-				check_config(config, "MACHINE")
-				common['CC_ARGS'].append("-mabi=32")
-				
-				if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
-					target = config['PLATFORM']
-					gnu_target = "mipsel-linux-gnu"
-				
-				if ((config['MACHINE'] == "bmalta")):
-					target = "mips32eb"
-					gnu_target = "mips-linux-gnu"
-			
-			if (config['PLATFORM'] == "mips64"):
-				check_config(config, "MACHINE")
-				common['CC_ARGS'].append("-mabi=64")
-				
-				if (config['MACHINE'] == "msim"):
-					target = config['PLATFORM']
-					gnu_target = "mips64el-linux-gnu"
-			
-			if (config['PLATFORM'] == "ppc32"):
-				target = config['PLATFORM']
-				gnu_target = "ppc-linux-gnu"
-			
-			if (config['PLATFORM'] == "sparc64"):
-				target = config['PLATFORM']
-				gnu_target = "sparc64-linux-gnu"
-			
+			target, cc_args, gnu_target, clang_target_unused = get_target(config)
 			path = "%s/%s/bin" % (cross_prefix, target)
 			prefix = "%s-" % gnu_target
@@ -708,4 +723,5 @@
 			check_common(common, "GCC")
 			common['CC'] = common['GCC']
+			common['CC_ARGS'].extend(cc_args)
 		
 		if (config['COMPILER'] == "gcc_native"):
@@ -723,8 +739,15 @@
 		
 		if (config['COMPILER'] == "clang"):
+			target, cc_args, gnu_target, clang_target = get_target(config, True)
+			path = "%s/%s/bin" % (cross_prefix, target)
+			prefix = "%s-" % gnu_target
+			
 			common['CC'] = "clang"
+			common['CC_ARGS'].extend(cc_args)
+			common['CC_ARGS'].append("-target")
+			common['CC_ARGS'].append(clang_target)
 			check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
-			check_gcc(None, "", common, PACKAGE_GCC)
-			check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
+			check_gcc(path, prefix, common, PACKAGE_GCC)
+			check_binutils(path, prefix, common, PACKAGE_BINUTILS)
 		
 		# Platform-specific utilities
Index: tools/ew.py
===================================================================
--- tools/ew.py	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ tools/ew.py	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -36,4 +36,5 @@
 import subprocess 
 import autotool
+import platform
 
 def run_in_console(cmd, title):
@@ -42,6 +43,18 @@
 	subprocess.call(cmdline, shell = True);
 
-def pc_options():
-	return '-enable-kvm'
+def get_host_native_width():
+	return int(platform.architecture()[0].strip('bit'))
+
+def pc_options(guest_width):
+	opts = ''
+	
+	# Do not enable KVM if running 64 bits HelenOS
+	# on 32 bits host
+	host_width = get_host_native_width()
+	if guest_width <= host_width:
+		opts = opts + ' -enable-kvm'
+	
+	# Remove the leading space
+	return opts[1:]
 
 def malta_options():
@@ -50,9 +63,9 @@
 def platform_to_qemu_options(platform, machine):
 	if platform == 'amd64':
-		return 'system-x86_64', pc_options()
+		return 'system-x86_64', pc_options(64)
 	elif platform == 'arm32':
 		return 'system-arm', ''
 	elif platform == 'ia32':
-		return 'system-i386', pc_options()
+		return 'system-i386', pc_options(32)
 	elif platform == 'mips32':
 		if machine == 'lmalta':
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ uspace/Makefile.common	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -198,10 +198,13 @@
 	-pipe -g -D__$(ENDIANESS)__
 
+# clang does not support following options but I am not sure whether
+# something won't break because of that:
+# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
 CLANG_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
+	-ffreestanding -fno-builtin -nostdlib -nostdinc \
 	-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
 	-Werror-implicit-function-declaration -Wwrite-strings \
-	-pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
+	-integrated-as \
+	-pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
 
 LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
@@ -251,4 +254,5 @@
 ifeq ($(COMPILER),clang)
 	CFLAGS += $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
+	GCC_CFLAGS += $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
@@ -303,5 +307,5 @@
 
 %.o: %.S $(DEPEND)
-	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ uspace/lib/c/Makefile	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -163,14 +163,14 @@
 
 $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
-	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
 
 $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
-	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DLOADER -E -x c $< | grep -v "^\#" > $@
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DLOADER -E -x c $< | grep -v "^\#" > $@
 
 $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
-	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DSHLIB -E -x c $< | grep -v "^\#" > $@
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DSHLIB -E -x c $< | grep -v "^\#" > $@
 
 $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
-	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DDLEXE -E -x c $< | grep -v "^\#" > $@
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DDLEXE -E -x c $< | grep -v "^\#" > $@
 
 $(COMMON_HEADER_ARCH): $(COMMON_HEADER)
Index: uspace/lib/c/arch/amd64/Makefile.common
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.common	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ uspace/lib/c/arch/amd64/Makefile.common	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -28,5 +28,7 @@
 
 CLANG_ARCH = x86_64
+CLANG_TARGET = x86_64-unknown-linux
 GCC_CFLAGS += -fno-omit-frame-pointer
+CLANG_CFLAGS += -fno-omit-frame-pointer
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/ia32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.common	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ uspace/lib/c/arch/ia32/Makefile.common	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -28,4 +28,5 @@
 
 CLANG_ARCH = i386
+CLANG_TARGET = i386-unknown-linux
 
 ifeq ($(PROCESSOR),i486)
@@ -34,4 +35,5 @@
 	GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
 endif
+CLANG_CFLAGS += -fno-omit-frame-pointer
 
 ENDIANESS = LE
Index: uspace/lib/c/include/io/verify.h
===================================================================
--- uspace/lib/c/include/io/verify.h	(revision c90aed45894edfe6e38e6306948757008e2bb0eb)
+++ uspace/lib/c/include/io/verify.h	(revision 94dfb921f6c450a02fb6df6e504c66a95d6ae95c)
@@ -38,6 +38,11 @@
 #ifndef NVERIFY_PRINTF
 
+#ifdef __clang__
+#define PRINTF_ATTRIBUTE(start, end) \
+	__attribute__((format(__printf__, start, end)))
+#else
 #define PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(gnu_printf, start, end)))
+#endif
 
 #else /* NVERIFY_PRINTF */
