Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4628730ybb; Tue, 7 Apr 2020 11:11:08 -0700 (PDT) X-Google-Smtp-Source: APiQypK0CPnInMwtky+Ak0xWqdJR86REJMxfoBiIOWF6Oc0rfcemZa0WY9NxYzDbcz+xsfLoEeFF X-Received: by 2002:a9d:6184:: with SMTP id g4mr2591699otk.38.1586283068493; Tue, 07 Apr 2020 11:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586283068; cv=none; d=google.com; s=arc-20160816; b=O01r3j1hrJvYfPhezvFAr/Sb+UD1290QHqZn2KcCGGJExMAuz3lEVHyogIqXp2Xb3I Qw3kIdGW2xyUBU6srcC9koI40PcZzKuD98YwdJ6268G+he9n//hC/PDQyKI/LAai3idy qlmPEMy5fFeFKXak//6V33hWRsWtp8DO+Y426tFRa7xuaKg118PRc2O9szEc3frK5O9e Q2z3yppBFlPj/Z8o7LpMkR0apfJo4itJ8ZSVMIxCBmOiBhq2utuGYaX3TDO9nTBHp2Ab uSETJmw9Hf2oJAC7SqghMWVZIffMQgUurSVnqqWQiPnsgo6LpFZP1HoLdV6tal2lYWGD cDVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date; bh=RqRMUcFYybnOGi8AONi7ZDh1UPTZ7wf+AlHIo8q1s3g=; b=bB+P2IRbA6NIlsMikj6Gfd2mSDD8rWaN74GJx2nQ+VLKz/mVpb/qJd3qEvl3CCiDcV xQfphHttA9JSf5cGXInZ1KxcoJnaLI4U6A6Mp6HAgLmCMHjffvz1LtOFA1Yal9Jr+Z0N KDDKhSsQAWLVNbkes0Z1KYCF9oE7mvX0FKV/IhcoQqPhx2Abi6HFy8yWWjQTuqNOtO1+ xcmzwSbW6Siio1WClN3vk2PtNQOktmTZLn5L3DflqG70Q26aKNS1PXDWx1pomVYEqkDh rJavpetIHikoYbWj+DBtxNfZi1LqALA5nXCk1QKVS2vBTrhK14tGAw6i1PMtRud26lFa OCMA== 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 u7si1597055oth.8.2020.04.07.11.10.53; Tue, 07 Apr 2020 11:11:08 -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; 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 S1726436AbgDGSKN (ORCPT + 99 others); Tue, 7 Apr 2020 14:10:13 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:33314 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgDGSKN (ORCPT ); Tue, 7 Apr 2020 14:10:13 -0400 Received: (from localhost user: 'macro', uid#1010) by eddie.linux-mips.org with ESMTP id S23993994AbgDGSKISscAr (ORCPT + 1 other); Tue, 7 Apr 2020 20:10:08 +0200 Date: Tue, 7 Apr 2020 19:10:08 +0100 (BST) From: "Maciej W. Rozycki" To: Nick Desaulniers cc: Jiaxun Yang , linux-mips@vger.kernel.org, clang-built-linux , Fangrui Song , Nathan Chancellor , Thomas Bogendoerfer , LKML Subject: Re: [PATCH v2] MIPS: Truncate load-y into 32bit for 32bit kernel In-Reply-To: Message-ID: References: <20200405082451.694910-1-jiaxun.yang@flygoat.com> <20200407080611.859256-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 7 Apr 2020, Nick Desaulniers wrote: > V2 is way too clever, V1 was much more readable. I think V2 is a step in the right direction except it still has some issues, and also I'd simplify it as there's surely too much processing there. OTOH V1 is going to be a maintenance nightmare, as you need to handle all platforms individually whether they want different 32-bit and 64-bit load addresses or not. > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > index e1c44aed8156..f8fd3c39fb55 100644 > > --- a/arch/mips/Makefile > > +++ b/arch/mips/Makefile > > @@ -286,6 +286,9 @@ ifdef CONFIG_64BIT > > $(error CONFIG_CPU_DADDI_WORKAROUNDS unsupported without -msym32) > > endif > > endif > > +else > > + # Truncate address into 32-bit > > + load-y := 0x$(shell echo "$(load-y)" | rev | head -c 8 | rev) You cannot just truncate `load-y' in place like this as it will break logic with `expr' used elsewhere in this Makefile (your original change would too) that does a string comparison on this variable. So you need to define another variable for the sole linker's use, like `load-ld'. Then I think there's no need to invoke multiple programs, especially ones we don't currently rely on (`rev'). How about: load-ld = $(shell echo "$(load-y)" | sed 's/.\{8\}\(.\{8\}\)$/\1/') Also this really needs to be placed elsewhere, as it has nothing to do with KBUILD_SYM32 it has been attached to with this change, and explain why it is done rather than what (it's obvious from the command it's meant to truncate the address). So use something along the lines of: # When linking a 32-bit executable the LLVM linker cannot cope with a # 32-bit load address that has been sign-extended to 64 bits. Simply # remove the upper 32 bits then, as it is safe to do so with other # linkers. ifdef CONFIG_64BIT load-ld = $(load-y) else load-ld = $(shell echo "$(load-y)" | sed 's/.\{8\}\(.\{8\}\)$/\1/') endif just above the use place, and then adjust the place to refer `load-ld' rather than `load-y'. Put the justification for this change (feel free to reuse observations I made here), like why a new variable, in the change description. Maciej