linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS
@ 2014-01-08 11:21 David Woodhouse
  2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-08 11:21 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

Define them once in arch/x86/Makefile instead of twice

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 arch/x86/Makefile             | 14 ++++++++++++++
 arch/x86/boot/Makefile        | 15 +--------------
 arch/x86/realmode/rm/Makefile | 17 ++---------------
 3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 3c54657..ef19271 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -11,6 +11,20 @@ else
         KBUILD_DEFCONFIG := $(ARCH)_defconfig
 endif
 
+# How to compile the 16-bit code.  Note we always compile for -march=i386;
+# that way we can complain to the user if the CPU is insufficient.
+REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
+		   -include $(srctree)/arch/x86/boot/code16gcc.h \
+		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
+		   -mno-mmx -mno-sse \
+		   $(call cc-option, -ffreestanding) \
+		   $(call cc-option, -fno-toplevel-reorder,\
+		   $(call cc-option, -fno-unit-at-a-time)) \
+		   $(call cc-option, -fno-stack-protector) \
+		   $(call cc-option, -mpreferred-stack-boundary=2)
+export REALMODE_CFLAGS
+
 # BITS is used as extension for files which are available in a 32 bit
 # and a 64 bit version to simplify shared Makefiles.
 # e.g.: obj-y += foo_$(BITS).o
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index d9c1195..7c2b0a1 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -51,20 +51,7 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
 
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index 9cac825..3497f14 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -64,20 +64,7 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
-		   -I$(srctree)/arch/x86/boot \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/../../boot/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
+		   -I$(srctree)/arch/x86/boot
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
@ 2014-01-08 11:21 ` David Woodhouse
  2014-01-22  2:03   ` [tip:x86/build] " tip-bot for David Woodhouse
  2014-01-22 12:25   ` tip-bot for David Woodhouse
  2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-08 11:21 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

It looks like GCC will always emit an object that is marked with an
explicit section, although the documentation doesn't say that and we
possibly shouldn't be relying on it.

Clang does *not* do so, so add __attribute__((used)) to make sure.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 arch/x86/boot/video.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/video.h b/arch/x86/boot/video.h
index ff339c5..0bb2549 100644
--- a/arch/x86/boot/video.h
+++ b/arch/x86/boot/video.h
@@ -80,7 +80,7 @@ struct card_info {
 	u16 xmode_n;		/* Size of unprobed mode range */
 };
 
-#define __videocard struct card_info __attribute__((section(".videocards")))
+#define __videocard struct card_info __attribute__((used,section(".videocards")))
 extern struct card_info video_cards[], video_cards_end[];
 
 int mode_defined(u16 mode);	/* video.c */
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
  2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
@ 2014-01-08 11:21 ` David Woodhouse
  2014-01-14 19:14   ` [llvmlinux] " Jan-Simon Möller
                     ` (2 more replies)
  2014-01-08 11:21 ` [PATCH 4/4] x86, boot: Work around clang PR18415 David Woodhouse
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-08 11:21 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

I have this working with LLVM/Clang, and a PR is filed for GCC because
the current hacks we have to do to *try* to ensure that .code16gcc is
the first thing in the asm output are horrid.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 arch/x86/Makefile | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index ef19271..60fc67d 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,21 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# We really want GCC to have a -m16 option like clang, so that we don't
+# have to play these evil and unreliable tricks to ensure that our
+# asm(".code16gcc") is first in the asm output. http://gcc.gnu.org/PR59672
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := -m16
+
+REALMODE_CFLAGS	:= -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   $(call cc-option, $(M16_CFLAGS), $(CODE16GCC_CFLAGS)) \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/4] x86, boot: Work around clang PR18415.
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
  2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
  2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
@ 2014-01-08 11:21 ` David Woodhouse
  2014-01-08 12:04   ` [llvmlinux] " PaX Team
  2014-01-08 13:03 ` [llvmlinux] [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS Jan-Simon Möller
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 19+ messages in thread
From: David Woodhouse @ 2014-01-08 11:21 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

Clang's intrinsics ignore -mregparm=3 when they fall back to calling the
out-of-line implementations. Putting the args on the stack when memcpy()
expects them in registers is not a recipe for a happy kernel.

This bites with -m32 too, so clang is presumably catastrophically
broken for the i386 kernel until this is fixed, unless I'm missing
something.

For information/testing only; do not apply. With this, I can use
'clang -m16' to build all the kernel's 16-bit code and get a successful
boot.

Not-signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 arch/x86/boot/boot.h   | 2 ++
 arch/x86/boot/memory.c | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
index ef72bae..1182dc9 100644
--- a/arch/x86/boot/boot.h
+++ b/arch/x86/boot/boot.h
@@ -232,8 +232,10 @@ void *copy_from_gs(void *dst, addr_t src, size_t len);
 void *memcpy(void *dst, void *src, size_t len);
 void *memset(void *dst, int c, size_t len);
 
+#ifndef __clang__ /* PR18415 */
 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
 #define memset(d,c,l) __builtin_memset(d,c,l)
+#endif
 
 /* a20.c */
 int enable_a20(void);
diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
index db75d07..7af6504 100644
--- a/arch/x86/boot/memory.c
+++ b/arch/x86/boot/memory.c
@@ -63,8 +63,13 @@ static int detect_memory_e820(void)
 			count = 0;
 			break;
 		}
