]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.34/x86-build-specify-elf_i386-linker-emulation-explicit.patch
Linux 4.19.34
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / x86-build-specify-elf_i386-linker-emulation-explicit.patch
CommitLineData
ba172962
SL
1From a1d59c78c333fb83b2a3089a35fa518a5d9dd24e Mon Sep 17 00:00:00 2001
2From: George Rimar <grimar@accesssoftek.com>
3Date: Fri, 11 Jan 2019 12:10:12 -0800
4Subject: x86/build: Specify elf_i386 linker emulation explicitly for i386
5 objects
6
7[ Upstream commit 927185c124d62a9a4d35878d7f6d432a166b74e3 ]
8
9The kernel uses the OUTPUT_FORMAT linker script command in it's linker
10scripts. Most of the time, the -m option is passed to the linker with
11correct architecture, but sometimes (at least for x86_64) the -m option
12contradicts the OUTPUT_FORMAT directive.
13
14Specifically, arch/x86/boot and arch/x86/realmode/rm produce i386 object
15files, but are linked with the -m elf_x86_64 linker flag when building
16for x86_64.
17
18The GNU linker manpage doesn't explicitly state any tie-breakers between
19-m and OUTPUT_FORMAT. But with BFD and Gold linkers, OUTPUT_FORMAT
20overrides the emulation value specified with the -m option.
21
22LLVM lld has a different behavior, however. When supplied with
23contradicting -m and OUTPUT_FORMAT values it fails with the following
24error message:
25
26 ld.lld: error: arch/x86/realmode/rm/header.o is incompatible with elf_x86_64
27
28Therefore, just add the correct -m after the incorrect one (it overrides
29it), so the linker invocation looks like this:
30
31 ld -m elf_x86_64 -z max-page-size=0x200000 -m elf_i386 --emit-relocs -T \
32 realmode.lds header.o trampoline_64.o stack.o reboot.o -o realmode.elf
33
34This is not a functional change for GNU ld, because (although not
35explicitly documented) OUTPUT_FORMAT overrides -m EMULATION.
36
37Tested by building x86_64 kernel with GNU gcc/ld toolchain and booting
38it in QEMU.
39
40 [ bp: massage and clarify text. ]
41
42Suggested-by: Dmitry Golovin <dima@golovin.in>
43Signed-off-by: George Rimar <grimar@accesssoftek.com>
44Signed-off-by: Tri Vo <trong@android.com>
45Signed-off-by: Borislav Petkov <bp@suse.de>
46Tested-by: Tri Vo <trong@android.com>
47Tested-by: Nick Desaulniers <ndesaulniers@google.com>
48Cc: "H. Peter Anvin" <hpa@zytor.com>
49Cc: Ingo Molnar <mingo@redhat.com>
50Cc: Michael Matz <matz@suse.de>
51Cc: Thomas Gleixner <tglx@linutronix.de>
52Cc: morbo@google.com
53Cc: ndesaulniers@google.com
54Cc: ruiu@google.com
55Cc: x86-ml <x86@kernel.org>
56Link: https://lkml.kernel.org/r/20190111201012.71210-1-trong@android.com
57Signed-off-by: Sasha Levin <sashal@kernel.org>
58---
59 arch/x86/boot/Makefile | 2 +-
60 arch/x86/realmode/rm/Makefile | 2 +-
61 2 files changed, 2 insertions(+), 2 deletions(-)
62
63diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
64index 9b5adae9cc40..e2839b5c246c 100644
65--- a/arch/x86/boot/Makefile
66+++ b/arch/x86/boot/Makefile
67@@ -100,7 +100,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE
68 AFLAGS_header.o += -I$(objtree)/$(obj)
69 $(obj)/header.o: $(obj)/zoffset.h
70
71-LDFLAGS_setup.elf := -T
72+LDFLAGS_setup.elf := -m elf_i386 -T
73 $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
74 $(call if_changed,ld)
75
76diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
77index 4463fa72db94..96cb20de08af 100644
78--- a/arch/x86/realmode/rm/Makefile
79+++ b/arch/x86/realmode/rm/Makefile
80@@ -47,7 +47,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
81 targets += realmode.lds
82 $(obj)/realmode.lds: $(obj)/pasyms.h
83
84-LDFLAGS_realmode.elf := --emit-relocs -T
85+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
86 CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
87
88 targets += realmode.elf
89--
902.19.1
91