Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3764765imu; Tue, 18 Dec 2018 03:55:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/WSMHXfhhGx/S1gl2OTLZKSvwsDQVRxU3V/q43obkTe+NuuwHjhlsNbgirj0JQ6MSbGqGeK X-Received: by 2002:a17:902:9f93:: with SMTP id g19mr15874957plq.195.1545134119412; Tue, 18 Dec 2018 03:55:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545134119; cv=none; d=google.com; s=arc-20160816; b=tUI94QGDwydz70jwcQVn7mWfx/73eTHiwqtwrpjqEbc5MOLZWyKf8mDFBikjWokva4 MvMmSW/njGhF5yOS46kc4RpHF3lA2Zh9zysiZ8pQGN80y65a/emMwtA4lbhIUpg7c6/s nL5xfrExjqo8OOhQWt3JR6hvRjU6HrI+bNBRPvUBluUFTAvDdJaRaDUBAvx4BnHJocni rfO0hj9LWuDOXsHG2T+Th+ejYras64stLRMYzfmeIIF4LrRWglnavxxTAYmjPsY8oTY+ fjbpOL/YPdHDh9Kklm4gLc9iPomMgk8OYVLbG9/YfEHYmqwgDy+Vyd229NRs+PyJi0uw vy/w== 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=3X/vszlupfR691Xj3L+uon+iGtK0aMOx5zSWa7ADSvs=; b=SD4g6qQoKsDhKXZZIam5yn8DvMmg+7qApfCL6YMsJTlmAV5kGl6G24a4YhUZnsDYE8 9LrLrAvEzQ1QoZx1Ejto4b1E70S05Mmfg4KRCxU+d4u7I2OopYx+QhjvMACKHopAcgdj xud9nqv9rNcwFyZC2F6bXzxHFgMFksYgjpyCy4xcMidt/qhDX7GoZ44Y2UHmgoNSKi1O wvjsRX+/x46MyVPiZU77bzSho04F7sC44+TnDdDxdw7d800fKRcjJZCq+Z7e/cBJm0ra EzV5ctuBV72zwTRjjlVOJjZGmWY0+1wbaouPd6nB0Kwt8UDAEG+hIQgzKXcKOczGQLpw gT1Q== 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 y2si13065500pfy.29.2018.12.18.03.55.03; Tue, 18 Dec 2018 03:55:19 -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 S1726663AbeLRLyB convert rfc822-to-8bit (ORCPT + 99 others); Tue, 18 Dec 2018 06:54:01 -0500 Received: from mail.accesssoftek.com ([12.202.173.242]:26810 "EHLO mail.accesssoftek.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbeLRLyB (ORCPT ); Tue, 18 Dec 2018 06:54:01 -0500 X-Greylist: delayed 901 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Dec 2018 06:54:00 EST 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; Tue, 18 Dec 2018 03:38:59 -0800 Received: from vm-mail2k13.accesssoftek.com ([::1]) by vm-mail2k13.accesssoftek.com ([::1]) with mapi id 15.00.1395.000; Tue, 18 Dec 2018 03:38:59 -0800 From: George Rimar To: Tri Vo , Nick Desaulniers CC: "bp@alien8.de" , "x86@kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , Dmitry Golovin , Bill Wendling , "hpa@zytor.com" , "linux-kernel@vger.kernel.org" , "ruiu@google.com" Subject: Re: [RFC PATCH] x86_64: Add "-m elf_i386" when linking i386 object files. Thread-Topic: [RFC PATCH] x86_64: Add "-m elf_i386" when linking i386 object files. Thread-Index: AQHUkNdwlIee1pwyXku0mPDK4R60X6V5GfsAgAF1d4CAAXxkgIAIXS6t Date: Tue, 18 Dec 2018 11:38:59 +0000 Message-ID: <1545132839351.85480@accesssoftek.com> References: <20181210222635.80886-1-trong@android.com> , In-Reply-To: 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 Added Rui, an LLD code owner. This patch contains the approach we discussed earlier during LLD development when faced this issue first time (and as a result of the discussion, the same fix was suggested: https://bugzilla.kernel.org/show_bug.cgi?id=194091#c0), so I think it is fine. Best regards, George | Developer | Access Softek, Inc ________________________________________ ??: Tri Vo ??????????: 12 ??????? 2018 ?. 22:48 ????: Nick Desaulniers ?????: bp@alien8.de; x86@kernel.org; tglx@linutronix.de; mingo@redhat.com; George Rimar; Dmitry Golovin; Bill Wendling; hpa@zytor.com; linux-kernel@vger.kernel.org ????: Re: [RFC PATCH] 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. Adding appropriate people, lists. On Tue, Dec 11, 2018 at 1:07 PM Nick Desaulniers wrote: > > On Mon, Dec 10, 2018 at 2:50 PM Nick Desaulniers > wrote: > > > > On Mon, Dec 10, 2018 at 2:26 PM Tri Vo wrote: > > > > > > 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. > > > > > > BFD and Gold linkers are OK with this, but lld fails: > > > 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 (it will also > > > work with GNU ld, because it supports OUTPUT_FORMAT and just ignores -m > > > options if this directive is in the linker script). > > > > > > Tested by building x86_64 kernel with GNU gcc/ld toolchain and booting > > > it in QEMU. > > > > > > Suggested-by: Dmitry Golovin > > > Signed-off-by: Tri Vo > > > Tested-by: Tri Vo > > > > This fixes the following linkage error I observe when linking an x86 > > kernel with LLD: > > > > ``` > > LD arch/x86/realmode/rm/realmode.elf > > ld.lld: error: arch/x86/realmode/rm/header.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/trampoline_64.o is incompatible > > with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/stack.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/reboot.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/wakeup_asm.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/wakemain.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/video-mode.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/copy.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/bioscall.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/regs.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/video-vga.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/video-vesa.o is incompatible with elf_x86_64 > > ld.lld: error: arch/x86/realmode/rm/video-bios.o is incompatible with elf_x86_64 > > arch/x86/realmode/rm/Makefile:55: recipe for target > > 'arch/x86/realmode/rm/realmode.elf' failed > > ``` > > Tested-by: Nick Desaulniers > > > > Looks like we still have a few other (unrelated) issues to track down > > with LLD, but this gets us one step closer. > > > > Thanks for sending this, Tri! > > Just some additional thoughts on this: > > The kernel is adding -m elf_x86_64 to the linker command line > parameters, but then relying on binutils tie-breaking-behavior by > specifying a different architecture via linker script. So it's > ambiguous which arch the kernel is trying to link for, and the kernel > gets lucky/relies on the way ld.bfd happens to resolve this ambiguity > without warning. An alternative fix may be to just filter out/remove > the -m elf_x86_64 for this target's linker flags. > > > > > > --- > > > 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.0.rc2.403.gdbc3b29805-goog > > > > > > > > > -- > > Thanks, > > ~Nick Desaulniers > > > > -- > Thanks, > ~Nick Desaulniers