Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1525942imu; Sat, 12 Jan 2019 02:01:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN63aX51vzsYt0hn5bQVsp584nvpXmTVCIQPUvzz0e+KtVl571xbQzbn5Dkf0mgTqzc1Qvr8 X-Received: by 2002:a63:62c4:: with SMTP id w187mr15084150pgb.230.1547287316533; Sat, 12 Jan 2019 02:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547287316; cv=none; d=google.com; s=arc-20160816; b=Lj271vmpQtZYI73ILDepKD0wHkS2GrkSnDzi7OzfF6NTUe7JW6Z3BWtScir+GYGmFN fiV71E28fDakF33c55M1ID+NwgdKB6i/tLwwWhyy9J9NzFgaEvtt3byhOJK6m5zwCdTL JPxhLImzyeZ+W4tMYPw/muSgkAWeC45AGY3QdoQ6Eh5gNVlbDNd3A+1TxsobU71y89B8 uK901U+86eDN93sdk5MNXoopvzlOuune0RsP++6R4diza75OWLhTY61r99nkeIUq4ypH RD9S31K+tVXf6xn7sabZsH8Osh/NzDukDuDP/fgoKe7QGSd0BXWPP5rj5ZbfMGKrSFAB Ngpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=luk1eLSAOB8p0u/GG+cpGIViiJvslla1DNy6GPperXg=; b=o2t5scsb3ETNN2KgLl2u4WFCekm2LLXf5JO7gOn4YLwd+8pYafjgouPcaoZqNZ7whM KaRjWxu3lBfUyyB7/640uH1k39sM4A7lGKdeSPvXg0EusewRWAhqF/XNDkSwG8u3d4wt nm6sBDCIPgD5CINqgdccfDql2/+9MFy392Ib1KIgX2XqMQ4IRV9PML13oDxNTfpmxsw2 3oT9r+ZSWyqmthsUwLiHizLv+6xP1CCHyiWAQS50UYHgaRywpJaOJk8Op4GHQRmtP5i8 MngLSllnadCo+YRoF/pPxvN92KAJfRnlrIdlOkcf7xgF1dFkOwMJQVH0yU/AyB0b1t7l KNFw== 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 p26si3717071pfj.244.2019.01.12.02.01.40; Sat, 12 Jan 2019 02:01:56 -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 S1725851AbfALKAh convert rfc822-to-8bit (ORCPT + 99 others); Sat, 12 Jan 2019 05:00:37 -0500 Received: from mail.accesssoftek.com ([12.202.173.242]:47677 "EHLO mail.accesssoftek.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbfALKAh (ORCPT ); Sat, 12 Jan 2019 05:00:37 -0500 Received: from vm-mail2k13.accesssoftek.com (172.16.0.242) by vm-mail2k13.accesssoftek.com (172.16.0.242) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Sat, 12 Jan 2019 02:00:36 -0800 Received: from vm-mail2k13.accesssoftek.com ([::1]) by vm-mail2k13.accesssoftek.com ([::1]) with mapi id 15.00.1395.000; Sat, 12 Jan 2019 02:00:36 -0800 From: George Rimar To: Tri Vo , "x86@kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "hpa@zytor.com" CC: "dima@golovin.in" , "morbo@google.com" , "ndesaulniers@google.com" , "matz@suse.de" , "ruiu@google.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3] x86_64: Add "-m elf_i386" when linking i386 object files. Thread-Topic: [PATCH v3] x86_64: Add "-m elf_i386" when linking i386 object files. Thread-Index: AQHUqemzjPdoQZ+FoUOJC0WuWoOLa6WrZ3sx Date: Sat, 12 Jan 2019 10:00:36 +0000 Message-ID: <1547286899727.75112@accesssoftek.com> References: ,<20190111201012.71210-1-trong@android.com> In-Reply-To: <20190111201012.71210-1-trong@android.com> Accept-Language: ru-RU, en-US Content-Language: ru-RU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [95.174.98.187] Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: George Rimar Best regards, George | Developer | Access Softek, Inc ________________________________________ ??: Tri Vo ??????????: 11 ?????? 2019 ?. 23:10 ????: x86@kernel.org; tglx@linutronix.de; mingo@redhat.com; bp@alien8.de; hpa@zytor.com ?????: George Rimar; dima@golovin.in; morbo@google.com; ndesaulniers@google.com; matz@suse.de; ruiu@google.com; linux-kernel@vger.kernel.org; Tri Vo ????: [PATCH v3] x86_64: Add "-m elf_i386" when linking i386 object files. CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. If you suspect potential phishing or spam email, report it to ReportSpam@accesssoftek.com From: George Rimar Linux kernel uses OUTPUT_FORMAT in it's linker scripts. Most of the time -m option is passed to the linker with correct architecture, but sometimes (at least for x86_64) the -m option contradicts OUTPUT_FORMAT directive. Specifically, arch/x86/boot and arch/x86/realmode/rm modules have i386 object files, but are linked with -m elf_x86_64 linker flag when building for x86_64. "man ld" doesn't explicitly state any tie-breakers between -m and OUTPUT_FORMAT. BFD and Gold linkers override -m value with OUTPUT_FORMAT. But LLVM lld has a different behavior. 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 Suggested fix: just add correct -m after 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) it already overrides -m EMULATION with OUTPUT_FORMAT. Tested by building x86_64 kernel with GNU gcc/ld toolchain and booting it in QEMU. Suggested-by: Dmitry Golovin Signed-off-by: George Rimar Signed-off-by: Tri Vo Tested-by: Tri Vo Tested-by: Nick Desaulniers --- v2: updated commit message to clarify that ld documentation is ambiguous w.r.t -m vs OUTPUT_FORMAT behavior. v3: fixed/added SOB and "Tested-by" fields. 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 -- 2.20.1.97.g81188d93c3-goog