Add SORT_NONE and don't sort sort .init/.fini sections

ld/

	PR ld/14156
	* NEWS: Mention SORT_NONE.

	* ld.h (sort_type): Add by_none.

	* ld.texinfo: Document SORT_NONE.

	* ldgram.y: Handle SORT_NONE.

	* ldlang.c (update_wild_statements): Handle by_none.  Don't
	sort .init/.fini sections.

	* ldlex.l: Add SORT_NONE.

ld/testsuite/

	PR ld/14156
	* ld-elf/fini0.s: New file.
	* ld-elf/fini1.s: Likewise.
	* ld-elf/fini2.s: Likewise.
	* ld-elf/fini3.s: Likewise.
	* ld-elf/finin.s: Likewise.
	* ld-elf/foo0.s: Likewise.
	* ld-elf/foo1.s: Likewise.
	* ld-elf/foo2.s: Likewise.
	* ld-elf/foo3.s: Likewise.
	* ld-elf/foon.s: Likewise.
	* ld-elf/init0.s: Likewise.
	* ld-elf/init1.s: Likewise.
	* ld-elf/init2.s: Likewise.
	* ld-elf/init3.s: Likewise.
	* ld-elf/initn.s: Likewise.
	* ld-elf/pr14156a.d: Likewise.
	* ld-elf/pr14156b.d: Likewise.
	* ld-elf/pr14156c.d: Likewise.
	* ld-elf/pr14156c.t: Likewise.
This commit is contained in:
H.J. Lu 2012-07-10 06:50:57 +00:00
parent bc9ad2e430
commit eda680f805
27 changed files with 231 additions and 4 deletions

View File

@ -1,3 +1,19 @@
2012-07-10 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14156
* NEWS: Mention SORT_NONE.
* ld.h (sort_type): Add by_none.
* ld.texinfo: Document SORT_NONE.
* ldgram.y: Handle SORT_NONE.
* ldlang.c (update_wild_statements): Handle by_none. Don't
sort .init/.fini sections.
* ldlex.l: Add SORT_NONE.
2012-07-02 H.J. Lu <hongjiu.lu@intel.com>
* ld.texinfo: Replace __end_SECNAME with __stop_SECNAME.

View File

@ -1,5 +1,7 @@
-*- text -*-
* Added SORT_NONE to the linker script language to disable section sorting.
* Add a linker-provided symbol when producing ELF output, '__ehdr_start'
to point to the ELF file header (and nearby program headers) in the
program's memory image.

View File

@ -87,7 +87,7 @@ typedef enum {sort_none, sort_ascending, sort_descending} sort_order;
typedef enum {
none, by_name, by_alignment, by_name_alignment, by_alignment_name,
by_init_priority
by_none, by_init_priority
} sort_type;
extern sort_type sort_section;

View File

@ -4038,6 +4038,10 @@ treated as nested sorting command.
If the section sorting command in linker script is nested, the
command line option will be ignored.
@cindex SORT_NONE
@code{SORT_NONE} disables section sorting by ignoring the command line
section sorting option.
If you ever get confused about where input sections are going, use the
@samp{-M} linker option to generate a map file. The map file shows
precisely how input sections are mapped to output sections.

View File

@ -129,7 +129,7 @@ static int error_index;
%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
%token SECTIONS PHDRS INSERT_K AFTER BEFORE
%token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
%token SORT_BY_NAME SORT_BY_ALIGNMENT
%token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
%token SORT_BY_INIT_PRIORITY
%token '{' '}'
%token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
@ -467,6 +467,13 @@ wildcard_spec:
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_NONE '(' wildcard_name ')'
{
$$.name = $3;
$$.sorted = by_none;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
{
$$.name = $5;

View File

@ -3510,6 +3510,8 @@ update_wild_statements (lang_statement_union_type *s)
if (sort_section == by_name)
sec->spec.sorted = by_alignment_name;
break;
case by_none:
sec->spec.sorted = none;
default:
break;
}
@ -3521,6 +3523,9 @@ update_wild_statements (lang_statement_union_type *s)
break;
case lang_output_section_statement_enum:
/* Don't sort .init/.fini sections. */
if (strcmp (s->output_section_statement.name, ".init") != 0
&& strcmp (s->output_section_statement.name, ".fini") != 0)
update_wild_statements
(s->output_section_statement.children.head);
break;

View File

@ -302,6 +302,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<BOTH,SCRIPT>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); }
<BOTH,SCRIPT>"SORT" { RTOKEN(SORT_BY_NAME); }
<BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); }
<BOTH,SCRIPT>"SORT_NONE" { RTOKEN(SORT_NONE); }
<EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
<EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
<EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}

View File

