public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Linker script extension SECTION_FLAGS
@ 2011-05-18 19:32 Catherine Moore
  2011-05-18 19:33 ` Catherine Moore
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Catherine Moore @ 2011-05-18 19:32 UTC (permalink / raw)
  To: binutils; +Cc: Catherine Moore

[-- Attachment #1: Type: text/plain, Size: 3724 bytes --]

This patch extends the linker script language to include SECTION_FLAGS 
on an output section statement.  The purpose of the flags is to ensure 
that all input sections assigned to the output section either have the 
flags set or cleared.

This version of the patch sets the infrastructure but does not define a 
backend implementation.  I will provide that along with additional 
testcases when I contribute the Powerpc VLE port.

This patch was originally discussed in the thread beginning here:
http://sourceware.org/ml/binutils/2011-04/msg00428.html

Does this look okay to install?

Thanks,
Catherine


2011-05-18  Catherine Moore  <clm@codesourcery.com>

       	include/
   	* bfdlink.h (flag_type): New enumeration.
         (flag_info_list): New structure.
         (flag_info): New structure.

	ld/
	* ld.texinfo: Document usage of SECTION_FLAGS.
	* ldgram.y (section): Recognize sect_flags.
	(sect_flags): New rule.
	(sect_flag_list): New rule.
	* ldlang.c (lang_add_section): Check section flags.
	(lang_enter_output_section_statement): Add argument sflags.
	Initialize sflags field in output statement.
	* ldlang.h (lang_output_section_statement_type): Add flag_info field.
	(lang_enter_output_section_statement): New argument sflags.  Update
	all callers.
	* ldlex.l (SECTION_FLAGS): New token.A
	* mri.c (mri_draw_tree): Update argument list for
	land_enter_output_section_statement.

	ld/testsuite/
	* ld-scripts/section-flags-1.exp: New.
         * ld-scripts/section-flags-1.s: New.
         * ld-scripts/section-flags-1.t: New.

	bfd/
	2011-05-18  Catherine Moore  <clm@codesourcery.com>

         * bfd-in2.h: Regenerated.
         * bfd.c (bfd_lookup_section_flags): New definition.
         * binary.c (binary_bfd_lookup_section_flags): New definition.
         * coff-rs6000.c (rs6000coff_vec): Include
         bfd_generic_lookup_section_flags.
         (pmac_xcoff_vec): Likewise.
         * coffcode.h (coff_bfd_lookup_section_flags): New definition.
         * elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
         (bfd_elf_lookup_section_flags): Declare.
         * elflink.c (bfd_elf_lookup_section_flags): New function.
         * elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
         (elf_backend_lookup_section_flags_hook): Define.
         (elf_backend_data): Add elf_backend_lookup_section_flags_hook.
         * ieee.c (ieee_bfd_lookup_section_flags): New define.
         * ihex.c (ihex_bfd_lookup_section_flags): New define.
         * libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
         (bfd_generic_lookup_section_flags): Declare.
         * libbfd.h: Regenerated.
         * mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
         * mmo.c (mmo_fd_lookup_section_flags): New definition.
         * oasys.c (oasys_bfd_lookup_section_flags): New definition.
         * pef.c (bfd_pef_bfd_lookup_section_flags): New definition.
         * plugin.c (bfd_plugin_bfd_lookup_section_flags): New definition.
         * ppcboot.c (ppcboot_bfd_lookup_section_flags): New definition.
         * reloc.c (bfd_generic_lookup_section_flags): New function.
         * som.c (som_bfd_lookup_section_flags): New definition.
         * srec.c (srec_bfd_lookup_section_flags): New definition.
         * targets.c (flag_info): Declare.
         (NAME##_bfd_lookup_section_flags): Add to LINK jump table.
         (_bfd_lookup_section_flags): New.
         * tekhex.c (tekhex_bfd_lookup_section_flags): New definition.
         * versados.c (versados_bfd_lookup_section_flags): New definition.
         * vms-alpha.c (alpha_vms_bfd_lookup_section_flag): New definition.
         * xsym.c (bfd_sym_bfd_lookup_section_flags): New definition.





[-- Attachment #2: sf.patch --]
[-- Type: text/x-patch, Size: 36545 bytes --]

Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.537
diff -u -p -r1.537 bfd-in2.h
--- bfd/bfd-in2.h	9 May 2011 13:23:24 -0000	1.537
+++ bfd/bfd-in2.h	18 May 2011 19:14:52 -0000
@@ -5394,6 +5394,9 @@ bfd_boolean bfd_set_private_flags (bfd *
 #define bfd_gc_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 
+#define bfd_lookup_section_flags(abfd, flag_info) \
+       BFD_SEND (abfd, _bfd_lookup_section_flags, (abfd, flag_info))
+
 #define bfd_merge_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 
@@ -5550,6 +5553,9 @@ enum bfd_endian { BFD_ENDIAN_BIG, BFD_EN
 /* Forward declaration.  */
 typedef struct bfd_link_info _bfd_link_info;
 
+/* Forward declaration.  */
+typedef struct flag_info flag_info;
+
 typedef struct bfd_target
 {
   /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
@@ -5815,6 +5821,7 @@ typedef struct bfd_target
   NAME##_bfd_final_link, \
   NAME##_bfd_link_split_section, \
   NAME##_bfd_gc_sections, \
+  NAME##_bfd_lookup_section_flags, \
   NAME##_bfd_merge_sections, \
   NAME##_bfd_is_group_section, \
   NAME##_bfd_discard_group, \
@@ -5859,6 +5866,9 @@ typedef struct bfd_target
   /* Remove sections that are not referenced from the output.  */
   bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 
+  /* Remove sections with incorrect flags.  */
+  void (*_bfd_lookup_section_flags) (bfd *, struct flag_info *);
+
   /* Attempt to merge SEC_MERGE sections.  */
   bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.116
diff -u -p -r1.116 bfd.c
--- bfd/bfd.c	17 Apr 2011 23:15:11 -0000	1.116
+++ bfd/bfd.c	18 May 2011 19:14:52 -0000
@@ -1373,6 +1373,9 @@ DESCRIPTION
 .#define bfd_gc_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 .
+.#define bfd_lookup_section_flags(abfd, flag_info) \
+.	BFD_SEND (abfd, _bfd_lookup_section_flags, (abfd, flag_info))
+.
 .#define bfd_merge_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 .
Index: bfd/binary.c
===================================================================
RCS file: /cvs/src/src/bfd/binary.c,v
retrieving revision 1.39
diff -u -p -r1.39 binary.c
--- bfd/binary.c	23 Nov 2009 14:41:28 -0000	1.39
+++ bfd/binary.c	18 May 2011 19:14:52 -0000
@@ -299,6 +299,7 @@ binary_sizeof_headers (bfd *abfd ATTRIBU
 #define binary_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define binary_bfd_relax_section                   bfd_generic_relax_section
 #define binary_bfd_gc_sections                     bfd_generic_gc_sections
+#define binary_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define binary_bfd_merge_sections                  bfd_generic_merge_sections
 #define binary_bfd_is_group_section                bfd_generic_is_group_section
 #define binary_bfd_discard_group                   bfd_generic_discard_group
Index: bfd/coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.101
diff -u -p -r1.101 coff-rs6000.c
--- bfd/coff-rs6000.c	18 May 2011 07:58:30 -0000	1.101
+++ bfd/coff-rs6000.c	18 May 2011 19:14:53 -0000
@@ -4101,6 +4101,7 @@ const bfd_target rs6000coff_vec =
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
@@ -4354,6 +4355,7 @@ const bfd_target pmac_xcoff_vec =
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.178
diff -u -p -r1.178 coffcode.h
--- bfd/coffcode.h	18 May 2011 07:58:31 -0000	1.178
+++ bfd/coffcode.h	18 May 2011 19:14:53 -0000
@@ -5652,6 +5652,10 @@ static bfd_coff_backend_data ticoff1_swa
 #define coff_bfd_gc_sections		    bfd_generic_gc_sections
 #endif
 
+#ifndef coff_bfd_lookup_section_flags
+#define coff_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
+#endif
+
 #ifndef coff_bfd_merge_sections
 #define coff_bfd_merge_sections		    bfd_generic_merge_sections
 #endif
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.318
diff -u -p -r1.318 elf-bfd.h
--- bfd/elf-bfd.h	20 Apr 2011 08:51:56 -0000	1.318
+++ bfd/elf-bfd.h	18 May 2011 19:14:53 -0000
@@ -1114,6 +1114,10 @@ struct elf_backend_data
   char *(*elf_backend_write_core_note)
     (bfd *abfd, char *buf, int *bufsiz, int note_type, ...);
 
+  /* This function, if defined, is called to the section flag hex value.  */
+  void (*elf_backend_lookup_section_flags_hook)
+    (struct flag_info *);
+
   /* This function returns class of a reloc type.  */
   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
     (const Elf_Internal_Rela *);
@@ -2192,6 +2196,8 @@ extern bfd_boolean _bfd_elf_is_function_
 
 extern int bfd_elf_get_default_section_type (flagword);
 
+extern void bfd_elf_lookup_section_flags (bfd *, struct flag_info *);
+
 extern Elf_Internal_Phdr * _bfd_elf_find_segment_containing_section
   (bfd * abfd, asection * section);
 
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.405
diff -u -p -r1.405 elflink.c
--- bfd/elflink.c	18 May 2011 14:04:31 -0000	1.405
+++ bfd/elflink.c	18 May 2011 19:14:53 -0000
@@ -12162,6 +12162,17 @@ bfd_elf_gc_record_vtentry (bfd *abfd ATT
   return TRUE;
 }
 
+void
+bfd_elf_lookup_section_flags (bfd *output_bfd, struct flag_info *finfo)
+{
+  const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
+
+  if (bed->elf_backend_lookup_section_flags_hook)
+    return (*bed->elf_backend_lookup_section_flags_hook) (finfo);
+
+  return;
+}
+
 struct alloc_got_off_arg {
   bfd_vma gotoff;
   struct bfd_link_info *info;
Index: bfd/elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.124
diff -u -p -r1.124 elfxx-target.h
--- bfd/elfxx-target.h	4 Nov 2010 11:35:01 -0000	1.124
+++ bfd/elfxx-target.h	18 May 2011 19:14:53 -0000
@@ -173,6 +173,10 @@
 #define bfd_elfNN_bfd_define_common_symbol bfd_generic_define_common_symbol
 #endif
 
+#ifndef bfd_elfNN_bfd_lookup_section_flags
+#define bfd_elfNN_bfd_lookup_section_flags bfd_elf_lookup_section_flags
+#endif
+
 #ifndef bfd_elfNN_bfd_make_debug_symbol
 #define bfd_elfNN_bfd_make_debug_symbol \
   ((asymbol * (*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
@@ -528,6 +532,9 @@
 #ifndef elf_backend_write_core_note
 #define elf_backend_write_core_note		NULL
 #endif
+#ifndef elf_backend_lookup_section_flags_hook
+#define elf_backend_lookup_section_flags_hook	NULL
+#endif
 #ifndef elf_backend_reloc_type_class
 #define elf_backend_reloc_type_class		_bfd_elf_reloc_type_class
 #endif
@@ -711,6 +718,7 @@ static struct elf_backend_data elfNN_bed
   elf_backend_grok_prstatus,
   elf_backend_grok_psinfo,
   elf_backend_write_core_note,
+  elf_backend_lookup_section_flags_hook,
   elf_backend_reloc_type_class,
   elf_backend_discard_info,
   elf_backend_ignore_discarded_relocs,
Index: bfd/ieee.c
===================================================================
RCS file: /cvs/src/src/bfd/ieee.c,v
retrieving revision 1.70
diff -u -p -r1.70 ieee.c
--- bfd/ieee.c	27 Jun 2010 04:07:53 -0000	1.70
+++ bfd/ieee.c	18 May 2011 19:14:53 -0000
@@ -3772,6 +3772,7 @@ ieee_sizeof_headers (bfd *abfd ATTRIBUTE
   bfd_generic_get_relocated_section_contents
 #define ieee_bfd_relax_section bfd_generic_relax_section
 #define ieee_bfd_gc_sections bfd_generic_gc_sections
+#define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ieee_bfd_merge_sections bfd_generic_merge_sections
 #define ieee_bfd_is_group_section bfd_generic_is_group_section
 #define ieee_bfd_discard_group bfd_generic_discard_group
Index: bfd/ihex.c
===================================================================
RCS file: /cvs/src/src/bfd/ihex.c,v
retrieving revision 1.40
diff -u -p -r1.40 ihex.c
--- bfd/ihex.c	23 Nov 2009 14:41:30 -0000	1.40
+++ bfd/ihex.c	18 May 2011 19:14:53 -0000
@@ -930,6 +930,7 @@ ihex_sizeof_headers (bfd *abfd ATTRIBUTE
 #define ihex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define ihex_bfd_relax_section                    bfd_generic_relax_section
 #define ihex_bfd_gc_sections                      bfd_generic_gc_sections
+#define ihex_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define ihex_bfd_merge_sections                   bfd_generic_merge_sections
 #define ihex_bfd_is_group_section                 bfd_generic_is_group_section
 #define ihex_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.88
diff -u -p -r1.88 libbfd-in.h
--- bfd/libbfd-in.h	28 Apr 2011 12:50:32 -0000	1.88
+++ bfd/libbfd-in.h	18 May 2011 19:14:53 -0000
@@ -453,6 +453,9 @@ extern bfd_boolean _bfd_generic_set_sect
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (bfd *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.251
diff -u -p -r1.251 libbfd.h
--- bfd/libbfd.h	28 Apr 2011 12:50:32 -0000	1.251
+++ bfd/libbfd.h	18 May 2011 19:14:53 -0000
@@ -458,6 +458,9 @@ extern bfd_boolean _bfd_generic_set_sect
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (bfd *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
@@ -2284,6 +2287,9 @@ bfd_boolean bfd_generic_relax_section
 bfd_boolean bfd_generic_gc_sections
    (bfd *, struct bfd_link_info *);
 
+void bfd_generic_lookup_section_flags
+   (bfd *, struct flag_info *);
+
 bfd_boolean bfd_generic_merge_sections
    (bfd *, struct bfd_link_info *);
 
Index: bfd/mach-o-target.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-target.c,v
retrieving revision 1.16
diff -u -p -r1.16 mach-o-target.c
--- bfd/mach-o-target.c	18 Aug 2010 12:24:07 -0000	1.16
+++ bfd/mach-o-target.c	18 May 2011 19:14:53 -0000
@@ -51,6 +51,7 @@
 #define bfd_mach_o_bfd_set_private_flags              _bfd_generic_bfd_set_private_flags
 #define bfd_mach_o_get_section_contents               _bfd_generic_get_section_contents
 #define bfd_mach_o_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_mach_o_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_mach_o_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_mach_o_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group                  bfd_generic_discard_group
Index: bfd/mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.41
diff -u -p -r1.41 mmo.c
--- bfd/mmo.c	27 Jun 2010 04:07:53 -0000	1.41
+++ bfd/mmo.c	18 May 2011 19:14:53 -0000
@@ -3190,6 +3190,7 @@ mmo_write_object_contents (bfd *abfd)
 #define mmo_bfd_get_relocated_section_contents \
   bfd_generic_get_relocated_section_contents
 #define mmo_bfd_gc_sections bfd_generic_gc_sections
+#define mmo_fd_lookup_section_flags bfd_generic_lookup_section_flags
 #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define mmo_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/oasys.c
===================================================================
RCS file: /cvs/src/src/bfd/oasys.c,v
retrieving revision 1.45
diff -u -p -r1.45 oasys.c
--- bfd/oasys.c	24 Mar 2010 15:41:59 -0000	1.45
+++ bfd/oasys.c	18 May 2011 19:14:53 -0000
@@ -1196,6 +1196,7 @@ oasys_sizeof_headers (bfd *abfd ATTRIBUT
 #define oasys_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define oasys_bfd_relax_section                    bfd_generic_relax_section
 #define oasys_bfd_gc_sections                      bfd_generic_gc_sections
+#define oasys_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define oasys_bfd_merge_sections                   bfd_generic_merge_sections
 #define oasys_bfd_is_group_section                 bfd_generic_is_group_section
 #define oasys_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/pef.c
===================================================================
RCS file: /cvs/src/src/bfd/pef.c,v
retrieving revision 1.31
diff -u -p -r1.31 pef.c
--- bfd/pef.c	14 Jan 2011 12:35:56 -0000	1.31
+++ bfd/pef.c	18 May 2011 19:14:53 -0000
@@ -48,6 +48,7 @@
 #define bfd_pef_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_pef_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_pef_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_pef_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_pef_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_pef_bfd_is_group_section		    bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
Index: bfd/plugin.c
===================================================================
RCS file: /cvs/src/src/bfd/plugin.c,v
retrieving revision 1.12
diff -u -p -r1.12 plugin.c
--- bfd/plugin.c	26 Feb 2011 00:03:09 -0000	1.12
+++ bfd/plugin.c	18 May 2011 19:14:53 -0000
@@ -63,6 +63,7 @@
 #define bfd_plugin_bfd_final_link                     _bfd_generic_final_link
 #define bfd_plugin_bfd_link_split_section             _bfd_generic_link_split_section
 #define bfd_plugin_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_plugin_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_plugin_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_plugin_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_plugin_bfd_discard_group                  bfd_generic_discard_group
Index: bfd/ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.33
diff -u -p -r1.33 ppcboot.c
--- bfd/ppcboot.c	23 Nov 2009 14:41:30 -0000	1.33
+++ bfd/ppcboot.c	18 May 2011 19:14:53 -0000
@@ -470,6 +470,7 @@ ppcboot_bfd_print_private_bfd_data (abfd
   bfd_generic_get_relocated_section_contents
 #define ppcboot_bfd_relax_section bfd_generic_relax_section
 #define ppcboot_bfd_gc_sections bfd_generic_gc_sections
+#define ppcboot_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ppcboot_bfd_merge_sections bfd_generic_merge_sections
 #define ppcboot_bfd_is_group_section bfd_generic_is_group_section
 #define ppcboot_bfd_discard_group bfd_generic_discard_group
Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.213
diff -u -p -r1.213 reloc.c
--- bfd/reloc.c	31 Mar 2011 08:58:20 -0000	1.213
+++ bfd/reloc.c	18 May 2011 19:14:54 -0000
@@ -5702,6 +5702,26 @@ bfd_generic_gc_sections (bfd *abfd ATTRI
 
 /*
 INTERNAL_FUNCTION
+	bfd_generic_lookup_section_flags
+
+SYNOPSIS
+	void bfd_generic_lookup_section_flags
+	  (bfd *, struct flag_info *);
+
+DESCRIPTION
+	Provides default handling for section flags lookup
+	-- i.e., does nothing.
+*/
+
+void
+bfd_generic_lookup_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
+				  struct flag_info *finfo) 
+{
+  finfo->done = TRUE;
+}
+
+/*
+INTERNAL_FUNCTION
 	bfd_generic_merge_sections
 
 SYNOPSIS
Index: bfd/som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.83
diff -u -p -r1.83 som.c
--- bfd/som.c	14 Jan 2011 12:35:55 -0000	1.83
+++ bfd/som.c	18 May 2011 19:14:54 -0000
@@ -6741,6 +6741,7 @@ som_bfd_link_split_section (bfd *abfd AT
   _bfd_generic_copy_link_hash_symbol_type
 #define som_bfd_final_link                      _bfd_generic_final_link
 #define som_bfd_gc_sections		        bfd_generic_gc_sections
+#define som_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define som_bfd_merge_sections		        bfd_generic_merge_sections
 #define som_bfd_is_group_section	        bfd_generic_is_group_section
 #define som_bfd_discard_group		        bfd_generic_discard_group
Index: bfd/srec.c
===================================================================
RCS file: /cvs/src/src/bfd/srec.c,v
retrieving revision 1.50
diff -u -p -r1.50 srec.c
--- bfd/srec.c	23 Nov 2009 14:41:30 -0000	1.50
+++ bfd/srec.c	18 May 2011 19:14:54 -0000
@@ -1252,6 +1252,7 @@ srec_print_symbol (bfd *abfd,
 #define srec_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define srec_bfd_relax_section                    bfd_generic_relax_section
 #define srec_bfd_gc_sections                      bfd_generic_gc_sections
+#define srec_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define srec_bfd_merge_sections                   bfd_generic_merge_sections
 #define srec_bfd_is_group_section                 bfd_generic_is_group_section
 #define srec_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.199
diff -u -p -r1.199 targets.c
--- bfd/targets.c	13 May 2011 18:15:32 -0000	1.199
+++ bfd/targets.c	18 May 2011 19:14:54 -0000
@@ -177,6 +177,9 @@ DESCRIPTION
 .{* Forward declaration.  *}
 .typedef struct bfd_link_info _bfd_link_info;
 .
+.{* Forward declaration.  *}
+.typedef struct flag_info flag_info;
+.
 .typedef struct bfd_target
 .{
 .  {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  *}
@@ -444,6 +447,7 @@ BFD_JUMP_TABLE macros.
 .  NAME##_bfd_final_link, \
 .  NAME##_bfd_link_split_section, \
 .  NAME##_bfd_gc_sections, \
+.  NAME##_bfd_lookup_section_flags, \
 .  NAME##_bfd_merge_sections, \
 .  NAME##_bfd_is_group_section, \
 .  NAME##_bfd_discard_group, \
@@ -488,6 +492,9 @@ BFD_JUMP_TABLE macros.
 .  {* Remove sections that are not referenced from the output.  *}
 .  bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 .
+.  {* Remove sections with incorrect flags.  *}
+.  void (*_bfd_lookup_section_flags) (bfd *, struct flag_info *);
+.
 .  {* Attempt to merge SEC_MERGE sections.  *}
 .  bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 .
Index: bfd/tekhex.c
===================================================================
RCS file: /cvs/src/src/bfd/tekhex.c,v
retrieving revision 1.39
diff -u -p -r1.39 tekhex.c
--- bfd/tekhex.c	15 Dec 2009 16:59:20 -0000	1.39
+++ bfd/tekhex.c	18 May 2011 19:14:54 -0000
@@ -943,6 +943,7 @@ tekhex_print_symbol (bfd *abfd,
 #define tekhex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define tekhex_bfd_relax_section                    bfd_generic_relax_section
 #define tekhex_bfd_gc_sections                      bfd_generic_gc_sections
+#define tekhex_bfd_lookup_section_flags		    bfd_generic_lookup_section_flags
 #define tekhex_bfd_merge_sections                   bfd_generic_merge_sections
 #define tekhex_bfd_is_group_section                 bfd_generic_is_group_section
 #define tekhex_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/versados.c
===================================================================
RCS file: /cvs/src/src/bfd/versados.c,v
retrieving revision 1.39
diff -u -p -r1.39 versados.c
--- bfd/versados.c	27 Jun 2010 04:07:53 -0000	1.39
+++ bfd/versados.c	18 May 2011 19:14:54 -0000
@@ -806,6 +806,7 @@ versados_canonicalize_reloc (bfd *abfd,
 #define versados_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define versados_bfd_relax_section                    bfd_generic_relax_section
 #define versados_bfd_gc_sections                      bfd_generic_gc_sections
+#define versados_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define versados_bfd_merge_sections                   bfd_generic_merge_sections
 #define versados_bfd_is_group_section                 bfd_generic_is_group_section
 #define versados_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/vms-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/vms-alpha.c,v
retrieving revision 1.44
diff -u -p -r1.44 vms-alpha.c
--- bfd/vms-alpha.c	6 May 2011 10:41:11 -0000	1.44
+++ bfd/vms-alpha.c	18 May 2011 19:14:54 -0000
@@ -9324,6 +9324,7 @@ bfd_vms_get_data (bfd *abfd)
 
 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
+#define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
Index: bfd/xsym.c
===================================================================
RCS file: /cvs/src/src/bfd/xsym.c,v
retrieving revision 1.28
diff -u -p -r1.28 xsym.c
--- bfd/xsym.c	27 Jun 2010 04:07:53 -0000	1.28
+++ bfd/xsym.c	18 May 2011 19:14:54 -0000
@@ -42,6 +42,7 @@
 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_sym_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_sym_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_sym_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_sym_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group
Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.87
diff -u -p -r1.87 bfdlink.h
--- include/bfdlink.h	17 May 2011 13:02:16 -0000	1.87
+++ include/bfdlink.h	18 May 2011 19:14:54 -0000
@@ -224,6 +224,25 @@ enum report_method
   RM_GENERATE_ERROR
 };
 
+typedef enum {with_flags, without_flags} flag_type;
+
+/* A section flag list.  */
+struct flag_info_list
+{
+  flag_type with; 
+  const char *name;
+  struct flag_info_list *next;
+};
+
+/* Section flag info.  */
+struct flag_info
+{
+  unsigned only_with_flags;
+  unsigned not_with_flags;
+  struct flag_info_list *flag_list;
+  int done;
+};
+
 struct bfd_elf_dynamic_list;
 
 /* This structure holds all the information needed to communicate
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.275
diff -u -p -r1.275 ld.texinfo
--- ld/ld.texinfo	9 May 2011 13:23:25 -0000	1.275
+++ ld/ld.texinfo	18 May 2011 19:14:55 -0000
@@ -1,4 +1,4 @@
-\input texinfo
+@samp{\input exinfo
 @setfilename ld.info
 @c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
 @c 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -3673,6 +3673,7 @@ The full description of an output sectio
   [ALIGN(@var{section_align})]
   [SUBALIGN(@var{subsection_align})]
   [@var{constraint}]
+  [SECTION_FLAGS(@var{section_flag_list})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -4310,6 +4311,7 @@ like this:
   [ALIGN(@var{section_align})]
   [SUBALIGN(@var{subsection_align})]
   [@var{constraint}]
+  [SECTION_FLAGS(@var{section_flag_list})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -4328,6 +4330,7 @@ remaining section attributes.
 * Forced Output Alignment::	Forced Output Alignment
 * Forced Input Alignment::	Forced Input Alignment
 * Output Section Constraint::   Output section constraint
+* Output Section Flags::	Output section flags
 * Output Section Region::	Output section region
 * Output Section Phdr::		Output section phdr
 * Output Section Fill::		Output section fill
@@ -4488,6 +4491,29 @@ of its input sections are read-only or a
 read-write by using the keyword @code{ONLY_IF_RO} and
 @code{ONLY_IF_RW} respectively.
 
+@node Output Section Flags
+@subsubsection Output Section Flags
+@kindex SECTION_FLAGS(@var{section_flag_list})
+@cindex section flags on output sections
+You can specify that an output section should include only those input
+sections with certain section flags or that the output section should
+exclude input sections with the specified flags.
+
+Here is a simple example:
+@smallexample
+@group
+SECTIONS @{
+  .text : SECTION_FLAGS (Anyflag, Betterflag) @{ *(.text) @}
+  .text2 : SECTION_FLAGS (!Otherflag) @{ *(.text) @}
+@}
+@end group
+@end smallexample
+
+In this example, the output section @samp{.text} will be comprised of any input text
+section whose section header flags @code{Anyflag} and @code{Betterflag} are set.
+The output section @samp{.text2} will be comprised of any input text section
+whose section header flag @code{Otherflag} is clear.
+
 @node Output Section Region
 @subsubsection Output Section Region
 @kindex >@var{region}
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.65
diff -u -p -r1.65 ldgram.y
--- ld/ldgram.y	13 Jan 2011 13:29:55 -0000	1.65
+++ ld/ldgram.y	18 May 2011 19:14:55 -0000
@@ -74,6 +74,8 @@ static int error_index;
   struct name_list *name_list;
   int token;
   union etree_union *etree;
+  struct flag_info_list *flag_info_list;
+  struct flag_info *flag_info;
   struct phdr_info
     {
       bfd_boolean filehdr;
@@ -144,13 +146,15 @@ static int error_index;
 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
 %type <token> assign_op atype attributes_opt sect_constraint
+%type <flag_info_list> sect_flag_list
+%type <flag_info> sect_flags
 %type <name>  filename
 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> 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 SECTION_FLAGS
 %token EXCLUDE_FILE
 %token CONSTANT
 %type <versyms> vers_defns
@@ -939,24 +943,77 @@ sect_constraint:
 	|	{ $$ = 0; }
 	;
 
+sect_flag_list:	NAME
+		{
+		  struct flag_info_list *n;
+		  n = ((struct flag_info_list *) xmalloc (sizeof *n));
+		  n->with = with_flags;
+		  n->name = $1;
+		  n->next = NULL;
+		  $$ = n;
+		}
+	|	sect_flag_list opt_comma NAME
+		{
+		  struct flag_info_list *n;
+		  n = ((struct flag_info_list *) xmalloc (sizeof *n));
+		  n->with = with_flags;
+		  n->name = $3;
+		  n->next = $1;
+		  $$ = n;
+		}
+	|	'!' NAME
+		{
+		  struct flag_info_list *n;
+		  n = ((struct flag_info_list *) xmalloc (sizeof *n));
+		  n->with = without_flags;
+		  n->name = $2;
+		  n->next = NULL;
+		  $$ = n;
+		}
+	|	sect_flag_list opt_comma '!' NAME
+		{
+		  struct flag_info_list *n;
+		  n = ((struct flag_info_list *) xmalloc (sizeof *n));
+		  n->with = without_flags;
+		  n->name = $4;
+		  n->next = $1;
+		  $$ = n;
+		}
+	;
+
+sect_flags:
+		SECTION_FLAGS '(' sect_flag_list ')'
+		{
+		  struct flag_info *n;
+		  n = ((struct flag_info *) xmalloc (sizeof *n));
+		  n->flag_list = $3;
+		  n->done = FALSE;
+		  n->not_with_flags = 0;
+		  n->only_with_flags = 0;
+		  $$ = n;
+		}
+	|	{ $$ = 0; }
+	;
+
 section:	NAME 		{ ldlex_expression(); }
 		opt_exp_with_type
 		opt_at
 		opt_align
 		opt_subalign	{ ldlex_popstate (); ldlex_script (); }
 		sect_constraint
+		sect_flags
 		'{'
 			{
 			  lang_enter_output_section_statement($1, $3,
 							      sectype,
-							      $5, $6, $4, $8);
+							      $5, $6, $4, $8, $9);
 			}
 		statement_list_opt
  		'}' { ldlex_popstate (); ldlex_expression (); }
 		memspec_opt memspec_at_opt phdr_opt fill_opt
 		{
 		  ldlex_popstate ();
-		  lang_leave_output_section_statement ($17, $14, $16, $15);
+		  lang_leave_output_section_statement ($18, $15, $17, $16);
 		}
 		opt_comma
 		{}
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.369
diff -u -p -r1.369 ldlang.c
--- ld/ldlang.c	16 May 2011 11:34:48 -0000	1.369
+++ ld/ldlang.c	18 May 2011 19:14:55 -0000
@@ -1793,7 +1793,7 @@ lang_insert_orphan (asection *s,
   os_tail = ((lang_output_section_statement_type **)
 	     lang_output_section_statement.tail);
   os = lang_enter_output_section_statement (secname, address, normal_section,
-                                            NULL, NULL, NULL, constraint);
+                                            NULL, NULL, NULL, constraint, NULL);
 
   ps = NULL;
   if (config.build_constructors && *os_tail == os)
@@ -2280,6 +2280,20 @@ lang_add_section (lang_statement_list_ty
       return;
     }
 
+  if (output->sectflags)
+    {
+      if (output->sectflags->done == FALSE)
+	bfd_lookup_section_flags (link_info.output_bfd, output->sectflags);
+
+      if (output->sectflags->only_with_flags != 0
+	  && (output->sectflags->only_with_flags & section->flags) == 0)
+	return;
+
+      if (output->sectflags->not_with_flags != 0
+          && (output->sectflags->not_with_flags & section->flags) != 0)
+	return;
+    }
+
   if (section->output_section != NULL)
     return;
 
@@ -6156,7 +6170,8 @@ lang_enter_output_section_statement (con
 				     etree_type *align,
 				     etree_type *subalign,
 				     etree_type *ebase,
-				     int constraint)
+				     int constraint,
+				     flag_info *sflags)
 {
   lang_output_section_statement_type *os;
 
@@ -6175,6 +6190,7 @@ lang_enter_output_section_statement (con
     os->flags = SEC_NEVER_LOAD;
   os->block_value = 1;
 
+  os->sectflags = sflags;
   /* Make next things chain into subchain of this.  */
   push_stat_ptr (&os->children);
 
@@ -7279,7 +7295,7 @@ lang_enter_overlay_section (const char *
   etree_type *size;
 
   lang_enter_output_section_statement (name, overlay_vma, overlay_section,
-				       0, overlay_subalign, 0, 0);
+				       0, overlay_subalign, 0, 0, 0);
 
   /* If this is the first section, then base the VMA of future
      sections on this one.  This will work correctly even if `.' is
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.97
diff -u -p -r1.97 ldlang.h
--- ld/ldlang.h	3 May 2011 14:56:14 -0000	1.97
+++ ld/ldlang.h	18 May 2011 19:14:55 -0000
@@ -157,6 +157,7 @@ typedef struct lang_output_section_state
   int section_alignment;	/* Alignment of start of section.  */
   int constraint;
   flagword flags;
