Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 4 Apr 2017 16:05:48 +0000 (09:05 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 4 Apr 2017 16:06:04 +0000 (09:06 -0700)
Mark an ALLOC section, which should be placed in special memory area,
with SHF_GNU_MBIND.  Its sh_info field indicates the special memory
type.  GNU_MBIND section names start with ".mbind" so that they are
placed as orphan sections by linker.  All input GNU_MBIND sections
with the same sh_type, sh_flags and sh_info are placed in one output
GNU_MBIND section.  In executable and shared object, create a
GNU_MBIND segment for each GNU_MBIND section and its segment type is
PT_GNU_MBIND_LO plus the sh_info value.  Each GNU_MBIND segment is
aligned at page boundary.

The assembler syntax:

    .section .mbind.foo,"adx",%progbits
                          ^             0: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.foo,"adx",%progbits,0x1
                          ^             1: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2
                          ^                               2: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

bfd/

* elf.c (get_program_header_size): Add a GNU_MBIND segment for
each GNU_MBIND section and align GNU_MBIND section to page size.
(_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
segment for each GNU_MBIND section.
(_bfd_elf_init_private_section_data): Copy sh_info from input
for GNU_MBIND section.

binutils/

* NEWS: Mention support for ELF SHF_GNU_MBIND and
PT_GNU_MBIND_XXX.
* readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
(get_elf_section_flags): Handle SHF_GNU_MBIND.
(process_section_headers): Likewise.
* testsuite/binutils-all/mbind1.s: New file.
* testsuite/binutils-all/objcopy.exp: Run readelf test on
mbind1.s.

gas/

* NEWS: Mention support for ELF SHF_GNU_MBIND.
* config/obj-elf.c (section_match): New.
(get_section): Match both sh_info and group name.
(obj_elf_change_section): Add argument for sh_info.  Pass both
sh_info and group name to get_section. Issue an error for
SHF_GNU_MBIND section without SHF_ALLOC.  Set sh_info.
(obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
(obj_elf_section): Support SHF_GNU_MBIND section info.
* config/obj-elf.h (obj_elf_change_section): Add argument for
sh_info.
* config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to
obj_elf_change_section.
* config/tc-ia64.c (obj_elf_vms_common): Likewise.
* config/tc-microblaze.c (microblaze_s_data): Likewise.
(microblaze_s_sdata): Likewise.
(microblaze_s_rdata): Likewise.
(microblaze_s_bss): Likewise.
* config/tc-mips.c (s_change_section): Likewise.
* config/tc-msp430.c (msp430_profiler): Likewise.
* config/tc-rx.c (parse_rx_section): Likewise.
* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
* doc/as.texinfo: Document 'd' for SHF_GNU_MBIND.
* testsuite/gas/elf/elf.exp: Run section12a, section12b and
section13.
* testsuite/gas/elf/section10.d: Updated.
* testsuite/gas/elf/section10.s: Likewise.
* testsuite/gas/elf/section12.s: New file.
* testsuite/gas/elf/section12a.d: Likewise.
* testsuite/gas/elf/section12b.d: Likewise.
* testsuite/gas/elf/section13.l: Likewise.
* testsuite/gas/elf/section13.d: Likewise.
* testsuite/gas/elf/section13.s: Likewise.

include/

* elf/common.h (PT_GNU_MBIND_NUM): New.
(PT_GNU_MBIND_LO): Likewise.
(PT_GNU_MBIND_HI): Likewise.
(SHF_GNU_MBIND): Likewise.

ld/

* NEWS: Mention support for ELF SHF_GNU_MBIND and
PT_GNU_MBIND_XXX.
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
input GNU_MBIND sections with the same type, attributes and
sh_info field into a single output GNU_MBIND section.
* testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
* testsuite/ld-elf/mbind1.s: New file.
* testsuite/ld-elf/mbind1a.d: Likewise.
* testsuite/ld-elf/mbind1b.d: Likewise.
* testsuite/ld-elf/mbind1c.d: Likewise.
* testsuite/ld-elf/mbind2a.s: Likewise.
* testsuite/ld-elf/mbind2b.c: Likewise.

40 files changed:
bfd/ChangeLog
bfd/elf.c
binutils/ChangeLog
binutils/NEWS
binutils/readelf.c
binutils/testsuite/binutils-all/mbind1.s [new file with mode: 0644]
binutils/testsuite/binutils-all/objcopy.exp
gas/ChangeLog
gas/NEWS
gas/config/obj-elf.c
gas/config/obj-elf.h
gas/config/tc-arm.c
gas/config/tc-ia64.c
gas/config/tc-microblaze.c
gas/config/tc-mips.c
gas/config/tc-msp430.c
gas/config/tc-rx.c
gas/config/tc-tic6x.c
gas/doc/as.texinfo
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/section10.d
gas/testsuite/gas/elf/section10.s
gas/testsuite/gas/elf/section12.s [new file with mode: 0644]
gas/testsuite/gas/elf/section12a.d [new file with mode: 0644]
gas/testsuite/gas/elf/section12b.d [new file with mode: 0644]
gas/testsuite/gas/elf/section13.d [new file with mode: 0644]
gas/testsuite/gas/elf/section13.l [new file with mode: 0644]
gas/testsuite/gas/elf/section13.s [new file with mode: 0644]
include/ChangeLog
include/elf/common.h
ld/ChangeLog
ld/NEWS
ld/emultempl/elf32.em
ld/testsuite/ld-elf/elf.exp
ld/testsuite/ld-elf/mbind1.s [new file with mode: 0644]
ld/testsuite/ld-elf/mbind1a.d [new file with mode: 0644]
ld/testsuite/ld-elf/mbind1b.d [new file with mode: 0644]
ld/testsuite/ld-elf/mbind1c.d [new file with mode: 0644]
ld/testsuite/ld-elf/mbind2a.s [new file with mode: 0644]
ld/testsuite/ld-elf/mbind2b.c [new file with mode: 0644]

index 5b0211f8b262154cff4096e6c6bec514eeaa97ea..46d92a037accc821d6e9d07b71c1c6873f29ac7a 100644 (file)
@@ -1,3 +1,12 @@
+2017-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf.c (get_program_header_size): Add a GNU_MBIND segment for
+       each GNU_MBIND section and align GNU_MBIND section to page size.
+       (_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
+       segment for each GNU_MBIND section.
+       (_bfd_elf_init_private_section_data): Copy sh_info from input
+       for GNU_MBIND section.
+
 2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>
 
        * elfnn-riscv.c (GP_NAME): Delete.
index d4d91b65c7893a87b556569877cb55465b9471fd..dcb0e6f986a3f60f90d01a9a6b714b615742aa37 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4330,9 +4330,33 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info)
        }
     }
 
-  /* Let the backend count up any program headers it might need.  */
   bed = get_elf_backend_data (abfd);
-  if (bed->elf_backend_additional_program_headers)
+
+ if ((abfd->flags & D_PAGED) != 0)
+   {
+     /* Add a PT_GNU_MBIND segment for each mbind section.  */
+     unsigned int page_align_power = bfd_log2 (bed->commonpagesize);
+     for (s = abfd->sections; s != NULL; s = s->next)
+       if (elf_section_flags (s) & SHF_GNU_MBIND)
+        {
+          if (elf_section_data (s)->this_hdr.sh_info
+              > PT_GNU_MBIND_NUM)
+            {
+              _bfd_error_handler
+                /* xgettext:c-format */
+                (_("%B: GNU_MBIN section `%A' has invalid sh_info field: %d"),
+                    abfd, s, elf_section_data (s)->this_hdr.sh_info);
+              continue;
+            }
+          /* Align mbind section to page size.  */
+          if (s->alignment_power < page_align_power)
+            s->alignment_power = page_align_power;
+          segs ++;
+        }
+   }
+
+ /* Let the backend count up any program headers it might need.  */
+ if (bed->elf_backend_additional_program_headers)
     {
       int a;
 
@@ -4504,6 +4528,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
       bfd_boolean writable;
       int tls_count = 0;
       asection *first_tls = NULL;
+      asection *first_mbind = NULL;
       asection *dynsec, *eh_frame_hdr;
       bfd_size_type amt;
       bfd_vma addr_mask, wrap_to = 0;
@@ -4836,6 +4861,9 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
                first_tls = s;
              tls_count++;
            }
+         if (first_mbind == NULL
+             && (elf_section_flags (s) & SHF_GNU_MBIND) != 0)
+           first_mbind = s;
        }
 
       /* If there are any SHF_TLS output sections, add PT_TLS segment.  */
