mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
08dedd6631
bfd/ChangeLog: * bfd-in.h (startswith): Add startswith function. (CONST_STRNEQ): Remove. * bfd-in2.h (startswith): Regenerate with make headers. * archive.c (bfd_slurp_armap): Replace usage of CONST_STRNEQ with startswith. (_bfd_slurp_extended_name_table): Likewise. * archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise. * bfd.c (bfd_get_sign_extend_vma): Likewise. (bfd_convert_section_size): Likewise. (bfd_convert_section_contents): Likewise. * coff-stgo32.c (go32exe_create_stub): Likewise. (go32exe_check_format): Likewise. * coffcode.h (styp_to_sec_flags): Likewise. (GNU_DEBUGALTLINK): Likewise. * coffgen.c (_bfd_coff_section_already_linked): Likewise. (coff_gc_sweep): Likewise. (bfd_coff_gc_sections): Likewise. * cofflink.c (coff_link_add_symbols): Likewise. (process_embedded_commands): Likewise. * compress.c (bfd_is_section_compressed_with_header): Likewise. (bfd_init_section_decompress_status): Likewise. * dwarf2.c (find_debug_info): Likewise. (place_sections): Likewise. * ecoff.c (_bfd_ecoff_slurp_armap): Likewise. * elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Likewise. * elf.c (_bfd_elf_make_section_from_shdr): Likewise. (assign_section_numbers): Likewise. (elfcore_grok_win32pstatus): Likewise. * elf32-arm.c (cmse_scan): Likewise. (elf32_arm_gc_mark_extra_sections): Likewise. (elf32_arm_size_dynamic_sections): Likewise. (is_arm_elf_unwind_section_name): Likewise. * elf32-bfin.c (bfin_size_dynamic_sections): Likewise. * elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise. * elf32-cris.c (elf_cris_size_dynamic_sections): Likewise. * elf32-csky.c (csky_elf_size_dynamic_sections): Likewise. * elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise. * elf32-iq2000.c (iq2000_elf_check_relocs): Likewise. * elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise. * elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise. * elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise. * elf32-metag.c (elf_metag_size_dynamic_sections): Likewise. * elf32-msp430.c (msp430_elf_relax_delete_bytes): Likewise. * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise. * elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise. * elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise. * elf32-s390.c (elf_s390_size_dynamic_sections): Likewise. * elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise. * elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise. * elf32-sh.c (sh_elf_size_dynamic_sections): Likewise. * elf32-tic6x.c (is_tic6x_elf_unwind_section_name): Likewise. (elf32_tic6x_size_dynamic_sections): Likewise. * elf32-vax.c (elf_vax_size_dynamic_sections): Likewise. * elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise. (xtensa_is_insntable_section): Likewise. (xtensa_is_littable_section): Likewise. (xtensa_is_proptable_section): Likewise. (xtensa_property_section_name): Likewise. (xtensa_callback_required_dependence): Likewise. * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise. * elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise. * elf64-ia64-vms.c (is_unwind_section_name): Likewise. (get_reloc_section): Likewise. (elf64_ia64_size_dynamic_sections): Likewise. (elf64_ia64_object_p): Likewise. * elf64-mmix.c (mmix_elf_add_symbol_hook): Likewise. * elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise. * elf64-s390.c (elf_s390_size_dynamic_sections): Likewise. * elflink.c (elf_link_add_object_symbols): Likewise. (_bfd_elf_gc_mark_extra_sections): Likewise. (bfd_elf_parse_eh_frame_entries): Likewise. (_bfd_elf_section_already_linked): Likewise. * elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise. * elfnn-ia64.c (is_unwind_section_name): Likewise. (elfNN_ia64_size_dynamic_sections): Likewise. (elfNN_ia64_object_p): Likewise. * elfxx-mips.c (FN_STUB_P): Likewise. (CALL_STUB_P): Likewise. (CALL_FP_STUB_P): Likewise. (_bfd_mips_elf_section_from_shdr): Likewise. (_bfd_mips_elf_fake_sections): Likewise. (_bfd_mips_elf_size_dynamic_sections): Likewise. (_bfd_mips_final_write_processing): Likewise. (_bfd_mips_elf_final_link): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise. * elfxx-x86.c (elf_i386_is_reloc_section): Likewise. (elf_x86_64_is_reloc_section): Likewise. * hpux-core.c (thread_section_p): Likewise. * libcoff.h (bfd_pei_p): Likewise. * linker.c (REAL): Likewise. (unwrap_hash_lookup): Likewise. (_bfd_generic_link_add_one_symbol): Likewise. * mmo.c (mmo_internal_write_section): Likewise. * osf-core.c (osf_core_core_file_p): Likewise. * pef.c (bfd_pef_print_symbol): Likewise. * pei-x86_64.c (pex64_print_all_pdata_sections): Likewise. * som.c (som_slurp_symbol_table): Likewise. (som_slurp_armap): Likewise. * wasm-module.c (wasm_compute_custom_section_file_position): Likewise. binutils/ChangeLog: * dlltool.c (scan_drectve_symbols): Replace usage of CONST_STRNEQ with startswith. * emul_aix.c (ar_emul_aix_parse_arg): Likewise. * objcopy.c (is_mergeable_note_section): Likewise. * objdump.c (dump_dwarf_section): Likewise. * prdbg.c (pr_method_type): Likewise. (pr_class_baseclass): Likewise. (tg_class_baseclass): Likewise. * readelf.c (process_lto_symbol_tables): Likewise. * stabs.c (ULLHIGH): Likewise. (parse_stab_argtypes): Likewise. (stab_demangle_function_name): Likewise. gas/ChangeLog: * config/tc-i386.c (md_parse_option): Replace usage of CONST_STRNEQ with startswith. (x86_64_section_word): Likewise. * config/tc-sparc.c (md_parse_option): Likewise. gdb/ChangeLog: * arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith. (_initialize_arm_tdep): Likewise. ld/ChangeLog: * emultempl/aix.em: Replace usage of CONST_STRNEQ with startswith. * emultempl/beos.em: Likewise. * emultempl/elf.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/xtensaelf.em: Likewise. * ldctor.c (ctor_prio): Likewise. * ldelf.c (ldelf_try_needed): Likewise. (ldelf_parse_ld_so_conf): Likewise. (ldelf_after_open): Likewise. (output_rel_find): Likewise. (ldelf_place_orphan): Likewise. * ldfile.c (ldfile_add_library_path): Likewise. * ldlang.c (lang_add_input_file): Likewise. * ldmain.c (get_sysroot): Likewise. (get_emulation): Likewise. (add_archive_element): Likewise. * ldwrite.c (unsplittable_name): Likewise. (clone_section): Likewise. * lexsup.c (parse_args): Likewise. * pe-dll.c (is_import): Likewise. (pe_implied_import_dll): Likewise. opcodes/ChangeLog: * aarch64-dis.c (parse_aarch64_dis_option): Replace usage of CONST_STRNEQ with startswith. * arc-dis.c (parse_option): Likewise. * arm-dis.c (parse_arm_disassembler_options): Likewise. * cris-dis.c (print_with_operands): Likewise. * h8300-dis.c (bfd_h8_disassemble): Likewise. * i386-dis.c (print_insn): Likewise. * ia64-gen.c (fetch_insn_class): Likewise. (parse_resource_users): Likewise. (in_iclass): Likewise. (lookup_specifier): Likewise. (insert_opcode_dependencies): Likewise. * mips-dis.c (parse_mips_ase_option): Likewise. (parse_mips_dis_option): Likewise. * s390-dis.c (disassemble_init_s390): Likewise. * wasm32-dis.c (parse_wasm32_disassembler_options): Likewise.
257 lines
7.5 KiB
C
257 lines
7.5 KiB
C
/* Support for 64-bit archives.
|
|
Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
|
Ian Lance Taylor, Cygnus Support
|
|
Linker support added by Mark Mitchell, CodeSourcery, LLC.
|
|
<mark@codesourcery.com>
|
|
|
|
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. */
|
|
|
|
/* This file supports the 64-bit archives. We use the same format as
|
|
the 64-bit (MIPS) ELF archives. */
|
|
|
|
#include "sysdep.h"
|
|
#include "bfd.h"
|
|
#include "libbfd.h"
|
|
#include "aout/ar.h"
|
|
|
|
/* Irix 6 defines a 64bit archive map format, so that they can
|
|
have archives more than 4 GB in size. */
|
|
|
|
/* Read an Irix 6 armap. */
|
|
|
|
bfd_boolean
|
|
_bfd_archive_64_bit_slurp_armap (bfd *abfd)
|
|
{
|
|
struct artdata *ardata = bfd_ardata (abfd);
|
|
char nextname[17];
|
|
bfd_size_type i, parsed_size, nsymz, stringsize, carsym_size, ptrsize;
|
|
struct areltdata *mapdata;
|
|
bfd_byte int_buf[8];
|
|
char *stringbase;
|
|
char *stringend;
|
|
bfd_byte *raw_armap = NULL;
|
|
carsym *carsyms;
|
|
bfd_size_type amt;
|
|
ufile_ptr filesize;
|
|
|
|
ardata->symdefs = NULL;
|
|
|
|
/* Get the name of the first element. */
|
|
i = bfd_bread (nextname, 16, abfd);
|
|
if (i == 0)
|
|
return TRUE;
|
|
if (i != 16)
|
|
return FALSE;
|
|
|
|
if (bfd_seek (abfd, (file_ptr) - 16, SEEK_CUR) != 0)
|
|
return FALSE;
|
|
|
|
/* Archives with traditional armaps are still permitted. */
|
|
if (startswith (nextname, "/ "))
|
|
return bfd_slurp_armap (abfd);
|
|
|
|
if (! startswith (nextname, "/SYM64/ "))
|
|
{
|
|
abfd->has_armap = FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd);
|
|
if (mapdata == NULL)
|
|
return FALSE;
|
|
parsed_size = mapdata->parsed_size;
|
|
free (mapdata);
|
|
|
|
filesize = bfd_get_file_size (abfd);
|
|
if (filesize != 0 && parsed_size > filesize)
|
|
{
|
|
bfd_set_error (bfd_error_malformed_archive);
|
|
return FALSE;
|
|
}
|
|
|
|
if (bfd_bread (int_buf, 8, abfd) != 8)
|
|
{
|
|
if (bfd_get_error () != bfd_error_system_call)
|
|
bfd_set_error (bfd_error_malformed_archive);
|
|
return FALSE;
|
|
}
|
|
|
|
nsymz = bfd_getb64 (int_buf);
|
|
stringsize = parsed_size - 8 * nsymz - 8;
|
|
|
|
carsym_size = nsymz * sizeof (carsym);
|
|
ptrsize = 8 * nsymz;
|
|
|
|
amt = carsym_size + stringsize + 1;
|
|
if (/* Catch overflow in stringsize (and ptrsize) expression. */
|
|
nsymz >= (bfd_size_type) -1 / 8
|
|
|| stringsize > parsed_size
|
|
/* Catch overflow in carsym_size expression. */
|
|
|| nsymz > (bfd_size_type) -1 / sizeof (carsym)
|
|
/* Catch overflow in amt expression. */
|
|
|| amt <= carsym_size
|
|
|| amt <= stringsize)
|
|
{
|
|
bfd_set_error (bfd_error_malformed_archive);
|
|
return FALSE;
|
|
}
|
|
ardata->symdefs = (struct carsym *) bfd_alloc (abfd, amt);
|
|
if (ardata->symdefs == NULL)
|
|
return FALSE;
|
|
carsyms = ardata->symdefs;
|
|
stringbase = ((char *) ardata->symdefs) + carsym_size;
|
|
|
|
raw_armap = (bfd_byte *) _bfd_alloc_and_read (abfd, ptrsize, ptrsize);
|
|
if (raw_armap == NULL
|
|
|| bfd_bread (stringbase, stringsize, abfd) != stringsize)
|
|
{
|
|
if (bfd_get_error () != bfd_error_system_call)
|
|
bfd_set_error (bfd_error_malformed_archive);
|
|
goto release_symdefs;
|
|
}
|
|
|
|
stringend = stringbase + stringsize;
|
|
*stringend = 0;
|
|
for (i = 0; i < nsymz; i++)
|
|
{
|
|
carsyms->file_offset = bfd_getb64 (raw_armap + i * 8);
|
|
carsyms->name = stringbase;
|
|
stringbase += strlen (stringbase);
|
|
if (stringbase != stringend)
|
|
++stringbase;
|
|
++carsyms;
|
|
}
|
|
|
|
ardata->symdef_count = nsymz;
|
|
ardata->first_file_filepos = bfd_tell (abfd);
|
|
/* Pad to an even boundary if you have to. */
|
|
ardata->first_file_filepos += (ardata->first_file_filepos) % 2;
|
|
|
|
abfd->has_armap = TRUE;
|
|
bfd_release (abfd, raw_armap);
|
|
|
|
return TRUE;
|
|
|
|
release_symdefs:
|
|
bfd_release (abfd, ardata->symdefs);
|
|
return FALSE;
|
|
}
|
|
|
|
/* Write out an Irix 6 armap. The Irix 6 tools are supposed to be
|
|
able to handle ordinary ELF armaps, but at least on Irix 6.2 the
|
|
linker crashes. */
|
|
|
|
bfd_boolean
|
|
_bfd_archive_64_bit_write_armap (bfd *arch,
|
|
unsigned int elength,
|
|
struct orl *map,
|
|
unsigned int symbol_count,
|
|
int stridx)
|
|
{
|
|
unsigned int ranlibsize = (symbol_count * 8) + 8;
|
|
unsigned int stringsize = stridx;
|
|
unsigned int mapsize = stringsize + ranlibsize;
|
|
file_ptr archive_member_file_ptr;
|
|
bfd *current = arch->archive_head;
|
|
unsigned int count;
|
|
struct ar_hdr hdr;
|
|
int padding;
|
|
bfd_byte buf[8];
|
|
|
|
padding = BFD_ALIGN (mapsize, 8) - mapsize;
|
|
mapsize += padding;
|
|
|
|
/* work out where the first object file will go in the archive */
|
|
archive_member_file_ptr = (mapsize
|
|
+ elength
|
|
+ sizeof (struct ar_hdr)
|
|
+ SARMAG);
|
|
|
|
memset (&hdr, ' ', sizeof (struct ar_hdr));
|
|
memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/"));
|
|
if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
|
|
return FALSE;
|
|
_bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
|
|
time (NULL));
|
|
/* This, at least, is what Intel coff sets the values to.: */
|
|
_bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0);
|
|
_bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", 0);
|
|
_bfd_ar_spacepad (hdr.ar_mode, sizeof (hdr.ar_mode), "%-7lo", 0);
|
|
memcpy (hdr.ar_fmag, ARFMAG, 2);
|
|
|
|
/* Write the ar header for this item and the number of symbols */
|
|
|
|
if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
|
|
!= sizeof (struct ar_hdr))
|
|
return FALSE;
|
|
|
|
bfd_putb64 ((bfd_vma) symbol_count, buf);
|
|
if (bfd_bwrite (buf, 8, arch) != 8)
|
|
return FALSE;
|
|
|
|
/* Two passes, first write the file offsets for each symbol -
|
|
remembering that each offset is on a two byte boundary. */
|
|
|
|
/* Write out the file offset for the file associated with each
|
|
symbol, and remember to keep the offsets padded out. */
|
|
count = 0;
|
|
for (current = arch->archive_head;
|
|
current != NULL && count < symbol_count;
|
|
current = current->archive_next)
|
|
{
|
|
/* For each symbol which is used defined in this object, write out
|
|
the object file's address in the archive. */
|
|
|
|
for (;
|
|
count < symbol_count && map[count].u.abfd == current;
|
|
count++)
|
|
{
|
|
bfd_putb64 ((bfd_vma) archive_member_file_ptr, buf);
|
|
if (bfd_bwrite (buf, 8, arch) != 8)
|
|
return FALSE;
|
|
}
|
|
|
|
/* Add size of this archive entry */
|
|
archive_member_file_ptr += sizeof (struct ar_hdr);
|
|
if (! bfd_is_thin_archive (arch))
|
|
archive_member_file_ptr += arelt_size (current);
|
|
/* remember about the even alignment */
|
|
archive_member_file_ptr += archive_member_file_ptr % 2;
|
|
}
|
|
|
|
/* now write the strings themselves */
|
|
for (count = 0; count < symbol_count; count++)
|
|
{
|
|
size_t len = strlen (*map[count].name) + 1;
|
|
|
|
if (bfd_bwrite (*map[count].name, len, arch) != len)
|
|
return FALSE;
|
|
}
|
|
|
|
/* The spec says that this should be padded to an 8 byte boundary.
|
|
However, the Irix 6.2 tools do not appear to do this. */
|
|
while (padding != 0)
|
|
{
|
|
if (bfd_bwrite ("", 1, arch) != 1)
|
|
return FALSE;
|
|
--padding;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|