Skip to contentSkip to conversation

U-Boot LTO (Sandbox + Some ARM boards)

PATCH In review Marek Behún 7 participants 111 messages May 20, 2021 – Jun 1, 2021

Subsystems (32)
lore
Share & tools
lore
#0 lore raw

v4 cover U-Boot LTO (Sandbox + Some ARM boards)

Hello,

this is version 4 of patches adding support for LTO to U-Boot.

This series is being tested by Github/Azure CI at
https://github.com/u-boot/u-boot/pull/57

There is a problem with sandbox_clang test scenario, which I was unable to resolve yet, or even determine correctly whether the problem is with my patches or was there before. (One of the problems is with testing stack protector test_stackprotector.py, but for some reason I could not make this work even with GCC on my local machine.)
Nevertheless I am sending these patches now so that at least you can review them. In the meantime I will try to resolve the issue with sandbox_clang test scenario.

Changes since v3:
- for some reason the mvneta driver does not work correctly when U-Boot is compiled with LTO. I have not debugged this issue yet, so for now I have removed Turris Omnia and Turris MOX from devices with enabled LTO
- linker list entry symbols are now forced to emit by using the __ADDRESSABLE macro in a generated C file (keep-syms-lto.c). Previously this was done in the ll_entry_declare() macro, but this was not flexible, since, for example, trying to declare an entry as extern could not work that way. This came to attention now after Simon's patches for dtoc were merged, and ll_entry_declare() is being used with the extern keyword in include/generated/dt-decl.h
- when compiling LTO with Clang, use llvm-ar and llvm-nm for AR and NM
- several patches rebased
- removed patch "api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA"
- updated patch converting __attribute__((section(...))) to __section(...)

Changes sinve v2:
- now linking with --build-id=none in order to avoid link failures with some toolchains (thanks Herald Seiler)
- we don't use -flto=jobserver anymore, since it causes build errors for some people. Instead we link with -flto=NPROC
- removed LTO exception for arch/arm/mach-omap2/omap3/clock.o, Adam Ford says it is not needed
- added some Reviewed-by tags

Changes since v1:
- remove patches applied into u-boot-marvell
- added Reviewed-by tags
- addressed some issues discovered by Bin Meng, Marek Vasut, Heinrich Schuchardt
- added more ARM boards (thanks to Adam Ford, Tim Harvey and Bin Meng)
- removed --gc-sections for ARM if internal libgcc is used
- remove -fwhole-program in final LTO LDFLAGS
- declared all 4 functions (memcpy, memset, memcmp, memmove) __used, (these are mentioned in GCC man page for option -nodefaultlibs that the compiler may generate; this seems to be a bug in GCC that linking fails with LTO even if these functions are present, because the symbols can be renamed on some targets by optimization)

Marek

Marek Beh?n (36):
regmap: fix a serious pointer casting bug
checkpatch: require quotes around section name in the __section()
macro
treewide: Convert macro and uses of __section(foo) to __section("foo") compiler.h: align the __ADDRESSABLE macro with Linux' version test/py: improve regular expression for ut subtest symbol matcher
string: make memcpy(), memset(), memcmp() and memmove() visible for
LTO
efi_loader: fix warning when linking with LTO
efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data
efi_loader: add macro for const EFI runtime data
efi_selftest: compiler flags for efi_selftest_miniapp_exception.o
lib: crc32: put the crc_table variable into efi_runtime_rodata section Makefile, Makefile.spl: cosmetic change
build: use thin archives instead of incremental linking
build: support building with Link Time Optimizations
build: link with --build-id=none
sandbox: errno: avoid conflict with libc's errno
sandbox: use sections instead of symbols for getopt array boundaries
sandbox: make LTO available
sandbox: enable LTO by default
ARM: global_data: make set_gd() work for armv5 and armv6
ARM: make gd a function call for LTO and set via set_gd()
ARM: fix LTO build for some thumb-interwork cases
ARM: fix LTO for imx28_xea
ARM: fix LTO for apf27
ARM: fix LTO for keystone
ARM: kona: fix clk_bsc_enable() type mismatch for LTO
ARM: imx8m: fix imx_eqos_txclk_set_rate() type mismatch for LTO
ARM: fix LTO for seaboard
ARM: fix LTO for rockchip and samsung
ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)
armv8: SPL: discard relocation information
ata: ahci: fix ahci_link_up() type mismatch for LTO
ARM: make LTO available
ARM: don't use -ffunction-sections/-fdata-sections with LTO build
ARM: don't use --gc-sections with LTO when using private libgcc
ARM: enable LTO for some boards

 Kbuild                                     |  2 +
 Kconfig                                    | 24 +++++++
 Makefile                                   | 81 ++++++++++++++++++++--
 arch/Kconfig                               |  3 +
 arch/arm/config.mk                         | 10 ++-
 arch/arm/cpu/arm926ejs/Makefile            |  2 +
 arch/arm/cpu/arm926ejs/mxs/mxs.c           |  2 +-
 arch/arm/cpu/arm926ejs/mxs/spl_boot.c      |  4 +-
 arch/arm/cpu/arm926ejs/spear/spl.c         |  2 +-
 arch/arm/cpu/armv7/kona-common/clk-stubs.c |  2 +-
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c  |  2 +-
 arch/arm/cpu/armv8/spl_data.c              |  4 +-
 arch/arm/cpu/armv8/u-boot-spl.lds          |  1 +
 arch/arm/include/asm/global_data.h         |  6 +-
 arch/arm/include/asm/secure.h              |  6 +-
 arch/arm/include/asm/setup.h               |  2 +-
 arch/arm/lib/Makefile                      |  3 +
 arch/arm/lib/sections.c                    | 31 +++++----
 arch/arm/lib/spl.c                         |  2 +-
 arch/arm/mach-at91/spl.c                   |  2 +-
 arch/arm/mach-exynos/spl_boot.c            |  2 +-
 arch/arm/mach-imx/imx8m/clock_imx8mm.c     |  2 +-
 arch/arm/mach-imx/imx8m/soc.c              |  2 +-
 arch/arm/mach-imx/spl_imx_romapi.c         | 16 ++---
 arch/arm/mach-k3/am642_init.c              |  2 +-
 arch/arm/mach-k3/am6_init.c                |  2 +-
 arch/arm/mach-k3/j721e_init.c              |  4 +-
 arch/arm/mach-keystone/Makefile            |  1 +
 arch/arm/mach-mvebu/mbus.c                 |  4 +-
 arch/arm/mach-mvebu/timer.c                |  2 +-
 arch/arm/mach-nexell/clock.c               |  6 +-
 arch/arm/mach-nexell/timer.c               |  6 +-
 arch/arm/mach-omap2/omap3/Makefile         |  1 +
 arch/arm/mach-rockchip/board.c             |  2 +-
 arch/arm/mach-socfpga/spl_a10.c            |  2 +-
 arch/arm/mach-sunxi/board.c                |  2 +-
 arch/arm/mach-tegra/board.c                |  2 +-
 arch/arm/mach-tegra/cboot.c                |  8 +--
 arch/arm/mach-tegra/tegra20/Makefile       |  1 +
 arch/mips/mach-jz47xx/jz4780/jz4780.c      |  2 +-
 arch/nds32/include/asm/setup.h             |  6 +-
 arch/powerpc/include/asm/cache.h           |  4 +-
 arch/riscv/cpu/cpu.c                       |  4 +-
 arch/sandbox/config.mk                     | 14 +++-
 arch/sandbox/cpu/os.c                      |  3 +-
 arch/sandbox/cpu/start.c                   |  3 +-
 arch/sandbox/cpu/u-boot-spl.lds            |  8 ++-
 arch/sandbox/cpu/u-boot.lds                |  8 ++-
 arch/sandbox/include/asm/getopt.h          |  2 +-
 arch/sandbox/include/asm/sections.h        | 21 +++++-
 arch/sandbox/lib/sections.c                |  9 +--
 arch/x86/cpu/coreboot/timestamp.c          |  2 +-
 arch/x86/lib/coreboot/cb_sysinfo.c         |  2 +-
 arch/x86/lib/sections.c                    |  9 +--
 arch/xtensa/cpu/cpu.c                      |  2 +-
 board/bosch/shc/board.c                    |  2 +-
 board/broadcom/bcmstb/bcmstb.c             |  2 +-
 board/samsung/arndale/arndale_spl.c        |  2 +-
 board/samsung/common/exynos5-dt.c          |  2 +-
 board/samsung/smdk5250/smdk5250_spl.c      |  2 +-
 board/samsung/smdk5420/smdk5420_spl.c      |  2 +-
 board/siemens/draco/board.c                |  2 +-
 board/xilinx/common/fru_ops.c              |  2 +-
 configs/am3517_evm_defconfig               |  1 +
 configs/da850evm_defconfig                 |  1 +
 configs/da850evm_direct_nor_defconfig      |  1 +
 configs/da850evm_nand_defconfig            |  1 +
 configs/imx6q_logic_defconfig              |  1 +
 configs/imx8mm_beacon_defconfig            |  1 +
 configs/imx8mm_venice_defconfig            |  1 +
 configs/imx8mn_beacon_2g_defconfig         |  1 +
 configs/imx8mn_beacon_defconfig            |  1 +
 configs/nokia_rx51_defconfig               |  1 +
 configs/omap3_logic_defconfig              |  1 +
 configs/r8a774a1_beacon_defconfig          |  1 +
 configs/r8a774b1_beacon_defconfig          |  1 +
 configs/r8a774e1_beacon_defconfig          |  1 +
 drivers/ata/ahci.c                         |  2 +-
 drivers/bios_emulator/biosemu.c            |  4 +-
 drivers/clk/kendryte/clk.c                 |  4 +-
 drivers/core/regmap.c                      | 59 +++++++++++++++-
 drivers/firmware/psci.c                    |  2 +-
 drivers/mtd/nand/raw/mxc_nand_spl.c        |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx5.c         |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx7.c         |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx8m.c        |  2 +-
 drivers/power/pmic/pmic_tps62362.c         |  2 +-
 drivers/power/pmic/pmic_tps65217.c         |  2 +-
 drivers/power/pmic/pmic_tps65218.c         |  2 +-
 drivers/power/pmic/pmic_tps65910.c         |  2 +-
 drivers/serial/serial_pl01x.c              |  4 +-
 include/efi_loader.h                       | 54 +++++++++++++--
 include/errno.h                            |  8 ++-
 include/linker_lists.h                     | 24 +++----
 include/linux/compiler.h                   | 10 +--
 include/linux/compiler_attributes.h        |  2 +-
 lib/crc32.c                                |  3 +-
 lib/efi_selftest/Makefile                  |  2 +
 lib/errno.c                                |  4 +-
 lib/string.c                               |  9 +--
 lib/trace.c                                |  4 +-
 scripts/Makefile.build                     | 16 ++---
 scripts/Makefile.lib                       |  3 +
 scripts/Makefile.spl                       | 63 +++++++++++++++--
 scripts/checkpatch.pl                      |  2 +-
 scripts/gen_ll_addressable_symbols.sh      | 12 ++++
 test/py/conftest.py                        |  2 +-
 107 files changed, 513 insertions(+), 183 deletions(-)
 create mode 100755 scripts/gen_ll_addressable_symbols.sh
Signature · 1 line
2.26.3
#1 lore raw

PATCH v4 1/36 regmap: fix a serious pointer casting bug

There is a serious bug in regmap_read() and regmap_write() functions where an uint pointer is cast to (void *) which is then cast to (u8 *), (u16 *), (u32 *) or (u64 *), depending on register width of the map.

For example given a regmap with 16-bit register width the code

	int val = 0x12340000;
	regmap_read(map, 0, &val);

only changes the lower 16 bits of val on little-endian machines. The upper 16 bits will remain 0x1234.

Nobody noticed this probably because this bug can be triggered with regmap_write() only on big-endian architectures (which are not used by many people anymore), and on little endian this bug has consequences only if register width is 8 or 16 bits and also the memory place to which regmap_read() should store it's result has non-zero upper bits, which it seems doesn't happen anywhere in U-Boot normally. CI managed to trigger this bug in unit test of dm_test_devm_regmap_field when compiled for sandbox_defconfig using LTO.

Fix this by utilizing an union { u8; u16; u32; u64; } and reading data into this union / writing data from this union.

Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Bin Meng <[email protected]>
Cc Pratyush Yadav <[email protected]>
---
 drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)
