From ab2901c843c2b9226f9319a8242fffbdf002e8bc Mon Sep 17 00:00:00 2001 From: Faraz Shahbazker Date: Sun, 28 Apr 2019 18:17:14 +0000 Subject: [PATCH] Fix order of eh_frame sections in linker scripts The compiler driver positions the linker script at the end of the linker command-line, after crtend.o. As a result, any INPUT objects and archive GROUPs introduced by the linker script are placed after crtend.o and the end-of-frame marker provided by crtend.o ends up in between .eh_frames instead of being at the end. This has always been a problem, but a binutils update to clean-up redundant NULL markers in .eh_frame exposes it as a execution failure in exception-handling tests. This patch re-orders .eh_frames in all MIPS linker scripts so that the one from crtend.o is always placed last. libgloss/ * mips/array.ld: Re-order to place .eh_frame from crtend.o after all other .eh_frame sections. * mips/cfe.ld: Likewise. * mips/ddb-kseg0.ld: Likewise. * mips/ddb.ld: Likewise. * mips/dve.ld: Likewise. * mips/idt.ld: Likewise. * mips/idt32.ld: Likewise. * mips/idt64.ld: Likewise. * mips/jmr3904app.ld: Likewise. * mips/lsi.ld: Likewise. * mips/mti32.ld: Likewise. * mips/mti64.ld: Likewise. * mips/mti64_64.ld: Likewise. * mips/mti64_n32.ld: Likewise. * mips/nullmon.ld: Likewise. * mips/pmon.ld: Likewise. * mips/sde32.ld: Likewise. * mips/sde64.ld: Likewise. --- libgloss/mips/array.ld | 7 ++++++- libgloss/mips/cfe.ld | 8 +++++++- libgloss/mips/ddb-kseg0.ld | 7 ++++++- libgloss/mips/ddb.ld | 7 ++++++- libgloss/mips/dve.ld | 8 +++++++- libgloss/mips/idt.ld | 8 +++++++- libgloss/mips/idt32.ld | 7 ++++++- libgloss/mips/idt64.ld | 7 ++++++- libgloss/mips/jmr3904app.ld | 7 ++++++- libgloss/mips/lsi.ld | 7 ++++++- libgloss/mips/mti32.ld | 7 ++++++- libgloss/mips/mti64.ld | 8 +++++++- libgloss/mips/mti64_64.ld | 8 +++++++- libgloss/mips/mti64_n32.ld | 8 +++++++- libgloss/mips/nullmon.ld | 8 +++++++- libgloss/mips/pmon.ld | 8 +++++++- libgloss/mips/sde32.ld | 8 +++++++- libgloss/mips/sde64.ld | 8 +++++++- 18 files changed, 118 insertions(+), 18 deletions(-) diff --git a/libgloss/mips/array.ld b/libgloss/mips/array.ld index fc4cc8fc2..2bc49c71b 100644 --- a/libgloss/mips/array.ld +++ b/libgloss/mips/array.ld @@ -100,7 +100,12 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/cfe.ld b/libgloss/mips/cfe.ld index 58e8014d7..78fb8533f 100644 --- a/libgloss/mips/cfe.ld +++ b/libgloss/mips/cfe.ld @@ -55,7 +55,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/ddb-kseg0.ld b/libgloss/mips/ddb-kseg0.ld index db3759ea6..74bc1b09c 100644 --- a/libgloss/mips/ddb-kseg0.ld +++ b/libgloss/mips/ddb-kseg0.ld @@ -49,7 +49,12 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/ddb.ld b/libgloss/mips/ddb.ld index 028078353..8fcafd361 100644 --- a/libgloss/mips/ddb.ld +++ b/libgloss/mips/ddb.ld @@ -49,7 +49,12 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/dve.ld b/libgloss/mips/dve.ld index 073d1e9ca..adce60f82 100644 --- a/libgloss/mips/dve.ld +++ b/libgloss/mips/dve.ld @@ -49,7 +49,13 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/idt.ld b/libgloss/mips/idt.ld index 05b39b78d..0d69af452 100644 --- a/libgloss/mips/idt.ld +++ b/libgloss/mips/idt.ld @@ -56,7 +56,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/idt32.ld b/libgloss/mips/idt32.ld index 95555291e..175a98b61 100644 --- a/libgloss/mips/idt32.ld +++ b/libgloss/mips/idt32.ld @@ -58,7 +58,12 @@ SECTIONS .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/idt64.ld b/libgloss/mips/idt64.ld index 4a958202f..bd217e535 100644 --- a/libgloss/mips/idt64.ld +++ b/libgloss/mips/idt64.ld @@ -59,7 +59,12 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/jmr3904app.ld b/libgloss/mips/jmr3904app.ld index 3056a36bf..d5b310918 100644 --- a/libgloss/mips/jmr3904app.ld +++ b/libgloss/mips/jmr3904app.ld @@ -48,7 +48,12 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/lsi.ld b/libgloss/mips/lsi.ld index 839382527..ca64ab927 100644 --- a/libgloss/mips/lsi.ld +++ b/libgloss/mips/lsi.ld @@ -48,7 +48,12 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/mti32.ld b/libgloss/mips/mti32.ld index 2739c620f..41592d12a 100644 --- a/libgloss/mips/mti32.ld +++ b/libgloss/mips/mti32.ld @@ -57,7 +57,12 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/mti64.ld b/libgloss/mips/mti64.ld index 15975ad89..8a47c4760 100644 --- a/libgloss/mips/mti64.ld +++ b/libgloss/mips/mti64.ld @@ -59,7 +59,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/mti64_64.ld b/libgloss/mips/mti64_64.ld index 7a2074f1a..81704f065 100644 --- a/libgloss/mips/mti64_64.ld +++ b/libgloss/mips/mti64_64.ld @@ -62,7 +62,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/mti64_n32.ld b/libgloss/mips/mti64_n32.ld index 4003845e0..6c5380934 100644 --- a/libgloss/mips/mti64_n32.ld +++ b/libgloss/mips/mti64_n32.ld @@ -62,7 +62,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/nullmon.ld b/libgloss/mips/nullmon.ld index c90aed308..14b0d0e59 100644 --- a/libgloss/mips/nullmon.ld +++ b/libgloss/mips/nullmon.ld @@ -50,7 +50,13 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/pmon.ld b/libgloss/mips/pmon.ld index 81fd8ee31..244c1f65b 100644 --- a/libgloss/mips/pmon.ld +++ b/libgloss/mips/pmon.ld @@ -50,7 +50,13 @@ SECTIONS } .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/sde32.ld b/libgloss/mips/sde32.ld index 715639ef5..657f5f31b 100644 --- a/libgloss/mips/sde32.ld +++ b/libgloss/mips/sde32.ld @@ -57,7 +57,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors : diff --git a/libgloss/mips/sde64.ld b/libgloss/mips/sde64.ld index 1bd11f6f8..e3a0f298b 100644 --- a/libgloss/mips/sde64.ld +++ b/libgloss/mips/sde64.ld @@ -59,7 +59,13 @@ SECTIONS _etext = .; .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : { KEEP (*(.eh_frame)) } + .eh_frame : + { + /* The .eh_frame section from the crtend file contains the + end of eh_frame marker and it must be last. */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .eh_frame)) + KEEP (*(.eh_frame)) + } .gcc_except_table : { *(.gcc_except_table) } .jcr : { KEEP (*(.jcr)) } .ctors :