summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongkyun Son <dongkyun.s@samsung.com>2020-01-31 11:32:24 +0900
committerDongkyun Son <dongkyun.s@samsung.com>2020-01-31 11:32:24 +0900
commit92828c11002c739f096c37dfe6353fb96660af88 (patch)
tree9da78d9b183495dde4319f650978a697cbb8d733
parent5c1ad300c5b817e6c7dc6fdf4b701d8f1351cfa8 (diff)
downloadbinutils-sandbox/dkson95/gas.tar.gz
binutils-sandbox/dkson95/gas.tar.bz2
binutils-sandbox/dkson95/gas.zip
Revert "Handle ELF compressed header alignment correctly by setting up the section alignment correctly for the Elf32_Chdr or Elf64_Chdr type and respect the ch_addralign field when decompressing the section data."sandbox/dkson95/gas
This reverts commit 4207142d6a5d2359170c5f9a140fc1a2351fbda9. Change-Id: I73f9a44acf2df190453c126bfd41d1b586f0a126
-rw-r--r--bfd/bfd-in2.h6
-rw-r--r--bfd/bfd.c20
-rw-r--r--bfd/compress.c35
-rw-r--r--bfd/elf.c5
-rw-r--r--binutils/readelf.c18
-rw-r--r--binutils/testsuite/binutils-all/dw2-3.rS2
-rw-r--r--binutils/testsuite/binutils-all/dw2-3.rt2
7 files changed, 39 insertions, 49 deletions
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 7b1cfbcf1a2..83628e12004 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7525,8 +7525,7 @@ void bfd_update_compression_header
bfd_boolean bfd_check_compression_header
(bfd *abfd, bfd_byte *contents, asection *sec,
- bfd_size_type *uncompressed_size,
- unsigned int *uncompressed_alignment_power);
+ bfd_size_type *uncompressed_size);
int bfd_get_compression_header_size (bfd *abfd, asection *sec);
@@ -8113,8 +8112,7 @@ void bfd_cache_section_contents
bfd_boolean bfd_is_section_compressed_with_header
(bfd *abfd, asection *section,
int *compression_header_size_p,
- bfd_size_type *uncompressed_size_p,
- unsigned int *uncompressed_alignment_power_p);
+ bfd_size_type *uncompressed_size_p);
bfd_boolean bfd_is_section_compressed
(bfd *abfd, asection *section);
diff --git a/bfd/bfd.c b/bfd/bfd.c
index f56a8d342fb..7e3aeb535f3 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2338,8 +2338,6 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
bfd_put_32 (abfd, sec->size, &echdr->ch_size);
bfd_put_32 (abfd, 1 << sec->alignment_power,
&echdr->ch_addralign);
- /* bfd_log2 (alignof (Elf32_Chdr)) */
- bfd_set_section_alignment (abfd, sec, 2);
}
else
{
@@ -2350,8 +2348,6 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
bfd_put_64 (abfd, sec->size, &echdr->ch_size);
bfd_put_64 (abfd, 1 << sec->alignment_power,
&echdr->ch_addralign);
- /* bfd_log2 (alignof (Elf64_Chdr)) */
- bfd_set_section_alignment (abfd, sec, 3);
}
}
else
@@ -2364,8 +2360,6 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
order. */
memcpy (contents, "ZLIB", 4);
bfd_putb64 (sec->size, contents + 4);
- /* No way to keep the original alignment, just use 1 always. */
- bfd_set_section_alignment (abfd, sec, 0);
}
}
}
@@ -2380,14 +2374,12 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
SYNOPSIS
bfd_boolean bfd_check_compression_header
(bfd *abfd, bfd_byte *contents, asection *sec,
- bfd_size_type *uncompressed_size,
- unsigned int *uncompressed_alignment_power);
+ bfd_size_type *uncompressed_size);
DESCRIPTION
Check the compression header at CONTENTS of SEC in ABFD and
- store the uncompressed size in UNCOMPRESSED_SIZE and the
- uncompressed data alignment in UNCOMPRESSED_ALIGNMENT_POWER
- if the compression header is valid.
+ store the uncompressed size in UNCOMPRESSED_SIZE if the
+ compression header is valid.
RETURNS
Return TRUE if the compression header is valid.
@@ -2396,8 +2388,7 @@ RETURNS
bfd_boolean
bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
asection *sec,
- bfd_size_type *uncompressed_size,
- unsigned int *uncompressed_alignment_power)
+ bfd_size_type *uncompressed_size)
{
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
&& (elf_section_flags (sec) & SHF_COMPRESSED) != 0)
@@ -2419,10 +2410,9 @@ bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
chdr.ch_addralign = bfd_get_64 (abfd, &echdr->ch_addralign);
}
if (chdr.ch_type == ELFCOMPRESS_ZLIB
- && chdr.ch_addralign == (1U << bfd_log2 (chdr.ch_addralign)))
+ && chdr.ch_addralign == 1U << sec->alignment_power)
{
*uncompressed_size = chdr.ch_size;
- *uncompressed_alignment_power = bfd_log2 (chdr.ch_addralign);
return TRUE;
}
}
diff --git a/bfd/compress.c b/bfd/compress.c
index cf862fe42e3..2569228492b 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -84,13 +84,11 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec,
int zlib_size = 0;
int orig_compression_header_size;
bfd_size_type orig_uncompressed_size;
- unsigned int orig_uncompressed_alignment_pow;
int header_size = bfd_get_compression_header_size (abfd, NULL);
bfd_boolean compressed
= bfd_is_section_compressed_with_header (abfd, sec,
&orig_compression_header_size,
- &orig_uncompressed_size,
- &orig_uncompressed_alignment_pow);
+ &orig_uncompressed_size);
/* Either ELF compression header or the 12-byte, "ZLIB" + 8-byte size,
overhead in .zdebug* section. */
@@ -155,9 +153,6 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec,
return 0;
}
free (uncompressed_buffer);
- bfd_set_section_alignment (abfd, sec,
- orig_uncompressed_alignment_pow);
-
sec->contents = buffer;
sec->compress_status = COMPRESS_SECTION_DONE;
return orig_uncompressed_size;
@@ -389,24 +384,20 @@ SYNOPSIS
bfd_boolean bfd_is_section_compressed_with_header
(bfd *abfd, asection *section,
int *compression_header_size_p,
- bfd_size_type *uncompressed_size_p,
- unsigned int *uncompressed_alignment_power_p);
+ bfd_size_type *uncompressed_size_p);
DESCRIPTION
Return @code{TRUE} if @var{section} is compressed. Compression
- header size is returned in @var{compression_header_size_p},
- uncompressed size is returned in @var{uncompressed_size_p}
- and the uncompressed data alignement power is returned in
- @var{uncompressed_align_pow_p}. If compression is
- unsupported, compression header size is returned with -1
- and uncompressed size is returned with 0.
+ header size is returned in @var{compression_header_size_p} and
+ uncompressed size is returned in @var{uncompressed_size_p}. If
+ compression is unsupported, compression header size is returned
+ with -1 and uncompressed size is returned with 0.
*/
bfd_boolean
bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec,
int *compression_header_size_p,
- bfd_size_type *uncompressed_size_p,
- unsigned int *uncompressed_align_pow_p)
+ bfd_size_type *uncompressed_size_p)
{
bfd_byte header[MAX_COMPRESSION_HEADER_SIZE];
int compression_header_size;
@@ -441,8 +432,7 @@ bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec,
if (compression_header_size != 0)
{
if (!bfd_check_compression_header (abfd, header, sec,
- uncompressed_size_p,
- uncompressed_align_pow_p))
+ uncompressed_size_p))
compression_header_size = -1;
}
/* Check for the pathalogical case of a debug string section that
@@ -479,11 +469,9 @@ bfd_is_section_compressed (bfd *abfd, sec_ptr sec)
{
int compression_header_size;
bfd_size_type uncompressed_size;
- unsigned int uncompressed_align_power;
return (bfd_is_section_compressed_with_header (abfd, sec,
&compression_header_size,
- &uncompressed_size,
- &uncompressed_align_power)
+ &uncompressed_size)
&& compression_header_size >= 0
&& uncompressed_size > 0);
}
@@ -512,7 +500,6 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
int compression_header_size;
int header_size;
bfd_size_type uncompressed_size;
- unsigned int uncompressed_alignment_power = 0;
compression_header_size = bfd_get_compression_header_size (abfd, sec);
if (compression_header_size > MAX_COMPRESSION_HEADER_SIZE)
@@ -541,8 +528,7 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
uncompressed_size = bfd_getb64 (header + 4);
}
else if (!bfd_check_compression_header (abfd, header, sec,
- &uncompressed_size,
- &uncompressed_alignment_power))
+ &uncompressed_size))
{
bfd_set_error (bfd_error_wrong_format);
return FALSE;
@@ -550,7 +536,6 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
sec->compressed_size = sec->size;
sec->size = uncompressed_size;
- bfd_set_section_alignment (abfd, sec, uncompressed_alignment_power);
sec->compress_status = DECOMPRESS_SECTION_SIZED;
return TRUE;
diff --git a/bfd/elf.c b/bfd/elf.c
index 5a061c91107..dcfee9d7ca7 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1213,12 +1213,11 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
enum { nothing, compress, decompress } action = nothing;
int compression_header_size;
bfd_size_type uncompressed_size;
- unsigned int uncompressed_align_power;
bfd_boolean compressed
= bfd_is_section_compressed_with_header (abfd, newsect,
&compression_header_size,
- &uncompressed_size,
- &uncompressed_align_power);
+ &uncompressed_size);
+
if (compressed)
{
/* Compressed section. Check if we should decompress. */
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 7f22c58dbe5..61a62e7778d 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -13635,6 +13635,12 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
printable_section_name (filedata, section), chdr.ch_type);
return FALSE;
}
+ else if (chdr.ch_addralign != section->sh_addralign)
+ {
+ warn (_("compressed section '%s' is corrupted\n"),
+ printable_section_name (filedata, section));
+ return FALSE;
+ }
uncompressed_size = chdr.ch_size;
start += compression_header_size;
new_size -= compression_header_size;
@@ -13776,6 +13782,12 @@ dump_section_as_bytes (Elf_Internal_Shdr * section,
printable_section_name (filedata, section), chdr.ch_type);
return FALSE;
}
+ else if (chdr.ch_addralign != section->sh_addralign)
+ {
+ warn (_("compressed section '%s' is corrupted\n"),
+ printable_section_name (filedata, section));
+ return FALSE;
+ }
uncompressed_size = chdr.ch_size;
start += compression_header_size;
new_size -= compression_header_size;
@@ -14099,6 +14111,12 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
section->name, chdr.ch_type);
return FALSE;
}
+ else if (chdr.ch_addralign != sec->sh_addralign)
+ {
+ warn (_("compressed section '%s' is corrupted\n"),
+ section->name);
+ return FALSE;
+ }
uncompressed_size = chdr.ch_size;
start += compression_header_size;
size -= compression_header_size;
diff --git a/binutils/testsuite/binutils-all/dw2-3.rS b/binutils/testsuite/binutils-all/dw2-3.rS
index 86bc73d9a29..f1637e9149f 100644
--- a/binutils/testsuite/binutils-all/dw2-3.rS
+++ b/binutils/testsuite/binutils-all/dw2-3.rS
@@ -1,3 +1,3 @@
#...
- +\[[ 0-9]+\] .debug_info +(PROGBITS|MIPS_DWARF) +0+ +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +C +0 +0 +(4|8)
+ +\[[ 0-9]+\] .debug_info +(PROGBITS|MIPS_DWARF) +0+ +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +C +0 +0 +1
#pass
diff --git a/binutils/testsuite/binutils-all/dw2-3.rt b/binutils/testsuite/binutils-all/dw2-3.rt
index 74e7f8deca8..f59cbaa22b2 100644
--- a/binutils/testsuite/binutils-all/dw2-3.rt
+++ b/binutils/testsuite/binutils-all/dw2-3.rt
@@ -1,6 +1,6 @@
#...
+\[[ 0-9]+\] .debug_info
- +(PROGBITS|MIPS_DWARF) +0+ +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0 +0 +(4|8)
+ +(PROGBITS|MIPS_DWARF) +0+ +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0 +0 +1
+\[0+800\]: COMPRESSED
+ZLIB, 0+9d, 1
#pass