@@ -4883,6 +4911,35 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
          pm = &m->next;
        }
 
+      if (first_mbind && (abfd->flags & D_PAGED) != 0)
+       for (s = first_mbind; s != NULL; s = s->next)
+         if ((elf_section_flags (s) & SHF_GNU_MBIND) != 0
+             && (elf_section_data (s)->this_hdr.sh_info
+                 <= PT_GNU_MBIND_NUM))
+           {
+             /* Mandated PF_R.  */
+             unsigned long p_flags = PF_R;
+             if ((s->flags & SEC_READONLY) == 0)
+               p_flags |= PF_W;
+             if ((s->flags & SEC_CODE) != 0)
+               p_flags |= PF_X;
+
+             amt = sizeof (struct elf_segment_map) + sizeof (asection *);
+             m = bfd_zalloc (abfd, amt);
+             if (m == NULL)
+               goto error_return;
+             m->next = NULL;
+             m->p_type = (PT_GNU_MBIND_LO
+                          + elf_section_data (s)->this_hdr.sh_info);
+             m->count = 1;
+             m->p_flags_valid = 1;
+             m->sections[0] = s;
+             m->p_flags = p_flags;
+
+             *pm = m;
+             pm = &m->next;
+           }
+
       /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME
         segment.  */
       eh_frame_hdr = elf_eh_frame_hdr (abfd);
@@ -7359,6 +7416,11 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
   elf_section_flags (osec) |= (elf_section_flags (isec)
                               & (SHF_MASKOS | SHF_MASKPROC));
 
+  /* Copy sh_info from input for mbind section.  */
+  if (elf_section_flags (isec) & SHF_GNU_MBIND)
+    elf_section_data (osec)->this_hdr.sh_info
+      = elf_section_data (isec)->this_hdr.sh_info;
+
   /* Set things up for objcopy and relocatable link.  The output
      SHT_GROUP section will have its elf_next_in_group pointing back
      to the input group members.  Ignore linker created group section.
index 5d81b353b0db2ffe9a4ea646662c2e4d5d4f8768..d3473363f4d16f04b3f218f5b83687937089befb 100644 (file)
@@ -1,3 +1,14 @@
+2017-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * NEWS: Mention support for ELF SHF_GNU_MBIND and
+       PT_GNU_MBIND_XXX.
+       * readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
+       (get_elf_section_flags): Handle SHF_GNU_MBIND.
+       (process_section_headers): Likewise.
+       * testsuite/binutils-all/mbind1.s: New file.
+       * testsuite/binutils-all/objcopy.exp: Run readelf test on
+       mbind1.s.
+
 2017-04-03  Nick Clifton  <nickc@redhat.com>
 
        PR binutils/21345
index d9d65c71e475d9d1f21b35ac277a6eb2d6cb3f51..c03539d26838cf5ebcbd23729c9295b013a44aff 100644 (file)
@@ -1,5 +1,7 @@
 -*- text -*-
 
+* Add support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX.
+
 * Add support for the wasm32 ELF conversion of the WebAssembly file format.
 
 * Add --inlines option to objdump, which extends the --line-numbers option
index b573921c13819133ca15a056dbbc6aaf24c28049..d2b8dd4e790554ac0f7b6cd4393d65fbabf6b5c1 100644 (file)
@@ -3825,7 +3825,12 @@ get_segment_type (unsigned long p_type)
     case PT_GNU_RELRO:  return "GNU_RELRO";
 
     default:
-      if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
+      if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
+       {
+         sprintf (buff, "GNU_MBIND+%#lx",
+                  p_type - PT_GNU_MBIND_LO);
+       }
+      else if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
        {
          const char * result;
 
@@ -5544,7 +5549,9 @@ get_elf_section_flags (bfd_vma sh_flags)
       /* ARM specific.  */
       /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
       /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
