2014-01-08 11:21:56

by Woodhouse, David

[permalink] [raw]
Subject: [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS

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

Signed-off-by: David Woodhouse <[email protected]>
---
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


2014-01-08 11:21:31

by Woodhouse, David

[permalink] [raw]
Subject: [PATCH 2/4] 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 <[email protected]>
---
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

2014-01-08 11:21:28

by Woodhouse, David

[permalink] [raw]
Subject: [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it

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 <[email protected]>
---
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

2014-01-08 11:21:53

by Woodhouse, David

[permalink] [raw]
Subject: [PATCH 4/4] x86, boot: Work around clang PR18415.

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 <[email protected]>
---
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

2014-01-08 12:05:37

by PaX Team

[permalink] [raw]
Subject: Re: [llvmlinux] [PATCH 4/4] x86, boot: Work around clang PR18415.

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

2014-01-08 13:03:24

by Jan-Simon Möller

[permalink] [raw]
Subject: Re: [llvmlinux] [PATCH 1/4] x86: Remove duplication of 16-bit CFLAGS

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 <[email protected]>
> ---
> 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

2014-01-14 19:15:00

by Jan-Simon Möller

[permalink] [raw]
Subject: Re: [llvmlinux] [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it

Hi David,

what version of clang did you use btw ?

--

Dipl.-Ing.
Jan-Simon M?ller

[email protected]
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 <[email protected]>
> ---
> 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

2014-01-14 23:59:11

by Woodhouse, David

[permalink] [raw]
Subject: Re: [llvmlinux] [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it

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
[email protected] Intel Corporation


Attachments:
smime.p7s (4.27 kB)

2014-01-22 00:54:15

by David Woodhouse

[permalink] [raw]
Subject: Re: [PATCH 3/4] x86: Allow building 16-bit code with -m16 with toolchains that support it

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


Attachments:
smime.p7s (5.61 kB)
Subject: [tip:x86/build] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted

Commit-ID: 2852657a9cf18a3bdb5842a13261bb1cc971572a
Gitweb: http://git.kernel.org/tip/2852657a9cf18a3bdb5842a13261bb1cc971572a
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 8 Jan 2014 11:21:21 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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 */

Subject: [tip:x86/build] x86: Remove duplication of 16-bit CFLAGS

Commit-ID: 01aa3d17aa39991aa62ccd48b3122417bbca4ef3
Gitweb: http://git.kernel.org/tip/01aa3d17aa39991aa62ccd48b3122417bbca4ef3
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 8 Jan 2014 11:21:20 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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

Subject: [tip:x86/build] x86: Remove duplication of 16-bit CFLAGS

Commit-ID: 1c678da3bd1339299ab667af68cad5032367fb1c
Gitweb: http://git.kernel.org/tip/1c678da3bd1339299ab667af68cad5032367fb1c
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 8 Jan 2014 11:21:20 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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

Subject: [tip:x86/build] x86, boot: Use __attribute__((used)) to ensure videocard structs are emitted

Commit-ID: 9b3965f7401b0cc3ed2c228085a4c13b1c9243b1
Gitweb: http://git.kernel.org/tip/9b3965f7401b0cc3ed2c228085a4c13b1c9243b1
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 8 Jan 2014 11:21:21 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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 */

2014-01-29 12:11:29

by David Woodhouse

[permalink] [raw]
Subject: [PATCH] x86: Build 16-bit code with -m16 where possible

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 <[email protected]>
---
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


Attachments:
smime.p7s (5.61 kB)

2014-01-29 12:16:51

by David Woodhouse

[permalink] [raw]
Subject: [PATCH v2] x86: 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 <[email protected]>
---
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


Attachments:
smime.p7s (5.61 kB)
Subject: [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible

Commit-ID: 372cb9eef903d1e18961d2c1a34c75f027f0bd8f
Gitweb: http://git.kernel.org/tip/372cb9eef903d1e18961d2c1a34c75f027f0bd8f
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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

Subject: [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible

Commit-ID: 4d468a094a881033e6559ba09ebae0705d8c0f62
Gitweb: http://git.kernel.org/tip/4d468a094a881033e6559ba09ebae0705d8c0f62
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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

Subject: [tip:x86/build] x86, build: Build 16-bit code with -m16 where possible

Commit-ID: de3accdaec88851874c573031de007283e90b199
Gitweb: http://git.kernel.org/tip/de3accdaec88851874c573031de007283e90b199
Author: David Woodhouse <[email protected]>
AuthorDate: Wed, 29 Jan 2014 12:16:47 +0000
Committer: H. Peter Anvin <[email protected]>
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 <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: H. Peter Anvin <[email protected]>
---
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

2014-01-31 10:23:16

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] x86: Build 16-bit code with -m16 where possible

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