android_kernel_samsung_a7y1.../arch/x86/boot
George Rimar ef94798256 x86/build: Specify elf_i386 linker emulation explicitly for i386 objects
commit 927185c124d62a9a4d35878d7f6d432a166b74e3 upstream.

The kernel uses the OUTPUT_FORMAT linker script command in it's linker
scripts. Most of the time, the -m option is passed to the linker with
correct architecture, but sometimes (at least for x86_64) the -m option
contradicts the OUTPUT_FORMAT directive.

Specifically, arch/x86/boot and arch/x86/realmode/rm produce i386 object
files, but are linked with the -m elf_x86_64 linker flag when building
for x86_64.

The GNU linker manpage doesn't explicitly state any tie-breakers between
-m and OUTPUT_FORMAT. But with BFD and Gold linkers, OUTPUT_FORMAT
overrides the emulation value specified with the -m option.

LLVM lld has a different behavior, however. When supplied with
contradicting -m and OUTPUT_FORMAT values it fails with the following
error message:

  ld.lld: error: arch/x86/realmode/rm/header.o is incompatible with elf_x86_64

Therefore, just add the correct -m after the incorrect one (it overrides
it), so the linker invocation looks like this:

  ld -m elf_x86_64 -z max-page-size=0x200000 -m elf_i386 --emit-relocs -T \
    realmode.lds header.o trampoline_64.o stack.o reboot.o -o realmode.elf

This is not a functional change for GNU ld, because (although not
explicitly documented) OUTPUT_FORMAT overrides -m EMULATION.

Tested by building x86_64 kernel with GNU gcc/ld toolchain and booting
it in QEMU.

 [ bp: massage and clarify text. ]

Suggested-by: Dmitry Golovin <dima@golovin.in>
Signed-off-by: George Rimar <grimar@accesssoftek.com>
Signed-off-by: Tri Vo <trong@android.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Tested-by: Tri Vo <trong@android.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Michael Matz <matz@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: morbo@google.com
Cc: ndesaulniers@google.com
Cc: ruiu@google.com
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190111201012.71210-1-trong@android.com
[nc: Fix conflicts due to lack of commit 58ab5e0c2c40 ("Kbuild: arch:
     look for generated headers in obtree") in this tree]
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-04-06 14:56:37 +02:00
..
compressed A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tools A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
a20.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
apm.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
bioscall.S A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
bitops.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
boot.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cmdline.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
code16gcc.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
copy.S A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cpu.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cpucheck.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cpuflags.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cpuflags.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ctype.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
early_serial_console.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
edd.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
header.S A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
install.sh A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
main.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Makefile x86/build: Specify elf_i386 linker emulation explicitly for i386 objects 2020-04-06 14:56:37 +02:00
memory.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
mkcpustr.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
mtools.conf.in A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pm.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pmjump.S A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
printf.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
regs.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
setup.ld A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
string.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
string.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tty.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
version.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
vesa.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video-bios.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video-mode.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video-vesa.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video-vga.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
video.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30