Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp108673ybg; Mon, 8 Jun 2020 17:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwetRZHMnCRgdWAuTEAiWDHJ0/QKzW1pQQBzpAV+dPmiQvGp8d1/MmCnW+tmq6gcJkg4+CC X-Received: by 2002:a17:906:2b81:: with SMTP id m1mr22375820ejg.488.1591663831643; Mon, 08 Jun 2020 17:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663831; cv=none; d=google.com; s=arc-20160816; b=f3L4jfgzwhIB1Zpr55+JcuwNw3x/6ZhqqOqoCK+gp5Bhs+kb/YDfwS07ajipXvW4ln vd0hw+lWpPIAAfd2FvTet+FVjscxfQsEQGGc2DOs/jcUU/zgJ8bslGmbEZog7JrWZRKJ jAZol4CBrZlFZ7+7KwoQ59xcdOUQyC9g5SMYdOhZDegcIRyzvAW35BZJixcxLsHtKBes D74Dn3qgNBgm3P+v0dVizqJvDA+3KvgyPWaofSrKDrwClaT80h6LkjsAOOD7+tQXC2SA Vz7ARKCCwkBj8yiH96rdJ2Gys3whL30+p9aKr7Sbij+BAu0q8xKrtK4N+YzUY58YC7om eh3Q== 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=pEMJJ7CAbuFCpVwQvUjAK/sVMsxgMKgm+cTVsqPXL0k=; b=M+Hvx65xz5np1HYNb9tTJyQ9LekWeeKZmGIXr+SVomz1RNVR2Cd85GsN4NyI1Ouo9v kSfFg9nvuXSEMeU805Ez2iYmNeB6QNDVKXdfAqajHNgL4l6lKUlx92WqqCcGjBkxZZh7 3MlE/OY2wOt3wed1J3kIzKVOy1FSQ/R50sIhnTivtMXeGn1gQCgcxBecQbls0q06uu9X qkpZPtyQ7jIrCS/RoqH5xiBsCIYc1vbDGAw1seHrRfwqnJdl+6VZx+zy3esUiihmdfq2 1IpYXYkcmjvs5MjdKd/9sHL5NKVvB076IY99zJjn0DMVJvjSYD0RhIDYwfqvxlmHIvVV Ga7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FTQkXcE6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id c23si9286429ejb.308.2020.06.08.17.50.00; Mon, 08 Jun 2020 17:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FTQkXcE6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728865AbgFHXLN (ORCPT + 99 others); Mon, 8 Jun 2020 19:11:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728520AbgFHXJu (ORCPT ); Mon, 8 Jun 2020 19:09:50 -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 16B4520897; Mon, 8 Jun 2020 23:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657790; bh=OnMZ5vdf2YOk5hWtwLFzh1/pxKKBakX8EVWv9pl+oRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FTQkXcE6rcB88KkQ3/0g+kt1qp7YVZvaoVUE28beR4iNng8B9DormmSdT78khEeQy gI/xsDTC3leqzNPw92UuUSxCgcKsoqRXFzVUd1So2WnI/5MZhqYS20cE86H6ywejtg 3kzpro3uQHzpC3OcKfsfOCNq8sGCwoGfkTMvOl6A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jiaxun Yang , Fangrui Song , Kees Cook , Nathan Chancellor , "Maciej W . Rozycki" , Nick Desaulniers , Thomas Bogendoerfer , Sasha Levin , linux-mips@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 5.7 170/274] MIPS: Truncate link address into 32bit for 32bit kernel Date: Mon, 8 Jun 2020 19:04:23 -0400 Message-Id: <20200608230607.3361041-170-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review 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: Jiaxun Yang [ Upstream commit ff487d41036035376e47972c7c522490b839ab37 ] LLD failed to link vmlinux with 64bit load address for 32bit ELF while bfd will strip 64bit address into 32bit silently. To fix LLD build, we should truncate load address provided by platform into 32bit for 32bit kernel. Signed-off-by: Jiaxun Yang Link: https://github.com/ClangBuiltLinux/linux/issues/786 Link: https://sourceware.org/bugzilla/show_bug.cgi?id=25784 Reviewed-by: Fangrui Song Reviewed-by: Kees Cook Tested-by: Nathan Chancellor Cc: Maciej W. Rozycki Tested-by: Nick Desaulniers Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/Makefile | 13 ++++++++++++- arch/mips/boot/compressed/Makefile | 2 +- arch/mips/kernel/vmlinux.lds.S | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/mips/Makefile b/arch/mips/Makefile index e1c44aed8156..b6ee29e4565a 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -288,12 +288,23 @@ ifdef CONFIG_64BIT endif endif +# 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 = $(subst 0xffffffff,0x,$(load-y)) +endif + KBUILD_AFLAGS += $(cflags-y) KBUILD_CFLAGS += $(cflags-y) -KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y) +KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y) -DLINKER_LOAD_ADDRESS=$(load-ld) KBUILD_CPPFLAGS += -DDATAOFFSET=$(if $(dataoffset-y),$(dataoffset-y),0) bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y) \ + LINKER_LOAD_ADDRESS=$(load-ld) \ VMLINUX_ENTRY_ADDRESS=$(entry-y) \ PLATFORM="$(platform-y)" \ ITS_INPUTS="$(its-y)" diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile index 0df0ee8a298d..6e56caef69f0 100644 --- a/arch/mips/boot/compressed/Makefile +++ b/arch/mips/boot/compressed/Makefile @@ -90,7 +90,7 @@ ifneq ($(zload-y),) VMLINUZ_LOAD_ADDRESS := $(zload-y) else VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \ - $(obj)/vmlinux.bin $(VMLINUX_LOAD_ADDRESS)) + $(obj)/vmlinux.bin $(LINKER_LOAD_ADDRESS)) endif UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index a5f00ec73ea6..f185a85a27c1 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -55,7 +55,7 @@ SECTIONS /* . = 0xa800000000300000; */ . = 0xffffffff80300000; #endif - . = VMLINUX_LOAD_ADDRESS; + . = LINKER_LOAD_ADDRESS; /* read-only */ _text = .; /* Text and read-only data */ .text : { -- 2.25.1