Bug 21231 - readelf fails to dump NT_GNU_PROPERTY_TYPE_0 note
Summary: readelf fails to dump NT_GNU_PROPERTY_TYPE_0 note
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: 2.29
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-07 19:10 UTC by H.J. Lu
Modified: 2017-03-08 15:48 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-03-07 19:10:53 UTC
[hjl@gnu-6 property-1]$ cat i.S
#ifndef NT_GNU_PROPERTY_TYPE_0
# define NT_GNU_PROPERTY_TYPE_0 5
#endif

#ifndef GNU_PROPERTY_STACK_SIZE
# define GNU_PROPERTY_STACK_SIZE 1
#endif

#ifndef GNU_PROPERTY_NO_COPY_ON_PROTECTED
# define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
#endif

#ifndef GNU_PROPERTY_X86_ISA_1_USED
# define GNU_PROPERTY_X86_ISA_1_USED 0xc0000000
#endif

#ifndef GNU_PROPERTY_X86_ISA_1_NEEDED
# define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0000001
#endif

	.section ".note.gnu.property", "a"
#if __SIZEOF_PTRDIFF_T__  == 8
	.p2align 3
#elif __SIZEOF_PTRDIFF_T__  == 4
	.p2align 2
#else
# error Unsupported pointer size!
#endif

	.long 1f - 0f		/* name length */
	.long 4f - 2f		/* data length */
	.long NT_GNU_PROPERTY_TYPE_0	/* note type */
0:	.asciz "GNU"		/* vendor name */
1:	.p2align 2
2:	.long GNU_PROPERTY_STACK_SIZE	/* pr_type.  */
	.long 9f - 3f	/* pr_datasz.  */
3:
	.dc.a 0x800000	/* Stack size.  */
9:
#if __SIZEOF_PTRDIFF_T__  == 8
	.p2align 3
#elif __SIZEOF_PTRDIFF_T__  == 4
	.p2align 2
#endif
	.long GNU_PROPERTY_NO_COPY_ON_PROTECTED	/* pr_type.  */
	.long 0	/* pr_datasz.  */
#if __SIZEOF_PTRDIFF_T__  == 8
	.p2align 3
#elif __SIZEOF_PTRDIFF_T__  == 4
	.p2align 2
#endif
	.long GNU_PROPERTY_X86_ISA_1_USED /* pr_type.  */
	.long 9f - 8f	/* pr_datasz.  */
8:
	.long -1
9:
#if __SIZEOF_PTRDIFF_T__  == 8
	.p2align 3
#elif __SIZEOF_PTRDIFF_T__  == 4
	.p2align 2
#endif
	.long GNU_PROPERTY_X86_ISA_1_NEEDED /* pr_type.  */
	.long 9f - 8f	/* pr_datasz.  */
8:
	.long 0xffff
9:
#if __SIZEOF_PTRDIFF_T__  == 8
	.p2align 3
#elif __SIZEOF_PTRDIFF_T__  == 4
	.p2align 2
#endif
4:
[hjl@gnu-6 property-1]$ make i.o
gcc -B./  -c -o i.o i.S
[hjl@gnu-6 property-1]$ ./readelf -n i.o

Displaying notes found in: .note.gnu.property
  Owner                 Data size	Description
  GNU                  0x00000038	NT_GNU_PROPERTY_TYPE_0
      Properties: <unknown type 0x800000001 data: corrupt datasz: 0x800000>

[hjl@gnu-6 property-1]$
Comment 1 cvs-commit@gcc.gnu.org 2017-03-08 15:45:17 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1fc87489b40b3100badf184a7c266387bae47def

commit 1fc87489b40b3100badf184a7c266387bae47def
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Mar 8 07:44:04 2017 -0800

    Properly dump NT_GNU_PROPERTY_TYPE_0
    
    Property type and datasz are always 4 bytes for both 32-bit and 64-bit
    objects.  Property values for GNU_PROPERTY_X86_ISA_1_USED and
    GNU_PROPERTY_X86_ISA_1_NEEDED are 4 bytes for both i386 and x86-64
    objects.  We should also check GNU_PROPERTY_LOPROC and
    GNU_PROPERTY_LOUSER.
    
    binutils/
    
    	PR binutils/21231
    	* readelf.c (decode_x86_isa): Change argument to unsigned int.
    	(print_gnu_property_note): Retrieve property type and datasz as
    	4-byte integer.  Consolidate property datasz check.  Check
    	GNU_PROPERTY_LOPROC and GNU_PROPERTY_LOUSER.
    	* testsuite/binutils-all/i386/pr21231a.d: New file.
    	* testsuite/binutils-all/i386/pr21231a.s: Likewise.
    	* testsuite/binutils-all/i386/pr21231b.d: Likewise.
    	* testsuite/binutils-all/i386/pr21231b.s: Likewise.
    	* testsuite/binutils-all/x86-64/pr21231a.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr21231a.s: Likewise.
    	* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr21231b.s: Likewise.
    
    include/
    
    	PR binutils/21231
    	* elf/common.h (GNU_PROPERTY_LOPROC): New.
    	(GNU_PROPERTY_HIPROC): Likewise.
    	(GNU_PROPERTY_LOUSER): Likewise.
    	(GNU_PROPERTY_HIUSER): Likewise.
Comment 2 H.J. Lu 2017-03-08 15:48:35 UTC
Fixed.