]> git.baikalelectronics.ru Git - uboot.git/commitdiff
ARM: make gd a function call for LTO and set via set_gd()
authorMarek Behún <marek.behun@nic.cz>
Thu, 20 May 2021 11:24:10 +0000 (13:24 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 24 May 2021 18:21:30 +0000 (14:21 -0400)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/arm/cpu/arm926ejs/mxs/spl_boot.c
arch/arm/include/asm/global_data.h
arch/arm/mach-exynos/spl_boot.c
arch/arm/mach-imx/imx8m/soc.c
arch/arm/mach-imx/spl_imx_romapi.c

index a16a15e79d8391e242ce692184e17e0c6bf28237..66406cc85795ade9f685e5f2da9da4293a2782dd 100644 (file)
@@ -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();
 
index bb82efafa61e194f6d293cd0a0768c4c3e29ef3f..2aff1c467c14e37954b5df7a18771babd83b0546 100644 (file)
@@ -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()
index 27f0dac182d37a9243e01b75e4608ac597388be1..722449881af27ab3803cbe655aa59c3a70f865cc 100644 (file)
@@ -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;
index 36abb2e57f0f69221fe7287e39acb86c8d1b00d2..0c44022a6dca744ddb6e42022d652b7ec3955a54 100644 (file)
@@ -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");
index 9f4d95982e59f9bf8b33c71dba334ee5bb533443..d2085dabd3f3baf585f06b1e575a6161d8fcc625 100644 (file)
@@ -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");