Browse Source
__{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.
gdb-10-branch
13 changed files with 320 additions and 1 deletions
@ -0,0 +1,46 @@ |
|||
/* Script for ld testsuite */ |
|||
OUTPUT_ARCH(msp430) |
|||
ENTRY(_start) |
|||
|
|||
SECTIONS |
|||
{ |
|||
.text : |
|||
{ |
|||
PROVIDE (_start = .); |
|||
. = ALIGN(2); |
|||
*(.text .stub .text.* .gnu.linkonce.t.* .text:*) |
|||
} |
|||
|
|||
.rodata : |
|||
{ |
|||
*(.rodata.* .rodata) |
|||
. = ALIGN(2); |
|||
PROVIDE (__preinit_array_start = .); |
|||
KEEP (*(SORT(.preinit_array.*))) |
|||
KEEP (*(.preinit_array)) |
|||
PROVIDE (__preinit_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__init_array_start = .); |
|||
KEEP (*(SORT(.init_array.*))) |
|||
KEEP (*(.init_array)) |
|||
PROVIDE (__init_array_end = .); |
|||
. = ALIGN(2); |
|||
. += 1; |
|||
PROVIDE (__fini_array_start = .); |
|||
KEEP (*(SORT(.fini_array.*))) |
|||
KEEP (*(.fini_array)) |
|||
PROVIDE (__fini_array_end = .); |
|||
} |
|||
|
|||
.data : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.data.* .data) |
|||
} |
|||
|
|||
.bss : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.bss.* .bss) |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
.*warning: "__fini_array_start" symbol \(finiarray-warn.ld\) is not word aligned |
|||
@ -0,0 +1,45 @@ |
|||
/* Script for ld testsuite */ |
|||
OUTPUT_ARCH(msp430) |
|||
ENTRY(_start) |
|||
|
|||
SECTIONS |
|||
{ |
|||
.text : |
|||
{ |
|||
PROVIDE (_start = .); |
|||
. = ALIGN(2); |
|||
*(.text .stub .text.* .gnu.linkonce.t.* .text:*) |
|||
} |
|||
|
|||
.rodata : |
|||
{ |
|||
*(.rodata.* .rodata) |
|||
. = ALIGN(2); |
|||
PROVIDE (__preinit_array_start = .); |
|||
KEEP (*(SORT(.preinit_array.*))) |
|||
KEEP (*(.preinit_array)) |
|||
PROVIDE (__preinit_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__init_array_start = .); |
|||
KEEP (*(SORT(.init_array.*))) |
|||
KEEP (*(.init_array)) |
|||
PROVIDE (__init_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__fini_array_start = .); |
|||
KEEP (*(SORT(.fini_array.*))) |
|||
KEEP (*(.fini_array)) |
|||
PROVIDE (__fini_array_end = .); |
|||
} |
|||
|
|||
.data : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.data.* .data) |
|||
} |
|||
|
|||
.bss : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.bss.* .bss) |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/* Script for ld testsuite */ |
|||
OUTPUT_ARCH(msp430) |
|||
ENTRY(_start) |
|||
|
|||
SECTIONS |
|||
{ |
|||
.text : |
|||
{ |
|||
PROVIDE (_start = .); |
|||
. = ALIGN(2); |
|||
*(.text .stub .text.* .gnu.linkonce.t.* .text:*) |
|||
} |
|||
|
|||
.rodata : |
|||
{ |
|||
*(.rodata.* .rodata) |
|||
. = ALIGN(2); |
|||
PROVIDE (__preinit_array_start = .); |
|||
KEEP (*(SORT(.preinit_array.*))) |
|||
KEEP (*(.preinit_array)) |
|||
PROVIDE (__preinit_array_end = .); |
|||
. = ALIGN(2); |
|||
. += 1; |
|||
PROVIDE (__init_array_start = .); |
|||
KEEP (*(SORT(.init_array.*))) |
|||
KEEP (*(.init_array)) |
|||
PROVIDE (__init_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__fini_array_start = .); |
|||
KEEP (*(SORT(.fini_array.*))) |
|||
KEEP (*(.fini_array)) |
|||
PROVIDE (__fini_array_end = .); |
|||
} |
|||
|
|||
.data : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.data.* .data) |
|||
} |
|||
|
|||
.bss : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.bss.* .bss) |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
.*warning: "__init_array_start" symbol \(initarray-warn.ld\) is not word aligned |
|||
@ -0,0 +1,21 @@ |
|||
.text |
|||
.section .preinit_array,"aw" |
|||
.short 42 |
|||
|
|||
.section .init_array,"aw" |
|||
.short 43 |
|||
|
|||
.section .fini_array,"aw" |
|||
.short 44 |
|||
|
|||
.text |
|||
.global main |
|||
.type main, @function |
|||
main: |
|||
MOV #__preinit_array_start, R8 |
|||
MOV #__init_array_start, R9 |
|||
MOV #__fini_array_start, R10 |
|||
CALL @R8 |
|||
CALL @R9 |
|||
CALL @R10 |
|||
RET |
|||
@ -0,0 +1,46 @@ |
|||
/* Script for ld testsuite */ |
|||
OUTPUT_ARCH(msp430) |
|||
ENTRY(_start) |
|||
|
|||
SECTIONS |
|||
{ |
|||
.text : |
|||
{ |
|||
PROVIDE (_start = .); |
|||
. = ALIGN(2); |
|||
*(.text .stub .text.* .gnu.linkonce.t.* .text:*) |
|||
} |
|||
|
|||
.rodata : |
|||
{ |
|||
*(.rodata.* .rodata) |
|||
. = ALIGN(2); |
|||
. += 1; |
|||
PROVIDE (__preinit_array_start = .); |
|||
KEEP (*(SORT(.preinit_array.*))) |
|||
KEEP (*(.preinit_array)) |
|||
PROVIDE (__preinit_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__init_array_start = .); |
|||
KEEP (*(SORT(.init_array.*))) |
|||
KEEP (*(.init_array)) |
|||
PROVIDE (__init_array_end = .); |
|||
. = ALIGN(2); |
|||
PROVIDE (__fini_array_start = .); |
|||
KEEP (*(SORT(.fini_array.*))) |
|||
KEEP (*(.fini_array)) |
|||
PROVIDE (__fini_array_end = .); |
|||
} |
|||
|
|||
.data : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.data.* .data) |
|||
} |
|||
|
|||
.bss : |
|||
{ |
|||
. = ALIGN(2); |
|||
*(.bss.* .bss) |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
.*warning: "__preinit_array_start" symbol \(preinitarray-warn.ld\) is not word aligned |
|||
Loading…
Reference in new issue