All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <marek.behun@nic.cz>
To: u-boot@lists.denx.de
Subject: [PATCH u-boot v4 21/36] ARM: make gd a function call for LTO and set via set_gd()
Date: Thu, 20 May 2021 13:24:10 +0200	[thread overview]
Message-ID: <20210520112425.25166-22-marek.behun@nic.cz> (raw)
In-Reply-To: <20210520112425.25166-1-marek.behun@nic.cz>

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 <marek.behun@nic.cz>
---
 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 <asm-generic/global_data.h>
 
-#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 36abb2e57f..0c44022a6d 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -537,7 +537,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");
-- 
2.26.3

  parent reply	other threads:[~2021-05-20 11:24 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20 11:23 [PATCH u-boot v4 00/36] U-Boot LTO (Sandbox + Some ARM boards) Marek Behún
2021-05-20 11:23 ` [PATCH u-boot v4 01/36] regmap: fix a serious pointer casting bug Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-20 19:30     ` Marek Behun
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 02/36] checkpatch: require quotes around section name in the __section() macro Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 03/36] treewide: Convert macro and uses of __section(foo) to __section("foo") Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 04/36] compiler.h: align the __ADDRESSABLE macro with Linux' version Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 05/36] test/py: improve regular expression for ut subtest symbol matcher Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 06/36] string: make memcpy(), memset(), memcmp() and memmove() visible for LTO Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 07/36] efi_loader: fix warning when linking with LTO Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 08/36] efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 09/36] efi_loader: add macro for const EFI runtime data Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 10/36] efi_selftest: compiler flags for efi_selftest_miniapp_exception.o Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 11/36] lib: crc32: put the crc_table variable into efi_runtime_rodata section Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 12/36] Makefile, Makefile.spl: cosmetic change Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 13/36] build: use thin archives instead of incremental linking Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 14/36] build: support building with Link Time Optimizations Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 15/36] build: link with --build-id=none Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 16/36] sandbox: errno: avoid conflict with libc's errno Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 17/36] sandbox: use sections instead of symbols for getopt array boundaries Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 18/36] sandbox: make LTO available Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 19/36] sandbox: enable LTO by default Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 20/36] ARM: global_data: make set_gd() work for armv5 and armv6 Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` Marek Behún [this message]
2021-05-20 17:52   ` [PATCH u-boot v4 21/36] ARM: make gd a function call for LTO and set via set_gd() Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 22/36] ARM: fix LTO build for some thumb-interwork cases Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 23/36] ARM: fix LTO for imx28_xea Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 24/36] ARM: fix LTO for apf27 Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 25/36] ARM: fix LTO for keystone Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 26/36] ARM: kona: fix clk_bsc_enable() type mismatch for LTO Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 27/36] ARM: imx8m: fix imx_eqos_txclk_set_rate() " Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 28/36] ARM: fix LTO for seaboard Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 29/36] ARM: fix LTO for rockchip and samsung Marek Behún
2021-05-22  2:45   ` Kever Yang
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 30/36] ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards) Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 31/36] armv8: SPL: discard relocation information Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 32/36] ata: ahci: fix ahci_link_up() type mismatch for LTO Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 33/36] ARM: make LTO available Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 34/36] ARM: don't use -ffunction-sections/-fdata-sections with LTO build Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 35/36] ARM: don't use --gc-sections with LTO when using private libgcc Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 36/36] ARM: enable LTO for some boards Marek Behún
2021-05-20 18:56   ` Adam Ford
2021-05-21 14:11     ` Tom Rini
2021-05-21 16:00       ` Marek Behún
2021-05-21 16:56         ` Tom Rini
2021-05-24 15:40           ` Tom Rini
2021-05-24 15:58             ` Marek Behun
2021-05-24 16:23               ` Tom Rini
2021-05-24 17:09               ` Tom Rini
2021-05-24 17:44                 ` Tom Rini
2021-05-24 19:19                   ` Marek Behun
2021-05-24 19:56                     ` Tom Rini
2021-05-24 19:54               ` Tom Rini
2021-05-21 16:00       ` Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-06-01 14:59 ` [PATCH u-boot v4 00/36] U-Boot LTO (Sandbox + Some ARM boards) Patrick DELAUNAY
2021-06-01 15:05   ` Tom Rini
2021-06-01 16:22   ` Marek Behún
2021-06-01 16:55     ` Heinrich Schuchardt
2021-06-01 17:23       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210520112425.25166-22-marek.behun@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.