Bug 23494 - .note.gnu.property section isn't properly converted
Summary: .note.gnu.property section isn't properly converted
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: 2.32
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-08 13:00 UTC by H.J. Lu
Modified: 2018-11-09 13:57 UTC (History)
0 users

See Also:
Host:
Target: x86-64
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 2018-08-08 13:00:38 UTC
[hjl@gnu-tools-1 tmp]$ cat x.s
	.section ".note.gnu.property", "a"
	.p2align 3
	.long 1f - 0f		/* name length.  */
	.long 4f - 1f		/* data length.  */
	/* NT_GNU_PROPERTY_TYPE_0 */
	.long 5			/* note type.  */
0:
	.asciz "GNU"		/* vendor name.  */
1:
	.p2align 3
	/* GNU_PROPERTY_X86_ISA_1_NEEDED */
	.long 0xc0000001	/* pr_type.  */
	.long 3f - 2f		/* pr_datasz.  */
2:
	.long 0x3
3:
	.p2align 3
4:
[hjl@gnu-tools-1 tmp]$ gcc -c x.s
[hjl@gnu-tools-1 tmp]$ objcopy -O elf32-x86-64 x.o x32.o
[hjl@gnu-tools-1 tmp]$ ld -shared -melf32_x86_64 x32.o
ld: warning: x32.o: corrupt GNU_PROPERTY_TYPE (5) size: 0x10
[hjl@gnu-tools-1 tmp]$
Comment 1 Sourceware Commits 2018-08-09 04:01:27 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=6404ab993797d1d6cd3d9e97cc281e3cb6226c12

commit 6404ab993797d1d6cd3d9e97cc281e3cb6226c12
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Aug 8 21:00:04 2018 -0700

    Convert .note.gnu.property section between ELF32 and ELF64
    
    .note.gnu.property section has different alignments and section
    sizes for 32-bit and 64-bit ELF binaries.  This patch updated
    bfd_convert_section_size and bfd_convert_section_contents to
    properly convert .note.gnu.property section between 32-bit and
    64-bit ELF binaries.
    
    bfd/
    
    	PR binutils/23494
    	* bfd.c (bfd_convert_section_size): Check BFD_DECOMPRESS after
    	calling _bfd_elf_convert_gnu_property_size to convert
    	.note.gnu.property section size.
    	(bfd_convert_section_contents): Check BFD_DECOMPRESS after
    	calling _bfd_elf_convert_gnu_properties to convert
    	.note.gnu.property section.
    	* elf-bfd.h (_bfd_elf_convert_gnu_property_size): New prototype.
    	(_bfd_elf_convert_gnu_properties): Likewise.
    	* elf-properties.c (elf_get_gnu_property_section_size): New
    	function.
    	(elf_write_gnu_properties): Likewise.
    	(_bfd_elf_convert_gnu_property_size): Likewise.
    	(_bfd_elf_convert_gnu_properties): Likewise.
    	(_bfd_elf_link_setup_gnu_properties): Use
    	elf_get_gnu_property_section_size and elf_write_gnu_properties.
    
    binutils/
    
    	PR binutils/23494
    	* testsuite/binutils-all/x86-64/pr23494a-x32.d: New file.
    	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494a.s: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494b-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494b.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494b.s: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
Comment 2 Sourceware Commits 2018-08-10 14:56:48 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=11459a79d97842a64961a35472bb8d67ed0fcf22

commit 11459a79d97842a64961a35472bb8d67ed0fcf22
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Aug 10 07:53:50 2018 -0700

    Skip PR binutils/23494 tests for nacl targets
    
    PR binutils/23494 tests pass "-O elf64-x86-64" and "-O elf32-x86-64"
    to objcopy which may not supported for nacl targets.  This patch skips
    these tests for nacl targets.
    
    	* testsuite/binutils-all/x86-64/pr23494a-x32.d: Skip nacl
    	targets.
    	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494b-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494b.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
Comment 3 Sourceware Commits 2018-08-10 15:38:27 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=9c973a29df61c411e24ce51b13401333c6f6e0e7

commit 9c973a29df61c411e24ce51b13401333c6f6e0e7
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Aug 9 04:29:43 2018 -0700

    Always use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE
    
    For GNU_PROPERTY_STACK_SIZE, pr_datasz is the same as align_size, which
    is 8 bytes for 64-bit ELF binaries and 4 bytes for 32-bit ELF binaries,
    Use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE to convert
    .note.gnu.property section.
    
    bfd/
    
    	PR binutils/23494
    	* elf-properties.c (elf_get_gnu_property_section_size): Always
    	use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE.
    	(elf_write_gnu_properties): Likewise.
    
    binutils/
    
    	PR binutils/23494
    	* testsuite/binutils-all/x86-64/pr23494c.s: New file.
    	* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
    	* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
Comment 4 Sourceware Commits 2018-08-13 14:38:10 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=98641896ad52915448c0dd1ab4b4bbe23148a582

commit 98641896ad52915448c0dd1ab4b4bbe23148a582
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 13 07:24:31 2018 -0700

    bfd: Move elf-properties.lo to BFD32_LIBS
    
    commit 6404ab993797d1d6cd3d9e97cc281e3cb6226c12
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Wed Aug 8 21:00:04 2018 -0700
    
        Convert .note.gnu.property section between ELF32 and ELF64
    
    updated bfd_convert_section_size and bfd_convert_section_contents
    in bfd.c to call _bfd_elf_convert_gnu_property_size and
    _bfd_elf_convert_gnu_properties, which are defined in elf-properties.c.
    It led to
    
    bfd.c:2484: undefined reference to `_bfd_elf_convert_gnu_property_size'
    
    for non-ELF targets.  Since elf-properties.c is a generic implementation
    and doesn't reference any ELF specific functions directly, this patch
    moves elf-properties.lo BFD32_LIBS.
    
    Tested for many ELF and non-ELF targets.
    
    	PR binutils/23494
    	* Makefile.am (BFD32_LIBS): Add elf-properties.lo.
    	(BFD32_LIBS_CFILES): Add elf-properties.c.
    	(BFD32_BACKENDS): Remove elf-properties.lo.
    	(BFD32_BACKENDS_CFILES): Remove elf-properties.c.
    	* configure.ac (elf): Remove elf-properties.lo.
    	* Makefile.in: Regenerated.
    	* configure: Likewise.
Comment 5 H.J. Lu 2018-11-09 13:57:15 UTC
Fixed for 2.32.
Comment 6 H.J. Lu 2018-11-09 13:57:33 UTC
Fixed.