-      /* 23 */ { STRING_COMMA_LEN ("COMDEF") }
+      /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
+      /* GNU specific.  */
+      /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
     };
 
   if (do_section_details)
@@ -5577,6 +5584,7 @@ get_elf_section_flags (bfd_vma sh_flags)
            case SHF_TLS:               sindex = 9; break;
            case SHF_EXCLUDE:           sindex = 18; break;
            case SHF_COMPRESSED:        sindex = 20; break;
+           case SHF_GNU_MBIND:         sindex = 24; break;
 
            default:
              sindex = -1;
@@ -5670,6 +5678,7 @@ get_elf_section_flags (bfd_vma sh_flags)
            case SHF_TLS:               *p = 'T'; break;
            case SHF_EXCLUDE:           *p = 'E'; break;
            case SHF_COMPRESSED:        *p = 'C'; break;
+           case SHF_GNU_MBIND:         *p = 'D'; break;
 
            default:
              if ((elf_header.e_machine == EM_X86_64
@@ -6198,7 +6207,9 @@ process_section_headers (FILE * file)
              if (section->sh_info < 1 || section->sh_info >= elf_header.e_shnum)
                warn (_("[%2u]: Expected link to another section in info field"), i);
            }
-         else if (section->sh_type < SHT_LOOS && section->sh_info != 0)
+         else if (section->sh_type < SHT_LOOS
+                  && (section->sh_flags & SHF_GNU_MBIND) == 0
+                  && section->sh_info != 0)
            warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
                  i, section->sh_info);
          break;
diff --git a/binutils/testsuite/binutils-all/mbind1.s b/binutils/testsuite/binutils-all/mbind1.s
new file mode 100644 (file)
index 0000000..41faad4
--- /dev/null
@@ -0,0 +1,33 @@
+       .section .mbind.data,"adw",%progbits
+       .byte 1
+
+       .section .mbind.data,"adw",%progbits,0x3
+       .byte 2
+
+       .section .mbind.text,"adx",%progbits
+       .byte 3
+
+       .section .mbind.text,"adx",%progbits,0x3
+       .byte 4
+
+       .section .mbind.bss,"adw",%nobits
+       .zero 5
+
+       .section .mbind.bss,"adw",%nobits,0x3
+       .zero 6
+
+       .section .mbind.rodata,"adG",%progbits,.foo_group,comdat,0x2
+       .byte 7
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat
+       .byte 8
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat,0x3
+       .byte 9
+
+       # Check that .pushsection works as well.
+       .pushsection .mbind.text,"adGx",%progbits,.foo_group,comdat,0x3
+       .byte 10
+
+       .popsection
+       .byte 11
index 7ecc0d5af7124332676c6dcb1efcb432ab0a1cdf..6d578375965c7683403c2343acc01856e677d429 100644 (file)
@@ -1049,6 +1049,7 @@ if [is_elf_format] {
     objcopy_test_readelf "ELF group" group-2.s
     objcopy_test_readelf "ELF group" group-3.s
     objcopy_test_readelf "ELF group" group-4.s
+    objcopy_test_readelf "GNU_MBIND section" mbind1.s
     run_dump_test "group-5"
     run_dump_test "group-6"
     run_dump_test "copy-1"
index 557b43cc5ece7e2b39223dce082c79f52227d380..cc5f3496c340f937e4b8b0a1cc719b79c7947a5c 100644 (file)
@@ -1,3 +1,38 @@
+2017-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * NEWS: Mention support for ELF SHF_GNU_MBIND.
+       * config/obj-elf.c (section_match): New.
+       (get_section): Match both sh_info and group name.
+       (obj_elf_change_section): Add argument for sh_info.  Pass both
+       sh_info and group name to get_section. Issue an error for
+       SHF_GNU_MBIND section without SHF_ALLOC.  Set sh_info.
+       (obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
+       (obj_elf_section): Support SHF_GNU_MBIND section info.
+       * config/obj-elf.h (obj_elf_change_section): Add argument for
+       sh_info.
+       * config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to
+       obj_elf_change_section.
+       * config/tc-ia64.c (obj_elf_vms_common): Likewise.
+       * config/tc-microblaze.c (microblaze_s_data): Likewise.
+       (microblaze_s_sdata): Likewise.
+       (microblaze_s_rdata): Likewise.
+       (microblaze_s_bss): Likewise.
+       * config/tc-mips.c (s_change_section): Likewise.
+       * config/tc-msp430.c (msp430_profiler): Likewise.
+       * config/tc-rx.c (parse_rx_section): Likewise.
+       * config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
+       * doc/as.texinfo: Document 'd' for SHF_GNU_MBIND.
+       * testsuite/gas/elf/elf.exp: Run section12a, section12b and
+       section13.
+       * testsuite/gas/elf/section10.d: Updated.
+       * testsuite/gas/elf/section10.s: Likewise.
+       * testsuite/gas/elf/section12.s: New file.
+       * testsuite/gas/elf/section12a.d: Likewise.
+       * testsuite/gas/elf/section12b.d: Likewise.
+       * testsuite/gas/elf/section13.l: Likewise.
+       * testsuite/gas/elf/section13.d: Likewise.
+       * testsuite/gas/elf/section13.s: Likewise.
+
 2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>
 
        * config/tc-riscv.c (riscv_clear_subsets): Cast argument to free to
index 46eaff3e7c7788f128bcbea2c796188e085b0acf..2078d29225ee6b5ecfa740b9a8a1bc48eee43efd 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -1,5 +1,7 @@
 -*- text -*-
 
+* Add support for ELF SHF_GNU_MBIND.
+
 * Add support for the WebAssembly file format and wasm32 ELF conversion.
 
 * PowerPC gas now checks that the correct register class is used in
index 1d59fc0296093b453d6aef5a5a503daadf6f44c6..3696d5ea5e274bcc8d96594a1b520db090214b02 100644 (file)
@@ -520,16 +520,26 @@ struct section_stack
 
 static struct section_stack *section_stack;
 
+/* Match both section group name and the sh_info field.  */
+struct section_match
+{
+  const char *group_name;
+  unsigned int info;
+};
+
 static bfd_boolean
 get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
 {
-  const char *gname = (const char *) inf;
+  struct section_match *match = (struct section_match *) inf;
+  const char *gname = match->group_name;
   const char *group_name = elf_group_name (sec);
+  unsigned int info = elf_section_data (sec)->this_hdr.sh_info;
 
-  return (group_name == gname
-         || (group_name != NULL
-             && gname != NULL
-             && strcmp (group_name, gname) == 0));
+  return (info == match->info
+         && (group_name == gname
+             || (group_name != NULL
+                 && gname != NULL
+                 && strcmp (group_name, gname) == 0)));
 }
 
 /* Handle the .section pseudo-op.  This code supports two different
@@ -553,6 +563,7 @@ get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
 void
 obj_elf_change_section (const char *name,
                        unsigned int type,
+                       unsigned int info,
                        bfd_vma attr,
                        int entsize,
                        const char *group_name,
@@ -564,6 +575,7 @@ obj_elf_change_section (const char *name,
   flagword flags;
   const struct elf_backend_data *bed;
   const struct bfd_elf_special_section *ssect;
+  struct section_match match;
 
 #ifdef md_flush_pending_output
   md_flush_pending_output ();
@@ -584,8 +596,10 @@ obj_elf_change_section (const char *name,
   previous_section = now_seg;
   previous_subsection = now_subseg;
 
+  match.group_name = group_name;
+  match.info = info;
   old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section,
-                                       (void *) group_name);
+                                       (void *) &match);
   if (old_sec)
     {
       sec = old_sec;
@@ -695,6 +709,9 @@ obj_elf_change_section (const char *name,
        attr |= ssect->attr;
     }
 
+  if ((attr & (SHF_ALLOC | SHF_GNU_MBIND)) == SHF_GNU_MBIND)
+    as_fatal (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name);
+
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC
           | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
@@ -720,6 +737,7 @@ obj_elf_change_section (const char *name,
        type = bfd_elf_get_default_section_type (flags);
       elf_section_type (sec) = type;
       elf_section_flags (sec) = attr;
+      elf_section_data (sec)->this_hdr.sh_info = info;
 
       /* Prevent SEC_HAS_CONTENTS from being inadvertently set.  */
       if (type == SHT_NOBITS)
@@ -803,6 +821,9 @@ obj_elf_parse_section_letters (char *str, size_t len, bfd_boolean *is_clone)
        case 'T':
          attr |= SHF_TLS;
          break;
+       case 'd':
+         attr |= SHF_GNU_MBIND;
+         break;
        case '?':
          *is_clone = TRUE;
          break;
@@ -996,6 +1017,7 @@ obj_elf_section (int push)
   int entsize;
   int linkonce;
   subsegT new_subsection = -1;
+  unsigned int info = 0;
 
 #ifndef TC_I370
   if (flag_mri)
@@ -1159,6 +1181,23 @@ obj_elf_section (int push)
                  linkonce = (now_seg->flags & SEC_LINK_ONCE) != 0;
                }
            }