-
+#ifdef __clang__
+		/* PR18415 */
+		memcpy(desc, &buf, sizeof(*desc));
+		desc++;
+#else
 		*desc++ = buf;
+#endif
 		count++;
 	} while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_map));
 
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [llvmlinux] [PATCH 4/4] x86, boot: Work around clang PR18415.
  2014-01-08 11:21 ` [PATCH 4/4] x86, boot: Work around clang PR18415 David Woodhouse
@ 2014-01-08 12:04   ` PaX Team
  0 siblings, 0 replies; 19+ messages in thread
From: PaX Team @ 2014-01-08 12:04 UTC (permalink / raw)
  To: x86; +Cc: llvmlinux, linux-kernel

On 8 Jan 2014 at 11:21, David Woodhouse wrote:

> Clang's intrinsics ignore -mregparm=3 when they fall back to calling the
> out-of-line implementations. Putting the args on the stack when memcpy()
> expects them in registers is not a recipe for a happy kernel.
> 
> This bites with -m32 too, so clang is presumably catastrophically
> broken for the i386 kernel until this is fixed, unless I'm missing
> something.

llvmlinux already carries my old patch (and some more) here:
 arch/i586/patches/0026-Add-own-versions-of-memcpy-and-memset-for-compilatio.patch

(see also my comment on the clang PR)

