Skip to content

Commit 2d3181c

Browse files
committed
Add SORT_NONE to .init and .fini in scripts
The special case for .init and .fini in update_wild_statements is ineffective for .init or .fini wildcards inside other output sections. The special case needs to be on the wildcard, not the output section. This patch is belt and braces, both fixing update_wild_statements and the scripts. * scripttempl/alpha.sc, * scripttempl/armbpabi.sc, * scripttempl/crisaout.sc, * scripttempl/elf32cr16.sc, * scripttempl/elf32crx.sc, * scripttempl/elf32xc16x.sc, * scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc, * scripttempl/elf64hppa.sc, * scripttempl/elf_chaos.sc, * scripttempl/elfarc.sc, * scripttempl/elfarcv2.sc, * scripttempl/elfd30v.sc, * scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc, * scripttempl/elfm9s12z.sc, * scripttempl/elfmicroblaze.sc, * scripttempl/elfxgate.sc, * scripttempl/elfxtensa.sc, * scripttempl/epiphany_4x4.sc, * scripttempl/ft32.sc, * scripttempl/i386beos.sc, * scripttempl/iq2000.sc, * scripttempl/mcorepe.sc, * scripttempl/mep.sc, * scripttempl/mips.sc, * scripttempl/moxie.sc, * scripttempl/pe.sc, * scripttempl/pep.sc, * scripttempl/ppcpe.sc, * scripttempl/tic4xcoff.sc, * scripttempl/tic80coff.sc, * scripttempl/v850.sc, * scripttempl/v850_rh850.sc, * scripttempl/visium.sc, * scripttempl/xstormy16.sc: Add KEEP and SORT_NONE to .init and .fini wildcards. * scripttempl/elf32xc16x.sc, * scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc: Add .fini wildcard. * scripttempl/elf_chaos.sc: Add .init output section. * scripttempl/elfd30v.sc: Remove duplicate .init. * scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc, * scripttempl/elfm9s12z.sc, * scripttempl/elfxgate.sc: Remove duplicate .init, and add .fini wildcard. * scripttempl/ppcpe.sc (INIT, FINI): Delete. * ldlang.c (update_wild_statements): Special case .init and .fini in the wildcard, not the output section.
1 parent cc00a5d commit 2d3181c

38 files changed

+119
-86
lines changed

ld/ChangeLog

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2019-03-21 Alan Modra <amodra@gmail.com>
2+
3+
* scripttempl/alpha.sc, * scripttempl/armbpabi.sc,
4+
* scripttempl/crisaout.sc, * scripttempl/elf32cr16.sc,
5+
* scripttempl/elf32crx.sc, * scripttempl/elf32xc16x.sc,
6+
* scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc,
7+
* scripttempl/elf64hppa.sc, * scripttempl/elf_chaos.sc,
8+
* scripttempl/elfarc.sc, * scripttempl/elfarcv2.sc,
9+
* scripttempl/elfd30v.sc, * scripttempl/elfm68hc11.sc,
10+
* scripttempl/elfm68hc12.sc, * scripttempl/elfm9s12z.sc,
11+
* scripttempl/elfmicroblaze.sc, * scripttempl/elfxgate.sc,
12+
* scripttempl/elfxtensa.sc, * scripttempl/epiphany_4x4.sc,
13+
* scripttempl/ft32.sc, * scripttempl/i386beos.sc,
14+
* scripttempl/iq2000.sc, * scripttempl/mcorepe.sc,
15+
* scripttempl/mep.sc, * scripttempl/mips.sc, * scripttempl/moxie.sc,
16+
* scripttempl/pe.sc, * scripttempl/pep.sc, * scripttempl/ppcpe.sc,
17+
* scripttempl/tic4xcoff.sc, * scripttempl/tic80coff.sc,
18+
* scripttempl/v850.sc, * scripttempl/v850_rh850.sc,
19+
* scripttempl/visium.sc, * scripttempl/xstormy16.sc: Add KEEP and
20+
SORT_NONE to .init and .fini wildcards.
21+
* scripttempl/elf32xc16x.sc,
22+
* scripttempl/elf32xc16xl.sc,
23+
* scripttempl/elf32xc16xs.sc: Add .fini wildcard.
24+
* scripttempl/elf_chaos.sc: Add .init output section.
25+
* scripttempl/elfd30v.sc: Remove duplicate .init.
26+
* scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc,
27+
* scripttempl/elfm9s12z.sc, * scripttempl/elfxgate.sc: Remove
28+
duplicate .init, and add .fini wildcard.
29+
* scripttempl/ppcpe.sc (INIT, FINI): Delete.
30+
* ldlang.c (update_wild_statements): Special case .init and
31+
.fini in the wildcard, not the output section.
32+
133
2019-03-21 Alan Modra <amodra@gmail.com>
234

335
* emulparams/elf32lm32fd.sh (DYNAMIC_LINK): Undef.

ld/ldlang.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,7 +3744,9 @@ update_wild_statements (lang_statement_union_type *s)
37443744
case lang_wild_statement_enum:
37453745
for (sec = s->wild_statement.section_list; sec != NULL;
37463746
sec = sec->next)
3747-
{
3747+
/* Don't sort .init/.fini sections. */
3748+
if (strcmp (sec->spec.name, ".init") != 0
3749+
&& strcmp (sec->spec.name, ".fini") != 0)
37483750
switch (sec->spec.sorted)
37493751
{
37503752
case none:
@@ -3761,19 +3763,15 @@ update_wild_statements (lang_statement_union_type *s)
37613763
default:
37623764
break;
37633765
}
3764-
}
37653766
break;
37663767

