Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1033050yba; Thu, 4 Apr 2019 02:54:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/3iaKMZI8iKLOiNowWlxGYlKyg4U9qjUeiYEO8HGfB0EyTeWeEAkrmYdAWq+oHG1VFx0K X-Received: by 2002:a17:902:7785:: with SMTP id o5mr5415455pll.33.1554371651560; Thu, 04 Apr 2019 02:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371651; cv=none; d=google.com; s=arc-20160816; b=rwC6I6jcxQmf4Px60wuT5FT3+NI8r05CUQPpfnLxG1ezch35JFC/gbwr+wirjAQ/lJ g0qOJ2FclOxpLdv4pb+bDCckO095iDX3Wud1iueoVKt3Ksyqzi+7T84FCjWj0WRNhxxx 5LCRGONFNBcTZuopI2TA3R9LvfBJEEE+qWSIQ5gBRQLybBD6inJ3dFkiXe8f0VxWDTAO Lw9w53FKi7gWE9EBv3gKt926SQQZkkTJUZjGqPn63gnXN1JKiwCVtnfBAAUku4DlCck9 xUtx1sD5R1T0lgwAUNTNyIzVNUpSZiXT6Wnc3ZDMrTDtBh4gf0ot4HkE0lsXyyEZnWzd gcSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eAupobIsQWeNTHYih9GxLjiOz8lJVXAsgwFzfK/CaTA=; b=0XELTukdFiWkrnDAagZ88rmijcnQagkz2/xFbsP2hTJHGd1kxl7mb1cOp5siFVHvv2 JRak79V/BGqQajHO+LGa7pvJZu/iOoutYmHYUtCrOsr6ir3XuGqLuBQS2N1cnIg196mw sdeBVYHhxtN+gCuGNMUzSf/NdnEQLnAtjFk/Aw8nzcTl21KPkcKLrQoAOSs72jo3Kw77 VSBKj1KPs0t8LMsz42wU8EYqHJv+y4ZVU2EJlWVUbXbPsojClsMnxyI6jTfeEXZM4oXS mj01JB+GmdIrn5YJlwGNDdES+Bw0Olotl/XwZJKmHxyP/0+veJAgHRs2i4tGcEnsT3Oz sJ/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="AMqzp/pn"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si7310458pgn.530.2019.04.04.02.53.56; Thu, 04 Apr 2019 02:54:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="AMqzp/pn"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729806AbfDDIx0 (ORCPT + 99 others); Thu, 4 Apr 2019 04:53:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729076AbfDDIxZ (ORCPT ); Thu, 4 Apr 2019 04:53:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9A10C2184B; Thu, 4 Apr 2019 08:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368003; bh=FlFBmuAMY+DY/P172A7FJW7Jgybyhq9UzpMNTwKhVLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMqzp/pnRFk4epmB7+FWwepluyeIq62Q7+bL2O7QxLNxLl2AvuVCinypvmbkONHYx 7fj7pfHq+XhXAeB10kd/hh7GhT/tkl7A5NgmjwSfN46zCpR3cXHpBQqF3N5m6ru05i KTzEQMV7vuX5eUJgwOG65AHlWbkDtFmbPBw4HqzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Golovin , George Rimar , Tri Vo , Borislav Petkov , Nick Desaulniers , "H. Peter Anvin" , Ingo Molnar , Michael Matz , Thomas Gleixner , morbo@google.com, ruiu@google.com, x86-ml , Sasha Levin Subject: [PATCH 4.9 85/91] x86/build: Specify elf_i386 linker emulation explicitly for i386 objects Date: Thu, 4 Apr 2019 10:48:09 +0200 Message-Id: <20190404084540.398204743@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084535.450029272@linuxfoundation.org> References: <20190404084535.450029272@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 927185c124d62a9a4d35878d7f6d432a166b74e3 ] 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 Signed-off-by: George Rimar Signed-off-by: Tri Vo Signed-off-by: Borislav Petkov Tested-by: Tri Vo Tested-by: Nick Desaulniers Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Michael Matz Cc: Thomas Gleixner Cc: morbo@google.com Cc: ndesaulniers@google.com Cc: ruiu@google.com Cc: x86-ml Link: https://lkml.kernel.org/r/20190111201012.71210-1-trong@android.com Signed-off-by: Sasha Levin --- arch/x86/boot/Makefile | 2 +- arch/x86/realmode/rm/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index 3b7156f46bc1..3b16935b22bc 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile @@ -100,7 +100,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE AFLAGS_header.o += -I$(objtree)/$(obj) $(obj)/header.o: $(obj)/zoffset.h -LDFLAGS_setup.elf := -T +LDFLAGS_setup.elf := -m elf_i386 -T $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE $(call if_changed,ld) diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile index 25012abc3409..ce5f431e6823 100644 --- a/arch/x86/realmode/rm/Makefile +++ b/arch/x86/realmode/rm/Makefile @@ -47,7 +47,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE targets += realmode.lds $(obj)/realmode.lds: $(obj)/pasyms.h -LDFLAGS_realmode.elf := --emit-relocs -T +LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj) targets += realmode.elf -- 2.19.1