Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5611663img; Wed, 27 Mar 2019 11:41:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXGr+q2WmIOvYq2vQhtRPYHohE8A6LXVFcNnq4rC5YawJ6tU8go74ETXumEitSqMyt2nG2 X-Received: by 2002:a65:5ac3:: with SMTP id d3mr12730894pgt.168.1553712060897; Wed, 27 Mar 2019 11:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712060; cv=none; d=google.com; s=arc-20160816; b=cBxgRpdJd9acarcfvqVZprzIpiF2F8doeS48GPL6E7+zH5V7wzos7Q/zxY7NY787MF tW35EOkGEV0dvS3LMA83lGCOkiAE6EE/vBMLBVP+tY/5/Svi94+dJlTipDgdVHHWi9Bt Ygp0mdg2nC2AgXmY2yryYFUg202QwpjaFkUViwvk5nNdtpMETupiBAw+iGmdu72Dg50i 5L2bIubYwfeIywmbojb51ey1EBjLCuSHW/MEkqVRp0C945lrGmat6+q0oiG7XDMDJgsj Y/3bRp+jlhqP3jjkyjWkGkzmKX9OjtRFMdHwOgQJuItHsBMg73WVHdwG7TWjWfuAQelo vZmQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5cTqKRCK+THCzU9zFxj2wNoU+s5c5iffxnpMfN5/umQ=; b=Kzma0+mN0VTn5alsH1tBEpEi5SPb7ugU1FIM/hMR+JZoieugwSRKhSposRe45xjJ2H wyh+C0vLi38dioBe9oLv6g5VazceWlevlTnSJ4Qjo1pj4HaXw/pZk3BBzNP4lhS1lrV1 ulDU5u8kdZpohrY+NzTD3p6Yy6+C0YnzjfH3oMIBr4xazJb1kEROi713McOuHoqDavmx D01Jm8a5iZ6mSYGs7PpSqYZFm0XFEqO/px38Oi4wDz7WYrhhoIl1bkOQE70hKbYq86Ck BYJNirHcL5oEGUvi15r5DaNtDMRC/eb6sfXLp5kYprIx8bxcldMizGLwi/tFu86Ymtf3 1qnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y8fbD7Jj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si18335700pgc.252.2019.03.27.11.40.45; Wed, 27 Mar 2019 11:41:00 -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=y8fbD7Jj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391437AbfC0SXP (ORCPT + 99 others); Wed, 27 Mar 2019 14:23:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391425AbfC0SXN (ORCPT ); Wed, 27 Mar 2019 14:23:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E62922147C; Wed, 27 Mar 2019 18:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710992; bh=Ek98DyMqGNfJJgGs5OKkAQBfUb6D/M6DNWE6LO1EwqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y8fbD7Jjj9tUQ8UyViqq/i/MXm4NO/xnV9acn3Hx1abZCa5tY9vRR/2KDPRNPhgIg HVgDmVeMdClewe5hJohpYJLKTyDULLNEeqIMufIE0z+d6uwnv0doBrVkmzBQ6D+lmM lzWP2Yf+oukyaOjscG6mXtIpiRI1wS8O7juLsMho= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: George Rimar , Tri Vo , Borislav Petkov , "H. Peter Anvin" , Ingo Molnar , Michael Matz , Thomas Gleixner , morbo@google.com, ndesaulniers@google.com, ruiu@google.com, x86-ml , Sasha Levin Subject: [PATCH AUTOSEL 4.9 81/87] x86/build: Specify elf_i386 linker emulation explicitly for i386 objects Date: Wed, 27 Mar 2019 14:20:34 -0400 Message-Id: <20190327182040.17444-81-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: George Rimar [ 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