37673768
case lang_constructors_statement_enum:
37683769
update_wild_statements (constructor_list.head);
37693770
break;
37703771

37713772
case lang_output_section_statement_enum:
3772-
/* Don't sort .init/.fini sections. */
3773-
if (strcmp (s->output_section_statement.name, ".init") != 0
3774-
&& strcmp (s->output_section_statement.name, ".fini") != 0)
3775-
update_wild_statements
3776-
(s->output_section_statement.children.head);
3773+
update_wild_statements
3774+
(s->output_section_statement.children.head);
37773775
break;
37783776

37793777
case lang_group_statement_enum:

ld/scripttempl/alpha.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ SECTIONS
3434
.text : {
3535
${RELOCATING+ _ftext = .;}
3636
${RELOCATING+ __istart = .;}
37-
${RELOCATING+ *(.init)}
37+
${RELOCATING+ KEEP (*(SORT_NONE(.init)))}
3838
${RELOCATING+ LONG (0x6bfa8001)}
3939
${RELOCATING+ eprol = .;}
4040
*(.text)
4141
${RELOCATING+ __fstart = .;}
42-
${RELOCATING+ *(.fini)}
42+
${RELOCATING+ KEEP (*(SORT_NONE(.fini)))}
4343
${RELOCATING+ LONG (0x6bfa8001)}
4444
${RELOCATING+ _etext = .;}
4545
}

ld/scripttempl/armbpabi.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ cat <<EOF
208208
.init ${RELOCATING-0} :
209209
{
210210
${RELOCATING+${INIT_START}}
211-
KEEP (*(.init))
211+
KEEP (*(SORT_NONE(.init)))
212212
${RELOCATING+${INIT_END}}
213213
} =${NOP-0}
214214
.text ${RELOCATING-0} :
@@ -222,7 +222,7 @@ cat <<EOF
222222
.fini ${RELOCATING-0} :
223223
{
224224
${RELOCATING+${FINI_START}}
225-
KEEP (*(.fini))
225+
KEEP (*(SORT_NONE(.fini)))
226226
${RELOCATING+${FINI_END}}
227227
} =${NOP-0}
228228
/* The SymbianOS kernel requires that the PLT go at the end of the

ld/scripttempl/crisaout.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SECTIONS
4242
${CONSTRUCTING+ PROVIDE (___do_global_ctors = .);}
4343
${CONSTRUCTING+ SHORT (0xe1fc); /* push srp */}
4444
${CONSTRUCTING+ SHORT (0xbe7e);}
45-
${CONSTRUCTING+ *(.init)}
45+
${CONSTRUCTING+ KEEP (*(SORT_NONE(.init)))}
4646
${CONSTRUCTING+ SHORT (0x0d3e); /* jump [sp+] */}
4747
${CONSTRUCTING+ PROVIDE (__init__end = .);}
4848
${CONSTRUCTING+ PROVIDE (___init__end = .);}
@@ -52,7 +52,7 @@ SECTIONS
5252
${CONSTRUCTING+ PROVIDE (___do_global_dtors = .);}
5353
${CONSTRUCTING+ SHORT (0xe1fc); /* push srp */}
5454
${CONSTRUCTING+ SHORT (0xbe7e);}
55-
${CONSTRUCTING+ *(.fini)}
55+
${CONSTRUCTING+ KEEP (*(SORT_NONE(.fini)))}
5656
${CONSTRUCTING+ SHORT (0x0d3e); /* jump [sp+] */}
5757
${CONSTRUCTING+ PROVIDE (__fini__end = .);}
5858
${CONSTRUCTING+ ___fini__end = .;}

ld/scripttempl/elf32cr16.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ SECTIONS
6262
.init :
6363
{
6464
__INIT_START = .;
65-
KEEP (*(.init))
65+
KEEP (*(SORT_NONE(.init)))
6666
__INIT_END = .;
6767
}${RELOCATING+ > rom}
6868

6969
.fini :
7070
{
7171
__FINI_START = .;
72-
KEEP (*(.fini))
72+
KEEP (*(SORT_NONE(.fini)))
7373
__FINI_END = .;
7474
}${RELOCATING+ > rom}
7575

ld/scripttempl/elf32crx.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ SECTIONS
5858
.init :
5959
{
6060
__INIT_START = .;
61-
KEEP (*(.init))
61+
KEEP (*(SORT_NONE(.init)))
6262
__INIT_END = .;
6363
} > rom
6464

6565
.fini :
6666
{
6767
__FINI_START = .;
68-
KEEP (*(.fini))
68+
KEEP (*(SORT_NONE(.fini)))
6969
__FINI_END = .;
7070
} > rom
7171

ld/scripttempl/elf32xc16x.sc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ SECTIONS
3838
{
3939
.init :
4040
{
41-
*(.init)
41+
KEEP (*(SORT_NONE(.init)))
42+
${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
4243
} ${RELOCATING+ >introm}
4344

4445
.text :

ld/scripttempl/elf32xc16xl.sc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SECTIONS
4040
} ${RELOCATING+ > vectarea} */
4141
.init :
4242
{
43-
*(.init)
43+
KEEP (*(SORT_NONE(.init)))
44+
${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
4445
} ${RELOCATING+ >introm}
4546

4647
.text :

ld/scripttempl/elf32xc16xs.sc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ SECTIONS
4141
} ${RELOCATING+ > vectarea} */
4242
.init :
4343
{
44-
*(.init)
44+
KEEP (*(SORT_NONE(.init)))
45+
${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
4546
} ${RELOCATING+ >introm}
4647

4748
.text :

0 commit comments

Comments
 (0)