This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] x86: Don't add GNU_PROPERTY_X86_FEATURE_2_NEEDED for -z separate-code
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 8 Oct 2018 05:12:56 -0700
- Subject: [PATCH] x86: Don't add GNU_PROPERTY_X86_FEATURE_2_NEEDED for -z separate-code
On Mon, Oct 08, 2018 at 08:32:46PM +1030, Alan Modra wrote:
> This patch, along with previous patches in the series, supports
> putting the ELF file header and program headers in a PT_LOAD without
> sections.
>
> Logic governing whether headers a loaded has changed a little: The
> primary reason to include headers is now the presence of
> SIZEOF_HEADERS in a linker script. However, to support scripts that
> may have reserved space for headers by hand, we continue to add
> headers whenever the first section address is past the end of headers
> modulo page size.
>
> include/
> * bfdlink.h (struct bfd_link_info): Add load_phdrs field.
> bfd/
> * elf-nacl.c (nacl_modify_segment_map): Cope with header PT_LOAD
> lacking sections.
> * elf.c (_bfd_elf_map_sections_to_segments): Assume file and
> program headers are required when info->load_phdrs. Reorganize
> code handling program headers. Generate a mapping without
> sections just for file and program headers when -z separate-code
> would indicate they should be on a different page to the first
> section.
> ld/
> * ldexp.c (fold_name <SIZEOF_HEADERS>): Set link_info.load_phdrs.
> * testsuite/ld-elf/loadaddr1.d: Pass -z noseparate-code.
> * testsuite/ld-elf/loadaddr2.d: Likewise.
> * testsuite/ld-i386/vxworks2.sd: Adjust expected output.
> * testsuite/ld-powerpc/vxworks2.sd: Likewise.
> * testsuite/ld-elf/overlay.d: Remove spu xfail.
> * testsuite/ld-spu/ovl.lnk: Don't use SIZEOF_HEADERS.
> * testsuite/ld-tic6x/dsbt-be.ld: Likewise.
> * testsuite/ld-tic6x/dsbt-inrange.ld: Likewise.
> * testsuite/ld-tic6x/dsbt-overflow.ld: Likewise.
> * testsuite/ld-tic6x/dsbt.ld: Likewise.
>
I am checking in this patch to skip GNU_PROPERTY_X86_FEATURE_2_NEEDED
for -z separate-code.
Thanks.
H.J.
---
With
commit 64029e93683a266c38d19789e780f3748bd6a188
Author: Alan Modra <amodra@gmail.com>
Date: Fri Oct 5 11:40:54 2018 +0930
Separate header PT_LOAD for -z separate-code
there is no need to add a GNU_PROPERTY_X86_ISA_1_USED note to force
program header in in non-code PT_LOAD segment when -z separate-code
is used.
bfd/
PR ld/23428
* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't
add GNU_PROPERTY_X86_FEATURE_2_NEEDED to force program header
in non-code PT_LOAD segment.
ld/
PR ld/23428
* testsuite/ld-i386/property-x86-4a.d: Updated.
* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
---
bfd/elfxx-x86.c | 45 --------------------
ld/testsuite/ld-i386/property-x86-4a.d | 3 +-
ld/testsuite/ld-x86-64/property-x86-4a-x32.d | 3 +-
ld/testsuite/ld-x86-64/property-x86-4a.d | 3 +-
4 files changed, 3 insertions(+), 51 deletions(-)
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index fc99b28c07..05f5c6a2f9 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2542,7 +2542,6 @@ _bfd_x86_elf_link_setup_gnu_properties
const struct elf_backend_data *bed;
unsigned int class_align = ABI_64_P (info->output_bfd) ? 3 : 2;
unsigned int got_align;
- bfd_boolean has_text = FALSE;
features = 0;
if (info->ibt)
@@ -2557,14 +2556,6 @@ _bfd_x86_elf_link_setup_gnu_properties
if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
&& bfd_count_sections (pbfd) != 0)
{
- if (!has_text)
- {
- /* Check if there is no non-empty text section. */
- sec = bfd_get_section_by_name (pbfd, ".text");
- if (sec != NULL && sec->size != 0)
- has_text = TRUE;
- }
-
ebfd = pbfd;
if (elf_properties (pbfd) != NULL)
@@ -2590,42 +2581,6 @@ _bfd_x86_elf_link_setup_gnu_properties
prop->u.number |= features;
prop->pr_kind = property_number;
}
- else if (has_text
- && elf_tdata (info->output_bfd)->o->build_id.sec == NULL
- && !htab->elf.dynamic_sections_created
- && !info->traditional_format
- && (info->output_bfd->flags & D_PAGED) != 0
- && info->separate_code)
- {
- /* If the separate code program header is needed, make sure
- that the first read-only PT_LOAD segment has no code by
- adding a GNU_PROPERTY_X86_FEATURE_2_NEEDED note. */
- elf_property_list *list;
- bfd_boolean need_property = TRUE;
-
- for (list = elf_properties (ebfd); list; list = list->next)
- {
- unsigned int pr_type = list->property.pr_type;
- if (pr_type == GNU_PROPERTY_STACK_SIZE
- || pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED
- || pr_type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
- || (pr_type >= GNU_PROPERTY_X86_UINT32_OR_LO
- && pr_type <= GNU_PROPERTY_X86_UINT32_OR_HI))
- {
- /* These properties won't be removed during merging. */
- need_property = FALSE;
- break;
- }
- }
-
- if (need_property)
- {
- prop = _bfd_elf_get_property
- (ebfd, GNU_PROPERTY_X86_FEATURE_2_NEEDED, 4);
- prop->u.number = GNU_PROPERTY_X86_FEATURE_2_X86;
- prop->pr_kind = property_number;
- }
- }
/* Create the GNU property note section if needed. */
if (prop != NULL && pbfd == NULL)
diff --git a/ld/testsuite/ld-i386/property-x86-4a.d b/ld/testsuite/ld-i386/property-x86-4a.d
index 8ab0115cdd..5e2b4689f8 100644
--- a/ld/testsuite/ld-i386/property-x86-4a.d
+++ b/ld/testsuite/ld-i386/property-x86-4a.d
@@ -6,8 +6,7 @@
Displaying notes found in: .note.gnu.property
Owner Data size Description
- GNU 0x0000002c NT_GNU_PROPERTY_TYPE_0
+ GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0
Properties: no copy on protected
- x86 feature needed: x86
x86 ISA used: <None>
x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/property-x86-4a-x32.d b/ld/testsuite/ld-x86-64/property-x86-4a-x32.d
index 9dd6e3540e..76f74e5ded 100644
--- a/ld/testsuite/ld-x86-64/property-x86-4a-x32.d
+++ b/ld/testsuite/ld-x86-64/property-x86-4a-x32.d
@@ -6,8 +6,7 @@
Displaying notes found in: .note.gnu.property
Owner Data size Description
- GNU 0x0000002c NT_GNU_PROPERTY_TYPE_0
+ GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0
Properties: no copy on protected
- x86 feature needed: x86
x86 ISA used: <None>
x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/property-x86-4a.d b/ld/testsuite/ld-x86-64/property-x86-4a.d
index 4dc87acd56..e76be796a6 100644
--- a/ld/testsuite/ld-x86-64/property-x86-4a.d
+++ b/ld/testsuite/ld-x86-64/property-x86-4a.d
@@ -6,8 +6,7 @@
Displaying notes found in: .note.gnu.property
Owner Data size Description
- GNU 0x00000038 NT_GNU_PROPERTY_TYPE_0
+ GNU 0x00000028 NT_GNU_PROPERTY_TYPE_0
Properties: no copy on protected
- x86 feature needed: x86
x86 ISA used: <None>
x86 feature used: x86
--
2.17.1