+
+         if ((attr & SHF_GNU_MBIND) != 0 && *input_line_pointer == ',')
+           {
+             ++input_line_pointer;
+             SKIP_WHITESPACE ();
+             if (ISDIGIT (* input_line_pointer))
+               {
+                 char *t = input_line_pointer;
+                 info = strtoul (input_line_pointer,
+                                 &input_line_pointer, 0);
+                 if (info == (unsigned int) -1)
+                   {
+                     as_warn (_("unsupported mbind section info: %s"), t);
+                     info = 0;
+                   }
+               }
+           }
        }
       else
        {
@@ -1189,7 +1228,8 @@ obj_elf_section (int push)
 done:
   demand_empty_rest_of_line ();
 
-  obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
+  obj_elf_change_section (name, type, info, attr, entsize, group_name,
+                         linkonce, push);
 
   if (push && new_subsection != -1)
     subseg_set (now_seg, new_subsection);
index f6bd2167d919a554cec0e7919b238db05fdb248e..37d6aee88eb02b66bdc6faab51a3839b5fc7053d 100644 (file)
@@ -162,7 +162,8 @@ extern void obj_elf_common (int);
 extern void obj_elf_data (int);
 extern void obj_elf_text (int);
 extern void obj_elf_change_section
-  (const char *, unsigned int, bfd_vma, int, const char *, int, int);
+  (const char *, unsigned int, unsigned int, bfd_vma, int, const char *,
+   int, int);
 extern struct fix *obj_elf_vtable_inherit (int);
 extern struct fix *obj_elf_vtable_entry (int);
 extern bfd_boolean obj_elf_seen_attribute
index bbfe634a64a5978385602245ee7ba36d94f28f73..83244b70473733801a44abfd3f7989992f409658 100644 (file)
@@ -22113,7 +22113,8 @@ start_unwind_section (const segT text_seg, int idx)
       linkonce = 1;
     }
 
-  obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+  obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
+                         linkonce, 0);
 
   /* Set the section link for index tables.  */
   if (idx)
