From patchwork Tue Mar 16 12:25:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1453890 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.a=rsa-sha256 header.s=default header.b=C5WKYgTR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0CNh2Zs9z9sRR for ; Tue, 16 Mar 2021 23:32:36 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 385E582903; Tue, 16 Mar 2021 13:28:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="C5WKYgTR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A344082654; Tue, 16 Mar 2021 13:27:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 347B280505 for ; Tue, 16 Mar 2021 13:26:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.behun@nic.cz Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTPSA id B9AAA140B53; Tue, 16 Mar 2021 13:26:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1615897609; bh=YSmYXOlsIlamNVmkxzaYJ2kLmZXWWOY4YWwHwCEvdps=; h=From:To:Date; b=C5WKYgTRz4DnQM2i6rRLJu8QC0n25tT1nNQVSk1VWXBb4t1+GJ1iLhgP1nG5Z9zJ4 k9DY7UIJfVFhWKFt0J5djqeFXrwlCSQBu//LXDtvtHjPpKY135e5n+6oxN6gWysgOV O31hRzddjygHrfaAc/n3x7IZS8/3sb+Gt7+ox3ek= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de, Simon Glass , Heiko Schocher , Patrick Delaunay , Patrice CHOTARD , Miquel Raynal , Tom Rini , =?utf-8?q?Pali_Roh=C3=A1r?= , Stefan Roese , Heinrich Schuchardt , Alexander Graf , Marek Vasut , Neil Armstrong , Ryder Lee , Adam Ford , Bin Meng , Harald Seiler , Tim Harvey Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot v3 24/39] ARM: make gd a function call for LTO and set via set_gd() Date: Tue, 16 Mar 2021 13:25:54 +0100 Message-Id: <20210316122609.6523-25-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210316122609.6523-1-marek.behun@nic.cz> References: <20210316122609.6523-1-marek.behun@nic.cz> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean On ARM, the gd pointer is stored in registers r9 / x18. For this the -ffixed-r9 / -ffixed-x18 flag is used when compiling, but using global register variables causes errors when building with LTO, and these errors are very difficult to overcome. Richard Biener says [1]: Note that global register vars shouldn't be used with LTO and if they are restricted to just a few compilation units the recommended fix is to build those CUs without -flto. We cannot do this for U-Boot since all CUs use -ffixed-reg flag. It seems that with LTO we could in fact store the gd pointer differently and gain performance or size benefit by allowing the compiler to use r9 / x18. But this would need more work. So for now, when building with LTO, go the clang way, and instead of declaring gd a global register variable, we make it a function call via macro. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68384 Signed-off-by: Marek BehĂșn --- arch/arm/cpu/arm926ejs/mxs/spl_boot.c | 2 +- arch/arm/include/asm/global_data.h | 2 +- arch/arm/mach-exynos/spl_boot.c | 2 +- arch/arm/mach-imx/imx8m/soc.c | 2 +- arch/arm/mach-imx/spl_imx_romapi.c | 16 ++++++++-------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c index a16a15e79d..66406cc857 100644 --- a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c +++ b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c @@ -122,7 +122,7 @@ void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr, { struct mxs_spl_data *data = MXS_SPL_DATA; uint8_t bootmode = mxs_get_bootmode_index(); - gd = &gdata; + set_gd(&gdata); mxs_spl_fixup_vectors(); diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h index bb82efafa6..2aff1c467c 100644 --- a/arch/arm/include/asm/global_data.h +++ b/arch/arm/include/asm/global_data.h @@ -91,7 +91,7 @@ struct arch_global_data { #include -#ifdef __clang__ +#if defined(__clang__) || defined(CONFIG_LTO) #define DECLARE_GLOBAL_DATA_PTR #define gd get_gd() diff --git a/arch/arm/mach-exynos/spl_boot.c b/arch/arm/mach-exynos/spl_boot.c index 27f0dac182..722449881a 100644 --- a/arch/arm/mach-exynos/spl_boot.c +++ b/arch/arm/mach-exynos/spl_boot.c @@ -279,7 +279,7 @@ void memzero(void *s, size_t n) */ static void setup_global_data(gd_t *gdp) { - gd = gdp; + set_gd(gdp); memzero((void *)gd, sizeof(gd_t)); gd->flags |= GD_FLG_RELOC; gd->baudrate = CONFIG_BAUDRATE; diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index 5f37282ff1..15d0da7060 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -509,7 +509,7 @@ enum boot_device get_boot_device(void) ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, ((uintptr_t)&boot) ^ QUERY_BT_DEV); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { puts("ROMAPI: failure at query_boot_info\n"); diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c index 9f4d95982e..d2085dabd3 100644 --- a/arch/arm/mach-imx/spl_imx_romapi.c +++ b/arch/arm/mach-imx/spl_imx_romapi.c @@ -45,7 +45,7 @@ static ulong spl_romapi_read_seekable(struct spl_load_info *load, ret = g_rom_api->download_image(buf, offset, byte, ((uintptr_t)buf) ^ offset ^ byte); - gd = pgd; + set_gd(pgd); if (ret == ROM_API_OKAY) return count; @@ -73,7 +73,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, ret |= g_rom_api->query_boot_infor(QUERY_IMG_OFF, &image_offset, ((uintptr_t)&image_offset) ^ QUERY_IMG_OFF); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { puts("ROMAPI: Failure query boot infor pagesize/offset\n"); @@ -94,7 +94,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, size = ALIGN(sizeof(struct image_header), pagesize); ret = g_rom_api->download_image((u8 *)header, offset, size, ((uintptr_t)header) ^ offset ^ size); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { printf("ROMAPI: download failure offset 0x%x size 0x%x\n", @@ -180,7 +180,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, ret = g_rom_api->query_boot_infor(QUERY_PAGE_SZ, &pagesize, ((uintptr_t)&pagesize) ^ QUERY_PAGE_SZ); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) puts("failure at query_boot_info\n"); @@ -192,7 +192,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, for (i = 0; i < 640; i++) { ret = g_rom_api->download_image(p, 0, pg, ((uintptr_t)p) ^ pg); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { puts("Steam(USB) download failure\n"); @@ -213,7 +213,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, if (p - pfit < sizeof(struct fdt_header)) { ret = g_rom_api->download_image(p, 0, pg, ((uintptr_t)p) ^ pg); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { puts("Steam(USB) download failure\n"); @@ -237,7 +237,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, ret = g_rom_api->download_image(p, 0, imagesize, ((uintptr_t)p) ^ imagesize); - gd = pgd; + set_gd(pgd); p += imagesize; @@ -280,7 +280,7 @@ int board_return_to_bootrom(struct spl_image_info *spl_image, ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, ((uintptr_t)&boot) ^ QUERY_BT_DEV); - gd = pgd; + set_gd(pgd); if (ret != ROM_API_OKAY) { puts("ROMAPI: failure at query_boot_info\n");