2010-07-04 04:52:24 +08:00
|
|
|
/* Compressed section support (intended for debug sections).
|
2017-01-02 11:36:43 +08:00
|
|
|
Copyright (C) 2008-2017 Free Software Foundation, Inc.
|
2008-07-10 09:32:23 +08:00
|
|
|
|
|
|
|
This file is part of BFD, the Binary File Descriptor library.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
|
|
|
|
|
|
|
#include "sysdep.h"
|
2015-03-29 22:12:38 +08:00
|
|
|
#include <zlib.h>
|
2008-07-10 09:32:23 +08:00
|
|
|
#include "bfd.h"
|
|
|
|
#include "libbfd.h"
|
2014-05-01 00:04:04 +08:00
|
|
|
#include "safe-ctype.h"
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
#define MAX_COMPRESSION_HEADER_SIZE 24
|
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
static bfd_boolean
|
|
|
|
decompress_contents (bfd_byte *compressed_buffer,
|
|
|
|
bfd_size_type compressed_size,
|
|
|
|
bfd_byte *uncompressed_buffer,
|
|
|
|
bfd_size_type uncompressed_size)
|
|
|
|
{
|
|
|
|
z_stream strm;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* It is possible the section consists of several compressed
|
|
|
|
buffers concatenated together, so we uncompress in a loop. */
|
2015-04-25 00:13:22 +08:00
|
|
|
/* PR 18313: The state field in the z_stream structure is supposed
|
|
|
|
to be invisible to the user (ie us), but some compilers will
|
|
|
|
still complain about it being used without initialisation. So
|
|
|
|
we first zero the entire z_stream structure and then set the fields
|
|
|
|
that we need. */
|
|
|
|
memset (& strm, 0, sizeof strm);
|
2015-05-15 06:58:51 +08:00
|
|
|
strm.avail_in = compressed_size;
|
|
|
|
strm.next_in = (Bytef*) compressed_buffer;
|
2010-10-29 20:10:39 +08:00
|
|
|
strm.avail_out = uncompressed_size;
|
|
|
|
|
2013-04-17 22:16:01 +08:00
|
|
|
BFD_ASSERT (Z_OK == 0);
|
2010-10-29 20:10:39 +08:00
|
|
|
rc = inflateInit (&strm);
|
2012-10-19 01:42:29 +08:00
|
|
|
while (strm.avail_in > 0 && strm.avail_out > 0)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
|
|
|
if (rc != Z_OK)
|
2013-04-17 22:16:01 +08:00
|
|
|
break;
|
2010-10-29 20:10:39 +08:00
|
|
|
strm.next_out = ((Bytef*) uncompressed_buffer
|
|
|
|
+ (uncompressed_size - strm.avail_out));
|
|
|
|
rc = inflate (&strm, Z_FINISH);
|
|
|
|
if (rc != Z_STREAM_END)
|
2013-04-17 22:16:01 +08:00
|
|
|
break;
|
2010-10-29 20:10:39 +08:00
|
|
|
rc = inflateReset (&strm);
|
|
|
|
}
|
2013-04-17 22:16:01 +08:00
|
|
|
rc |= inflateEnd (&strm);
|
2010-12-24 18:40:19 +08:00
|
|
|
return rc == Z_OK && strm.avail_out == 0;
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 02:20:06 +08:00
|
|
|
/* Compress data of the size specified in @var{uncompressed_size}
|
|
|
|
and pointed to by @var{uncompressed_buffer} using zlib and store
|
|
|
|
as the contents field. This function assumes the contents
|
2015-04-10 03:48:49 +08:00
|
|
|
field was allocated using bfd_malloc() or equivalent.
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
Return the uncompressed size if the full section contents is
|
|
|
|
compressed successfully. Otherwise return 0. */
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
static bfd_size_type
|
|
|
|
bfd_compress_section_contents (bfd *abfd, sec_ptr sec,
|
2015-03-29 22:12:38 +08:00
|
|
|
bfd_byte *uncompressed_buffer,
|
2015-04-24 07:37:44 +08:00
|
|
|
bfd_size_type uncompressed_size)
|
2008-07-10 09:32:23 +08:00
|
|
|
{
|
2010-10-30 03:56:00 +08:00
|
|
|
uLong compressed_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_byte *buffer;
|
|
|
|
bfd_size_type buffer_size;
|
|
|
|
bfd_boolean decompress;
|
2015-04-09 00:25:08 +08:00
|
|
|
int zlib_size = 0;
|
2015-04-08 22:53:54 +08:00
|
|
|
int orig_compression_header_size;
|
2015-05-15 06:58:51 +08:00
|
|
|
bfd_size_type orig_uncompressed_size;
|
|
|
|
int header_size = bfd_get_compression_header_size (abfd, NULL);
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_boolean compressed
|
|
|
|
= bfd_is_section_compressed_with_header (abfd, sec,
|
2015-05-15 06:58:51 +08:00
|
|
|
&orig_compression_header_size,
|
|
|
|
&orig_uncompressed_size);
|
|
|
|
|
|
|
|
/* Either ELF compression header or the 12-byte, "ZLIB" + 8-byte size,
|
|
|
|
overhead in .zdebug* section. */
|
|
|
|
if (!header_size)
|
|
|
|
header_size = 12;
|
2015-04-08 22:53:54 +08:00
|
|
|
|
|
|
|
if (compressed)
|
|
|
|
{
|
|
|
|
/* We shouldn't decompress unsupported compressed section. */
|
|
|
|
if (orig_compression_header_size < 0)
|
|
|
|
abort ();
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
/* Different compression schemes. Just move the compressed section
|
|
|
|
contents to the right position. */
|
|
|
|
if (orig_compression_header_size == 0)
|
|
|
|
{
|
|
|
|
/* Convert it from .zdebug* section. Get the uncompressed
|
2017-07-18 23:58:14 +08:00
|
|
|
size first. We need to subtract the 12-byte overhead in
|
2015-05-15 06:58:51 +08:00
|
|
|
.zdebug* section. Set orig_compression_header_size to
|
|
|
|
the 12-bye overhead. */
|
|
|
|
orig_compression_header_size = 12;
|
|
|
|
zlib_size = uncompressed_size - 12;
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
/* Convert it to .zdebug* section. */
|
2015-04-08 22:53:54 +08:00
|
|
|
zlib_size = uncompressed_size - orig_compression_header_size;
|
|
|
|
}
|
2015-05-15 06:58:51 +08:00
|
|
|
|
|
|
|
/* Add the header size. */
|
|
|
|
compressed_size = zlib_size + header_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
|
|
|
else
|
2015-05-15 06:58:51 +08:00
|
|
|
compressed_size = compressBound (uncompressed_size) + header_size;
|
2011-03-07 02:37:07 +08:00
|
|
|
|
2015-05-15 06:58:51 +08:00
|
|
|
/* Uncompress if it leads to smaller size. */
|
|
|
|
if (compressed && compressed_size > orig_uncompressed_size)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
2015-04-08 22:53:54 +08:00
|
|
|
decompress = TRUE;
|
2015-05-15 06:58:51 +08:00
|
|
|
buffer_size = orig_uncompressed_size;
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
2015-04-08 22:53:54 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
decompress = FALSE;
|
2015-05-15 06:58:51 +08:00
|
|
|
buffer_size = compressed_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
2015-04-10 18:54:41 +08:00
|
|
|
buffer = (bfd_byte *) bfd_alloc (abfd, buffer_size);
|
2015-04-08 22:53:54 +08:00
|
|
|
if (buffer == NULL)
|
|
|
|
return 0;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
if (compressed)
|
2015-03-25 04:27:52 +08:00
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
sec->size = orig_uncompressed_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
if (decompress)
|
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
if (!decompress_contents (uncompressed_buffer
|
|
|
|
+ orig_compression_header_size,
|
|
|
|
zlib_size, buffer, buffer_size))
|
2015-04-08 22:53:54 +08:00
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_bad_value);
|
2015-04-10 18:54:41 +08:00
|
|
|
bfd_release (abfd, buffer);
|
2015-04-08 22:53:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
free (uncompressed_buffer);
|
|
|
|
sec->contents = buffer;
|
|
|
|
sec->compress_status = COMPRESS_SECTION_DONE;
|
2015-05-15 06:58:51 +08:00
|
|
|
return orig_uncompressed_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_update_compression_header (abfd, buffer, sec);
|
2015-05-15 06:58:51 +08:00
|
|
|
memmove (buffer + header_size,
|
2015-04-08 22:53:54 +08:00
|
|
|
uncompressed_buffer + orig_compression_header_size,
|
|
|
|
zlib_size);
|
|
|
|
}
|
2015-03-25 04:27:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-08 22:53:54 +08:00
|
|
|
if (compress ((Bytef*) buffer + header_size,
|
|
|
|
&compressed_size,
|
|
|
|
(const Bytef*) uncompressed_buffer,
|
|
|
|
uncompressed_size) != Z_OK)
|
|
|
|
{
|
2015-04-10 18:54:41 +08:00
|
|
|
bfd_release (abfd, buffer);
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_set_error (bfd_error_bad_value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
compressed_size += header_size;
|
|
|
|
/* PR binutils/18087: If compression didn't make the section smaller,
|
2015-04-24 07:37:44 +08:00
|
|
|
just keep it uncompressed. */
|
|
|
|
if (compressed_size < uncompressed_size)
|
2015-05-15 06:58:51 +08:00
|
|
|
bfd_update_compression_header (abfd, buffer, sec);
|
2015-04-08 22:53:54 +08:00
|
|
|
else
|
|
|
|
{
|
2015-04-10 18:54:41 +08:00
|
|
|
/* NOTE: There is a small memory leak here since
|
|
|
|
uncompressed_buffer is malloced and won't be freed. */
|
|
|
|
bfd_release (abfd, buffer);
|
2015-04-08 22:53:54 +08:00
|
|
|
sec->contents = uncompressed_buffer;
|
|
|
|
sec->compress_status = COMPRESS_SECTION_NONE;
|
|
|
|
return uncompressed_size;
|
|
|
|
}
|
2015-03-25 04:27:52 +08:00
|
|
|
}
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
free (uncompressed_buffer);
|
|
|
|
sec->contents = buffer;
|
|
|
|
sec->size = compressed_size;
|
|
|
|
sec->compress_status = COMPRESS_SECTION_DONE;
|
|
|
|
|
|
|
|
return uncompressed_size;
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_get_full_section_contents
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bfd_boolean bfd_get_full_section_contents
|
|
|
|
(bfd *abfd, asection *section, bfd_byte **ptr);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Read all data from @var{section} in BFD @var{abfd}, decompress
|
|
|
|
if needed, and store in @var{*ptr}. If @var{*ptr} is NULL,
|
2013-01-11 04:03:55 +08:00
|
|
|
return @var{*ptr} with memory malloc'd by this function.
|
2010-10-29 20:10:39 +08:00
|
|
|
|
|
|
|
Return @code{TRUE} if the full section contents is retrieved
|
2014-12-02 00:43:46 +08:00
|
|
|
successfully. If the section has no contents then this function
|
|
|
|
returns @code{TRUE} but @var{*ptr} is set to NULL.
|
2010-10-29 20:10:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
|
|
|
bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
|
|
|
|
{
|
2011-04-11 12:08:13 +08:00
|
|
|
bfd_size_type sz;
|
2010-10-29 20:10:39 +08:00
|
|
|
bfd_byte *p = *ptr;
|
2010-12-24 18:40:19 +08:00
|
|
|
bfd_boolean ret;
|
2012-10-20 16:27:13 +08:00
|
|
|
bfd_size_type save_size;
|
|
|
|
bfd_size_type save_rawsize;
|
2010-10-29 20:10:39 +08:00
|
|
|
bfd_byte *compressed_buffer;
|
2015-04-08 22:53:54 +08:00
|
|
|
unsigned int compression_header_size;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2011-04-11 12:08:13 +08:00
|
|
|
if (abfd->direction != write_direction && sec->rawsize != 0)
|
|
|
|
sz = sec->rawsize;
|
|
|
|
else
|
|
|
|
sz = sec->size;
|
2010-10-29 20:10:39 +08:00
|
|
|
if (sz == 0)
|
2014-12-02 00:43:46 +08:00
|
|
|
{
|
|
|
|
*ptr = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-10-29 20:10:39 +08:00
|
|
|
|
|
|
|
switch (sec->compress_status)
|
|
|
|
{
|
|
|
|
case COMPRESS_SECTION_NONE:
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2011-12-15 00:12:13 +08:00
|
|
|
p = (bfd_byte *) bfd_malloc (sz);
|
2010-10-29 20:10:39 +08:00
|
|
|
if (p == NULL)
|
2016-11-10 20:26:53 +08:00
|
|
|
{
|
|
|
|
/* PR 20801: Provide a more helpful error message. */
|
|
|
|
if (bfd_get_error () == bfd_error_no_memory)
|
|
|
|
_bfd_error_handler
|
|
|
|
/* xgettext:c-format */
|
bfd_error_handler bfd_vma and bfd_size_type args
This patch uses the new %L _bfd_error_handler support for printing
bfd_vma arguments, and fixes a many other format and/or argument
errors in error messages.
bfd/
* binary.c (binary_set_section_contents): Don't print filepos in
error message.
(coff_write_object_contents): Cast size_t for error message.
(coff_slurp_line_table): Don't use bfd_vma symndx.
(coff_slurp_reloc_table): Remove unneeded cast.
* dwarf2.c (read_section): Cast bfd_int64_t to long long for
error message.
(find_abstract_instance_name): Likewise.
* elf32-arm.c (arm_type_of_stub): Correct error arg order.
(bfd_elf32_arm_stm32l4xx_erratum_scan): Don't cast error arg.
(elf32_arm_check_relocs): Make r_symndx an int.
* elf32-cris.c (cris_elf_check_relocs): Delete extraneous %s in
format string.
* elf32-metag.c (elf_metag_relocate_section): Delete extra error
message arg.
* elf32-nds32.c (nds32_elf_ex9_build_hash_table): Rewrite bogus
error message.
* elf32-i386.c (elf_i386_check_relocs): Make r_symndx an int.
* elf32-s390.c (elf_s390_check_relocs): Likewise.
* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
* elf64-s390.c (elf_s390_check_relocs): Likewise.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Likewise.
* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
* elf64-mmix.c (_bfd_mmix_after_linker_allocation): Cast size_t args
and use %lu for error message.
* elflink.c (elf_link_adjust_relocs): Delete extra error message arg.
* mmo.c (mmo_scan): Make stab_loc a file_ptr. Cast expression for
error message.
* elf32-arm.c (elf32_arm_tls_relax): Correct format string and args
in error message.
(elf32_arm_final_link_relocate): Likewise.
* coff-arm.c (bfd_arm_process_before_allocation): Likewise.
* coffcode.h (styp_to_sec_flags): Likewise.
* cofflink.c (_bfd_coff_write_global_sym): Likewise.
* ecoff.c (_bfd_ecoff_slurp_symbol_table): Likewise.
* elf32-arc.c (arc_elf_merge_private_bfd_data): Likewise.
* elf32-bfin.c (bfinfdpic_check_relocs): Likewise.
(elf32_bfin_merge_private_bfd_data): Likewise.
* elf32-cris.c (cris_elf_relocate_section): Likewise.
* elf32-frv.c (frv_elf_merge_private_bfd_data): Likewise.
* elf32-i370.c (i370_elf_merge_private_bfd_data): Likewise.
(i370_elf_relocate_section): Likewise.
* elf32-iq2000.c (iq2000_elf_merge_private_bfd_data): Likewise.
* elf32-m32c.c (m32c_elf_merge_private_bfd_data): Likewise.
* elf32-m68hc1x.c (_bfd_m68hc11_elf_merge_private_bfd_data): Likewise.
* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
* elf32-mep.c (mep_elf_merge_private_bfd_data): Likewise.
* elf32-mt.c (mt_elf_merge_private_bfd_data): Likewise.
* elf64-sparc.c (elf64_sparc_merge_private_bfd_data): Likewise.
* elfxx-mips.c (mips_elf_merge_obj_e_flags): Likewise.
(_bfd_mips_elf_merge_private_bfd_data): Likewise.
* ieee.c (ieee_write_id, read_id): Likewise.
* mach-o.c (bfd_mach_o_write_contents): Likewise.
(bfd_mach_o_layout_commands, bfd_mach_o_read_section_32): Likewise.
(bfd_mach_o_read_section_64, bfd_mach_o_read_symtab_symbol): Likewise.
(bfd_mach_o_read_command, bfd_mach_o_header_p): Likewise.
* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Likewise.
* stabs.c (_bfd_link_section_stabs): Likewise.
* coff-arm.c (coff_arm_relocate_section): Use L modifier in error
format.
* coff-mcore.c (coff_mcore_relocate_section): Likewise.
* coff-ppc.c (coff_ppc_relocate_section): Likewise.
* coff-rs6000.c (xcoff_reloc_type_toc): Likewise.
* coff-sh.c (sh_relax_section): Likewise.
(sh_relax_delete_bytes, sh_swap_insns): Likewise.
* coff-tic80.c (coff_tic80_relocate_section): Likewise.
* coffcode.h (coff_slurp_reloc_table): Likewise.
* coffgen.c (_bfd_coff_get_external_symbols): Likewise.
(_bfd_coff_read_string_table): Likewise.
* cofflink.c (_bfd_coff_generic_relocate_section): Likewise.
* compress.c (bfd_get_full_section_contents): Likewise.
* dwarf2.c (read_formatted_entries, decode_line_info): Likewise.
* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
* elf.c (bfd_elf_string_from_elf_section): Likewise.
* elf32-arc.c (arc_special_overflow_checks): Likewise.
* elf32-arm.c (elf32_arm_tls_relax): Likewise.
(elf32_arm_final_link_relocate, elf32_arm_relocate_section): Likewise.
(elf32_arm_write_section): Likewise.
* elf32-bfin.c (bfin_relocate_section): Likewise.
(bfinfdpic_relocate_section): Likewise.
* elf32-hppa.c (hppa_build_one_stub): Likewise.
(final_link_relocate, elf32_hppa_relocate_section): Likewise.
* elf32-i386.c (elf_i386_tls_transition): Likewise.
(elf_i386_relocate_section): Likewise.
* elf32-ip2k.c (ip2k_final_link_relocate): Likewise.
* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Likewise.
* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
* elf32-metag.c (elf_metag_relocate_section): Likewise.
* elf32-nds32.c (unrecognized_reloc_msg): Likewise.
(nds32_elf_relax_longcall1, nds32_elf_relax_longcall2): Likewise.
(nds32_elf_relax_longcall3, nds32_elf_relax_longjump1): Likewise.
(nds32_elf_relax_longjump2, nds32_elf_relax_longjump3): Likewise.
(nds32_elf_relax_longcall4, nds32_elf_relax_longcall5): Likewise.
(nds32_elf_relax_longcall6, nds32_elf_relax_longjump4): Likewise.
(nds32_elf_relax_longjump5, nds32_elf_relax_longjump6): Likewise.
(nds32_elf_relax_longjump7, nds32_elf_relax_loadstore): Likewise.
(nds32_elf_relax_ptr, nds32_elf_ex9_build_hash_table): Likewise.
* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
* elf32-rx.c (UNSAFE_FOR_PID): Likewise.
* elf32-s390.c (invalid_tls_insn, elf_s390_relocate_section): Likewise.
* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
* elf32-sh.c (sh_elf_relax_section): Likewise.
(sh_elf_relax_delete_bytes, sh_elf_swap_insns): Likewise.
(sh_elf_relocate_section): Likewise.
* elf32-sh64.c (shmedia_prepare_reloc): Likewise.
* elf32-spu.c (spu_elf_relocate_section): Likewise.
* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
* elf32-v850.c (v850_elf_relax_section): Likewise.
* elf32-vax.c (elf_vax_check_relocs): Likewise.
(elf_vax_relocate_section): Likewise.
* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
(extend_ebb_bounds_forward, extend_ebb_bounds_backward): Likewise.
(compute_text_actions, compute_ebb_proposed_actions): Likewise.
(do_fix_for_relocatable_link): Likewise.
* elf64-alpha.c (elf64_alpha_relax_got_load): Likewise.
(elf64_alpha_relax_with_lituse): Likewise.
* elf64-hppa.c (elf64_hppa_finish_dynamic_symbol): Likewise.
(elf_hppa_final_link_relocate): Likewise.
* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
(elf64_ia64_choose_gp, elf64_ia64_relocate_section): Likewise.
(elf64_vms_link_add_object_symbols): Likewise.
* elf64-mmix.c (mmix_elf_perform_relocation): Likewise.
(mmix_final_link_relocate): Likewise.
* elf64-s390.c (invalid_tls_insn): Likewise.
(elf_s390_relocate_section): Likewise.
* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
(elf_x86_64_relocate_section): Likewise.
* elfcode.h (elf_slurp_symbol_table): Likewise.
* elfcore.h (elf_core_file_p): Likewise.
* elflink.c (elf_link_read_relocs_from_section): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
(elfNN_aarch64_relocate_section): Likewise.
* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
(elfNN_ia64_choose_gp, elfNN_ia64_relocate_section): Likewise.
* elfnn-riscv.c (riscv_elf_relocate_section): Likewise.
* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
(_bfd_mips_elf_relocate_section): Likewise.
(_bfd_mips_elf_finish_dynamic_symbol, mips_finish_exec_plt): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
* ieee.c (ieee_slurp_external_symbols): Likewise.
* ihex.c (ihex_write_object_content): Likewise.
* mach-o.c (bfd_mach_o_build_exec_seg_command): Likewise.
* merge.c (_bfd_merged_section_offset): Likewise.
* mmo.c (mmo_write_loc_chunk): Likewise.
(mmo_write_object_contents): Likewise.
* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Likewise.
* stabs.c (_bfd_link_section_stabs): Likewise.
* xcofflink.c (xcoff_link_add_symbols, xcoff_find_tc0): Likewise.
ld/
* testsuite/ld-arc/nps-1b.err: Update.
* testsuite/ld-x86-64/ilp32-11.d: Update.
2017-07-09 21:41:32 +08:00
|
|
|
(_("error: %B(%A) is too large (%#Lx bytes)"),
|
|
|
|
abfd, sec, sz);
|
2017-06-27 00:24:49 +08:00
|
|
|
return FALSE;
|
2016-11-10 20:26:53 +08:00
|
|
|
}
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
2014-12-02 00:43:46 +08:00
|
|
|
|
2010-12-24 18:40:19 +08:00
|
|
|
if (!bfd_get_section_contents (abfd, sec, p, 0, sz))
|
|
|
|
{
|
|
|
|
if (*ptr != p)
|
|
|
|
free (p);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*ptr = p;
|
2010-10-29 20:10:39 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case DECOMPRESS_SECTION_SIZED:
|
2010-12-24 18:40:19 +08:00
|
|
|
/* Read in the full compressed section contents. */
|
2012-10-20 16:27:13 +08:00
|
|
|
compressed_buffer = (bfd_byte *) bfd_malloc (sec->compressed_size);
|
2010-12-24 18:40:19 +08:00
|
|
|
if (compressed_buffer == NULL)
|
|
|
|
return FALSE;
|
2012-10-20 16:27:13 +08:00
|
|
|
save_rawsize = sec->rawsize;
|
|
|
|
save_size = sec->size;
|
2010-12-24 18:40:19 +08:00
|
|
|
/* Clear rawsize, set size to compressed size and set compress_status
|
|
|
|
to COMPRESS_SECTION_NONE. If the compressed size is bigger than
|
|
|
|
the uncompressed size, bfd_get_section_contents will fail. */
|
|
|
|
sec->rawsize = 0;
|
2012-10-20 16:27:13 +08:00
|
|
|
sec->size = sec->compressed_size;
|
2010-12-24 18:40:19 +08:00
|
|
|
sec->compress_status = COMPRESS_SECTION_NONE;
|
|
|
|
ret = bfd_get_section_contents (abfd, sec, compressed_buffer,
|
2012-10-20 16:27:13 +08:00
|
|
|
0, sec->compressed_size);
|
2010-12-24 18:40:19 +08:00
|
|
|
/* Restore rawsize and size. */
|
2012-10-20 16:27:13 +08:00
|
|
|
sec->rawsize = save_rawsize;
|
|
|
|
sec->size = save_size;
|
2010-10-29 20:10:39 +08:00
|
|
|
sec->compress_status = DECOMPRESS_SECTION_SIZED;
|
2010-12-24 18:40:19 +08:00
|
|
|
if (!ret)
|
|
|
|
goto fail_compressed;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2012-10-20 16:27:13 +08:00
|
|
|
if (p == NULL)
|
|
|
|
p = (bfd_byte *) bfd_malloc (sz);
|
|
|
|
if (p == NULL)
|
2010-10-29 20:10:39 +08:00
|
|
|
goto fail_compressed;
|
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
compression_header_size = bfd_get_compression_header_size (abfd, sec);
|
2015-05-15 06:58:51 +08:00
|
|
|
if (compression_header_size == 0)
|
|
|
|
/* Set header size to the zlib header size if it is a
|
|
|
|
SHF_COMPRESSED section. */
|
|
|
|
compression_header_size = 12;
|
2015-04-08 22:53:54 +08:00
|
|
|
if (!decompress_contents (compressed_buffer + compression_header_size,
|
2017-02-17 19:39:20 +08:00
|
|
|
sec->compressed_size - compression_header_size, p, sz))
|
2010-12-24 18:40:19 +08:00
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_bad_value);
|
2012-10-20 16:27:13 +08:00
|
|
|
if (p != *ptr)
|
|
|
|
free (p);
|
2010-12-24 18:40:19 +08:00
|
|
|
fail_compressed:
|
|
|
|
free (compressed_buffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2010-12-24 18:40:19 +08:00
|
|
|
free (compressed_buffer);
|
2012-10-20 16:27:13 +08:00
|
|
|
*ptr = p;
|
|
|
|
return TRUE;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2010-12-24 18:40:19 +08:00
|
|
|
case COMPRESS_SECTION_DONE:
|
2014-12-04 03:50:48 +08:00
|
|
|
if (sec->contents == NULL)
|
|
|
|
return FALSE;
|
2010-12-24 18:40:19 +08:00
|
|
|
if (p == NULL)
|
|
|
|
{
|
|
|
|
p = (bfd_byte *) bfd_malloc (sz);
|
|
|
|
if (p == NULL)
|
|
|
|
return FALSE;
|
|
|
|
*ptr = p;
|
|
|
|
}
|
2014-12-02 00:43:46 +08:00
|
|
|
/* PR 17512; file: 5bc29788. */
|
|
|
|
if (p != sec->contents)
|
|
|
|
memcpy (p, sec->contents, sz);
|
2010-12-24 18:40:19 +08:00
|
|
|
return TRUE;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2010-12-24 18:40:19 +08:00
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
|
|
|
|
2012-10-21 17:06:07 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_cache_section_contents
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
void bfd_cache_section_contents
|
|
|
|
(asection *sec, void *contents);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Stash @var(contents) so any following reads of @var(sec) do
|
|
|
|
not need to decompress again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
bfd_cache_section_contents (asection *sec, void *contents)
|
|
|
|
{
|
|
|
|
if (sec->compress_status == DECOMPRESS_SECTION_SIZED)
|
|
|
|
sec->compress_status = COMPRESS_SECTION_DONE;
|
|
|
|
sec->contents = contents;
|
|
|
|
sec->flags |= SEC_IN_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_is_section_compressed_with_header
|
2010-10-29 20:10:39 +08:00
|
|
|
|
|
|
|
SYNOPSIS
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_boolean bfd_is_section_compressed_with_header
|
|
|
|
(bfd *abfd, asection *section,
|
2015-05-15 06:58:51 +08:00
|
|
|
int *compression_header_size_p,
|
|
|
|
bfd_size_type *uncompressed_size_p);
|
2010-10-29 20:10:39 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
2015-04-08 22:53:54 +08:00
|
|
|
Return @code{TRUE} if @var{section} is compressed. Compression
|
2015-05-15 06:58:51 +08:00
|
|
|
header size is returned in @var{compression_header_size_p} and
|
|
|
|
uncompressed size is returned in @var{uncompressed_size_p}. If
|
2015-04-08 22:53:54 +08:00
|
|
|
compression is unsupported, compression header size is returned
|
2015-05-15 06:58:51 +08:00
|
|
|
with -1 and uncompressed size is returned with 0.
|
2010-10-29 20:10:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
2015-04-08 22:53:54 +08:00
|
|
|
bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec,
|
2015-05-15 06:58:51 +08:00
|
|
|
int *compression_header_size_p,
|
|
|
|
bfd_size_type *uncompressed_size_p)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
bfd_byte header[MAX_COMPRESSION_HEADER_SIZE];
|
2015-04-08 22:53:54 +08:00
|
|
|
int compression_header_size;
|
2015-05-15 06:58:51 +08:00
|
|
|
int header_size;
|
2012-10-25 05:36:50 +08:00
|
|
|
unsigned int saved = sec->compress_status;
|
|
|
|
bfd_boolean compressed;
|
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
compression_header_size = bfd_get_compression_header_size (abfd, sec);
|
|
|
|
if (compression_header_size > MAX_COMPRESSION_HEADER_SIZE)
|
|
|
|
abort ();
|
2015-05-15 06:58:51 +08:00
|
|
|
header_size = compression_header_size ? compression_header_size : 12;
|
2015-04-08 22:53:54 +08:00
|
|
|
|
2012-10-25 05:36:50 +08:00
|
|
|
/* Don't decompress the section. */
|
|
|
|
sec->compress_status = COMPRESS_SECTION_NONE;
|
2010-10-29 20:10:39 +08:00
|
|
|
|
2015-05-15 06:58:51 +08:00
|
|
|
/* Read the header. */
|
|
|
|
if (bfd_get_section_contents (abfd, sec, header, 0, header_size))
|
|
|
|
{
|
|
|
|
if (compression_header_size == 0)
|
|
|
|
/* In this case, it should be "ZLIB" followed by the uncompressed
|
|
|
|
section size, 8 bytes in big-endian order. */
|
|
|
|
compressed = CONST_STRNEQ ((char*) header , "ZLIB");
|
|
|
|
else
|
|
|
|
compressed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
compressed = FALSE;
|
2012-10-25 05:36:50 +08:00
|
|
|
|
2015-05-15 06:58:51 +08:00
|
|
|
*uncompressed_size_p = sec->size;
|
2015-04-08 22:53:54 +08:00
|
|
|
if (compressed)
|
|
|
|
{
|
|
|
|
if (compression_header_size != 0)
|
|
|
|
{
|
|
|
|
if (!bfd_check_compression_header (abfd, header, sec,
|
2015-05-15 06:58:51 +08:00
|
|
|
uncompressed_size_p))
|
2015-04-08 22:53:54 +08:00
|
|
|
compression_header_size = -1;
|
|
|
|
}
|
|
|
|
/* Check for the pathalogical case of a debug string section that
|
|
|
|
contains the string ZLIB.... as the first entry. We assume that
|
|
|
|
no uncompressed .debug_str section would ever be big enough to
|
|
|
|
have the first byte of its (big-endian) size be non-zero. */
|
|
|
|
else if (strcmp (sec->name, ".debug_str") == 0
|
2015-05-15 06:58:51 +08:00
|
|
|
&& ISPRINT (header[4]))
|
2015-04-08 22:53:54 +08:00
|
|
|
compressed = FALSE;
|
2015-05-15 06:58:51 +08:00
|
|
|
else
|
|
|
|
*uncompressed_size_p = bfd_getb64 (header + 4);
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
2014-05-01 00:04:04 +08:00
|
|
|
|
2012-10-25 05:36:50 +08:00
|
|
|
/* Restore compress_status. */
|
|
|
|
sec->compress_status = saved;
|
2015-04-08 22:53:54 +08:00
|
|
|
*compression_header_size_p = compression_header_size;
|
2012-10-25 05:36:50 +08:00
|
|
|
return compressed;
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_is_section_compressed
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bfd_boolean bfd_is_section_compressed
|
|
|
|
(bfd *abfd, asection *section);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Return @code{TRUE} if @var{section} is compressed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
|
|
|
bfd_is_section_compressed (bfd *abfd, sec_ptr sec)
|
|
|
|
{
|
|
|
|
int compression_header_size;
|
2015-05-15 06:58:51 +08:00
|
|
|
bfd_size_type uncompressed_size;
|
2015-04-08 22:53:54 +08:00
|
|
|
return (bfd_is_section_compressed_with_header (abfd, sec,
|
2015-05-15 06:58:51 +08:00
|
|
|
&compression_header_size,
|
|
|
|
&uncompressed_size)
|
|
|
|
&& compression_header_size >= 0
|
|
|
|
&& uncompressed_size > 0);
|
2015-04-08 22:53:54 +08:00
|
|
|
}
|
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_init_section_decompress_status
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bfd_boolean bfd_init_section_decompress_status
|
|
|
|
(bfd *abfd, asection *section);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Record compressed section size, update section size with
|
|
|
|
decompressed size and set compress_status to
|
|
|
|
DECOMPRESS_SECTION_SIZED.
|
|
|
|
|
|
|
|
Return @code{FALSE} if the section is not a valid compressed
|
2015-04-10 03:48:49 +08:00
|
|
|
section. Otherwise, return @code{TRUE}.
|
2010-10-29 20:10:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
2015-03-29 22:12:38 +08:00
|
|
|
bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
bfd_byte header[MAX_COMPRESSION_HEADER_SIZE];
|
2015-04-08 22:53:54 +08:00
|
|
|
int compression_header_size;
|
2015-05-15 06:58:51 +08:00
|
|
|
int header_size;
|
2010-10-29 20:10:39 +08:00
|
|
|
bfd_size_type uncompressed_size;
|
|
|
|
|
2015-04-08 22:53:54 +08:00
|
|
|
compression_header_size = bfd_get_compression_header_size (abfd, sec);
|
|
|
|
if (compression_header_size > MAX_COMPRESSION_HEADER_SIZE)
|
|
|
|
abort ();
|
2015-05-15 06:58:51 +08:00
|
|
|
header_size = compression_header_size ? compression_header_size : 12;
|
2015-04-08 22:53:54 +08:00
|
|
|
|
2015-05-15 06:58:51 +08:00
|
|
|
/* Read the header. */
|
2010-10-29 20:10:39 +08:00
|
|
|
if (sec->rawsize != 0
|
|
|
|
|| sec->contents != NULL
|
|
|
|
|| sec->compress_status != COMPRESS_SECTION_NONE
|
2015-04-08 22:53:54 +08:00
|
|
|
|| !bfd_get_section_contents (abfd, sec, header, 0, header_size))
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_invalid_operation);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2015-05-15 06:58:51 +08:00
|
|
|
if (compression_header_size == 0)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
2015-05-15 06:58:51 +08:00
|
|
|
/* In this case, it should be "ZLIB" followed by the uncompressed
|
|
|
|
section size, 8 bytes in big-endian order. */
|
|
|
|
if (! CONST_STRNEQ ((char*) header, "ZLIB"))
|
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_wrong_format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
uncompressed_size = bfd_getb64 (header + 4);
|
2010-10-29 20:10:39 +08:00
|
|
|
}
|
2015-05-15 06:58:51 +08:00
|
|
|
else if (!bfd_check_compression_header (abfd, header, sec,
|
|
|
|
&uncompressed_size))
|
2015-04-08 22:53:54 +08:00
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_wrong_format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-05-15 06:58:51 +08:00
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
sec->compressed_size = sec->size;
|
|
|
|
sec->size = uncompressed_size;
|
|
|
|
sec->compress_status = DECOMPRESS_SECTION_SIZED;
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_init_section_compress_status
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bfd_boolean bfd_init_section_compress_status
|
|
|
|
(bfd *abfd, asection *section);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
If open for read, compress section, update section size with
|
|
|
|
compressed size and set compress_status to COMPRESS_SECTION_DONE.
|
|
|
|
|
|
|
|
Return @code{FALSE} if the section is not a valid compressed
|
2015-04-10 03:48:49 +08:00
|
|
|
section. Otherwise, return @code{TRUE}.
|
2010-10-29 20:10:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
2015-03-29 22:12:38 +08:00
|
|
|
bfd_init_section_compress_status (bfd *abfd, sec_ptr sec)
|
2010-10-29 20:10:39 +08:00
|
|
|
{
|
|
|
|
bfd_size_type uncompressed_size;
|
|
|
|
bfd_byte *uncompressed_buffer;
|
|
|
|
|
|
|
|
/* Error if not opened for read. */
|
|
|
|
if (abfd->direction != read_direction
|
|
|
|
|| sec->size == 0
|
|
|
|
|| sec->rawsize != 0
|
|
|
|
|| sec->contents != NULL
|
|
|
|
|| sec->compress_status != COMPRESS_SECTION_NONE)
|
2008-07-10 09:32:23 +08:00
|
|
|
{
|
2010-10-29 20:10:39 +08:00
|
|
|
bfd_set_error (bfd_error_invalid_operation);
|
|
|
|
return FALSE;
|
2008-07-10 09:32:23 +08:00
|
|
|
}
|
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
/* Read in the full section contents and compress it. */
|
|
|
|
uncompressed_size = sec->size;
|
|
|
|
uncompressed_buffer = (bfd_byte *) bfd_malloc (uncompressed_size);
|
2017-04-26 20:07:49 +08:00
|
|
|
/* PR 21431 */
|
|
|
|
if (uncompressed_buffer == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-10-29 20:10:39 +08:00
|
|
|
if (!bfd_get_section_contents (abfd, sec, uncompressed_buffer,
|
|
|
|
0, uncompressed_size))
|
2017-04-26 20:07:49 +08:00
|
|
|
return FALSE;
|
2008-07-10 09:32:23 +08:00
|
|
|
|
2017-04-26 20:07:49 +08:00
|
|
|
uncompressed_size = bfd_compress_section_contents (abfd, sec,
|
|
|
|
uncompressed_buffer,
|
|
|
|
uncompressed_size);
|
|
|
|
return uncompressed_size != 0;
|
2008-07-10 09:32:23 +08:00
|
|
|
}
|
2015-04-15 13:01:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
bfd_compress_section
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bfd_boolean bfd_compress_section
|
|
|
|
(bfd *abfd, asection *section, bfd_byte *uncompressed_buffer);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
If open for write, compress section, update section size with
|
|
|
|
compressed size and set compress_status to COMPRESS_SECTION_DONE.
|
|
|
|
|
|
|
|
Return @code{FALSE} if compression fail. Otherwise, return
|
|
|
|
@code{TRUE}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bfd_boolean
|
|
|
|
bfd_compress_section (bfd *abfd, sec_ptr sec, bfd_byte *uncompressed_buffer)
|
|
|
|
{
|
|
|
|
bfd_size_type uncompressed_size = sec->size;
|
|
|
|
|
|
|
|
/* Error if not opened for write. */
|
|
|
|
if (abfd->direction != write_direction
|
|
|
|
|| uncompressed_size == 0
|
|
|
|
|| uncompressed_buffer == NULL
|
|
|
|
|| sec->contents != NULL
|
|
|
|
|| sec->compressed_size != 0
|
|
|
|
|| sec->compress_status != COMPRESS_SECTION_NONE)
|
|
|
|
{
|
|
|
|
bfd_set_error (bfd_error_invalid_operation);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compress it. */
|
|
|
|
return bfd_compress_section_contents (abfd, sec, uncompressed_buffer,
|
2015-04-24 07:37:44 +08:00
|
|
|
uncompressed_size) != 0;
|
2015-04-15 13:01:25 +08:00
|
|
|
}
|