ld: pru: Fix resource_table output section alignment

Message ID 20210928193544.366154-1-dimitar@dinux.eu
State New
Headers show
Series
  • ld: pru: Fix resource_table output section alignment
Related show

Commit Message

Dimitar Dimitrov Sept. 28, 2021, 7:35 p.m.
My commit 261980de18b added alignment for the resource table symbol.
But it is wrong.  The Linux remoteproc driver loads and interprets the
contents of the .resource_table ELF section, not of a table symbol.

Without this patch, if the linker happens to output padding for symbol
alignment, then the resource table contents as viewed by the kernel
loader would "shift" and look corrupted.

I kindly ask this fix to be picked for both trunk and the 2.37 branch.

ld/ChangeLog:

	* scripttempl/pru.sc  (.resource_table): Align the output
	section, not the first symbol.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

---
 ld/scripttempl/pru.sc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

-- 
2.31.1

Comments

Alan Modra via Binutils Sept. 30, 2021, 4:49 a.m. | #1
On Tue, Sep 28, 2021 at 10:35:44PM +0300, Dimitar Dimitrov wrote:
> My commit 261980de18b added alignment for the resource table symbol.

> But it is wrong.  The Linux remoteproc driver loads and interprets the

> contents of the .resource_table ELF section, not of a table symbol.

> 

> Without this patch, if the linker happens to output padding for symbol

> alignment, then the resource table contents as viewed by the kernel

> loader would "shift" and look corrupted.

> 

> I kindly ask this fix to be picked for both trunk and the 2.37 branch.

> 

> ld/ChangeLog:

> 

> 	* scripttempl/pru.sc  (.resource_table): Align the output

> 	section, not the first symbol.


This is OK.  I assume you can commit the patch since I see you have
commits to sim/.

-- 
Alan Modra
Australia Development Lab, IBM
Dimitar Dimitrov Sept. 30, 2021, 7:27 p.m. | #2
On Thu, Sep 30, 2021 at 02:19:10PM +0930, Alan Modra wrote:
> On Tue, Sep 28, 2021 at 10:35:44PM +0300, Dimitar Dimitrov wrote:

> > My commit 261980de18b added alignment for the resource table symbol.

> > But it is wrong.  The Linux remoteproc driver loads and interprets the

> > contents of the .resource_table ELF section, not of a table symbol.

> > 

> > Without this patch, if the linker happens to output padding for symbol

> > alignment, then the resource table contents as viewed by the kernel

> > loader would "shift" and look corrupted.

> > 

> > I kindly ask this fix to be picked for both trunk and the 2.37 branch.

> > 

> > ld/ChangeLog:

> > 

> > 	* scripttempl/pru.sc  (.resource_table): Align the output

> > 	section, not the first symbol.

> 

> This is OK.  I assume you can commit the patch since I see you have

> commits to sim/.

Thank you. I pushed to both 2.37 (a9c3934f6cb) and master (5109a7bd9b8).

Regards,
Dimitar

> 

> -- 

> Alan Modra

> Australia Development Lab, IBM

Patch

diff --git a/ld/scripttempl/pru.sc b/ld/scripttempl/pru.sc
index b2c941b7911..97d8be0a0a4 100644
--- a/ld/scripttempl/pru.sc
+++ b/ld/scripttempl/pru.sc
@@ -151,11 +151,10 @@  SECTIONS
     ${RELOCATING+ PROVIDE (_data_end = .) ; }
   } ${RELOCATING+ > dmem }
 
-  .resource_table ${RELOCATING-0} :
+  /* Linux remoteproc loader requires the resource_table section
+     start address to be aligned to 8 bytes.  */
+  .resource_table ${RELOCATING-0} ${RELOCATING+ ALIGN(8)} :
   {
-    /* Linux remoteproc loader requires the resource table address
-       to be aligned to 8 bytes.  */
-    ${RELOCATING+. = ALIGN(8);}
     KEEP (*(.resource_table))
   } ${RELOCATING+ > dmem}