@ -1,3 +1,26 @@
2012-07-10 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14156
* ld-elf/fini0.s: New file.
* ld-elf/fini1.s: Likewise.
* ld-elf/fini2.s: Likewise.
* ld-elf/fini3.s: Likewise.
* ld-elf/finin.s: Likewise.
* ld-elf/foo0.s: Likewise.
* ld-elf/foo1.s: Likewise.
* ld-elf/foo2.s: Likewise.
* ld-elf/foo3.s: Likewise.
* ld-elf/foon.s: Likewise.
* ld-elf/init0.s: Likewise.
* ld-elf/init1.s: Likewise.
* ld-elf/init2.s: Likewise.
* ld-elf/init3.s: Likewise.
* ld-elf/initn.s: Likewise.
* ld-elf/pr14156a.d: Likewise.
* ld-elf/pr14156b.d: Likewise.
* ld-elf/pr14156c.d: Likewise.
* ld-elf/pr14156c.t: Likewise.
2012-07-09 H.J. Lu <hongjiu.lu@intel.com>
PR ld/14323

View File

@ -0,0 +1,16 @@
.text
.global start /* Used by SH targets. */
start:
.global _start
_start:
.global __start
__start:
.global main /* Used by HPPA targets. */
main:
.dc.a 0
.section .fini
.p2align 2
.globl foo
.type foo,%function
foo:

View File

@ -0,0 +1,6 @@
.section .fini
.p2align 2
.type foo1,%function
foo1:
.dc.a 0x0
.size foo1,.-foo1

View File

@ -0,0 +1,6 @@
.section .fini
.p2align 6
.type foo2,%function
foo2:
.dc.a 0x0
.size foo2,.-foo2

View File

@ -0,0 +1,6 @@
.section .fini
.p2align 4
.type foo3,%function
foo3:
.dc.a 0x0
.size foo3,.-foo3

View File

@ -0,0 +1,6 @@
.section .fini
.p2align 8
.type last,%function
last:
.dc.a 0x0
.size last,.-last

View File

@ -0,0 +1,16 @@
.text
.global start /* Used by SH targets. */
start:
.global _start
_start:
.global __start
__start:
.global main /* Used by HPPA targets. */
main:
.dc.a 0
.section .foo,"ax",@progbits
.p2align 2
.globl foo
.type foo,%function
foo:

View File

@ -0,0 +1,6 @@
.section .foo,"ax",@progbits
.p2align 2
.type foo1,%function
foo1:
.dc.a 0x0
.size foo1,.-foo1

View File

@ -0,0 +1,6 @@
.section .foo,"ax",@progbits
.p2align 6
.type foo2,%function
foo2:
.dc.a 0x0
.size foo2,.-foo2

View File

@ -0,0 +1,6 @@
.section .foo,"ax",@progbits
.p2align 4
.type foo3,%function
foo3:
.dc.a 0x0
.size foo3,.-foo3

View File

@ -0,0 +1,6 @@
.section .foo,"ax",@progbits
.p2align 8
.type last,%function
last:
.dc.a 0x0
.size last,.-last

View File

@ -0,0 +1,16 @@
.text
.global start /* Used by SH targets. */
start:
.global _start
_start:
.global __start
__start:
.global main /* Used by HPPA targets. */
main:
.dc.a 0
.section .init
.p2align 2
.globl foo
.type foo,%function
foo:

View File

@ -0,0 +1,6 @@
.section .init
.p2align 2
.type foo1,%function
foo1:
.dc.a 0x0
.size foo1,.-foo1

View File

@ -0,0 +1,6 @@
.section .init
.p2align 6
.type foo2,%function
foo2:
.dc.a 0x0
.size foo2,.-foo2

View File

@ -0,0 +1,6 @@
.section .init
.p2align 4
.type foo3,%function
foo3:
.dc.a 0x0
.size foo3,.-foo3

View File

@ -0,0 +1,6 @@
.section .init
.p2align 8
.type last,%function
last:
.dc.a 0x0
.size last,.-last

View File

@ -0,0 +1,15 @@
#source: init0.s
#source: init1.s
#source: init2.s
#source: init3.s
#source: initn.s
#ld: --sort-section=alignment
#nm: -n
#...
[0-9a-f]+ T foo
[0-9a-f]+ t foo1
[0-9a-f]+ t foo2
[0-9a-f]+ t foo3
[0-9a-f]+ t last
#pass

View File

@ -0,0 +1,15 @@
#source: fini0.s
#source: fini1.s
#source: fini2.s
#source: fini3.s
#source: finin.s
#ld: --sort-section=alignment
#nm: -n
#...
[0-9a-f]+ T foo
[0-9a-f]+ t foo1
[0-9a-f]+ t foo2
[0-9a-f]+ t foo3
[0-9a-f]+ t last
#pass

View File

@ -0,0 +1,15 @@
#source: foo0.s
#source: foo1.s
#source: foo2.s
#source: foo3.s
#source: foon.s
#ld: --sort-section=alignment -T pr14156c.t
#nm: -n
#...
[0-9a-f]+ T foo
[0-9a-f]+ t foo1
[0-9a-f]+ t foo2
[0-9a-f]+ t foo3
[0-9a-f]+ t last
#pass

View File

@ -0,0 +1,4 @@
SECTIONS {
.foo : { *(SORT_NONE(.foo)) }
/DISCARD/ : { *(.*) }
}