From 0a59decbb81676ac30deede1bb6b6e241cd75502 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 14 Dec 2018 04:55:08 -0800 Subject: elf: Add PT_GNU_PROPERTY segment type Linkers group input note sections with the same name into one output note section with the same name. One output note section is placed in one PT_NOTE segment. New linkers merge all input .note.gnu.property sections into one output .note.gnu.property section with a single NT_GNU_PROPERTY_TYPE_0 note in a single PT_NOTE segment. Since older linkers treat input .note.gnu.property section as a generic note section and just concatenate all input .note.gnu.property sections into one output .note.gnu.property section without merging them, we may see one or more NT_GNU_PROPERTY_TYPE_0 notes in PT_NOTE segment, which are invalid. GNU_PROPERTY_X86_UINT32_VALID was defined to address this issue such that linker sets the bit for non-relocatable outputs. But it isn't sufficient: 1. It doesn't cover generic properties. 2. When -mx86-used-note=yes is passed to x86 assembler, the GNU_PROPERTY_X86_UINT32_VALID bit is set in GNU_PROPERTY_X86_ISA_1_USED property in object file and older linkers generate invalid NT_GNU_PROPERTY_TYPE_0 notes with the GNU_PROPERTY_X86_UINT32_VALID bit set. I am proposing the following changes: 1. Add PT_GNU_PROPERTY segment type: # define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) which covers .note.gnu.property section. 2. Remove GNU_PROPERTY_X86_UINT32_VALID. bfd/ PR ld/23900 * elf.c (get_program_header_size): Add a PT_GNU_PROPERTY segment for NOTE_GNU_PROPERTY_SECTION_NAME. (_bfd_elf_map_sections_to_segments): Create a PT_GNU_PROPERTY segment for NOTE_GNU_PROPERTY_SECTION_NAME. * elfxx-x86.c (_bfd_elf_link_setup_gnu_properties): Don't set GNU_PROPERTY_X86_UINT32_VALID. binutils/ PR ld/23900 * readelf.c (get_segment_type): Support PT_GNU_PROPERTY. (decode_x86_isa): Don't check GNU_PROPERTY_X86_UINT32_VALID. (decode_x86_feature_1): Likewise. (decode_x86_feature_2): Likewise. (print_gnu_property_note): Remove GNU_PROPERTY_X86_UINT32_VALID check. * testsuite/binutils-all/i386/empty.d: Updated. * testsuite/binutils-all/x86-64/empty-x32.d: Likewise. * testsuite/binutils-all/x86-64/empty.d: Likewise. * testsuite/binutils-all/i386/pr21231b.s: Change GNU_PROPERTY_X86_ISA_1_USED bits to 0x7fffffff. * testsuite/binutils-all/x86-64/pr21231b.s: Likewise. gas/ PR ld/23900 * config/tc-i386.c (x86_cleanup): Don't set GNU_PROPERTY_X86_UINT32_VALID. * testsuite/gas/i386/property-1.s: Change GNU_PROPERTY_X86_ISA_1_USED bits to 0. include/ PR ld/23900 * elf/common.h (PT_GNU_PROPERTY): New. (GNU_PROPERTY_X86_UINT32_VALID): Removed. ld/ PR ld/23900 * testsuite/ld-elf/elf.exp: Run PR ld/23900 test. * testsuite/ld-elf/pr23900-1-32.rd: New file. * testsuite/ld-elf/pr23900-1-64.rd: Likewise. * testsuite/ld-elf/pr23900-1.d: Likewise. * testsuite/ld-elf/pr23900-1.s: Likewise. * testsuite/ld-elf/pr23900-2.s: Likewise. * testsuite/ld-elf/pr23900-2a.d: Likewise. * testsuite/ld-elf/pr23900-2b.d: Likewise. * testsuite/ld-i386/ibt-plt-1.d: Adjusted. * testsuite/ld-i386/ibt-plt-2c.d: Likewise. * testsuite/ld-i386/ibt-plt-2d.d: Likewise. * testsuite/ld-i386/ibt-plt-3d.d: Likewise. * testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-1.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d.d: Likewise. * testsuite/ld-i386/pr23372c.d: Expect for GNU_PROPERTY_X86_ISA_1_USED. * testsuite/ld-x86-64/pr23372c-x32.d: Likewise. * testsuite/ld-x86-64/pr23372c.d: Likewise. * testsuite/ld-x86-64/pr23372d-x32.d: Likewise. * testsuite/ld-x86-64/pr23372d.d: Likewise. * testsuite/ld-x86-64/property-x86-5a.s: Change GNU_PROPERTY_X86_ISA_1_USED bits to 0. * testsuite/ld-x86-64/property-x86-5b.s: Likewise. --- binutils/ChangeLog | 16 ++++++++++++++++ binutils/readelf.c | 21 +++++---------------- binutils/testsuite/binutils-all/i386/empty.d | 2 +- binutils/testsuite/binutils-all/i386/pr21231b.s | 2 +- binutils/testsuite/binutils-all/x86-64/empty-x32.d | 2 +- binutils/testsuite/binutils-all/x86-64/empty.d | 2 +- binutils/testsuite/binutils-all/x86-64/pr21231b.s | 2 +- 7 files changed, 26 insertions(+), 21 deletions(-) (limited to 'binutils') diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 12d4802..3a251e9 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,19 @@ +2018-12-14 H.J. Lu + + PR ld/23900 + * readelf.c (get_segment_type): Support PT_GNU_PROPERTY. + (decode_x86_isa): Don't check GNU_PROPERTY_X86_UINT32_VALID. + (decode_x86_feature_1): Likewise. + (decode_x86_feature_2): Likewise. + (print_gnu_property_note): Remove GNU_PROPERTY_X86_UINT32_VALID + check. + * testsuite/binutils-all/i386/empty.d: Updated. + * testsuite/binutils-all/x86-64/empty-x32.d: Likewise. + * testsuite/binutils-all/x86-64/empty.d: Likewise. + * testsuite/binutils-all/i386/pr21231b.s: Change + GNU_PROPERTY_X86_ISA_1_USED bits to 0x7fffffff. + * testsuite/binutils-all/x86-64/pr21231b.s: Likewise. + 2018-12-13 Sam Tebbs * dwarf.c (read_cie): Add check for 'B'. diff --git a/binutils/readelf.c b/binutils/readelf.c index 9969e46..dd84a19 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -3930,6 +3930,7 @@ get_segment_type (Filedata * filedata, unsigned long p_type) case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; case PT_GNU_STACK: return "GNU_STACK"; case PT_GNU_RELRO: return "GNU_RELRO"; + case PT_GNU_PROPERTY: return "GNU_PROPERTY"; default: if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) @@ -17048,13 +17049,11 @@ decode_x86_compat_isa (unsigned int bitmask) static void decode_x86_isa (unsigned int bitmask) { - if (bitmask == GNU_PROPERTY_X86_UINT32_VALID) + if (!bitmask) { printf (_("")); return; } - else - bitmask &= ~GNU_PROPERTY_X86_UINT32_VALID; while (bitmask) { @@ -17147,13 +17146,11 @@ decode_x86_isa (unsigned int bitmask) static void decode_x86_feature_1 (unsigned int bitmask) { - if (bitmask == GNU_PROPERTY_X86_UINT32_VALID) + if (!bitmask) { printf (_("")); return; } - else - bitmask &= ~GNU_PROPERTY_X86_UINT32_VALID; while (bitmask) { @@ -17180,13 +17177,11 @@ decode_x86_feature_1 (unsigned int bitmask) static void decode_x86_feature_2 (unsigned int bitmask) { - if (bitmask == GNU_PROPERTY_X86_UINT32_VALID) + if (!bitmask) { printf (_("")); return; } - else - bitmask &= ~GNU_PROPERTY_X86_UINT32_VALID; while (bitmask) { @@ -17282,13 +17277,7 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) unsigned int bitmask; if (datasz == 4) - { - bitmask = byte_get (ptr, 4); - if ((filedata->file_header.e_type == ET_EXEC - || filedata->file_header.e_type == ET_DYN) - && !(bitmask & GNU_PROPERTY_X86_UINT32_VALID)) - printf ("Invalid "); - } + bitmask = byte_get (ptr, 4); else bitmask = 0; diff --git a/binutils/testsuite/binutils-all/i386/empty.d b/binutils/testsuite/binutils-all/i386/empty.d index 809280f..3c0e860 100644 --- a/binutils/testsuite/binutils-all/i386/empty.d +++ b/binutils/testsuite/binutils-all/i386/empty.d @@ -6,7 +6,7 @@ Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x0000000c NT_GNU_PROPERTY_TYPE_0 - Properties: x86 feature: + Properties: x86 feature: GNU 0x00000018 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA used: x86 feature used: x86 diff --git a/binutils/testsuite/binutils-all/i386/pr21231b.s b/binutils/testsuite/binutils-all/i386/pr21231b.s index 793e282..1fd2575 100644 --- a/binutils/testsuite/binutils-all/i386/pr21231b.s +++ b/binutils/testsuite/binutils-all/i386/pr21231b.s @@ -22,7 +22,7 @@ .long 0xc0010000 /* pr_type. */ .long 4f - 3f /* pr_datasz. */ 3: - .long -1 + .long 0x7fffffff 4: .p2align 2 /* GNU_PROPERTY_X86_ISA_1_NEEDED */ diff --git a/binutils/testsuite/binutils-all/x86-64/empty-x32.d b/binutils/testsuite/binutils-all/x86-64/empty-x32.d index f650374..32cc55e 100644 --- a/binutils/testsuite/binutils-all/x86-64/empty-x32.d +++ b/binutils/testsuite/binutils-all/x86-64/empty-x32.d @@ -7,7 +7,7 @@ Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x0000000c NT_GNU_PROPERTY_TYPE_0 - Properties: x86 feature: + Properties: x86 feature: GNU 0x00000018 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA used: x86 feature used: x86 diff --git a/binutils/testsuite/binutils-all/x86-64/empty.d b/binutils/testsuite/binutils-all/x86-64/empty.d index 30a2ea4..3cc52ba 100644 --- a/binutils/testsuite/binutils-all/x86-64/empty.d +++ b/binutils/testsuite/binutils-all/x86-64/empty.d @@ -6,7 +6,7 @@ Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 - Properties: x86 feature: + Properties: x86 feature: GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA used: x86 feature used: x86 diff --git a/binutils/testsuite/binutils-all/x86-64/pr21231b.s b/binutils/testsuite/binutils-all/x86-64/pr21231b.s index add9227..8fefebd 100644 --- a/binutils/testsuite/binutils-all/x86-64/pr21231b.s +++ b/binutils/testsuite/binutils-all/x86-64/pr21231b.s @@ -22,7 +22,7 @@ .long 0xc0010000 /* pr_type. */ .long 4f - 3f /* pr_datasz. */ 3: - .long -1 + .long 0x7fffffff 4: .p2align 3 /* GNU_PROPERTY_X86_ISA_1_NEEDED */ -- cgit v1.1