* [PATCH] ld: pru: Place exception-handling sections correctly
@ 2023-05-03 17:11 Dimitar Dimitrov
2023-05-04 11:43 ` Nick Clifton
0 siblings, 1 reply; 2+ messages in thread
From: Dimitar Dimitrov @ 2023-05-03 17:11 UTC (permalink / raw)
To: binutils; +Cc: Dimitar Dimitrov
A recent GCC commit [1] exposed a latent bug in the PRU default linker
script. The exception-handling sections were not described in the linker
script. When GCC started outputting read-only EH sections, their
contents would erroneously be placed in the instruction memory (IMEM),
which in turn is not readable at runtime. Thus any access to the
read-only exception-handling data results in a runtime crash.
Fix by declaring the EH output sections. Do not split in read-only and
read-write sections because PRU has no true support for rodata. It has
only one memory for data (DMEM).
Tested pru-unknown-elf and found no regressions in Binutils. All GCC
failures caused by [1] are now fixed.
[1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2744dbb9ecf104a113da3a0f39115da4653bb676
ld/ChangeLog:
* scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable
to place at end of DMEM output sections.
(.eh_frame): New output section.
(.gnu_extab): Ditto.
(.gcc_except_table): Ditto.
Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
---
ld/scripttempl/pru.sc | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/ld/scripttempl/pru.sc b/ld/scripttempl/pru.sc
index 8531cb8d5be..3ff86bc61c7 100644
--- a/ld/scripttempl/pru.sc
+++ b/ld/scripttempl/pru.sc
@@ -24,6 +24,12 @@ ENTRY (_start)
EOF
+OUTPUT_SECTION_ALIGN="
+ ${RELOCATING+/* In case this is the last input section,
+ align to keep the loadable segment size a multiple of the common page size.
+ Some SoCs have stricter memory size requirements than others. */
+ . = ALIGN (CONSTANT (COMMONPAGESIZE));}"
+
cat <<EOF
SECTIONS
{
@@ -163,10 +169,25 @@ SECTIONS
${RELOCATING+*(COMMON)}
${RELOCATING+ PROVIDE (_bss_end = .) ; }
- ${RELOCATING+/* In case this is the last input section, align to
- keep the loadable segment size a multiple of the common page size.
- Some SoCs have stricter memory size requirements than others. */
- . = ALIGN (CONSTANT (COMMONPAGESIZE));}
+ ${OUTPUT_SECTION_ALIGN}
+ } ${RELOCATING+ > dmem}
+
+ .eh_frame ${RELOCATING-0} :
+ {
+ KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)}
+ ${OUTPUT_SECTION_ALIGN}
+ } ${RELOCATING+ > dmem}
+
+ .gnu_extab ${RELOCATING-0} :
+ {
+ *(.gnu_extab)
+ ${OUTPUT_SECTION_ALIGN}
+ } ${RELOCATING+ > dmem}
+
+ .gcc_except_table ${RELOCATING-0} :
+ {
+ *(.gcc_except_table${RELOCATING+ .gcc_except_table.*})
+ ${OUTPUT_SECTION_ALIGN}
} ${RELOCATING+ > dmem}
/* Linux remoteproc loader requires the resource_table section
@@ -175,10 +196,7 @@ SECTIONS
.resource_table ${RELOCATING-0} ${RELOCATING+ ALIGN (CONSTANT (MAXPAGESIZE))} :
{
KEEP (*(.resource_table))
- ${RELOCATING+/* In case this is the last input section, align to
- keep the loadable segment size a multiple of the common page size.
- Some SoCs have stricter memory size requirements than others. */
- . = ALIGN (CONSTANT (COMMONPAGESIZE));}
+ ${OUTPUT_SECTION_ALIGN}
} ${RELOCATING+ > dmem}
/* Global data not cleared after reset. */
--
2.40.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ld: pru: Place exception-handling sections correctly
2023-05-03 17:11 [PATCH] ld: pru: Place exception-handling sections correctly Dimitar Dimitrov
@ 2023-05-04 11:43 ` Nick Clifton
0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2023-05-04 11:43 UTC (permalink / raw)
To: Dimitar Dimitrov, binutils
Hi Dimitar,
> A recent GCC commit [1] exposed a latent bug in the PRU default linker
> script. The exception-handling sections were not described in the linker
> script. When GCC started outputting read-only EH sections, their
> contents would erroneously be placed in the instruction memory (IMEM),
> which in turn is not readable at runtime. Thus any access to the
> read-only exception-handling data results in a runtime crash.
>
> Fix by declaring the EH output sections. Do not split in read-only and
> read-write sections because PRU has no true support for rodata. It has
> only one memory for data (DMEM).
Patch approved and applied.
Note - I extended the ChangeLog entry to also mention the updated to the
.data and .resource_table sections.
Cheers
Nick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-04 11:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 17:11 [PATCH] ld: pru: Place exception-handling sections correctly Dimitar Dimitrov
2023-05-04 11:43 ` Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).