Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1467878imu; Sat, 12 Jan 2019 00:41:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN6h8Qw1R7AvJZJdWJy/ozRGDM2H2QqFw/88w1/3avrE5qezwqWYPtgkTarD+Y8BBSsgODH+ X-Received: by 2002:a17:902:108a:: with SMTP id c10mr18173402pla.131.1547282514660; Sat, 12 Jan 2019 00:41:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547282514; cv=none; d=google.com; s=arc-20160816; b=BFATS5VQ1PLTJK0oKVClR4RhOnJMiMk1qGQn0GVPATIB9gWscFritef02DcW2Sno8F U4kLgFeAQwBQNXCQVewp35CmfOpu3eaL3tEUblE5BNuu1SShrT2mBwrhpQbMGRKmiZkg OapBmX0NC5z/c/NhMjxzSCEcCEVwNA16u09d8OXVmENEgJ7d8GzrP/CnGT6vWK5/oS/3 9A7wlGjV9CsFMPy4pqB6mq6amp02+1+guAUxkSjuPLRKS+36XbBdWA4+qpiIDrzrPwaa s9Gv1j7cNhj73cpVkh00oIikhrJFuLUQaJ9KX5i2MxSHVVa59/GpHfHTwp5J5Sahue+z t/hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=ukZyFiosnj73PZihVaYE3pRapBN6jCd0ilRKFTBkIRE=; b=wYS+ontf7CQKK8D4j2UIE/uD4a/I5W+EuukZELgz6HFyhh9lPQEqUB+Z3whwNb42Pw 9TPcLF22CUH4bPwSxsFL+5itTTrcVv5GeEMoxOR5ziHD6lHFBM+hzQmwlSxEiKUrPeXN M+xCd4YK4CfGXLmoCiz9p1PgxPA0q2Ih3jhi0MAcP/a45ssl2z/Lx8sFhJqUVCPFwgpQ VhgGm2sdRMPGwvQENFzR2tTQ8KzO78V+FwZPaC4nuIStAXVMYx2hNF+DurXlYvNToa/z hkVF47fOQUl47zenXbPxQreerS9oCsz0b8wpvIjerzdT40YwJE5uqrP1MLdBZs4eONl1 /L3w== ARC-Authentication-Results: i=1; mx.google.com; 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 j29si17781308pga.550.2019.01.12.00.41.38; Sat, 12 Jan 2019 00:41:54 -0800 (PST) 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; 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 S1725854AbfALIkh (ORCPT + 99 others); Sat, 12 Jan 2019 03:40:37 -0500 Received: from terminus.zytor.com ([198.137.202.136]:35407 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725806AbfALIkh (ORCPT ); Sat, 12 Jan 2019 03:40:37 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0C8dvSk1078706 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 12 Jan 2019 00:39:57 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0C8dtil1078703; Sat, 12 Jan 2019 00:39:55 -0800 Date: Sat, 12 Jan 2019 00:39:55 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for George Rimar Message-ID: Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, bp@suse.de, trong@android.com, tglx@linutronix.de, ndesaulniers@google.com, mingo@kernel.org, grimar@accesssoftek.com, matz@suse.de, x86@kernel.org, dima@golovin.in Reply-To: mingo@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, bp@suse.de, mingo@kernel.org, grimar@accesssoftek.com, ndesaulniers@google.com, tglx@linutronix.de, trong@android.com, dima@golovin.in, x86@kernel.org, matz@suse.de In-Reply-To: <20190111201012.71210-1-trong@android.com> References: <20190111201012.71210-1-trong@android.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/build] x86/build: Specify elf_i386 linker emulation explicitly for i386 objects Git-Commit-ID: 927185c124d62a9a4d35878d7f6d432a166b74e3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 927185c124d62a9a4d35878d7f6d432a166b74e3 Gitweb: https://git.kernel.org/tip/927185c124d62a9a4d35878d7f6d432a166b74e3 Author: George Rimar AuthorDate: Fri, 11 Jan 2019 12:10:12 -0800 Committer: Borislav Petkov CommitDate: Sat, 12 Jan 2019 00:11:39 +0100 x86/build: Specify elf_i386 linker emulation explicitly for i386 objects 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 --- 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 9b5adae9cc40..e2839b5c246c 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 4463fa72db94..96cb20de08af 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