Index: NEWS =================================================================== RCS file: /cvs/src/src/ld/NEWS,v retrieving revision 1.118 diff -u -r1.118 NEWS --- NEWS 15 Jun 2011 09:12:08 -0000 1.118 +++ NEWS 30 Jun 2011 20:30:03 -0000 @@ -1,5 +1,8 @@ -*- text -*- +* INPUT_SECTION_FLAGS has been added to the linker script language +to allow selection of input sections by section header section flags. + * Add support for the Tilera TILEPRO and TILE-Gx architectures. * Added SORT_BY_INIT_PRIORITY to the linker script language to permit Index: ld.h =================================================================== RCS file: /cvs/src/src/ld/ld.h,v retrieving revision 1.50 diff -u -r1.50 ld.h --- ld.h 20 Apr 2011 12:52:16 -0000 1.50 +++ ld.h 30 Jun 2011 20:30:03 -0000 @@ -96,6 +96,7 @@ const char *name; struct name_list *exclude_name_list; sort_type sorted; + struct flag_info *section_flag_list; }; struct wildcard_list { Index: ld.texinfo =================================================================== RCS file: /cvs/src/src/ld/ld.texinfo,v retrieving revision 1.276 diff -u -r1.276 ld.texinfo --- ld.texinfo 20 Jun 2011 13:18:48 -0000 1.276 +++ ld.texinfo 30 Jun 2011 20:30:03 -0000 @@ -3859,6 +3859,26 @@ data.o(.data) @end smallexample +To refine the sections that are included based on the section flags +of an input section, INPUT_SECTION_FLAGS may be used. + +Here is a simple example for using Section header flags for ELF sections: + +@smallexample +@group +SECTIONS @{ + .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @} + .text2 : @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @} +@} +@end group +@end smallexample + +In this example, the output section @samp{.text} will be comprised of any +input section matching the name *(.text) whose section header flags +@code{SHF_MERGE} and @code{SHF_STRINGS} are set. The output section +@samp{.text2} will be comprised of any input section matching the name *(.text) +whose section header flag @code{SHF_WRITE} is clear. + You can also specify files within archives by writing a pattern matching the archive, a colon, then the pattern matching the file, with no whitespace around the colon. Index: ldgram.y =================================================================== RCS file: /cvs/src/src/ld/ldgram.y,v retrieving revision 1.65 diff -u -r1.65 ldgram.y --- ldgram.y 13 Jan 2011 13:29:55 -0000 1.65 +++ ldgram.y 30 Jun 2011 20:30:03 -0000 @@ -72,6 +72,8 @@ struct wildcard_spec wildcard; struct wildcard_list *wildcard_list; struct name_list *name_list; + struct flag_info_list *flag_info_list; + struct flag_info *flag_info; int token; union etree_union *etree; struct phdr_info @@ -93,6 +95,8 @@ %type fill_opt fill_exp %type exclude_name_list %type file_NAME_list +%type sect_flag_list +%type sect_flags %type memspec_opt casesymlist %type memspec_at_opt %type wildcard_name @@ -150,7 +154,7 @@ %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START %token VERS_TAG VERS_IDENTIFIER %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT -%token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL +%token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS %token EXCLUDE_FILE %token CONSTANT %type vers_defns @@ -437,60 +441,121 @@ $$.name = $1; $$.sorted = none; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name { $$.name = $5; $$.sorted = none; $$.exclude_name_list = $3; + $$.section_flag_list = NULL; } | SORT_BY_NAME '(' wildcard_name ')' { $$.name = $3; $$.sorted = by_name; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_ALIGNMENT '(' wildcard_name ')' { $$.name = $3; $$.sorted = by_alignment; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' { $$.name = $5; $$.sorted = by_name_alignment; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')' { $$.name = $5; $$.sorted = by_name; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')' { $$.name = $5; $$.sorted = by_alignment_name; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' { $$.name = $5; $$.sorted = by_alignment; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; } | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')' { $$.name = $7; $$.sorted = by_name; $$.exclude_name_list = $5; + $$.section_flag_list = NULL; } | SORT_BY_INIT_PRIORITY '(' wildcard_name ')' { $$.name = $3; $$.sorted = by_init_priority; $$.exclude_name_list = NULL; + $$.section_flag_list = NULL; + } + ; + +sect_flag_list: NAME + { + struct flag_info_list *n; + n = ((struct flag_info_list *) xmalloc (sizeof *n)); + if ($1[0] == '!') + { + n->with = without_flags; + n->name = &$1[1]; + } + else + { + n->with = with_flags; + n->name = $1; + } + n->valid = FALSE; + n->next = NULL; + $$ = n; + } + | sect_flag_list '&' NAME + { + struct flag_info_list *n; + n = ((struct flag_info_list *) xmalloc (sizeof *n)); + if ($3[0] == '!') + { + n->with = without_flags; + n->name = &$3[1]; + } + else + { + n->with = with_flags; + n->name = $3; + } + n->valid = FALSE; + n->next = $1; + $$ = n; + } + ; + +sect_flags: + INPUT_SECTION_FLAGS '(' sect_flag_list ')' + { + struct flag_info *n; + n = ((struct flag_info *) xmalloc (sizeof *n)); + n->flag_list = $3; + n->flags_initialized = FALSE; + n->not_with_flags = 0; + n->only_with_flags = 0; + $$ = n; } ; @@ -541,16 +606,40 @@ tmp.name = $1; tmp.exclude_name_list = NULL; tmp.sorted = none; + tmp.section_flag_list = NULL; + lang_add_wild (&tmp, NULL, ldgram_had_keep); + } + | sect_flags NAME + { + struct wildcard_spec tmp; + tmp.name = $2; + tmp.exclude_name_list = NULL; + tmp.sorted = none; + tmp.section_flag_list = $1; lang_add_wild (&tmp, NULL, ldgram_had_keep); } | '[' file_NAME_list ']' { lang_add_wild (NULL, $2, ldgram_had_keep); } + | sect_flags '[' file_NAME_list ']' + { + struct wildcard_spec tmp; + tmp.name = NULL; + tmp.exclude_name_list = NULL; + tmp.sorted = none; + tmp.section_flag_list = $1; + lang_add_wild (NULL, $3, ldgram_had_keep); + } | wildcard_spec '(' file_NAME_list ')' { lang_add_wild (&$1, $3, ldgram_had_keep); } + | sect_flags wildcard_spec '(' file_NAME_list ')' + { + $2.section_flag_list = $1; + lang_add_wild (&$2, $4, ldgram_had_keep); + } ; input_section_spec: Index: ldlang.c =================================================================== RCS file: /cvs/src/src/ld/ldlang.c,v retrieving revision 1.372 diff -u -r1.372 ldlang.c --- ldlang.c 13 Jun 2011 00:59:42 -0000 1.372 +++ ldlang.c 30 Jun 2011 20:30:04 -0000 @@ -237,6 +237,9 @@ { struct name_list *list_tmp; + /* Propagate the section_flag_info from the wild statement to the section. */ + s->section_flag_info = ptr->section_flag_list; + /* Don't process sections from files which were excluded. */ for (list_tmp = sec->spec.exclude_name_list; list_tmp; @@ -2256,8 +2259,11 @@ lang_output_section_statement_type *output) { flagword flags = section->flags; + struct flag_info *sflag_info = section->section_flag_info; + bfd_boolean discard; lang_input_section_type *new_section; + bfd *abfd = link_info.output_bfd; /* Discard sections marked with SEC_EXCLUDE. */ discard = (flags & SEC_EXCLUDE) != 0; @@ -2283,6 +2289,28 @@ return; } + if (sflag_info) + { + if (sflag_info->flags_initialized == FALSE) + bfd_lookup_section_flags (&link_info, sflag_info); + + if (sflag_info->only_with_flags != 0 + && sflag_info->not_with_flags != 0 + && ((sflag_info->not_with_flags & flags) != 0 + || (sflag_info->only_with_flags & flags) + != sflag_info->only_with_flags)) + return; + + if (sflag_info->only_with_flags != 0 + && (sflag_info->only_with_flags & flags) + != sflag_info->only_with_flags) + return; + + if (sflag_info->not_with_flags != 0 + && (sflag_info->not_with_flags & flags) != 0) + return; + } + if (section->output_section != NULL) return; @@ -6713,10 +6741,12 @@ new_stmt = new_stat (lang_wild_statement, stat_ptr); new_stmt->filename = NULL; new_stmt->filenames_sorted = FALSE; + new_stmt->section_flag_list = NULL; if (filespec != NULL) { new_stmt->filename = filespec->name; new_stmt->filenames_sorted = filespec->sorted == by_name; + new_stmt->section_flag_list = filespec->section_flag_list; } new_stmt->section_list = section_list; new_stmt->keep_sections = keep_sections; Index: ldlang.h =================================================================== RCS file: /cvs/src/src/ld/ldlang.h,v retrieving revision 1.97 diff -u -r1.97 ldlang.h --- ldlang.h 3 May 2011 14:56:14 -0000 1.97 +++ ldlang.h 30 Jun 2011 20:30:04 -0000 @@ -240,6 +240,8 @@ bfd *the_bfd; + struct flag_info *section_flag_list; + /* Point to the next file - whatever it is, wanders up and down archives */ union lang_statement_union *next; @@ -337,6 +339,7 @@ walk_wild_section_handler_t walk_wild_section_handler; struct wildcard_list *handler_data[4]; lang_section_bst_type *tree; + struct flag_info *section_flag_list; }; typedef struct lang_address_statement_struct Index: ldlex.l =================================================================== RCS file: /cvs/src/src/ld/ldlex.l,v retrieving revision 1.52 diff -u -r1.52 ldlex.l --- ldlex.l 29 Mar 2011 02:52:36 -0000 1.52 +++ ldlex.l 30 Jun 2011 20:30:04 -0000 @@ -313,6 +313,7 @@ "org" { RTOKEN(ORIGIN);} "l" { RTOKEN( LENGTH);} "len" { RTOKEN( LENGTH);} +"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); } "INCLUDE" { RTOKEN(INCLUDE);} "PHDRS" { RTOKEN (PHDRS); } "AT" { RTOKEN(AT);} Index: mri.c =================================================================== RCS file: /cvs/src/src/ld/mri.c,v retrieving revision 1.24 diff -u -r1.24 mri.c --- mri.c 13 Jan 2011 13:06:22 -0000 1.24 +++ mri.c 30 Jun 2011 20:30:04 -0000 @@ -215,6 +215,7 @@ tmp->spec.name = p->name; tmp->spec.exclude_name_list = NULL; tmp->spec.sorted = none; + tmp->spec.section_flag_list = NULL; lang_add_wild (NULL, tmp, FALSE); /* If there is an alias for this section, add it too. */ @@ -226,6 +227,7 @@ tmp->spec.name = aptr->name; tmp->spec.exclude_name_list = NULL; tmp->spec.sorted = none; + tmp->spec.section_flag_list = NULL; lang_add_wild (NULL, tmp, FALSE); } Index: testsuite/ChangeLog =================================================================== RCS file: /cvs/src/src/ld/testsuite/ChangeLog,v retrieving revision 1.1436 diff -u -r1.1436 ChangeLog --- testsuite/ChangeLog 27 Jun 2011 15:02:55 -0000 1.1436 +++ testsuite/ChangeLog 30 Jun 2011 20:30:04 -0000 @@ -1,3 +1,11 @@ +2011-06-30 Catherine Moore + + * ld-scripts/section-flags-1.s: New. + * ld-scripts/section-flags-1.t: New. + * ld-scripts/section-flags-2.s: New. + * ld-scripts/section-flags-2.t: New. + * ld-scripts/section-flags.exp: New. + 2011-06-27 Nick Clifton * ld-elf/elf.exp: Exlcude all v850 targets from note-3 test. Index: testsuite/ld-scripts/section-flags-1.s =================================================================== RCS file: testsuite/ld-scripts/section-flags-1.s diff -N testsuite/ld-scripts/section-flags-1.s --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/ld-scripts/section-flags-1.s 30 Jun 2011 20:30:04 -0000 @@ -0,0 +1,2 @@ + .text + .space 16 Index: testsuite/ld-scripts/section-flags-1.t =================================================================== RCS file: testsuite/ld-scripts/section-flags-1.t diff -N testsuite/ld-scripts/section-flags-1.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/ld-scripts/section-flags-1.t 30 Jun 2011 20:30:04 -0000 @@ -0,0 +1,21 @@ +MEMORY +{ + ram (rwx) : ORIGIN = 0x100000, LENGTH = 144M +} + +SECTIONS +{ + .text : + { + INPUT_SECTION_FLAGS (!SHF_TLS) *(.text .text.* .text_* .gnu.linkonce.t.*) + } >ram + + .text_vle : + { + INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS & SHF_LINK_ORDER) *(.text .text.* .text_* .gnu.linkonce.t.*) + } >ram + .text_other : + { + INPUT_SECTION_FLAGS (SHF_MERGE & !SHF_STRINGS) *(.text .text.* .text_* .gnu.linkonce.t.*) + } +} Index: testsuite/ld-scripts/section-flags-2.s =================================================================== RCS file: testsuite/ld-scripts/section-flags-2.s diff -N testsuite/ld-scripts/section-flags-2.s --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/ld-scripts/section-flags-2.s 30 Jun 2011 20:30:04 -0000 @@ -0,0 +1,2 @@ + .text + .space 16 Index: testsuite/ld-scripts/section-flags-2.t =================================================================== RCS file: testsuite/ld-scripts/section-flags-2.t diff -N testsuite/ld-scripts/section-flags-2.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/ld-scripts/section-flags-2.t 30 Jun 2011 20:30:04 -0000 @@ -0,0 +1,12 @@ +MEMORY +{ + ram (rwx) : ORIGIN = 0x100000, LENGTH = 144M +} + +SECTIONS +{ + .text : + { + INPUT_SECTION_FLAGS (!SHF_TLS) *(EXCLUDE_FILE (section-flags-1.o) .text .text.* .text_* .gnu.linkonce.t.*) + } >ram +} Index: testsuite/ld-scripts/section-flags.exp =================================================================== RCS file: testsuite/ld-scripts/section-flags.exp diff -N testsuite/ld-scripts/section-flags.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/ld-scripts/section-flags.exp 30 Jun 2011 20:30:04 -0000 @@ -0,0 +1,52 @@ +# Test SECTION_FLAGS in a linker script. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +set testname "SECTION_FLAGS-1" + + +# This test only works for ELF targets +if {! [is_elf_format]} { + unsupported $testname + return +} + +if ![ld_assemble $as $srcdir/$subdir/section-flags-1.s tmpdir/section-flags-1.o] { + unresolved $testname + return +} + +if ![ld_simple_link $ld tmpdir/section-flags-1 "-T $srcdir/$subdir/section-flags-1.t tmpdir/section-flags-1.o"] { + fail $testname + return +} + +pass $testname + +set testname "SECTION_FLAGS-2" +if ![ld_assemble $as $srcdir/$subdir/section-flags-2.s tmpdir/section-flags-2.o] { + unresolved $testname + return +} + +if ![ld_simple_link $ld tmpdir/section-flags-2 "-T $srcdir/$subdir/section-flags-2.t tmpdir/section-flags-1.o tmpdir/section-flags-2.o"] { + fail $testname + return +} + +pass $testname