cheers,
 PaX Team


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [llvmlinux] [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
                   ` (2 preceding siblings ...)
  2014-01-08 11:21 ` [PATCH 4/4] x86, boot: Work around clang PR18415 David Woodhouse
@ 2014-01-08 13:03 ` Jan-Simon Möller
  2014-01-22  2:03 ` [tip:x86/build] " tip-bot for David Woodhouse
  2014-01-22 12:25 ` tip-bot for David Woodhouse
  5 siblings, 0 replies; 19+ messages in thread
From: Jan-Simon Möller @ 2014-01-08 13:03 UTC (permalink / raw)
  To: Compiling the Linux Kernel with Clang/LLVM, x86; +Cc: linux-kernel

Hi David,

I'll import your patches to our queue and resolve them with the existing
ones.

Thanks.

Best,
Jan-Simon

Am 08.01.2014 12:21, schrieb David Woodhouse:
> Define them once in arch/x86/Makefile instead of twice
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> ---
>  arch/x86/Makefile             | 14 ++++++++++++++
>  arch/x86/boot/Makefile        | 15 +--------------
>  arch/x86/realmode/rm/Makefile | 17 ++---------------
>  3 files changed, 17 insertions(+), 29 deletions(-)
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 3c54657..ef19271 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -11,6 +11,20 @@ else
>          KBUILD_DEFCONFIG := $(ARCH)_defconfig
>  endif
>  
> +# How to compile the 16-bit code.  Note we always compile for -march=i386;
> +# that way we can complain to the user if the CPU is insufficient.
> +REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
> +		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
> +		   -include $(srctree)/arch/x86/boot/code16gcc.h \
> +		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
> +		   -mno-mmx -mno-sse \
> +		   $(call cc-option, -ffreestanding) \
> +		   $(call cc-option, -fno-toplevel-reorder,\
> +		   $(call cc-option, -fno-unit-at-a-time)) \
> +		   $(call cc-option, -fno-stack-protector) \
> +		   $(call cc-option, -mpreferred-stack-boundary=2)
> +export REALMODE_CFLAGS
> +
>  # BITS is used as extension for files which are available in a 32 bit
>  # and a 64 bit version to simplify shared Makefiles.
>  # e.g.: obj-y += foo_$(BITS).o
> diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
> index d9c1195..7c2b0a1 100644
> --- a/arch/x86/boot/Makefile
> +++ b/arch/x86/boot/Makefile
> @@ -51,20 +51,7 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
>  
>  # ---------------------------------------------------------------------------
>  
> -# How to compile the 16-bit code.  Note we always compile for -march=i386,
> -# that way we can complain to the user if the CPU is insufficient.
> -KBUILD_CFLAGS	:= $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
> -		   -DDISABLE_BRANCH_PROFILING \
> -		   -Wall -Wstrict-prototypes \
> -		   -march=i386 -mregparm=3 \
> -		   -include $(srctree)/$(src)/code16gcc.h \
> -		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
> -		   -mno-mmx -mno-sse \
> -		   $(call cc-option, -ffreestanding) \
> -		   $(call cc-option, -fno-toplevel-reorder,\
> -		   $(call cc-option, -fno-unit-at-a-time)) \
> -		   $(call cc-option, -fno-stack-protector) \
> -		   $(call cc-option, -mpreferred-stack-boundary=2)
> +KBUILD_CFLAGS	:= $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
>  KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
>  GCOV_PROFILE := n
>  
> diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> index 9cac825..3497f14 100644
> --- a/arch/x86/realmode/rm/Makefile
> +++ b/arch/x86/realmode/rm/Makefile
> @@ -64,20 +64,7 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
>  
>  # ---------------------------------------------------------------------------
>  
> -# How to compile the 16-bit code.  Note we always compile for -march=i386,
> -# that way we can complain to the user if the CPU is insufficient.
> -KBUILD_CFLAGS	:= $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
> -		   -I$(srctree)/arch/x86/boot \
> -		   -DDISABLE_BRANCH_PROFILING \
> -		   -Wall -Wstrict-prototypes \
> -		   -march=i386 -mregparm=3 \
> -		   -include $(srctree)/$(src)/../../boot/code16gcc.h \
> -		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
> -		   -mno-mmx -mno-sse \
> -		   $(call cc-option, -ffreestanding) \
> -		   $(call cc-option, -fno-toplevel-reorder,\
> -		   $(call cc-option, -fno-unit-at-a-time)) \
> -		   $(call cc-option, -fno-stack-protector) \
> -		   $(call cc-option, -mpreferred-stack-boundary=2)
> +KBUILD_CFLAGS	:= $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
> +		   -I$(srctree)/arch/x86/boot
>  KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
>  GCOV_PROFILE := n


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [llvmlinux] [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it
  2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
@ 2014-01-14 19:14   ` Jan-Simon Möller
  2014-01-14 23:59     ` Woodhouse, David
  2014-01-22  0:54   ` David Woodhouse
  2014-01-29 12:11   ` [PATCH] x86: Build 16-bit code with -m16 where possible David Woodhouse
  2 siblings, 1 reply; 19+ messages in thread
From: Jan-Simon Möller @ 2014-01-14 19:14 UTC (permalink / raw)
  To: llvmlinux; +Cc: David Woodhouse, x86, linux-kernel

Hi David,

what version of clang did you use btw ?

-- 

Dipl.-Ing.
Jan-Simon Möller

jansimon.moeller@gmx.de
Am Mittwoch, 8. Januar 2014, 11:21:22 schrieb David Woodhouse:
> I have this working with LLVM/Clang, and a PR is filed for GCC because
> the current hacks we have to do to *try* to ensure that .code16gcc is
> the first thing in the asm output are horrid.
> 
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> ---
>  arch/x86/Makefile | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index ef19271..60fc67d 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -13,14 +13,21 @@ endif
> 
>  # How to compile the 16-bit code.  Note we always compile for -march=i386;
>  # that way we can complain to the user if the CPU is insufficient.
> -REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
> +#
> +# We really want GCC to have a -m16 option like clang, so that we don't
> +# have to play these evil and unreliable tricks to ensure that our
> +# asm(".code16gcc") is first in the asm output. http://gcc.gnu.org/PR59672
> +CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
> +		    $(call cc-option, -fno-toplevel-reorder,\
> +		      $(call cc-option, -fno-unit-at-a-time))
> +M16_CFLAGS	 := -m16
> +
> +REALMODE_CFLAGS	:= -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
> +		   $(call cc-option, $(M16_CFLAGS), $(CODE16GCC_CFLAGS)) \
>  		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
> -		   -include $(srctree)/arch/x86/boot/code16gcc.h \
>  		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
>  		   -mno-mmx -mno-sse \
>  		   $(call cc-option, -ffreestanding) \
> -		   $(call cc-option, -fno-toplevel-reorder,\
> -		   $(call cc-option, -fno-unit-at-a-time)) \
>  		   $(call cc-option, -fno-stack-protector) \
>  		   $(call cc-option, -mpreferred-stack-boundary=2)
>  export REALMODE_CFLAGS


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [llvmlinux] [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it
  2014-01-14 19:14   ` [llvmlinux] " Jan-Simon Möller
@ 2014-01-14 23:59     ` Woodhouse, David
  0 siblings, 0 replies; 19+ messages in thread
From: Woodhouse, David @ 2014-01-14 23:59 UTC (permalink / raw)
  To: Jan-Simon Möller; +Cc: llvmlinux, x86, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2321 bytes --]

On Tue, 2014-01-14 at 20:14 +0100, Jan-Simon Möller wrote:
> Hi David,
> 
> what version of clang did you use btw ?

This is LLVM HEAD + extra patches at git://,
http://git.infradead.org/users/dwmw2/llvm.git and the following patch to
clang HEAD:

diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 948b448..9eeace1 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -964,6 +964,7 @@ def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
 def EL : Flag<["-"], "EL">, Flags<[DriverOption]>;
 def EB : Flag<["-"], "EB">, Flags<[DriverOption]>;
+def m16 : Flag<["-"], "m16">, Group<m_Group>, Flags<[DriverOption, CoreOption]>;
 def m32 : Flag<["-"], "m32">, Group<m_Group>, Flags<[DriverOption, CoreOption]>;
 def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group<m_Group>, Flags<[DriverOption,CC1Option]>,
   HelpText<"Enable hexagon-qdsp6 backward compatibility">;
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 253a083..8248149 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1911,12 +1911,20 @@ static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
     return Target;
 
   // Handle pseudo-target flags '-m32' and '-m64'.
-  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
+  if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64, options::OPT_m16)) {
     llvm::Triple::ArchType AT;
     if (A->getOption().matches(options::OPT_m32))
       AT = Target.get32BitArchVariant().getArch();
-    else
+    else if (A->getOption().matches(options::OPT_m64))
       AT = Target.get64BitArchVariant().getArch();
+    else if (A->getOption().matches(options::OPT_m16)) {
+      AT = Target.get32BitArchVariant().getArch();
+      if (AT == llvm::Triple::x86)
+        Target.setEnvironment(llvm::Triple::CODE16);
+      else
+        AT = llvm::Triple::UnknownArch;
+    }
+
     if (AT != llvm::Triple::UnknownArch)
       Target.setArch(AT);
   }
-- 
1.8.3.1



-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@intel.com                              Intel Corporation

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 4370 bytes --]

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it
  2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
  2014-01-14 19:14   ` [llvmlinux] " Jan-Simon Möller
@ 2014-01-22  0:54   ` David Woodhouse
  2014-01-29 12:11   ` [PATCH] x86: Build 16-bit code with -m16 where possible David Woodhouse
  2 siblings, 0 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-22  0:54 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

On Wed, 2014-01-08 at 11:21 +0000, David Woodhouse wrote:
> I have this working with LLVM/Clang, and a PR is filed for GCC because
> the current hacks we have to do to *try* to ensure that .code16gcc is
> the first thing in the asm output are horrid.

This is now all merged into LLVM/clang upstream, and the kernel's 16-bit
startup code should build fine with these patches.

-- 
dwmw2

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5745 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86: Remove duplication of 16-bit CFLAGS
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
                   ` (3 preceding siblings ...)
  2014-01-08 13:03 ` [llvmlinux] [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS Jan-Simon Möller
@ 2014-01-22  2:03 ` tip-bot for David Woodhouse
  2014-01-22 12:25 ` tip-bot for David Woodhouse
  5 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-22  2:03 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, David.Woodhouse

Commit-ID:  01aa3d17aa39991aa62ccd48b3122417bbca4ef3
Gitweb:     http://git.kernel.org/tip/01aa3d17aa39991aa62ccd48b3122417bbca4ef3
Author:     David Woodhouse <David.Woodhouse@intel.com>
AuthorDate: Wed, 8 Jan 2014 11:21:20 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 21 Jan 2014 17:59:27 -0800

x86: Remove duplication of 16-bit CFLAGS

Define them once in arch/x86/Makefile instead of twice.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1389180083-23249-1-git-send-email-David.Woodhouse@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/Makefile             | 14 ++++++++++++++
 arch/x86/boot/Makefile        | 15 +--------------
 arch/x86/realmode/rm/Makefile | 17 ++---------------
 3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 13b22e0..9ecbc1c 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -11,6 +11,20 @@ else
         KBUILD_DEFCONFIG := $(ARCH)_defconfig
 endif
 
+# How to compile the 16-bit code.  Note we always compile for -march=i386;
+# that way we can complain to the user if the CPU is insufficient.
+REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
+		   -include $(srctree)/arch/x86/boot/code16gcc.h \
+		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
+		   -mno-mmx -mno-sse \
+		   $(call cc-option, -ffreestanding) \
+		   $(call cc-option, -fno-toplevel-reorder,\
+		   $(call cc-option, -fno-unit-at-a-time)) \
+		   $(call cc-option, -fno-stack-protector) \
+		   $(call cc-option, -mpreferred-stack-boundary=2)
+export REALMODE_CFLAGS
+
 # BITS is used as extension for files which are available in a 32 bit
 # and a 64 bit version to simplify shared Makefiles.
 # e.g.: obj-y += foo_$(BITS).o
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index de70669..878df7e 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -51,20 +51,7 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
 
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index 9cac825..3497f14 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -64,20 +64,7 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
-		   -I$(srctree)/arch/x86/boot \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/../../boot/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
+		   -I$(srctree)/arch/x86/boot
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted
  2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
@ 2014-01-22  2:03   ` tip-bot for David Woodhouse
  2014-01-22 12:25   ` tip-bot for David Woodhouse
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-22  2:03 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, David.Woodhouse

Commit-ID:  2852657a9cf18a3bdb5842a13261bb1cc971572a
Gitweb:     http://git.kernel.org/tip/2852657a9cf18a3bdb5842a13261bb1cc971572a
Author:     David Woodhouse <David.Woodhouse@intel.com>
AuthorDate: Wed, 8 Jan 2014 11:21:21 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 21 Jan 2014 17:59:33 -0800

x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted

It looks like GCC will always emit an object that is marked with an
explicit section, although the documentation doesn't say that and we
possibly shouldn't be relying on it.

Clang does *not* do so, so add __attribute__((used)) to make sure.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1389180083-23249-2-git-send-email-David.Woodhouse@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/boot/video.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/video.h b/arch/x86/boot/video.h
index ff339c5..0bb2549 100644
--- a/arch/x86/boot/video.h
+++ b/arch/x86/boot/video.h
@@ -80,7 +80,7 @@ struct card_info {
 	u16 xmode_n;		/* Size of unprobed mode range */
 };
 
-#define __videocard struct card_info __attribute__((section(".videocards")))
+#define __videocard struct card_info __attribute__((used,section(".videocards")))
 extern struct card_info video_cards[], video_cards_end[];
 
 int mode_defined(u16 mode);	/* video.c */

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86: Remove duplication of 16-bit CFLAGS
  2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
                   ` (4 preceding siblings ...)
  2014-01-22  2:03 ` [tip:x86/build] " tip-bot for David Woodhouse
@ 2014-01-22 12:25 ` tip-bot for David Woodhouse
  5 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-22 12:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, David.Woodhouse

Commit-ID:  1c678da3bd1339299ab667af68cad5032367fb1c
Gitweb:     http://git.kernel.org/tip/1c678da3bd1339299ab667af68cad5032367fb1c
Author:     David Woodhouse <David.Woodhouse@intel.com>
AuthorDate: Wed, 8 Jan 2014 11:21:20 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Wed, 22 Jan 2014 04:21:45 -0800

x86: Remove duplication of 16-bit CFLAGS

Define them once in arch/x86/Makefile instead of twice.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1389180083-23249-1-git-send-email-David.Woodhouse@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/Makefile             | 14 ++++++++++++++
 arch/x86/boot/Makefile        | 15 +--------------
 arch/x86/realmode/rm/Makefile | 17 ++---------------
 3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 57d0215..83e67d5 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -11,6 +11,20 @@ else
         KBUILD_DEFCONFIG := $(ARCH)_defconfig
 endif
 
+# How to compile the 16-bit code.  Note we always compile for -march=i386;
+# that way we can complain to the user if the CPU is insufficient.
+REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
+		   -include $(srctree)/arch/x86/boot/code16gcc.h \
+		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
+		   -mno-mmx -mno-sse \
+		   $(call cc-option, -ffreestanding) \
+		   $(call cc-option, -fno-toplevel-reorder,\
+		   $(call cc-option, -fno-unit-at-a-time)) \
+		   $(call cc-option, -fno-stack-protector) \
+		   $(call cc-option, -mpreferred-stack-boundary=2)
+export REALMODE_CFLAGS
+
 # BITS is used as extension for files which are available in a 32 bit
 # and a 64 bit version to simplify shared Makefiles.
 # e.g.: obj-y += foo_$(BITS).o
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index d9c1195..7c2b0a1 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -51,20 +51,7 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
 
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index 9cac825..3497f14 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -64,20 +64,7 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
 
 # ---------------------------------------------------------------------------
 
-# How to compile the 16-bit code.  Note we always compile for -march=i386,
-# that way we can complain to the user if the CPU is insufficient.
-KBUILD_CFLAGS	:= $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
-		   -I$(srctree)/arch/x86/boot \
-		   -DDISABLE_BRANCH_PROFILING \
-		   -Wall -Wstrict-prototypes \
-		   -march=i386 -mregparm=3 \
-		   -include $(srctree)/$(src)/../../boot/code16gcc.h \
-		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
-		   -mno-mmx -mno-sse \
-		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
-		   $(call cc-option, -fno-stack-protector) \
-		   $(call cc-option, -mpreferred-stack-boundary=2)
+KBUILD_CFLAGS	:= $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
+		   -I$(srctree)/arch/x86/boot
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted
  2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
  2014-01-22  2:03   ` [tip:x86/build] " tip-bot for David Woodhouse
@ 2014-01-22 12:25   ` tip-bot for David Woodhouse
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-22 12:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, David.Woodhouse

Commit-ID:  9b3965f7401b0cc3ed2c228085a4c13b1c9243b1
Gitweb:     http://git.kernel.org/tip/9b3965f7401b0cc3ed2c228085a4c13b1c9243b1
Author:     David Woodhouse <David.Woodhouse@intel.com>
AuthorDate: Wed, 8 Jan 2014 11:21:21 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Wed, 22 Jan 2014 04:21:45 -0800

x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted

It looks like GCC will always emit an object that is marked with an
explicit section, although the documentation doesn't say that and we
possibly shouldn't be relying on it.

Clang does *not* do so, so add __attribute__((used)) to make sure.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1389180083-23249-2-git-send-email-David.Woodhouse@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/boot/video.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/video.h b/arch/x86/boot/video.h
index ff339c5..0bb2549 100644
--- a/arch/x86/boot/video.h
+++ b/arch/x86/boot/video.h
@@ -80,7 +80,7 @@ struct card_info {
 	u16 xmode_n;		/* Size of unprobed mode range */
 };
 
-#define __videocard struct card_info __attribute__((section(".videocards")))
+#define __videocard struct card_info __attribute__((used,section(".videocards")))
 extern struct card_info video_cards[], video_cards_end[];
 
 int mode_defined(u16 mode);	/* video.c */

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH] x86: Build 16-bit code with -m16 where possible
  2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
  2014-01-14 19:14   ` [llvmlinux] " Jan-Simon Möller
  2014-01-22  0:54   ` David Woodhouse
@ 2014-01-29 12:11   ` David Woodhouse
  2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
  2014-01-31 10:23     ` [PATCH] x86: " Pavel Machek
  2 siblings, 2 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-29 12:11 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

[-- Attachment #1: Type: text/plain, Size: 2095 bytes --]

Both clang 3.5 and GCC 4.9 will support this (as of r207196 and r199754
respectively). Both have been tested to produce booting kernels when the
16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
Updated comments, and retested, now that GCC supports it too. I think
the two preparatory patches already made it into tip:x86/build?

Note that for clang -m16 to work you do need the patch I just posted to
fix has_eflag() too. And a workaround for PR3997 as before.

 arch/x86/Makefile | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0f68712..0141cb0 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,22 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
+# older versions of GCC, we need to play evil and unreliable tricks to
+# attempt to ensure that our asm(".code16gcc") is first in the asm
+# output.
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := -m16
+
+REALMODE_CFLAGS	:= -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   $(call cc-option, $(M16_CFLAGS), $(CODE16GCC_CFLAGS)) \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS
-- 
1.8.5.3



-- 
dwmw2

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5745 bytes --]

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2] x86: Build 16-bit code with -m16 where possible
  2014-01-29 12:11   ` [PATCH] x86: Build 16-bit code with -m16 where possible David Woodhouse
@ 2014-01-29 12:16     ` David Woodhouse
  2014-01-29 17:51       ` [tip:x86/build] x86, build: " tip-bot for David Woodhouse
                         ` (2 more replies)
  2014-01-31 10:23     ` [PATCH] x86: " Pavel Machek
  1 sibling, 3 replies; 19+ messages in thread
From: David Woodhouse @ 2014-01-29 12:16 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, llvmlinux

[-- Attachment #1: Type: text/plain, Size: 2041 bytes --]

Both clang 3.5 and GCC 4.9 will support this (as of r199754 and r207196
respectively). Both have been tested to produce booting kernels when the
16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
v2: Get the revision numbers for GCC and clang the right way round.

v1: Patch rescued from an earlier series which was applied up to this point.
    Updated comments, and retested, now that GCC supports it too.

 arch/x86/Makefile | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0f68712..0141cb0 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,22 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
+# older versions of GCC, we need to play evil and unreliable tricks to
+# attempt to ensure that our asm(".code16gcc") is first in the asm
+# output.
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := -m16
+
+REALMODE_CFLAGS	:= -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   $(call cc-option, $(M16_CFLAGS), $(CODE16GCC_CFLAGS)) \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS
-- 
1.8.5.3




-- 
dwmw2

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5745 bytes --]

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible
  2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
@ 2014-01-29 17:51       ` tip-bot for David Woodhouse
  2014-01-29 17:57       ` tip-bot for David Woodhouse
  2014-01-30 16:10       ` tip-bot for David Woodhouse
  2 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-29 17:51 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, dwmw2, tglx, hpa, David.Woodhouse

Commit-ID:  372cb9eef903d1e18961d2c1a34c75f027f0bd8f
Gitweb:     http://git.kernel.org/tip/372cb9eef903d1e18961d2c1a34c75f027f0bd8f
Author:     David Woodhouse <dwmw2@infradead.org>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Wed, 29 Jan 2014 09:47:49 -0800

x86, build: Build 16-bit code with -m16 where possible

Both clang 3.5 and GCC 4.9 will support this (as of r199754 and r207196
respectively). Both have been tested to produce booting kernels when the
16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1390997807.20153.133.camel@i7.infradead.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/Makefile | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 9ecbc1c..dbc9b2b 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,22 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
+# older versions of GCC, we need to play evil and unreliable tricks to
+# attempt to ensure that our asm(".code16gcc") is first in the asm
+# output.
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := -m16
+
+REALMODE_CFLAGS	:= -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+		   $(call cc-option, $(M16_CFLAGS), $(CODE16GCC_CFLAGS)) \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible
  2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
  2014-01-29 17:51       ` [tip:x86/build] x86, build: " tip-bot for David Woodhouse
@ 2014-01-29 17:57       ` tip-bot for David Woodhouse
  2014-01-30 16:10       ` tip-bot for David Woodhouse
  2 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-29 17:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, dwmw2, tglx, hpa, David.Woodhouse

Commit-ID:  4d468a094a881033e6559ba09ebae0705d8c0f62
Gitweb:     http://git.kernel.org/tip/4d468a094a881033e6559ba09ebae0705d8c0f62
Author:     David Woodhouse <dwmw2@infradead.org>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Wed, 29 Jan 2014 09:55:34 -0800

x86, build: Build 16-bit code with -m16 where possible

Both clang 3.5 and GCC 4.9 will support this (as of r199754 and r207196
respectively). Both have been tested to produce booting kernels when the
16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

[ hpa: folded test for -m16 into M16_CFLAGS ]

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1390997807.20153.133.camel@i7.infradead.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/Makefile | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 9ecbc1c..eeda43a 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,22 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
+# older versions of GCC, we need to play evil and unreliable tricks to
+# attempt to ensure that our asm(".code16gcc") is first in the asm
+# output.
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
+
+REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
+		   -DDISABLE_BRANCH_PROFILING \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible
  2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
  2014-01-29 17:51       ` [tip:x86/build] x86, build: " tip-bot for David Woodhouse
  2014-01-29 17:57       ` tip-bot for David Woodhouse
@ 2014-01-30 16:10       ` tip-bot for David Woodhouse
  2 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Woodhouse @ 2014-01-30 16:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, dwmw2, tglx, hpa, David.Woodhouse

Commit-ID:  de3accdaec88851874c573031de007283e90b199
Gitweb:     http://git.kernel.org/tip/de3accdaec88851874c573031de007283e90b199
Author:     David Woodhouse <dwmw2@infradead.org>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Thu, 30 Jan 2014 08:05:36 -0800

x86, build: Build 16-bit code with -m16 where possible

Both clang 3.5 and GCC 4.9 will support this (as of r199754 and r207196
respectively). Both have been tested to produce booting kernels when the
16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

[ hpa: folded test for -m16 into M16_CFLAGS ]

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1390997807.20153.133.camel@i7.infradead.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/Makefile | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 9ecbc1c..eeda43a 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -13,14 +13,22 @@ endif
 
 # How to compile the 16-bit code.  Note we always compile for -march=i386;
 # that way we can complain to the user if the CPU is insufficient.
-REALMODE_CFLAGS	:= -m32 -g -Os -D__KERNEL__ -DDISABLE_BRANCH_PROFILING \
+#
+# The -m16 option is supported by GCC >= 4.9 and clang >= 3.5. For
+# older versions of GCC, we need to play evil and unreliable tricks to
+# attempt to ensure that our asm(".code16gcc") is first in the asm
+# output.
+CODE16GCC_CFLAGS := -m32 -include $(srctree)/arch/x86/boot/code16gcc.h \
+		    $(call cc-option, -fno-toplevel-reorder,\
+		      $(call cc-option, -fno-unit-at-a-time))
+M16_CFLAGS	 := $(call cc-option, -m16, $(CODE16GCC_CFLAGS))
+
+REALMODE_CFLAGS	:= $(M16_CFLAGS) -g -Os -D__KERNEL__ \
+		   -DDISABLE_BRANCH_PROFILING \
 		   -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \
-		   -include $(srctree)/arch/x86/boot/code16gcc.h \
 		   -fno-strict-aliasing -fomit-frame-pointer -fno-pic \
 		   -mno-mmx -mno-sse \
 		   $(call cc-option, -ffreestanding) \
-		   $(call cc-option, -fno-toplevel-reorder,\
-		   $(call cc-option, -fno-unit-at-a-time)) \
 		   $(call cc-option, -fno-stack-protector) \
 		   $(call cc-option, -mpreferred-stack-boundary=2)
 export REALMODE_CFLAGS

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] x86: Build 16-bit code with -m16 where possible
  2014-01-29 12:11   ` [PATCH] x86: Build 16-bit code with -m16 where possible David Woodhouse
  2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
@ 2014-01-31 10:23     ` Pavel Machek
  1 sibling, 0 replies; 19+ messages in thread
From: Pavel Machek @ 2014-01-31 10:23 UTC (permalink / raw)
  To: David Woodhouse; +Cc: x86, linux-kernel, llvmlinux

On Wed 2014-01-29 12:11:25, David Woodhouse wrote:
> Both clang 3.5 and GCC 4.9 will support this (as of r207196 and r199754
> respectively). Both have been tested to produce booting kernels when the
> 16-bit code is built with -m16. (Modulo LLVM PR3997, at least.)

Will this break compilation with older GCC versions? Current minimum
gcc is 3.2.

								Pavel


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2014-01-31 10:23 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-08 11:21 [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS David Woodhouse
2014-01-08 11:21 ` [PATCH 2/4] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted David Woodhouse
2014-01-22  2:03   ` [tip:x86/build] " tip-bot for David Woodhouse
2014-01-22 12:25   ` tip-bot for David Woodhouse
2014-01-08 11:21 ` [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it David Woodhouse
2014-01-14 19:14   ` [llvmlinux] " Jan-Simon Möller
2014-01-14 23:59     ` Woodhouse, David
2014-01-22  0:54   ` David Woodhouse
2014-01-29 12:11   ` [PATCH] x86: Build 16-bit code with -m16 where possible David Woodhouse
2014-01-29 12:16     ` [PATCH v2] " David Woodhouse
2014-01-29 17:51       ` [tip:x86/build] x86, build: " tip-bot for David Woodhouse
2014-01-29 17:57       ` tip-bot for David Woodhouse
2014-01-30 16:10       ` tip-bot for David Woodhouse
2014-01-31 10:23     ` [PATCH] x86: " Pavel Machek
2014-01-08 11:21 ` [PATCH 4/4] x86, boot: Work around clang PR18415 David Woodhouse
2014-01-08 12:04   ` [llvmlinux] " PaX Team
2014-01-08 13:03 ` [llvmlinux] [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS Jan-Simon Möller
2014-01-22  2:03 ` [tip:x86/build] " tip-bot for David Woodhouse
2014-01-22 12:25 ` tip-bot for David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).