+  flag_info *sectflags;
   enum section_type sectype;
   unsigned int processed_vma : 1;
   unsigned int processed_lma : 1;
@@ -497,7 +498,8 @@ extern lang_output_section_statement_typ
    enum section_type sectype,
    etree_type *align,
    etree_type *subalign,
-   etree_type *, int);
+   etree_type *, int,
+   flag_info *sflags);
 extern void lang_final
   (void);
 extern void lang_relax_sections
Index: ld/ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.52
diff -u -p -r1.52 ldlex.l
--- ld/ldlex.l	29 Mar 2011 02:52:36 -0000	1.52
+++ ld/ldlex.l	18 May 2011 19:14:55 -0000
@@ -309,6 +309,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([
 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO"	{ RTOKEN(ONLY_IF_RO); }
 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW"	{ RTOKEN(ONLY_IF_RW); }
 <EXPRESSION,BOTH,SCRIPT>"SPECIAL"	{ RTOKEN(SPECIAL); }
+<EXPRESSION,BOTH,SCRIPT>"SECTION_FLAGS"	{ RTOKEN(SECTION_FLAGS); }
 <BOTH,SCRIPT>"o"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"org"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"l"			{ RTOKEN( LENGTH);}
Index: ld/mri.c
===================================================================
RCS file: /cvs/src/src/ld/mri.c,v
retrieving revision 1.24
diff -u -p -r1.24 mri.c
--- ld/mri.c	13 Jan 2011 13:06:22 -0000	1.24
+++ ld/mri.c	18 May 2011 19:14:55 -0000
@@ -208,7 +208,7 @@ mri_draw_tree (void)
 
 	  lang_enter_output_section_statement (p->name, base,
 					       p->ok_to_load ? normal_section : noload_section,
-					       align, subalign, NULL, 0);
+					       align, subalign, NULL, 0, NULL);
 	  base = 0;
 	  tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
 	  tmp->next = NULL;
Index: ld/testsuite/ld-scripts/section-flags-1.exp
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.exp
diff -N ld/testsuite/ld-scripts/section-flags-1.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.exp	18 May 2011 19:14:55 -0000
@@ -0,0 +1,32 @@
+# 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"
+
+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
Index: ld/testsuite/ld-scripts/section-flags-1.s
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.s
diff -N ld/testsuite/ld-scripts/section-flags-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.s	18 May 2011 19:14:55 -0000
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: ld/testsuite/ld-scripts/section-flags-1.t
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.t
diff -N ld/testsuite/ld-scripts/section-flags-1.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.t	18 May 2011 19:14:55 -0000
@@ -0,0 +1,17 @@
+MEMORY
+{
+  ram (rwx) : ORIGIN = 0x100000, LENGTH = 144M
+}
+
+SECTIONS
+{
+  .text : SECTION_FLAGS (!anyflag)
+  {
+    *(.text .text.* .text_* .gnu.linkonce.t.*)
+  } >ram
+
+  .text_vle : SECTION_FLAGS (anyflag, otherflag, thirdflag)
+  {
+    *(.text .text.* .text_* .gnu.linkonce.t.*)
+  } >ram
+}

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-18 19:32 [RFA] Linker script extension SECTION_FLAGS Catherine Moore
@ 2011-05-18 19:33 ` Catherine Moore
  2011-05-19  0:07 ` Ian Lance Taylor
  2011-05-19  7:44 ` Tristan Gingold
  2 siblings, 0 replies; 16+ messages in thread
From: Catherine Moore @ 2011-05-18 19:33 UTC (permalink / raw)
  To: binutils, Catherine Moore

I forgot to mention that I tested this patch for arm-coff, ppc-elf and 
mips-elf.


On 05/18/2011 03:32 PM, Catherine Moore wrote:
> This patch extends the linker script language to include SECTION_FLAGS
> on an output section statement. The purpose of the flags is to ensure
> that all input sections assigned to the output section either have the
> flags set or cleared.
>
> This version of the patch sets the infrastructure but does not define a
> backend implementation. I will provide that along with additional
> testcases when I contribute the Powerpc VLE port.
>
> This patch was originally discussed in the thread beginning here:
> http://sourceware.org/ml/binutils/2011-04/msg00428.html
>
> Does this look okay to install?
>
> Thanks,
> Catherine
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-18 19:32 [RFA] Linker script extension SECTION_FLAGS Catherine Moore
  2011-05-18 19:33 ` Catherine Moore
@ 2011-05-19  0:07 ` Ian Lance Taylor
  2011-05-24 22:57   ` Catherine Moore
  2011-05-19  7:44 ` Tristan Gingold
  2 siblings, 1 reply; 16+ messages in thread
From: Ian Lance Taylor @ 2011-05-19  0:07 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils

Catherine Moore <clm@codesourcery.com> writes:

> This patch extends the linker script language to include SECTION_FLAGS
> on an output section statement.  The purpose of the flags is to ensure
> that all input sections assigned to the output section either have the
> flags set or cleared.
>
> This version of the patch sets the infrastructure but does not define
> a backend implementation.  I will provide that along with additional
> testcases when I contribute the Powerpc VLE port.
>
> This patch was originally discussed in the thread beginning here:
> http://sourceware.org/ml/binutils/2011-04/msg00428.html
>
> Does this look okay to install?

I didn't look at the patch, but I think the documentation needs to use
some real section flags, and ideally the set of valid flags should be
defined somewhere.  It's not obvious what the valid values are.

I'm also not sure about the way it appears in a linker script.  You have
SECTION_FLAGS, which describes a constraint on the input sections
attached to an output section, next to things like AT, ALIGN, and
SUBALIGN, which describe characteristics of the output section.  That is
OK, but I think that somebody looking at a linker script is likely to
think that SECTION_FLAGS is setting flags for the output section, much
as ALIGN sets the alignment of the output section.  But that's not what
happens at all.  So perhaps the name should be something like
INPUT_SECTION_FLAGS or perhaps the constraint should be expressed
somehow inside the output section definition, in the list of input
sections, rather than outside.

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-18 19:32 [RFA] Linker script extension SECTION_FLAGS Catherine Moore
  2011-05-18 19:33 ` Catherine Moore
  2011-05-19  0:07 ` Ian Lance Taylor
@ 2011-05-19  7:44 ` Tristan Gingold
  2 siblings, 0 replies; 16+ messages in thread
From: Tristan Gingold @ 2011-05-19  7:44 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils


On May 18, 2011, at 9:32 PM, Catherine Moore wrote:
> 2011-05-18  Catherine Moore  <clm@codesourcery.com>
> 	bfd/
> 	2011-05-18  Catherine Moore  <clm@codesourcery.com>
> 
>        * bfd-in2.h: Regenerated.
>        * bfd.c (bfd_lookup_section_flags): New definition.
>        * binary.c (binary_bfd_lookup_section_flags): New definition.
>        * coff-rs6000.c (rs6000coff_vec): Include
>        bfd_generic_lookup_section_flags.
>        (pmac_xcoff_vec): Likewise.
>        * coffcode.h (coff_bfd_lookup_section_flags): New definition.
>        * elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
>        (bfd_elf_lookup_section_flags): Declare.
>        * elflink.c (bfd_elf_lookup_section_flags): New function.
>        * elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
>        (elf_backend_lookup_section_flags_hook): Define.
>        (elf_backend_data): Add elf_backend_lookup_section_flags_hook.
>        * ieee.c (ieee_bfd_lookup_section_flags): New define.
>        * ihex.c (ihex_bfd_lookup_section_flags): New define.
>        * libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
>        (bfd_generic_lookup_section_flags): Declare.
>        * libbfd.h: Regenerated.
>        * mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
>        * mmo.c (mmo_fd_lookup_section_flags): New definition.

Typo in the code too: mmo_bfd_...

Also, I am not sure that you really need to have elf_backend_lookup_section_flags_hook.
In your patch, bfd_elf_lookup_section_flags is simply a wrapper.
Each ELF target can simply define its own XX_bfd_lookup_section_flags.

Finally, in the grammar of SECTION_FLAGS, I would replace the comma with a '&' to clarify
the fact this is a conjunction.

Thank you for working on that.

Tristan.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-19  0:07 ` Ian Lance Taylor
@ 2011-05-24 22:57   ` Catherine Moore
  2011-05-25 12:28     ` Tristan Gingold
  2011-06-06 22:02     ` PING " Catherine Moore
  0 siblings, 2 replies; 16+ messages in thread
From: Catherine Moore @ 2011-05-24 22:57 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils, Catherine Moore, Tristan Gingold

[-- Attachment #1: Type: text/plain, Size: 4967 bytes --]

On 05/18/2011 08:07 PM, Ian Lance Taylor wrote:
> Catherine Moore<clm@codesourcery.com>  writes:
>>
>> Does this look okay to install?
>
> I didn't look at the patch, but I think the documentation needs to use
> some real section flags, and ideally the set of valid flags should be
> defined somewhere.  It's not obvious what the valid values are.
>
> I'm also not sure about the way it appears in a linker script.  You have
> SECTION_FLAGS, which describes a constraint on the input sections
> attached to an output section, next to things like AT, ALIGN, and
> SUBALIGN, which describe characteristics of the output section.  That is
> OK, but I think that somebody looking at a linker script is likely to
> think that SECTION_FLAGS is setting flags for the output section, much
> as ALIGN sets the alignment of the output section.  But that's not what
> happens at all.  So perhaps the name should be something like
> INPUT_SECTION_FLAGS or perhaps the constraint should be expressed
> somehow inside the output section definition, in the list of input
> sections, rather than outside.
>

A new patch that addresses these concerns plus a couple that were 
pointed out by Tristan is attached here.  Tristan, I didn't incorporate 
your comment regarding the backend hook into the new patch.  I have now 
filled in bfd_elf_lookup_section_flags to handle all of the ELF common 
section header flags.  The backend hook is intended to handle the 
target-specific flags.  Although, I'm not submitting it at this time, 
the backend hook that I am using for the PowerPC VLE target is attached 
as an example.

Please let me know if there are additional concerns or comments and 
whether this is okay to commit.

I've tested ppc-elf, mips-elf and arm-coff targets.

Thanks,
Catherine

bfd/
2011-05-24  Catherine Moore  <clm@codesourcery.com>

         * bfd-in2.h: Regenerated.
         * bfd.c (bfd_lookup_section_flags): New definition.
         * binary.c (binary_bfd_lookup_section_flags): New definition.
         * coff-rs6000.c (rs6000coff_vec): Include
         bfd_generic_lookup_section_flags.
         (pmac_xcoff_vec): Likewise.
         * coffcode.h (coff_bfd_lookup_section_flags): New definition.
         * elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
         (bfd_elf_lookup_section_flags): Declare.
         * elflink.c (bfd_elf_lookup_section_flags): New function.
         * elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
         (elf_backend_lookup_section_flags_hook): Define.
         (elf_backend_data): Add elf_backend_lookup_section_flags_hook.
         * ieee.c (ieee_bfd_lookup_section_flags): New define.
         * ihex.c (ihex_bfd_lookup_section_flags): New define.
         * libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
         (bfd_generic_lookup_section_flags): Declare.
         * libbfd.h: Regenerated.
         * mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
         * mmo.c (mmo_bfd_lookup_section_flags): New definition.
         * oasys.c (oasys_bfd_lookup_section_flags): New definition.
         * pef.c (bfd_pef_bfd_lookup_section_flags): New definition.
         * plugin.c (bfd_plugin_bfd_lookup_section_flags): New definition.
         * ppcboot.c (ppcboot_bfd_lookup_section_flags): New definition.
         * reloc.c (bfd_generic_lookup_section_flags): New function.
         * som.c (som_bfd_lookup_section_flags): New definition.
         * srec.c (srec_bfd_lookup_section_flags): New definition.
         * targets.c (flag_info): Declare.
         (NAME##_bfd_lookup_section_flags): Add to LINK jump table.
         (_bfd_lookup_section_flags): New.
         * tekhex.c (tekhex_bfd_lookup_section_flags): New definition.
         * versados.c (versados_bfd_lookup_section_flags): New definition.
         * vms-alpha.c (alpha_vms_bfd_lookup_section_flag): New definition.
         * xsym.c (bfd_sym_bfd_lookup_section_flags): New definition.


include/
2011-05-24  Catherine Moore  <clm@codesourcery.com>

	* bfdlink.h (flag_type): New enumeration.
	(flag_info_list): New structure.
	(flag_info): New structure.

ld/testsuite/
2011-05-24  Catherine Moore  <clm@codesourcery.com>

	* ld-scripts/section-flags-1.exp: New.
	* ld-scripts/section-flags-1.s: New.
	* ld-scripts/section-flags-1.t: New.


ld/2011-05-23  Catherine Moore  <clm@codesourcery.com>

	* ld.texinfo: Document usage of INPUT_SECTION_FLAGS.
	* ldgram.y (section): Recognize sect_flags.
	(sect_flags): New rule.
	(sect_flag_list): New rule.
	* ldlang.c (lang_add_section): Check section flags.
	(lang_enter_output_section_statement): Add argument sflags.
	Initialize sflags field in output statement.
	* ldlang.h (lang_output_section_statement_type): Add flag_info field.
	(lang_enter_output_section_statement): New argument sflags.  Update
	all callers.
	* ldlex.l (INPUT_SECTION_FLAGS): New token.
	* mri.c (mri_draw_tree): Update argument list for
	land_enter_output_section_statement.





[-- Attachment #2: sf.patch2 --]
[-- Type: text/plain, Size: 40163 bytes --]

Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.537
diff -p -u -r1.537 bfd-in2.h
--- bfd/bfd-in2.h	9 May 2011 13:23:24 -0000	1.537
+++ bfd/bfd-in2.h	24 May 2011 22:28:19 -0000
@@ -5394,6 +5394,9 @@ bfd_boolean bfd_set_private_flags (bfd *
 #define bfd_gc_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 
+#define bfd_lookup_section_flags(link_info, flag_info) \
+       BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
+
 #define bfd_merge_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 
@@ -5550,6 +5553,9 @@ enum bfd_endian { BFD_ENDIAN_BIG, BFD_EN
 /* Forward declaration.  */
 typedef struct bfd_link_info _bfd_link_info;
 
+/* Forward declaration.  */
+typedef struct flag_info flag_info;
+
 typedef struct bfd_target
 {
   /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
@@ -5815,6 +5821,7 @@ typedef struct bfd_target
   NAME##_bfd_final_link, \
   NAME##_bfd_link_split_section, \
   NAME##_bfd_gc_sections, \
+  NAME##_bfd_lookup_section_flags, \
   NAME##_bfd_merge_sections, \
   NAME##_bfd_is_group_section, \
   NAME##_bfd_discard_group, \
@@ -5859,6 +5866,10 @@ typedef struct bfd_target
   /* Remove sections that are not referenced from the output.  */
   bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 
+  /* Remove sections with incorrect flags.  */
+  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
+                                     struct flag_info *);
+
   /* Attempt to merge SEC_MERGE sections.  */
   bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.116
diff -p -u -r1.116 bfd.c
--- bfd/bfd.c	17 Apr 2011 23:15:11 -0000	1.116
+++ bfd/bfd.c	24 May 2011 22:28:19 -0000
@@ -1373,6 +1373,9 @@ DESCRIPTION
 .#define bfd_gc_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 .
+.#define bfd_lookup_section_flags(link_info, flag_info) \
+.	BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
+.
 .#define bfd_merge_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 .
Index: bfd/binary.c
===================================================================
RCS file: /cvs/src/src/bfd/binary.c,v
retrieving revision 1.39
diff -p -u -r1.39 binary.c
--- bfd/binary.c	23 Nov 2009 14:41:28 -0000	1.39
+++ bfd/binary.c	24 May 2011 22:28:19 -0000
@@ -299,6 +299,7 @@ binary_sizeof_headers (bfd *abfd ATTRIBU
 #define binary_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define binary_bfd_relax_section                   bfd_generic_relax_section
 #define binary_bfd_gc_sections                     bfd_generic_gc_sections
+#define binary_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define binary_bfd_merge_sections                  bfd_generic_merge_sections
 #define binary_bfd_is_group_section                bfd_generic_is_group_section
 #define binary_bfd_discard_group                   bfd_generic_discard_group
Index: bfd/coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.101
diff -p -u -r1.101 coff-rs6000.c
--- bfd/coff-rs6000.c	18 May 2011 07:58:30 -0000	1.101
+++ bfd/coff-rs6000.c	24 May 2011 22:28:19 -0000
@@ -4101,6 +4101,7 @@ const bfd_target rs6000coff_vec =
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
@@ -4354,6 +4355,7 @@ const bfd_target pmac_xcoff_vec =
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.178
diff -p -u -r1.178 coffcode.h
--- bfd/coffcode.h	18 May 2011 07:58:31 -0000	1.178
+++ bfd/coffcode.h	24 May 2011 22:28:19 -0000
@@ -5652,6 +5652,10 @@ static bfd_coff_backend_data ticoff1_swa
 #define coff_bfd_gc_sections		    bfd_generic_gc_sections
 #endif
 
+#ifndef coff_bfd_lookup_section_flags
+#define coff_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
+#endif
+
 #ifndef coff_bfd_merge_sections
 #define coff_bfd_merge_sections		    bfd_generic_merge_sections
 #endif
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.319
diff -p -u -r1.319 elf-bfd.h
--- bfd/elf-bfd.h	23 May 2011 06:22:50 -0000	1.319
+++ bfd/elf-bfd.h	24 May 2011 22:28:19 -0000
@@ -1114,6 +1114,10 @@ struct elf_backend_data
   char *(*elf_backend_write_core_note)
     (bfd *abfd, char *buf, int *bufsiz, int note_type, ...);
 
+  /* This function, if defined, is called to the section flag hex value.  */
+  void (*elf_backend_lookup_section_flags_hook)
+    (struct flag_info *);
+
   /* This function returns class of a reloc type.  */
   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
     (const Elf_Internal_Rela *);
@@ -2192,6 +2196,9 @@ extern bfd_boolean _bfd_elf_is_function_
 
 extern int bfd_elf_get_default_section_type (flagword);
 
+extern void bfd_elf_lookup_section_flags
+  (struct bfd_link_info *, struct flag_info *);
+
 extern Elf_Internal_Phdr * _bfd_elf_find_segment_containing_section
   (bfd * abfd, asection * section);
 
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.405
diff -p -u -r1.405 elflink.c
--- bfd/elflink.c	18 May 2011 14:04:31 -0000	1.405
+++ bfd/elflink.c	24 May 2011 22:28:20 -0000
@@ -12162,6 +12162,128 @@ bfd_elf_gc_record_vtentry (bfd *abfd ATT
   return TRUE;
 }
 
+void
+bfd_elf_lookup_section_flags (struct bfd_link_info *info,
+			      struct flag_info *finfo)
+{
+  bfd *output_bfd = info->output_bfd;
+  const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
+  struct flag_info_list *tf = finfo->flag_list;
+  int with_hex = 0;
+  int without_hex = 0;
+
+ if (bed->elf_backend_lookup_section_flags_hook)
+   (*bed->elf_backend_lookup_section_flags_hook) (finfo);
+
+  while (tf)
+    {
+      if (!strcmp (tf->name, "SHF_WRITE"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_WRITE;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_WRITE;
+	}
+      else if (!strcmp (tf->name, "SHF_ALLOC"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_ALLOC;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_ALLOC;
+	}
+      else if (!strcmp (tf->name, "SHF_EXECINSTR"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_EXECINSTR;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_EXECINSTR;
+	}
+      else if (!strcmp (tf->name, "SHF_MERGE"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_MERGE;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_MERGE;
+	}
+      else if (!strcmp (tf->name, "SHF_STRINGS"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_STRINGS;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_STRINGS;
+	}
+      else if (!strcmp (tf->name, "SHF_INFO_LINK"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_INFO_LINK;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_INFO_LINK;
+	}
+      else if (!strcmp (tf->name, "SHF_LINK_ORDER"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_LINK_ORDER;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_LINK_ORDER;
+	}
+      else if (!strcmp (tf->name, "SHF_OS_NONCONFORMING"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_OS_NONCONFORMING;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_OS_NONCONFORMING;
+	}
+      else if (!strcmp (tf->name, "SHF_GROUP"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_GROUP;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_GROUP;
+	}
+      else if (!strcmp (tf->name, "SHF_TLS"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_TLS;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_TLS;
+	}
+      else if (!strcmp (tf->name, "SHF_MASKOS"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_MASKOS;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_MASKOS;
+	}
+      else if (!strcmp (tf->name, "SHF_MASKOS"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_MASKOS;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_MASKOS;
+	}
+      else if (!strcmp (tf->name, "SHF_EXCLUDE"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_EXCLUDE;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_EXCLUDE;
+	}
+      else 
+	{
+	  if (tf->valid == FALSE)
+            info->callbacks->einfo
+		(_("Unrecognized INPUT_SECTION_FLAG %s\n"), tf->name);
+	  return;
+	}
+      tf = tf->next;
+    }
+ finfo->done = TRUE;
+ finfo->only_with_flags |= with_hex;
+ finfo->not_with_flags |= without_hex;
+
+ return;
+}
+
 struct alloc_got_off_arg {
   bfd_vma gotoff;
   struct bfd_link_info *info;
Index: bfd/elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.124
diff -p -u -r1.124 elfxx-target.h
--- bfd/elfxx-target.h	4 Nov 2010 11:35:01 -0000	1.124
+++ bfd/elfxx-target.h	24 May 2011 22:28:20 -0000
@@ -173,6 +173,10 @@
 #define bfd_elfNN_bfd_define_common_symbol bfd_generic_define_common_symbol
 #endif
 
+#ifndef bfd_elfNN_bfd_lookup_section_flags
+#define bfd_elfNN_bfd_lookup_section_flags bfd_elf_lookup_section_flags
+#endif
+
 #ifndef bfd_elfNN_bfd_make_debug_symbol
 #define bfd_elfNN_bfd_make_debug_symbol \
   ((asymbol * (*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
@@ -528,6 +532,9 @@
 #ifndef elf_backend_write_core_note
 #define elf_backend_write_core_note		NULL
 #endif
+#ifndef elf_backend_lookup_section_flags_hook
+#define elf_backend_lookup_section_flags_hook	NULL
+#endif
 #ifndef elf_backend_reloc_type_class
 #define elf_backend_reloc_type_class		_bfd_elf_reloc_type_class
 #endif
@@ -711,6 +718,7 @@ static struct elf_backend_data elfNN_bed
   elf_backend_grok_prstatus,
   elf_backend_grok_psinfo,
   elf_backend_write_core_note,
+  elf_backend_lookup_section_flags_hook,
   elf_backend_reloc_type_class,
   elf_backend_discard_info,
   elf_backend_ignore_discarded_relocs,
Index: bfd/ieee.c
===================================================================
RCS file: /cvs/src/src/bfd/ieee.c,v
retrieving revision 1.70
diff -p -u -r1.70 ieee.c
--- bfd/ieee.c	27 Jun 2010 04:07:53 -0000	1.70
+++ bfd/ieee.c	24 May 2011 22:28:20 -0000
@@ -3772,6 +3772,7 @@ ieee_sizeof_headers (bfd *abfd ATTRIBUTE
   bfd_generic_get_relocated_section_contents
 #define ieee_bfd_relax_section bfd_generic_relax_section
 #define ieee_bfd_gc_sections bfd_generic_gc_sections
+#define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ieee_bfd_merge_sections bfd_generic_merge_sections
 #define ieee_bfd_is_group_section bfd_generic_is_group_section
 #define ieee_bfd_discard_group bfd_generic_discard_group
Index: bfd/ihex.c
===================================================================
RCS file: /cvs/src/src/bfd/ihex.c,v
retrieving revision 1.40
diff -p -u -r1.40 ihex.c
--- bfd/ihex.c	23 Nov 2009 14:41:30 -0000	1.40
+++ bfd/ihex.c	24 May 2011 22:28:20 -0000
@@ -930,6 +930,7 @@ ihex_sizeof_headers (bfd *abfd ATTRIBUTE
 #define ihex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define ihex_bfd_relax_section                    bfd_generic_relax_section
 #define ihex_bfd_gc_sections                      bfd_generic_gc_sections
+#define ihex_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define ihex_bfd_merge_sections                   bfd_generic_merge_sections
 #define ihex_bfd_is_group_section                 bfd_generic_is_group_section
 #define ihex_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.88
diff -p -u -r1.88 libbfd-in.h
--- bfd/libbfd-in.h	28 Apr 2011 12:50:32 -0000	1.88
+++ bfd/libbfd-in.h	24 May 2011 22:28:20 -0000
@@ -453,6 +453,9 @@ extern bfd_boolean _bfd_generic_set_sect
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (struct bfd_link_info *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.251
diff -p -u -r1.251 libbfd.h
--- bfd/libbfd.h	28 Apr 2011 12:50:32 -0000	1.251
+++ bfd/libbfd.h	24 May 2011 22:28:20 -0000
@@ -458,6 +458,9 @@ extern bfd_boolean _bfd_generic_set_sect
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (struct bfd_link_info *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
@@ -2284,6 +2287,9 @@ bfd_boolean bfd_generic_relax_section
 bfd_boolean bfd_generic_gc_sections
    (bfd *, struct bfd_link_info *);
 
+void bfd_generic_lookup_section_flags
+   (struct bfd_link_info *, struct flag_info *);
+
 bfd_boolean bfd_generic_merge_sections
    (bfd *, struct bfd_link_info *);
 
Index: bfd/mach-o-target.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-target.c,v
retrieving revision 1.16
diff -p -u -r1.16 mach-o-target.c
--- bfd/mach-o-target.c	18 Aug 2010 12:24:07 -0000	1.16
+++ bfd/mach-o-target.c	24 May 2011 22:28:20 -0000
@@ -51,6 +51,7 @@
 #define bfd_mach_o_bfd_set_private_flags              _bfd_generic_bfd_set_private_flags
 #define bfd_mach_o_get_section_contents               _bfd_generic_get_section_contents
 #define bfd_mach_o_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_mach_o_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_mach_o_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_mach_o_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group                  bfd_generic_discard_group
Index: bfd/mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.41
diff -p -u -r1.41 mmo.c
--- bfd/mmo.c	27 Jun 2010 04:07:53 -0000	1.41
+++ bfd/mmo.c	24 May 2011 22:28:20 -0000
@@ -3190,6 +3190,7 @@ mmo_write_object_contents (bfd *abfd)
 #define mmo_bfd_get_relocated_section_contents \
   bfd_generic_get_relocated_section_contents
 #define mmo_bfd_gc_sections bfd_generic_gc_sections
+#define mmo_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define mmo_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/oasys.c
===================================================================
RCS file: /cvs/src/src/bfd/oasys.c,v
retrieving revision 1.45
diff -p -u -r1.45 oasys.c
--- bfd/oasys.c	24 Mar 2010 15:41:59 -0000	1.45
+++ bfd/oasys.c	24 May 2011 22:28:20 -0000
@@ -1196,6 +1196,7 @@ oasys_sizeof_headers (bfd *abfd ATTRIBUT
 #define oasys_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define oasys_bfd_relax_section                    bfd_generic_relax_section
 #define oasys_bfd_gc_sections                      bfd_generic_gc_sections
+#define oasys_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define oasys_bfd_merge_sections                   bfd_generic_merge_sections
 #define oasys_bfd_is_group_section                 bfd_generic_is_group_section
 #define oasys_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/pef.c
===================================================================
RCS file: /cvs/src/src/bfd/pef.c,v
retrieving revision 1.31
diff -p -u -r1.31 pef.c
--- bfd/pef.c	14 Jan 2011 12:35:56 -0000	1.31
+++ bfd/pef.c	24 May 2011 22:28:20 -0000
@@ -48,6 +48,7 @@
 #define bfd_pef_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_pef_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_pef_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_pef_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_pef_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_pef_bfd_is_group_section		    bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
Index: bfd/plugin.c
===================================================================
RCS file: /cvs/src/src/bfd/plugin.c,v
retrieving revision 1.12
diff -p -u -r1.12 plugin.c
--- bfd/plugin.c	26 Feb 2011 00:03:09 -0000	1.12
+++ bfd/plugin.c	24 May 2011 22:28:20 -0000
@@ -63,6 +63,7 @@
 #define bfd_plugin_bfd_final_link                     _bfd_generic_final_link
 #define bfd_plugin_bfd_link_split_section             _bfd_generic_link_split_section
 #define bfd_plugin_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_plugin_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_plugin_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_plugin_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_plugin_bfd_discard_group                  bfd_generic_discard_group
Index: bfd/ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.33
diff -p -u -r1.33 ppcboot.c
--- bfd/ppcboot.c	23 Nov 2009 14:41:30 -0000	1.33
+++ bfd/ppcboot.c	24 May 2011 22:28:20 -0000
@@ -470,6 +470,7 @@ ppcboot_bfd_print_private_bfd_data (abfd
   bfd_generic_get_relocated_section_contents
 #define ppcboot_bfd_relax_section bfd_generic_relax_section
 #define ppcboot_bfd_gc_sections bfd_generic_gc_sections
+#define ppcboot_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ppcboot_bfd_merge_sections bfd_generic_merge_sections
 #define ppcboot_bfd_is_group_section bfd_generic_is_group_section
 #define ppcboot_bfd_discard_group bfd_generic_discard_group
Index: bfd/reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.213
diff -p -u -r1.213 reloc.c
--- bfd/reloc.c	31 Mar 2011 08:58:20 -0000	1.213
+++ bfd/reloc.c	24 May 2011 22:28:20 -0000
@@ -5702,6 +5702,26 @@ bfd_generic_gc_sections (bfd *abfd ATTRI
 
 /*
 INTERNAL_FUNCTION
+	bfd_generic_lookup_section_flags
+
+SYNOPSIS
+	void bfd_generic_lookup_section_flags
+	  (struct bfd_link_info *, struct flag_info *);
+
+DESCRIPTION
+	Provides default handling for section flags lookup
+	-- i.e., does nothing.
+*/
+
+void
+bfd_generic_lookup_section_flags (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+				  struct flag_info *finfo) 
+{
+  finfo->done = TRUE;
+}
+
+/*
+INTERNAL_FUNCTION
 	bfd_generic_merge_sections
 
 SYNOPSIS
Index: bfd/som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.83
diff -p -u -r1.83 som.c
--- bfd/som.c	14 Jan 2011 12:35:55 -0000	1.83
+++ bfd/som.c	24 May 2011 22:28:20 -0000
@@ -6741,6 +6741,7 @@ som_bfd_link_split_section (bfd *abfd AT
   _bfd_generic_copy_link_hash_symbol_type
 #define som_bfd_final_link                      _bfd_generic_final_link
 #define som_bfd_gc_sections		        bfd_generic_gc_sections
+#define som_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define som_bfd_merge_sections		        bfd_generic_merge_sections
 #define som_bfd_is_group_section	        bfd_generic_is_group_section
 #define som_bfd_discard_group		        bfd_generic_discard_group
Index: bfd/srec.c
===================================================================
RCS file: /cvs/src/src/bfd/srec.c,v
retrieving revision 1.50
diff -p -u -r1.50 srec.c
--- bfd/srec.c	23 Nov 2009 14:41:30 -0000	1.50
+++ bfd/srec.c	24 May 2011 22:28:20 -0000
@@ -1252,6 +1252,7 @@ srec_print_symbol (bfd *abfd,
 #define srec_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define srec_bfd_relax_section                    bfd_generic_relax_section
 #define srec_bfd_gc_sections                      bfd_generic_gc_sections
+#define srec_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define srec_bfd_merge_sections                   bfd_generic_merge_sections
 #define srec_bfd_is_group_section                 bfd_generic_is_group_section
 #define srec_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.199
diff -p -u -r1.199 targets.c
--- bfd/targets.c	13 May 2011 18:15:32 -0000	1.199
+++ bfd/targets.c	24 May 2011 22:28:20 -0000
@@ -177,6 +177,9 @@ DESCRIPTION
 .{* Forward declaration.  *}
 .typedef struct bfd_link_info _bfd_link_info;
 .
+.{* Forward declaration.  *}
+.typedef struct flag_info flag_info;
+.
 .typedef struct bfd_target
 .{
 .  {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  *}
@@ -444,6 +447,7 @@ BFD_JUMP_TABLE macros.
 .  NAME##_bfd_final_link, \
 .  NAME##_bfd_link_split_section, \
 .  NAME##_bfd_gc_sections, \
+.  NAME##_bfd_lookup_section_flags, \
 .  NAME##_bfd_merge_sections, \
 .  NAME##_bfd_is_group_section, \
 .  NAME##_bfd_discard_group, \
@@ -488,6 +492,10 @@ BFD_JUMP_TABLE macros.
 .  {* Remove sections that are not referenced from the output.  *}
 .  bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 .
+.  {* Remove sections with incorrect flags.  *}
+.  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
+.				      struct flag_info *);
+.
 .  {* Attempt to merge SEC_MERGE sections.  *}
 .  bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 .
Index: bfd/tekhex.c
===================================================================
RCS file: /cvs/src/src/bfd/tekhex.c,v
retrieving revision 1.39
diff -p -u -r1.39 tekhex.c
--- bfd/tekhex.c	15 Dec 2009 16:59:20 -0000	1.39
+++ bfd/tekhex.c	24 May 2011 22:28:20 -0000
@@ -943,6 +943,7 @@ tekhex_print_symbol (bfd *abfd,
 #define tekhex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define tekhex_bfd_relax_section                    bfd_generic_relax_section
 #define tekhex_bfd_gc_sections                      bfd_generic_gc_sections
+#define tekhex_bfd_lookup_section_flags		    bfd_generic_lookup_section_flags
 #define tekhex_bfd_merge_sections                   bfd_generic_merge_sections
 #define tekhex_bfd_is_group_section                 bfd_generic_is_group_section
 #define tekhex_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/versados.c
===================================================================
RCS file: /cvs/src/src/bfd/versados.c,v
retrieving revision 1.39
diff -p -u -r1.39 versados.c
--- bfd/versados.c	27 Jun 2010 04:07:53 -0000	1.39
+++ bfd/versados.c	24 May 2011 22:28:20 -0000
@@ -806,6 +806,7 @@ versados_canonicalize_reloc (bfd *abfd,
 #define versados_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define versados_bfd_relax_section                    bfd_generic_relax_section
 #define versados_bfd_gc_sections                      bfd_generic_gc_sections
+#define versados_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define versados_bfd_merge_sections                   bfd_generic_merge_sections
 #define versados_bfd_is_group_section                 bfd_generic_is_group_section
 #define versados_bfd_discard_group                    bfd_generic_discard_group
Index: bfd/vms-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/vms-alpha.c,v
retrieving revision 1.44
diff -p -u -r1.44 vms-alpha.c
--- bfd/vms-alpha.c	6 May 2011 10:41:11 -0000	1.44
+++ bfd/vms-alpha.c	24 May 2011 22:28:20 -0000
@@ -9324,6 +9324,7 @@ bfd_vms_get_data (bfd *abfd)
 
 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
+#define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
Index: bfd/xsym.c
===================================================================
RCS file: /cvs/src/src/bfd/xsym.c,v
retrieving revision 1.28
diff -p -u -r1.28 xsym.c
--- bfd/xsym.c	27 Jun 2010 04:07:53 -0000	1.28
+++ bfd/xsym.c	24 May 2011 22:28:20 -0000
@@ -42,6 +42,7 @@
 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_sym_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_sym_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_sym_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_sym_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group
Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.87
diff -p -u -r1.87 bfdlink.h
--- include/bfdlink.h	17 May 2011 13:02:16 -0000	1.87
+++ include/bfdlink.h	24 May 2011 22:28:20 -0000
@@ -224,6 +224,26 @@ enum report_method
   RM_GENERATE_ERROR
 };
 
+typedef enum {with_flags, without_flags} flag_type;
+
+/* A section flag list.  */
+struct flag_info_list
+{
+  flag_type with; 
+  const char *name;
+  bfd_boolean valid;
+  struct flag_info_list *next;
+};
+
+/* Section flag info.  */
+struct flag_info
+{
+  unsigned only_with_flags;
+  unsigned not_with_flags;
+  struct flag_info_list *flag_list;
+  int done;
+};
+
 struct bfd_elf_dynamic_list;
 
 /* This structure holds all the information needed to communicate
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.275
diff -p -u -r1.275 ld.texinfo
--- ld/ld.texinfo	9 May 2011 13:23:25 -0000	1.275
+++ ld/ld.texinfo	24 May 2011 22:28:20 -0000
@@ -1,4 +1,4 @@
-\input texinfo
+@samp{\input exinfo
 @setfilename ld.info
 @c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
 @c 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -3673,6 +3673,7 @@ The full description of an output sectio
   [ALIGN(@var{section_align})]
   [SUBALIGN(@var{subsection_align})]
   [@var{constraint}]
+  [INPUT_SECTION_FLAGS(@var{section_flag_list})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -4310,6 +4311,7 @@ like this:
   [ALIGN(@var{section_align})]
   [SUBALIGN(@var{subsection_align})]
   [@var{constraint}]
+  [INPUT_SECTION_FLAGS(@var{section_flag_list})]
   @{
     @var{output-section-command}
     @var{output-section-command}
@@ -4328,6 +4330,7 @@ remaining section attributes.
 * Forced Output Alignment::	Forced Output Alignment
 * Forced Input Alignment::	Forced Input Alignment
 * Output Section Constraint::   Output section constraint
+* Output Section Input Section Flags::	Output section input section flags
 * Output Section Region::	Output section region
 * Output Section Phdr::		Output section phdr
 * Output Section Fill::		Output section fill
@@ -4488,6 +4491,29 @@ of its input sections are read-only or a
 read-write by using the keyword @code{ONLY_IF_RO} and
 @code{ONLY_IF_RW} respectively.
 
+@node Output Section Input Section Flags
+@subsubsection Output Section Input Section Flags
+@kindex INPUT_SECTION_FLAGS(@var{section_flag_list})
+@cindex input section flags on output sections
+You can specify that an output section should include only those input
+sections with certain section flags or that the output section should
+exclude input sections with the specified flags.
+
+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 text
+section whose section header flags @code{SHF_MERGE} and @code{SHF_STRINGS} are set.
+The output section @samp{.text2} will be comprised of any input text section
+whose section header flag @code{SHF_WRITE} is clear.
+
 @node Output Section Region
 @subsubsection Output Section Region
 @kindex >@var{region}
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.65
diff -p -u -r1.65 ldgram.y
--- ld/ldgram.y	13 Jan 2011 13:29:55 -0000	1.65
+++ ld/ldgram.y	24 May 2011 22:28:20 -0000
@@ -74,6 +74,8 @@ static int error_index;
   struct name_list *name_list;
   int token;
   union etree_union *etree;
+  struct flag_info_list *flag_info_list;
+  struct flag_info *flag_info;
   struct phdr_info
     {
       bfd_boolean filehdr;
@@ -144,13 +146,15 @@ static int error_index;
 %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS
 %token ALIGNMOD AT SUBALIGN PROVIDE PROVIDE_HIDDEN AS_NEEDED
 %type <token> assign_op atype attributes_opt sect_constraint
+%type <flag_info_list> sect_flag_list
+%type <flag_info> sect_flags
 %type <name>  filename
 %token CHIP LIST SECT ABSOLUTE  LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K
 %token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> 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 <versyms> vers_defns
@@ -939,24 +943,77 @@ sect_constraint:
 	|	{ $$ = 0; }
 	;
 
+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->done = FALSE;
+		  n->not_with_flags = 0;
+		  n->only_with_flags = 0;
+		  $$ = n;
+		}
+	|	{ $$ = 0; }
+	;
+
 section:	NAME 		{ ldlex_expression(); }
 		opt_exp_with_type
 		opt_at
 		opt_align
 		opt_subalign	{ ldlex_popstate (); ldlex_script (); }
 		sect_constraint
+		sect_flags
 		'{'
 			{
 			  lang_enter_output_section_statement($1, $3,
 							      sectype,
-							      $5, $6, $4, $8);
+							      $5, $6, $4, $8, $9);
 			}
 		statement_list_opt
  		'}' { ldlex_popstate (); ldlex_expression (); }
 		memspec_opt memspec_at_opt phdr_opt fill_opt
 		{
 		  ldlex_popstate ();
-		  lang_leave_output_section_statement ($17, $14, $16, $15);
+		  lang_leave_output_section_statement ($18, $15, $17, $16);
 		}
 		opt_comma
 		{}
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.370
diff -p -u -r1.370 ldlang.c
--- ld/ldlang.c	23 May 2011 05:41:01 -0000	1.370
+++ ld/ldlang.c	24 May 2011 22:28:20 -0000
@@ -1799,7 +1799,7 @@ lang_insert_orphan (asection *s,
   os_tail = ((lang_output_section_statement_type **)
 	     lang_output_section_statement.tail);
   os = lang_enter_output_section_statement (secname, address, normal_section,
-                                            NULL, NULL, NULL, constraint);
+                                            NULL, NULL, NULL, constraint, NULL);
 
   ps = NULL;
   if (config.build_constructors && *os_tail == os)
@@ -2261,6 +2261,7 @@ lang_add_section (lang_statement_list_ty
   flagword flags = section->flags;
   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;
@@ -2286,6 +2287,20 @@ lang_add_section (lang_statement_list_ty
       return;
     }
 
+  if (output->sectflags)
+    {
+      if (output->sectflags->done == FALSE)
+	bfd_lookup_section_flags (&link_info, output->sectflags);
+
+      if (output->sectflags->only_with_flags != 0
+	  && (output->sectflags->only_with_flags & section->flags) == 0)
+	return;
+
+      if (output->sectflags->not_with_flags != 0
+          && (output->sectflags->not_with_flags & section->flags) != 0)
+	return;
+    }
+
   if (section->output_section != NULL)
     return;
 
@@ -6162,7 +6177,8 @@ lang_enter_output_section_statement (con
 				     etree_type *align,
 				     etree_type *subalign,
 				     etree_type *ebase,
-				     int constraint)
+				     int constraint,
+				     flag_info *sflags)
 {
   lang_output_section_statement_type *os;
 
@@ -6181,6 +6197,7 @@ lang_enter_output_section_statement (con
     os->flags = SEC_NEVER_LOAD;
   os->block_value = 1;
 
+  os->sectflags = sflags;
   /* Make next things chain into subchain of this.  */
   push_stat_ptr (&os->children);
 
@@ -7285,7 +7302,7 @@ lang_enter_overlay_section (const char *
   etree_type *size;
 
   lang_enter_output_section_statement (name, overlay_vma, overlay_section,
-				       0, overlay_subalign, 0, 0);
+				       0, overlay_subalign, 0, 0, 0);
 
   /* If this is the first section, then base the VMA of future
      sections on this one.  This will work correctly even if `.' is
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.97
diff -p -u -r1.97 ldlang.h
--- ld/ldlang.h	3 May 2011 14:56:14 -0000	1.97
+++ ld/ldlang.h	24 May 2011 22:28:20 -0000
@@ -157,6 +157,7 @@ typedef struct lang_output_section_state
   int section_alignment;	/* Alignment of start of section.  */
   int constraint;
   flagword flags;
+  flag_info *sectflags;
   enum section_type sectype;
   unsigned int processed_vma : 1;
   unsigned int processed_lma : 1;
@@ -497,7 +498,8 @@ extern lang_output_section_statement_typ
    enum section_type sectype,
    etree_type *align,
    etree_type *subalign,
-   etree_type *, int);
+   etree_type *, int,
+   flag_info *sflags);
 extern void lang_final
   (void);
 extern void lang_relax_sections
Index: ld/ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.52
diff -p -u -r1.52 ldlex.l
--- ld/ldlex.l	29 Mar 2011 02:52:36 -0000	1.52
+++ ld/ldlex.l	24 May 2011 22:28:21 -0000
@@ -309,6 +309,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([
 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO"	{ RTOKEN(ONLY_IF_RO); }
 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW"	{ RTOKEN(ONLY_IF_RW); }
 <EXPRESSION,BOTH,SCRIPT>"SPECIAL"	{ RTOKEN(SPECIAL); }
+<EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS"	{ RTOKEN(INPUT_SECTION_FLAGS); }
 <BOTH,SCRIPT>"o"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"org"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"l"			{ RTOKEN( LENGTH);}
Index: ld/mri.c
===================================================================
RCS file: /cvs/src/src/ld/mri.c,v
retrieving revision 1.24
diff -p -u -r1.24 mri.c
--- ld/mri.c	13 Jan 2011 13:06:22 -0000	1.24
+++ ld/mri.c	24 May 2011 22:28:21 -0000
@@ -208,7 +208,7 @@ mri_draw_tree (void)
 
 	  lang_enter_output_section_statement (p->name, base,
 					       p->ok_to_load ? normal_section : noload_section,
-					       align, subalign, NULL, 0);
+					       align, subalign, NULL, 0, NULL);
 	  base = 0;
 	  tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
 	  tmp->next = NULL;
Index: ld/testsuite/ld-scripts/section-flags-1.exp
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.exp
diff -N ld/testsuite/ld-scripts/section-flags-1.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.exp	24 May 2011 22:28:21 -0000
@@ -0,0 +1,32 @@
+# 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"
+
+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
Index: ld/testsuite/ld-scripts/section-flags-1.s
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.s
diff -N ld/testsuite/ld-scripts/section-flags-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.s	24 May 2011 22:28:21 -0000
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: ld/testsuite/ld-scripts/section-flags-1.t
===================================================================
RCS file: ld/testsuite/ld-scripts/section-flags-1.t
diff -N ld/testsuite/ld-scripts/section-flags-1.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-scripts/section-flags-1.t	24 May 2011 22:28:21 -0000
@@ -0,0 +1,17 @@
+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
+}

[-- Attachment #3: ppc-backend.patch --]
[-- Type: text/x-patch, Size: 814 bytes --]

Index: elf32-ppc.c
===================================================================
--- elf32-ppc.c	(revision 326234)
+++ elf32-ppc.c	(working copy)
@@ -2320,6 +2320,50 @@ ppc_elf_write_core_note (bfd *abfd, char
     }
 }
 
+static void
+ppc_elf_lookup_section_flags (struct flag_info *finfo) 
+{
+  struct flag_info_list *tf = finfo->flag_list;
+  int with_hex = 0;
+  int without_hex = 0;
+  bfd_boolean valid_flag_found = FALSE;
+
+  while (tf)
+    {
+      if (!strcmp (tf->name, "SHF_PPC_VLE"))
+	{
+	  if (tf->with == with_flags)
+	    with_hex |= SHF_PPC_VLE;
+	  else if (tf->with == without_flags)
+	    without_hex |= SHF_PPC_VLE;
+	  valid_flag_found = TRUE;
+	}
+      tf = tf->next;
+    }
+  finfo->done = TRUE;
+  finfo->only_with_flags = with_hex;
+  finfo->not_with_flags = without_hex;
+}
+

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-24 22:57   ` Catherine Moore
@ 2011-05-25 12:28     ` Tristan Gingold
  2011-06-06 22:02     ` PING " Catherine Moore
  1 sibling, 0 replies; 16+ messages in thread
From: Tristan Gingold @ 2011-05-25 12:28 UTC (permalink / raw)
  To: Catherine Moore; +Cc: Ian Lance Taylor, binutils


On May 25, 2011, at 12:57 AM, Catherine Moore wrote:
> 
> A new patch that addresses these concerns plus a couple that were pointed out by Tristan is attached here.  Tristan, I didn't incorporate your comment regarding the backend hook into the new patch.  I have now filled in bfd_elf_lookup_section_flags to handle all of the ELF common section header flags.

Ok, that makes sense.

>  The backend hook is intended to handle the target-specific flags.  Although, I'm not submitting it at this time, the backend hook that I am using for the PowerPC VLE target is attached as an example.
> 
> Please let me know if there are additional concerns or comments and whether this is okay to commit.

I am not an ELF maintainer, but still I'd like to make three additional comments:

* I think you'd better to use a for statement for this pattern (in ppc_elf_lookup_section_flags and bfd_elf_lookup_section_flags):

+  struct flag_info_list *tf = finfo->flag_list;
..
+
+  while (tf)
+    {
..
+      tf = tf->next;
+    }

Something like:
  for (tf = finfo->flag_list; tf != NULL; tf = tf->next)
clarify the iteration use.

* bfd_generic_lookup_section_flags shouldn't silently accept any flag, but generates an error message.

* I think you should simplify the bfd_lookup_section_flags hook: it should only convert a name to a flag and return an error/success
  status.  All the logical operations (setting only_with_flag or not_with_flag) and error handling should be made by the caller.
  You could add a new function, bfd_lookup_section_flags, to do this work.  This approach will also make the hooks smaller.

  Sorry, I haven't noticed that from your previous patch.

Fell free to argue.

Tristan.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-05-24 22:57   ` Catherine Moore
  2011-05-25 12:28     ` Tristan Gingold
@ 2011-06-06 22:02     ` Catherine Moore
  2011-06-07 13:11       ` Nick Clifton
  1 sibling, 1 reply; 16+ messages in thread
From: Catherine Moore @ 2011-06-06 22:02 UTC (permalink / raw)
  Cc: binutils, Catherine Moore

Hi, Do any of the maintainers have time to review this patch?
Thanks,
Catherine

On 05/24/2011 06:57 PM, Catherine Moore wrote:
> On 05/18/2011 08:07 PM, Ian Lance Taylor wrote:
>> Catherine Moore<clm@codesourcery.com> writes:
>>>
>>> Does this look okay to install?
>>
>> I didn't look at the patch, but I think the documentation needs to use
>> some real section flags, and ideally the set of valid flags should be
>> defined somewhere. It's not obvious what the valid values are.
>>
>> I'm also not sure about the way it appears in a linker script. You have
>> SECTION_FLAGS, which describes a constraint on the input sections
>> attached to an output section, next to things like AT, ALIGN, and
>> SUBALIGN, which describe characteristics of the output section. That is
>> OK, but I think that somebody looking at a linker script is likely to
>> think that SECTION_FLAGS is setting flags for the output section, much
>> as ALIGN sets the alignment of the output section. But that's not what
>> happens at all. So perhaps the name should be something like
>> INPUT_SECTION_FLAGS or perhaps the constraint should be expressed
>> somehow inside the output section definition, in the list of input
>> sections, rather than outside.
>>
>
> A new patch that addresses these concerns plus a couple that were
> pointed out by Tristan is attached here. Tristan, I didn't incorporate
> your comment regarding the backend hook into the new patch. I have now
> filled in bfd_elf_lookup_section_flags to handle all of the ELF common
> section header flags. The backend hook is intended to handle the
> target-specific flags. Although, I'm not submitting it at this time, the
> backend hook that I am using for the PowerPC VLE target is attached as
> an example.
>
> Please let me know if there are additional concerns or comments and
> whether this is okay to commit.
>
> I've tested ppc-elf, mips-elf and arm-coff targets.
>
> Thanks,
> Catherine
>
> bfd/
> 2011-05-24 Catherine Moore <clm@codesourcery.com>
>
> * bfd-in2.h: Regenerated.
> * bfd.c (bfd_lookup_section_flags): New definition.
> * binary.c (binary_bfd_lookup_section_flags): New definition.
> * coff-rs6000.c (rs6000coff_vec): Include
> bfd_generic_lookup_section_flags.
> (pmac_xcoff_vec): Likewise.
> * coffcode.h (coff_bfd_lookup_section_flags): New definition.
> * elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
> (bfd_elf_lookup_section_flags): Declare.
> * elflink.c (bfd_elf_lookup_section_flags): New function.
> * elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
> (elf_backend_lookup_section_flags_hook): Define.
> (elf_backend_data): Add elf_backend_lookup_section_flags_hook.
> * ieee.c (ieee_bfd_lookup_section_flags): New define.
> * ihex.c (ihex_bfd_lookup_section_flags): New define.
> * libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
> (bfd_generic_lookup_section_flags): Declare.
> * libbfd.h: Regenerated.
> * mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
> * mmo.c (mmo_bfd_lookup_section_flags): New definition.
> * oasys.c (oasys_bfd_lookup_section_flags): New definition.
> * pef.c (bfd_pef_bfd_lookup_section_flags): New definition.
> * plugin.c (bfd_plugin_bfd_lookup_section_flags): New definition.
> * ppcboot.c (ppcboot_bfd_lookup_section_flags): New definition.
> * reloc.c (bfd_generic_lookup_section_flags): New function.
> * som.c (som_bfd_lookup_section_flags): New definition.
> * srec.c (srec_bfd_lookup_section_flags): New definition.
> * targets.c (flag_info): Declare.
> (NAME##_bfd_lookup_section_flags): Add to LINK jump table.
> (_bfd_lookup_section_flags): New.
> * tekhex.c (tekhex_bfd_lookup_section_flags): New definition.
> * versados.c (versados_bfd_lookup_section_flags): New definition.
> * vms-alpha.c (alpha_vms_bfd_lookup_section_flag): New definition.
> * xsym.c (bfd_sym_bfd_lookup_section_flags): New definition.
>
>
> include/
> 2011-05-24 Catherine Moore <clm@codesourcery.com>
>
> * bfdlink.h (flag_type): New enumeration.
> (flag_info_list): New structure.
> (flag_info): New structure.
>
> ld/testsuite/
> 2011-05-24 Catherine Moore <clm@codesourcery.com>
>
> * ld-scripts/section-flags-1.exp: New.
> * ld-scripts/section-flags-1.s: New.
> * ld-scripts/section-flags-1.t: New.
>
>
> ld/2011-05-23 Catherine Moore <clm@codesourcery.com>
>
> * ld.texinfo: Document usage of INPUT_SECTION_FLAGS.
> * ldgram.y (section): Recognize sect_flags.
> (sect_flags): New rule.
> (sect_flag_list): New rule.
> * ldlang.c (lang_add_section): Check section flags.
> (lang_enter_output_section_statement): Add argument sflags.
> Initialize sflags field in output statement.
> * ldlang.h (lang_output_section_statement_type): Add flag_info field.
> (lang_enter_output_section_statement): New argument sflags. Update
> all callers.
> * ldlex.l (INPUT_SECTION_FLAGS): New token.
> * mri.c (mri_draw_tree): Update argument list for
> land_enter_output_section_statement.
>
>
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-06 22:02     ` PING " Catherine Moore
@ 2011-06-07 13:11       ` Nick Clifton
  2011-06-22 21:32         ` Catherine Moore
  0 siblings, 1 reply; 16+ messages in thread
From: Nick Clifton @ 2011-06-07 13:11 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils

Hi Catherine,

> Hi, Do any of the maintainers have time to review this patch?

Did you see Tristan's follow up comments on your patch ?

   http://sources.redhat.com/ml/binutils/2011-05/msg00350.html


Some of the comments in the code need clarification:

   +  /* Remove sections with incorrect flags.  */
   +  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
   +                                     struct flag_info *);

I think that you mean "Sets the bitmasks of allowed and disallowed 
section flags" or something like that.  It does not actually remove 
sections at all...

   +  /* This function, if defined, is called to the section flag hex 
value.  */
   +  void (*elf_backend_lookup_section_flags_hook)

The comment here should presumably be: "This function, if defined, is 
called to convert target specific section flags names into hex values."



There appears to be a bug in the change to lang_add_section():

+      if (output->sectflags->only_with_flags != 0
+	  && (output->sectflags->only_with_flags & section->flags) == 0)
+	return;

I think that this will accept any section that contains any combination 
of any of the required flags, rather than only those sections that 
contain all of the required flags.  Ie, I think that the test should be:

+      if (output->sectflags->only_with_flags != 0
+	  && (output->sectflags->only_with_flags & section->flags) != 
output->sectflags->only_with_flags)
+	return;

Either this, or the documentation of how INPUT_SECTION_FLAGS works is wrong.

Following on from this, what would a linker script writer do if they 
wanted to include multiple, different sets of input section flags in 
their output section.  As I read the current the proposed documentation 
this cannot be done.  I suppose that you could add a comma separated 
syntax, ala:

   INPUT_SECTON_FLAGS (SHF_WRITE & SHF_ALLOC, SHF_WRITE & SHF_STRINGS)

But it might be better to go with Ian Lance Taylor's suggestion of 
putting the constraint *inside* the output section description.  Ie 
something like this:

     .text : {
        SECTION_FLAGS(SHF_WRITE & SHF_STRINGS, *(.text))
        SECTION_FLAGS(SHF_WRITE & SHF_ALLOC, *(.text))
      }


In the new bfd_elf_lookup_sections_flags() function there is an awful 
lot of repeated, almost identical code:

   +      if (!strcmp (tf->name, "SHF_WRITE"))
   +	{
   +	  if (tf->with == with_flags)
   +	    with_hex |= SHF_WRITE;
   +	  else if (tf->with == without_flags)
   +	    without_hex |= SHF_WRITE;
   +	}

It would be much cleaner to use an array of section names and flags and 
iterate through it.


Some of the fields in the flag_info structure ought be changed:

   +/* Section flag info.  */
   +struct flag_info
   +{
   +  unsigned only_with_flags;
   +  unsigned not_with_flags;
   +  struct flag_info_list *flag_list;
   +  int done;
   +};

The only_with_flags and not_with_flags fields should be of the type 
"flagword".  The "done" field should be a bfd_boolean and IMHO should be 
renamed to a slightly more descriptive term such as "flags_initialised".

Cheers
   Nick

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-07 13:11       ` Nick Clifton
@ 2011-06-22 21:32         ` Catherine Moore
  2011-06-28 11:37           ` Nick Clifton
  0 siblings, 1 reply; 16+ messages in thread
From: Catherine Moore @ 2011-06-22 21:32 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils, Catherine Moore, Tristan Gingold

[-- Attachment #1: Type: text/plain, Size: 3508 bytes --]

Hi Nick,

Thanks for the patch review.  I've developed a new patch that addresses 
the comments that both you and Tristan made regarding the original 
patch.  I've now associated the INPUT_SECTION_FLAGS with the input 
section specifications instead of the output sectionas you and others 
suggested.  I've tested arm-coff, mips-elf and ppc-elf.  What do you 
think?  Is this okay to commit?

Thanks,
Catherine

Does
On 06/07/2011 09:11 AM, Nick Clifton wrote:
> Hi Catherine,
>
>> Hi, Do any of the maintainers have time to review this patch?
>
> Did you see Tristan's follow up comments on your patch ?
>
> http://sources.redhat.com/ml/binutils/2011-05/msg00350.html
>
>
> Some of the comments in the code need clarification:
>
> + /* Remove sections with incorrect flags. */
> + void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
> + struct flag_info *);
>
> I think that you mean "Sets the bitmasks of allowed and disallowed
> section flags" or something like that. It does not actually remove
> sections at all...
>
> + /* This function, if defined, is called to the section flag hex value. */
> + void (*elf_backend_lookup_section_flags_hook)
>
> The comment here should presumably be: "This function, if defined, is
> called to convert target specific section flags names into hex values."
>
>
>
> There appears to be a bug in the change to lang_add_section():
>
> + if (output->sectflags->only_with_flags != 0
> + && (output->sectflags->only_with_flags & section->flags) == 0)
> + return;
>
> I think that this will accept any section that contains any combination
> of any of the required flags, rather than only those sections that
> contain all of the required flags. Ie, I think that the test should be:
>
> + if (output->sectflags->only_with_flags != 0
> + && (output->sectflags->only_with_flags & section->flags) !=
> output->sectflags->only_with_flags)
> + return;
>
> Either this, or the documentation of how INPUT_SECTION_FLAGS works is
> wrong.
>
> Following on from this, what would a linker script writer do if they
> wanted to include multiple, different sets of input section flags in
> their output section. As I read the current the proposed documentation
> this cannot be done. I suppose that you could add a comma separated
> syntax, ala:
>
> INPUT_SECTON_FLAGS (SHF_WRITE & SHF_ALLOC, SHF_WRITE & SHF_STRINGS)
>
> But it might be better to go with Ian Lance Taylor's suggestion of
> putting the constraint *inside* the output section description. Ie
> something like this:
>
> .text : {
> SECTION_FLAGS(SHF_WRITE & SHF_STRINGS, *(.text))
> SECTION_FLAGS(SHF_WRITE & SHF_ALLOC, *(.text))
> }
>
>
> In the new bfd_elf_lookup_sections_flags() function there is an awful
> lot of repeated, almost identical code:
>
> + if (!strcmp (tf->name, "SHF_WRITE"))
> + {
> + if (tf->with == with_flags)
> + with_hex |= SHF_WRITE;
> + else if (tf->with == without_flags)
> + without_hex |= SHF_WRITE;
> + }
>
> It would be much cleaner to use an array of section names and flags and
> iterate through it.
>
>
> Some of the fields in the flag_info structure ought be changed:
>
> +/* Section flag info. */
> +struct flag_info
> +{
> + unsigned only_with_flags;
> + unsigned not_with_flags;
> + struct flag_info_list *flag_list;
> + int done;
> +};
>
> The only_with_flags and not_with_flags fields should be of the type
> "flagword". The "done" field should be a bfd_boolean and IMHO should be
> renamed to a slightly more descriptive term such as "flags_initialised".
>
> Cheers
> Nick


[-- Attachment #2: include.cl --]
[-- Type: text/plain, Size: 160 bytes --]

2011-06-22  Catherine Moore  <clm@codesourcery.com>

	* bfdlink.h (flag_type): New enumeration.
	(flag_info_list): New structure.
	(flag_info): New structure.


[-- Attachment #3: include.patch --]
[-- Type: text/x-patch, Size: 805 bytes --]

Index: bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.88
diff -u -r1.88 bfdlink.h
--- bfdlink.h	20 Jun 2011 13:18:48 -0000	1.88
+++ bfdlink.h	22 Jun 2011 20:40:13 -0000
@@ -224,6 +224,26 @@
   RM_GENERATE_ERROR
 };
 
+typedef enum {with_flags, without_flags} flag_type;
+
+/* A section flag list.  */
+struct flag_info_list
+{
+  flag_type with; 
+  const char *name;
+  bfd_boolean valid;
+  struct flag_info_list *next;
+};
+
+/* Section flag info.  */
+struct flag_info
+{
+  flagword only_with_flags;
+  flagword not_with_flags;
+  struct flag_info_list *flag_list;
+  bfd_boolean flags_initialized;
+};
+
 struct bfd_elf_dynamic_list;
 
 /* This structure holds all the information needed to communicate

[-- Attachment #4: ld.cl --]
[-- Type: text/plain, Size: 900 bytes --]

2011-06-22  Catherine Moore  <clm@codesourcery.com>

	* ld.h (section_flag_list): Add field to struct wildcard_spec.
	* ld.texinfo (INPUT_SECTION_FLAGS): Document.
	* ldgram.y (flag_info_list, flag_info): Add to union.
	(INPUT_SECTION_FLAGS): New token.
	(wildcard_spec): Initialize section_flag_list to NULL for
	each alternative.
	(sect_flag_list, sect_flags): New rules.
	(input_section_spec_no_keep): Add alternatives to recognize
	sect_flags.
	* ldlang.c (walk_wild_consider_section): Initialize
	section_flag_info field of the section struct.
	(lang_add_section): Check input section flags.
	(lang_add_wild): Initialize section_flag_list field of 
	the statement struct.
	* ldlang.h (lang_input_statement_struct): Add section_flag_list field.
	(lang_wild_statement_struct): Likewise.
	* ldlex.l (INPUT_SECTION_FLAGS): New token.
	* mri.c (mri_draw_tree): Initialize section_flag_list to NULL.


[-- Attachment #5: ld.patch --]
[-- Type: text/x-patch, Size: 12966 bytes --]

Index: ld.h
===================================================================
--- ld.h	(revision 329725)
+++ ld.h	(working copy)
@@ -95,6 +95,7 @@ struct wildcard_spec {
   const char *name;
   struct name_list *exclude_name_list;
   sort_type sorted;
+  struct flag_info *section_flag_list;
 };
 
 struct wildcard_list {
Index: testsuite/ld-scripts/section-flags-1.s
===================================================================
--- testsuite/ld-scripts/section-flags-1.s	(revision 0)
+++ testsuite/ld-scripts/section-flags-1.s	(revision 0)
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: testsuite/ld-scripts/section-flags-1.t
===================================================================
--- testsuite/ld-scripts/section-flags-1.t	(revision 0)
+++ testsuite/ld-scripts/section-flags-1.t	(revision 0)
@@ -0,0 +1,17 @@
+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
+}
Index: testsuite/ld-scripts/section-flags.exp
===================================================================
--- testsuite/ld-scripts/section-flags.exp	(revision 0)
+++ testsuite/ld-scripts/section-flags.exp	(revision 0)
@@ -0,0 +1,45 @@
+# 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"
+
+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
Index: testsuite/ld-scripts/section-flags-2.s
===================================================================
--- testsuite/ld-scripts/section-flags-2.s	(revision 0)
+++ testsuite/ld-scripts/section-flags-2.s	(revision 0)
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: testsuite/ld-scripts/section-flags-2.t
===================================================================
--- testsuite/ld-scripts/section-flags-2.t	(revision 0)
+++ testsuite/ld-scripts/section-flags-2.t	(revision 0)
@@ -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: ldlang.c
===================================================================
--- ldlang.c	(revision 329725)
+++ ldlang.c	(working copy)
@@ -232,6 +232,9 @@ walk_wild_consider_section (lang_wild_st
 {
   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;
@@ -2186,8 +2189,11 @@ lang_add_section (lang_statement_list_ty
 		  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;
@@ -2213,6 +2219,21 @@ lang_add_section (lang_statement_list_ty
       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->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;
 
@@ -6455,6 +6476,7 @@ lang_add_wild (struct wildcard_spec *fil
     {
       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
===================================================================
--- ldlang.h	(revision 329725)
+++ ldlang.h	(working copy)
@@ -157,6 +157,7 @@ typedef struct lang_output_section_state
   int section_alignment;	/* Alignment of start of section.  */
   int constraint;
   flagword flags;
+  flag_info *sectflags;
   enum section_type sectype;
   unsigned int processed_vma : 1;
   unsigned int processed_lma : 1;
@@ -240,6 +241,8 @@ typedef struct lang_input_statement_stru
 
   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;
@@ -328,6 +331,7 @@ struct lang_wild_statement_struct
   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
===================================================================
--- ldlex.l	(revision 329725)
+++ ldlex.l	(working copy)
@@ -309,6 +309,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([
 <BOTH,SCRIPT>"org"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"l"			{ RTOKEN( LENGTH);}
 <BOTH,SCRIPT>"len"			{ RTOKEN( LENGTH);}
+<EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS"	{ RTOKEN(INPUT_SECTION_FLAGS); }
 <EXPRESSION,BOTH,SCRIPT>"INCLUDE"	{ RTOKEN(INCLUDE);}
 <BOTH,SCRIPT>"PHDRS"			{ RTOKEN (PHDRS); }
 <EXPRESSION,BOTH,SCRIPT>"AT"		{ RTOKEN(AT);}
Index: ldgram.y
===================================================================
--- ldgram.y	(revision 329732)
+++ ldgram.y	(working copy)
@@ -72,6 +72,8 @@ static int error_index;
   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 @@ static int error_index;
 %type <fill> fill_opt fill_exp
 %type <name_list> exclude_name_list
 %type <wildcard_list> file_NAME_list
+%type <flag_info_list> sect_flag_list
+%type <flag_info> sect_flags
 %type <name> memspec_opt casesymlist
 %type <name> memspec_at_opt
 %type <cname> wildcard_name
@@ -148,7 +152,7 @@ static int error_index;
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> 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 <versyms> vers_defns
@@ -433,54 +437,114 @@ wildcard_spec:
 			  $$.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;
+			}
+	;
+
+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;
 			}
 	;
 
@@ -533,14 +597,37 @@ input_section_spec_no_keep:
 			  tmp.sorted = none;
 			  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: ld.texinfo
===================================================================
--- ld.texinfo	(revision 329725)
+++ ld.texinfo	(working copy)
@@ -3802,6 +3802,26 @@ needs to be at a particular location in 
 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.

[-- Attachment #6: ld-test.cl --]
[-- Type: text/plain, Size: 238 bytes --]

2011-06-22  Catherine Moore  <clm@cm00re.com>

	* 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.


[-- Attachment #7: ld-test.patch --]
[-- Type: text/x-patch, Size: 3567 bytes --]

Index: ld-scripts/section-flags-1.s
===================================================================
RCS file: ld-scripts/section-flags-1.s
diff -N ld-scripts/section-flags-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-scripts/section-flags-1.s	22 Jun 2011 21:07:53 -0000
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: ld-scripts/section-flags-1.t
===================================================================
RCS file: ld-scripts/section-flags-1.t
diff -N ld-scripts/section-flags-1.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-scripts/section-flags-1.t	22 Jun 2011 21:07:53 -0000
@@ -0,0 +1,17 @@
+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
+}
Index: ld-scripts/section-flags-2.s
===================================================================
RCS file: ld-scripts/section-flags-2.s
diff -N ld-scripts/section-flags-2.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-scripts/section-flags-2.s	22 Jun 2011 21:07:53 -0000
@@ -0,0 +1,2 @@
+	.text
+	.space 16
Index: ld-scripts/section-flags-2.t
===================================================================
RCS file: ld-scripts/section-flags-2.t
diff -N ld-scripts/section-flags-2.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-scripts/section-flags-2.t	22 Jun 2011 21:07:53 -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: ld-scripts/section-flags.exp
===================================================================
RCS file: ld-scripts/section-flags.exp
diff -N ld-scripts/section-flags.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-scripts/section-flags.exp	22 Jun 2011 21:07:53 -0000
@@ -0,0 +1,45 @@
+# 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"
+
+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

[-- Attachment #8: bfd.cl --]
[-- Type: text/plain, Size: 1903 bytes --]

2011-06-22  Catherine Moore  <clm@codesourcery.com>

        * bfd-in2.h: Regenerated.
	* bfd.c (bfd_lookup_section_flags): New definition.
	* binary.c (binary_bfd_lookup_section_flags): New definition.
	* coff-rs6000.c (rs6000coff_vec): Include
	bfd_generic_lookup_section_flags.
	(pmac_xcoff_vec): Likewise.
	* coffcode.h (coff_bfd_lookup_section_flags): New definition.
	* elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
	(bfd_elf_lookup_section_flags): Declare.
	* elflink.c (bfd_elf_lookup_section_flags): New function.
	* elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
	(elf_backend_lookup_section_flags_hook): Define.
	(elf_backend_data): Add elf_backend_lookup_section_flags_hook.
	* ieee.c (ieee_bfd_lookup_section_flags): New define.
	* ihex.c (ihex_bfd_lookup_section_flags): New define.
	* libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
	(bfd_generic_lookup_section_flags): Declare.
	* libbfd.h: Regenerated.
	* mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
	* mmo.c (mmo_bfd_lookup_section_flags): New definition.
	* oasys.c (oasys_bfd_lookup_section_flags): New definition.
	* pef.c (bfd_pef_bfd_lookup_section_flags): New definition.
	* plugin.c (bfd_plugin_bfd_lookup_section_flags): New definition.
	* ppcboot.c (ppcboot_bfd_lookup_section_flags): New definition.
	* reloc.c (bfd_generic_lookup_section_flags): New function.
	* som.c (som_bfd_lookup_section_flags): New definition.
	* srec.c (srec_bfd_lookup_section_flags): New definition.
	* targets.c (flag_info): Declare.
	(NAME##_bfd_lookup_section_flags): Add to LINK jump table.
	(_bfd_lookup_section_flags): New.
	* tekhex.c (tekhex_bfd_lookup_section_flags): New definition.
	* versados.c (versados_bfd_lookup_section_flags): New definition.
	* vms-alpha.c (alpha_vms_bfd_lookup_section_flag): New definition.
	* xsym.c (bfd_sym_bfd_lookup_section_flags): New definition.


[-- Attachment #9: bfd.patch --]
[-- Type: text/x-patch, Size: 25902 bytes --]

Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.539
diff -u -r1.539 bfd-in2.h
--- bfd-in2.h	13 Jun 2011 15:18:45 -0000	1.539
+++ bfd-in2.h	22 Jun 2011 20:25:30 -0000
@@ -1513,6 +1513,9 @@
   /* The BFD which owns the section.  */
   bfd *owner;
 
+  /* INPUT_SECTION_FLAGS if specified in the linker script.  */
+  struct flag_info *section_flag_info;
+
   /* A symbol which points at this section only.  */
   struct bfd_symbol *symbol;
   struct bfd_symbol **symbol_ptr_ptr;
@@ -1691,6 +1694,9 @@
   /* target_index, used_by_bfd, constructor_chain, owner,          */  \
      0,            NULL,        NULL,              NULL,               \
                                                                        \
+  /* flag_info,                                                    */  \
+     NULL,                                                             \
+                                                                       \
   /* symbol,                    symbol_ptr_ptr,                    */  \
      (struct bfd_symbol *) SYM, &SEC.symbol,                           \
                                                                        \
@@ -5570,6 +5576,9 @@
 #define bfd_gc_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 
+#define bfd_lookup_section_flags(link_info, flag_info) \
+       BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
+
 #define bfd_merge_sections(abfd, link_info) \
        BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 
@@ -5726,6 +5735,9 @@
 /* Forward declaration.  */
 typedef struct bfd_link_info _bfd_link_info;
 
+/* Forward declaration.  */
+typedef struct flag_info flag_info;
+
 typedef struct bfd_target
 {
   /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
@@ -5995,6 +6007,7 @@
   NAME##_bfd_final_link, \
   NAME##_bfd_link_split_section, \
   NAME##_bfd_gc_sections, \
+  NAME##_bfd_lookup_section_flags, \
   NAME##_bfd_merge_sections, \
   NAME##_bfd_is_group_section, \
   NAME##_bfd_discard_group, \
@@ -6039,6 +6052,10 @@
   /* Remove sections that are not referenced from the output.  */
   bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 
+  /* Sets the bitmask of allowed and disallowed section flags.  */
+  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
+                                     struct flag_info *);
+
   /* Attempt to merge SEC_MERGE sections.  */
   bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.117
diff -u -r1.117 bfd.c
--- bfd.c	9 Jun 2011 15:31:41 -0000	1.117
+++ bfd.c	22 Jun 2011 20:25:30 -0000
@@ -1374,6 +1374,9 @@
 .#define bfd_gc_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
 .
+.#define bfd_lookup_section_flags(link_info, flag_info) \
+.	BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
+.
 .#define bfd_merge_sections(abfd, link_info) \
 .	BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
 .
Index: binary.c
===================================================================
RCS file: /cvs/src/src/bfd/binary.c,v
retrieving revision 1.40
diff -u -r1.40 binary.c
--- binary.c	6 Jun 2011 01:26:01 -0000	1.40
+++ binary.c	22 Jun 2011 20:25:30 -0000
@@ -299,6 +299,7 @@
 #define binary_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define binary_bfd_relax_section                   bfd_generic_relax_section
 #define binary_bfd_gc_sections                     bfd_generic_gc_sections
+#define binary_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define binary_bfd_merge_sections                  bfd_generic_merge_sections
 #define binary_bfd_is_group_section                bfd_generic_is_group_section
 #define binary_bfd_discard_group                   bfd_generic_discard_group
Index: coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.102
diff -u -r1.102 coff-rs6000.c
--- coff-rs6000.c	6 Jun 2011 01:26:02 -0000	1.102
+++ coff-rs6000.c	22 Jun 2011 20:25:30 -0000
@@ -4102,6 +4102,7 @@
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
@@ -4356,6 +4357,7 @@
     _bfd_xcoff_bfd_final_link,
     _bfd_generic_link_split_section,
     bfd_generic_gc_sections,
+    bfd_generic_lookup_section_flags,
     bfd_generic_merge_sections,
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
Index: coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.179
diff -u -r1.179 coffcode.h
--- coffcode.h	6 Jun 2011 01:26:02 -0000	1.179
+++ coffcode.h	22 Jun 2011 20:25:30 -0000
@@ -5652,6 +5652,10 @@
 #define coff_bfd_gc_sections		    bfd_generic_gc_sections
 #endif
 
+#ifndef coff_bfd_lookup_section_flags
+#define coff_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
+#endif
+
 #ifndef coff_bfd_merge_sections
 #define coff_bfd_merge_sections		    bfd_generic_merge_sections
 #endif
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.323
diff -u -r1.323 elf-bfd.h
--- elf-bfd.h	15 Jun 2011 16:36:55 -0000	1.323
+++ elf-bfd.h	22 Jun 2011 20:25:30 -0000
@@ -1112,6 +1112,11 @@
   char *(*elf_backend_write_core_note)
     (bfd *abfd, char *buf, int *bufsiz, int note_type, ...);
 
+  /* This function, if defined, is called to convert target-specific
+     section flag names into hex values.  */
+  flagword (*elf_backend_lookup_section_flags_hook)
+    (char *);
+
   /* This function returns class of a reloc type.  */
   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
     (const Elf_Internal_Rela *);
@@ -2193,6 +2198,9 @@
 
 extern int bfd_elf_get_default_section_type (flagword);
 
+extern void bfd_elf_lookup_section_flags
+  (struct bfd_link_info *, struct flag_info *);
+
 extern Elf_Internal_Phdr * _bfd_elf_find_segment_containing_section
   (bfd * abfd, asection * section);
 
Index: elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.412
diff -u -r1.412 elflink.c
--- elflink.c	21 Jun 2011 14:55:26 -0000	1.412
+++ elflink.c	22 Jun 2011 20:25:30 -0000
@@ -12167,6 +12167,83 @@
   return TRUE;
 }
 
+/* Map an ELF section header flag to its corresponding string.  */
+typedef struct
+{
+  char *flag_name;
+  flagword flag_value;
+} elf_flags_to_name_table;
+
+static elf_flags_to_name_table elf_flags_to_names [] =
+{
+  { "SHF_WRITE", SHF_WRITE },
+  { "SHF_ALLOC", SHF_ALLOC },
+  { "SHF_EXECINSTR", SHF_EXECINSTR },
+  { "SHF_MERGE", SHF_MERGE },
+  { "SHF_STRINGS", SHF_STRINGS },
+  { "SHF_INFO_LINK", SHF_INFO_LINK},
+  { "SHF_LINK_ORDER", SHF_LINK_ORDER},
+  { "SHF_OS_NONCONFORMING", SHF_OS_NONCONFORMING},
+  { "SHF_GROUP", SHF_GROUP },
+  { "SHF_TLS", SHF_TLS },
+  { "SHF_MASKOS", SHF_MASKOS },
+  { "SHF_EXCLUDE", SHF_EXCLUDE },
+};
+
+void
+bfd_elf_lookup_section_flags (struct bfd_link_info *info,
+			      struct flag_info *finfo)
+{
+  bfd *output_bfd = info->output_bfd;
+  const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
+  struct flag_info_list *tf = finfo->flag_list;
+  int with_hex = 0;
+  int without_hex = 0;
+
+  for (tf = finfo->flag_list; tf != NULL; tf = tf->next)
+    {
+      int i;
+      if (bed->elf_backend_lookup_section_flags_hook)
+	{
+	  flagword hexval =
+	     (*bed->elf_backend_lookup_section_flags_hook) ((char *) tf->name);
+
+	  if (hexval != 0)
+	    {
+	      if (tf->with == with_flags)
+		with_hex |= hexval;
+	      else if (tf->with == without_flags)
+		without_hex |= hexval;
+	      tf->valid = TRUE;
+	      continue;
+	    }
+	}
+      for (i = 0; i < 12; i++)
+	{
+	  if (!strcmp (tf->name, elf_flags_to_names[i].flag_name))
+	    {
+	      if (tf->with == with_flags)
+		with_hex |= elf_flags_to_names[i].flag_value;
+	      else if (tf->with == without_flags)
+		without_hex |= elf_flags_to_names[i].flag_value;
+	      tf->valid = TRUE;
+	      continue;
+	    }
+	}
+      if (tf->valid == FALSE)
+	{
+	  info->callbacks->einfo 
+		(_("Unrecognized INPUT_SECTION_FLAG %s\n"), tf->name);
+	  return;
+	}
+    }
+ finfo->flags_initialized = TRUE;
+ finfo->only_with_flags |= with_hex;
+ finfo->not_with_flags |= without_hex;
+
+ return;
+}
+
 struct alloc_got_off_arg {
   bfd_vma gotoff;
   struct bfd_link_info *info;
Index: elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.126
diff -u -r1.126 elfxx-target.h
--- elfxx-target.h	14 Jun 2011 02:45:12 -0000	1.126
+++ elfxx-target.h	22 Jun 2011 20:25:30 -0000
@@ -174,6 +174,10 @@
 #define bfd_elfNN_bfd_define_common_symbol bfd_generic_define_common_symbol
 #endif
 
+#ifndef bfd_elfNN_bfd_lookup_section_flags
+#define bfd_elfNN_bfd_lookup_section_flags bfd_elf_lookup_section_flags
+#endif
+
 #ifndef bfd_elfNN_bfd_make_debug_symbol
 #define bfd_elfNN_bfd_make_debug_symbol \
   ((asymbol * (*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
@@ -529,6 +533,9 @@
 #ifndef elf_backend_write_core_note
 #define elf_backend_write_core_note		NULL
 #endif
+#ifndef elf_backend_lookup_section_flags_hook
+#define elf_backend_lookup_section_flags_hook	NULL
+#endif
 #ifndef elf_backend_reloc_type_class
 #define elf_backend_reloc_type_class		_bfd_elf_reloc_type_class
 #endif
@@ -717,6 +724,7 @@
   elf_backend_grok_prstatus,
   elf_backend_grok_psinfo,
   elf_backend_write_core_note,
+  elf_backend_lookup_section_flags_hook,
   elf_backend_reloc_type_class,
   elf_backend_discard_info,
   elf_backend_ignore_discarded_relocs,
Index: ieee.c
===================================================================
RCS file: /cvs/src/src/bfd/ieee.c,v
retrieving revision 1.71
diff -u -r1.71 ieee.c
--- ieee.c	6 Jun 2011 01:26:03 -0000	1.71
+++ ieee.c	22 Jun 2011 20:25:30 -0000
@@ -3772,6 +3772,7 @@
   bfd_generic_get_relocated_section_contents
 #define ieee_bfd_relax_section bfd_generic_relax_section
 #define ieee_bfd_gc_sections bfd_generic_gc_sections
+#define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ieee_bfd_merge_sections bfd_generic_merge_sections
 #define ieee_bfd_is_group_section bfd_generic_is_group_section
 #define ieee_bfd_discard_group bfd_generic_discard_group
Index: ihex.c
===================================================================
RCS file: /cvs/src/src/bfd/ihex.c,v
retrieving revision 1.41
diff -u -r1.41 ihex.c
--- ihex.c	6 Jun 2011 01:26:03 -0000	1.41
+++ ihex.c	22 Jun 2011 20:25:30 -0000
@@ -930,6 +930,7 @@
 #define ihex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define ihex_bfd_relax_section                    bfd_generic_relax_section
 #define ihex_bfd_gc_sections                      bfd_generic_gc_sections
+#define ihex_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define ihex_bfd_merge_sections                   bfd_generic_merge_sections
 #define ihex_bfd_is_group_section                 bfd_generic_is_group_section
 #define ihex_bfd_discard_group                    bfd_generic_discard_group
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.88
diff -u -r1.88 libbfd-in.h
--- libbfd-in.h	28 Apr 2011 12:50:32 -0000	1.88
+++ libbfd-in.h	22 Jun 2011 20:25:30 -0000
@@ -453,6 +453,9 @@
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (struct bfd_link_info *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.252
diff -u -r1.252 libbfd.h
--- libbfd.h	13 Jun 2011 15:18:46 -0000	1.252
+++ libbfd.h	22 Jun 2011 20:25:30 -0000
@@ -458,6 +458,9 @@
 #define _bfd_nolink_bfd_gc_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
+#define _bfd_nolink_bfd_lookup_section_flags \
+  ((void (*) (struct bfd_link_info *, struct flag_info *)) \
+   bfd_0)
 #define _bfd_nolink_bfd_merge_sections \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
    bfd_false)
@@ -2452,6 +2455,9 @@
 bfd_boolean bfd_generic_gc_sections
    (bfd *, struct bfd_link_info *);
 
+void bfd_generic_lookup_section_flags
+   (struct bfd_link_info *, struct flag_info *);
+
 bfd_boolean bfd_generic_merge_sections
    (bfd *, struct bfd_link_info *);
 
Index: mach-o-target.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-target.c,v
retrieving revision 1.17
diff -u -r1.17 mach-o-target.c
--- mach-o-target.c	6 Jun 2011 01:26:03 -0000	1.17
+++ mach-o-target.c	22 Jun 2011 20:25:30 -0000
@@ -51,6 +51,7 @@
 #define bfd_mach_o_bfd_set_private_flags              _bfd_generic_bfd_set_private_flags
 #define bfd_mach_o_get_section_contents               _bfd_generic_get_section_contents
 #define bfd_mach_o_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_mach_o_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_mach_o_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_mach_o_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group                  bfd_generic_discard_group
Index: mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.42
diff -u -r1.42 mmo.c
--- mmo.c	6 Jun 2011 01:26:03 -0000	1.42
+++ mmo.c	22 Jun 2011 20:25:30 -0000
@@ -3190,6 +3190,7 @@
 #define mmo_bfd_get_relocated_section_contents \
   bfd_generic_get_relocated_section_contents
 #define mmo_bfd_gc_sections bfd_generic_gc_sections
+#define mmo_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define mmo_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: oasys.c
===================================================================
RCS file: /cvs/src/src/bfd/oasys.c,v
retrieving revision 1.46
diff -u -r1.46 oasys.c
--- oasys.c	6 Jun 2011 01:26:03 -0000	1.46
+++ oasys.c	22 Jun 2011 20:25:30 -0000
@@ -1196,6 +1196,7 @@
 #define oasys_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define oasys_bfd_relax_section                    bfd_generic_relax_section
 #define oasys_bfd_gc_sections                      bfd_generic_gc_sections
+#define oasys_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define oasys_bfd_merge_sections                   bfd_generic_merge_sections
 #define oasys_bfd_is_group_section                 bfd_generic_is_group_section
 #define oasys_bfd_discard_group                    bfd_generic_discard_group
Index: pef.c
===================================================================
RCS file: /cvs/src/src/bfd/pef.c,v
retrieving revision 1.32
diff -u -r1.32 pef.c
--- pef.c	6 Jun 2011 01:26:03 -0000	1.32
+++ pef.c	22 Jun 2011 20:25:30 -0000
@@ -48,6 +48,7 @@
 #define bfd_pef_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_pef_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_pef_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_pef_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_pef_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_pef_bfd_is_group_section		    bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
Index: plugin.c
===================================================================
RCS file: /cvs/src/src/bfd/plugin.c,v
retrieving revision 1.13
diff -u -r1.13 plugin.c
--- plugin.c	6 Jun 2011 01:26:03 -0000	1.13
+++ plugin.c	22 Jun 2011 20:25:30 -0000
@@ -63,6 +63,7 @@
 #define bfd_plugin_bfd_final_link                     _bfd_generic_final_link
 #define bfd_plugin_bfd_link_split_section             _bfd_generic_link_split_section
 #define bfd_plugin_bfd_gc_sections                    bfd_generic_gc_sections
+#define bfd_plugin_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
 #define bfd_plugin_bfd_merge_sections                 bfd_generic_merge_sections
 #define bfd_plugin_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_plugin_bfd_discard_group                  bfd_generic_discard_group
Index: ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.34
diff -u -r1.34 ppcboot.c
--- ppcboot.c	6 Jun 2011 01:26:03 -0000	1.34
+++ ppcboot.c	22 Jun 2011 20:25:30 -0000
@@ -470,6 +470,7 @@
   bfd_generic_get_relocated_section_contents
 #define ppcboot_bfd_relax_section bfd_generic_relax_section
 #define ppcboot_bfd_gc_sections bfd_generic_gc_sections
+#define ppcboot_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define ppcboot_bfd_merge_sections bfd_generic_merge_sections
 #define ppcboot_bfd_is_group_section bfd_generic_is_group_section
 #define ppcboot_bfd_discard_group bfd_generic_discard_group
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.214
diff -u -r1.214 reloc.c
--- reloc.c	13 Jun 2011 15:18:46 -0000	1.214
+++ reloc.c	22 Jun 2011 20:25:31 -0000
@@ -6044,6 +6044,30 @@
 
 /*
 INTERNAL_FUNCTION
+	bfd_generic_lookup_section_flags
+
+SYNOPSIS
+	void bfd_generic_lookup_section_flags
+	  (struct bfd_link_info *, struct flag_info *);
+
+DESCRIPTION
+	Provides default handling for section flags lookup
+	-- i.e., does nothing.
+*/
+
+void
+bfd_generic_lookup_section_flags (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+				  struct flag_info *finfo) 
+{
+  if (finfo != NULL)
+    {
+      (*_bfd_error_handler) (_("INPUT_SECTION_FLAGS are not supported.\n"));
+      return;
+    }
+}
+
+/*
+INTERNAL_FUNCTION
 	bfd_generic_merge_sections
 
 SYNOPSIS
Index: section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.110
diff -u -r1.110 section.c
--- section.c	7 May 2011 14:12:59 -0000	1.110
+++ section.c	22 Jun 2011 20:25:31 -0000
@@ -516,6 +516,9 @@
 .  {* The BFD which owns the section.  *}
 .  bfd *owner;
 .
+.  {* INPUT_SECTION_FLAGS if specified in the linker script.  *}
+.  struct flag_info *section_flag_info;
+.
 .  {* A symbol which points at this section only.  *}
 .  struct bfd_symbol *symbol;
 .  struct bfd_symbol **symbol_ptr_ptr;
@@ -694,6 +697,9 @@
 .  {* target_index, used_by_bfd, constructor_chain, owner,          *}	\
 .     0,            NULL,        NULL,              NULL,		\
 .									\
+.  {* flag_info,						    *}  \
+.     NULL,								\
+.									\
 .  {* symbol,                    symbol_ptr_ptr,                    *}	\
 .     (struct bfd_symbol *) SYM, &SEC.symbol,				\
 .									\
Index: som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.84
diff -u -r1.84 som.c
--- som.c	6 Jun 2011 01:26:03 -0000	1.84
+++ som.c	22 Jun 2011 20:25:31 -0000
@@ -6741,6 +6741,7 @@
   _bfd_generic_copy_link_hash_symbol_type
 #define som_bfd_final_link                      _bfd_generic_final_link
 #define som_bfd_gc_sections		        bfd_generic_gc_sections
+#define som_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define som_bfd_merge_sections		        bfd_generic_merge_sections
 #define som_bfd_is_group_section	        bfd_generic_is_group_section
 #define som_bfd_discard_group		        bfd_generic_discard_group
Index: srec.c
===================================================================
RCS file: /cvs/src/src/bfd/srec.c,v
retrieving revision 1.51
diff -u -r1.51 srec.c
--- srec.c	6 Jun 2011 01:26:04 -0000	1.51
+++ srec.c	22 Jun 2011 20:25:31 -0000
@@ -1252,6 +1252,7 @@
 #define srec_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define srec_bfd_relax_section                    bfd_generic_relax_section
 #define srec_bfd_gc_sections                      bfd_generic_gc_sections
+#define srec_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define srec_bfd_merge_sections                   bfd_generic_merge_sections
 #define srec_bfd_is_group_section                 bfd_generic_is_group_section
 #define srec_bfd_discard_group                    bfd_generic_discard_group
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.202
diff -u -r1.202 targets.c
--- targets.c	13 Jun 2011 15:18:46 -0000	1.202
+++ targets.c	22 Jun 2011 20:25:31 -0000
@@ -177,6 +177,9 @@
 .{* Forward declaration.  *}
 .typedef struct bfd_link_info _bfd_link_info;
 .
+.{* Forward declaration.  *}
+.typedef struct flag_info flag_info;
+.
 .typedef struct bfd_target
 .{
 .  {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  *}
@@ -448,6 +451,7 @@
 .  NAME##_bfd_final_link, \
 .  NAME##_bfd_link_split_section, \
 .  NAME##_bfd_gc_sections, \
+.  NAME##_bfd_lookup_section_flags, \
 .  NAME##_bfd_merge_sections, \
 .  NAME##_bfd_is_group_section, \
 .  NAME##_bfd_discard_group, \
@@ -492,6 +496,10 @@
 .  {* Remove sections that are not referenced from the output.  *}
 .  bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
 .
+.  {* Sets the bitmask of allowed and disallowed section flags.  *}
+.  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
+.				      struct flag_info *);
+.
 .  {* Attempt to merge SEC_MERGE sections.  *}
 .  bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
 .
Index: tekhex.c
===================================================================
RCS file: /cvs/src/src/bfd/tekhex.c,v
retrieving revision 1.40
diff -u -r1.40 tekhex.c
--- tekhex.c	6 Jun 2011 01:26:04 -0000	1.40
+++ tekhex.c	22 Jun 2011 20:25:31 -0000
@@ -943,6 +943,7 @@
 #define tekhex_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define tekhex_bfd_relax_section                    bfd_generic_relax_section
 #define tekhex_bfd_gc_sections                      bfd_generic_gc_sections
+#define tekhex_bfd_lookup_section_flags		    bfd_generic_lookup_section_flags
 #define tekhex_bfd_merge_sections                   bfd_generic_merge_sections
 #define tekhex_bfd_is_group_section                 bfd_generic_is_group_section
 #define tekhex_bfd_discard_group                    bfd_generic_discard_group
Index: versados.c
===================================================================
RCS file: /cvs/src/src/bfd/versados.c,v
retrieving revision 1.40
diff -u -r1.40 versados.c
--- versados.c	6 Jun 2011 01:26:04 -0000	1.40
+++ versados.c	22 Jun 2011 20:25:31 -0000
@@ -806,6 +806,7 @@
 #define versados_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
 #define versados_bfd_relax_section                    bfd_generic_relax_section
 #define versados_bfd_gc_sections                      bfd_generic_gc_sections
+#define versados_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
 #define versados_bfd_merge_sections                   bfd_generic_merge_sections
 #define versados_bfd_is_group_section                 bfd_generic_is_group_section
 #define versados_bfd_discard_group                    bfd_generic_discard_group
Index: vms-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/vms-alpha.c,v
retrieving revision 1.47
diff -u -r1.47 vms-alpha.c
--- vms-alpha.c	13 Jun 2011 00:59:15 -0000	1.47
+++ vms-alpha.c	22 Jun 2011 20:25:31 -0000
@@ -9333,6 +9333,7 @@
 
 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
+#define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
Index: xsym.c
===================================================================
RCS file: /cvs/src/src/bfd/xsym.c,v
retrieving revision 1.29
diff -u -r1.29 xsym.c
--- xsym.c	6 Jun 2011 01:26:04 -0000	1.29
+++ xsym.c	22 Jun 2011 20:25:31 -0000
@@ -42,6 +42,7 @@
 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_sym_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_sym_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_sym_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_sym_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-22 21:32         ` Catherine Moore
@ 2011-06-28 11:37           ` Nick Clifton
  2011-06-28 11:56             ` Tristan Gingold
  2011-06-30 21:11             ` Catherine Moore
  0 siblings, 2 replies; 16+ messages in thread
From: Nick Clifton @ 2011-06-28 11:37 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils, Tristan Gingold

Hi Catherine,

> Thanks for the patch review. I've developed a new patch that addresses
> the comments that both you and Tristan made regarding the original
> patch. I've now associated the INPUT_SECTION_FLAGS with the input
> section specifications instead of the output sectionas you and others
> suggested. I've tested arm-coff, mips-elf and ppc-elf. What do you
> think? Is this okay to commit?

I like this patch, but I am afraid that I cannot approve it yet.  There 
are still several problems that need to be addressed:

   * You did not test building a toolchain configured with 
"--enable-targets=all --enable-64-bit-bfd".  There were several targets 
that did not build because they did not define an appropriate 
xxx_bfd_lookup_section_flags macro.


   * The new linker tests fail for targets that do not support the 
INPUT_SECTION_FLAGS feature.  (Ie the ones that use 
bfd_generic_lookup_section_flags).


   * The ld.patch file contained the new linker tests, so the 
ld-test.patch file could not be applied afterwards.


   * The code did not check for contradictory input section flags, eg:

      INPUT_SECTION_FLAGS (SHF_TLS & !SHF_TLS)


   * There was no mention of this new feature in the ld/NEWS file.


   * You have not provided a patch for GOLD.  I would like to keep the 
two linkers in sync, at least as far as features go.


I hope that you will be willing to resolve these issues and submit a 
revised patch.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-28 11:37           ` Nick Clifton
@ 2011-06-28 11:56             ` Tristan Gingold
  2011-06-28 12:22               ` Nick Clifton
  2011-06-28 13:30               ` Ian Lance Taylor
  2011-06-30 21:11             ` Catherine Moore
  1 sibling, 2 replies; 16+ messages in thread
From: Tristan Gingold @ 2011-06-28 11:56 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Catherine Moore, binutils


On Jun 28, 2011, at 1:37 PM, Nick Clifton wrote:

> Hi Catherine,
> 
>> Thanks for the patch review. I've developed a new patch that addresses
>> the comments that both you and Tristan made regarding the original
>> patch. I've now associated the INPUT_SECTION_FLAGS with the input
>> section specifications instead of the output sectionas you and others
>> suggested. I've tested arm-coff, mips-elf and ppc-elf. What do you
>> think? Is this okay to commit?

[...]

>  * You have not provided a patch for GOLD.  I would like to keep the two linkers in sync, at least as far as features go.

Should we really require that ?  I think that this is asking too much.  There are some interesting features in gold (such as ICF)
that aren't in ld; so they are already not in sync.

Tristan.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-28 11:56             ` Tristan Gingold
@ 2011-06-28 12:22               ` Nick Clifton
  2011-06-28 13:30               ` Ian Lance Taylor
  1 sibling, 0 replies; 16+ messages in thread
From: Nick Clifton @ 2011-06-28 12:22 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Catherine Moore, binutils

Hi Tristan,

>>   * You have not provided a patch for GOLD.  I would like to keep the two linkers in sync, at least as far as features go.
>
> Should we really require that ?  I think that this is asking too much.  There are some interesting features in gold (such as ICF)
> that aren't in ld; so they are already not in sync.

OK, fair enough.  Lets make it an optional request.  It would be nice if 
linker scripts were compatible between the two linkers though...

Cheers
   Nicjk


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-28 11:56             ` Tristan Gingold
  2011-06-28 12:22               ` Nick Clifton
@ 2011-06-28 13:30               ` Ian Lance Taylor
  1 sibling, 0 replies; 16+ messages in thread
From: Ian Lance Taylor @ 2011-06-28 13:30 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Nick Clifton, Catherine Moore, binutils

Tristan Gingold <gingold@adacore.com> writes:

> On Jun 28, 2011, at 1:37 PM, Nick Clifton wrote:
>
>> Hi Catherine,
>> 
>>> Thanks for the patch review. I've developed a new patch that addresses
>>> the comments that both you and Tristan made regarding the original
>>> patch. I've now associated the INPUT_SECTION_FLAGS with the input
>>> section specifications instead of the output sectionas you and others
>>> suggested. I've tested arm-coff, mips-elf and ppc-elf. What do you
>>> think? Is this okay to commit?
>
> [...]
>
>>  * You have not provided a patch for GOLD.  I would like to keep the two linkers in sync, at least as far as features go.
>
> Should we really require that ?  I think that this is asking too much.  There are some interesting features in gold (such as ICF)
> that aren't in ld; so they are already not in sync.

Yeah, I agree.  I would very much like gold to be in sync, but I don't
think we can reasonably request it of patch writers.  Gold does not yet
support all the linker script features of GNU ld; e.g.,
DATA_SEGMENT_RELRO_END is not correctly supported (gold implements relro
directly rather than via linker script shenanigans).

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-28 11:37           ` Nick Clifton
  2011-06-28 11:56             ` Tristan Gingold
@ 2011-06-30 21:11             ` Catherine Moore
  2011-07-11 13:55               ` Nick Clifton
  2012-02-09  5:27               ` Alan Modra
  1 sibling, 2 replies; 16+ messages in thread
From: Catherine Moore @ 2011-06-30 21:11 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils, Tristan Gingold, catherine Moore

[-- Attachment #1: Type: text/plain, Size: 1513 bytes --]

Hi Nick,

On 06/28/2011 07:37 AM, Nick Clifton wrote:
> Hi Catherine,
>
> I like this patch, but I am afraid that I cannot approve it yet. There
> are still several problems that need to be addressed:
>
> * You did not test building a toolchain configured with
> "--enable-targets=all --enable-64-bit-bfd". There were several targets
> that did not build because they did not define an appropriate
> xxx_bfd_lookup_section_flags macro.
>
This has now been done.
>
> * The new linker tests fail for targets that do not support the
> INPUT_SECTION_FLAGS feature. (Ie the ones that use
> bfd_generic_lookup_section_flags).
>

These tests have now been marked as unsupported for platforms other than 
elf.

> * The ld.patch file contained the new linker tests, so the ld-test.patch
> file could not be applied afterwards.
>
Sorry!
>
> * The code did not check for contradictory input section flags, eg:
>
> INPUT_SECTION_FLAGS (SHF_TLS & !SHF_TLS)

Now done.  Thanks for spotting that.
>
>
> * There was no mention of this new feature in the ld/NEWS file.

Now done.
>
>
> * You have not provided a patch for GOLD. I would like to keep the two
> linkers in sync, at least as far as features go.

I did not implement this piece of the patch, although I might be willing 
to take it on down the road.  It looks like you changed your mind about 
requiring this.
>
>
> I hope that you will be willing to resolve these issues and submit a
> revised patch.

The new patch is attached.  What do you think?

Thanks,
Catherin

[-- Attachment #2: bfd.cl --]
[-- Type: text/plain, Size: 1903 bytes --]

2011-06-30  Catherine Moore  <clm@codesourcery.com>

        * bfd-in2.h: Regenerated.
	* bfd.c (bfd_lookup_section_flags): New definition.
	* binary.c (binary_bfd_lookup_section_flags): New definition.
	* coff-rs6000.c (rs6000coff_vec): Include
	bfd_generic_lookup_section_flags.
	(pmac_xcoff_vec): Likewise.
	* coffcode.h (coff_bfd_lookup_section_flags): New definition.
	* elf-bfd.h (elf_backend_lookup_section_flags_hook): Declare.
	(bfd_elf_lookup_section_flags): Declare.
	* elflink.c (bfd_elf_lookup_section_flags): New function.
	* elfxx-target.h (bfd_elfNN_bfd_lookup_section_flags): Define.
	(elf_backend_lookup_section_flags_hook): Define.
	(elf_backend_data): Add elf_backend_lookup_section_flags_hook.
	* ieee.c (ieee_bfd_lookup_section_flags): New define.
	* ihex.c (ihex_bfd_lookup_section_flags): New define.
	* libbfd-in.h (_bfd_nolink_bfd_lookup_section_flags): Declare.
	(bfd_generic_lookup_section_flags): Declare.
	* libbfd.h: Regenerated.
	* mach-o-target.c (bfd_mach_o_bfd_lookup_section_flags): New.
	* mmo.c (mmo_bfd_lookup_section_flags): New definition.
	* oasys.c (oasys_bfd_lookup_section_flags): New definition.
	* pef.c (bfd_pef_bfd_lookup_section_flags): New definition.
	* plugin.c (bfd_plugin_bfd_lookup_section_flags): New definition.
	* ppcboot.c (ppcboot_bfd_lookup_section_flags): New definition.
	* reloc.c (bfd_generic_lookup_section_flags): New function.
	* som.c (som_bfd_lookup_section_flags): New definition.
	* srec.c (srec_bfd_lookup_section_flags): New definition.
	* targets.c (flag_info): Declare.
	(NAME##_bfd_lookup_section_flags): Add to LINK jump table.
	(_bfd_lookup_section_flags): New.
	* tekhex.c (tekhex_bfd_lookup_section_flags): New definition.
	* versados.c (versados_bfd_lookup_section_flags): New definition.
	* vms-alpha.c (alpha_vms_bfd_lookup_section_flag): New definition.
	* xsym.c (bfd_sym_bfd_lookup_section_flags): New definition.


[-- Attachment #3: bfd.patch --]
[-- Type: text/x-patch, Size: 14550 bytes --]

Index: aout-adobe.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-adobe.c,v
retrieving revision 1.33
diff -r1.33 aout-adobe.c
461a462
> #define aout_32_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
Index: aout-target.h
===================================================================
RCS file: /cvs/src/src/bfd/aout-target.h,v
retrieving revision 1.42
diff -r1.42 aout-target.h
488a489,491
> #ifndef MY_bfd_lookup_section_flags
> #define MY_bfd_lookup_section_flags bfd_generic_lookup_section_flags
> #endif
Index: aout-tic30.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-tic30.c,v
retrieving revision 1.42
diff -r1.42 aout-tic30.c
946a947,949
> #ifndef MY_bfd_lookup_section_flags
> #define MY_bfd_lookup_section_flags bfd_generic_lookup_section_flags
> #endif
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.540
diff -r1.540 bfd-in2.h
1516a1517,1519
>   /* INPUT_SECTION_FLAGS if specified in the linker script.  */
>   struct flag_info *section_flag_info;
> 
1694a1698,1700
>   /* flag_info,                                                    */  \
>      NULL,                                                             \
>                                                                        \
5573a5580,5582
> #define bfd_lookup_section_flags(link_info, flag_info) \
>        BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
> 
5729a5739,5741
> /* Forward declaration.  */
> typedef struct flag_info flag_info;
> 
5998a6011
>   NAME##_bfd_lookup_section_flags, \
6042a6056,6059
>   /* Sets the bitmask of allowed and disallowed section flags.  */
>   void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
>                                      struct flag_info *);
> 
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.117
diff -r1.117 bfd.c
1376a1377,1379
> .#define bfd_lookup_section_flags(link_info, flag_info) \
> .	BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info))
> .
Index: binary.c
===================================================================
RCS file: /cvs/src/src/bfd/binary.c,v
retrieving revision 1.40
diff -r1.40 binary.c
301a302
> #define binary_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
Index: bout.c
===================================================================
RCS file: /cvs/src/src/bfd/bout.c,v
retrieving revision 1.37
diff -r1.37 bout.c
1389a1390
> #define b_out_bfd_lookup_section_flags         bfd_generic_lookup_section_flags
Index: coff-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-alpha.c,v
retrieving revision 1.46
diff -r1.46 coff-alpha.c
2395a2396,2398
> /* Input section flag lookup is generic.  */
> #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
> 
Index: coff-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-mips.c,v
retrieving revision 1.39
diff -r1.39 coff-mips.c
1412a1413,1415
> /* Input section flags is not implemented.  */
> #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
> 
Index: coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.102
diff -r1.102 coff-rs6000.c
4104a4105
>     bfd_generic_lookup_section_flags,
4358a4360
>     bfd_generic_lookup_section_flags,
Index: coff64-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff64-rs6000.c,v
retrieving revision 1.88
diff -r1.88 coff64-rs6000.c
2740a2741
>     bfd_generic_lookup_section_flags,
2996a2998
>     bfd_generic_lookup_section_flags,
Index: coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.179
diff -r1.179 coffcode.h
5654a5655,5658
> #ifndef coff_bfd_lookup_section_flags
> #define coff_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
> #endif
> 
Index: ecoff.c
===================================================================
RCS file: /cvs/src/src/bfd/ecoff.c,v
retrieving revision 1.73
diff -r1.73 ecoff.c
75a76,77
>   /* flag_info,                                                    */
>      NULL,
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.323
diff -r1.323 elf-bfd.h
1114a1115,1119
>   /* This function, if defined, is called to convert target-specific
>      section flag names into hex values.  */
>   flagword (*elf_backend_lookup_section_flags_hook)
>     (char *);
> 
2195a2201,2203
> extern void bfd_elf_lookup_section_flags
>   (struct bfd_link_info *, struct flag_info *);
> 
Index: elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.412
diff -r1.412 elflink.c
12169a12170,12246
> /* Map an ELF section header flag to its corresponding string.  */
> typedef struct
> {
>   char *flag_name;
>   flagword flag_value;
> } elf_flags_to_name_table;
> 
> static elf_flags_to_name_table elf_flags_to_names [] =
> {
>   { "SHF_WRITE", SHF_WRITE },
>   { "SHF_ALLOC", SHF_ALLOC },
>   { "SHF_EXECINSTR", SHF_EXECINSTR },
>   { "SHF_MERGE", SHF_MERGE },
>   { "SHF_STRINGS", SHF_STRINGS },
>   { "SHF_INFO_LINK", SHF_INFO_LINK},
>   { "SHF_LINK_ORDER", SHF_LINK_ORDER},
>   { "SHF_OS_NONCONFORMING", SHF_OS_NONCONFORMING},
>   { "SHF_GROUP", SHF_GROUP },
>   { "SHF_TLS", SHF_TLS },
>   { "SHF_MASKOS", SHF_MASKOS },
>   { "SHF_EXCLUDE", SHF_EXCLUDE },
> };
> 
> void
> bfd_elf_lookup_section_flags (struct bfd_link_info *info,
> 			      struct flag_info *finfo)
> {
>   bfd *output_bfd = info->output_bfd;
>   const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
>   struct flag_info_list *tf = finfo->flag_list;
>   int with_hex = 0;
>   int without_hex = 0;
> 
>   for (tf = finfo->flag_list; tf != NULL; tf = tf->next)
>     {
>       int i;
>       if (bed->elf_backend_lookup_section_flags_hook)
> 	{
> 	  flagword hexval =
> 	     (*bed->elf_backend_lookup_section_flags_hook) ((char *) tf->name);
> 
> 	  if (hexval != 0)
> 	    {
> 	      if (tf->with == with_flags)
> 		with_hex |= hexval;
> 	      else if (tf->with == without_flags)
> 		without_hex |= hexval;
> 	      tf->valid = TRUE;
> 	      continue;
> 	    }
> 	}
>       for (i = 0; i < 12; i++)
> 	{
> 	  if (!strcmp (tf->name, elf_flags_to_names[i].flag_name))
> 	    {
> 	      if (tf->with == with_flags)
> 		with_hex |= elf_flags_to_names[i].flag_value;
> 	      else if (tf->with == without_flags)
> 		without_hex |= elf_flags_to_names[i].flag_value;
> 	      tf->valid = TRUE;
> 	      continue;
> 	    }
> 	}
>       if (tf->valid == FALSE)
> 	{
> 	  info->callbacks->einfo 
> 		(_("Unrecognized INPUT_SECTION_FLAG %s\n"), tf->name);
> 	  return;
> 	}
>     }
>  finfo->flags_initialized = TRUE;
>  finfo->only_with_flags |= with_hex;
>  finfo->not_with_flags |= without_hex;
> 
>  return;
> }
> 
Index: elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.126
diff -r1.126 elfxx-target.h
176a177,180
> #ifndef bfd_elfNN_bfd_lookup_section_flags
> #define bfd_elfNN_bfd_lookup_section_flags bfd_elf_lookup_section_flags
> #endif
> 
531a536,538
> #ifndef elf_backend_lookup_section_flags_hook
> #define elf_backend_lookup_section_flags_hook	NULL
> #endif
719a727
>   elf_backend_lookup_section_flags_hook,
Index: i386msdos.c
===================================================================
RCS file: /cvs/src/src/bfd/i386msdos.c,v
retrieving revision 1.31
diff -r1.31 i386msdos.c
145a146
> #define msdos_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: i386os9k.c
===================================================================
RCS file: /cvs/src/src/bfd/i386os9k.c,v
retrieving revision 1.27
diff -r1.27 i386os9k.c
169a170
> #define os9k_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: ieee.c
===================================================================
RCS file: /cvs/src/src/bfd/ieee.c,v
retrieving revision 1.71
diff -r1.71 ieee.c
3774a3775
> #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: ihex.c
===================================================================
RCS file: /cvs/src/src/bfd/ihex.c,v
retrieving revision 1.41
diff -r1.41 ihex.c
932a933
> #define ihex_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.88
diff -r1.88 libbfd-in.h
455a456,458
> #define _bfd_nolink_bfd_lookup_section_flags \
>   ((void (*) (struct bfd_link_info *, struct flag_info *)) \
>    bfd_0)
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.253
diff -r1.253 libbfd.h
460a461,463
> #define _bfd_nolink_bfd_lookup_section_flags \
>   ((void (*) (struct bfd_link_info *, struct flag_info *)) \
>    bfd_0)
2460a2464,2466
> void bfd_generic_lookup_section_flags
>    (struct bfd_link_info *, struct flag_info *);
> 
Index: mach-o-target.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o-target.c,v
retrieving revision 1.17
diff -r1.17 mach-o-target.c
53a54
> #define bfd_mach_o_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
Index: mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.42
diff -r1.42 mmo.c
3192a3193
> #define mmo_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: nlm-target.h
===================================================================
RCS file: /cvs/src/src/bfd/nlm-target.h,v
retrieving revision 1.23
diff -r1.23 nlm-target.h
47a48
> #define nlm_bfd_lookup_section_flags		bfd_generic_lookup_section_flags
Index: oasys.c
===================================================================
RCS file: /cvs/src/src/bfd/oasys.c,v
retrieving revision 1.46
diff -r1.46 oasys.c
1198a1199
> #define oasys_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
Index: pef.c
===================================================================
RCS file: /cvs/src/src/bfd/pef.c,v
retrieving revision 1.32
diff -r1.32 pef.c
50a51
> #define bfd_pef_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
Index: plugin.c
===================================================================
RCS file: /cvs/src/src/bfd/plugin.c,v
retrieving revision 1.13
diff -r1.13 plugin.c
65a66
> #define bfd_plugin_bfd_lookup_section_flags           bfd_generic_lookup_section_flags
Index: ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.34
diff -r1.34 ppcboot.c
472a473
> #define ppcboot_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.214
diff -r1.214 reloc.c
6046a6047,6070
> 	bfd_generic_lookup_section_flags
> 
> SYNOPSIS
> 	void bfd_generic_lookup_section_flags
> 	  (struct bfd_link_info *, struct flag_info *);
> 
> DESCRIPTION
> 	Provides default handling for section flags lookup
> 	-- i.e., does nothing.
> */
> 
> void
> bfd_generic_lookup_section_flags (struct bfd_link_info *info ATTRIBUTE_UNUSED,
> 				  struct flag_info *finfo) 
> {
>   if (finfo != NULL)
>     {
>       (*_bfd_error_handler) (_("INPUT_SECTION_FLAGS are not supported.\n"));
>       return;
>     }
> }
> 
> /*
> INTERNAL_FUNCTION
Index: section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.110
diff -r1.110 section.c
518a519,521
> .  {* INPUT_SECTION_FLAGS if specified in the linker script.  *}
> .  struct flag_info *section_flag_info;
> .
696a700,702
> .  {* flag_info,						    *}  \
> .     NULL,								\
> .									\
Index: som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.84
diff -r1.84 som.c
6743a6744
> #define som_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
Index: srec.c
===================================================================
RCS file: /cvs/src/src/bfd/srec.c,v
retrieving revision 1.51
diff -r1.51 srec.c
1254a1255
> #define srec_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.202
diff -r1.202 targets.c
179a180,182
> .{* Forward declaration.  *}
> .typedef struct flag_info flag_info;
> .
450a454
> .  NAME##_bfd_lookup_section_flags, \
494a499,502
> .  {* Sets the bitmask of allowed and disallowed section flags.  *}
> .  void (*_bfd_lookup_section_flags) (struct bfd_link_info *,
> .				      struct flag_info *);
> .
Index: tekhex.c
===================================================================
RCS file: /cvs/src/src/bfd/tekhex.c,v
retrieving revision 1.40
diff -r1.40 tekhex.c
945a946
> #define tekhex_bfd_lookup_section_flags		    bfd_generic_lookup_section_flags
Index: versados.c
===================================================================
RCS file: /cvs/src/src/bfd/versados.c,v
retrieving revision 1.40
diff -r1.40 versados.c
808a809
> #define versados_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
Index: vms-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/vms-alpha.c,v
retrieving revision 1.50
diff -r1.50 vms-alpha.c
9338a9339
> #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
Index: xsym.c
===================================================================
RCS file: /cvs/src/src/bfd/xsym.c,v
retrieving revision 1.29
diff -r1.29 xsym.c
44a45
> #define bfd_sym_bfd_lookup_section_flags            bfd_generic_lookup_section_flags

[-- Attachment #4: include.cl --]
[-- Type: text/plain, Size: 160 bytes --]

2011-06-30  Catherine Moore  <clm@codesourcery.com>

	* bfdlink.h (flag_type): New enumeration.
	(flag_info_list): New structure.
	(flag_info): New structure.


[-- Attachment #5: include.patch --]
[-- Type: text/x-patch, Size: 805 bytes --]

Index: bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.88
diff -u -r1.88 bfdlink.h
--- bfdlink.h	20 Jun 2011 13:18:48 -0000	1.88
+++ bfdlink.h	22 Jun 2011 20:40:13 -0000
@@ -224,6 +224,26 @@
   RM_GENERATE_ERROR
 };
 
+typedef enum {with_flags, without_flags} flag_type;
+
+/* A section flag list.  */
+struct flag_info_list
+{
+  flag_type with; 
+  const char *name;
+  bfd_boolean valid;
+  struct flag_info_list *next;
+};
+
+/* Section flag info.  */
+struct flag_info
+{
+  flagword only_with_flags;
+  flagword not_with_flags;
+  struct flag_info_list *flag_list;
+  bfd_boolean flags_initialized;
+};
+
 struct bfd_elf_dynamic_list;
 
 /* This structure holds all the information needed to communicate

[-- Attachment #6: ld.cl --]
[-- Type: text/plain, Size: 951 bytes --]

2011-06-30  Catherine Moore  <clm@codesourcery.com>

	* ld.h (section_flag_list): Add field to struct wildcard_spec.
	* ld.texinfo (INPUT_SECTION_FLAGS): Document.
	* ldgram.y (flag_info_list, flag_info): Add to union.
	(INPUT_SECTION_FLAGS): New token.
	(wildcard_spec): Initialize section_flag_list to NULL for
	each alternative.
	(sect_flag_list, sect_flags): New rules.
	(input_section_spec_no_keep): Add alternatives to recognize
	sect_flags.
	* ldlang.c (walk_wild_consider_section): Initialize
	section_flag_info field of the section struct.
	(lang_add_section): Check input section flags.
	(lang_add_wild): Initialize section_flag_list field of 
	the statement struct.
	* ldlang.h (lang_input_statement_struct): Add section_flag_list field.
	(lang_wild_statement_struct): Likewise.
	* ldlex.l (INPUT_SECTION_FLAGS): New token.
	* mri.c (mri_draw_tree): Initialize section_flag_list to NULL.
	* NEWS: Announce INPUT_SECTION_FLAGS enhancement.


[-- Attachment #7: ld.patch --]
[-- Type: text/x-patch, Size: 16256 bytes --]

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> fill_opt fill_exp
 %type <name_list> exclude_name_list
 %type <wildcard_list> file_NAME_list
+%type <flag_info_list> sect_flag_list
+%type <flag_info> sect_flags
 %type <name> memspec_opt casesymlist
 %type <name> memspec_at_opt
 %type <cname> wildcard_name
@@ -150,7 +154,7 @@
 %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START
 %token <name> 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 <versyms> 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 @@
 <BOTH,SCRIPT>"org"			{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"l"			{ RTOKEN( LENGTH);}
 <BOTH,SCRIPT>"len"			{ RTOKEN( LENGTH);}
+<EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS"	{ RTOKEN(INPUT_SECTION_FLAGS); }
 <EXPRESSION,BOTH,SCRIPT>"INCLUDE"	{ RTOKEN(INCLUDE);}
 <BOTH,SCRIPT>"PHDRS"			{ RTOKEN (PHDRS); }
 <EXPRESSION,BOTH,SCRIPT>"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  <clm@cm00re.com>
+
+	* 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  <nickc@redhat.com>
 
 	* 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-30 21:11             ` Catherine Moore
@ 2011-07-11 13:55               ` Nick Clifton
  2012-02-09  5:27               ` Alan Modra
  1 sibling, 0 replies; 16+ messages in thread
From: Nick Clifton @ 2011-07-11 13:55 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils, Tristan Gingold

Hi  Catherine

> The new patch is attached. What do you think?

(Sorry for the delay in replying - I was on vacation last week).#

I like it - please consider the patch approved and apply it at your leisure.

Cheers
   Nick
-

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PING Re: [RFA] Linker script extension SECTION_FLAGS
  2011-06-30 21:11             ` Catherine Moore
  2011-07-11 13:55               ` Nick Clifton
@ 2012-02-09  5:27               ` Alan Modra
  1 sibling, 0 replies; 16+ messages in thread
From: Alan Modra @ 2012-02-09  5:27 UTC (permalink / raw)
  To: Catherine Moore; +Cc: binutils

On Thu, Jun 30, 2011 at 05:10:32PM -0400, Catherine Moore wrote:
[snip]
> 	(input_section_spec_no_keep): Add alternatives to recognize
> 	sect_flags.
[snip]

A compiler warning about 'tmp' set but not used prompted this patch.
Applied mainline.

	* ldgram.y (input_section_spec_no_keep): Don't ignore sect_flags.

Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.66
diff -u -p -r1.66 ldgram.y
--- ld/ldgram.y	11 Jul 2011 15:03:09 -0000	1.66
+++ ld/ldgram.y	9 Feb 2012 05:09:14 -0000
@@ -629,7 +629,7 @@ input_section_spec_no_keep:
 			  tmp.exclude_name_list = NULL;
 			  tmp.sorted = none;
 			  tmp.section_flag_list = $1;
-			  lang_add_wild (NULL, $3, ldgram_had_keep);
+			  lang_add_wild (&tmp, $3, ldgram_had_keep);
 			}
 	|	wildcard_spec '(' file_NAME_list ')'
 			{

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-02-09  5:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-18 19:32 [RFA] Linker script extension SECTION_FLAGS Catherine Moore
2011-05-18 19:33 ` Catherine Moore
2011-05-19  0:07 ` Ian Lance Taylor
2011-05-24 22:57   ` Catherine Moore
2011-05-25 12:28     ` Tristan Gingold
2011-06-06 22:02     ` PING " Catherine Moore
2011-06-07 13:11       ` Nick Clifton
2011-06-22 21:32         ` Catherine Moore
2011-06-28 11:37           ` Nick Clifton
2011-06-28 11:56             ` Tristan Gingold
2011-06-28 12:22               ` Nick Clifton
2011-06-28 13:30               ` Ian Lance Taylor
2011-06-30 21:11             ` Catherine Moore
2011-07-11 13:55               ` Nick Clifton
2012-02-09  5:27               ` Alan Modra
2011-05-19  7:44 ` Tristan Gingold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).