summaryrefslogtreecommitdiff
path: root/bfd/bfd.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-08-08 21:00:04 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-08-08 21:00:18 -0700
commit6404ab993797d1d6cd3d9e97cc281e3cb6226c12 (patch)
treeeee63602c3e8fdeca481656be671146ad4bbbaf1 /bfd/bfd.c
parentf40f4a11d12025d18be2b0f9072f6ddcc94d3cdb (diff)
downloadbinutils-gdb-6404ab993797d1d6cd3d9e97cc281e3cb6226c12.tar.gz
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.
Diffstat (limited to 'bfd/bfd.c')
-rw-r--r--bfd/bfd.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 851710401e0..15becd7ae82 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2469,10 +2469,6 @@ bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd,
{
bfd_size_type hdr_size;
- /* Do nothing if input file will be decompressed. */
- if ((ibfd->flags & BFD_DECOMPRESS))
- return size;
-
/* Do nothing if either input or output aren't ELF. */
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -2483,6 +2479,14 @@ bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd,
== get_elf_backend_data (obfd)->s->elfclass)
return size;
+ /* Convert GNU property size. */
+ if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+ return _bfd_elf_convert_gnu_property_size (ibfd, obfd);
+
+ /* Do nothing if input file will be decompressed. */
+ if ((ibfd->flags & BFD_DECOMPRESS))
+ return size;
+
/* Do nothing if the input section isn't a SHF_COMPRESSED section. */
hdr_size = bfd_get_compression_header_size (ibfd, isec);
if (hdr_size == 0)
@@ -2523,10 +2527,6 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
Elf_Internal_Chdr chdr;
bfd_boolean use_memmove;
- /* Do nothing if input file will be decompressed. */
- if ((ibfd->flags & BFD_DECOMPRESS))
- return TRUE;
-
/* Do nothing if either input or output aren't ELF. */
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -2537,6 +2537,15 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
== get_elf_backend_data (obfd)->s->elfclass)
return TRUE;
+ /* Convert GNU properties. */
+ if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+ return _bfd_elf_convert_gnu_properties (ibfd, isec, obfd, ptr,
+ ptr_size);
+
+ /* Do nothing if input file will be decompressed. */
+ if ((ibfd->flags & BFD_DECOMPRESS))
+ return TRUE;
+
/* Do nothing if the input section isn't a SHF_COMPRESSED section. */
ihdr_size = bfd_get_compression_header_size (ibfd, isec);
if (ihdr_size == 0)