* [PATCH v2 00/15] Various toolchain compatibility fixes/improvements
@ 2025-03-15 22:17 Sam Edwards
2025-03-15 22:17 ` [PATCH v2 01/15] arm: Remove stray .mmutable reference in linker script Sam Edwards
` (16 more replies)
0 siblings, 17 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:17 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
Hello again U-Boot list,
This is v2 of my "misc. fixes" series, sent to prepare the codebase for more
direct LLVM support in the near future. This series contains several fixes that
I found in the process of preparing that support and which address issues
independent of any future feature or enhancement. I am sending these now, both
so that their inclusion is not delayed by discussion on my upcoming series and
to make the latter more manageable.
PLEASE APPLY PARTIALLY! I have tried to sort these so that the most
straightforward changes come first. If any patch proves contentious, you can
either skip it or stop applying the series at that point. Any patches that need
revisions will be included in a future series, but I'm trying to avoid there
being a v3 of *this* series. :)
Happy Saturday,
Sam
Changes v1->v2:
- Carried forward acked/reviewed tags
- Dropped two patches (one was incorrect, the other can be fixed differently)
- Minor phrasing changes to commit messages
- Instead of removing `ENTRY(_start)`, I instead added `.globl _start` where
appropriate, in the EFI apps
Sam Edwards (15):
arm: Remove stray .mmutable reference in linker script
arm: Exclude eabi_compat from LTO
arm: Add __aeabi_memclr in eabi_compat
arm: Add aligned-memory aliases to eabi_compat
arm: Discard unwanted sections in linker script
arm: Replace 'adrl' in EFI crt0
x86: Fix call64's section flags
makefile: Avoid objcopy --gap-fill for .hex/.srec
makefile: Add `norelro` linker option
makefile: Add READELF command variable
arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
efi_loader: Move .dynamic out of .text in EFI
scripts/Makefile.lib: efi: Preserve the .dynstr section as well
spl: riscv: opensbi: Error on misaligned FDT
spl: Align FDT load address
Makefile | 14 ++++++++------
arch/arm/cpu/u-boot.lds | 29 ++++++++++-------------------
arch/arm/lib/Makefile | 1 +
arch/arm/lib/crt0_aarch64_efi.S | 1 +
arch/arm/lib/crt0_arm_efi.S | 4 +++-
arch/arm/lib/eabi_compat.c | 17 +++++++++++++++++
arch/riscv/lib/crt0_riscv_efi.S | 1 +
arch/x86/cpu/i386/call64.S | 2 +-
common/spl/spl_fit.c | 2 +-
common/spl/spl_opensbi.c | 5 +++++
lib/efi_loader/elf_efi.ldsi | 6 +++---
scripts/Makefile.lib | 4 ++--
12 files changed, 53 insertions(+), 33 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v2 01/15] arm: Remove stray .mmutable reference in linker script
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
@ 2025-03-15 22:17 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 02/15] arm: Exclude eabi_compat from LTO Sam Edwards
` (15 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:17 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
The .mmutable section was deprecated in 2012 [1] and finally removed
entirely from U-Boot in 2022 [2], so this special handling is no longer
necessary. Remove it to tidy up the linker script.
[1]: dde3b70dcf3d ("arm: add a common .lds link script")
[2]: 3135ba642f9a ("arm: pxa: Remove CONFIG_CPU_PXA25X")
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
arch/arm/cpu/u-boot.lds | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 2f50087f57a..63e82a09fad 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -169,15 +169,6 @@ SECTIONS
_end = .;
_image_binary_end = .;
- /*
- * Deprecated: this MMU section is used by pxa at present but
- * should not be used by new boards/CPUs.
- */
- . = ALIGN(4096);
- .mmutable : {
- *(.mmutable)
- }
-
/*
* These sections occupy the same memory, but their lifetimes do
* not overlap: U-Boot initializes .bss only after applying dynamic
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 02/15] arm: Exclude eabi_compat from LTO
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
2025-03-15 22:17 ` [PATCH v2 01/15] arm: Remove stray .mmutable reference in linker script Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 03/15] arm: Add __aeabi_memclr in eabi_compat Sam Edwards
` (14 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
These symbols need to survive the IR-level dead function elimination pass,
since nothing at the IR level is referencing them (calls to these are inserted
later, at codegen time).
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
arch/arm/lib/Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 1c95dd6fed2..74cd5051552 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -92,6 +92,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
# For EABI conformant tool chains, provide eabi_compat()
ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
extra-y += eabi_compat.o
+CFLAGS_REMOVE_eabi_compat.o := $(LTO_CFLAGS)
endif
# some files can only build in ARM or THUMB2, not THUMB1
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 03/15] arm: Add __aeabi_memclr in eabi_compat
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
2025-03-15 22:17 ` [PATCH v2 01/15] arm: Remove stray .mmutable reference in linker script Sam Edwards
2025-03-15 22:18 ` [PATCH v2 02/15] arm: Exclude eabi_compat from LTO Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 04/15] arm: Add aligned-memory aliases to eabi_compat Sam Edwards
` (13 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
LLVM's code generator will sometimes emit calls to __aeabi_memclr. Add an
implementation of this for LLVM compatibility.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
arch/arm/lib/eabi_compat.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm/lib/eabi_compat.c b/arch/arm/lib/eabi_compat.c
index 602efe04c04..e4190c049a3 100644
--- a/arch/arm/lib/eabi_compat.c
+++ b/arch/arm/lib/eabi_compat.c
@@ -37,3 +37,8 @@ void __aeabi_memset(void *dest, size_t n, int c)
{
(void) memset(dest, c, n);
}
+
+void __aeabi_memclr(void *dest, size_t n)
+{
+ (void) memset(dest, 0, n);
+}
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 04/15] arm: Add aligned-memory aliases to eabi_compat
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (2 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 03/15] arm: Add __aeabi_memclr in eabi_compat Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 05/15] arm: Discard unwanted sections in linker script Sam Edwards
` (12 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
These are sometimes used by LLVM's code-generator, when it can guarantee that
the memory buffer being passed is aligned on a (4- or 8-byte) boundary. They
can safely be aliased to the unaligned versions.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
arch/arm/lib/eabi_compat.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/arm/lib/eabi_compat.c b/arch/arm/lib/eabi_compat.c
index e4190c049a3..e6cafcc5f2b 100644
--- a/arch/arm/lib/eabi_compat.c
+++ b/arch/arm/lib/eabi_compat.c
@@ -33,12 +33,24 @@ void __aeabi_memcpy(void *dest, const void *src, size_t n)
(void) memcpy(dest, src, n);
}
+void __aeabi_memcpy4(void *dest, const void *src, size_t n) __alias(__aeabi_memcpy);
+
+void __aeabi_memcpy8(void *dest, const void *src, size_t n) __alias(__aeabi_memcpy);
+
void __aeabi_memset(void *dest, size_t n, int c)
{
(void) memset(dest, c, n);
}
+void __aeabi_memset4(void *dest, size_t n, int c) __alias(__aeabi_memset);
+
+void __aeabi_memset8(void *dest, size_t n, int c) __alias(__aeabi_memset);
+
void __aeabi_memclr(void *dest, size_t n)
{
(void) memset(dest, 0, n);
}
+
+void __aeabi_memclr4(void *dest, size_t n) __alias(__aeabi_memclr);
+
+void __aeabi_memclr8(void *dest, size_t n) __alias(__aeabi_memclr);
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 05/15] arm: Discard unwanted sections in linker script
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (3 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 04/15] arm: Add aligned-memory aliases to eabi_compat Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-30 6:47 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0 Sam Edwards
` (11 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
There are a handful of sections that are not useful in the U-Boot output
binary. At present, the linker script moves these to the end of the
binary, after the _image_binary_end marker symbol, so that they don't
get loaded.
The linker script syntax supports discarding sections that shouldn't be
included in the output. Switch to this instead, to make the intention
clearer and reduce the ELF sections that have to be handled later in the
build. This is also consistent with the other architectures' linker
scripts.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
arch/arm/cpu/u-boot.lds | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 63e82a09fad..817e7a983ae 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -181,14 +181,14 @@ SECTIONS
__bss_end = .;
}
- .dynsym _image_binary_end : { *(.dynsym) }
- .dynbss : { *(.dynbss) }
- .dynstr : { *(.dynstr*) }
- .dynamic : { *(.dynamic*) }
- .plt : { *(.plt*) }
- .interp : { *(.interp*) }
- .gnu.hash : { *(.gnu.hash) }
- .gnu : { *(.gnu*) }
- .ARM.exidx : { *(.ARM.exidx*) }
- .gnu.linkonce.armexidx : { *(.gnu.linkonce.armexidx.*) }
+ /DISCARD/ : { *(.dynsym) }
+ /DISCARD/ : { *(.dynbss) }
+ /DISCARD/ : { *(.dynstr*) }
+ /DISCARD/ : { *(.dynamic*) }
+ /DISCARD/ : { *(.plt*) }
+ /DISCARD/ : { *(.interp*) }
+ /DISCARD/ : { *(.gnu.hash) }
+ /DISCARD/ : { *(.gnu*) }
+ /DISCARD/ : { *(.ARM.exidx*) }
+ /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
}
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (4 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 05/15] arm: Discard unwanted sections in linker script Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-30 6:46 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 07/15] x86: Fix call64's section flags Sam Edwards
` (10 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
LLVM's IAS does not (and cannot easily) support the 'adrl'
pseudoinstruction, and ARM developers generally do not consider it
portable across assembler implementations either.
Instead, expand it into the two subtract instructions it would emit
anyway. An explanation of the math follows:
The .+8 and .+4 refer to the same memory location; this is because the
.+4 expression occurs in a subsequent instruction, 4 bytes after the
first. This memory location is the value of the PC register when it is
read by the first sub instruction. Thus, both inner parenthesized
expressions evaluate to the same result: PC's offset relative to
image_base. The subtract instructions then remove one byte each
(low, then high) of the total offset, thereby getting the absolute
address of image_base loaded in r0.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
arch/arm/lib/crt0_arm_efi.S | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
index 91b0fe12c51..235b3a0c48f 100644
--- a/arch/arm/lib/crt0_arm_efi.S
+++ b/arch/arm/lib/crt0_arm_efi.S
@@ -149,7 +149,8 @@ _start:
adr r1, .L_DYNAMIC
ldr r0, [r1]
add r1, r0, r1
- adrl r0, image_base
+ sub r0, pc, #((.+8-image_base) & 0xff)
+ sub r0, r0, #((.+4-image_base) & 0xff00)
bl _relocate
teq r0, #0
bne 0f
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 07/15] x86: Fix call64's section flags
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (5 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0 Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec Sam Edwards
` (9 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
When a section is not flagged with SHF_ALLOC, LLD's --gc-sections
algorithm fails to visit the sections that it references. As a result of
this, LLD was dropping the call64.o(.data) section, which is itself only
referenced by .text_call64.
This appears to be a bug in LLD, but the .section directive for
.text_call64 should really have the correct flags either way.
Add `"ax"` to mark the section as ALLOC ("supposed to be loaded") and
CODE ("supposed to be executed").
Fixes: 7dc82591d68e2a ("x86: Move call64 into its own section")
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
arch/x86/cpu/i386/call64.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/cpu/i386/call64.S b/arch/x86/cpu/i386/call64.S
index d81bcc6f8f4..424732fa3fa 100644
--- a/arch/x86/cpu/i386/call64.S
+++ b/arch/x86/cpu/i386/call64.S
@@ -10,7 +10,7 @@
#include <asm/processor-flags.h>
.code32
-.section .text_call64
+.section .text_call64, "ax"
.globl cpu_call64
cpu_call64:
/*
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (6 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 07/15] x86: Fix call64's section flags Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-30 6:47 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 09/15] makefile: Add `norelro` linker option Sam Edwards
` (8 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
This flag only makes sense for `binary` output, because .hex/.srec are
sparse formats and represent gaps without filler. While the GNU binutils
version of objcopy does not seem to mind the extra flag being passed,
llvm-objcopy considers this a fatal error.
There is already a version of the objcopy command template in the
Makefile that doesn't use --gap-fill, which is provided for EFI. So use
this other version for all .hex/.srec outputs as well.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
Makefile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 0694c425438..9c353af17cd 100644
--- a/Makefile
+++ b/Makefile
@@ -1067,7 +1067,7 @@ quiet_cmd_objcopy = OBJCOPY $@
cmd_objcopy = $(OBJCOPY) --gap-fill=0xff $(OBJCOPYFLAGS) \
$(OBJCOPYFLAGS_$(@F)) $< $@
-# Provide a version which does not do this, for use by EFI
+# Provide a version which does not do this, for use by EFI and hex/srec
quiet_cmd_zobjcopy = OBJCOPY $@
cmd_zobjcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
@@ -1282,7 +1282,7 @@ OBJCOPYFLAGS_u-boot.hex := -O ihex
OBJCOPYFLAGS_u-boot.srec := -O srec
u-boot.hex u-boot.srec: u-boot FORCE
- $(call if_changed,objcopy)
+ $(call if_changed,zobjcopy)
OBJCOPYFLAGS_u-boot-elf.srec := $(OBJCOPYFLAGS_u-boot.srec)
@@ -1296,12 +1296,12 @@ OBJCOPYFLAGS_u-boot-elf.srec += --change-addresses=0x50000000
endif
u-boot-elf.srec: u-boot.elf FORCE
- $(call if_changed,objcopy)
+ $(call if_changed,zobjcopy)
OBJCOPYFLAGS_u-boot-spl.srec = $(OBJCOPYFLAGS_u-boot.srec)
spl/u-boot-spl.srec: spl/u-boot-spl FORCE
- $(call if_changed,objcopy)
+ $(call if_changed,zobjcopy)
%.scif: %.srec
$(Q)$(MAKE) $(build)=arch/arm/mach-renesas $@
@@ -1436,7 +1436,7 @@ OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
u-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE
- $(call if_changed,objcopy)
+ $(call if_changed,zobjcopy)
ifdef CONFIG_SPL_LOAD_FIT
MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 09/15] makefile: Add `norelro` linker option
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (7 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 10/15] makefile: Add READELF command variable Sam Edwards
` (7 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
RELRO is an instruction to a dynamic loader to make a memory range
read-only after relocations are applied, for added security. Some
linkers (e.g. LLD) require that all sections covered by the RELRO are
contiguous, so that only a single RELRO is needed. U-Boot at present
neither satisfies this requirement (e.g. x86_64 linker script currently
puts .dynamic too far from .got) nor preserves the RELRO when converting
away from ELF, therefore add `-z norelro` to global linker options.
This can be brought back in the future when the linker scripts are
cleaned up and U-Boot understands RELROs.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile
index 9c353af17cd..05a93813afa 100644
--- a/Makefile
+++ b/Makefile
@@ -820,6 +820,7 @@ KBUILD_AFLAGS += $(KAFLAGS)
KBUILD_CFLAGS += $(KCFLAGS)
KBUILD_LDFLAGS += -z noexecstack
+KBUILD_LDFLAGS += -z norelro
KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g)
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 10/15] makefile: Add READELF command variable
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (8 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 09/15] makefile: Add `norelro` linker option Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs Sam Edwards
` (6 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
This allows setting READELF=llvm-readelf in order to use the LLVM
version of the readelf utility. It also aligns with the practice of not
using $(CROSS_COMPILE) in any build recipes directly, reducing the
number of places where $(CROSS_COMPILE) is used.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 05a93813afa..fb5cd67745f 100644
--- a/Makefile
+++ b/Makefile
@@ -406,6 +406,7 @@ LDR = $(CROSS_COMPILE)ldr
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
+READELF = $(CROSS_COMPILE)readelf
LEX = flex
YACC = bison
AWK = awk
@@ -2177,7 +2178,7 @@ System.map: u-boot
# ARM relocations should all be R_ARM_RELATIVE (32-bit) or
# R_AARCH64_RELATIVE (64-bit).
checkarmreloc: u-boot
- @RELOC="`$(CROSS_COMPILE)readelf -r -W $< | cut -d ' ' -f 4 | \
+ @RELOC="`$(READELF) -r -W $< | cut -d ' ' -f 4 | \
grep R_A | sort -u`"; \
if test "$$RELOC" != "R_ARM_RELATIVE" -a \
"$$RELOC" != "R_AARCH64_RELATIVE"; then \
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (9 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 10/15] makefile: Add READELF command variable Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-17 8:43 ` Heinrich Schuchardt
2025-03-15 22:18 ` [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI Sam Edwards
` (5 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
While the _start label is only intended for use locally to populate the
(hand-written) PE header, the linker script includes ENTRY(_start) which
designates it as the entry point in the output ELF, resulting in linker
warnings under some linkers (e.g. LLVM's lld) due to _start not being a
globally-visible symbol. Since ELF is only an intermediary build
format, and the aforementioned PE header correctly points to _start, the
ENTRY(_start) directive could easily be removed to silence this warning.
However, since some developers who are debugging EFI by analyzing the
intermediary ELF may appreciate having correct entry-point information,
this patch instead promotes the _start labels to global symbols,
silencing the linker warning and making the intermediary ELF reflect the
true entry point.
This patch doesn't affect the final output binaries in any way.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
arch/arm/lib/crt0_aarch64_efi.S | 1 +
arch/arm/lib/crt0_arm_efi.S | 1 +
arch/riscv/lib/crt0_riscv_efi.S | 1 +
3 files changed, 3 insertions(+)
diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
index e21b54fdbcb..003d5f83041 100644
--- a/arch/arm/lib/crt0_aarch64_efi.S
+++ b/arch/arm/lib/crt0_aarch64_efi.S
@@ -144,6 +144,7 @@ section_table:
IMAGE_SCN_CNT_INITIALIZED_DATA)
.align 12
+ .globl _start
_start:
stp x29, x30, [sp, #-32]!
mov x29, sp
diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
index 235b3a0c48f..593ee1e194a 100644
--- a/arch/arm/lib/crt0_arm_efi.S
+++ b/arch/arm/lib/crt0_arm_efi.S
@@ -143,6 +143,7 @@ section_table:
IMAGE_SCN_CNT_INITIALIZED_DATA)
.align 12
+ .globl _start
_start:
stmfd sp!, {r0-r2, lr}
diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
index 9eacbe4a859..f170e4b26d6 100644
--- a/arch/riscv/lib/crt0_riscv_efi.S
+++ b/arch/riscv/lib/crt0_riscv_efi.S
@@ -179,6 +179,7 @@ section_table:
IMAGE_SCN_CNT_INITIALIZED_DATA)
.align 12
+ .globl _start
_start:
addi sp, sp, -(SIZE_LONG * 3)
SAVE_LONG(a0, 0)
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (10 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-17 8:34 ` Heinrich Schuchardt
2025-03-15 22:18 ` [PATCH v2 13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well Sam Edwards
` (4 subsequent siblings)
16 siblings, 1 reply; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards, Heinrich Schuchardt
EFI applications need to be relocatable. Ordinarily, this is achieved
through a PE-format .reloc section, but since that requires toolchain
tricks to achieve, U-Boot's EFI applications instead embed ELF-flavored
relocation information and use it for self-relocation; thus, the
.dynamic section needs to be preserved.
Before this patch, it was tacked on to the end of .text, but this was
not proper: A .text section is SHT_PROGBITS, while the .dynamic section
is SHT_DYNAMIC. Attempting to combine them like this creates a section
type mismatch. While GNU ld doesn't seem to complain, LLVM's lld
considers this a fatal linking error.
This patch moves .dynamic out to its own section, so that the output ELF
has the correct types. (They're all mashed together when converting to
binary anyway, so this patch causes no change in the final .efi output.)
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
lib/efi_loader/elf_efi.ldsi | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/efi_loader/elf_efi.ldsi b/lib/efi_loader/elf_efi.ldsi
index 190a88fb69e..4fa5ca43872 100644
--- a/lib/efi_loader/elf_efi.ldsi
+++ b/lib/efi_loader/elf_efi.ldsi
@@ -21,10 +21,10 @@ SECTIONS
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
- . = ALIGN(16);
- *(.dynamic);
- . = ALIGN(512);
}
+ . = ALIGN(16);
+ .dynamic : { *(.dynamic) }
+ . = ALIGN(512);
.rela.dyn : { *(.rela.dyn) }
.rela.plt : { *(.rela.plt) }
.rela.got : { *(.rela.got) }
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (11 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 14/15] spl: riscv: opensbi: Error on misaligned FDT Sam Edwards
` (3 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
This section is required by .dynamic and llvm-objcopy will exit with a
fatal error if it is not also preserved in the output.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
scripts/Makefile.lib | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 18993435eae..275c308154b 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -513,8 +513,8 @@ $(obj)/%_efi.S: $(obj)/%.efi
$(call cmd,S_efi)
quiet_cmd_efi_objcopy = OBJCOPY $@
-cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data -j \
- .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc \
+cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data \
+ -j .dynamic -j .dynstr -j .dynsym -j .rel* -j .reloc \
$(if $(EFI_TARGET),$(EFI_TARGET),-O binary) $^ $@
$(obj)/%.efi: $(obj)/%_efi.so
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 14/15] spl: riscv: opensbi: Error on misaligned FDT
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (12 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-15 22:18 ` [PATCH v2 15/15] spl: Align FDT load address Sam Edwards
` (2 subsequent siblings)
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
libfdt 1.6.1+ requires the FDT to be 8-byte aligned and returns an error
if not. OpenSBI 1.0+ includes this version of libfdt and will also
reject misaligned FDTs.
However, OpenSBI cannot indicate the error to the user: since it cannot
access the serial console, it can only silently hang. This proved very
difficult to diagnose without proper debugging facilities. Therefore,
give the U-Boot SPL, which *can* print error messages, an additional
check for proper FDT alignment. Hopefully this saves a lot of
development cycles if another developer encounters alignment problems.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
common/spl/spl_opensbi.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c
index 5a26d7c31a4..0ed6afeacc6 100644
--- a/common/spl/spl_opensbi.c
+++ b/common/spl/spl_opensbi.c
@@ -57,6 +57,11 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)
hang();
}
+ if (!IS_ALIGNED((uintptr_t)spl_image->fdt_addr, 8)) {
+ pr_err("SPL image loaded an improperly-aligned device tree\n");
+ hang();
+ }
+
/*
* Originally, u-boot-spl will place DTB directly after the kernel,
* but the size of the kernel did not include the BSS section, which
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 15/15] spl: Align FDT load address
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (13 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 14/15] spl: riscv: opensbi: Error on misaligned FDT Sam Edwards
@ 2025-03-15 22:18 ` Sam Edwards
2025-03-16 5:27 ` [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Heinrich Schuchardt
2025-04-03 1:59 ` Tom Rini
16 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-15 22:18 UTC (permalink / raw)
To: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas, Simon Glass,
Bin Meng, Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
While the image size is generally a multiple of 8 bytes, this is not
actually guaranteed; some linkers (like LLD) will shave a few bytes off
of the end of output sections if there are no content bytes there. Since
libfdt imposes a hard rule of 8-byte alignment, make the SPL also be
explicit about the alignment when loading the FDT.
Signed-off-by: Sam Edwards <CFSworks@gmail.com>
---
common/spl/spl_fit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 49b4df60560..86506d6905c 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -397,7 +397,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
* Use the address following the image as target address for the
* device tree.
*/
- image_info.load_addr = spl_image->load_addr + spl_image->size;
+ image_info.load_addr = ALIGN(spl_image->load_addr + spl_image->size, 8);
/* Figure out which device tree the board wants to use */
node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);
--
2.48.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v2 00/15] Various toolchain compatibility fixes/improvements
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (14 preceding siblings ...)
2025-03-15 22:18 ` [PATCH v2 15/15] spl: Align FDT load address Sam Edwards
@ 2025-03-16 5:27 ` Heinrich Schuchardt
2025-03-16 19:31 ` Sam Edwards
2025-04-03 1:59 ` Tom Rini
16 siblings, 1 reply; 24+ messages in thread
From: Heinrich Schuchardt @ 2025-03-16 5:27 UTC (permalink / raw)
To: Sam Edwards, Tom Rini, Ilias Apalodimas, Simon Glass, Bin Meng,
Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Sam Edwards
Am 15. März 2025 23:17:58 MEZ schrieb Sam Edwards <cfsworks@gmail.com>:
>Hello again U-Boot list,
>
>This is v2 of my "misc. fixes" series, sent to prepare the codebase for more
>direct LLVM support in the near future. This series contains several fixes that
>I found in the process of preparing that support and which address issues
>independent of any future feature or enhancement. I am sending these now, both
>so that their inclusion is not delayed by discussion on my upcoming series and
>to make the latter more manageable.
>
>PLEASE APPLY PARTIALLY! I have tried to sort these so that the most
>straightforward changes come first. If any patch proves contentious, you can
>either skip it or stop applying the series at that point. Any patches that need
>revisions will be included in a future series, but I'm trying to avoid there
>being a v3 of *this* series. :)
>
>Happy Saturday,
>Sam
Hello Sam,
I wonder why there are only ARM and X86 specific patches in this series . Wouldn't some of the changes also be needed for RISC-V and other architectures?
For EFI we have carved out a linker script include file to harmonize the linker scripts used by ARM and RISC-V. Shouldn't we do the same for main U-Boot?
Best regards
Heinrich
>
>Changes v1->v2:
>- Carried forward acked/reviewed tags
>- Dropped two patches (one was incorrect, the other can be fixed differently)
>- Minor phrasing changes to commit messages
>- Instead of removing `ENTRY(_start)`, I instead added `.globl _start` where
> appropriate, in the EFI apps
>
>Sam Edwards (15):
> arm: Remove stray .mmutable reference in linker script
> arm: Exclude eabi_compat from LTO
> arm: Add __aeabi_memclr in eabi_compat
> arm: Add aligned-memory aliases to eabi_compat
> arm: Discard unwanted sections in linker script
> arm: Replace 'adrl' in EFI crt0
> x86: Fix call64's section flags
> makefile: Avoid objcopy --gap-fill for .hex/.srec
> makefile: Add `norelro` linker option
> makefile: Add READELF command variable
> arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
> efi_loader: Move .dynamic out of .text in EFI
> scripts/Makefile.lib: efi: Preserve the .dynstr section as well
> spl: riscv: opensbi: Error on misaligned FDT
> spl: Align FDT load address
>
> Makefile | 14 ++++++++------
> arch/arm/cpu/u-boot.lds | 29 ++++++++++-------------------
> arch/arm/lib/Makefile | 1 +
> arch/arm/lib/crt0_aarch64_efi.S | 1 +
> arch/arm/lib/crt0_arm_efi.S | 4 +++-
> arch/arm/lib/eabi_compat.c | 17 +++++++++++++++++
> arch/riscv/lib/crt0_riscv_efi.S | 1 +
> arch/x86/cpu/i386/call64.S | 2 +-
> common/spl/spl_fit.c | 2 +-
> common/spl/spl_opensbi.c | 5 +++++
> lib/efi_loader/elf_efi.ldsi | 6 +++---
> scripts/Makefile.lib | 4 ++--
> 12 files changed, 53 insertions(+), 33 deletions(-)
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 00/15] Various toolchain compatibility fixes/improvements
2025-03-16 5:27 ` [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Heinrich Schuchardt
@ 2025-03-16 19:31 ` Sam Edwards
0 siblings, 0 replies; 24+ messages in thread
From: Sam Edwards @ 2025-03-16 19:31 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Tom Rini, Ilias Apalodimas, Simon Glass, Bin Meng, Rick Chen, Leo,
Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot
On Sat, Mar 15, 2025 at 10:27 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Am 15. März 2025 23:17:58 MEZ schrieb Sam Edwards <cfsworks@gmail.com>:
> >Hello again U-Boot list,
> >
> >This is v2 of my "misc. fixes" series, sent to prepare the codebase for more
> >direct LLVM support in the near future. This series contains several fixes that
> >I found in the process of preparing that support and which address issues
> >independent of any future feature or enhancement. I am sending these now, both
> >so that their inclusion is not delayed by discussion on my upcoming series and
> >to make the latter more manageable.
> >
> >PLEASE APPLY PARTIALLY! I have tried to sort these so that the most
> >straightforward changes come first. If any patch proves contentious, you can
> >either skip it or stop applying the series at that point. Any patches that need
> >revisions will be included in a future series, but I'm trying to avoid there
> >being a v3 of *this* series. :)
> >
> >Happy Saturday,
> >Sam
>
> Hello Sam,
>
> I wonder why there are only ARM and X86 specific patches in this series . Wouldn't some of the changes also be needed for RISC-V and other architectures?
Hi Heinrich,
The breakdown of arch-specific patches is: 6 for ARM, 1 for RISC-V, 1
for X86. This distribution was only because ARM needed more work, not
because it received more attention. (Some architectures, like
"sandbox," required no fixes, and MIPS appears to need only
compiler-side improvements at this time, for example.)
>
> For EFI we have carved out a linker script include file to harmonize the linker scripts used by ARM and RISC-V. Shouldn't we do the same for main U-Boot?
I like the idea in principle, but I'm skeptical because EFI
applications have a much more uniform and constrained memory layout
compared to raw binaries on [vendor-specific board]. So while it's
possible to mostly unify the memory layout, doing so would take
significantly more effort than with EFI. Plus, most of our supported
architectures don't have EFI at all, so unifying EFI across a few
architectures isn't a strong indicator that this approach would scale
well. Also, Linux doesn't do this either, and I'd expect they would
have if it were a good idea.
That said, I'd prefer to keep this patchset focused on fixing these
immediate issues rather than reworking the linker scripts more
broadly. If we want to explore that as a separate effort, I think it
would need a deeper discussion.
Happy Sunday,
Sam
>
> Best regards
>
> Heinrich
>
> >
> >Changes v1->v2:
> >- Carried forward acked/reviewed tags
> >- Dropped two patches (one was incorrect, the other can be fixed differently)
> >- Minor phrasing changes to commit messages
> >- Instead of removing `ENTRY(_start)`, I instead added `.globl _start` where
> > appropriate, in the EFI apps
> >
> >Sam Edwards (15):
> > arm: Remove stray .mmutable reference in linker script
> > arm: Exclude eabi_compat from LTO
> > arm: Add __aeabi_memclr in eabi_compat
> > arm: Add aligned-memory aliases to eabi_compat
> > arm: Discard unwanted sections in linker script
> > arm: Replace 'adrl' in EFI crt0
> > x86: Fix call64's section flags
> > makefile: Avoid objcopy --gap-fill for .hex/.srec
> > makefile: Add `norelro` linker option
> > makefile: Add READELF command variable
> > arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
> > efi_loader: Move .dynamic out of .text in EFI
> > scripts/Makefile.lib: efi: Preserve the .dynstr section as well
> > spl: riscv: opensbi: Error on misaligned FDT
> > spl: Align FDT load address
> >
> > Makefile | 14 ++++++++------
> > arch/arm/cpu/u-boot.lds | 29 ++++++++++-------------------
> > arch/arm/lib/Makefile | 1 +
> > arch/arm/lib/crt0_aarch64_efi.S | 1 +
> > arch/arm/lib/crt0_arm_efi.S | 4 +++-
> > arch/arm/lib/eabi_compat.c | 17 +++++++++++++++++
> > arch/riscv/lib/crt0_riscv_efi.S | 1 +
> > arch/x86/cpu/i386/call64.S | 2 +-
> > common/spl/spl_fit.c | 2 +-
> > common/spl/spl_opensbi.c | 5 +++++
> > lib/efi_loader/elf_efi.ldsi | 6 +++---
> > scripts/Makefile.lib | 4 ++--
> > 12 files changed, 53 insertions(+), 33 deletions(-)
> >
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI
2025-03-15 22:18 ` [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI Sam Edwards
@ 2025-03-17 8:34 ` Heinrich Schuchardt
0 siblings, 0 replies; 24+ messages in thread
From: Heinrich Schuchardt @ 2025-03-17 8:34 UTC (permalink / raw)
To: Sam Edwards, Tom Rini, Ilias Apalodimas, Simon Glass, Bin Meng,
Rick Chen, Leo
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot, Heinrich Schuchardt
On 3/15/25 23:18, Sam Edwards wrote:
> EFI applications need to be relocatable. Ordinarily, this is achieved
> through a PE-format .reloc section, but since that requires toolchain
> tricks to achieve, U-Boot's EFI applications instead embed ELF-flavored
> relocation information and use it for self-relocation; thus, the
> .dynamic section needs to be preserved.
>
> Before this patch, it was tacked on to the end of .text, but this was
> not proper: A .text section is SHT_PROGBITS, while the .dynamic section
> is SHT_DYNAMIC. Attempting to combine them like this creates a section
> type mismatch. While GNU ld doesn't seem to complain, LLVM's lld
> considers this a fatal linking error.
>
> This patch moves .dynamic out to its own section, so that the output ELF
> has the correct types. (They're all mashed together when converting to
> binary anyway, so this patch causes no change in the final .efi output.)
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
> Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> lib/efi_loader/elf_efi.ldsi | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lib/efi_loader/elf_efi.ldsi b/lib/efi_loader/elf_efi.ldsi
> index 190a88fb69e..4fa5ca43872 100644
> --- a/lib/efi_loader/elf_efi.ldsi
> +++ b/lib/efi_loader/elf_efi.ldsi
> @@ -21,10 +21,10 @@ SECTIONS
> *(.gnu.linkonce.t.*)
> *(.srodata)
> *(.rodata*)
> - . = ALIGN(16);
> - *(.dynamic);
> - . = ALIGN(512);
> }
> + . = ALIGN(16);
> + .dynamic : { *(.dynamic) }
> + . = ALIGN(512);
> .rela.dyn : { *(.rela.dyn) }
> .rela.plt : { *(.rela.plt) }
> .rela.got : { *(.rela.got) }
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
2025-03-15 22:18 ` [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs Sam Edwards
@ 2025-03-17 8:43 ` Heinrich Schuchardt
0 siblings, 0 replies; 24+ messages in thread
From: Heinrich Schuchardt @ 2025-03-17 8:43 UTC (permalink / raw)
To: Sam Edwards
Cc: Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
Tom Rini, Ilias Apalodimas, Simon Glass, Bin Meng, Rick Chen, Leo,
u-boot
On 3/15/25 23:18, Sam Edwards wrote:
> While the _start label is only intended for use locally to populate the
> (hand-written) PE header, the linker script includes ENTRY(_start) which
> designates it as the entry point in the output ELF, resulting in linker
> warnings under some linkers (e.g. LLVM's lld) due to _start not being a
> globally-visible symbol. Since ELF is only an intermediary build
> format, and the aforementioned PE header correctly points to _start, the
> ENTRY(_start) directive could easily be removed to silence this warning.
>
> However, since some developers who are debugging EFI by analyzing the
> intermediary ELF may appreciate having correct entry-point information,
> this patch instead promotes the _start labels to global symbols,
> silencing the linker warning and making the intermediary ELF reflect the
> true entry point.
>
> This patch doesn't affect the final output binaries in any way.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> arch/arm/lib/crt0_aarch64_efi.S | 1 +
> arch/arm/lib/crt0_arm_efi.S | 1 +
> arch/riscv/lib/crt0_riscv_efi.S | 1 +
> 3 files changed, 3 insertions(+)
>
> diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
> index e21b54fdbcb..003d5f83041 100644
> --- a/arch/arm/lib/crt0_aarch64_efi.S
> +++ b/arch/arm/lib/crt0_aarch64_efi.S
> @@ -144,6 +144,7 @@ section_table:
> IMAGE_SCN_CNT_INITIALIZED_DATA)
>
> .align 12
> + .globl _start
> _start:
> stp x29, x30, [sp, #-32]!
> mov x29, sp
> diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
> index 235b3a0c48f..593ee1e194a 100644
> --- a/arch/arm/lib/crt0_arm_efi.S
> +++ b/arch/arm/lib/crt0_arm_efi.S
> @@ -143,6 +143,7 @@ section_table:
> IMAGE_SCN_CNT_INITIALIZED_DATA)
>
> .align 12
> + .globl _start
> _start:
> stmfd sp!, {r0-r2, lr}
>
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 9eacbe4a859..f170e4b26d6 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -179,6 +179,7 @@ section_table:
> IMAGE_SCN_CNT_INITIALIZED_DATA)
>
> .align 12
> + .globl _start
> _start:
> addi sp, sp, -(SIZE_LONG * 3)
> SAVE_LONG(a0, 0)
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0
2025-03-15 22:18 ` [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0 Sam Edwards
@ 2025-03-30 6:46 ` Ilias Apalodimas
0 siblings, 0 replies; 24+ messages in thread
From: Ilias Apalodimas @ 2025-03-30 6:46 UTC (permalink / raw)
To: Sam Edwards
Cc: Tom Rini, Heinrich Schuchardt, Simon Glass, Bin Meng, Rick Chen,
Leo, Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot
On Sun, 16 Mar 2025 at 00:18, Sam Edwards <cfsworks@gmail.com> wrote:
>
> LLVM's IAS does not (and cannot easily) support the 'adrl'
> pseudoinstruction, and ARM developers generally do not consider it
> portable across assembler implementations either.
>
> Instead, expand it into the two subtract instructions it would emit
> anyway. An explanation of the math follows:
>
> The .+8 and .+4 refer to the same memory location; this is because the
> .+4 expression occurs in a subsequent instruction, 4 bytes after the
> first. This memory location is the value of the PC register when it is
> read by the first sub instruction. Thus, both inner parenthesized
> expressions evaluate to the same result: PC's offset relative to
> image_base. The subtract instructions then remove one byte each
> (low, then high) of the total offset, thereby getting the absolute
> address of image_base loaded in r0.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> arch/arm/lib/crt0_arm_efi.S | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
> index 91b0fe12c51..235b3a0c48f 100644
> --- a/arch/arm/lib/crt0_arm_efi.S
> +++ b/arch/arm/lib/crt0_arm_efi.S
> @@ -149,7 +149,8 @@ _start:
> adr r1, .L_DYNAMIC
> ldr r0, [r1]
> add r1, r0, r1
> - adrl r0, image_base
> + sub r0, pc, #((.+8-image_base) & 0xff)
> + sub r0, r0, #((.+4-image_base) & 0xff00)
> bl _relocate
> teq r0, #0
> bne 0f
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec
2025-03-15 22:18 ` [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec Sam Edwards
@ 2025-03-30 6:47 ` Ilias Apalodimas
0 siblings, 0 replies; 24+ messages in thread
From: Ilias Apalodimas @ 2025-03-30 6:47 UTC (permalink / raw)
To: Sam Edwards
Cc: Tom Rini, Heinrich Schuchardt, Simon Glass, Bin Meng, Rick Chen,
Leo, Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot
On Sun, 16 Mar 2025 at 00:18, Sam Edwards <cfsworks@gmail.com> wrote:
>
> This flag only makes sense for `binary` output, because .hex/.srec are
> sparse formats and represent gaps without filler. While the GNU binutils
> version of objcopy does not seem to mind the extra flag being passed,
> llvm-objcopy considers this a fatal error.
>
> There is already a version of the objcopy command template in the
> Makefile that doesn't use --gap-fill, which is provided for EFI. So use
> this other version for all .hex/.srec outputs as well.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> Makefile | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 0694c425438..9c353af17cd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1067,7 +1067,7 @@ quiet_cmd_objcopy = OBJCOPY $@
> cmd_objcopy = $(OBJCOPY) --gap-fill=0xff $(OBJCOPYFLAGS) \
> $(OBJCOPYFLAGS_$(@F)) $< $@
>
> -# Provide a version which does not do this, for use by EFI
> +# Provide a version which does not do this, for use by EFI and hex/srec
> quiet_cmd_zobjcopy = OBJCOPY $@
> cmd_zobjcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
>
> @@ -1282,7 +1282,7 @@ OBJCOPYFLAGS_u-boot.hex := -O ihex
> OBJCOPYFLAGS_u-boot.srec := -O srec
>
> u-boot.hex u-boot.srec: u-boot FORCE
> - $(call if_changed,objcopy)
> + $(call if_changed,zobjcopy)
>
> OBJCOPYFLAGS_u-boot-elf.srec := $(OBJCOPYFLAGS_u-boot.srec)
>
> @@ -1296,12 +1296,12 @@ OBJCOPYFLAGS_u-boot-elf.srec += --change-addresses=0x50000000
> endif
>
> u-boot-elf.srec: u-boot.elf FORCE
> - $(call if_changed,objcopy)
> + $(call if_changed,zobjcopy)
>
> OBJCOPYFLAGS_u-boot-spl.srec = $(OBJCOPYFLAGS_u-boot.srec)
>
> spl/u-boot-spl.srec: spl/u-boot-spl FORCE
> - $(call if_changed,objcopy)
> + $(call if_changed,zobjcopy)
>
> %.scif: %.srec
> $(Q)$(MAKE) $(build)=arch/arm/mach-renesas $@
> @@ -1436,7 +1436,7 @@ OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
> OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
>
> u-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE
> - $(call if_changed,objcopy)
> + $(call if_changed,zobjcopy)
>
> ifdef CONFIG_SPL_LOAD_FIT
> MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 05/15] arm: Discard unwanted sections in linker script
2025-03-15 22:18 ` [PATCH v2 05/15] arm: Discard unwanted sections in linker script Sam Edwards
@ 2025-03-30 6:47 ` Ilias Apalodimas
0 siblings, 0 replies; 24+ messages in thread
From: Ilias Apalodimas @ 2025-03-30 6:47 UTC (permalink / raw)
To: Sam Edwards
Cc: Tom Rini, Heinrich Schuchardt, Simon Glass, Bin Meng, Rick Chen,
Leo, Marek Vasut, Sumit Garg, Peter Robinson, Richard Henderson,
u-boot
On Sun, 16 Mar 2025 at 00:18, Sam Edwards <cfsworks@gmail.com> wrote:
>
> There are a handful of sections that are not useful in the U-Boot output
> binary. At present, the linker script moves these to the end of the
> binary, after the _image_binary_end marker symbol, so that they don't
> get loaded.
>
> The linker script syntax supports discarding sections that shouldn't be
> included in the output. Switch to this instead, to make the intention
> clearer and reduce the ELF sections that have to be handled later in the
> build. This is also consistent with the other architectures' linker
> scripts.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> arch/arm/cpu/u-boot.lds | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> index 63e82a09fad..817e7a983ae 100644
> --- a/arch/arm/cpu/u-boot.lds
> +++ b/arch/arm/cpu/u-boot.lds
> @@ -181,14 +181,14 @@ SECTIONS
> __bss_end = .;
> }
>
> - .dynsym _image_binary_end : { *(.dynsym) }
> - .dynbss : { *(.dynbss) }
> - .dynstr : { *(.dynstr*) }
> - .dynamic : { *(.dynamic*) }
> - .plt : { *(.plt*) }
> - .interp : { *(.interp*) }
> - .gnu.hash : { *(.gnu.hash) }
> - .gnu : { *(.gnu*) }
> - .ARM.exidx : { *(.ARM.exidx*) }
> - .gnu.linkonce.armexidx : { *(.gnu.linkonce.armexidx.*) }
> + /DISCARD/ : { *(.dynsym) }
> + /DISCARD/ : { *(.dynbss) }
> + /DISCARD/ : { *(.dynstr*) }
> + /DISCARD/ : { *(.dynamic*) }
> + /DISCARD/ : { *(.plt*) }
> + /DISCARD/ : { *(.interp*) }
> + /DISCARD/ : { *(.gnu.hash) }
> + /DISCARD/ : { *(.gnu*) }
> + /DISCARD/ : { *(.ARM.exidx*) }
> + /DISCARD/ : { *(.gnu.linkonce.armexidx.*) }
> }
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 00/15] Various toolchain compatibility fixes/improvements
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
` (15 preceding siblings ...)
2025-03-16 5:27 ` [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Heinrich Schuchardt
@ 2025-04-03 1:59 ` Tom Rini
16 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2025-04-03 1:59 UTC (permalink / raw)
To: Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Bin Meng,
Rick Chen, Leo, Sam Edwards
Cc: Marek Vasut, Peter Robinson, Richard Henderson, u-boot,
Sam Edwards, Sumit Garg
On Sat, 15 Mar 2025 15:17:58 -0700, Sam Edwards wrote:
> This is v2 of my "misc. fixes" series, sent to prepare the codebase for more
> direct LLVM support in the near future. This series contains several fixes that
> I found in the process of preparing that support and which address issues
> independent of any future feature or enhancement. I am sending these now, both
> so that their inclusion is not delayed by discussion on my upcoming series and
> to make the latter more manageable.
>
> [...]
Applied to u-boot/next, thanks!
[01/15] arm: Remove stray .mmutable reference in linker script
commit: 805377b1f5ae1834e2b1a07dbb6fed94672e0954
[02/15] arm: Exclude eabi_compat from LTO
commit: 6ba839a0f5473aac8dc038f8601071234c810119
[03/15] arm: Add __aeabi_memclr in eabi_compat
commit: 828484a7740d4ebfed8db85e4b4569cfbfe66cde
[04/15] arm: Add aligned-memory aliases to eabi_compat
commit: deba40dd0ba452a3f15a359894e6b50494870d0e
[05/15] arm: Discard unwanted sections in linker script
commit: 16448c443c8cacba7dacb3e919c0b414f70b8a7c
[06/15] arm: Replace 'adrl' in EFI crt0
commit: d5734b183c3d578fff1c1e81e46a1d04342edffe
[07/15] x86: Fix call64's section flags
commit: 8c39dc549b0de155c02a2b39f01dae19775f41a5
[08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec
commit: 86838a1ddc8a0e5b5f548a5051e5e68f90fb6660
[09/15] makefile: Add `norelro` linker option
commit: 7a8121fe6d314b314531eee7487272601f469c1d
[10/15] makefile: Add READELF command variable
commit: 586bb720e776396208df399874665ae8c6eb81e8
[11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs
commit: f692540b24a7775e43f1d315d3e13a5d3ed21dd4
[12/15] efi_loader: Move .dynamic out of .text in EFI
commit: 1755071db7d95fa0b95e9f9bedd3785e2abc10cf
[13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well
commit: 9ca475a6b5da06908a70d1eceb439d480137d69b
[14/15] spl: riscv: opensbi: Error on misaligned FDT
commit: 17d830cb4b6cdbac56d41938d455820fd7a96a89
[15/15] spl: Align FDT load address
commit: 358d1cc232c30091767ce192e74169e7861ae58a
--
Tom
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2025-04-03 2:00 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-15 22:17 [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Sam Edwards
2025-03-15 22:17 ` [PATCH v2 01/15] arm: Remove stray .mmutable reference in linker script Sam Edwards
2025-03-15 22:18 ` [PATCH v2 02/15] arm: Exclude eabi_compat from LTO Sam Edwards
2025-03-15 22:18 ` [PATCH v2 03/15] arm: Add __aeabi_memclr in eabi_compat Sam Edwards
2025-03-15 22:18 ` [PATCH v2 04/15] arm: Add aligned-memory aliases to eabi_compat Sam Edwards
2025-03-15 22:18 ` [PATCH v2 05/15] arm: Discard unwanted sections in linker script Sam Edwards
2025-03-30 6:47 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 06/15] arm: Replace 'adrl' in EFI crt0 Sam Edwards
2025-03-30 6:46 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 07/15] x86: Fix call64's section flags Sam Edwards
2025-03-15 22:18 ` [PATCH v2 08/15] makefile: Avoid objcopy --gap-fill for .hex/.srec Sam Edwards
2025-03-30 6:47 ` Ilias Apalodimas
2025-03-15 22:18 ` [PATCH v2 09/15] makefile: Add `norelro` linker option Sam Edwards
2025-03-15 22:18 ` [PATCH v2 10/15] makefile: Add READELF command variable Sam Edwards
2025-03-15 22:18 ` [PATCH v2 11/15] arm: riscv: efi: Export _start symbol from crt0_*_efi stubs Sam Edwards
2025-03-17 8:43 ` Heinrich Schuchardt
2025-03-15 22:18 ` [PATCH v2 12/15] efi_loader: Move .dynamic out of .text in EFI Sam Edwards
2025-03-17 8:34 ` Heinrich Schuchardt
2025-03-15 22:18 ` [PATCH v2 13/15] scripts/Makefile.lib: efi: Preserve the .dynstr section as well Sam Edwards
2025-03-15 22:18 ` [PATCH v2 14/15] spl: riscv: opensbi: Error on misaligned FDT Sam Edwards
2025-03-15 22:18 ` [PATCH v2 15/15] spl: Align FDT load address Sam Edwards
2025-03-16 5:27 ` [PATCH v2 00/15] Various toolchain compatibility fixes/improvements Heinrich Schuchardt
2025-03-16 19:31 ` Sam Edwards
2025-04-03 1:59 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox