• George Rimar's avatar
    x86/build: Specify elf_i386 linker emulation explicitly for i386 objects · 993f9641
    George Rimar authored
    [ Upstream commit 927185c1 ]
    
    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's avatarDmitry Golovin <dima@golovin.in>
    Signed-off-by: 's avatarGeorge Rimar <grimar@accesssoftek.com>
    Signed-off-by: 's avatarTri Vo <trong@android.com>
    Signed-off-by: 's avatarBorislav Petkov <bp@suse.de>
    Tested-by: 's avatarTri Vo <trong@android.com>
    Tested-by: 's avatarNick 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.comSigned-off-by: 's avatarSasha Levin <sashal@kernel.org>
    993f9641
Name
Last commit
Last update
Documentation Loading commit data...
LICENSES Loading commit data...
arch Loading commit data...
block Loading commit data...
certs Loading commit data...
crypto Loading commit data...
drivers Loading commit data...
firmware Loading commit data...
fs Loading commit data...
include Loading commit data...
init Loading commit data...
ipc Loading commit data...
kernel Loading commit data...
lib Loading commit data...
mm Loading commit data...
net Loading commit data...
samples Loading commit data...
scripts Loading commit data...
security Loading commit data...
sound Loading commit data...
tools Loading commit data...
usr Loading commit data...
virt Loading commit data...
.clang-format Loading commit data...
.cocciconfig Loading commit data...
.get_maintainer.ignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...