drivers/core/regmap.c +57 -2
index b51ce108c1..3206f3d112 100644
@@ -435,7 +435,36 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
 
 int regmap_read(struct regmap *map, uint offset, uint *valp)
 {
-	return regmap_raw_read(map, offset, valp, map->width);
+	union {
+		u8 v8;
+		u16 v16;
+		u32 v32;
+		u64 v64;
+	} u;
+	int res;
+
+	res = regmap_raw_read(map, offset, &u, map->width);
+	if (res)
+		return res;
+
+	switch (map->width) {
+	case REGMAP_SIZE_8:
+		*valp = u.v8;
+		break;
+	case REGMAP_SIZE_16:
+		*valp = u.v16;
+		break;
+	case REGMAP_SIZE_32:
+		*valp = u.v32;
+		break;
+	case REGMAP_SIZE_64:
+		*valp = u.v64;
+		break;
+	default:
+		unreachable();
+	}
+
+	return 0;
 }
 
 static inline void __write_8(u8 *addr, const u8 *val,
@@ -546,7 +575,33 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,
 
 int regmap_write(struct regmap *map, uint offset, uint val)
 {
-	return regmap_raw_write(map, offset, &val, map->width);
+	union {
+		u8 v8;
+		u16 v16;
+		u32 v32;
+		u64 v64;
+	} u;
+
+	switch (map->width) {
+	case REGMAP_SIZE_8:
+		u.v8 = val;
+		break;
+	case REGMAP_SIZE_16:
+		u.v16 = val;
+		break;
+	case REGMAP_SIZE_32:
+		u.v32 = val;
+		break;
+	case REGMAP_SIZE_64:
+		u.v64 = val;
+		break;
+	default:
+		debug("%s: regmap size %zu unknown\n", __func__,
+		      (size_t)map->width);
+		return -EINVAL;
+	}
+
+	return regmap_raw_write(map, offset, &u, map->width);
 }
 
 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
Signature · 1 line
2.26.3
#2 lore raw

PATCH v4 1/36 regmap: fix a serious pointer casting bug

Hi Marek,

Quoted 23 lines · Marek Beh?n

There is a serious bug in regmap_read() and regmap_write() functions where an uint pointer is cast to (void *) which is then cast to (u8 *), (u16 *), (u32 *) or (u64 *), depending on register width of the map.

For example given a regmap with 16-bit register width the code

        int val = 0x12340000;
        regmap_read(map, 0, &val);

only changes the lower 16 bits of val on little-endian machines. The upper 16 bits will remain 0x1234.

Nobody noticed this probably because this bug can be triggered with regmap_write() only on big-endian architectures (which are not used by many people anymore), and on little endian this bug has consequences only if register width is 8 or 16 bits and also the memory place to which regmap_read() should store it's result has non-zero upper bits, which it seems doesn't happen anywhere in U-Boot normally. CI managed to trigger this bug in unit test of dm_test_devm_regmap_field when compiled for sandbox_defconfig using LTO.

Fix this by utilizing an union { u8; u16; u32; u64; } and reading data into this union / writing data from this union.

Quoted 8 lines
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Bin Meng <[email protected]>
Cc Pratyush Yadav <[email protected]>
---
 drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

I don't see a changelog here but this is v4. Are you using patman?

Regards,
Simon

#3 lore raw

PATCH v4 1/36 regmap: fix a serious pointer casting bug

Quoted 1 line

I don't see a changelog here but this is v4. Are you using patman?

Changelog is in cover letter. Unfortunately I am not using patman yet.

Marek

#4 lore raw

Re: [PATCH u-boot v4 01/36] regmap: fix a serious pointer casting bug

In reply to Marek Behún
Quoted 19 lines · Marek Behún

There is a serious bug in regmap_read() and regmap_write() functions where an uint pointer is cast to (void *) which is then cast to (u8 *), (u16 *), (u32 *) or (u64 *), depending on register width of the map.

For example given a regmap with 16-bit register width the code

	int val = 0x12340000;
	regmap_read(map, 0, &val);

only changes the lower 16 bits of val on little-endian machines. The upper 16 bits will remain 0x1234.

Nobody noticed this probably because this bug can be triggered with regmap_write() only on big-endian architectures (which are not used by many people anymore), and on little endian this bug has consequences only if register width is 8 or 16 bits and also the memory place to which regmap_read() should store it's result has non-zero upper bits, which it seems doesn't happen anywhere in U-Boot normally. CI managed to trigger this bug in unit test of dm_test_devm_regmap_field when compiled for sandbox_defconfig using LTO.

Quoted 8 lines

Fix this by utilizing an union { u8; u16; u32; u64; } and reading data into this union / writing data from this union.

Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Bin Meng <[email protected]>
Cc Pratyush Yadav <[email protected]>

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#5 lore raw

PATCH v4 2/36 checkpatch: require quotes around section name in the __section() macro

In reply to Marek Behún

This is how Linux does this now, see Linux commit 339f29d91acf.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 59a714a95f..08a827535a 100755
@@ -6073,7 +6073,7 @@ sub process {
 			my $old = substr($rawline, $-[1], $+[1] - $-[1]);
 			my $new = substr($old, 1, -1);
 			if (WARN("PREFER_SECTION",
-				 "__section($new) is preferred over __attribute__((section($old)))\n" . $herecurr) &&
+				 "__section(\"$new\") is preferred over __attribute__((section($old)))\n" . $herecurr) &&
 			    $fix) {
 				$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/;
 			}
Signature · 1 line
2.26.3
#8 lore raw

PATCH v4 3/36 treewide: Convert macro and uses of __section(foo) to __section("foo")

In reply to Marek Behún

This commit does the same thing as Linux commit 33def8498fdd.

Use a more generic form for __section that requires quotes to avoid complications with clang and gcc differences.

Remove the quote operator # from compiler_attributes.h __section macro.

Convert all unquoted __section(foo) uses to quoted __section("foo"). Also convert __attribute__((section("foo"))) uses to __section("foo") even if the __attribute__ has multiple list entry forms.

---
 arch/arm/cpu/arm926ejs/spear/spl.c        |  2 +-
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c |  2 +-
 arch/arm/cpu/armv8/spl_data.c             |  4 +--
 arch/arm/include/asm/secure.h             |  6 ++---
 arch/arm/include/asm/setup.h              |  2 +-
 arch/arm/lib/sections.c                   | 31 ++++++++++++-----------
 arch/arm/lib/spl.c                        |  2 +-
 arch/arm/mach-at91/spl.c                  |  2 +-
 arch/arm/mach-k3/am642_init.c             |  2 +-
 arch/arm/mach-k3/am6_init.c               |  2 +-
 arch/arm/mach-k3/j721e_init.c             |  4 +--
 arch/arm/mach-mvebu/mbus.c                |  4 +--
 arch/arm/mach-mvebu/timer.c               |  2 +-
 arch/arm/mach-nexell/clock.c              |  6 ++---
 arch/arm/mach-nexell/timer.c              |  6 ++---
 arch/arm/mach-socfpga/spl_a10.c           |  2 +-
 arch/arm/mach-sunxi/board.c               |  2 +-
 arch/arm/mach-tegra/board.c               |  2 +-
 arch/arm/mach-tegra/cboot.c               |  8 +++---
 arch/mips/mach-jz47xx/jz4780/jz4780.c     |  2 +-
 arch/nds32/include/asm/setup.h            |  6 ++---
 arch/powerpc/include/asm/cache.h          |  4 +--
 arch/riscv/cpu/cpu.c                      |  4 +--
 arch/sandbox/include/asm/getopt.h         |  2 +-
 arch/sandbox/lib/sections.c               |  9 ++++---
 arch/x86/cpu/coreboot/timestamp.c         |  2 +-
 arch/x86/lib/coreboot/cb_sysinfo.c        |  2 +-
 arch/x86/lib/sections.c                   |  9 ++++---
 arch/xtensa/cpu/cpu.c                     |  2 +-
 board/bosch/shc/board.c                   |  2 +-
 board/broadcom/bcmstb/bcmstb.c            |  2 +-
 board/samsung/arndale/arndale_spl.c       |  2 +-
 board/samsung/smdk5250/smdk5250_spl.c     |  2 +-
 board/samsung/smdk5420/smdk5420_spl.c     |  2 +-
 board/siemens/draco/board.c               |  2 +-
 board/xilinx/common/fru_ops.c             |  2 +-
 drivers/bios_emulator/biosemu.c           |  4 +--
 drivers/clk/kendryte/clk.c                |  4 +--
 drivers/firmware/psci.c                   |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx5.c        |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx7.c        |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx8m.c       |  2 +-
 drivers/power/pmic/pmic_tps62362.c        |  2 +-
 drivers/power/pmic/pmic_tps65217.c        |  2 +-
 drivers/power/pmic/pmic_tps65218.c        |  2 +-
 drivers/power/pmic/pmic_tps65910.c        |  2 +-
 drivers/serial/serial_pl01x.c             |  4 +--
 include/efi_loader.h                      |  4 +--
 include/linker_lists.h                    | 24 +++++++++---------
 include/linux/compiler.h                  |  8 +++---
 include/linux/compiler_attributes.h       |  2 +-
 lib/trace.c                               |  4 +--
 52 files changed, 110 insertions(+), 107 deletions(-)
arch/arm/cpu/arm926ejs/spear/spl.c +1 -1
index 08b98a2d06..b5b9945a87 100644
@@ -22,7 +22,7 @@
  * The BSS cannot be used for this purpose because it will be zeroed after
  * having stored the pointer, so force the location to the data section.
  */
-u32 bootrom_stash_sp __attribute__((section(".data")));
+u32 bootrom_stash_sp __section(".data");
 
 static void ddr_clock_init(void)
 {
arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c +1 -1
index 4a4b3c6f23..28a7945207 100644
@@ -13,7 +13,7 @@
 #include <fsl_immap.h>
 #include "fsl_epu.h"
 
-#define __secure __attribute__((section("._secure.text")))
+#define __secure __section("._secure.text")
 
 #define CCSR_GICD_CTLR			0x1000
 #define CCSR_GICC_CTLR			0x2000
arch/arm/cpu/armv8/spl_data.c +2 -2
index 8fd986a67a..8f1231c86e 100644
@@ -6,8 +6,8 @@
 #include <common.h>
 #include <spl.h>
 
-char __data_save_start[0] __section(.__data_save_start);
-char __data_save_end[0] __section(.__data_save_end);
+char __data_save_start[0] __section(".__data_save_start");
+char __data_save_end[0] __section(".__data_save_end");
 
 u32 cold_reboot_flag = 1;
 
arch/arm/include/asm/secure.h +3 -3
index 64e5582c1f..c7b00be8e0 100644
@@ -4,8 +4,8 @@
 #include <config.h>
 #include <asm/global_data.h>
 
-#define __secure __attribute__ ((section ("._secure.text")))
-#define __secure_data __attribute__ ((section ("._secure.data")))
+#define __secure __section("._secure.text")
+#define __secure_data __section("._secure.data")
 
 #ifndef __ASSEMBLY__
 
@@ -22,7 +22,7 @@ typedef struct secure_svc_tbl {
  */
 #define DECLARE_SECURE_SVC(_name, _id, _fn) \
 	static const secure_svc_tbl_t __secure_svc_ ## _name \
-		__attribute__((used, section("._secure_svc_tbl_entries"))) \
+		__used __section("._secure_svc_tbl_entries") \
 			 = { \
 				.id = _id, \
 				.func = _fn }
arch/arm/include/asm/setup.h +1 -1
index 3a4e902af1..e0e2d7e360 100644
@@ -235,7 +235,7 @@ struct tagtable {
 	int (*parse)(const struct tag *);
 };
 
-#define __tag __attribute__((unused, __section__(".taglist")))
+#define __tag __attribute__((unused)) __section(".taglist")
 #define __tagtable(tag, fn) \
 static struct tagtable __tagtable_##fn __tag = { tag, fn }
 
arch/arm/lib/sections.c +16 -15
index 3bb2d8468c..857879711c 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright 2013 Albert ARIBAUD <[email protected]>
  */
+#include <linux/compiler.h>
 
 /**
  * These two symbols are declared in a C file so that the linker
@@ -18,18 +19,18 @@
  * aliasing warnings.
  */
 
-char __bss_start[0] __attribute__((section(".__bss_start")));
-char __bss_end[0] __attribute__((section(".__bss_end")));
-char __image_copy_start[0] __attribute__((section(".__image_copy_start")));
-char __image_copy_end[0] __attribute__((section(".__image_copy_end")));
-char __rel_dyn_start[0] __attribute__((section(".__rel_dyn_start")));
-char __rel_dyn_end[0] __attribute__((section(".__rel_dyn_end")));
-char __secure_start[0] __attribute__((section(".__secure_start")));
-char __secure_end[0] __attribute__((section(".__secure_end")));
-char __secure_stack_start[0] __attribute__((section(".__secure_stack_start")));
-char __secure_stack_end[0] __attribute__((section(".__secure_stack_end")));
-char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start")));
-char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop")));
-char __efi_runtime_rel_start[0] __attribute__((section(".__efi_runtime_rel_start")));
-char __efi_runtime_rel_stop[0] __attribute__((section(".__efi_runtime_rel_stop")));
-char _end[0] __attribute__((section(".__end")));
+char __bss_start[0] __section(".__bss_start");
+char __bss_end[0] __section(".__bss_end");
+char __image_copy_start[0] __section(".__image_copy_start");
+char __image_copy_end[0] __section(".__image_copy_end");
+char __rel_dyn_start[0] __section(".__rel_dyn_start");
+char __rel_dyn_end[0] __section(".__rel_dyn_end");
+char __secure_start[0] __section(".__secure_start");
+char __secure_end[0] __section(".__secure_end");
+char __secure_stack_start[0] __section(".__secure_stack_start");
+char __secure_stack_end[0] __section(".__secure_stack_end");
+char __efi_runtime_start[0] __section(".__efi_runtime_start");
+char __efi_runtime_stop[0] __section(".__efi_runtime_stop");
+char __efi_runtime_rel_start[0] __section(".__efi_runtime_rel_start");
+char __efi_runtime_rel_stop[0] __section(".__efi_runtime_rel_stop");
+char _end[0] __section(".__end");
arch/arm/lib/spl.c +1 -1
index b2b54f28fc..8e2bdf3536 100644
@@ -26,7 +26,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * WARNING: This is going away very soon. Don't use it and don't submit
  * pafches that rely on it. The global_data area is set up in crt0.S.
  */
-gd_t gdata __attribute__ ((section(".data")));
+gd_t gdata __section(".data");
 #endif
 
 /*
arch/arm/mach-at91/spl.c +1 -1
index 156150c89c..8d537998c9 100644
@@ -26,7 +26,7 @@ void at91_disable_wdt(void)
 #include <asm/arch/sama5_boot.h>
 struct {
 	u32	r4;
-} bootrom_stash __attribute__((section(".data")));
+} bootrom_stash __section(".data");
 
 u32 spl_boot_device(void)
 {
arch/arm/mach-k3/am642_init.c +1 -1
index 885f181d58..a433702b4e 100644
@@ -44,7 +44,7 @@ static void ctrl_mmr_unlock(void)
  * it to the .data section.
  */
 u32 bootindex __section(".data");
-static struct rom_extended_boot_data bootdata __section(.data);
+static struct rom_extended_boot_data bootdata __section(".data");
 
 static void store_boot_info_from_rom(void)
 {
arch/arm/mach-k3/am6_init.c +1 -1
index d78d2b8751..425b3f93c8 100644
@@ -77,7 +77,7 @@ static void ctrl_mmr_unlock(void)
  * but the .bss is cleared between writing and reading this variable, so move
  * it to the .data section.
  */
-u32 bootindex __attribute__((section(".data")));
+u32 bootindex __section(".data");
 
 static void store_boot_index_from_rom(void)
 {
arch/arm/mach-k3/j721e_init.c +2 -2
index 1a4f796e5e..76a04a9035 100644
@@ -125,8 +125,8 @@ void k3_mmc_restart_clock(void)
  * but the .bss is cleared between writing and reading this variable, so move
  * it to the .data section.
  */
-u32 bootindex __attribute__((section(".data")));
-static struct rom_extended_boot_data bootdata __section(.data);
+u32 bootindex __section(".data");
+static struct rom_extended_boot_data bootdata __section(".data");
 
 static void store_boot_info_from_rom(void)
 {
arch/arm/mach-mvebu/mbus.c +2 -2
index f29abe5911..3b1b9f73eb 100644
@@ -98,9 +98,9 @@ struct mvebu_mbus_soc_data {
 };
 
 struct mvebu_mbus_state mbus_state
-	__attribute__ ((section(".data")));
+	__section(".data");
 static struct mbus_dram_target_info mbus_dram_info
-	__attribute__ ((section(".data")));
+	__section(".data");
 
 /*
  * Functions to manipulate the address decoding windows
arch/arm/mach-mvebu/timer.c +1 -1
index 43b3ed15d0..557a378776 100644
@@ -14,7 +14,7 @@
 
 #define TIMER_LOAD_VAL			0xffffffff
 
-static int init_done __attribute__((section(".data"))) = 0;
+static int init_done __section(".data") = 0;
 
 /*
  * Timer initialization
arch/arm/mach-nexell/clock.c +3 -3
index a0ba2d8e0c..d5b46a87a1 100644
@@ -99,7 +99,7 @@ static const char * const clk_core[] = {
  * in board_init_f(), respectively! I.e. global variables can not be used!
  */
 static struct clk_dev_peri clk_periphs[]
-	__attribute__((section(".data"))) = {
+	__section(".data") = {
 	CLK_PERI_1S(DEV_NAME_TIMER,	0,	CLK_ID_TIMER_0,
 		    PHY_BASEADDR_CLKGEN14, (I_PLL_0_2)),
 	CLK_PERI_1S(DEV_NAME_TIMER,	1,	CLK_ID_TIMER_1,
@@ -167,7 +167,7 @@ static struct clk_dev_peri clk_periphs[]
 #define	MAX_DIVIDER		((1 << 8) - 1)	/* 256, align 2 */
 
 static struct clk_dev		st_clk_devs[CLK_DEVS_NUM]
-				__attribute__((section(".data")));
+				__section(".data");
 #define	clk_dev_get(n)		((struct clk_dev *)&st_clk_devs[n])
 #define	clk_container(p)	(container_of(p, struct clk_dev, clk))
 
@@ -196,7 +196,7 @@ struct _core_hz_ {
  * in board_init_f(), respectively! I.e. global variables can not be used!
  */
 /* core clock */
-static struct _core_hz_ core_hz __attribute__((section(".data")));
+static struct _core_hz_ core_hz __section(".data");
 
 #define	CORE_HZ_SIZE	(sizeof(core_hz) / 4)
 
arch/arm/mach-nexell/timer.c +3 -3
index fecee67265..3b311fd22a 100644
@@ -23,9 +23,9 @@
  * Section ".data" must be used because BSS is not available before relocation,
  * in board_init_f(), respectively! I.e. global variables can not be used!
  */
-static unsigned long timestamp __attribute__ ((section(".data")));
-static unsigned long lastdec __attribute__ ((section(".data")));
-static int	timerinit __attribute__ ((section(".data")));
+static unsigned long timestamp __section(".data");
+static unsigned long lastdec __section(".data");
+static int	timerinit __section(".data");
 
 /* macro to hw timer tick config */
 static long	TIMER_FREQ  = 1000000;
arch/arm/mach-socfpga/spl_a10.c +1 -1
index 92231b5ba3..b5f43f09d1 100644
@@ -40,7 +40,7 @@ DECLARE_GLOBAL_DATA_PTR;
 					 SOCFPGA_PHYS_OCRAM_SIZE - \
 					 BOOTROM_SHARED_MEM_SIZE)
 #define RST_STATUS_SHARED_ADDR		(BOOTROM_SHARED_MEM_ADDR + 0x438)
-static u32 rst_mgr_status __section(.data);
+static u32 rst_mgr_status __section(".data");
 
 /*
  * Bootrom will clear the status register in reset manager and stores the
arch/arm/mach-sunxi/board.c +1 -1
index 503538e26d..9b84132eda 100644
@@ -39,7 +39,7 @@ struct fel_stash {
 	uint32_t cr;
 };
 
-struct fel_stash fel_stash __attribute__((section(".data")));
+struct fel_stash fel_stash __section(".data");
 
 #ifdef CONFIG_ARM64
 #include <asm/armv8/mmu.h>
arch/arm/mach-tegra/board.c +1 -1
index 21852e2388..95d6555a0d 100644
@@ -45,7 +45,7 @@ enum {
 	UART_COUNT = 5,
 };
 
-static bool from_spl __attribute__ ((section(".data")));
+static bool from_spl __section(".data");
 
 #ifndef CONFIG_SPL_BUILD
 void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
arch/arm/mach-tegra/cboot.c +4 -4
index bb46fb23ff..55eb819860 100644
@@ -49,7 +49,7 @@ extern struct mm_region tegra_mem_map[];
  */
 
 /* The number of valid entries in ram_banks[] */
-static int ram_bank_count __attribute__((section(".data")));
+static int ram_bank_count __section(".data");
 
 /*
  * The usable top-of-RAM for U-Boot. This is both:
@@ -57,15 +57,15 @@ static int ram_bank_count __attribute__((section(".data")));
  * b) At the end of a region that has enough space to hold the relocated U-Boot
  *    and all other allocations made around it (stack, heap, page tables, etc.)
  */
-static u64 ram_top __attribute__((section(".data")));
+static u64 ram_top __section(".data");
 /* The base address of the region of RAM that ends at ram_top */
-static u64 region_base __attribute__((section(".data")));
+static u64 region_base __section(".data");
 
 /*
  * Explicitly put this in the .data section because it is written before the
  * .bss section is zeroed out but it needs to persist.
  */
-unsigned long cboot_boot_x0 __attribute__((section(".data")));
+unsigned long cboot_boot_x0 __section(".data");
 
 void cboot_save_boot_params(unsigned long x0, unsigned long x1,
 			    unsigned long x2, unsigned long x3)
arch/mips/mach-jz47xx/jz4780/jz4780.c +1 -1
index 43f5651f83..fefba12873 100644
@@ -23,7 +23,7 @@
 #ifdef CONFIG_SPL_BUILD
 /* Pointer to the global data structure for SPL */
 DECLARE_GLOBAL_DATA_PTR;
-gd_t gdata __attribute__ ((section(".bss")));
+gd_t gdata __section(".bss");
 
 void board_init_f(ulong dummy)
 {
arch/nds32/include/asm/setup.h +3 -3
index 8217bbf6fe..a7d52373c6 100644
@@ -155,7 +155,7 @@ struct tagtable {
 
 #ifdef __KERNEL__
 
-#define __tag __used __attribute__((__section__(".taglist")))
+#define __tag __used __section(".taglist")
 #define __tagtable(tag, fn) \
 static struct tagtable __tagtable_##fn __tag = { tag, fn }
 
@@ -182,8 +182,8 @@ struct early_params {
 };
 
 #define __early_param(name, fn)					\
-static struct early_params __early_##fn __used	\
-__attribute__((__section__("__early_param"))) = { name, fn }
+static struct early_params __early_##fn __used			\
+__section("__early_param") = { name, fn }
 
 #endif
 #endif
arch/powerpc/include/asm/cache.h +2 -2
index 445a366807..ac8eeb4caa 100644
@@ -41,8 +41,8 @@
 #define __cacheline_aligned __attribute__((__aligned__(L1_CACHE_BYTES)))
 #else
 #define __cacheline_aligned					\
-  __attribute__((__aligned__(L1_CACHE_BYTES),			\
-		 __section__(".data.cacheline_aligned")))
+  __attribute__((__aligned__(L1_CACHE_BYTES)))			\
+  __section(".data.cacheline_aligned")
 #endif
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
arch/riscv/cpu/cpu.c +2 -2
index 296e458db4..c894ac10b5 100644
@@ -17,10 +17,10 @@
  * before the bss section is available.
  */
 #ifdef CONFIG_OF_PRIOR_STAGE
-phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
+phys_addr_t prior_stage_fdt_address __section(".data");
 #endif
 #ifndef CONFIG_XIP
-u32 hart_lottery __attribute__((section(".data"))) = 0;
+u32 hart_lottery __section(".data") = 0;
 
 /*
  * The main hart running U-Boot has acquired available_harts_lock until it has
arch/sandbox/include/asm/getopt.h +1 -1
index 3048c2cc30..d2145ad6e2 100644
@@ -44,7 +44,7 @@ struct sandbox_cmdline_option {
 		.callback = sandbox_cmdline_cb_##f, \
 	}; \
 	/* Ppointer to the struct in a special section for the linker script */ \
-	static __attribute__((section(".u_boot_sandbox_getopt"), used)) \
+	static __used __section(".u_boot_sandbox_getopt") \
 		struct sandbox_cmdline_option \
 			*sandbox_cmdline_option_##f##_ptr = \
 			&sandbox_cmdline_option_##f
arch/sandbox/lib/sections.c +5 -4
index 697a8167dd..2559eeea38 100644
@@ -3,10 +3,11 @@
  * Copyright 2013 Albert ARIBAUD <[email protected]>
  *
  */
+#include <linux/compiler.h>
 
-char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start")));
-char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop")));
+char __efi_runtime_start[0] __section(".__efi_runtime_start");
+char __efi_runtime_stop[0] __section(".__efi_runtime_stop");
 char __efi_runtime_rel_start[0]
-		__attribute__((section(".__efi_runtime_rel_start")));
+		__section(".__efi_runtime_rel_start");
 char __efi_runtime_rel_stop[0]
-		__attribute__((section(".__efi_runtime_rel_stop")));
+		__section(".__efi_runtime_rel_stop");
arch/x86/cpu/coreboot/timestamp.c +1 -1
index 7f133cefae..3ad611a530 100644
@@ -11,7 +11,7 @@
 #include <asm/cb_sysinfo.h>
 #include <linux/compiler.h>
 
-static struct timestamp_table *ts_table  __attribute__((section(".data")));
+static struct timestamp_table *ts_table  __section(".data");
 
 void timestamp_init(void)
 {
arch/x86/lib/coreboot/cb_sysinfo.c +1 -1
index e2c65bfb1e..748fa4ee53 100644
@@ -21,7 +21,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * with zeroes when transitioning from "ROM", which is really RAM, to other
  * RAM.
  */
-struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
+struct sysinfo_t lib_sysinfo __section(".data");
 
 /*
  * Some of this is x86 specific, and the rest of it is generic. Right now,
arch/x86/lib/sections.c +5 -4
index 8d1700776d..375029ead0 100644
@@ -2,10 +2,11 @@
 /*
  * Copyright 2013 Albert ARIBAUD <[email protected]>
  */
+#include <linux/compiler.h>
 
-char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start")));
-char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop")));
+char __efi_runtime_start[0] __section(".__efi_runtime_start");
+char __efi_runtime_stop[0] __section(".__efi_runtime_stop");
 char __efi_runtime_rel_start[0]
-		__attribute__((section(".__efi_runtime_rel_start")));
+		__section(".__efi_runtime_rel_start");
 char __efi_runtime_rel_stop[0]
-		__attribute__((section(".__efi_runtime_rel_stop")));
+		__section(".__efi_runtime_rel_stop");
arch/xtensa/cpu/cpu.c +1 -1
index 85d3464607..a09e103fc1 100644
@@ -20,7 +20,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-gd_t *gd __attribute__((section(".data")));
+gd_t *gd __section(".data");
 
 #if defined(CONFIG_DISPLAY_CPUINFO)
 /*
board/bosch/shc/board.c +1 -1
index e893781887..86356e3875 100644
@@ -45,7 +45,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct shc_eeprom __attribute__((section(".data"))) header;
+static struct shc_eeprom __section(".data") header;
 static int shc_eeprom_valid;
 
 /*
board/broadcom/bcmstb/bcmstb.c +1 -1
index ee0a341077..076ac94144 100644
@@ -22,7 +22,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define BCMSTB_DATA_SECTION __attribute__((section(".data")))
+#define BCMSTB_DATA_SECTION __section(".data")
 
 struct bcmstb_boot_parameters bcmstb_boot_parameters BCMSTB_DATA_SECTION;
 
board/samsung/arndale/arndale_spl.c +1 -1
index baa5048335..6ad0273e04 100644
@@ -10,7 +10,7 @@
 
 /* Parameters of early board initialization in SPL */
 static struct spl_machine_param machine_param
-		__attribute__((section(".machine_param"))) = {
+		__section(".machine_param") = {
 	.signature	= SIGNATURE,
 	.version	= 1,
 	.params		= "vmubfasirM",
board/samsung/smdk5250/smdk5250_spl.c +1 -1
index eb25dfc0a0..b0ef34dd6a 100644
@@ -12,7 +12,7 @@
 
 /* Parameters of early board initialization in SPL */
 static struct spl_machine_param machine_param
-		__attribute__((section(".machine_param"))) = {
+		__section(".machine_param") = {
 	.signature	= SIGNATURE,
 	.version	= 1,
 	.params		= "vmubfasirM",
board/samsung/smdk5420/smdk5420_spl.c +1 -1
index 72748ec089..84126f5608 100644
@@ -12,7 +12,7 @@
 
 /* Parameters of early board initialization in SPL */
 static struct spl_machine_param machine_param
-		__attribute__((section(".machine_param"))) = {
+		__section(".machine_param") = {
 	.signature	= SIGNATURE,
 	.version	= 1,
 	.params		= "vmubfasirM",
board/siemens/draco/board.c +1 -1
index b512bdbfab..01fdfb5cb4 100644
@@ -41,7 +41,7 @@
 #include <nand.h>
 
 #ifdef CONFIG_SPL_BUILD
-static struct draco_baseboard_id __attribute__((section(".data"))) settings;
+static struct draco_baseboard_id __section(".data") settings;
 
 #if DDR_PLL_FREQ == 303
 #if !defined(CONFIG_TARGET_ETAMIN)
board/xilinx/common/fru_ops.c +1 -1
index 44f0913f2e..6ed63bb7ee 100644
@@ -14,7 +14,7 @@
 
 #include "fru.h"
 
-struct fru_table fru_data __section(.data);
+struct fru_table fru_data __section(".data");
 
 static u16 fru_cal_area_len(u8 len)
 {
drivers/bios_emulator/biosemu.c +2 -2
index 9d4f07c074..82befbae66 100644
@@ -50,7 +50,7 @@
 #include "biosemui.h"
 
 BE_sysEnv _BE_env = {{0}};
-static X86EMU_memFuncs _BE_mem __attribute__((section(GOT2_TYPE))) = {
+static X86EMU_memFuncs _BE_mem __section(GOT2_TYPE) = {
 	BE_rdb,
 	BE_rdw,
 	BE_rdl,
@@ -59,7 +59,7 @@ static X86EMU_memFuncs _BE_mem __attribute__((section(GOT2_TYPE))) = {
 	BE_wrl,
 	};
 
-static X86EMU_pioFuncs _BE_pio __attribute__((section(GOT2_TYPE))) = {
+static X86EMU_pioFuncs _BE_pio __section(GOT2_TYPE) = {
 	BE_inb,
 	BE_inw,
 	BE_inl,
drivers/clk/kendryte/clk.c +2 -2
index 2d6ac03693..41c712e03f 100644
@@ -347,7 +347,7 @@ static const struct k210_comp_params k210_comps[] = {
 #undef COMP_NOMUX_ID
 #undef COMP_LIST
 
-static struct clk *k210_bypass_children __section(.data);
+static struct clk *k210_bypass_children __section(".data");
 
 /* Helper functions to create sub-clocks */
 static struct clk_mux *k210_create_mux(const struct k210_mux_params *params,
@@ -473,7 +473,7 @@ cleanup_mux:
 	return comp;
 }
 
-static bool __section(.data) probed;
+static bool __section(".data") probed;
 
 /* reset probed so we will probe again post-relocation */
 static int k210_clk_bind(struct udevice *dev)
drivers/firmware/psci.c +1 -1
index 6755e74e3f..89cb7d88e5 100644
@@ -42,7 +42,7 @@
 #if CONFIG_IS_ENABLED(EFI_LOADER)
 int __efi_runtime_data psci_method;
 #else
-int psci_method __attribute__ ((section(".data")));
+int psci_method __section(".data");
 #endif
 
 unsigned long __efi_runtime invoke_psci_fn
drivers/pinctrl/nxp/pinctrl-imx5.c +1 -1
index 71e0c94c96..b32b748cfc 100644
@@ -10,7 +10,7 @@
 
 #include "pinctrl-imx.h"
 
-static struct imx_pinctrl_soc_info imx5_pinctrl_soc_info __attribute__((section(".data")));
+static struct imx_pinctrl_soc_info imx5_pinctrl_soc_info __section(".data");
 
 static int imx5_pinctrl_probe(struct udevice *dev)
 {
drivers/pinctrl/nxp/pinctrl-imx7.c +1 -1
index 8301413ac7..77ddb8e0b9 100644
@@ -9,7 +9,7 @@
 
 #include "pinctrl-imx.h"
 
-static struct imx_pinctrl_soc_info imx7_pinctrl_soc_info __attribute__((section(".data")));
+static struct imx_pinctrl_soc_info imx7_pinctrl_soc_info __section(".data");
 
 static struct imx_pinctrl_soc_info imx7_lpsr_pinctrl_soc_info = {
 	.flags = ZERO_OFFSET_VALID,
drivers/pinctrl/nxp/pinctrl-imx8m.c +1 -1
index 99c6d014d6..6ea66a080b 100644
@@ -8,7 +8,7 @@
 
 #include "pinctrl-imx.h"
 
-static struct imx_pinctrl_soc_info imx8mq_pinctrl_soc_info __attribute__((section(".data")));
+static struct imx_pinctrl_soc_info imx8mq_pinctrl_soc_info __section(".data");
 
 static int imx8mq_pinctrl_probe(struct udevice *dev)
 {
drivers/power/pmic/pmic_tps62362.c +1 -1
index 76fd14db59..59190d6f67 100644
@@ -11,7 +11,7 @@
 #include <power/tps62362.h>
 
 #if CONFIG_IS_ENABLED(DM_I2C)
-struct udevice *tps62362_dev __attribute__((section(".data"))) = NULL;
+struct udevice *tps62362_dev __section(".data") = NULL;
 #endif
 
 /**
drivers/power/pmic/pmic_tps65217.c +1 -1
index 54b5bed99a..c7f532df4d 100644
@@ -8,7 +8,7 @@
 #include <i2c.h>
 #include <power/tps65217.h>
 
-struct udevice *tps65217_dev __attribute__((section(".data"))) = NULL;
+struct udevice *tps65217_dev __section(".data") = NULL;
 
 /**
  * tps65217_reg_read() - Generic function that can read a TPS65217 register
drivers/power/pmic/pmic_tps65218.c +1 -1
index f8bae4545c..6717490180 100644
@@ -86,7 +86,7 @@ int tps65218_reg_write(uchar prot_level, uchar dest_reg, uchar dest_val,
 	return 0;
 }
 #else
-struct udevice *tps65218_dev __attribute__((section(".data"))) = NULL;
+struct udevice *tps65218_dev __section(".data") = NULL;
 
 int tps65218_reg_read(uchar dest_reg, uchar *dest_val)
 {
drivers/power/pmic/pmic_tps65910.c +1 -1
index 84a58c28d8..fcd0a654a8 100644
@@ -8,7 +8,7 @@
 #include <i2c.h>
 #include <power/tps65910.h>
 
-struct udevice *tps65910_dev __attribute__((section(".data"))) = NULL;
+struct udevice *tps65910_dev __section(".data") = NULL;
 
 static inline int tps65910_read_reg(int addr, uchar *buf)
 {
drivers/serial/serial_pl01x.c +2 -2
index 4f9de0da76..5283d5ed11 100644
@@ -30,8 +30,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #ifndef CONFIG_DM_SERIAL
 
 static volatile unsigned char *const port[] = CONFIG_PL01x_PORTS;
-static enum pl01x_type pl01x_type __attribute__ ((section(".data")));
-static struct pl01x_regs *base_regs __attribute__ ((section(".data")));
+static enum pl01x_type pl01x_type __section(".data");
+static struct pl01x_regs *base_regs __section(".data");
 #define NUM_PORTS (sizeof(port)/sizeof(port[0]))
 
 #endif
include/efi_loader.h +2 -2
index de1a496a97..ce9b2388c5 100644
@@ -682,8 +682,8 @@ ssize_t efi_dp_check_length(const struct efi_device_path *dp,
  * Use these to indicate that your code / data should go into the EFI runtime
  * section and thus still be available when the OS is running
  */
-#define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
-#define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
+#define __efi_runtime_data __section(".data.efi_runtime")
+#define __efi_runtime __section(".text.efi_runtime")
 
 /* Indicate supported runtime services */
 efi_status_t efi_init_runtime_supported(void);
include/linker_lists.h +12 -12
index 2fea54c834..0575164ce4 100644
@@ -69,8 +69,8 @@
  */
 #define ll_entry_declare(_type, _name, _list)				\
 	_type _u_boot_list_2_##_list##_2_##_name __aligned(4)		\
-			__attribute__((unused,				\
-			section(".u_boot_list_2_"#_list"_2_"#_name)))
+			__attribute__((unused))				\
+			__section(".u_boot_list_2_"#_list"_2_"#_name)
 
 /**
  * ll_entry_declare_list() - Declare a list of link-generated array entries
@@ -92,8 +92,8 @@
  */
 #define ll_entry_declare_list(_type, _name, _list)			\
 	_type _u_boot_list_2_##_list##_2_##_name[] __aligned(4)		\
-			__attribute__((unused,				\
-			section(".u_boot_list_2_"#_list"_2_"#_name)))
+			__attribute__((unused))				\
+			__section(".u_boot_list_2_"#_list"_2_"#_name)
 
 /*
  * We need a 0-byte-size type for iterator symbols, and the compiler
@@ -125,8 +125,8 @@
 #define ll_entry_start(_type, _list)					\
 ({									\
 	static char start[0] __aligned(CONFIG_LINKER_LIST_ALIGN)	\
-		__attribute__((unused,					\
-		section(".u_boot_list_2_"#_list"_1")));			\
+		__attribute__((unused))					\
+		__section(".u_boot_list_2_"#_list"_1");			\
 	(_type *)&start;						\
 })
 
@@ -151,8 +151,8 @@
  */
 #define ll_entry_end(_type, _list)					\
 ({									\
-	static char end[0] __aligned(4) __attribute__((unused,		\
-		section(".u_boot_list_2_"#_list"_3")));			\
+	static char end[0] __aligned(4) __attribute__((unused))		\
+		__section(".u_boot_list_2_"#_list"_3");			\
 	(_type *)&end;							\
 })
 /**
@@ -245,8 +245,8 @@
  */
 #define ll_start(_type)							\
 ({									\
-	static char start[0] __aligned(4) __attribute__((unused,	\
-		section(".u_boot_list_1")));				\
+	static char start[0] __aligned(4) __attribute__((unused))	\
+		__section(".u_boot_list_1");				\
 	(_type *)&start;						\
 })
 
@@ -268,8 +268,8 @@
  */
 #define ll_end(_type)							\
 ({									\
-	static char end[0] __aligned(4) __attribute__((unused,		\
-		section(".u_boot_list_3")));				\
+	static char end[0] __aligned(4) __attribute__((unused))		\
+		__section(".u_boot_list_3");				\
 	(_type *)&end;							\
 })
 
include/linux/compiler.h +4 -4
index 5e3b3c08e9..82a8a4ede9 100644
@@ -24,7 +24,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 			long ______r;					\
 			static struct ftrace_likely_data		\
 				__aligned(4)				\
-				__section(_ftrace_annotated_branch)	\
+				__section("_ftrace_annotated_branch")	\
 				______f = {				\
 				.data.func = __func__,			\
 				.data.file = __FILE__,			\
@@ -60,7 +60,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 #define __trace_if_value(cond) ({			\
 	static struct ftrace_branch_data		\
 		__aligned(4)				\
-		__section(_ftrace_branch)		\
+		__section("_ftrace_branch")		\
 		__if_trace = {				\
 			.func = __func__,		\
 			.file = __FILE__,		\
@@ -118,7 +118,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 	".popsection\n\t"
 
 /* Annotate a C jump table to allow objtool to follow the code flow */
-#define __annotate_jump_table __section(.rodata..c_jump_table)
+#define __annotate_jump_table __section(".rodata..c_jump_table")
 
 #else
 #define annotate_reachable()
@@ -294,7 +294,7 @@ unsigned long read_word_at_a_time(const void *addr)
  * visible to the compiler.
  */
 #define __ADDRESSABLE(sym) \
-	static void * __section(.discard.addressable) __used \
+	static void * __section(".discard.addressable") __used \
 		__PASTE(__addressable_##sym, __LINE__) = (void *)&sym;
 
 /**
include/linux/compiler_attributes.h +1 -1
index cdf0165966..44c9a08d73 100644
@@ -246,7 +246,7 @@
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute
  * clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate
  */
-#define __section(S)                    __attribute__((__section__(#S)))
+#define __section(S)                    __attribute__((__section__(S)))
 
 /*
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute
lib/trace.c +2 -2
index 9e34b19537..505a31806c 100644
@@ -13,8 +13,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static char trace_enabled __attribute__((section(".data")));
-static char trace_inited __attribute__((section(".data")));
+static char trace_enabled __section(".data");
+static char trace_inited __section(".data");
 
 /* The header block at the start of the trace memory area */
 struct trace_hdr {
Signature · 1 line
2.26.3
#9 lore raw

PATCH v4 3/36 treewide: Convert macro and uses of __section(foo) to __section("foo")

Quoted 60 lines · Marek Beh?n

This commit does the same thing as Linux commit 33def8498fdd.

Use a more generic form for __section that requires quotes to avoid complications with clang and gcc differences.

Remove the quote operator # from compiler_attributes.h __section macro.

Convert all unquoted __section(foo) uses to quoted __section("foo"). Also convert __attribute__((section("foo"))) uses to __section("foo") even if the __attribute__ has multiple list entry forms.

---
 arch/arm/cpu/arm926ejs/spear/spl.c        |  2 +-
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c |  2 +-
 arch/arm/cpu/armv8/spl_data.c             |  4 +--
 arch/arm/include/asm/secure.h             |  6 ++---
 arch/arm/include/asm/setup.h              |  2 +-
 arch/arm/lib/sections.c                   | 31 ++++++++++++-----------
 arch/arm/lib/spl.c                        |  2 +-
 arch/arm/mach-at91/spl.c                  |  2 +-
 arch/arm/mach-k3/am642_init.c             |  2 +-
 arch/arm/mach-k3/am6_init.c               |  2 +-
 arch/arm/mach-k3/j721e_init.c             |  4 +--
 arch/arm/mach-mvebu/mbus.c                |  4 +--
 arch/arm/mach-mvebu/timer.c               |  2 +-
 arch/arm/mach-nexell/clock.c              |  6 ++---
 arch/arm/mach-nexell/timer.c              |  6 ++---
 arch/arm/mach-socfpga/spl_a10.c           |  2 +-
 arch/arm/mach-sunxi/board.c               |  2 +-
 arch/arm/mach-tegra/board.c               |  2 +-
 arch/arm/mach-tegra/cboot.c               |  8 +++---
 arch/mips/mach-jz47xx/jz4780/jz4780.c     |  2 +-
 arch/nds32/include/asm/setup.h            |  6 ++---
 arch/powerpc/include/asm/cache.h          |  4 +--
 arch/riscv/cpu/cpu.c                      |  4 +--
 arch/sandbox/include/asm/getopt.h         |  2 +-
 arch/sandbox/lib/sections.c               |  9 ++++---
 arch/x86/cpu/coreboot/timestamp.c         |  2 +-
 arch/x86/lib/coreboot/cb_sysinfo.c        |  2 +-
 arch/x86/lib/sections.c                   |  9 ++++---
 arch/xtensa/cpu/cpu.c                     |  2 +-
 board/bosch/shc/board.c                   |  2 +-
 board/broadcom/bcmstb/bcmstb.c            |  2 +-
 board/samsung/arndale/arndale_spl.c       |  2 +-
 board/samsung/smdk5250/smdk5250_spl.c     |  2 +-
 board/samsung/smdk5420/smdk5420_spl.c     |  2 +-
 board/siemens/draco/board.c               |  2 +-
 board/xilinx/common/fru_ops.c             |  2 +-
 drivers/bios_emulator/biosemu.c           |  4 +--
 drivers/clk/kendryte/clk.c                |  4 +--
 drivers/firmware/psci.c                   |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx5.c        |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx7.c        |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx8m.c       |  2 +-
 drivers/power/pmic/pmic_tps62362.c        |  2 +-
 drivers/power/pmic/pmic_tps65217.c        |  2 +-
 drivers/power/pmic/pmic_tps65218.c        |  2 +-
Quoted 8 lines
 drivers/power/pmic/pmic_tps65910.c        |  2 +-
 drivers/serial/serial_pl01x.c             |  4 +--
 include/efi_loader.h                      |  4 +--
 include/linker_lists.h                    | 24 +++++++++---------
 include/linux/compiler.h                  |  8 +++---
 include/linux/compiler_attributes.h       |  2 +-
 lib/trace.c                               |  4 +--
 52 files changed, 110 insertions(+), 107 deletions(-)
#10 lore raw

Re: [PATCH u-boot v4 03/36] treewide: Convert macro and uses of __section(foo) to __section("foo")

In reply to Marek Behún
Quoted 7 lines · Marek Behún

This commit does the same thing as Linux commit 33def8498fdd.

Use a more generic form for __section that requires quotes to avoid complications with clang and gcc differences.

Remove the quote operator # from compiler_attributes.h __section macro.

Quoted 7 lines

Convert all unquoted __section(foo) uses to quoted __section("foo"). Also convert __attribute__((section("foo"))) uses to __section("foo") even if the __attribute__ has multiple list entry forms.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#11 lore raw

PATCH v4 4/36 compiler.h: align the __ADDRESSABLE macro with Linux' version

In reply to Marek Behún

Use UNIQUE_ID in the __ADDRESSABLE macro.

---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler.h +1 -1
index 82a8a4ede9..98dd3fc4cc 100644
@@ -295,7 +295,7 @@ unsigned long read_word_at_a_time(const void *addr)
  */
 #define __ADDRESSABLE(sym) \
 	static void * __section(".discard.addressable") __used \
-		__PASTE(__addressable_##sym, __LINE__) = (void *)&sym;
+		__UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym;
 
 /**
  * offset_to_ptr - convert a relative memory offset to an absolute pointer
Signature · 1 line
2.26.3
#13 lore raw

PATCH v4 5/36 test/py: improve regular expression for ut subtest symbol matcher

In reply to Marek Behún

Improve the regular expression that matches unittest symbols in u-boot.sym.

Currently we do not enforce no prefix in symbol string, but with the soon to come change in linker lists declaring lists and entries with the __ADDRESSABLE macro (because of LTO), the symbol file will contain for every symbol of the form
_u_boot_list_2_ut_X_2_Y
also symbol
__UNIQUE_ID___addressable__u_boot_list_2_ut_X_2_YN,
(where N at the end is some number).

In order to avoid matching these additional symbols, ensure that the character before "_u_boot_list_2_ut" is not a symbol name character.

---
 test/py/conftest.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/py/conftest.py +1 -1
index 1b909cde9d..11a3f307ea 100644
@@ -226,7 +226,7 @@ def pytest_configure(config):
         import u_boot_console_exec_attach
         console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
 
-re_ut_test_list = re.compile(r'_u_boot_list_2_ut_(.*)_test_2_\1_test_(.*)\s*$')
+re_ut_test_list = re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_ut_(.*)_test_2_\1_test_(.*)\s*$')
 def generate_ut_subtest(metafunc, fixture_name, sym_path):
     """Provide parametrization for a ut_subtest fixture.
 
Signature · 1 line
2.26.3
#14 lore raw

PATCH v4 5/36 test/py: improve regular expression for ut subtest symbol matcher

Quoted 13 lines · Marek Beh?n

Improve the regular expression that matches unittest symbols in u-boot.sym.

Currently we do not enforce no prefix in symbol string, but with the soon to come change in linker lists declaring lists and entries with the __ADDRESSABLE macro (because of LTO), the symbol file will contain for every symbol of the form
_u_boot_list_2_ut_X_2_Y
also symbol
__UNIQUE_ID___addressable__u_boot_list_2_ut_X_2_YN,
(where N at the end is some number).

Quoted 7 lines

In order to avoid matching these additional symbols, ensure that the character before "_u_boot_list_2_ut" is not a symbol name character.

---
 test/py/conftest.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#15 lore raw

Re: [PATCH u-boot v4 05/36] test/py: improve regular expression for ut subtest symbol matcher

In reply to Marek Behún
Quoted 12 lines · Marek Behún

Improve the regular expression that matches unittest symbols in u-boot.sym.

Currently we do not enforce no prefix in symbol string, but with the soon to come change in linker lists declaring lists and entries with the __ADDRESSABLE macro (because of LTO), the symbol file will contain for every symbol of the form
_u_boot_list_2_ut_X_2_Y
also symbol
__UNIQUE_ID___addressable__u_boot_list_2_ut_X_2_YN,
(where N at the end is some number).

Quoted 5 lines

In order to avoid matching these additional symbols, ensure that the character before "_u_boot_list_2_ut" is not a symbol name character.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#16 lore raw

PATCH v4 6/36 string: make memcpy(), memset(), memcmp() and memmove() visible for LTO

In reply to Marek Behún

It seems that sometimes (happening on ARM64, for example with turris_mox_defconfig) GCC, when linking with LTO, changes the symbol names of some functions, for example lib/string.c's memcpy() function to memcpy.isra.0.

This is a problem however when GCC for a code such as this:

	struct some_struct *info = get_some_struct();
	struct some struct tmpinfo;
	tmpinfo = *info;

emits a call to memcpy() by builtin behaviour, to copy *info to tmpinfo.

This then results in the following linking error:
.../lz4.c:93: undefined reference to memcpy' .../uuid.c:206: more undefined references to memcpy' follow

GCC's documentation says this about -nodefaultlibs option:
The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

Make these functions visible by using the __used macro to avoid this error.

---
 lib/string.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/string.c +5 -4
index a0cff8fe88..ba176fb08f 100644
@@ -16,6 +16,7 @@
  */
 
 #include <config.h>
+#include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
@@ -513,7 +514,7 @@ char *strswab(const char *s)
  *
  * Do not use memset() to access IO space, use memset_io() instead.
  */
-void * memset(void * s,int c,size_t count)
+__used void * memset(void * s,int c,size_t count)
 {
 	unsigned long *sl = (unsigned long *) s;
 	char *s8;
@@ -552,7 +553,7 @@ void * memset(void * s,int c,size_t count)
  * You should not use this function to access IO space, use memcpy_toio()
  * or memcpy_fromio() instead.
  */
-void * memcpy(void *dest, const void *src, size_t count)
+__used void * memcpy(void *dest, const void *src, size_t count)
 {
 	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
 	char *d8, *s8;
@@ -586,7 +587,7 @@ void * memcpy(void *dest, const void *src, size_t count)
  *
  * Unlike memcpy(), memmove() copes with overlapping areas.
  */
-void * memmove(void * dest,const void *src,size_t count)
+__used void * memmove(void * dest,const void *src,size_t count)
 {
 	char *tmp, *s;
 
@@ -622,7 +623,7 @@ void * memmove(void * dest,const void *src,size_t count)
  * @ct: Another area of memory
  * @count: The size of the area.
  */
-int memcmp(const void * cs,const void * ct,size_t count)
+__used int memcmp(const void * cs,const void * ct,size_t count)
 {
 	const unsigned char *su1, *su2;
 	int res = 0;
Signature · 1 line
2.26.3
#17 lore raw

PATCH v4 6/36 string: make memcpy(), memset(), memcmp() and memmove() visible for LTO

Quoted 22 lines · Marek Beh?n

It seems that sometimes (happening on ARM64, for example with turris_mox_defconfig) GCC, when linking with LTO, changes the symbol names of some functions, for example lib/string.c's memcpy() function to memcpy.isra.0.

This is a problem however when GCC for a code such as this:

        struct some_struct *info = get_some_struct();
        struct some struct tmpinfo;
        tmpinfo = *info;

emits a call to memcpy() by builtin behaviour, to copy *info to tmpinfo.

This then results in the following linking error:
.../lz4.c:93: undefined reference to memcpy' .../uuid.c:206: more undefined references to memcpy' follow

GCC's documentation says this about -nodefaultlibs option:
The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

Quoted 7 lines

Make these functions visible by using the __used macro to avoid this error.

---
 lib/string.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
#18 lore raw

Re: [PATCH u-boot v4 06/36] string: make memcpy(), memset(), memcmp() and memmove() visible for LTO

In reply to Marek Behún
Quoted 21 lines · Marek Behún

It seems that sometimes (happening on ARM64, for example with turris_mox_defconfig) GCC, when linking with LTO, changes the symbol names of some functions, for example lib/string.c's memcpy() function to memcpy.isra.0.

This is a problem however when GCC for a code such as this:

	struct some_struct *info = get_some_struct();
	struct some struct tmpinfo;
	tmpinfo = *info;

emits a call to memcpy() by builtin behaviour, to copy *info to tmpinfo.

This then results in the following linking error:
.../lz4.c:93: undefined reference to memcpy' .../uuid.c:206: more undefined references to memcpy' follow

GCC's documentation says this about -nodefaultlibs option:
The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

Quoted 5 lines

Make these functions visible by using the __used macro to avoid this error.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#19 lore raw

PATCH v4 7/36 efi_loader: fix warning when linking with LTO

In reply to Marek Behún

When linking with LTO, the compiler complains about type mismatch of variables __efi_runtime_start, __efi_runtime_stop, __efi_runtime_rel_start and __efi_runtime_rel_stop:

include/efi_loader.h:218:21: warning: type of ?__efi_runtime_start?
does not match original declaration [-Wlto-type-mismatch]
218 | extern unsigned int __efi_runtime_start, __efi_runtime_stop;
| ^
arch/sandbox/lib/sections.c:7:6: note: ?__efi_runtime_start? was
previously declared here
7 | char __efi_runtime_start[0] __attribute__((section(".__efi_run
| ^

Change the type to char[] in include/efi_loader.h.

---
 include/efi_loader.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/efi_loader.h +2 -2
index ce9b2388c5..ea03af43c2 100644
@@ -217,8 +217,8 @@ extern const efi_guid_t efi_guid_firmware_management_protocol;
 /* GUID for the ESRT */
 extern const efi_guid_t efi_esrt_guid;
 
-extern unsigned int __efi_runtime_start, __efi_runtime_stop;
-extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
+extern char __efi_runtime_start[], __efi_runtime_stop[];
+extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[];
 
 /**
  * struct efi_open_protocol_info_item - open protocol info item
Signature · 1 line
2.26.3
#20 lore raw

Re: [PATCH u-boot v4 07/36] efi_loader: fix warning when linking with LTO

Quoted 14 lines · Marek Behún

When linking with LTO, the compiler complains about type mismatch of variables __efi_runtime_start, __efi_runtime_stop, __efi_runtime_rel_start and __efi_runtime_rel_stop:

include/efi_loader.h:218:21: warning: type of ‘__efi_runtime_start’
does not match original declaration [-Wlto-type-mismatch]
218 | extern unsigned int __efi_runtime_start, __efi_runtime_stop;
| ^
arch/sandbox/lib/sections.c:7:6: note: ‘__efi_runtime_start’ was
previously declared here
7 | char __efi_runtime_start[0] __attribute__((section(".__efi_run
| ^

Quoted 4 lines

Change the type to char[] in include/efi_loader.h.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#21 lore raw

PATCH v4 8/36 efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data

In reply to Marek Behún

Document the macros __efi_runtime and __efi_runtime_data in Sphinx style.

---
 include/efi_loader.h | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
include/efi_loader.h +26 -3
index ea03af43c2..cfd68e329c 100644
@@ -678,11 +678,34 @@ ssize_t efi_dp_check_length(const struct efi_device_path *dp,
 	(((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
 	 ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
 
-/*
- * Use these to indicate that your code / data should go into the EFI runtime
- * section and thus still be available when the OS is running
+/**
+ * __efi_runtime_data - declares a non-const variable for EFI runtime section
+ *
+ * This macro indicates that a variable is non-const and should go into the
+ * EFI runtime section, and thus still be available when the OS is running.
+ *
+ * Only use on variables not declared const.
+ *
+ * Example:
+ *
+ * ::
+ *
+ *   static __efi_runtime_data my_computed_table[256];
  */
 #define __efi_runtime_data __section(".data.efi_runtime")
+
+/**
+ * __efi_runtime - declares a function for EFI runtime section
+ *
+ * This macro indicates that a function should go into the EFI runtime section,
+ * and thus still be available when the OS is running.
+ *
+ * Example:
+ *
+ * ::
+ *
+ *   static __efi_runtime compute_my_table(void);
+ */
 #define __efi_runtime __section(".text.efi_runtime")
 
 /* Indicate supported runtime services */
Signature · 1 line
2.26.3
#23 lore raw

PATCH v4 9/36 efi_loader: add macro for const EFI runtime data

In reply to Marek Behún

Add macro __efi_runtime_rodata, for const variables with similar purpose as those using __efi_runtime_data.

---
 include/efi_loader.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/efi_loader.h +17 -0
index cfd68e329c..522696d635 100644
@@ -694,6 +694,22 @@ ssize_t efi_dp_check_length(const struct efi_device_path *dp,
  */
 #define __efi_runtime_data __section(".data.efi_runtime")
 
+/**
+ * __efi_runtime_rodata - declares a read-only variable for EFI runtime section
+ *
+ * This macro indicates that a variable is read-only (const) and should go into
+ * the EFI runtime section, and thus still be available when the OS is running.
+ *
+ * Only use on variables also declared const.
+ *
+ * Example:
+ *
+ * ::
+ *
+ *   static const __efi_runtime_rodata my_const_table[] = { 1, 2, 3 };
+ */
+#define __efi_runtime_rodata __section(".rodata.efi_runtime")
+
 /**
  * __efi_runtime - declares a function for EFI runtime section
  *
@@ -911,6 +927,7 @@ efi_status_t efi_launch_capsules(void);
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
 #define __efi_runtime_data
+#define __efi_runtime_rodata
 #define __efi_runtime
 static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
 {
Signature · 1 line
2.26.3
#25 lore raw

PATCH v4 10/36 efi_selftest: compiler flags for efi_selftest_miniapp_exception.o

In reply to Marek Behún

Add $(CFLAGS_EFI) and remove $(CFLAGS_NON_EFI) for efi_selftest_miniapp_exception.o.

The removal is needed when compiling with LTO - this object file needs to be compiled without -flto.

The adding is for consistency with other miniapps.

---
 lib/efi_selftest/Makefile | 2 ++
 1 file changed, 2 insertions(+)
lib/efi_selftest/Makefile +2 -0
index aa71d0995c..9ff6e1760c 100644
@@ -10,6 +10,8 @@ ccflags-y += -DHOST_ARCH="$(HOST_ARCH)"
 
 CFLAGS_dtbdump.o := $(CFLAGS_EFI) -Os -ffreestanding
 CFLAGS_REMOVE_dtbdump.o := $(CFLAGS_NON_EFI)
+CFLAGS_efi_selftest_miniapp_exception.o := $(CFLAGS_EFI) -Os -ffreestanding
+CFLAGS_REMOVE_efi_selftest_miniapp_exception.o := $(CFLAGS_NON_EFI)
 CFLAGS_efi_selftest_miniapp_exit.o := $(CFLAGS_EFI) -Os -ffreestanding
 CFLAGS_REMOVE_efi_selftest_miniapp_exit.o := $(CFLAGS_NON_EFI)
 CFLAGS_efi_selftest_miniapp_return.o := $(CFLAGS_EFI) -Os -ffreestanding
Signature · 1 line
2.26.3
#26 lore raw

Re: [PATCH u-boot v4 10/36] efi_selftest: compiler flags for efi_selftest_miniapp_exception.o

Quoted 10 lines · Marek Behún

Add $(CFLAGS_EFI) and remove $(CFLAGS_NON_EFI) for efi_selftest_miniapp_exception.o.

The removal is needed when compiling with LTO - this object file needs to be compiled without -flto.

The adding is for consistency with other miniapps.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#27 lore raw

PATCH v4 11/36 lib: crc32: put the crc_table variable into efi_runtime_rodata section

In reply to Marek Behún

When compiling with LTO, the compiler fails with an error saying that crc_table causes a section type conflict with efi_var_buf.

This is because both are declared to be in the same section (via macro __efi_runtime_data), but one is const while the other is not.

Put this variable into the section .rodata.efi_runtime, instead of .data.efi_runtime, via macro __efi_runtime_rodata.

---
 lib/crc32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/crc32.c +2 -1
index e9be3bf386..f2acc107fe 100644
@@ -26,6 +26,7 @@
 #ifdef USE_HOSTCC
 #define __efi_runtime
 #define __efi_runtime_data
+#define __efi_runtime_rodata
 #endif
 
 #define tole(x) cpu_to_le32(x)
@@ -88,7 +89,7 @@ static void __efi_runtime make_crc_table(void)
  * Table of CRC-32's of all single-byte values (made by make_crc_table)
  */
 
-static const uint32_t __efi_runtime_data crc_table[256] = {
+static const uint32_t __efi_runtime_rodata crc_table[256] = {
 tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
 tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
 tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
Signature · 1 line
2.26.3
#28 lore raw

Re: [PATCH u-boot v4 11/36] lib: crc32: put the crc_table variable into efi_runtime_rodata section

Quoted 6 lines · Marek Behún

When compiling with LTO, the compiler fails with an error saying that crc_table causes a section type conflict with efi_var_buf.

This is because both are declared to be in the same section (via macro __efi_runtime_data), but one is const while the other is not.

Quoted 6 lines

Put this variable into the section .rodata.efi_runtime, instead of .data.efi_runtime, via macro __efi_runtime_rodata.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#29 lore raw

PATCH v4 12/36 Makefile, Makefile.spl: cosmetic change

In reply to Marek Behún

Indent the linking commands so that they look cosmetically better.

---
 Makefile             | 12 +++++++-----
 scripts/Makefile.spl | 17 +++++++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)
Makefile +7 -5
index 3a6cd15460..bfdb65e098 100644
@@ -1709,11 +1709,13 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink)
 # Rule to link u-boot
 # May be overridden by arch/$(ARCH)/config.mk
 quiet_cmd_u-boot__ ?= LD      $@
-      cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
-      -T u-boot.lds $(u-boot-init)                             \
-      --start-group $(u-boot-main) --end-group                 \
-      $(PLATFORM_LIBS) -Map u-boot.map;                        \
-      $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+      cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@		\
+		-T u-boot.lds $(u-boot-init)					\
+		--start-group							\
+			$(u-boot-main)						\
+		--end-group							\
+		$(PLATFORM_LIBS) -Map u-boot.map;				\
+		$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
 quiet_cmd_smap = GEN     common/system_map.o
 cmd_smap = \
scripts/Makefile.spl +11 -6
index c69525fa74..92775fef54 100644
@@ -451,12 +451,17 @@ $(obj)/$(SPL_BIN).sym: $(obj)/$(SPL_BIN) FORCE
 # Rule to link u-boot-spl
 # May be overridden by arch/$(ARCH)/config.mk
 quiet_cmd_u-boot-spl ?= LD      $@
-      cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F)) \
-		       $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
-		       $(patsubst $(obj)/%,%,$(u-boot-spl-main))  \
-		       $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
-		       --end-group \
-		       $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
+      cmd_u-boot-spl ?= \
+	(								\
+		cd $(obj) &&						\
+		$(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F))		\
+		$(patsubst $(obj)/%,%,$(u-boot-spl-init))		\
+		--start-group						\
+			$(patsubst $(obj)/%,%,$(u-boot-spl-main))	\
+			$(patsubst $(obj)/%,%,$(u-boot-spl-platdata))	\
+		--end-group						\
+		$(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)	\
+	)
 
 $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
 		$(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
Signature · 1 line
2.26.3
#32 lore raw

PATCH v4 13/36 build: use thin archives instead of incremental linking

In reply to Marek Behún

Currently we use incremental linking (ld -r) to link several object files from one directory into one built-in.o object file containing the linked code from that directory (and its subdirectories).

Linux has, some time ago, moved to thin archives instead.

Thin archives are archives (.a) that do not really contain the object files, only references to them.

Using thin archives instead of incremental linking
- saves disk space
- apparently works better with dead code elimination
- makes things easier for LTO

The third point is the important one for us. With incremental linking there are several options how to do LTO, and that would unnecessarily complicate things.

We have to use the --whole-archive/--no-whole-archive linking option instead of --start-group/--end-group, otherwise linking may fail because of unresolved symbols, or the resulting binary will be unusable.

We also need to use the P flag for ar, otherwise final linking may fail.

---
 Makefile               |  4 ++--
 arch/sandbox/config.mk | 10 +++++++---
 scripts/Makefile.build | 16 ++++++++--------
 scripts/Makefile.spl   |  4 ++--
 4 files changed, 19 insertions(+), 15 deletions(-)
Makefile +2 -2
index bfdb65e098..70728b3351 100644
@@ -1711,9 +1711,9 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink)
 quiet_cmd_u-boot__ ?= LD      $@
       cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@		\
 		-T u-boot.lds $(u-boot-init)					\
-		--start-group							\
+		--whole-archive							\
 			$(u-boot-main)						\
-		--end-group							\
+		--no-whole-archive						\
 		$(PLATFORM_LIBS) -Map u-boot.map;				\
 		$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
arch/sandbox/config.mk +7 -3
index 189e9c2b0c..2149771324 100644
@@ -17,13 +17,17 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
 endif
 
 cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
-	-Wl,--start-group $(u-boot-main) -Wl,--end-group \
+	-Wl,--whole-archive \
+		$(u-boot-main) \
+	-Wl,--no-whole-archive \
 	$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
 
 cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
 	$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
-	-Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
-	$(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \
+	-Wl,--whole-archive \
+		$(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
+		$(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
+	-Wl,--no-whole-archive \
 	$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
 
 CONFIG_ARCH_DEVICE_TREE := sandbox
scripts/Makefile.build +8 -8
index 705a886cb9..7e59ca54cd 100644
@@ -331,12 +331,11 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
 # Rule to compile a set of .o files into one .o file
 #
 ifdef builtin-target
-quiet_cmd_link_o_target = LD      $@
+quiet_cmd_link_o_target = AR      $@
 # If the list of objects to link is empty, just create an empty built-in.o
 cmd_link_o_target = $(if $(strip $(obj-y)),\
-		      $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
-		      $(cmd_secanalysis),\
-		      rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
+		      rm -f $@; $(AR) cDPrsT $@ $(filter $(obj-y), $^), \
+		      rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@)
 
 $(builtin-target): $(obj-y) FORCE
 	$(call if_changed,link_o_target)
@@ -362,7 +361,7 @@ $(modorder-target): $(subdir-ym) FORCE
 #
 ifdef lib-target
 quiet_cmd_link_l_target = AR      $@
-cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
+cmd_link_l_target = rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@ $(lib-y)
 
 $(lib-target): $(lib-y) FORCE
 	$(call if_changed,link_l_target)
@@ -382,10 +381,11 @@ $(filter $(addprefix $(obj)/,         \
 $($(subst $(obj)/,,$(@:.o=-objs)))    \
 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
 
-quiet_cmd_link_multi-y = LD      $@
-cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
 
-quiet_cmd_link_multi-m = LD [M]  $@
+quiet_cmd_link_multi-y = AR      $@
+cmd_link_multi-y = rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@ $(link_multi_deps)
+
+quiet_cmd_link_multi-m = AR [M]  $@
 cmd_link_multi-m = $(cmd_link_multi-y)
 
 $(multi-used-y): FORCE
scripts/Makefile.spl +2 -2
index 92775fef54..ac2d2033ba 100644
@@ -456,10 +456,10 @@ quiet_cmd_u-boot-spl ?= LD      $@
 		cd $(obj) &&						\
 		$(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F))		\
 		$(patsubst $(obj)/%,%,$(u-boot-spl-init))		\
-		--start-group						\
+		--whole-archive						\
 			$(patsubst $(obj)/%,%,$(u-boot-spl-main))	\
 			$(patsubst $(obj)/%,%,$(u-boot-spl-platdata))	\
-		--end-group						\
+		--no-whole-archive					\
 		$(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)	\
 	)
 
Signature · 1 line
2.26.3
#33 lore raw

PATCH v4 13/36 build: use thin archives instead of incremental linking

Quoted 25 lines · Marek Beh?n

Currently we use incremental linking (ld -r) to link several object files from one directory into one built-in.o object file containing the linked code from that directory (and its subdirectories).

Linux has, some time ago, moved to thin archives instead.

Thin archives are archives (.a) that do not really contain the object files, only references to them.

Using thin archives instead of incremental linking
- saves disk space
- apparently works better with dead code elimination
- makes things easier for LTO

The third point is the important one for us. With incremental linking there are several options how to do LTO, and that would unnecessarily complicate things.

We have to use the --whole-archive/--no-whole-archive linking option instead of --start-group/--end-group, otherwise linking may fail because of unresolved symbols, or the resulting binary will be unusable.

We also need to use the P flag for ar, otherwise final linking may fail.

Quoted 7 lines
---
 Makefile               |  4 ++--
 arch/sandbox/config.mk | 10 +++++++---
 scripts/Makefile.build | 16 ++++++++--------
 scripts/Makefile.spl   |  4 ++--
 4 files changed, 19 insertions(+), 15 deletions(-)
#34 lore raw

Re: [PATCH u-boot v4 13/36] build: use thin archives instead of incremental linking

In reply to Marek Behún
Quoted 18 lines · Marek Behún

Currently we use incremental linking (ld -r) to link several object files from one directory into one built-in.o object file containing the linked code from that directory (and its subdirectories).

Linux has, some time ago, moved to thin archives instead.

Thin archives are archives (.a) that do not really contain the object files, only references to them.

Using thin archives instead of incremental linking
- saves disk space
- apparently works better with dead code elimination
- makes things easier for LTO

The third point is the important one for us. With incremental linking there are several options how to do LTO, and that would unnecessarily complicate things.

Quoted 8 lines

We have to use the --whole-archive/--no-whole-archive linking option instead of --start-group/--end-group, otherwise linking may fail because of unresolved symbols, or the resulting binary will be unusable.

We also need to use the P flag for ar, otherwise final linking may fail.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#35 lore raw

PATCH v4 14/36 build: support building with Link Time Optimizations

In reply to Marek Behún

Add plumbing for building U-Boot with Link Time Optimizations.

When building with LTO, $(PLATFORM_LIBS) has to be in --whole-archive / --no-whole-archive group, otherwise some functions declared in assembly may not be resolved and linking may fail.

Note: clang may throw away linker list symbols it thinks are unused when compiling with LTO. To force these symbols to be included, we refer to them via the __ADDRESSABLE macro in a C file generated from compiled built-in.o files before linking.

---
 Kbuild                                |  2 +
 Kconfig                               | 24 ++++++++++
 Makefile                              | 67 ++++++++++++++++++++++++++-
 scripts/Makefile.lib                  |  3 ++
 scripts/Makefile.spl                  | 44 +++++++++++++++++-
 scripts/gen_ll_addressable_symbols.sh | 12 +++++
 6 files changed, 149 insertions(+), 3 deletions(-)
 create mode 100755 scripts/gen_ll_addressable_symbols.sh
Kbuild +2 -0
index 1eac091594..bf52e54051 100644
@@ -10,6 +10,8 @@ generic-offsets-file := include/generated/generic-asm-offsets.h
 always  := $(generic-offsets-file)
 targets := lib/asm-offsets.s
 
+CFLAGS_REMOVE_asm-offsets.o := $(LTO_CFLAGS)
+
 $(obj)/$(generic-offsets-file): $(obj)/lib/asm-offsets.s FORCE
 	$(call filechk,offsets,__GENERIC_ASM_OFFSETS_H__)
 
Kconfig +24 -0
index 86f0a39bb0..f8c1a77bed 100644
@@ -85,6 +85,30 @@ config SPL_OPTIMIZE_INLINING
 	  do what it thinks is best, which is desirable in some cases for size
 	  reasons.
 
+config ARCH_SUPPORTS_LTO
+	bool
+
+config LTO
+	bool "Enable Link Time Optimizations"
+	depends on ARCH_SUPPORTS_LTO
+	default n
+	help
+	  This option enables Link Time Optimization (LTO), a mechanism which
+	  allows the compiler to optimize between different compilation units.
+
+	  This can optimize away dead code paths, resulting in smaller binary
+	  size (if CC_OPTIMIZE_FOR_SIZE is enabled).
+
+	  This option is not available for every architecture and may
+	  introduce bugs.
+
+	  Currently, when compiling with GCC, due to a weird bug regarding
+	  jobserver, the final linking will not respect make's --jobs argument.
+	  Instead all available processors will be used (as reported by the
+	  nproc command).
+
+	  If unsure, say n.
+
 config TPL_OPTIMIZE_INLINING
 	bool "Allow compiler to uninline functions marked 'inline' in TPL"
 	depends on TPL
Makefile +65 -2

99 lines not on this page · raw message

scripts/Makefile.lib +3 -0
index 78543c6dd1..78bbebe7e9 100644
@@ -419,6 +419,9 @@ $(obj)/%_efi.so: $(obj)/%.o $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_free
 
 targets += $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_freestanding.o
 
+CFLAGS_REMOVE_efi_reloc.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_efi_freestanding.o := $(LTO_CFLAGS)
+
 # ACPI
 # ---------------------------------------------------------------------------
 #
scripts/Makefile.spl +43 -1

60 lines not on this page · raw message

scripts/gen_ll_addressable_symbols.sh new file +12 -0
new file mode 100755
index 0000000000..3978a39d97
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2020 Marek Beh?n <[email protected]>
+
+# Generate __ADDRESSABLE(symbol) for every linker list entry symbol, so that LTO
+# does not optimize these symbols away
+
+set -e
+
+echo '#include <common.h>'
+$NM "$@" 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' | \
+	sort -u | sed -e 's/^\(.*\)/extern char \1[];\n__ADDRESSABLE(\1);/'
Signature · 1 line
2.26.3
#36 lore raw

PATCH v4 14/36 build: support building with Link Time Optimizations

Quoted 12 lines · Marek Beh?n

Add plumbing for building U-Boot with Link Time Optimizations.

When building with LTO, $(PLATFORM_LIBS) has to be in --whole-archive / --no-whole-archive group, otherwise some functions declared in assembly may not be resolved and linking may fail.

Note: clang may throw away linker list symbols it thinks are unused when compiling with LTO. To force these symbols to be included, we refer to them via the __ADDRESSABLE macro in a C file generated from compiled built-in.o files before linking.

Quoted 8 lines
---
 Kbuild                                |  2 +
 Kconfig                               | 24 ++++++++++
 Makefile                              | 67 ++++++++++++++++++++++++++-
 scripts/Makefile.lib                  |  3 ++
 scripts/Makefile.spl                  | 44 +++++++++++++++++-
 scripts/gen_ll_addressable_symbols.sh | 12 +++++

That is very long. How about gen_linkerlist_syms.sh ?

Quoted 2 lines
 6 files changed, 149 insertions(+), 3 deletions(-)
 create mode 100755 scripts/gen_ll_addressable_symbols.sh
#37 lore raw

Re: [PATCH u-boot v4 14/36] build: support building with Link Time Optimizations

In reply to Marek Behún
Quoted 6 lines · Marek Behún

Add plumbing for building U-Boot with Link Time Optimizations.

When building with LTO, $(PLATFORM_LIBS) has to be in --whole-archive / --no-whole-archive group, otherwise some functions declared in assembly may not be resolved and linking may fail.

Quoted 7 lines

Note: clang may throw away linker list symbols it thinks are unused when compiling with LTO. To force these symbols to be included, we refer to them via the __ADDRESSABLE macro in a C file generated from compiled built-in.o files before linking.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#38 lore raw

PATCH v4 15/36 build: link with --build-id=none

In reply to Marek Behún

Some toolchains are compiled so that they pass a --build-id=something parameter to the linker implicitly.

This causes U-Boot LTO linking to fail with something like:
ld: section .note.gnu.build-id LMA ... overlaps section .text LMA ...
because U-Boot's link scripts do not currently handle .note.gnu.build-id section.

Fix this by explicitly disabling build-id.

---
 Makefile             | 2 ++
 scripts/Makefile.spl | 2 ++
 2 files changed, 4 insertions(+)
Makefile +2 -0
index 2329edc159..a62f7e3f7c 100644
@@ -996,6 +996,8 @@ LDFLAGS_u-boot += $(LDFLAGS_FINAL)
 # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
 LDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker)
 
+LDFLAGS_u-boot += --build-id=none
+
 ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),)
 LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
 endif
scripts/Makefile.spl +2 -0
index 7872cbaabe..5be1a9ba1b 100644
@@ -399,6 +399,8 @@ LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
 # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
 LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
 
+LDFLAGS_$(SPL_BIN) += --build-id=none
+
 # Pick the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
 ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
Signature · 1 line
2.26.3
#39 lore raw

PATCH v4 15/36 build: link with --build-id=none

Quoted 9 lines · Marek Beh?n

Some toolchains are compiled so that they pass a --build-id=something parameter to the linker implicitly.

This causes U-Boot LTO linking to fail with something like:
ld: section .note.gnu.build-id LMA ... overlaps section .text LMA ...
because U-Boot's link scripts do not currently handle .note.gnu.build-id section.

Quoted 7 lines

Fix this by explicitly disabling build-id.

---
 Makefile             | 2 ++
 scripts/Makefile.spl | 2 ++
 2 files changed, 4 insertions(+)
#40 lore raw

Re: [PATCH u-boot v4 15/36] build: link with --build-id=none

In reply to Marek Behún
Quoted 8 lines · Marek Behún

Some toolchains are compiled so that they pass a --build-id=something parameter to the linker implicitly.

This causes U-Boot LTO linking to fail with something like:
ld: section .note.gnu.build-id LMA ... overlaps section .text LMA ...
because U-Boot's link scripts do not currently handle .note.gnu.build-id section.

Quoted 4 lines

Fix this by explicitly disabling build-id.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#41 lore raw

PATCH v4 16/36 sandbox: errno: avoid conflict with libc's errno

In reply to Marek Behún

When building with LTO, the system libc's errno variable used in arch/sandbox/cpu/os.c conflicts with U-Boot's errno (defined in lib/errno.c) with the following error:
.../ld: errno@@GLIBC_PRIVATE: TLS definition in /lib64/libc.so.6
section .tbss mismatches non-TLS reference in /tmp/u-boot.EQlEXz.ltrans0.ltrans.o

To avoid this conflict use different asm label for this variable when CONFIG_SANDBOX is enabled.

---
 include/errno.h | 8 +++++++-
 lib/errno.c     | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)
include/errno.h +7 -1
index 3af539b9e9..652ad67306 100644
@@ -8,7 +8,13 @@
 
 #include <linux/errno.h>
 
-extern int errno;
+#ifdef __SANDBOX__
+#define __errno_asm_label asm("__u_boot_errno")
+#else
+#define __errno_asm_label
+#endif
+
+extern int errno __errno_asm_label;
 
 #define __set_errno(val) do { errno = val; } while (0)
 
lib/errno.c +3 -1
index 8330a8fd14..ca0c756bd9 100644
@@ -1 +1,3 @@
-int errno = 0;
+#include <errno.h>
+
+int errno __errno_asm_label = 0;
Signature · 1 line
2.26.3
#42 lore raw

Re: [PATCH u-boot v4 16/36] sandbox: errno: avoid conflict with libc's errno

Quoted 7 lines · Marek Behún

When building with LTO, the system libc's errno variable used in arch/sandbox/cpu/os.c conflicts with U-Boot's errno (defined in lib/errno.c) with the following error:
.../ld: errno@@GLIBC_PRIVATE: TLS definition in /lib64/libc.so.6
section .tbss mismatches non-TLS reference in /tmp/u-boot.EQlEXz.ltrans0.ltrans.o

Quoted 6 lines

To avoid this conflict use different asm label for this variable when CONFIG_SANDBOX is enabled.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#43 lore raw

PATCH v4 17/36 sandbox: use sections instead of symbols for getopt array boundaries

In reply to Marek Behún

In style of linked lists, instead of declaring symbols for boundaries of getopt options array in the linker script, declare corresponding sections and retrieve the boundaries via static inline functions.

Without this clang's LTO produces binary without any getopt options, because for some reason it thinks that array is empty (start and end symbols are at the same address).

---
 arch/sandbox/cpu/os.c               |  3 ++-
 arch/sandbox/cpu/start.c            |  3 ++-
 arch/sandbox/cpu/u-boot-spl.lds     |  8 +++++---
 arch/sandbox/cpu/u-boot.lds         |  8 +++++---
 arch/sandbox/include/asm/sections.h | 21 ++++++++++++++++++---
 5 files changed, 32 insertions(+), 11 deletions(-)
arch/sandbox/cpu/os.c +2 -1
index b9ad341861..0d21827e1b 100644
@@ -375,7 +375,8 @@ static struct option *long_opts;
 
 int os_parse_args(struct sandbox_state *state, int argc, char *argv[])
 {
-	struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
+	struct sandbox_cmdline_option **sb_opt =
+		__u_boot_sandbox_option_start();
 	size_t num_options = __u_boot_sandbox_option_count();
 	size_t i;
 
arch/sandbox/cpu/start.c +2 -1
index e87365e800..63ca514ebd 100644
@@ -58,7 +58,8 @@ static int h_compare_opt(const void *p1, const void *p2)
 int sandbox_early_getopt_check(void)
 {
 	struct sandbox_state *state = state_get_current();
-	struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
+	struct sandbox_cmdline_option **sb_opt =
+		__u_boot_sandbox_option_start();
 	size_t num_options = __u_boot_sandbox_option_count();
 	size_t i;
 	int max_arg_len, max_noarg_len;
arch/sandbox/cpu/u-boot-spl.lds +5 -3
index 18160436a3..6754f4ef6c 100644
@@ -21,9 +21,11 @@ SECTIONS
 		__priv_data_end = .;
 	}
 
-	__u_boot_sandbox_option_start = .;
-	_u_boot_sandbox_getopt : { KEEP(*(.u_boot_sandbox_getopt)) }
-	__u_boot_sandbox_option_end = .;
+	_u_boot_sandbox_getopt : {
+		*(.u_boot_sandbox_getopt_start)
+		KEEP(*(.u_boot_sandbox_getopt))
+		*(.u_boot_sandbox_getopt_end)
+	}
 }
 
 INSERT AFTER .data;
arch/sandbox/cpu/u-boot.lds +5 -3
index a1f509c9ab..6d710618f5 100644
@@ -13,9 +13,11 @@ SECTIONS
 		KEEP(*(SORT(.u_boot_list*)));
 	}
 
-	__u_boot_sandbox_option_start = .;
-	_u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) }
-	__u_boot_sandbox_option_end = .;
+	_u_boot_sandbox_getopt : {
+		*(.u_boot_sandbox_getopt_start)
+		*(.u_boot_sandbox_getopt)
+		*(.u_boot_sandbox_getopt_end)
+	}
 
 	.__efi_runtime_start : {
 		*(.__efi_runtime_start)
arch/sandbox/include/asm/sections.h +18 -3
index fbc1bd11a3..f4351ae7db 100644
@@ -13,12 +13,27 @@
 
 struct sandbox_cmdline_option;
 
-extern struct sandbox_cmdline_option *__u_boot_sandbox_option_start[],
-	*__u_boot_sandbox_option_end[];
+static inline struct sandbox_cmdline_option **
+__u_boot_sandbox_option_start(void)
+{
+	static char start[0] __aligned(4) __attribute__((unused))
+		__section(".u_boot_sandbox_getopt_start");
+
+	return (struct sandbox_cmdline_option **)&start;
+}
+
+static inline struct sandbox_cmdline_option **
+__u_boot_sandbox_option_end(void)
+{
+	static char end[0] __aligned(4) __attribute__((unused))
+		__section(".u_boot_sandbox_getopt_end");
+
+	return (struct sandbox_cmdline_option **)&end;
+}
 
 static inline size_t __u_boot_sandbox_option_count(void)
 {
-	return __u_boot_sandbox_option_end - __u_boot_sandbox_option_start;
+	return __u_boot_sandbox_option_end() - __u_boot_sandbox_option_start();
 }
 
 #endif
Signature · 1 line
2.26.3
#44 lore raw

PATCH v4 17/36 sandbox: use sections instead of symbols for getopt array boundaries

Quoted 9 lines · Marek Beh?n

In style of linked lists, instead of declaring symbols for boundaries of getopt options array in the linker script, declare corresponding sections and retrieve the boundaries via static inline functions.

Without this clang's LTO produces binary without any getopt options, because for some reason it thinks that array is empty (start and end symbols are at the same address).

Quoted 8 lines
---
 arch/sandbox/cpu/os.c               |  3 ++-
 arch/sandbox/cpu/start.c            |  3 ++-
 arch/sandbox/cpu/u-boot-spl.lds     |  8 +++++---
 arch/sandbox/cpu/u-boot.lds         |  8 +++++---
 arch/sandbox/include/asm/sections.h | 21 ++++++++++++++++++---
 5 files changed, 32 insertions(+), 11 deletions(-)
#45 lore raw

Re: [PATCH u-boot v4 17/36] sandbox: use sections instead of symbols for getopt array boundaries

In reply to Marek Behún
Quoted 10 lines · Marek Behún

In style of linked lists, instead of declaring symbols for boundaries of getopt options array in the linker script, declare corresponding sections and retrieve the boundaries via static inline functions.

Without this clang's LTO produces binary without any getopt options, because for some reason it thinks that array is empty (start and end symbols are at the same address).

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#46 lore raw

PATCH v4 18/36 sandbox: make LTO available

In reply to Marek Behún

Make LTO available for sandbox architecture.

---
 arch/Kconfig           | 1 +
 arch/sandbox/config.mk | 4 ++++
 2 files changed, 5 insertions(+)
arch/Kconfig +1 -0
index 6c4b81a486..c5c03d438c 100644
@@ -101,6 +101,7 @@ config RISCV
 
 config SANDBOX
 	bool "Sandbox"
+	select ARCH_SUPPORTS_LTO
 	select BOARD_LATE_INIT
 	select BZIP2
 	select CMD_POWEROFF
arch/sandbox/config.mk +4 -0
index 2149771324..1f8cb61c8b 100644
@@ -17,16 +17,20 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
 endif
 
 cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
+	$(LTO_FINAL_LDFLAGS) \
 	-Wl,--whole-archive \
 		$(u-boot-main) \
+		$(u-boot-keep-syms-lto) \
 	-Wl,--no-whole-archive \
 	$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
 
 cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
+	$(LTO_FINAL_LDFLAGS) \
 	$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
 	-Wl,--whole-archive \
 		$(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
 		$(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
+		$(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto)) \
 	-Wl,--no-whole-archive \
 	$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
 
Signature · 1 line
2.26.3
#48 lore raw

PATCH v4 19/36 sandbox: enable LTO by default

In reply to Marek Behún

Build sandbox targets with LTO by default.

---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
index c5c03d438c..8fd39e36b4 100644
@@ -125,6 +125,7 @@ config SANDBOX
 	select SUPPORT_EXTENSION_SCAN
 	imply BITREVERSE
 	select BLOBLIST
+	imply LTO
 	imply CMD_DM
 	imply CMD_EXCEPTION
 	imply CMD_GETTIME
Signature · 1 line
2.26.3
#50 lore raw

PATCH v4 20/36 ARM: global_data: make set_gd() work for armv5 and armv6

In reply to Marek Behún

The Thumb instruction ldr is able to move high registers only from armv7. For armv5 and armv6 we have to use mov.

---
 arch/arm/include/asm/global_data.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/include/asm/global_data.h +3 -1
index fba655f3b9..bb82efafa6 100644
@@ -122,8 +122,10 @@ static inline void set_gd(volatile gd_t *gd_ptr)
 {
 #ifdef CONFIG_ARM64
 	__asm__ volatile("ldr x18, %0\n" : : "m"(gd_ptr));
-#else
+#elif __ARM_ARCH >= 7
 	__asm__ volatile("ldr r9, %0\n" : : "m"(gd_ptr));
+#else
+	__asm__ volatile("mov r9, %0\n" : : "r"(gd_ptr));
 #endif
 }
 
Signature · 1 line
2.26.3
#51 lore raw

PATCH v4 20/36 ARM: global_data: make set_gd() work for armv5 and armv6

Quoted 8 lines · Marek Beh?n

The Thumb instruction ldr is able to move high registers only from armv7. For armv5 and armv6 we have to use mov.

---
 arch/arm/include/asm/global_data.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
#53 lore raw

PATCH v4 21/36 ARM: make gd a function call for LTO and set via set_gd()

In reply to Marek Behún

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

---
 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(-)
arch/arm/cpu/arm926ejs/mxs/spl_boot.c +1 -1
index a16a15e79d..66406cc857 100644
@@ -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();
 
arch/arm/include/asm/global_data.h +1 -1
index bb82efafa6..2aff1c467c 100644
@@ -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()
arch/arm/mach-exynos/spl_boot.c +1 -1
index 27f0dac182..722449881a 100644
@@ -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;
arch/arm/mach-imx/imx8m/soc.c +1 -1
index 36abb2e57f..0c44022a6d 100644
@@ -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");
arch/arm/mach-imx/spl_imx_romapi.c +8 -8
index 9f4d95982e..d2085dabd3 100644
@@ -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");
Signature · 1 line
2.26.3
#54 lore raw

PATCH v4 21/36 ARM: make gd a function call for LTO and set via set_gd()

Quoted 23 lines · Marek Beh?n

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

Quoted 8 lines
---
 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(-)
#55 lore raw

Re: [PATCH u-boot v4 21/36] ARM: make gd a function call for LTO and set via set_gd()

In reply to Marek Behún
Quoted 16 lines · Marek Behún

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.

Quoted 8 lines

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

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#56 lore raw

PATCH v4 22/36 ARM: fix LTO build for some thumb-interwork cases

In reply to Marek Behún

Fix LTO build for some thumb-interwork usecases (such as for da850evm_defconfig), where inline assmebly such as
mrc p15,0,r2,c1,c0,0
causes the compiler to fail during LTO linking with
Error: selected processor does not support `mrc p15,0,r2,c1,c0,0'
in Thumb mode

---
 arch/arm/cpu/arm926ejs/Makefile | 2 ++
 arch/arm/lib/Makefile           | 1 +
 2 files changed, 3 insertions(+)
arch/arm/cpu/arm926ejs/Makefile +2 -0
index af63d5cc5e..98aafe805a 100644
@@ -25,6 +25,8 @@ ifndef CONFIG_HAS_THUMB2
 
 CFLAGS_cpu.o := -marm
 CFLAGS_cache.o := -marm
+CFLAGS_REMOVE_cpu.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_cache.o := $(LTO_CFLAGS)
 
 endif
 endif
arch/arm/lib/Makefile +1 -0
index 27b12e7f2b..61bef1d5af 100644
@@ -64,6 +64,7 @@ endif
 
 obj-y	+= cache.o
 obj-$(CONFIG_SYS_ARM_CACHE_CP15)	+= cache-cp15.o
+CFLAGS_REMOVE_cache-cp15.o := $(LTO_CFLAGS)
 
 obj-y	+= psci-dt.o
 
Signature · 1 line
2.26.3
#57 lore raw

PATCH v4 22/36 ARM: fix LTO build for some thumb-interwork cases

Quoted 3 lines · Marek Beh?n

Fix LTO build for some thumb-interwork usecases (such as for da850evm_defconfig), where inline assmebly such as

assembly

Quoted 10 lines

mrc p15,0,r2,c1,c0,0
causes the compiler to fail during LTO linking with
Error: selected processor does not support `mrc p15,0,r2,c1,c0,0'
in Thumb mode

---
 arch/arm/cpu/arm926ejs/Makefile | 2 ++
 arch/arm/lib/Makefile           | 1 +
 2 files changed, 3 insertions(+)
#58 lore raw

Re: [PATCH u-boot v4 22/36] ARM: fix LTO build for some thumb-interwork cases

In reply to Marek Behún
Quoted 9 lines · Marek Behún

Fix LTO build for some thumb-interwork usecases (such as for da850evm_defconfig), where inline assmebly such as
mrc p15,0,r2,c1,c0,0
causes the compiler to fail during LTO linking with
Error: selected processor does not support `mrc p15,0,r2,c1,c0,0'
in Thumb mode

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#59 lore raw

PATCH v4 23/36 ARM: fix LTO for imx28_xea

In reply to Marek Behún

When imx28_xea_defconfig is built with LTO, the compiler complains about the two different declarations of _start:

   include/asm-generic/sections.h    as  extern void _start(void);
   arch/arm/cpu/arm926ejs/mxs/mxs.c  as  extern uint32_t _start;

Fix this.

---
 arch/arm/cpu/arm926ejs/mxs/mxs.c      | 2 +-
 arch/arm/cpu/arm926ejs/mxs/spl_boot.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/cpu/arm926ejs/mxs/mxs.c +1 -1
index 344b9b4e55..4d21e3df76 100644
@@ -25,6 +25,7 @@
 #include <asm/arch/iomux.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/sys_proto.h>
+#include <asm/sections.h>
 #include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -98,7 +99,6 @@ int arch_cpu_init(void)
 {
 	struct mxs_clkctrl_regs *clkctrl_regs =
 		(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
-	extern uint32_t _start;
 
 	mx28_fixup_vt((uint32_t)&_start);
 
arch/arm/cpu/arm926ejs/mxs/spl_boot.c +1 -1
index 66406cc857..0a8985b90a 100644
@@ -16,6 +16,7 @@
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/gpio.h>
+#include <asm/sections.h>
 #include <linux/compiler.h>
 
 #include "mxs_init.h"
@@ -100,7 +101,6 @@ static void mxs_spl_fixup_vectors(void)
 	 * thus this fixup. Our vectoring table is PIC, so copying is
 	 * fine.
 	 */
-	extern uint32_t _start;
 
 	/* cppcheck-suppress nullPointer */
 	memcpy(0x0, &_start, 0x60);
Signature · 1 line
2.26.3
#60 lore raw

Re: [PATCH u-boot v4 23/36] ARM: fix LTO for imx28_xea

Quoted 9 lines · Marek Behún

When imx28_xea_defconfig is built with LTO, the compiler complains about the two different declarations of _start:

   include/asm-generic/sections.h    as  extern void _start(void);
   arch/arm/cpu/arm926ejs/mxs/mxs.c  as  extern uint32_t _start;

Fix this.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#61 lore raw

PATCH v4 24/36 ARM: fix LTO for apf27

In reply to Marek Behún

When apf27_defconfig is built with LTO, linking complains about undefined reference to nand_boot. This is because it is referenced from inline assembly. Make it visible.

---
 drivers/mtd/nand/raw/mxc_nand_spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/mxc_nand_spl.c +1 -1
index e1e542519d..2f054b60ed 100644
@@ -326,7 +326,7 @@ int nand_spl_load_image(uint32_t from, unsigned int size, void *buf)
  * configured and available since this code loads the main U-Boot image
  * from NAND into SDRAM and starts it from there.
  */
-void nand_boot(void)
+__used void nand_boot(void)
 {
 	__attribute__((noreturn)) void (*uboot)(void);
 
Signature · 1 line
2.26.3
#62 lore raw

Re: [PATCH u-boot v4 24/36] ARM: fix LTO for apf27

Quoted 5 lines · Marek Behún

When apf27_defconfig is built with LTO, linking complains about undefined reference to nand_boot. This is because it is referenced from inline assembly. Make it visible.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#63 lore raw

PATCH v4 25/36 ARM: fix LTO for keystone

In reply to Marek Behún

When building keystone with LTO the compiler complains:
Error: selected processor does not support `smc #0' in Thumb mode

Fix this by removing -flto for the file implementing these SMC calls.

---
 arch/arm/mach-keystone/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-keystone/Makefile +1 -0
index 3e076e12ec..6c7c25090a 100644
@@ -9,6 +9,7 @@ obj-y	+= init.o
 obj-y	+= psc.o
 obj-y	+= clock.o
 obj-y	+= mon.o
+CFLAGS_REMOVE_mon.o := $(LTO_CFLAGS)
 ifndef CONFIG_SPL_BUILD
 obj-y	+= cmd_clock.o
 obj-y	+= cmd_mon.o
Signature · 1 line
2.26.3
#64 lore raw

Re: [PATCH u-boot v4 25/36] ARM: fix LTO for keystone

Quoted 6 lines · Marek Behún

When building keystone with LTO the compiler complains:
Error: selected processor does not support `smc #0' in Thumb mode

Fix this by removing -flto for the file implementing these SMC calls.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#65 lore raw

PATCH v4 26/36 ARM: kona: fix clk_bsc_enable() type mismatch for LTO

In reply to Marek Behún

When building with LTO, the compiler complains about type mismatch of function clk_bsc_enable() in file:
arch/arm/cpu/armv7/kona-common/clk-stubs.c
vs other files that define or use this function:
warning: type of ?clk_bsc_enable? does not match original declaration.

Change the type of this function to that of the other usages.

---
 arch/arm/cpu/armv7/kona-common/clk-stubs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv7/kona-common/clk-stubs.c +1 -1
index 2dfa3f7e73..4eddaca887 100644
@@ -14,7 +14,7 @@ int __weak clk_sdio_enable(void *base, u32 rate, u32 *actual_ratep)
 	return 0;
 }
 
-int __weak clk_bsc_enable(void *base, u32 rate, u32 *actual_ratep)
+int __weak clk_bsc_enable(void *base)
 {
 	return 0;
 }
Signature · 1 line
2.26.3
#66 lore raw

Re: [PATCH u-boot v4 26/36] ARM: kona: fix clk_bsc_enable() type mismatch for LTO

Quoted 10 lines · Marek Behún

When building with LTO, the compiler complains about type mismatch of function clk_bsc_enable() in file:
arch/arm/cpu/armv7/kona-common/clk-stubs.c
vs other files that define or use this function:
warning: type of ‘clk_bsc_enable’ does not match original declaration.

Change the type of this function to that of the other usages.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#67 lore raw

PATCH v4 27/36 ARM: imx8m: fix imx_eqos_txclk_set_rate() type mismatch for LTO

In reply to Marek Behún

When building imx8mp_evk_defconfig with LTO, the compiler complains about type mismatch of function imx_eqos_txclk_set_rate() in file
drivers/net/dwc_eth_qos.c:845:12
which contains a weak definition of this function, vs file
arch/arm/mach-imx/imx8m/clock_imx8mm.c
which contains an implementation.

Change the type of this function in the implementation to fix this.

---
 arch/arm/mach-imx/imx8m/clock_imx8mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-imx/imx8m/clock_imx8mm.c +1 -1
index 029d06f27f..65d476e037 100644
@@ -846,7 +846,7 @@ int set_clk_eqos(enum enet_freq type)
 	return 0;
 }
 
-int imx_eqos_txclk_set_rate(u32 rate)
+int imx_eqos_txclk_set_rate(ulong rate)
 {
 	u32 val;
 	u32 eqos_post_div;
Signature · 1 line
2.26.3
#68 lore raw

Re: [PATCH u-boot v4 27/36] ARM: imx8m: fix imx_eqos_txclk_set_rate() type mismatch for LTO

Quoted 11 lines · Marek Behún

When building imx8mp_evk_defconfig with LTO, the compiler complains about type mismatch of function imx_eqos_txclk_set_rate() in file
drivers/net/dwc_eth_qos.c:845:12
which contains a weak definition of this function, vs file
arch/arm/mach-imx/imx8m/clock_imx8mm.c
which contains an implementation.

Change the type of this function in the implementation to fix this.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#69 lore raw

PATCH v4 28/36 ARM: fix LTO for seaboard

In reply to Marek Behún

When seaboard_defconfig is compiled with LTO, the compiler complains about some instructions not being supported in ARM mode.

This is caused by arch/arm/mach-tegra/tegra20/warmboot_avp.c having different CFLAGS declared in Makefile. This file needs to be compiled without LTO.

Fix this by removing -flto for this file.

---
 arch/arm/mach-tegra/tegra20/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-tegra/tegra20/Makefile +1 -0
index faaf30d068..bb17c90cca 100644
@@ -10,6 +10,7 @@ endif
 # flags for any startup files it might use.
 CFLAGS_warmboot_avp.o = -march=armv4t -U__LINUX_ARM_ARCH__ \
 	-D__LINUX_ARM_ARCH__=4
+CFLAGS_REMOVE_warmboot_avp.o := $(LTO_CFLAGS)
 
 obj-y	+= clock.o funcmux.o pinmux.o
 obj-$(CONFIG_TEGRA_LP0) += warmboot.o crypto.o warmboot_avp.o
Signature · 1 line
2.26.3
#70 lore raw

PATCH v4 28/36 ARM: fix LTO for seaboard

Quoted 8 lines · Marek Beh?n

When seaboard_defconfig is compiled with LTO, the compiler complains about some instructions not being supported in ARM mode.

This is caused by arch/arm/mach-tegra/tegra20/warmboot_avp.c having different CFLAGS declared in Makefile. This file needs to be compiled without LTO.

Quoted 7 lines

Fix this by removing -flto for this file.

---
 arch/arm/mach-tegra/tegra20/Makefile | 1 +
 1 file changed, 1 insertion(+)
#71 lore raw

Re: [PATCH u-boot v4 28/36] ARM: fix LTO for seaboard

In reply to Marek Behún
Quoted 11 lines · Marek Behún

When seaboard_defconfig is compiled with LTO, the compiler complains about some instructions not being supported in ARM mode.

This is caused by arch/arm/mach-tegra/tegra20/warmboot_avp.c having different CFLAGS declared in Makefile. This file needs to be compiled without LTO.

Fix this by removing -flto for this file.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#72 lore raw

PATCH v4 29/36 ARM: fix LTO for rockchip and samsung

In reply to Marek Behún

When building with LTO, the compiler complains about type mismatch of function usb_gadget_handle_interrupts(). This function is defined without parameters in files
arch/arm/mach-rockchip/board.c board/samsung/common/exynos5-dt.c
but it should have one parameter, int index.

Fix this.

---
 arch/arm/mach-rockchip/board.c    | 2 +-
 board/samsung/common/exynos5-dt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-rockchip/board.c +1 -1
index c386b52987..5304eb055c 100644
@@ -139,7 +139,7 @@ static struct dwc3_device dwc3_device_data = {
 	.hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW,
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	dwc3_uboot_handle_interrupt(0);
 	return 0;
board/samsung/common/exynos5-dt.c +1 -1
index 4463cdcb87..1318ea716a 100644
@@ -126,7 +126,7 @@ static struct dwc3_device dwc3_device_data = {
 	.index = 0,
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	dwc3_uboot_handle_interrupt(0);
 	return 0;
Signature · 1 line
2.26.3
Reviewed-by on v4 29/36
#73 lore raw

Re: [PATCH u-boot v4 29/36] ARM: fix LTO for rockchip and samsung

Quoted 11 lines · Marek Behún

When building with LTO, the compiler complains about type mismatch of function usb_gadget_handle_interrupts(). This function is defined without parameters in files
arch/arm/mach-rockchip/board.c board/samsung/common/exynos5-dt.c
but it should have one parameter, int index.

Fix this.

Thanks,

- Kever

Quoted 31 lines
---
  arch/arm/mach-rockchip/board.c    | 2 +-
  board/samsung/common/exynos5-dt.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-rockchip/board.c +1 -1
index c386b52987..5304eb055c 100644
@@ -139,7 +139,7 @@ static struct dwc3_device dwc3_device_data = {
  	.hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW,
  };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
  {
  	dwc3_uboot_handle_interrupt(0);
  	return 0;
board/samsung/common/exynos5-dt.c +1 -1
index 4463cdcb87..1318ea716a 100644
@@ -126,7 +126,7 @@ static struct dwc3_device dwc3_device_data = {
  	.index = 0,
  };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
  {
  	dwc3_uboot_handle_interrupt(0);
  	return 0;
#74 lore raw

Re: [PATCH u-boot v4 29/36] ARM: fix LTO for rockchip and samsung

In reply to Marek Behún
Quoted 7 lines · Marek Behún

When building with LTO, the compiler complains about type mismatch of function usb_gadget_handle_interrupts(). This function is defined without parameters in files
arch/arm/mach-rockchip/board.c board/samsung/common/exynos5-dt.c
but it should have one parameter, int index.

Quoted 5 lines

Fix this.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#75 lore raw

PATCH v4 30/36 ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)

In reply to Marek Behún

Adam Ford says that DM3730 needs board.c compiled without LTO flags.

---
 arch/arm/mach-omap2/omap3/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-omap2/omap3/Makefile +1 -0
index 91ed8ebc9f..151bdf6ebc 100644
@@ -9,6 +9,7 @@ CFLAGS_clock.o += -marm
 obj-y	:= lowlevel_init.o
 
 obj-y	+= board.o
+CFLAGS_REMOVE_board.o := $(LTO_CFLAGS)
 obj-y	+= boot.o
 obj-y	+= clock.o
 obj-y	+= sys_info.o
Signature · 1 line
2.26.3
#77 lore raw

PATCH v4 31/36 armv8: SPL: discard relocation information

In reply to Marek Behún

For some reason when building SPL for ARMv8 with LTO, the relocation information is not discarded.

Discard it explicitly in the linker script.

This fixes LTO build for imx8mm_venice_defconfig.

---
 arch/arm/cpu/armv8/u-boot-spl.lds | 1 +
 1 file changed, 1 insertion(+)
arch/arm/cpu/armv8/u-boot-spl.lds +1 -0
index 0e67ab09d7..9edb662b09 100644
@@ -77,6 +77,7 @@ SECTIONS
 		KEEP(*(.__bss_end));
 	} >.sdram
 
+	/DISCARD/ : { *(.rela*) }
 	/DISCARD/ : { *(.dynsym) }
 	/DISCARD/ : { *(.dynstr*) }
 	/DISCARD/ : { *(.dynamic*) }
Signature · 1 line
2.26.3
#78 lore raw

PATCH v4 31/36 armv8: SPL: discard relocation information

Quoted 4 lines · Marek Beh?n

For some reason when building SPL for ARMv8 with LTO, the relocation information is not discarded.

Quoted 8 lines

Discard it explicitly in the linker script.

This fixes LTO build for imx8mm_venice_defconfig.

---
 arch/arm/cpu/armv8/u-boot-spl.lds | 1 +
 1 file changed, 1 insertion(+)
#79 lore raw

Re: [PATCH u-boot v4 31/36] armv8: SPL: discard relocation information

In reply to Marek Behún
Quoted 9 lines · Marek Behún

For some reason when building SPL for ARMv8 with LTO, the relocation information is not discarded.

Discard it explicitly in the linker script.

This fixes LTO build for imx8mm_venice_defconfig.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#80 lore raw

PATCH v4 32/36 ata: ahci: fix ahci_link_up() type mismatch for LTO

In reply to Marek Behún

When building highbank_defconfig with LTO, the compiler complains about type mismatch of function ahci_link_up().

The third parameter of this function is of type u8 in drivers/ata/ahci.c, but of type int in board/highbank/ahci.c.

There is no reason in using u8, and the code using this function actually passes an int variable into the function (so it is implicitly converted to u8).

Change the type of this parameter to int in drivers/ata/ahci.c.

---
 drivers/ata/ahci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/ahci.c +1 -1
index 57c4e153ba..d4047c04f5 100644
@@ -110,7 +110,7 @@ static int waiting_for_cmd_completed(void __iomem *offset,
 	return (i < timeout_msec) ? 0 : -1;
 }
 
-int __weak ahci_link_up(struct ahci_uc_priv *uc_priv, u8 port)
+int __weak ahci_link_up(struct ahci_uc_priv *uc_priv, int port)
 {
 	u32 tmp;
 	int j = 0;
Signature · 1 line
2.26.3
#81 lore raw

Re: [PATCH u-boot v4 32/36] ata: ahci: fix ahci_link_up() type mismatch for LTO

Quoted 6 lines · Marek Behún

When building highbank_defconfig with LTO, the compiler complains about type mismatch of function ahci_link_up().

The third parameter of this function is of type u8 in drivers/ata/ahci.c, but of type int in board/highbank/ahci.c.

Quoted 8 lines

There is no reason in using u8, and the code using this function actually passes an int variable into the function (so it is implicitly converted to u8).

Change the type of this parameter to int in drivers/ata/ahci.c.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#82 lore raw

PATCH v4 33/36 ARM: make LTO available

In reply to Marek Behún

Make LTO available for ARM architecture.

---
 arch/Kconfig          | 1 +
 arch/arm/lib/Makefile | 2 ++
 2 files changed, 3 insertions(+)
arch/Kconfig +1 -0
index 8fd39e36b4..49813a4c9b 100644
@@ -33,6 +33,7 @@ config ARC
 
 config ARM
 	bool "ARM architecture"
+	select ARCH_SUPPORTS_LTO
 	select CREATE_ARCH_SYMLINK
 	select HAVE_PRIVATE_LIBGCC if !ARM64
 	select SUPPORT_OF_CONTROL
arch/arm/lib/Makefile +2 -0
index 61bef1d5af..7f66332715 100644
@@ -45,6 +45,8 @@ obj-$(CONFIG_SEMIHOSTING) += semihosting.o
 
 obj-y	+= bdinfo.o
 obj-y	+= sections.o
+CFLAGS_REMOVE_sections.o := $(LTO_CFLAGS)
+
 obj-y	+= stack.o
 ifdef CONFIG_CPU_V7M
 obj-y	+= interrupts_m.o
Signature · 1 line
2.26.3
#85 lore raw

PATCH v4 34/36 ARM: don't use -ffunction-sections/-fdata-sections with LTO build

In reply to Marek Behún

When building with LTO, using -ffunction-sections/-fdata-sections is not useful anymore.

---
 arch/arm/config.mk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/config.mk +6 -2
index e79f0104b9..f556ee3329 100644
@@ -16,8 +16,12 @@ CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections \
 CFLAGS_EFI := -fpic -fshort-wchar
 
 LDFLAGS_FINAL += --gc-sections
-PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections \
-		     -fno-common -ffixed-r9
+
+ifndef CONFIG_LTO
+PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+endif
+
+PLATFORM_RELFLAGS += -fno-common -ffixed-r9
 PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \
       $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
 
Signature · 1 line
2.26.3
#88 lore raw

PATCH v4 35/36 ARM: don't use --gc-sections with LTO when using private libgcc

In reply to Marek Behún

When using LTO, we can throw away the --gc-sections flag, but only if using private libgcc.

When using system's libgcc, --gc-sections is still needed, otherwise linking will fail due to undefined references to libc's symbols.

---
 arch/arm/config.mk | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/config.mk +2 -0
index f556ee3329..16c63e1266 100644
@@ -15,7 +15,9 @@ CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections \
 		  -fstack-protector-strong
 CFLAGS_EFI := -fpic -fshort-wchar
 
+ifneq ($(CONFIG_LTO)$(CONFIG_USE_PRIVATE_LIBGCC),yy)
 LDFLAGS_FINAL += --gc-sections
+endif
 
 ifndef CONFIG_LTO
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
Signature · 1 line
2.26.3
#89 lore raw

PATCH v4 35/36 ARM: don't use --gc-sections with LTO when using private libgcc

Quoted 11 lines · Marek Beh?n

When using LTO, we can throw away the --gc-sections flag, but only if using private libgcc.

When using system's libgcc, --gc-sections is still needed, otherwise linking will fail due to undefined references to libc's symbols.

---
 arch/arm/config.mk | 2 ++
 1 file changed, 2 insertions(+)
#90 lore raw

Re: [PATCH u-boot v4 35/36] ARM: don't use --gc-sections with LTO when using private libgcc

In reply to Marek Behún
Quoted 8 lines · Marek Behún

When using LTO, we can throw away the --gc-sections flag, but only if using private libgcc.

When using system's libgcc, --gc-sections is still needed, otherwise linking will fail due to undefined references to libc's symbols.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#91 lore raw

PATCH v4 36/36 ARM: enable LTO for some boards

In reply to Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

---
 configs/am3517_evm_defconfig          | 1 +
 configs/da850evm_defconfig            | 1 +
 configs/da850evm_direct_nor_defconfig | 1 +
 configs/da850evm_nand_defconfig       | 1 +
 configs/imx6q_logic_defconfig         | 1 +
 configs/imx8mm_beacon_defconfig       | 1 +
 configs/imx8mm_venice_defconfig       | 1 +
 configs/imx8mn_beacon_2g_defconfig    | 1 +
 configs/imx8mn_beacon_defconfig       | 1 +
 configs/nokia_rx51_defconfig          | 1 +
 configs/omap3_logic_defconfig         | 1 +
 configs/r8a774a1_beacon_defconfig     | 1 +
 configs/r8a774b1_beacon_defconfig     | 1 +
 configs/r8a774e1_beacon_defconfig     | 1 +
 14 files changed, 14 insertions(+)
configs/am3517_evm_defconfig +1 -0
index bae0e0af35..d61eec94a4 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SPL_USE_ARCH_MEMCPY is not set
 # CONFIG_SPL_USE_ARCH_MEMSET is not set
configs/da850evm_defconfig +1 -0
index cbb7bcf0b6..8b93f33552 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
configs/da850evm_direct_nor_defconfig +1 -0
index 4ea41ca005..2610a82f7a 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_CPU_INIT=y
 CONFIG_ARCH_DAVINCI=y
configs/da850evm_nand_defconfig +1 -0
index 9a86e57334..b347c01283 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
configs/imx6q_logic_defconfig +1 -0
index 36dc24d080..0f8aea6983 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_SYS_TEXT_BASE=0x17800000
configs/imx8mm_beacon_defconfig +1 -0
index 6b26daee5c..6b2dc24b85 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mm_venice_defconfig +1 -0
index d8228a4b9f..4b0e5d04d8 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mn_beacon_2g_defconfig +1 -0
index c60bebc3ed..cc4c56c422 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mn_beacon_defconfig +1 -0
index db904d7735..66fe9d34c0 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/nokia_rx51_defconfig +1 -0
index f79613260f..802568aea7 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SYS_THUMB_BUILD is not set
 CONFIG_ARCH_OMAP2PLUS=y
configs/omap3_logic_defconfig +1 -0
index 12483ffee2..7b17b28e6d 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SPL_USE_ARCH_MEMCPY is not set
 # CONFIG_SPL_USE_ARCH_MEMSET is not set
configs/r8a774a1_beacon_defconfig +1 -0
index 58d3f9f019..8e65654318 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
configs/r8a774b1_beacon_defconfig +1 -0
index c0d2d1bf53..37584db185 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
configs/r8a774e1_beacon_defconfig +1 -0
index 800c7b8c79..8a65e86380 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
Signature · 1 line
2.26.3
#92 lore raw

PATCH v4 36/36 ARM: enable LTO for some boards

Quoted 8 lines · Marek Beh?n

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

adam

Quoted 146 lines
---
 configs/am3517_evm_defconfig          | 1 +
 configs/da850evm_defconfig            | 1 +
 configs/da850evm_direct_nor_defconfig | 1 +
 configs/da850evm_nand_defconfig       | 1 +
 configs/imx6q_logic_defconfig         | 1 +
 configs/imx8mm_beacon_defconfig       | 1 +
 configs/imx8mm_venice_defconfig       | 1 +
 configs/imx8mn_beacon_2g_defconfig    | 1 +
 configs/imx8mn_beacon_defconfig       | 1 +
 configs/nokia_rx51_defconfig          | 1 +
 configs/omap3_logic_defconfig         | 1 +
 configs/r8a774a1_beacon_defconfig     | 1 +
 configs/r8a774b1_beacon_defconfig     | 1 +
 configs/r8a774e1_beacon_defconfig     | 1 +
 14 files changed, 14 insertions(+)
configs/am3517_evm_defconfig +1 -0
index bae0e0af35..d61eec94a4 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SPL_USE_ARCH_MEMCPY is not set
 # CONFIG_SPL_USE_ARCH_MEMSET is not set
configs/da850evm_defconfig +1 -0
index cbb7bcf0b6..8b93f33552 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
configs/da850evm_direct_nor_defconfig +1 -0
index 4ea41ca005..2610a82f7a 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_CPU_INIT=y
 CONFIG_ARCH_DAVINCI=y
configs/da850evm_nand_defconfig +1 -0
index 9a86e57334..b347c01283 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
configs/imx6q_logic_defconfig +1 -0
index 36dc24d080..0f8aea6983 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_SYS_TEXT_BASE=0x17800000
configs/imx8mm_beacon_defconfig +1 -0
index 6b26daee5c..6b2dc24b85 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mm_venice_defconfig +1 -0
index d8228a4b9f..4b0e5d04d8 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mn_beacon_2g_defconfig +1 -0
index c60bebc3ed..cc4c56c422 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/imx8mn_beacon_defconfig +1 -0
index db904d7735..66fe9d34c0 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x40200000
configs/nokia_rx51_defconfig +1 -0
index f79613260f..802568aea7 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SYS_THUMB_BUILD is not set
 CONFIG_ARCH_OMAP2PLUS=y
configs/omap3_logic_defconfig +1 -0
index 12483ffee2..7b17b28e6d 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SPL_USE_ARCH_MEMCPY is not set
 # CONFIG_SPL_USE_ARCH_MEMSET is not set
configs/r8a774a1_beacon_defconfig +1 -0
index 58d3f9f019..8e65654318 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
configs/r8a774b1_beacon_defconfig +1 -0
index c0d2d1bf53..37584db185 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
configs/r8a774e1_beacon_defconfig +1 -1
index 800c7b8c79..8a65e86380 100644
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_RMOBILE=y
 CONFIG_SYS_TEXT_BASE=0x50000000
--

2.26.3

#93 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 19 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Signature · 1 line
Tom
#94 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Marek

#95 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 34 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Signature · 1 line
Tom
#96 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 35 lines · Tom Rini
Quoted 34 lines · Marek Behún
Quoted 30 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 7 lines
Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

Signature · 1 line
Tom
#97 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 41 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 40 lines · Tom Rini
Quoted 38 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Quoted 7 lines
Quoted 2 lines

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

#98 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 47 lines · Marek Behun
Quoted 44 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 42 lines · Tom Rini
Quoted 34 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Quoted 7 lines
Quoted 3 lines

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

The first problem I saw was a bunch of warnings building pylibfdt. I see now those two problems, and yeah, OK, gotta figure out something there next.

Signature · 1 line
Tom
#99 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

In reply to Marek Behun
Quoted 47 lines · Marek Behun
Quoted 44 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 42 lines · Tom Rini
Quoted 34 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Quoted 8 lines
Quoted 4 lines

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

I don't have a full answer about the stack protector test just yet, but it almost seems like it's too simple and maybe something is happening with it being optimized to not a problem?

Signature · 1 line
Tom
#100 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 53 lines · Tom Rini
Quoted 52 lines · Marek Behun
Quoted 48 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 35 lines · Tom Rini
Quoted 34 lines · Marek Behún
Quoted 30 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 7 lines
Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

Quoted 7 lines
Quoted 3 lines

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

I don't have a full answer about the stack protector test just yet, but it almost seems like it's too simple and maybe something is happening with it being optimized to not a problem?

Yeah, so clang with LTO optimizes away that memset call, and so the test passes. I'll do something to make sure the array is used so it won't be optimized away.

Signature · 1 line
Tom
#101 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 58 lines · On Mon, 24 May 2021 13:44:38 -0400 Tom Rini <[email protected]> wrote:
Quoted 57 lines · Tom Rini
Quoted 55 lines · Marek Behun
Quoted 41 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 40 lines · Tom Rini
Quoted 38 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Quoted 7 lines
Quoted 2 lines

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

Quoted 8 lines
Quoted 3 lines

I don't have a full answer about the stack protector test just yet, but it almost seems like it's too simple and maybe something is happening with it being optimized to not a problem?

Yeah, so clang with LTO optimizes away that memset call, and so the test passes. I'll do something to make sure the array is used so it won't be optimized away.

I am unable to make the compiler to protect the stack of that function even with GCC on my local machine. It seems that at least on my gentoo with gcc-10.2, when compiling with -ffreestanding, the call to __stack_chk_fail is not made at all.

I even started reading sources of gcc on thursday because of this, but it didn't lead anywhere...

When you compile sandbox_defconfig with gcc, does the test pass on your local machine?

Marek

#102 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

Quoted 75 lines · Marek Behun
Quoted 58 lines · On Mon, 24 May 2021 13:44:38 -0400 Tom Rini <[email protected]> wrote:
Quoted 57 lines · Tom Rini
Quoted 55 lines · Marek Behun
Quoted 41 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 40 lines · Tom Rini
Quoted 38 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Quoted 7 lines
Quoted 2 lines

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test
- one with stack protector test

Quoted 8 lines
Quoted 3 lines

I don't have a full answer about the stack protector test just yet, but it almost seems like it's too simple and maybe something is happening with it being optimized to not a problem?

Yeah, so clang with LTO optimizes away that memset call, and so the test passes. I'll do something to make sure the array is used so it won't be optimized away.

I am unable to make the compiler to protect the stack of that function even with GCC on my local machine. It seems that at least on my gentoo with gcc-10.2, when compiling with -ffreestanding, the call to __stack_chk_fail is not made at all.

Quoted 5 lines

I even started reading sources of gcc on thursday because of this, but it didn't lead anywhere...

When you compile sandbox_defconfig with gcc, does the test pass on your local machine?

It passes here with gcc-7.5 as well as gcc-9.2.0 in CI. When I moved to a gcc-11 snapshot in CI, it was also passing there before, so I'm not sure what's going on in your setup. But as part of coming up with the patch I sent to fix the test, I ran it manually and saw the expected failure message.

Signature · 1 line
Tom
#103 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

In reply to Marek Behun
Quoted 47 lines · Marek Behun
Quoted 44 lines · On Mon, 24 May 2021 11:40:53 -0400 Tom Rini <[email protected]> wrote:
Quoted 42 lines · Tom Rini
Quoted 34 lines · Marek Behún
Quoted 24 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

Quoted 6 lines

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

Quoted 4 lines

Tom, are there some other issues aside from the one failing CI scenario (sandbox_clang)? Would you be willing to merge this if I resolved that one fail by disabling LTO for that scenario (until I resolve it)? It would help me not having to maintain all 30+ patches...

Yeah, CI needs to keep passing, so if we need to disable sandbox+clang+lto for now, OK.

Quoted 7 lines
Quoted 4 lines

Ah, I see the problem now. I've worked out a fix after looking at the Linux kernel a bit and I'll post something for us and upstream dtc as well.

What do you mean? The problem is in dtc? I see 2 problems:
- one with DM test

So, this looks like another case of the optimizer being so good it causes the test to fail. Happily in this case, a patch Simon made to fix coverity complaining about using srand/rand here:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
also gets the test passing with LTO.

Signature · 1 line
Tom
#104 lore raw

Re: [PATCH u-boot v4 36/36] ARM: enable LTO for some boards

In reply to Tom Rini
Quoted 31 lines · On Fri, 21 May 2021 10:11:47 -0400 Tom Rini <[email protected]> wrote:
Quoted 20 lines · Adam Ford
Quoted 8 lines · Marek Behún

Enable LTO for some boards that were tested by people on U-Boot Mailing List.

Since the imx8mm beacon boards and the imx8mm venice board both show promise, does it make sense to 'imply' the LTO for anything enabling imx8mm?
Same thing for the various omap3 boards, and potentially the renesas RZ/G2 boards. I know Tom went through to remove a bunch of boards that were never converted to DM. Most of the boards remaining boards have minimal board files and most of code is common to other boards in the same platforms.

Quoted 2 lines

I have an l138_lcdk that I can use to test which I expect to be similar to the da850evm.

As much as I am eager to move everything, quickly, over to LTO by default, I think the problems that we've seen thus far show it's best to really make it an explicit enable per board at least for the first release or two. Once we've hopefully gotten more boards tested and enabled we can see what makes sense for defaults, give a release worth of heads up, and then go.

#106 lore raw
In reply to Marek Behún

Hi Marek,

Quoted 209 lines · Marek Behún

Hello,

this is version 4 of patches adding support for LTO to U-Boot.

This series is being tested by Github/Azure CI at
https://github.com/u-boot/u-boot/pull/57

There is a problem with sandbox_clang test scenario, which I was unable to resolve yet, or even determine correctly whether the problem is with my patches or was there before. (One of the problems is with testing stack protector test_stackprotector.py, but for some reason I could not make this work even with GCC on my local machine.)
Nevertheless I am sending these patches now so that at least you can review them. In the meantime I will try to resolve the issue with sandbox_clang test scenario.

Changes since v3:
- for some reason the mvneta driver does not work correctly when U-Boot is compiled with LTO. I have not debugged this issue yet, so for now I have removed Turris Omnia and Turris MOX from devices with enabled LTO
- linker list entry symbols are now forced to emit by using the __ADDRESSABLE macro in a generated C file (keep-syms-lto.c). Previously this was done in the ll_entry_declare() macro, but this was not flexible, since, for example, trying to declare an entry as extern could not work that way. This came to attention now after Simon's patches for dtoc were merged, and ll_entry_declare() is being used with the extern keyword in include/generated/dt-decl.h
- when compiling LTO with Clang, use llvm-ar and llvm-nm for AR and NM
- several patches rebased
- removed patch "api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA"
- updated patch converting __attribute__((section(...))) to __section(...)

Changes sinve v2:
- now linking with --build-id=none in order to avoid link failures with some toolchains (thanks Herald Seiler)
- we don't use -flto=jobserver anymore, since it causes build errors for some people. Instead we link with -flto=NPROC
- removed LTO exception for arch/arm/mach-omap2/omap3/clock.o, Adam Ford says it is not needed
- added some Reviewed-by tags

Changes since v1:
- remove patches applied into u-boot-marvell
- added Reviewed-by tags
- addressed some issues discovered by Bin Meng, Marek Vasut, Heinrich Schuchardt
- added more ARM boards (thanks to Adam Ford, Tim Harvey and Bin Meng)
- removed --gc-sections for ARM if internal libgcc is used
- remove -fwhole-program in final LTO LDFLAGS
- declared all 4 functions (memcpy, memset, memcmp, memmove) __used, (these are mentioned in GCC man page for option -nodefaultlibs that the compiler may generate; this seems to be a bug in GCC that linking fails with LTO even if these functions are present, because the symbols can be renamed on some targets by optimization)

Marek

Marek Behún (36):
regmap: fix a serious pointer casting bug
checkpatch: require quotes around section name in the __section()
macro
treewide: Convert macro and uses of __section(foo) to __section("foo") compiler.h: align the __ADDRESSABLE macro with Linux' version test/py: improve regular expression for ut subtest symbol matcher
string: make memcpy(), memset(), memcmp() and memmove() visible for
LTO
efi_loader: fix warning when linking with LTO
efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data
efi_loader: add macro for const EFI runtime data
efi_selftest: compiler flags for efi_selftest_miniapp_exception.o
lib: crc32: put the crc_table variable into efi_runtime_rodata section Makefile, Makefile.spl: cosmetic change
build: use thin archives instead of incremental linking
build: support building with Link Time Optimizations
build: link with --build-id=none
sandbox: errno: avoid conflict with libc's errno
sandbox: use sections instead of symbols for getopt array boundaries
sandbox: make LTO available
sandbox: enable LTO by default
ARM: global_data: make set_gd() work for armv5 and armv6
ARM: make gd a function call for LTO and set via set_gd()
ARM: fix LTO build for some thumb-interwork cases
ARM: fix LTO for imx28_xea
ARM: fix LTO for apf27
ARM: fix LTO for keystone
ARM: kona: fix clk_bsc_enable() type mismatch for LTO
ARM: imx8m: fix imx_eqos_txclk_set_rate() type mismatch for LTO
ARM: fix LTO for seaboard
ARM: fix LTO for rockchip and samsung
ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)
armv8: SPL: discard relocation information
ata: ahci: fix ahci_link_up() type mismatch for LTO
ARM: make LTO available
ARM: don't use -ffunction-sections/-fdata-sections with LTO build
ARM: don't use --gc-sections with LTO when using private libgcc
ARM: enable LTO for some boards

  Kbuild                                     |  2 +
  Kconfig                                    | 24 +++++++
  Makefile                                   | 81 ++++++++++++++++++++--
  arch/Kconfig                               |  3 +
  arch/arm/config.mk                         | 10 ++-
  arch/arm/cpu/arm926ejs/Makefile            |  2 +
  arch/arm/cpu/arm926ejs/mxs/mxs.c           |  2 +-
  arch/arm/cpu/arm926ejs/mxs/spl_boot.c      |  4 +-
  arch/arm/cpu/arm926ejs/spear/spl.c         |  2 +-
  arch/arm/cpu/armv7/kona-common/clk-stubs.c |  2 +-
  arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c  |  2 +-
  arch/arm/cpu/armv8/spl_data.c              |  4 +-
  arch/arm/cpu/armv8/u-boot-spl.lds          |  1 +
  arch/arm/include/asm/global_data.h         |  6 +-
  arch/arm/include/asm/secure.h              |  6 +-
  arch/arm/include/asm/setup.h               |  2 +-
  arch/arm/lib/Makefile                      |  3 +
  arch/arm/lib/sections.c                    | 31 +++++----
  arch/arm/lib/spl.c                         |  2 +-
  arch/arm/mach-at91/spl.c                   |  2 +-
  arch/arm/mach-exynos/spl_boot.c            |  2 +-
  arch/arm/mach-imx/imx8m/clock_imx8mm.c     |  2 +-
  arch/arm/mach-imx/imx8m/soc.c              |  2 +-
  arch/arm/mach-imx/spl_imx_romapi.c         | 16 ++---
  arch/arm/mach-k3/am642_init.c              |  2 +-
  arch/arm/mach-k3/am6_init.c                |  2 +-
  arch/arm/mach-k3/j721e_init.c              |  4 +-
  arch/arm/mach-keystone/Makefile            |  1 +
  arch/arm/mach-mvebu/mbus.c                 |  4 +-
  arch/arm/mach-mvebu/timer.c                |  2 +-
  arch/arm/mach-nexell/clock.c               |  6 +-
  arch/arm/mach-nexell/timer.c               |  6 +-
  arch/arm/mach-omap2/omap3/Makefile         |  1 +
  arch/arm/mach-rockchip/board.c             |  2 +-
  arch/arm/mach-socfpga/spl_a10.c            |  2 +-
  arch/arm/mach-sunxi/board.c                |  2 +-
  arch/arm/mach-tegra/board.c                |  2 +-
  arch/arm/mach-tegra/cboot.c                |  8 +--
  arch/arm/mach-tegra/tegra20/Makefile       |  1 +
  arch/mips/mach-jz47xx/jz4780/jz4780.c      |  2 +-
  arch/nds32/include/asm/setup.h             |  6 +-
  arch/powerpc/include/asm/cache.h           |  4 +-
  arch/riscv/cpu/cpu.c                       |  4 +-
  arch/sandbox/config.mk                     | 14 +++-
  arch/sandbox/cpu/os.c                      |  3 +-
  arch/sandbox/cpu/start.c                   |  3 +-
  arch/sandbox/cpu/u-boot-spl.lds            |  8 ++-
  arch/sandbox/cpu/u-boot.lds                |  8 ++-
  arch/sandbox/include/asm/getopt.h          |  2 +-
  arch/sandbox/include/asm/sections.h        | 21 +++++-
  arch/sandbox/lib/sections.c                |  9 +--
  arch/x86/cpu/coreboot/timestamp.c          |  2 +-
  arch/x86/lib/coreboot/cb_sysinfo.c         |  2 +-
  arch/x86/lib/sections.c                    |  9 +--
  arch/xtensa/cpu/cpu.c                      |  2 +-
  board/bosch/shc/board.c                    |  2 +-
  board/broadcom/bcmstb/bcmstb.c             |  2 +-
  board/samsung/arndale/arndale_spl.c        |  2 +-
  board/samsung/common/exynos5-dt.c          |  2 +-
  board/samsung/smdk5250/smdk5250_spl.c      |  2 +-
  board/samsung/smdk5420/smdk5420_spl.c      |  2 +-
  board/siemens/draco/board.c                |  2 +-
  board/xilinx/common/fru_ops.c              |  2 +-
  configs/am3517_evm_defconfig               |  1 +
  configs/da850evm_defconfig                 |  1 +
  configs/da850evm_direct_nor_defconfig      |  1 +
  configs/da850evm_nand_defconfig            |  1 +
  configs/imx6q_logic_defconfig              |  1 +
  configs/imx8mm_beacon_defconfig            |  1 +
  configs/imx8mm_venice_defconfig            |  1 +
  configs/imx8mn_beacon_2g_defconfig         |  1 +
  configs/imx8mn_beacon_defconfig            |  1 +
  configs/nokia_rx51_defconfig               |  1 +
  configs/omap3_logic_defconfig              |  1 +
  configs/r8a774a1_beacon_defconfig          |  1 +
  configs/r8a774b1_beacon_defconfig          |  1 +
  configs/r8a774e1_beacon_defconfig          |  1 +
  drivers/ata/ahci.c                         |  2 +-
  drivers/bios_emulator/biosemu.c            |  4 +-
  drivers/clk/kendryte/clk.c                 |  4 +-
  drivers/core/regmap.c                      | 59 +++++++++++++++-
  drivers/firmware/psci.c                    |  2 +-
  drivers/mtd/nand/raw/mxc_nand_spl.c        |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx5.c         |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx7.c         |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx8m.c        |  2 +-
  drivers/power/pmic/pmic_tps62362.c         |  2 +-
  drivers/power/pmic/pmic_tps65217.c         |  2 +-
  drivers/power/pmic/pmic_tps65218.c         |  2 +-
  drivers/power/pmic/pmic_tps65910.c         |  2 +-
  drivers/serial/serial_pl01x.c              |  4 +-
  include/efi_loader.h                       | 54 +++++++++++++--
  include/errno.h                            |  8 ++-
  include/linker_lists.h                     | 24 +++----
  include/linux/compiler.h                   | 10 +--
  include/linux/compiler_attributes.h        |  2 +-
  lib/crc32.c                                |  3 +-
  lib/efi_selftest/Makefile                  |  2 +
  lib/errno.c                                |  4 +-
  lib/string.c                               |  9 +--
  lib/trace.c                                |  4 +-
  scripts/Makefile.build                     | 16 ++---
  scripts/Makefile.lib                       |  3 +
  scripts/Makefile.spl                       | 63 +++++++++++++++--
  scripts/checkpatch.pl                      |  2 +-
  scripts/gen_ll_addressable_symbols.sh      | 12 ++++
  test/py/conftest.py                        |  2 +-
  107 files changed, 513 insertions(+), 183 deletions(-)
Quoted 2 lines

create mode 100755 scripts/gen_ll_addressable_symbols.sh

I am trying to activate CONFIG_LTO for STMicroelectronics stm32mp15 platform

(stm32mp15_trusted_defconfig and stm32mp15_basic_defconfig).

The config stm32mp15_basic_defconfig, with SPL supported failed to boot

with gcc-arm-9.2-2019.12.

because a weak function is not correctly handle between

1/ ./arch/arm/lib/cache-cp15.c: 96

    __weak void dram_bank_mmu_setup(int bank);

2/ the stm32mp implementation in

   arch/arm/mach-stm32mp/cpu.c:62

   void dram_bank_mmu_setup(int bank)

=> The used function in SPL is the cache library, not the stm32mp function.

      and SPL boot it OK when I remove the function in the cache library...

And the issue is also solved with I use a more recent version

gcc-arm-10.2-2020.11 on my PC.

Do you see the same kind of issue for old version of gcc ?

Do you think CONFIG_LTO require a more recent version of gcc that

the minimal version required by U-Boot  because I don't see this information

in the serie?

Regards

Patrick

#107 lore raw
Quoted 232 lines · Patrick DELAUNAY

Hi Marek,

Quoted 209 lines · Marek Behún

Hello,

this is version 4 of patches adding support for LTO to U-Boot.

This series is being tested by Github/Azure CI at
https://github.com/u-boot/u-boot/pull/57

There is a problem with sandbox_clang test scenario, which I was unable to resolve yet, or even determine correctly whether the problem is with my patches or was there before. (One of the problems is with testing stack protector test_stackprotector.py, but for some reason I could not make this work even with GCC on my local machine.)
Nevertheless I am sending these patches now so that at least you can review them. In the meantime I will try to resolve the issue with sandbox_clang test scenario.

Changes since v3:
- for some reason the mvneta driver does not work correctly when U-Boot is compiled with LTO. I have not debugged this issue yet, so for now I have removed Turris Omnia and Turris MOX from devices with enabled LTO
- linker list entry symbols are now forced to emit by using the __ADDRESSABLE macro in a generated C file (keep-syms-lto.c). Previously this was done in the ll_entry_declare() macro, but this was not flexible, since, for example, trying to declare an entry as extern could not work that way. This came to attention now after Simon's patches for dtoc were merged, and ll_entry_declare() is being used with the extern keyword in include/generated/dt-decl.h
- when compiling LTO with Clang, use llvm-ar and llvm-nm for AR and NM
- several patches rebased
- removed patch "api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA"
- updated patch converting __attribute__((section(...))) to __section(...)

Changes sinve v2:
- now linking with --build-id=none in order to avoid link failures with some toolchains (thanks Herald Seiler)
- we don't use -flto=jobserver anymore, since it causes build errors for some people. Instead we link with -flto=NPROC
- removed LTO exception for arch/arm/mach-omap2/omap3/clock.o, Adam Ford says it is not needed
- added some Reviewed-by tags

Changes since v1:
- remove patches applied into u-boot-marvell
- added Reviewed-by tags
- addressed some issues discovered by Bin Meng, Marek Vasut, Heinrich Schuchardt
- added more ARM boards (thanks to Adam Ford, Tim Harvey and Bin Meng)
- removed --gc-sections for ARM if internal libgcc is used
- remove -fwhole-program in final LTO LDFLAGS
- declared all 4 functions (memcpy, memset, memcmp, memmove) __used, (these are mentioned in GCC man page for option -nodefaultlibs that the compiler may generate; this seems to be a bug in GCC that linking fails with LTO even if these functions are present, because the symbols can be renamed on some targets by optimization)

Marek

Marek Behún (36):
regmap: fix a serious pointer casting bug
checkpatch: require quotes around section name in the __section()
macro
treewide: Convert macro and uses of __section(foo) to __section("foo") compiler.h: align the __ADDRESSABLE macro with Linux' version test/py: improve regular expression for ut subtest symbol matcher
string: make memcpy(), memset(), memcmp() and memmove() visible for
LTO
efi_loader: fix warning when linking with LTO
efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data
efi_loader: add macro for const EFI runtime data
efi_selftest: compiler flags for efi_selftest_miniapp_exception.o
lib: crc32: put the crc_table variable into efi_runtime_rodata section Makefile, Makefile.spl: cosmetic change
build: use thin archives instead of incremental linking
build: support building with Link Time Optimizations
build: link with --build-id=none
sandbox: errno: avoid conflict with libc's errno
sandbox: use sections instead of symbols for getopt array boundaries
sandbox: make LTO available
sandbox: enable LTO by default
ARM: global_data: make set_gd() work for armv5 and armv6
ARM: make gd a function call for LTO and set via set_gd()
ARM: fix LTO build for some thumb-interwork cases
ARM: fix LTO for imx28_xea
ARM: fix LTO for apf27
ARM: fix LTO for keystone
ARM: kona: fix clk_bsc_enable() type mismatch for LTO
ARM: imx8m: fix imx_eqos_txclk_set_rate() type mismatch for LTO
ARM: fix LTO for seaboard
ARM: fix LTO for rockchip and samsung
ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)
armv8: SPL: discard relocation information
ata: ahci: fix ahci_link_up() type mismatch for LTO
ARM: make LTO available
ARM: don't use -ffunction-sections/-fdata-sections with LTO build
ARM: don't use --gc-sections with LTO when using private libgcc
ARM: enable LTO for some boards

  Kbuild                                     |  2 +
  Kconfig                                    | 24 +++++++
  Makefile                                   | 81 ++++++++++++++++++++--
  arch/Kconfig                               |  3 +
  arch/arm/config.mk                         | 10 ++-
  arch/arm/cpu/arm926ejs/Makefile            |  2 +
  arch/arm/cpu/arm926ejs/mxs/mxs.c           |  2 +-
  arch/arm/cpu/arm926ejs/mxs/spl_boot.c      |  4 +-
  arch/arm/cpu/arm926ejs/spear/spl.c         |  2 +-
  arch/arm/cpu/armv7/kona-common/clk-stubs.c |  2 +-
  arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c  |  2 +-
  arch/arm/cpu/armv8/spl_data.c              |  4 +-
  arch/arm/cpu/armv8/u-boot-spl.lds          |  1 +
  arch/arm/include/asm/global_data.h         |  6 +-
  arch/arm/include/asm/secure.h              |  6 +-
  arch/arm/include/asm/setup.h               |  2 +-
  arch/arm/lib/Makefile                      |  3 +
  arch/arm/lib/sections.c                    | 31 +++++----
  arch/arm/lib/spl.c                         |  2 +-
  arch/arm/mach-at91/spl.c                   |  2 +-
  arch/arm/mach-exynos/spl_boot.c            |  2 +-
  arch/arm/mach-imx/imx8m/clock_imx8mm.c     |  2 +-
  arch/arm/mach-imx/imx8m/soc.c              |  2 +-
  arch/arm/mach-imx/spl_imx_romapi.c         | 16 ++---
  arch/arm/mach-k3/am642_init.c              |  2 +-
  arch/arm/mach-k3/am6_init.c                |  2 +-
  arch/arm/mach-k3/j721e_init.c              |  4 +-
  arch/arm/mach-keystone/Makefile            |  1 +
  arch/arm/mach-mvebu/mbus.c                 |  4 +-
  arch/arm/mach-mvebu/timer.c                |  2 +-
  arch/arm/mach-nexell/clock.c               |  6 +-
  arch/arm/mach-nexell/timer.c               |  6 +-
  arch/arm/mach-omap2/omap3/Makefile         |  1 +
  arch/arm/mach-rockchip/board.c             |  2 +-
  arch/arm/mach-socfpga/spl_a10.c            |  2 +-
  arch/arm/mach-sunxi/board.c                |  2 +-
  arch/arm/mach-tegra/board.c                |  2 +-
  arch/arm/mach-tegra/cboot.c                |  8 +--
  arch/arm/mach-tegra/tegra20/Makefile       |  1 +
  arch/mips/mach-jz47xx/jz4780/jz4780.c      |  2 +-
  arch/nds32/include/asm/setup.h             |  6 +-
  arch/powerpc/include/asm/cache.h           |  4 +-
  arch/riscv/cpu/cpu.c                       |  4 +-
  arch/sandbox/config.mk                     | 14 +++-
  arch/sandbox/cpu/os.c                      |  3 +-
  arch/sandbox/cpu/start.c                   |  3 +-
  arch/sandbox/cpu/u-boot-spl.lds            |  8 ++-
  arch/sandbox/cpu/u-boot.lds                |  8 ++-
  arch/sandbox/include/asm/getopt.h          |  2 +-
  arch/sandbox/include/asm/sections.h        | 21 +++++-
  arch/sandbox/lib/sections.c                |  9 +--
  arch/x86/cpu/coreboot/timestamp.c          |  2 +-
  arch/x86/lib/coreboot/cb_sysinfo.c         |  2 +-
  arch/x86/lib/sections.c                    |  9 +--
  arch/xtensa/cpu/cpu.c                      |  2 +-
  board/bosch/shc/board.c                    |  2 +-
  board/broadcom/bcmstb/bcmstb.c             |  2 +-
  board/samsung/arndale/arndale_spl.c        |  2 +-
  board/samsung/common/exynos5-dt.c          |  2 +-
  board/samsung/smdk5250/smdk5250_spl.c      |  2 +-
  board/samsung/smdk5420/smdk5420_spl.c      |  2 +-
  board/siemens/draco/board.c                |  2 +-
  board/xilinx/common/fru_ops.c              |  2 +-
  configs/am3517_evm_defconfig               |  1 +
  configs/da850evm_defconfig                 |  1 +
  configs/da850evm_direct_nor_defconfig      |  1 +
  configs/da850evm_nand_defconfig            |  1 +
  configs/imx6q_logic_defconfig              |  1 +
  configs/imx8mm_beacon_defconfig            |  1 +
  configs/imx8mm_venice_defconfig            |  1 +
  configs/imx8mn_beacon_2g_defconfig         |  1 +
  configs/imx8mn_beacon_defconfig            |  1 +
  configs/nokia_rx51_defconfig               |  1 +
  configs/omap3_logic_defconfig              |  1 +
  configs/r8a774a1_beacon_defconfig          |  1 +
  configs/r8a774b1_beacon_defconfig          |  1 +
  configs/r8a774e1_beacon_defconfig          |  1 +
  drivers/ata/ahci.c                         |  2 +-
  drivers/bios_emulator/biosemu.c            |  4 +-
  drivers/clk/kendryte/clk.c                 |  4 +-
  drivers/core/regmap.c                      | 59 +++++++++++++++-
  drivers/firmware/psci.c                    |  2 +-
  drivers/mtd/nand/raw/mxc_nand_spl.c        |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx5.c         |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx7.c         |  2 +-
  drivers/pinctrl/nxp/pinctrl-imx8m.c        |  2 +-
  drivers/power/pmic/pmic_tps62362.c         |  2 +-
  drivers/power/pmic/pmic_tps65217.c         |  2 +-
  drivers/power/pmic/pmic_tps65218.c         |  2 +-
  drivers/power/pmic/pmic_tps65910.c         |  2 +-
  drivers/serial/serial_pl01x.c              |  4 +-
  include/efi_loader.h                       | 54 +++++++++++++--
  include/errno.h                            |  8 ++-
  include/linker_lists.h                     | 24 +++----
  include/linux/compiler.h                   | 10 +--
  include/linux/compiler_attributes.h        |  2 +-
  lib/crc32.c                                |  3 +-
  lib/efi_selftest/Makefile                  |  2 +
  lib/errno.c                                |  4 +-
  lib/string.c                               |  9 +--
  lib/trace.c                                |  4 +-
  scripts/Makefile.build                     | 16 ++---
  scripts/Makefile.lib                       |  3 +
  scripts/Makefile.spl                       | 63 +++++++++++++++--
  scripts/checkpatch.pl                      |  2 +-
  scripts/gen_ll_addressable_symbols.sh      | 12 ++++
  test/py/conftest.py                        |  2 +-
  107 files changed, 513 insertions(+), 183 deletions(-)
Quoted 2 lines

create mode 100755 scripts/gen_ll_addressable_symbols.sh

I am trying to activate CONFIG_LTO for STMicroelectronics stm32mp15 platform

(stm32mp15_trusted_defconfig and stm32mp15_basic_defconfig).

The config stm32mp15_basic_defconfig, with SPL supported failed to boot

with gcc-arm-9.2-2019.12.

because a weak function is not correctly handle between

1/ ./arch/arm/lib/cache-cp15.c: 96

    __weak void dram_bank_mmu_setup(int bank);

2/ the stm32mp implementation in

Quoted 7 lines

   arch/arm/mach-stm32mp/cpu.c:62

   void dram_bank_mmu_setup(int bank)

=> The used function in SPL is the cache library, not the stm32mp function.

      and SPL boot it OK when I remove the function in the cache library...

Good work figuring that out. It might help lead to people figuring out some other problems with LTO off/on. FWIW, I found using buildman's size display options can also be useful.

Quoted 5 lines

And the issue is also solved with I use a more recent version

gcc-arm-10.2-2020.11 on my PC.

Quoted 8 lines

Do you see the same kind of issue for old version of gcc ?

Do you think CONFIG_LTO require a more recent version of gcc that

the minimal version required by U-Boot  because I don't see this information

in the serie?

Note that we only test with gcc-9.2.x right now, moving up to gcc-11. But that had its own problems I didn't get feedback on (grub+riscv32 just doesn't build, and that's an upstream problem that's been ignored as of when I posted my patches at least).

Signature · 1 line
Tom
#108 lore raw
In reply to Patrick DELAUNAY
Quoted 40 lines · On Tue, 1 Jun 2021 16:59:52 +0200 Patrick DELAUNAY…

Hi Marek,

I am trying to activate CONFIG_LTO for STMicroelectronics stm32mp15 platform

(stm32mp15_trusted_defconfig and stm32mp15_basic_defconfig).

The config stm32mp15_basic_defconfig, with SPL supported failed to boot

with gcc-arm-9.2-2019.12.

because a weak function is not correctly handle between

1/ ./arch/arm/lib/cache-cp15.c: 96

    __weak void dram_bank_mmu_setup(int bank);

2/ the stm32mp implementation in

   arch/arm/mach-stm32mp/cpu.c:62

   void dram_bank_mmu_setup(int bank)

=> The used function in SPL is the cache library, not the stm32mp function.

      and SPL boot it OK when I remove the function in the cache
library...

And the issue is also solved with I use a more recent version

gcc-arm-10.2-2020.11 on my PC.

Do you see the same kind of issue for old version of gcc ?

Quoted 6 lines

Do you think CONFIG_LTO require a more recent version of gcc that

the minimal version required by U-Boot  because I don't see this information

in the serie?

I only tried compiling with older versions in the CI.

On the devices for which I tested it I only compiled with newer gcc (10.2.0) since it is the stable version on my system.

But yeah, I suggest to use newer GCC for LTO.

Marek

#109 lore raw
Quoted 50 lines · Marek Behún
Quoted 40 lines · On Tue, 1 Jun 2021 16:59:52 +0200 Patrick DELAUNAY…

Hi Marek,

I am trying to activate CONFIG_LTO for STMicroelectronics stm32mp15 platform

(stm32mp15_trusted_defconfig and stm32mp15_basic_defconfig).

The config stm32mp15_basic_defconfig, with SPL supported failed to boot

with gcc-arm-9.2-2019.12.

because a weak function is not correctly handle between

1/ ./arch/arm/lib/cache-cp15.c: 96

      __weak void dram_bank_mmu_setup(int bank);

2/ the stm32mp implementation in

   arch/arm/mach-stm32mp/cpu.c:62

   void dram_bank_mmu_setup(int bank)

=> The used function in SPL is the cache library, not the stm32mp function.

      and SPL boot it OK when I remove the function in the cache
library...

And the issue is also solved with I use a more recent version

gcc-arm-10.2-2020.11 on my PC.

Do you see the same kind of issue for old version of gcc ?

Quoted 6 lines

Do you think CONFIG_LTO require a more recent version of gcc that

the minimal version required by U-Boot  because I don't see this information

in the serie?

Quoted 9 lines

I only tried compiling with older versions in the CI.

On the devices for which I tested it I only compiled with newer gcc (10.2.0) since it is the stable version on my system.

But yeah, I suggest to use newer GCC for LTO.

Marek

gcc (Debian 11-20210327-1) 11.0.1 compiles stm32mp15_basic_defconfig with CONFIG_LTO=y.

Best regards

Heinrich

#110 lore raw
Quoted 56 lines · Heinrich Schuchardt
Quoted 55 lines · Marek Behún
Quoted 40 lines · On Tue, 1 Jun 2021 16:59:52 +0200 Patrick DELAUNAY…

Hi Marek,

I am trying to activate CONFIG_LTO for STMicroelectronics stm32mp15 platform

(stm32mp15_trusted_defconfig and stm32mp15_basic_defconfig).

The config stm32mp15_basic_defconfig, with SPL supported failed to boot

with gcc-arm-9.2-2019.12.

because a weak function is not correctly handle between

1/ ./arch/arm/lib/cache-cp15.c: 96

      __weak void dram_bank_mmu_setup(int bank);

2/ the stm32mp implementation in

   arch/arm/mach-stm32mp/cpu.c:62

   void dram_bank_mmu_setup(int bank)

=> The used function in SPL is the cache library, not the stm32mp function.

      and SPL boot it OK when I remove the function in the cache
library...

And the issue is also solved with I use a more recent version

gcc-arm-10.2-2020.11 on my PC.

Do you see the same kind of issue for old version of gcc ?

Quoted 6 lines

Do you think CONFIG_LTO require a more recent version of gcc that

the minimal version required by U-Boot  because I don't see this information

in the serie?

I only tried compiling with older versions in the CI.

On the devices for which I tested it I only compiled with newer gcc (10.2.0) since it is the stable version on my system.

Quoted 7 lines
Quoted 4 lines

But yeah, I suggest to use newer GCC for LTO.

Marek

gcc (Debian 11-20210327-1) 11.0.1 compiles stm32mp15_basic_defconfig with CONFIG_LTO=y.

It's run-time not compile time that shows the problem however as gcc-9.x sounds like it has a problem with LTO and weak functions.

Signature · 1 line
Tom