This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RFC: ld: Support ELF GNU program properties
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Mon, 13 Mar 2017 11:20:54 -0700
- Subject: RFC: ld: Support ELF GNU program properties
- Authentication-results: sourceware.org; auth=none
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
>From .note.gnu.property section in each ELF input, we build a list of
GNU properties if .note.gnu.property section isn't corrupt. The unknown
properties are ignored. All property lists in relocatable inputs are
merged into an output property list. When -z stack-size=N is used and
N isn't 0, the GNU_PROPERTY_STACK_SIZE property will be merged with or
added to the output property list. .note.gnu.property section is
generated in output from the output property list.
Any comments?
H.J.
---
bfd/
* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
(BFD32_BACKENDS_CFILES): Add elf-properties.c.
* configure.ac (elf): Add elf-properties.lo.
* Makefile.in: Regenerated.
* configure: Likewise.
* elf-bfd.h (elf_property_kind): New.
(elf_property): Likewise.
(elf_property_list): Likewise.
(elf_properties): Likewise.
(_bfd_elf_parse_gnu_properties): Likewise.
(_bfd_elf_get_property): Likewise.
(_bfd_elf_link_setup_gnu_properties): Likewise.
(elf_backend_data): Add parse_gnu_properties and
merge_gnu_properties.
(elf_obj_tdata): Add properties.
* elf-properties.c: New file.
* elf32-i386.c (elf_i386_parse_gnu_properties): New.
(elf_i386_merge_gnu_properties): Likewise.
(elf_backend_parse_gnu_properties): Likewise.
(elf_backend_merge_gnu_properties): Likewise.
* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
(elf_x86_64_merge_gnu_properties): Likewise.
(elf_backend_parse_gnu_properties): Likewise.
(elf_backend_merge_gnu_properties): Likewise.
* elfxx-target.h (elf_backend_merge_gnu_properties): Likewise.
(elf_backend_parse_gnu_properties): Likewise.
(elfNN_bed): Add elf_backend_parse_gnu_properties and
elf_backend_merge_gnu_properties.
ld/
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Call
_bfd_elf_link_setup_gnu_properties.
* testsuite/ld-i386/i386.exp: Run property tests for Linux/i386.
* testsuite/ld-i386/pass.c: New file.
* testsuite/ld-i386/property-1.r: Likewise.
* testsuite/ld-i386/property-2.r: Likewise.
* testsuite/ld-i386/property-3.r: Likewise.
* testsuite/ld-i386/property-4.r: Likewise.
* testsuite/ld-i386/property-5.r: Likewise.
* testsuite/ld-i386/property-6.r: Likewise.
* testsuite/ld-i386/property-6a.c: Likewise.
* testsuite/ld-i386/property-6b.c: Likewise.
* testsuite/ld-i386/property-6c.S: Likewise.
* testsuite/ld-i386/property-no-copy.S: Likewise.
* testsuite/ld-i386/property-stack.S: Likewise.
* testsuite/ld-i386/property-x86-1.S: Likewise.
* testsuite/ld-i386/property-x86-2.S: Likewise.
* testsuite/ld-x86-64/pass.c: Likewise.
* testsuite/ld-x86-64/property-1.r: Likewise.
* testsuite/ld-x86-64/property-2.r: Likewise.
* testsuite/ld-x86-64/property-3.r: Likewise.
* testsuite/ld-x86-64/property-4.r: Likewise.
* testsuite/ld-x86-64/property-5.r: Likewise.
* testsuite/ld-x86-64/property-6.r: Likewise.
* testsuite/ld-x86-64/property-6a.c: Likewise.
* testsuite/ld-x86-64/property-6b.c: Likewise.
* testsuite/ld-x86-64/property-6c.S: Likewise.
* testsuite/ld-x86-64/property-no-copy.S: Likewise.
* testsuite/ld-x86-64/property-stack.S: Likewise.
* testsuite/ld-x86-64/property-x86-1.S: Likewise.
* testsuite/ld-x86-64/property-x86-2.S: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run property tests for
Linux/x86-64.
---
bfd/Makefile.am | 2 +
bfd/Makefile.in | 3 +
bfd/configure | 2 +-
bfd/configure.ac | 2 +-
bfd/elf-bfd.h | 44 ++++
bfd/elf-properties.c | 370 ++++++++++++++++++++++++++++++
bfd/elf.c | 3 +
bfd/elf32-i386.c | 62 +++++
bfd/elf64-x86-64.c | 66 +++++-
bfd/elfxx-target.h | 8 +
ld/emultempl/elf32.em | 2 +
ld/testsuite/ld-i386/i386.exp | 257 +++++++++++++++++++++
ld/testsuite/ld-i386/pass.c | 8 +
ld/testsuite/ld-i386/property-1.r | 7 +
ld/testsuite/ld-i386/property-2.r | 7 +
ld/testsuite/ld-i386/property-3.r | 8 +
ld/testsuite/ld-i386/property-4.r | 8 +
ld/testsuite/ld-i386/property-5.r | 8 +
ld/testsuite/ld-i386/property-6.r | 7 +
ld/testsuite/ld-i386/property-6a.c | 7 +
ld/testsuite/ld-i386/property-6b.c | 8 +
ld/testsuite/ld-i386/property-6c.S | 18 ++
ld/testsuite/ld-i386/property-no-copy.S | 15 ++
ld/testsuite/ld-i386/property-stack.S | 18 ++
ld/testsuite/ld-i386/property-x86-1.S | 32 +++
ld/testsuite/ld-i386/property-x86-2.S | 25 ++
ld/testsuite/ld-x86-64/pass.c | 8 +
ld/testsuite/ld-x86-64/property-1.r | 7 +
ld/testsuite/ld-x86-64/property-2.r | 7 +
ld/testsuite/ld-x86-64/property-3.r | 8 +
ld/testsuite/ld-x86-64/property-4.r | 8 +
ld/testsuite/ld-x86-64/property-5.r | 8 +
ld/testsuite/ld-x86-64/property-6.r | 7 +
ld/testsuite/ld-x86-64/property-6a.c | 7 +
ld/testsuite/ld-x86-64/property-6b.c | 8 +
ld/testsuite/ld-x86-64/property-6c.S | 23 ++
ld/testsuite/ld-x86-64/property-no-copy.S | 20 ++
ld/testsuite/ld-x86-64/property-stack.S | 23 ++
ld/testsuite/ld-x86-64/property-x86-1.S | 37 +++
ld/testsuite/ld-x86-64/property-x86-2.S | 30 +++
ld/testsuite/ld-x86-64/x86-64.exp | 257 +++++++++++++++++++++
41 files changed, 1452 insertions(+), 3 deletions(-)
create mode 100644 bfd/elf-properties.c
create mode 100644 ld/testsuite/ld-i386/pass.c
create mode 100644 ld/testsuite/ld-i386/property-1.r
create mode 100644 ld/testsuite/ld-i386/property-2.r
create mode 100644 ld/testsuite/ld-i386/property-3.r
create mode 100644 ld/testsuite/ld-i386/property-4.r
create mode 100644 ld/testsuite/ld-i386/property-5.r
create mode 100644 ld/testsuite/ld-i386/property-6.r
create mode 100644 ld/testsuite/ld-i386/property-6a.c
create mode 100644 ld/testsuite/ld-i386/property-6b.c
create mode 100644 ld/testsuite/ld-i386/property-6c.S
create mode 100644 ld/testsuite/ld-i386/property-no-copy.S
create mode 100644 ld/testsuite/ld-i386/property-stack.S
create mode 100644 ld/testsuite/ld-i386/property-x86-1.S
create mode 100644 ld/testsuite/ld-i386/property-x86-2.S
create mode 100644 ld/testsuite/ld-x86-64/pass.c
create mode 100644 ld/testsuite/ld-x86-64/property-1.r
create mode 100644 ld/testsuite/ld-x86-64/property-2.r
create mode 100644 ld/testsuite/ld-x86-64/property-3.r
create mode 100644 ld/testsuite/ld-x86-64/property-4.r
create mode 100644 ld/testsuite/ld-x86-64/property-5.r
create mode 100644 ld/testsuite/ld-x86-64/property-6.r
create mode 100644 ld/testsuite/ld-x86-64/property-6a.c
create mode 100644 ld/testsuite/ld-x86-64/property-6b.c
create mode 100644 ld/testsuite/ld-x86-64/property-6c.S
create mode 100644 ld/testsuite/ld-x86-64/property-no-copy.S
create mode 100644 ld/testsuite/ld-x86-64/property-stack.S
create mode 100644 ld/testsuite/ld-x86-64/property-x86-1.S
create mode 100644 ld/testsuite/ld-x86-64/property-x86-2.S
diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 0b02263..87dd2db 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -319,6 +319,7 @@ BFD32_BACKENDS = \
elf-m10200.lo \
elf-m10300.lo \
elf-nacl.lo \
+ elf-properties.lo \
elf-strtab.lo \
elf-vxworks.lo \
elf.lo \
@@ -512,6 +513,7 @@ BFD32_BACKENDS_CFILES = \
elf-m10200.c \
elf-m10300.c \
elf-nacl.c \
+ elf-properties.c \
elf-strtab.c \
elf-vxworks.c \
elf.c \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index 096c7ef..67d112d 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -653,6 +653,7 @@ BFD32_BACKENDS = \
elf-m10200.lo \
elf-m10300.lo \
elf-nacl.lo \
+ elf-properties.lo \
elf-strtab.lo \
elf-vxworks.lo \
elf.lo \
@@ -846,6 +847,7 @@ BFD32_BACKENDS_CFILES = \
elf-m10200.c \
elf-m10300.c \
elf-nacl.c \
+ elf-properties.c \
elf-strtab.c \
elf-vxworks.c \
elf.c \
@@ -1464,6 +1466,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-m10200.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-m10300.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-nacl.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-properties.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-strtab.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-vxworks.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf.Plo@am__quote@
diff --git a/bfd/configure b/bfd/configure
index 83256d2..a40e621 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -14234,7 +14234,7 @@ selarchs="$f"
# Target backend .o files.
tb=
-elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo
+elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo elf-properties.lo
elf-eh-frame.lo dwarf1.lo dwarf2.lo"
coffgen="coffgen.lo dwarf2.lo"
coff="cofflink.lo $coffgen"
diff --git a/bfd/configure.ac b/bfd/configure.ac
index ee0c537..e90ea9f 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -365,7 +365,7 @@ selarchs="$f"
# Target backend .o files.
tb=
-elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo
+elf="elf.lo elflink.lo elf-attrs.lo elf-strtab.lo elf-properties.lo
elf-eh-frame.lo dwarf1.lo dwarf2.lo"
coffgen="coffgen.lo dwarf2.lo"
coff="cofflink.lo $coffgen"
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 9e3d6f5..fd500c5 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -766,6 +766,31 @@ typedef asection * (*elf_gc_mark_hook_fn)
(asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *, Elf_Internal_Sym *);
+enum elf_property_kind
+ {
+ property_unknown = 0,
+ property_ignored,
+ property_corrupt,
+ property_value
+ };
+
+typedef struct elf_property
+{
+ unsigned int type;
+ unsigned int datasz;
+ union
+ {
+ bfd_vma value;
+ } u;
+ enum elf_property_kind kind;
+} elf_property;
+
+typedef struct elf_property_list
+{
+ struct elf_property_list *next;
+ struct elf_property property;
+} elf_property_list;
+
struct bfd_elf_section_reloc_data;
struct elf_backend_data
@@ -1389,6 +1414,15 @@ struct elf_backend_data
or give an error and return FALSE. */
bfd_boolean (*obj_attrs_handle_unknown) (bfd *, int);
+ /* Parse GNU properties. */
+ enum elf_property_kind (*parse_gnu_properties) (bfd *, unsigned int,
+ bfd_byte *,
+ unsigned int);
+
+ /* Merge GNU properties. */
+ bfd_boolean (*merge_gnu_properties) (bfd *, elf_property *,
+ elf_property *);
+
/* Encoding used for compact EH tables. */
int (*compact_eh_encoding) (struct bfd_link_info *);
@@ -1798,6 +1832,8 @@ struct elf_obj_tdata
/* Symbol buffer. */
void *symbuf;
+ elf_property_list *properties;
+
obj_attribute known_obj_attributes[2][NUM_KNOWN_OBJ_ATTRIBUTES];
obj_attribute_list *other_obj_attributes[2];
@@ -1882,6 +1918,7 @@ struct elf_obj_tdata
(elf_known_obj_attributes (bfd) [OBJ_ATTR_PROC])
#define elf_other_obj_attributes_proc(bfd) \
(elf_other_obj_attributes (bfd) [OBJ_ATTR_PROC])
+#define elf_properties(bfd) (elf_tdata (bfd) -> properties)
extern void _bfd_elf_swap_verdef_in
(bfd *, const Elf_External_Verdef *, Elf_Internal_Verdef *);
@@ -2538,6 +2575,13 @@ extern bfd_boolean _bfd_elf_merge_unknown_attribute_low (bfd *, bfd *, int);
extern bfd_boolean _bfd_elf_merge_unknown_attribute_list (bfd *, bfd *);
extern Elf_Internal_Shdr *_bfd_elf_single_rel_hdr (asection *sec);
+extern bfd_boolean _bfd_elf_parse_gnu_properties
+ (bfd *, Elf_Internal_Note *);
+extern elf_property * _bfd_elf_get_property
+ (bfd *, unsigned int, unsigned int);
+extern void _bfd_elf_link_setup_gnu_properties
+ (struct bfd_link_info *);
+
/* The linker may need to keep track of the number of relocs that it
decides to copy as dynamic relocs in check_relocs for each symbol.
This is so that it can later discard them if they are found to be
diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
new file mode 100644
index 0000000..e849a43
--- /dev/null
+++ b/bfd/elf-properties.c
@@ -0,0 +1,370 @@
+/* ELF program property support.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ 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. */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "libbfd.h"
+#include "elf-bfd.h"
+
+/* Get a property, allocate a new one if needed. */
+
+elf_property *
+_bfd_elf_get_property (bfd *abfd, unsigned int type, unsigned int datasz)
+{
+ elf_property_list *p, **lastp;
+
+ /* Keep the property list in order of type. */
+ lastp = &elf_properties (abfd);
+ for (p = *lastp; p; p = p->next)
+ {
+ /* Reuse the existing entry. */
+ if (type == p->property.type)
+ return &p->property;
+ else if (type < p->property.type)
+ break;
+ lastp = &p->next;
+ }
+ p = (elf_property_list *) bfd_alloc (abfd, sizeof (*p));
+ memset (p, 0, sizeof (*p));
+ p->property.type = type;
+ p->property.datasz = datasz;
+ p->next = *lastp;
+ *lastp = p;
+ return &p->property;
+}
+
+/* Parse GNU properties. */
+
+bfd_boolean
+_bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
+{
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+ unsigned int align_size = bed->s->elfclass == ELFCLASS64 ? 8 : 4;
+ bfd_byte *ptr = (bfd_byte *) note->descdata;
+ bfd_byte *ptr_end = ptr + note->descsz;
+
+ if (note->descsz < 8 || (note->descsz % align_size) != 0)
+ {
+bad_size:
+ _bfd_error_handler
+ (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) size: %#lx\n"),
+ abfd, note->type, note->descsz);
+ return FALSE;
+ }
+
+ while (1)
+ {
+ unsigned int type = bfd_h_get_32 (abfd, ptr);
+ unsigned int datasz = bfd_h_get_32 (abfd, ptr + 4);
+ elf_property *prop;
+
+ ptr += 8;
+
+ if ((ptr + datasz) > ptr_end)
+ {
+ _bfd_error_handler
+ (_("warning: %B: corrupt GNU_PROPERTY_TYPE (%ld) type (0x%x) datasz: 0x%x\n"),
+ abfd, note->type, type, datasz);
+ /* Clear all properties. */
+ elf_properties (abfd) = NULL;
+ return FALSE;
+ }
+
+ if (type >= GNU_PROPERTY_LOPROC)
+ {
+ if (type < GNU_PROPERTY_LOUSER && bed->parse_gnu_properties)
+ {
+ enum elf_property_kind kind
+ = bed->parse_gnu_properties (abfd, type, ptr, datasz);
+ if (kind == property_corrupt)
+ {
+ /* Clear all properties. */
+ elf_properties (abfd) = NULL;
+ return FALSE;
+ }
+ else if (kind != property_ignored)
+ goto next;
+ }
+ }
+ else
+ {
+ switch (type)
+ {
+ case GNU_PROPERTY_STACK_SIZE:
+ if (datasz != align_size)
+ {
+ _bfd_error_handler
+ (_("warning: %B: corrupt stack size: 0x%x\n"),
+ abfd, datasz);
+ /* Clear all properties. */
+ elf_properties (abfd) = NULL;
+ return FALSE;
+ }
+ prop = _bfd_elf_get_property (abfd, type, datasz);
+ if (datasz == 8)
+ prop->u.value = bfd_h_get_64 (abfd, ptr);
+ else
+ prop->u.value = bfd_h_get_32 (abfd, ptr);
+ prop->kind = property_value;
+ goto next;
+
+ case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
+ if (datasz != 0)
+ {
+ _bfd_error_handler
+ (_("warning: %B: corrupt no copy on protected size: 0x%x\n"),
+ abfd, datasz);
+ /* Clear all properties. */
+ elf_properties (abfd) = NULL;
+ return FALSE;
+ }
+ prop = _bfd_elf_get_property (abfd, type, datasz);
+ prop->kind = property_value;
+ goto next;
+
+ default:
+ break;
+ }
+ }
+
+ _bfd_error_handler
+ (_("warning: %B: unsupported GNU_PROPERTY_TYPE (%ld) type: 0x%x\n"),
+ abfd, note->type, type);
+
+next:
+ ptr += (datasz + (align_size - 1)) & ~ (align_size - 1);
+ if (ptr == ptr_end)
+ break;
+
+ if (ptr > (ptr_end - 8))
+ goto bad_size;
+ }
+
+ return TRUE;
+}
+
+/* Merge GNU property. Return TRUE if property is updated. */
+
+static bfd_boolean
+elf_merge_gnu_properties (bfd *abfd, elf_property *prop, elf_property *p)
+{
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+
+ if (prop->type >= GNU_PROPERTY_LOPROC
+ && prop->type < GNU_PROPERTY_LOUSER
+ && bed->merge_gnu_properties != NULL)
+ return bed->merge_gnu_properties (abfd, prop, p);
+
+ switch (prop->type)
+ {
+ case GNU_PROPERTY_STACK_SIZE:
+ if (p->u.value > prop->u.value)
+ {
+ prop->u.value = p->u.value;
+ return TRUE;
+ }
+ break;
+
+ case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
+ break;
+
+ default:
+ /* Never should happen. */
+ abort ();
+ }
+
+ return FALSE;
+}
+
+/* Merge GNU property list. Return TRUE if property list is updated. */
+
+static bfd_boolean
+elf_merge_gnu_property_list (bfd *abfd, elf_property_list *list)
+{
+ bfd_boolean updated = FALSE;
+
+ for (; list != NULL; list = list->next)
+ {
+ elf_property *p;
+ p = _bfd_elf_get_property (abfd, list->property.type,
+ list->property.datasz);
+ if (p->kind == property_unknown)
+ {
+ /* Add a new property. */
+ *p = list->property;
+ updated = TRUE;
+ }
+ else
+ updated |= elf_merge_gnu_properties (abfd, p, &list->property);
+ }
+
+ return updated;
+}
+
+/* Set up GNU properties. */
+
+void
+_bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
+{
+ bfd *abfd, *first_pbfd = NULL;
+ elf_property_list *list;
+ asection *sec;
+ bfd_boolean updated = FALSE;
+ const struct elf_backend_data *bed;
+ unsigned int align_size;
+
+ for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+ && bfd_count_sections (abfd) != 0)
+ {
+ /* Check .note.gnu.property section in relocatable ELF input. */
+ list = elf_properties (abfd);
+ if (list)
+ {
+ if (first_pbfd == NULL)
+ {
+ /* Keep .note.gnu.property section in FIRST_PBFD. */
+ first_pbfd = abfd;
+ continue;
+ }
+
+ /* Merge properties with FIRST_PBFD. */
+ updated |= elf_merge_gnu_property_list (first_pbfd, list);
+
+ /* Discard .note.gnu.property section in the rest inputs. */
+ sec = bfd_get_section_by_name (abfd, ".note.gnu.property");
+ sec->output_section = bfd_abs_section_ptr;
+ }
+ }
+
+ /* Do nothing if there is no .note.gnu.property section. */
+ if (first_pbfd == NULL)
+ return;
+
+ bed = get_elf_backend_data (first_pbfd);
+ align_size = bed->s->elfclass == ELFCLASS64 ? 8 : 4;
+
+ /* Update stack size in .note.gnu.property with -z stack-size=N if
+ N > 0. */
+ if (info->stacksize && first_pbfd != NULL && info->stacksize > 0)
+ {
+ elf_property *p;
+ bfd_vma stacksize = info->stacksize;
+
+ p = _bfd_elf_get_property (first_pbfd, GNU_PROPERTY_STACK_SIZE,
+ align_size);
+ if (p->kind == property_unknown)
+ {
+ /* Create GNU_PROPERTY_STACK_SIZE. */
+ p->u.value = stacksize;
+ p->kind = property_value;
+ updated = TRUE;
+ }
+ else if (stacksize > p->u.value)
+ {
+ p->u.value = stacksize;
+ updated = TRUE;
+ }
+ }
+
+ if (updated)
+ {
+ unsigned int size;
+ unsigned int descsz;
+ bfd_byte *contents;
+ Elf_External_Note *e_note;
+
+ sec = bfd_get_section_by_name (first_pbfd, ".note.gnu.property");
+
+ /* Compute the section size. */
+ descsz = offsetof (Elf_External_Note, name[sizeof "GNU"]);
+ descsz = (descsz + 3) & -(unsigned int) 4;
+ size = descsz;
+ for (list = elf_properties (first_pbfd);
+ list != NULL;
+ list = list->next)
+ {
+ /* There are 4 byte type + 4 byte datasz for each property. */
+ size += 4 + 4 + list->property.datasz;
+ /* Align each property. */
+ size = (size + (align_size - 1)) & ~(align_size - 1);
+ }
+
+ /* Update .note.gnu.property section now. */
+ sec->size = size;
+ contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
+
+ e_note = (Elf_External_Note *) contents;
+ bfd_h_put_32 (first_pbfd, sizeof "GNU", &e_note->namesz);
+ bfd_h_put_32 (first_pbfd, size - descsz, &e_note->descsz);
+ bfd_h_put_32 (first_pbfd, NT_GNU_PROPERTY_TYPE_0, &e_note->type);
+ memcpy (e_note->name, "GNU", sizeof "GNU");
+
+ size = descsz;
+ for (list = elf_properties (first_pbfd);
+ list != NULL;
+ list = list->next)
+ {
+ /* There are 4 byte type + 4 byte datasz for each property. */
+ bfd_h_put_32 (first_pbfd, list->property.type,
+ contents + size);
+ bfd_h_put_32 (first_pbfd, list->property.datasz,
+ contents + size + 4);
+ size += 4 + 4;
+
+ /* Write out property value. */
+ switch (list->property.kind)
+ {
+ case property_value:
+ switch (list->property.datasz)
+ {
+ default:
+ /* Never should happen. */
+ abort ();
+
+ case 0:
+ break;
+
+ case 4:
+ bfd_h_put_32 (first_pbfd, list->property.u.value,
+ contents + size);
+ break;
+
+ case 8:
+ bfd_h_put_64 (first_pbfd, list->property.u.value,
+ contents + size);
+ break;
+ }
+ break;
+
+ default:
+ /* Never should happen. */
+ abort ();
+ }
+ size += list->property.datasz;
+
+ /* Align each property. */
+ size = (size + (align_size - 1)) & ~ (align_size - 1);
+ }
+
+ /* Cache the section contents for elf_link_input_bfd. */
+ elf_section_data (sec)->this_hdr.contents = contents;
+ }
+}
diff --git a/bfd/elf.c b/bfd/elf.c
index 9418e51..d4d91b6 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9691,6 +9691,9 @@ elfobj_grok_gnu_note (bfd *abfd, Elf_Internal_Note *note)
default:
return TRUE;
+ case NT_GNU_PROPERTY_TYPE_0:
+ return _bfd_elf_parse_gnu_properties (abfd, note);
+
case NT_GNU_BUILD_ID:
return elfobj_grok_gnu_build_id (abfd, note);
}
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 2784ef7..7e82b0d 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -6131,6 +6131,66 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h)
return _bfd_elf_hash_symbol (h);
}
+/* Parse i386 GNU properties. */
+
+static enum elf_property_kind
+elf_i386_parse_gnu_properties (bfd *abfd, unsigned int type,
+ bfd_byte *ptr, unsigned int datasz)
+{
+ elf_property *prop;
+
+ switch (type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ if (datasz != 4)
+ {
+ _bfd_error_handler
+ ((type == GNU_PROPERTY_X86_ISA_1_USED
+ ? _("error: %B: <corrupt x86 ISA used size: 0x%x>\n")
+ : _("error: %B: <corrupt x86 ISA needed size: 0x%x>\n")),
+ abfd, datasz);
+ return property_corrupt;
+ }
+ prop = _bfd_elf_get_property (abfd, type, datasz);
+ prop->u.value = bfd_h_get_32 (abfd, ptr);
+ prop->kind = property_value;
+ break;
+
+ default:
+ return property_ignored;
+ }
+
+ return property_value;
+}
+
+/* Merge i386 GNU property. Return TRUE if property is updated. */
+
+static bfd_boolean
+elf_i386_merge_gnu_properties (bfd *abfd ATTRIBUTE_UNUSED,
+ elf_property *prop,
+ elf_property *p)
+{
+ unsigned int value;
+ bfd_boolean updated = FALSE;
+
+ switch (prop->type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ value = prop->u.value;
+ prop->u.value = value | p->u.value;
+ updated = value != (unsigned int) prop->u.value;
+ break;
+
+ default:
+ /* Never should happen. */
+ abort ();
+ }
+
+ return updated;
+}
+
#define TARGET_LITTLE_SYM i386_elf32_vec
#define TARGET_LITTLE_NAME "elf32-i386"
#define ELF_ARCH bfd_arch_i386
@@ -6182,6 +6242,8 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h)
((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
#define elf_backend_hash_symbol elf_i386_hash_symbol
#define elf_backend_fixup_symbol elf_i386_fixup_symbol
+#define elf_backend_parse_gnu_properties elf_i386_parse_gnu_properties
+#define elf_backend_merge_gnu_properties elf_i386_merge_gnu_properties
#include "elf32-target.h"
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index e0e6c16..717e087 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -6896,8 +6896,68 @@ elf_x86_64_relocs_compatible (const bfd_target *input,
&& _bfd_elf_relocs_compatible (input, output));
}
+/* Parse x86-64 GNU properties. */
+
+static enum elf_property_kind
+elf_x86_64_parse_gnu_properties (bfd *abfd, unsigned int type,
+ bfd_byte *ptr, unsigned int datasz)
+{
+ elf_property *prop;
+
+ switch (type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ if (datasz != 4)
+ {
+ _bfd_error_handler
+ ((type == GNU_PROPERTY_X86_ISA_1_USED
+ ? _("error: %B: <corrupt x86 ISA used size: 0x%x>\n")
+ : _("error: %B: <corrupt x86 ISA needed size: 0x%x>\n")),
+ abfd, datasz);
+ return property_corrupt;
+ }
+ prop = _bfd_elf_get_property (abfd, type, datasz);
+ prop->u.value = bfd_h_get_32 (abfd, ptr);
+ prop->kind = property_value;
+ break;
+
+ default:
+ return property_ignored;
+ }
+
+ return property_value;
+}
+
+/* Merge x86-64 GNU property. Return TRUE if property is updated. */
+
+static bfd_boolean
+elf_x86_64_merge_gnu_properties (bfd *abfd ATTRIBUTE_UNUSED,
+ elf_property *prop,
+ elf_property *p)
+{
+ unsigned int value;
+ bfd_boolean updated = FALSE;
+
+ switch (prop->type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ value = prop->u.value;
+ prop->u.value = value | p->u.value;
+ updated = value != (unsigned int) prop->u.value;
+ break;
+
+ default:
+ /* Never should happen. */
+ abort ();
+ }
+
+ return updated;
+}
+
static const struct bfd_elf_special_section
- elf_x86_64_special_sections[]=
+elf_x86_64_special_sections[]=
{
{ STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
{ STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
@@ -6988,6 +7048,10 @@ static const struct bfd_elf_special_section
((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
#define elf_backend_fixup_symbol \
elf_x86_64_fixup_symbol
+#define elf_backend_parse_gnu_properties \
+ elf_x86_64_parse_gnu_properties
+#define elf_backend_merge_gnu_properties \
+ elf_x86_64_merge_gnu_properties
#include "elf64-target.h"
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index d063fb7..8aa2de5 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -519,6 +519,12 @@
#ifndef elf_backend_obj_attrs_handle_unknown
#define elf_backend_obj_attrs_handle_unknown NULL
#endif
+#ifndef elf_backend_parse_gnu_properties
+#define elf_backend_parse_gnu_properties NULL
+#endif
+#ifndef elf_backend_merge_gnu_properties
+#define elf_backend_merge_gnu_properties NULL
+#endif
#ifndef elf_backend_static_tls_alignment
#define elf_backend_static_tls_alignment 1
#endif
@@ -838,6 +844,8 @@ static struct elf_backend_data elfNN_bed =
elf_backend_obj_attrs_section_type,
elf_backend_obj_attrs_order,
elf_backend_obj_attrs_handle_unknown,
+ elf_backend_parse_gnu_properties,
+ elf_backend_merge_gnu_properties,
elf_backend_compact_eh_encoding,
elf_backend_cant_unwind_opcode,
elf_backend_static_tls_alignment,
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index d4837d0..1bd1265 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1258,6 +1258,8 @@ gld${EMULATION_NAME}_after_open (void)
}
}
+ _bfd_elf_link_setup_gnu_properties (&link_info);
+
if (bfd_link_relocatable (&link_info))
{
if (link_info.execstack == ! link_info.noexecstack)
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index c489227..2f6fe76 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -736,6 +736,158 @@ if { [isnative]
{{objdump {-dw} pr19319.dd}} \
"pr19319" \
] \
+ [list \
+ "Build property 1" \
+ "" \
+ "" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1" \
+ ] \
+ [list \
+ "Build property 1 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1.o" \
+ ] \
+ [list \
+ "Build property 1 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1.so" \
+ ] \
+ [list \
+ "Build property 2" \
+ "" \
+ "" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2" \
+ ] \
+ [list \
+ "Build property 2 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2.o" \
+ ] \
+ [list \
+ "Build property 2 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2.so" \
+ ] \
+ [list \
+ "Build property 3" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3" \
+ ] \
+ [list \
+ "Build property 3 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3.o" \
+ ] \
+ [list \
+ "Build property 3 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3.so" \
+ ] \
+ [list \
+ "Build property 4" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4" \
+ ] \
+ [list \
+ "Build property 4 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4.o" \
+ ] \
+ [list \
+ "Build property 4 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4.so" \
+ ] \
+ [list \
+ "Build property 4 (-Wl,-z,stack-size=0)" \
+ "-Wl,-z,stack-size=0" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4" \
+ ] \
+ [list \
+ "Build property 5" \
+ "-Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5" \
+ ] \
+ [list \
+ "Build property 5 (.o)" \
+ "-r -nostdlib -Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5.o" \
+ ] \
+ [list \
+ "Build property 5 (.so)" \
+ "-shared -Wl,-z,stack-size=0x900000" \
+ "-fPIC" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5.so" \
+ ] \
+ [list \
+ "Build property-6.so" \
+ "-shared" \
+ "-fPIC" \
+ {property-6a.c property-6c.S} \
+ {{readelf {-n} property-6.r}} \
+ "property-6.so" \
+ ] \
+ [list \
+ "Build property-6.o" \
+ "-r -nostdlib" \
+ "" \
+ {property-6b.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-6.o" \
+ ] \
+ [list \
+ "Build property-6" \
+ "-Wl,--as-needed tmpdir/property-6.o tmpdir/property-6.so" \
+ { dummy.s } \
+ "" \
+ {{readelf {-n} property-2.r}} \
+ "property-6" \
+ ] \
]
run_ld_link_exec_tests [list \
@@ -814,6 +966,111 @@ if { [isnative]
"got1" \
"got1.out" \
] \
+ [list \
+ "Run property 1" \
+ "" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "property-1" "pass.out" \
+ ] \
+ [list \
+ "Run property 1 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "property-1-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 1 (static)" \
+ "-static" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "roperty-1-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 2" \
+ "" \
+ "" \
+ {pass.c property-stack.S} \
+ "property-2" "pass.out" \
+ ] \
+ [list \
+ "Run property 2 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-stack.S} \
+ "property-2-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 2 (static)" \
+ "-static" \
+ "" \
+ {pass.c property-stack.S} \
+ "roperty-3-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 3" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S} \
+ "property-3" "pass.out" \
+ ] \
+ [list \
+ "Run property 3 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-x86-1.S property-stack.S} \
+ "property-3-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 3 (static)" \
+ "-static" \
+ "" \
+ {property-x86-1.S pass.c property-stack.S} \
+ "roperty-3-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 4" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ "property-4" "pass.out" \
+ ] \
+ [list \
+ "Run property 4 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ "property-4-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 4 (static)" \
+ "-static" \
+ "" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ "roperty-4-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 5" \
+ "-Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ "property-5" "pass.out" \
+ ] \
+ [list \
+ "Run property 5 (PIE)" \
+ "-pie -Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ "property-5-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 5 (static)" \
+ "-static -Wl,-z,stack-size=0x900000" \
+ "" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ "roperty-5-static" "pass.out" \
+ ] \
]
undefined_weak "" ""
diff --git a/ld/testsuite/ld-i386/pass.c b/ld/testsuite/ld-i386/pass.c
new file mode 100644
index 0000000..8fb892c
--- /dev/null
+++ b/ld/testsuite/ld-i386/pass.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main ()
+{
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-i386/property-1.r b/ld/testsuite/ld-i386/property-1.r
new file mode 100644
index 0000000..d8f08c0
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-1.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: no copy on protected
+
+#pass
diff --git a/ld/testsuite/ld-i386/property-2.r b/ld/testsuite/ld-i386/property-2.r
new file mode 100644
index 0000000..5e3d156
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-2.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+
+#pass
diff --git a/ld/testsuite/ld-i386/property-3.r b/ld/testsuite/ld-i386/property-3.r
new file mode 100644
index 0000000..0ed91f5
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-3.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ x86 ISA used: 586, SSE
+ x86 ISA needed: i486, 586
+#pass
diff --git a/ld/testsuite/ld-i386/property-4.r b/ld/testsuite/ld-i386/property-4.r
new file mode 100644
index 0000000..cb2bc15
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-4.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ x86 ISA used: i486, 586, SSE
+ x86 ISA needed: i486, 586, SSE
+#pass
diff --git a/ld/testsuite/ld-i386/property-5.r b/ld/testsuite/ld-i386/property-5.r
new file mode 100644
index 0000000..5529650
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-5.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x900000
+ x86 ISA used: i486, 586, SSE
+ x86 ISA needed: i486, 586, SSE
+#pass
diff --git a/ld/testsuite/ld-i386/property-6.r b/ld/testsuite/ld-i386/property-6.r
new file mode 100644
index 0000000..97a479f
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-6.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0xa00000
+
+#pass
diff --git a/ld/testsuite/ld-i386/property-6a.c b/ld/testsuite/ld-i386/property-6a.c
new file mode 100644
index 0000000..c7cc10b
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-6a.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+property (void)
+{
+ printf ("PASS\n");
+}
diff --git a/ld/testsuite/ld-i386/property-6b.c b/ld/testsuite/ld-i386/property-6b.c
new file mode 100644
index 0000000..5336b0e
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-6b.c
@@ -0,0 +1,8 @@
+extern void property (void);
+
+int
+main ()
+{
+ property ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-i386/property-6c.S b/ld/testsuite/ld-i386/property-6c.S
new file mode 100644
index 0000000..13f729d
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-6c.S
@@ -0,0 +1,18 @@
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0xa00000 /* Stack size. */
+5:
+ .p2align 2
+3:
diff --git a/ld/testsuite/ld-i386/property-no-copy.S b/ld/testsuite/ld-i386/property-no-copy.S
new file mode 100644
index 0000000..3116911
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-no-copy.S
@@ -0,0 +1,15 @@
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align 2
+3:
diff --git a/ld/testsuite/ld-i386/property-stack.S b/ld/testsuite/ld-i386/property-stack.S
new file mode 100644
index 0000000..5e9bcce
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-stack.S
@@ -0,0 +1,18 @@
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0x800000 /* Stack size. */
+5:
+ .p2align 2
+3:
diff --git a/ld/testsuite/ld-i386/property-x86-1.S b/ld/testsuite/ld-i386/property-x86-1.S
new file mode 100644
index 0000000..953ca87
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-x86-1.S
@@ -0,0 +1,32 @@
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0x600000 /* Stack size. */
+5:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0xa
+5:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0x3
+5:
+ .p2align 2
+3:
diff --git a/ld/testsuite/ld-i386/property-x86-2.S b/ld/testsuite/ld-i386/property-x86-2.S
new file mode 100644
index 0000000..f11e1fe
--- /dev/null
+++ b/ld/testsuite/ld-i386/property-x86-2.S
@@ -0,0 +1,25 @@
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0x3
+5:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0xa
+5:
+ .p2align 2
+3:
diff --git a/ld/testsuite/ld-x86-64/pass.c b/ld/testsuite/ld-x86-64/pass.c
new file mode 100644
index 0000000..8fb892c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pass.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main ()
+{
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-x86-64/property-1.r b/ld/testsuite/ld-x86-64/property-1.r
new file mode 100644
index 0000000..d8f08c0
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-1.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: no copy on protected
+
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-2.r b/ld/testsuite/ld-x86-64/property-2.r
new file mode 100644
index 0000000..5e3d156
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-2.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-3.r b/ld/testsuite/ld-x86-64/property-3.r
new file mode 100644
index 0000000..0ed91f5
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-3.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ x86 ISA used: 586, SSE
+ x86 ISA needed: i486, 586
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-4.r b/ld/testsuite/ld-x86-64/property-4.r
new file mode 100644
index 0000000..cb2bc15
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-4.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ x86 ISA used: i486, 586, SSE
+ x86 ISA needed: i486, 586, SSE
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-5.r b/ld/testsuite/ld-x86-64/property-5.r
new file mode 100644
index 0000000..5529650
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-5.r
@@ -0,0 +1,8 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x900000
+ x86 ISA used: i486, 586, SSE
+ x86 ISA needed: i486, 586, SSE
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-6.r b/ld/testsuite/ld-x86-64/property-6.r
new file mode 100644
index 0000000..97a479f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-6.r
@@ -0,0 +1,7 @@
+#...
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0xa00000
+
+#pass
diff --git a/ld/testsuite/ld-x86-64/property-6a.c b/ld/testsuite/ld-x86-64/property-6a.c
new file mode 100644
index 0000000..c7cc10b
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-6a.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+property (void)
+{
+ printf ("PASS\n");
+}
diff --git a/ld/testsuite/ld-x86-64/property-6b.c b/ld/testsuite/ld-x86-64/property-6b.c
new file mode 100644
index 0000000..5336b0e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-6b.c
@@ -0,0 +1,8 @@
+extern void property (void);
+
+int
+main ()
+{
+ property ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-x86-64/property-6c.S b/ld/testsuite/ld-x86-64/property-6c.S
new file mode 100644
index 0000000..fbe4713
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-6c.S
@@ -0,0 +1,23 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+ .section ".note.gnu.property", "a"
+ .p2align ALIGN
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0xa00000 /* Stack size. */
+5:
+ .p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-x86-64/property-no-copy.S b/ld/testsuite/ld-x86-64/property-no-copy.S
new file mode 100644
index 0000000..1b62f78
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-no-copy.S
@@ -0,0 +1,20 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+ .section ".note.gnu.property", "a"
+ .p2align ALIGN
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-x86-64/property-stack.S b/ld/testsuite/ld-x86-64/property-stack.S
new file mode 100644
index 0000000..ccf7820
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-stack.S
@@ -0,0 +1,23 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+ .section ".note.gnu.property", "a"
+ .p2align ALIGN
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0x800000 /* Stack size. */
+5:
+ .p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-x86-64/property-x86-1.S b/ld/testsuite/ld-x86-64/property-x86-1.S
new file mode 100644
index 0000000..d2c1ff7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-x86-1.S
@@ -0,0 +1,37 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+ .section ".note.gnu.property", "a"
+ .p2align ALIGN
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .dc.a 0x600000 /* Stack size. */
+5:
+ .p2align ALIGN
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0xa
+5:
+ .p2align ALIGN
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0x3
+5:
+ .p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-x86-64/property-x86-2.S b/ld/testsuite/ld-x86-64/property-x86-2.S
new file mode 100644
index 0000000..a2f1b7a
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/property-x86-2.S
@@ -0,0 +1,30 @@
+#ifdef __LP64__
+# define ALIGN 3
+#else
+# define ALIGN 2
+#endif
+ .section ".note.gnu.property", "a"
+ .p2align ALIGN
+ .long 1f - 0f /* name length. */
+ .long 3f - 1f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0:
+ .asciz "GNU" /* vendor name. */
+1:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0x3
+5:
+ .p2align ALIGN
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 5f - 4f /* pr_datasz. */
+4:
+ .long 0xa
+5:
+ .p2align ALIGN
+3:
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 8e4e422..070a2c2 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -828,6 +828,158 @@ if { [isnative] && [which $CC] != 0 } {
{{objdump {-dw} pr19319.dd}} \
"pr19319" \
] \
+ [list \
+ "Build property 1" \
+ "" \
+ "" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1" \
+ ] \
+ [list \
+ "Build property 1 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1.o" \
+ ] \
+ [list \
+ "Build property 1 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {pass.c property-no-copy.S} \
+ {{readelf {-n} property-1.r}} \
+ "property-1.so" \
+ ] \
+ [list \
+ "Build property 2" \
+ "" \
+ "" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2" \
+ ] \
+ [list \
+ "Build property 2 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2.o" \
+ ] \
+ [list \
+ "Build property 2 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {pass.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-2.so" \
+ ] \
+ [list \
+ "Build property 3" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3" \
+ ] \
+ [list \
+ "Build property 3 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3.o" \
+ ] \
+ [list \
+ "Build property 3 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-3.r}} \
+ "property-3.so" \
+ ] \
+ [list \
+ "Build property 4" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4" \
+ ] \
+ [list \
+ "Build property 4 (.o)" \
+ "-r -nostdlib" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4.o" \
+ ] \
+ [list \
+ "Build property 4 (.so)" \
+ "-shared" \
+ "-fPIC" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4.so" \
+ ] \
+ [list \
+ "Build property 4 (-Wl,-z,stack-size=0)" \
+ "-Wl,-z,stack-size=0" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-4.r}} \
+ "property-4" \
+ ] \
+ [list \
+ "Build property 5" \
+ "-Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5" \
+ ] \
+ [list \
+ "Build property 5 (.o)" \
+ "-r -nostdlib -Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5.o" \
+ ] \
+ [list \
+ "Build property 5 (.so)" \
+ "-shared -Wl,-z,stack-size=0x900000" \
+ "-fPIC" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ {{readelf {-n} property-5.r}} \
+ "property-5.so" \
+ ] \
+ [list \
+ "Build property-6.so" \
+ "-shared" \
+ "-fPIC" \
+ {property-6a.c property-6c.S} \
+ {{readelf {-n} property-6.r}} \
+ "property-6.so" \
+ ] \
+ [list \
+ "Build property-6.o" \
+ "-r -nostdlib" \
+ "" \
+ {property-6b.c property-stack.S} \
+ {{readelf {-n} property-2.r}} \
+ "property-6.o" \
+ ] \
+ [list \
+ "Build property-6" \
+ "-Wl,--as-needed tmpdir/property-6.o tmpdir/property-6.so" \
+ { dummy.s } \
+ "" \
+ {{readelf {-n} property-2.r}} \
+ "property-6" \
+ ] \
]
run_ld_link_exec_tests [list \
@@ -898,6 +1050,111 @@ if { [isnative] && [which $CC] != 0 } {
"gotpcrel1" \
"gotpcrel1.out" \
] \
+ [list \
+ "Run property 1" \
+ "" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "property-1" "pass.out" \
+ ] \
+ [list \
+ "Run property 1 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "property-1-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 1 (static)" \
+ "-static" \
+ "" \
+ {pass.c property-no-copy.S} \
+ "roperty-1-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 2" \
+ "" \
+ "" \
+ {pass.c property-stack.S} \
+ "property-2" "pass.out" \
+ ] \
+ [list \
+ "Run property 2 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-stack.S} \
+ "property-2-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 2 (static)" \
+ "-static" \
+ "" \
+ {pass.c property-stack.S} \
+ "roperty-3-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 3" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S} \
+ "property-3" "pass.out" \
+ ] \
+ [list \
+ "Run property 3 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-x86-1.S property-stack.S} \
+ "property-3-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 3 (static)" \
+ "-static" \
+ "" \
+ {property-x86-1.S pass.c property-stack.S} \
+ "roperty-3-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 4" \
+ "" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ "property-4" "pass.out" \
+ ] \
+ [list \
+ "Run property 4 (PIE)" \
+ "-pie" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ "property-4-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 4 (static)" \
+ "-static" \
+ "" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ "roperty-4-static" "pass.out" \
+ ] \
+ [list \
+ "Run property 5" \
+ "-Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-stack.S property-x86-1.S property-x86-2.S} \
+ "property-5" "pass.out" \
+ ] \
+ [list \
+ "Run property 5 (PIE)" \
+ "-pie -Wl,-z,stack-size=0x900000" \
+ "" \
+ {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ "property-5-pie" "pass.out" "-fPIE" \
+ ] \
+ [list \
+ "Run property 5 (static)" \
+ "-static -Wl,-z,stack-size=0x900000" \
+ "" \
+ {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
+ "roperty-5-static" "pass.out" \
+ ] \
]
# Run-time tests which require working ifunc attribute support.
--
2.9.3