index aa01eff08d3fb5f49d5abc742fe95c776fec5042..e236dd584e3fa3a448195337a4aa912f665e605e 100644 (file)
@@ -1139,7 +1139,7 @@ obj_elf_vms_common (int ignore ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 
   obj_elf_change_section
-    (sec_name, SHT_NOBITS,
+    (sec_name, SHT_NOBITS, 0,
      SHF_ALLOC | SHF_WRITE | SHF_IA_64_VMS_OVERLAID | SHF_IA_64_VMS_GLOBAL,
      0, NULL, 1, 0);
 
index c3b091fc7d162f0235c7ae4f3eaa9b9808511a31..01244221681747797da7faf27cbd9a7785aff58e 100644 (file)
@@ -145,7 +145,8 @@ static void
 microblaze_s_data (int ignore ATTRIBUTE_UNUSED)
 {
 #ifdef OBJ_ELF
-  obj_elf_change_section (".data", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+  obj_elf_change_section (".data", SHT_PROGBITS, 0, SHF_ALLOC+SHF_WRITE,
+                         0, 0, 0, 0);
 #else
   s_data (ignore);
 #endif
@@ -157,7 +158,8 @@ static void
 microblaze_s_sdata (int ignore ATTRIBUTE_UNUSED)
 {
 #ifdef OBJ_ELF
-  obj_elf_change_section (".sdata", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+  obj_elf_change_section (".sdata", SHT_PROGBITS, 0, SHF_ALLOC+SHF_WRITE,
+                         0, 0, 0, 0);
 #else
   s_data (ignore);
 #endif
@@ -275,14 +277,16 @@ microblaze_s_rdata (int localvar)
   if (localvar == 0)
     {
       /* rodata.  */
-      obj_elf_change_section (".rodata", SHT_PROGBITS, SHF_ALLOC, 0, 0, 0, 0);
+      obj_elf_change_section (".rodata", SHT_PROGBITS, 0, SHF_ALLOC,
+                             0, 0, 0, 0);
       if (rodata_segment == 0)
        rodata_segment = subseg_new (".rodata", 0);
     }
   else
     {
       /* 1 .sdata2.  */
-      obj_elf_change_section (".sdata2", SHT_PROGBITS, SHF_ALLOC, 0, 0, 0, 0);
+      obj_elf_change_section (".sdata2", SHT_PROGBITS, 0, SHF_ALLOC,
+                             0, 0, 0, 0);
     }
 #else
   s_data (ignore);
@@ -294,11 +298,13 @@ microblaze_s_bss (int localvar)
 {
 #ifdef OBJ_ELF
   if (localvar == 0) /* bss.  */
-    obj_elf_change_section (".bss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+    obj_elf_change_section (".bss", SHT_NOBITS, 0, SHF_ALLOC+SHF_WRITE,
+                           0, 0, 0, 0);
   else if (localvar == 1)
     {
       /* sbss.  */
-      obj_elf_change_section (".sbss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+      obj_elf_change_section (".sbss", SHT_NOBITS, 0, SHF_ALLOC+SHF_WRITE,
+                             0, 0, 0, 0);
       if (sbss_segment == 0)
        sbss_segment = subseg_new (".sbss", 0);
     }
index 54b94bec9722d66476c8381619b11824ef886fc9..6a981227279c0be47472d3fa6c2faa7edfd5d126 100644 (file)
@@ -15879,7 +15879,7 @@ s_change_section (int ignore ATTRIBUTE_UNUSED)
   if (section_type == SHT_MIPS_DWARF)
     section_type = SHT_PROGBITS;
 
-  obj_elf_change_section (section_name, section_type, section_flag,
+  obj_elf_change_section (section_name, section_type, 0, section_flag,
                          section_entry_size, 0, 0, 0);
 
   if (now_seg->name != section_name)
index a24771b9777973b393112cd97aca7f535a61b868..10e5972d870d4435052b85d22148c7a3ffb81d5b 100644 (file)
@@ -612,7 +612,7 @@ msp430_profiler (int dummy ATTRIBUTE_UNUSED)
   subseg = now_subseg;
 
   /* Now go to .profiler section.  */
-  obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0);
+  obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0, 0);
 
   /* Save flags.  */
   emit_expr (& exp, 2);
index 05fa4da032346051262d7ed58434e9a76e2bd38d..ba826c7b298c4804f03e832d346f8358b0deb4ce 100644 (file)
@@ -486,7 +486,7 @@ parse_rx_section (char * name)
       else
        type = SHT_NOBITS;
 
-      obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
+      obj_elf_change_section (name, type, 0, attr, 0, NULL, FALSE, FALSE);
     }
   else /* Try not to redefine a section, especially B_1.  */
     {
@@ -501,7 +501,7 @@ parse_rx_section (char * name)
        | ((flags & SEC_STRINGS) ? SHF_STRINGS : 0)
        | ((flags & SEC_THREAD_LOCAL) ? SHF_TLS : 0);
 
-      obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
+      obj_elf_change_section (name, type, 0, attr, 0, NULL, FALSE, FALSE);
     }
 
   bfd_set_section_alignment (stdoutput, now_seg, align);
index c75fcf6f90e927cc163dbba17e669dc9cf18e055..6958a0e6ce707f41c52d99a052a98bc7a33b4f2f 100644 (file)
@@ -4666,7 +4666,8 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
       linkonce = 1;
     }
 
-  obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+  obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
+                         linkonce, 0);
 
   /* Set the section link for index tables.  */
   if (idx)
index d03d0b64c4805b57e02fb9cc6f8f635d8060880a..a5cff3daaf3fb751dbba014aac069b1f6447ed7c 100644 (file)
@@ -6525,6 +6525,8 @@ combination of the following characters:
 @table @code
 @item a
 section is allocatable
+@item d
+section is a GNU_MBIND section
 @item e
 section is excluded from executable and shared library.
 @item w
index e4dd684b44c84b5bfa70e87cc0a84287f91b0fe0..2a1bb27b52884963c6ebde4dda0524b4120a86ac 100644 (file)
@@ -209,6 +209,9 @@ if { [is_elf_format] } then {
     run_dump_test "section9"
     run_dump_test "section10"
     run_dump_test "section11"
+    run_dump_test "section12a"
+    run_dump_test "section12b"
+    run_dump_test "section13"
     run_dump_test "dwarf2-1"
     run_dump_test "dwarf2-2"
     run_dump_test "dwarf2-3"
index aa5ca3c0ac3b225a8df28ee523d256c7e0eedc1e..e187263d8ff3357c68856d24c5239f00cb565bd1 100644 (file)
@@ -18,7 +18,7 @@
 #...
 [      ]*\[.*\][       ]+sec3
 [      ]*PROGBITS.*
-[      ]*\[.*ffff030\]: MERGE, STRINGS,.* EXCLUDE, OS \(.*ff00000\), PROC \(.*[347]0000000\), UNKNOWN \(0+0ff000\)
+[      ]*\[.*fefff030\]: MERGE, STRINGS,.* EXCLUDE, OS \(.*ef00000\), PROC \(.*[347]0000000\), UNKNOWN \(0+0ff000\)
 #...
 [      ]*\[.*\][       ]+sec4
 [      ]*LOOS\+0x11[   ].*
@@ -26,7 +26,7 @@
 #...
 [      ]*\[.*\][       ]+sec5
 [      ]*LOUSER\+0x9[  ].*
-[      ]*\[.*fff0000\]:.* EXCLUDE, OS \(.*ff00000\), PROC \(.*[347]0000000\), UNKNOWN \(.*f0000\)
+[      ]*\[.*feff0000\]:.* EXCLUDE, OS \(.*ef00000\), PROC \(.*[347]0000000\), UNKNOWN \(.*f0000\)
 [      ]*\[.*\][       ]+.data.foo
 [      ]*LOUSER\+0x7f000000[   ].*
 [      ]*\[0+003\]: WRITE, ALLOC
index 057600706882388e54d404b36637f2e3805c4629..29f11845235e5b24c68e555e8490adc927a8b545 100644 (file)
@@ -7,7 +7,7 @@
        .word 2
 
        # Make sure that specifying further arguments to .sections is still supported
-       .section sec3, "0xfffff000MS", %progbits, 32
+       .section sec3, "0xfefff000MS", %progbits, 32
        .word 3
 
        # Make sure that extra flags can be set for well known sections as well.
@@ -19,7 +19,7 @@
        .word 5
 
        # Test both together, with a quoted type value.
-       .section sec5, "0xffff0000", "0x80000009"
+       .section sec5, "0xfeff0000", "0x80000009"
        .word 6
 
        # Test that declaring an extended version of a known special section works.
diff --git a/gas/testsuite/gas/elf/section12.s b/gas/testsuite/gas/elf/section12.s
new file mode 100644 (file)
index 0000000..41faad4
--- /dev/null
@@ -0,0 +1,33 @@
+       .section .mbind.data,"adw",%progbits
+       .byte 1
+
+       .section .mbind.data,"adw",%progbits,0x3
+       .byte 2
+
+       .section .mbind.text,"adx",%progbits
+       .byte 3
+
+       .section .mbind.text,"adx",%progbits,0x3
+       .byte 4
+
+       .section .mbind.bss,"adw",%nobits
+       .zero 5
+
+       .section .mbind.bss,"adw",%nobits,0x3
+       .zero 6
+
+       .section .mbind.rodata,"adG",%progbits,.foo_group,comdat,0x2
+       .byte 7
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat
+       .byte 8
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat,0x3
+       .byte 9
+
+       # Check that .pushsection works as well.
+       .pushsection .mbind.text,"adGx",%progbits,.foo_group,comdat,0x3
+       .byte 10
+
+       .popsection
+       .byte 11
diff --git a/gas/testsuite/gas/elf/section12a.d b/gas/testsuite/gas/elf/section12a.d
new file mode 100644 (file)
index 0000000..d31a675
--- /dev/null
@@ -0,0 +1,35 @@
+#source: section12.s
+#as: --no-pad-sections
+#readelf: -Sg --wide
+#name: mbind sections
+# The RX port annoyingly reorders the sections so that they do not match the sequence expected below.
+#skip: rx-*-*
+
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 WAD  0   0  1
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 WAD  0   3  1
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 AXD  0   0  1
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 AXD  0   3  1
+#...
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+0+0 0+[0-9a-f]+ 0+5 00 WAD  0   0  1
+#...
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+0+0 0+[0-9a-f]+ 0+6 00 WAD  0   3  1
+#...
+  \[[ 0-9]+\] \.mbind\.rodata[         ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 AGD  0   2  1
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 WAGD  0   0  1
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+2 00 WAGD  0   3  1
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+0+0 0+[0-9a-f]+ 0+1 00 AXGD  0   3  1
+#...
+COMDAT group section \[    1\] `\.group' \[\.foo_group\] contains 4 sections:
+[      ]+\[Index\][    ]+Name
+[      ]+\[[ 0-9]+][   ]+\.mbind\.rodata
+[      ]+\[[ 0-9]+][   ]+\.mbind\.data
+[      ]+\[[ 0-9]+][   ]+\.mbind\.data
+[      ]+\[[ 0-9]+][   ]+\.mbind\.text
+#pass
diff --git a/gas/testsuite/gas/elf/section12b.d b/gas/testsuite/gas/elf/section12b.d
new file mode 100644 (file)
index 0000000..717bc1a
--- /dev/null
@@ -0,0 +1,32 @@
+#source: section12.s
+#as: --no-pad-sections
+#objdump: -s
+#name: mbind section contents
+# The RX port annoyingly reorders the sections so that they do not match the sequence expected below.
+#skip: rx-*-*
+
+#...
+Contents of section .mbind.data:
+ 0000 01                                   .               
+#...
+Contents of section .mbind.data:
+ 0000 02                                   .               
+#...
+Contents of section .mbind.text:
+ 0000 03                                   .               
+#...
+Contents of section .mbind.text:
+ 0000 04                                   .               
+#...
+Contents of section .mbind.rodata:
+ 0000 07                                   .               
+#...
+Contents of section .mbind.data:
+ 0000 08                                   .               
+#...
+Contents of section .mbind.data:
+ 0000 090b                                 ..              
+#...
+Contents of section .mbind.text:
+ 0000 0a                                   .               
+#pass
diff --git a/gas/testsuite/gas/elf/section13.d b/gas/testsuite/gas/elf/section13.d
new file mode 100644 (file)
index 0000000..3ee7c82
--- /dev/null
@@ -0,0 +1,2 @@
+#name: mbind sections without SHF_ALLOC
+#error-output: section13.l
diff --git a/gas/testsuite/gas/elf/section13.l b/gas/testsuite/gas/elf/section13.l
new file mode 100644 (file)
index 0000000..c56b5ae
--- /dev/null
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*:1: Fatal error: SHF_ALLOC isn't set for GNU_MBIND section: .mbind.data
diff --git a/gas/testsuite/gas/elf/section13.s b/gas/testsuite/gas/elf/section13.s
new file mode 100644 (file)
index 0000000..6630f35
--- /dev/null
@@ -0,0 +1,2 @@
+       .section .mbind.data,"dw",@nobits
+       .byte 0
index c7a0ef29850c25edbe24cea853f5db3669d61463..fa0f3deb7224489e6af6983b8837f0f8e89a2332 100644 (file)
@@ -1,3 +1,10 @@
+2017-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf/common.h (PT_GNU_MBIND_NUM): New.
+       (PT_GNU_MBIND_LO): Likewise.
+       (PT_GNU_MBIND_HI): Likewise.
+       (SHF_GNU_MBIND): Likewise.
+
 2017-04-03  Palmer Dabbelt  <palmer@dabbelt.com>
 
        * elf/riscv.h (RISCV_GP_SYMBOL): New define.
index 65877fe4a414ef53a4f51cfd323b069b03e93faa..484cb48f96eb0fdf08b277d3d5df06ec93d0b72b 100644 (file)
 #define PT_GNU_STACK   (PT_LOOS + 0x474e551) /* Stack flags */
 #define PT_GNU_RELRO   (PT_LOOS + 0x474e552) /* Read-only after relocation */
 
+/* Mbind segments */
+#define PT_GNU_MBIND_NUM 4096
+#define PT_GNU_MBIND_LO (PT_LOOS + 0x474e555)
+#define PT_GNU_MBIND_HI (PT_GNU_MBIND_LO + PT_GNU_MBIND_NUM - 1)
+
 /* Program segment permissions, in program header p_flags field.  */
 
 #define PF_X           (1 << 0)        /* Segment is executable */
                                           are not to be further
                                           relocated.  */
 
+#define SHF_GNU_MBIND  0x01000000      /* Mbind section.  */
+
 /* Compression types.  */
 #define ELFCOMPRESS_ZLIB   1           /* Compressed with zlib.  */
 #define ELFCOMPRESS_LOOS   0x60000000  /* OS-specific semantics, lo */
index c3490a5a76a982774542abbed25470f0af8b8cdd..c9298e940038e22ef3cec6a084d84ac0f2958ad8 100644 (file)
@@ -1,3 +1,18 @@
+2017-04-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * NEWS: Mention support for ELF SHF_GNU_MBIND and
+       PT_GNU_MBIND_XXX.
+       * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
+       input GNU_MBIND sections with the same type, attributes and
+       sh_info field into a single output GNU_MBIND section.
+       * testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
+       * testsuite/ld-elf/mbind1.s: New file.
+       * testsuite/ld-elf/mbind1a.d: Likewise.
+       * testsuite/ld-elf/mbind1b.d: Likewise.
+       * testsuite/ld-elf/mbind1c.d: Likewise.
+       * testsuite/ld-elf/mbind2a.s: Likewise.
+       * testsuite/ld-elf/mbind2b.c: Likewise.
+
 2017-04-03  H.J. Lu  <hongjiu.lu@intel.com>
 
        * NEWS: Mention support for ELF GNU program properties.
diff --git a/ld/NEWS b/ld/NEWS
index 039a90e8cab1d0d862e49a0c1e8359850d6ad9df..52daa6bf57ed9ea6654b7a7e350bdfcd96a5c9e7 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,7 @@
 -*- text -*-
 
+* Add support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX.
+
 * Add support for ELF GNU program properties.
 
 * Add support for the Texas Instruments PRU processor.
index 007e48d6a85897b0167c84a580f820dc006f67c1..3442c955bf92b0d07e2cb51ef71ad2b31840945c 100644 (file)
@@ -2093,6 +2093,47 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
        }
     }
 
+  if (!bfd_link_relocatable (&link_info)
+      && (s->flags & SEC_ALLOC) != 0
+      && (elf_section_flags (s) & SHF_GNU_MBIND) != 0)
+    {
+      /* Find the output mbind section with the same type, attributes
+        and sh_info field.  */
+      for (os = &lang_output_section_statement.head->output_section_statement;
+          os != NULL;
+          os = os->next)
+       if (os->bfd_section != NULL
+           && !bfd_is_abs_section (os->bfd_section)
+           && (elf_section_flags (os->bfd_section) & SHF_GNU_MBIND) != 0
+           && ((s->flags & (SEC_ALLOC
+                            | SEC_LOAD
+                            | SEC_HAS_CONTENTS
+                            | SEC_READONLY
+                            | SEC_CODE))
+               == (os->bfd_section->flags & (SEC_ALLOC
+                                             | SEC_LOAD
+                                             | SEC_HAS_CONTENTS
+                                             | SEC_READONLY
+                                             | SEC_CODE)))
+           && (elf_section_data (os->bfd_section)->this_hdr.sh_info
+               == elf_section_data (s)->this_hdr.sh_info))
+           {
+             lang_add_section (&os->children, s, NULL, os);
+             return os;
+           }
+
+      /* Create the output mbind section with the ".mbind." prefix
+        in section name.  */
+      if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+       secname = ".mbind.bss";
+      else if ((s->flags & SEC_READONLY) == 0)
+       secname = ".mbind.data";
+      else if ((s->flags & SEC_CODE) == 0)
+       secname = ".mbind.rodata";
+      else
+       secname = ".mbind.text";
+    }
+
   /* Look through the script to see where to place this section.  */
   if (constraint == 0)
     for (os = lang_output_section_find (secname);
@@ -2105,8 +2146,11 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
 
        /* SEC_EXCLUDE is cleared when doing a relocatable link.  But
           we can't merge 2 input sections with the same name when only
-          one of them has SHF_EXCLUDE.  */
+          one of them has SHF_EXCLUDE.  Don't merge 2 sections with
+          different sh_info.  */
        if (os->bfd_section != NULL
+           && (elf_section_data (os->bfd_section)->this_hdr.sh_info
+               == elf_section_data (s)->this_hdr.sh_info)
            && (os->bfd_section->flags == 0
                || ((!bfd_link_relocatable (&link_info)
                     || (iself && (((elf_section_flags (s)
index 09c9dda9c4c3b206ae053780c44d1dc021e3bf62..f889070f5d8efb70f6cb2e86b49ad34058eab585 100644 (file)
@@ -298,6 +298,27 @@ if { [istarget *-*-linux*]
      || [istarget *-*-nacl*]
      || [istarget *-*-gnu*] } {
     run_ld_link_exec_tests $array_tests_pie $xfails
+
+    run_ld_link_exec_tests [list \
+       [list \
+           "Run mbind2a" \
+           "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
+           "" \
+           { mbind2a.s mbind2b.c } \
+           "mbind2a" \
+           "pass.out" \
+           "-O2 -I../bfd" \
+       ] \
+       [list \
+           "Run mbind2b" \
+           "-static -Wl,-z,common-page-size=0x4000" \
+           "" \
+           { mbind2a.s mbind2b.c } \
+           "mbind2b" \
+           "pass.out" \
+           "-O2 -I../bfd" \
+       ] \
+    ]
 }
 
 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
diff --git a/ld/testsuite/ld-elf/mbind1.s b/ld/testsuite/ld-elf/mbind1.s
new file mode 100644 (file)
index 0000000..414b9fe
--- /dev/null
@@ -0,0 +1,43 @@
+       .text
+       .global start   /* Used by SH targets.  */
+start:
+       .global _start
+_start:
+       .global __start
+__start:
+       .global main    /* Used by HPPA targets.  */
+main:
+       .dc.a 0
+       .section .mbind.data,"adw",%progbits
+       .byte 1
+
+       .section .mbind.data,"adw",%progbits,0x3
+       .byte 2
+
+       .section .mbind.text,"adx",%progbits
+       .byte 3
+
+       .section .mbind.text,"adx",%progbits,0x3
+       .byte 4
+
+       .section .mbind.bss,"adw",%nobits
+       .zero 5
+
+       .section .mbind.bss,"adw",%nobits,0x3
+       .zero 6
+
+       .section .mbind.rodata,"adG",%progbits,.foo_group,comdat,0x2
+       .byte 7
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat
+       .byte 8
+
+       .section .mbind.data,"adGw",%progbits,.foo_group,comdat,0x3
+       .byte 9
+
+       # Check that .pushsection works as well.
+       .pushsection .mbind.text,"adGx",%progbits,.foo_group,comdat,0x3
+       .byte 10
+
+       .popsection
+       .byte 11
diff --git a/ld/testsuite/ld-elf/mbind1a.d b/ld/testsuite/ld-elf/mbind1a.d
new file mode 100644 (file)
index 0000000..aabf781
--- /dev/null
@@ -0,0 +1,44 @@
+#source: mbind1.s
+#ld: -z common-page-size=0x1000 -z max-page-size=0x200000
+#readelf: -S -l --wide
+#target: *-*-linux* *-*-gnu*
+
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   3 4096
+  \[[ 0-9]+\] \.mbind\.rodata[         ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00  AD  0   2 4096
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+Program Headers:
+  Type.*
+#...
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x200000
+#...
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x2[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R   0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+#...
+ Section to Segment mapping:
+  Segment Sections...
+#...
+   [0-9]+     .*.text .mbind.text .mbind.text .mbind.rodata .*
+   [0-9]+     .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .*
+#...
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.rodata +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.bss +
+   [0-9]+     .mbind.bss +
+#pass
diff --git a/ld/testsuite/ld-elf/mbind1b.d b/ld/testsuite/ld-elf/mbind1b.d
new file mode 100644 (file)
index 0000000..f161108
--- /dev/null
@@ -0,0 +1,44 @@
+#source: mbind1.s
+#ld: -shared -z common-page-size=0x1000 -z max-page-size=0x200000
+#readelf: -S -l --wide
+#target: *-*-linux* *-*-gnu*
+
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   3 4096
+  \[[ 0-9]+\] \.mbind\.rodata[         ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00  AD  0   2 4096
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+Program Headers:
+  Type.*
+#...
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x200000
+#...
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x2[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R   0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+#...
+ Section to Segment mapping:
+  Segment Sections...
+#...
+   [0-9]+     .*.text .mbind.text .mbind.text .mbind.rodata .*
+   [0-9]+     .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .*
+#...
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.rodata +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.bss +
+   [0-9]+     .mbind.bss +
+#pass
diff --git a/ld/testsuite/ld-elf/mbind1c.d b/ld/testsuite/ld-elf/mbind1c.d
new file mode 100644 (file)
index 0000000..1348d0c
--- /dev/null
@@ -0,0 +1,44 @@
+#source: mbind1.s
+#ld: -pie -z common-page-size=0x1000 -z max-page-size=0x200000
+#readelf: -S -l --wide
+#target: *-*-linux* *-*-gnu*
+
+#...
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.text[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD  0   3 4096
+  \[[ 0-9]+\] \.mbind\.rodata[         ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00  AD  0   2 4096
+#...
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.data[   ]+PROGBITS[     ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   0 4096
+  \[[ 0-9]+\] \.mbind\.bss[    ]+NOBITS[       ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD  0   3 4096
+#...
+Program Headers:
+  Type.*
+#...
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+  LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x200000
+#...
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000
+  GNU_MBIND\+0x2[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R   0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+  GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW  0x1000
+#...
+ Section to Segment mapping:
+  Segment Sections...
+#...
+   [0-9]+     .*.text .mbind.text .mbind.text .mbind.rodata .*
+   [0-9]+     .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .*
+#...
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.text +
+   [0-9]+     .mbind.rodata +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.data +
+   [0-9]+     .mbind.bss +
+   [0-9]+     .mbind.bss +
+#pass
diff --git a/ld/testsuite/ld-elf/mbind2a.s b/ld/testsuite/ld-elf/mbind2a.s
new file mode 100644 (file)
index 0000000..2da9792
--- /dev/null
@@ -0,0 +1,15 @@
+/* Place bss_in_mbind0 in .mbind.bss section with sh_info == 0.  */
+       .globl bss_in_mbind0
+       .section .mbind.bss,"adw",@nobits,0
+       .type bss_in_mbind0, @object
+       .size bss_in_mbind0, 1
+bss_in_mbind0:
+       .zero 1
+
+/* Place data_in_mbind3 in .mbind.data section with sh_info == 3.  */
+       .globl data_in_mbind3
+       .section .mbind.data,"adw",@progbits,0x3
+       .type data_in_mbind3, @object
+       .size data_in_mbind3, 1
+data_in_mbind3:
+       .byte 0
diff --git a/ld/testsuite/ld-elf/mbind2b.c b/ld/testsuite/ld-elf/mbind2b.c
new file mode 100644 (file)
index 0000000..10922a1
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <bfd_stdint.h>
+
+extern char bss_in_mbind0;
+extern char data_in_mbind3;
+
+int
+main (void)
+{
+  if (((intptr_t) &bss_in_mbind0 & (0x4000 - 1)) != 0)
+    abort ();
+  if (((intptr_t) &data_in_mbind3 & (0x4000 - 1)) != 0)
+    abort ();
+  printf ("PASS\n");
+  return 0;
+}