From: Dimitar Dimitrov <dimitar@dinux.eu>
To: binutils@sourceware.org
Cc: Dimitar Dimitrov <dimitar@dinux.eu>
Subject: [PATCH] ld: pru: Place exception-handling sections correctly
Date: Wed, 3 May 2023 20:11:24 +0300 [thread overview]
Message-ID: <20230503171124.6710-1-dimitar@dinux.eu> (raw)
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
next reply other threads:[~2023-05-03 17:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-03 17:11 Dimitar Dimitrov [this message]
2023-05-04 11:43 ` Nick Clifton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230503171124.6710-1-dimitar@dinux.eu \
--to=dimitar@dinux.eu \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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).