MSP430: Fix alignment of __*_array_start symbols in default linker script
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Fri, 28 Aug 2020 12:56:53 +0000 (13:56 +0100)
committerJozef Lawrynowicz <jozef.l@mittosystems.com>
Fri, 28 Aug 2020 13:01:10 +0000 (14:01 +0100)
commit64b63c2993db8606334f6f0852b4e7bb70b5682a
treeac258fac488e748215125eb78ed3e556e8b627c5
parent87870682f3a7fc29208026dfa4aac75b195cc990
MSP430: Fix alignment of __*_array_start symbols in default linker script

__{preinit,init,fini}_array_start symbols must be word aligned in
linker scripts. If the section preceding the __*_array_start symbol
has an odd size, then a NULL byte will be present between the start
symbol and the .*_array section itself, when the section gets
automatically word-aligned.

This results in a branch to an invalid address when the CRT startup
code tries to run through the functions listed in the array sections.

Some MSP430 linker scripts do not align the __*_array start symbols, so
this added warning will catch that problem and help the user avoid
the potential incorrect execution of the program.

ld/ChangeLog:

* emultempl/msp430.em (input_section_exists): New.
(check_array_section_alignment): New.
(gld${EMULATION_NAME}_finish): New.
* scripttempl/elf32msp430.sc: Add ALIGN directives before the
definition of __*_array_start symbols.
* testsuite/ld-msp430-elf/finiarray-warn.ld: New test.
* testsuite/ld-msp430-elf/finiarray-warn.r: New test.
* testsuite/ld-msp430-elf/initarray-nowarn.ld: New test.
* testsuite/ld-msp430-elf/initarray-warn.ld: New test.
* testsuite/ld-msp430-elf/initarray-warn.r: New test.
* testsuite/ld-msp430-elf/initarray.s: New test.
* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
* testsuite/ld-msp430-elf/preinitarray-warn.ld: New test.
* testsuite/ld-msp430-elf/preinitarray-warn.r: New test.
13 files changed:
ld/ChangeLog
ld/emultempl/msp430.em
ld/scripttempl/elf32msp430.sc
ld/testsuite/ld-msp430-elf/finiarray-warn.ld [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/finiarray-warn.r [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/initarray-nowarn.ld [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/initarray-nowarn.r [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/initarray-warn.ld [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/initarray-warn.r [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/initarray.s [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/msp430-elf.exp
ld/testsuite/ld-msp430-elf/preinitarray-warn.ld [new file with mode: 0644]
ld/testsuite/ld-msp430-elf/preinitarray-warn.r [new file with mode: 0644]