summaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog548
-rw-r--r--binutils/Makefile.am706
-rw-r--r--binutils/Makefile.in1462
-rw-r--r--binutils/dlltool.c3678
-rw-r--r--binutils/dwarf.c4642
-rw-r--r--binutils/objdump.c3395
-rw-r--r--binutils/readelf.c10851
-rw-r--r--binutils/resrc.c3345
-rw-r--r--binutils/resres.c737
-rw-r--r--binutils/size.c611
-rw-r--r--binutils/windmc.c1206
11 files changed, 0 insertions, 31181 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
deleted file mode 100644
index 1023e26b0a4..00000000000
--- a/binutils/ChangeLog
+++ /dev/null
@@ -1,548 +0,0 @@
-2008-08-04 Alan Modra <amodra@bigpond.net.au>
-
- * Makefile.am (POTFILES.in): Set LC_ALL=C.
- * Makefile.in: Regenerate.
-
-2008-08-04 Markus Weiss <weissms@aros.org>
-
- * readelf.c (get_osabi_name <ELFOSABI_AROS>): Change name.
-
-2008-08-01 H.J. Lu <hongjiu.lu@intel.com>
-
- * dwarf.c (dwarf_regnames_i386): Remove AVX registers.
- (dwarf_regnames_x86_64): Likewise.
-
-2008-07-30 Alan Modra <amodra@bigpond.net.au>
-
- * dlltool.c, dwarf.c, objdump.c, readelf.c, resrc.c, resres.c,
- windmc.c: Silence gcc warnings.
-
-2008-07-28 Alan Modra <amodra@bigpond.net.au>
-
- * readelf.c (print_vma): Typo fix.
-
-2008-07-28 Alan Modra <amodra@bigpond.net.au>
-
- PR 6769
- * readelf.c (print_dec_vma, print_hex_vma): Delete.
- (print_vma): Use BFD_VMA_FMT.
- * size.c (size_number, rprint_number): Likewise.
-
-2008-07-26 Michael Eager <eager@eagercon.com>
-
- * readelf.c (display_power_gnu_attribute): Display
- single-precision hard float.
-
-2008-07-21 Luis Machado <luisgpm@br.ibm.com>
-
- * readelf.c (get_note_type): Handle VSX notes.
-
-2008-07-15 H.J. Lu <hongjiu.lu@intel.com>
-
- * objdump.c (load_debug_section): Initialize section_is_compressed
- for gcc 3.4/ia64.
- * readelf.c (load_debug_section): Likewise.
-
-2008-07-12 Jie Zhang <jie.zhang@analog.com>
-
- Revert
- 2008-07-12 Jie Zhang <jie.zhang@analog.com>
- * readelf.c (get_machine_flags): Deal with Blackfin specific
- flags.
-
-2008-07-12 Jie Zhang <jie.zhang@analog.com>
-
- * readelf.c (get_machine_flags): Deal with Blackfin specific
- flags.
-
-2008-07-09 Craig Silverstein <csilvers@google.com>
-
- * config.in: Add HAVE_ZLIB_H
- * configure.in: Add test for libz and zlib.h
- * configure: Regenerate.
- * dwarf.c (debug_displays): Add .zdebug_* strings.
- * dwarf.h (struct dwarf_section): Add fields uncompressed_namd
- and compressed_name.
- * objdump.c (load_debug_section): Call
- bfd_uncompress_section_contents when loading a compressed
- section.
- (dump_dwarf_section): Recognize compressed section name.
- (mach_o_dwarf_sections): Rename as
- mach_o_uncompressed_dwarf_sections.
- (mach_o_compressed_dwarf_sections): New variable.
- (generic_dwarf_section): Rename as
- generic_uncompressed_dwarf_sections.
- (generic_compressed_dwarf_sections): New variable.
- (check_mach_o_dwarf): Save and restore
- mach_o_compressed_dwarf_sections.
- * readelf.c: Add #include for config.h and zlib.h
- (process_section_headers): Recognize compressed section name.
- (uncompress_section_contents): New function.
- (load_debug_section): Call uncompress_section_contents when
- loading a compressed section.
- (display_debug_section): Recognize compressed section name.
-
-2008-07-07 Alan Modra <amodra@bigpond.net.au>
-
- * objdump.c (find_symbol_for_address): Prefer symbols in current
- section.
-
-2008-07-07 Alan Modra <amodra@bigpond.net.au>
-
- * ieee.c (write_ieee_debugging_info): Use bfd_make_section_with_flags.
- * nlmconv.c (main, powerpc_build_stubs): Likewise.
- * rescoff.c (write_coff_file): Likewise.
- * resres.c (write_res_file): Likewise.
- * windmc.c (windmc_write_bin): Likewise.
-
-2008-06-18 M R Swami Reddy <MR.Swami.Reddy@nsc.com>
-
- * readelf.c (guess_is_rela): Add EM_CR16_OLD.
- (dump_relocations): Likewise.
- (get_machine_name): Likewise.
- (is_32bit_abs_reloc): Likewise.
-
-2008-06-17 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
-
- * configure: Regenerate.
-
-2008-06-12 DJ Delorie <dj@redhat.com>
-
- * readelf.c (guess_is_rela): Add EM_M32C_OLD.
- (dump_relocations): Likewise.
- (process_section_headers): Likewise.
- (is_32bit_abs_reloc): Likewise.
- (is_16bit_abs_reloc): Likewise.
-
-2008-06-12 Nick Clifton <nickc@redhat.com>
-
- PR binutils/6483
- * objdump.c (dump_bfd): If the -g option found no STABS or IEEE
- debug information to display, try dumping DWARF information
- instead.
- * rddbg.c (read_debugging_info): Add a parameter to suppress the
- display of a warning message when no debug information is found.
- * budbg.h (read_debugging_info): Update prototype.
- * objcopy.c (copy_object): Continue to allow read_debugging_info
- to produce warning messages.
- * doc/binutils.texi (--debugging): Document new behaviour of the
- -g/--debugging option.
-
-2008-06-10 Ben Elliston <bje@gnu.org>
-
- * MAINTAINERS: Remove myself as m68k maintainer.
-
-2008-05-14 Alan Modra <amodra@bigpond.net.au>
-
- * Makefile.in: Regenerate.
- * doc/Makefile.in: Regenerate.
-
-2008-05-12 Alan Modra <amodra@bigpond.net.au>
-
- * embedspu.sh: Test for presence of ._ea by looking at section
- table rather than looking at relocs. Correct toe_addr substitution.
-
-2008-05-08 Alan Modra <amodra@bigpond.net.au>
-
- * embedspu.sh: Take note of R_SPU_PPU32/64 relocs without a symbol,
- and if present, put image in ".data.speelf". Put program handle
- in ".data.spehandle".
-
-2008-05-01 Nick Clifton <nickc@redhat.com>
-
- * readelf.c (print_symbol): Add code to display non-printing
- characters.
-
-2008-04-30 John Heidemann <johnh@isi.edu>
-
- * doc/binutils.texi (strings): Add "unicode" to the documentation
- of strings in order to make explicit that it supports this
- feature.
-
-2008-04-30 Alan Modra <amodra@bigpond.net.au>
-
- * readelf.c (process_program_headers): Correct section in segment
- display.
-
-2008-04-28 M Thomas <mthomas@rhrk.uni-kl.de>
- Nick Clifton <nickc@redhat.com>
-
- PR binutils/6449
- * objdump.c (slurp_file): Open the file in binary mode.
- * ar.c: Remove conditional definition of O_BINARY.
- * bin2.c: Likewise.
- * rename.c: Likewise.
- * strings.c: Likewise.
- * sysdep.h: Add conditional definition of O_BINARY.
-
-2008-04-23 Paolo Bonzini <bonzini@gnu.org>
-
- * aclocal.m4: Regenerate.
- * configure: Regenerate.
-
-2008-04-16 Jean-Yves Lefort <jylefort@brutele.be>
-
- PR binutils/6034
- * objcopy.c (stuct symlist): Rename to
- is_specified_symbol_predicate_data.
- (strip_specific_list): Rename to strip_specific_htab.
- (strip_unneeded_list): Rename to strip_unneeded_htab.
- (keep_specific_list): Rename to keep_specific_htab.
- (localize_specific_list): Rename to localize_specific_htab.
- (globalize_specific_list): Rename to globalize_specific_htab.
- (keepglobal_specific_list): Rename to keepglobal_specific_htab.
- (weaken_specific_list): Rename to weaken_specific_htab.
- (eq_string): New function.
- (create_symbol_htab): New function.
- (create_symbol_htabs): New function.
- (add_specific_symbol): Change to use hash tables.
- (is_specified_symbol_predicate): New function.
- (is_specified_symbol): Use hash table lookup.
- (is_strip_section): Update to use new functions and hash tables.
- (filter_symbols): Likewise.
- (copy_object): Likewise.
- (copy_section): Likewise.
- (strip_main): Likewise.
- (copy_main): Likewise.
- (main): Likewise.
-
-2008-04-14 David S. Miller <davem@davemloft.net>
-
- * readelf.c (get_gnu_elf_note_type): Recognize NT_GNU_GOLD_VERSION.
-
-2008-04-11 Torleif Sandnes <torleif.sandnes@gmail.com>
-
- * dwarf.c (display_debug_lines): Rename to
- display_debug_lines_raw.
- (display_debug_lines_decoded): New function. Displays the
- interpreted contents of a .debug_line section.
- (display_debug_lines): New function: Selects either a raw dump or
- a decoded dump (or both) as requested by the user.
- * dwarf.h (do_debug_lines_decoded): New extern.
- * readelf.c: Add support for -wL or --debug-dump=decodedline
- option to display the decoded contents of a .debug_line section.
- * doc/binutils.texi: Document the new option.
- * NEWS: Mention the new feature.
-
-2008-04-08 Alan Modra <amodra@bigpond.net.au>
-
- * dwarf.c: Remove trailing whitespace throughout file.
-
-2008-04-04 Nick Clifton <nickc@redhat.com>
-
- * po/sk.po: Updated Slovak translation.
-
-2008-04-03 H.J. Lu <hongjiu.lu@intel.com>
-
- * dwarf.c (dwarf_regnames_i386): Add AVX registers.
- (dwarf_regnames_x86_64): Likewise.
-
-2008-03-27 Cary Coutant <ccoutant@google.com>
-
- Add support for thin archives.
- * ar.c (make_thin_archive): New global flag.
- (map_over_members): Deal with full pathnames in thin archives.
- (usage, main): Add 'T' option for building thin archives.
- (replace_members): Pass thin archive flag to ar_emul_append.
- * arsup.c (ar_open): Initialize new flag.
- * binemul.c (ar_emul_append): Add new parameter for
- flattening nested archives.
- (do_ar_emul_default_append): New function.
- (ar_emul_default_append): Factored out recursive code.
- * binutils/binemul.h (ar_emul_default_append): Add new parameter.
- (struct bin_emulation_xfer_struct): New parameter for ar_append.
- * dlltool.c (gen_lib_file): Initialize thin archive flag.
- * emul_aix.c (ar_emul_aix_internal): Add new flatten
- parameter, currently unimplemented.
- All callers changed.
- * objcopy.c (copy_archive): Preserve thin archive flag.
- * doc/binutils.texi: Update ar documentation.
- * NEWS: Mention the new feature.
-
-2008-03-20 H.J. Lu <hongjiu.lu@intel.com>
-
- * readelf.c (process_mips_specific): Declare addr_size as int.
-
-2008-03-20 Richard Sandiford <rsandifo@nildram.co.uk>
-
- * readelf.c (print_mips_got_entry): New function.
- (process_mips_specific): Print GOT information.
-
-2008-03-17 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
-
- * aclocal.m4: Regenerate.
- * configure: Likewise.
- * Makefile.in: Likewise.
- * doc/Makefile.in: Likewise.
-
-2008-03-16 Brian Dessent <brian@dessent.net>
-
- * rcparse.y (resid): Allow control text to span multiple lines.
-
-2008-03-13 Alan Modra <amodra@bigpond.net.au>
-
- * readelf.c: Use %u throughout when printing sh_link or sh_info,
- %lu when printing sh_addralign.
- (process_version_sections): Use identical formats when printing
- all offset and sh_link fields.
-
-2008-03-13 Alan Modra <amodra@bigpond.net.au>
-
- * Makefile.am: Run "make dep-am".
- * Makefile.in: Regenerate.
- * doc/Makefile.in: Regenerate.
- * configure: Regenerate.
-
-2008-03-12 Alan Modra <amodra@bigpond.net.au>
-
- PR 5900
- * readelf.c (SECTION_HEADER_INDEX, SECTION_HEADER_NUM): Delete.
- Remove use throughout file.
- (SECTION_HEADER): Likewise.
- (dump_relocations): Don't adjust st_shndx for reserved range.
- (process_file_header): Mask SHN_XINDEX to values seen in external
- elf structs. Simplify valid section index tests.
- (get_32bit_elf_symbols, get_64bit_elf_symbols): Mask SHN_XINDEX.
- Map reserved st_shndx to internal form.
- (process_section_groups): Test that group symbol st_shndx is in
- range, not just non-zero. Delete reserved range check.
- (get_symbol_index_type): Mask "type" to 16 bits when printing PRC,
- OS or RSV.
-
-2008-03-09 Paul Brook <paul@codesourcery.com>
-
- * readelf.c (arm_attr_tag_VFP_arch): Add "VFPv3-D16".
-
-2008-03-03 James E. Wilson <wilson@tuliptree.org>
-
- * MAINTAINERS: Update my email address.
-
-2008-03-03 Nick Clifton <nickc@redhat.com>
-
- * dwarf.c (decode_location_expression): Handle
- DW_OP_PGI_omp_thread_num.
-
-2008-03-01 Alan Modra <amodra@bigpond.net.au>
-
- * objdump.c (objdump_print_addr): Initialise "sym".
-
-2008-02-27 Justin Pryzby <justinpryzby@users.sourceforge.net>
- Nick Clifton <nickc@redhat.com>
-
- * ar.c (usage): Mention -t command line switch.
- * doc/binutils.texi (ranlib): Document -t command line switch.
-
-2008-02-26 Nick Clifton <nickc@redhat.com>
-
- * objdump.c (objdump_print_addr): If displaying file offsets, show
- the offset even if there are no symbols available.
- (dump_section): Display nothing if none of the section is going to
- be dumped. Display the file offset, if requested, of the location
- from where the dump starts.
- * doc/binutils.texi (objdump): Mention that dumping via the -s
- switch is also affected by the -F option.
-
-2008-02-26 Nick Clifton <nickc@redhat.com>
-
- Re-apply this patch which was accidentally deleted:
- 2006-05-16 Carlos O'Donell <carlos@codesourcery.com>
-
- * doc/binutils.texi: Use "Binutils Index" for index name.
-
-2008-02-22 Nick Clifton <nickc@redhat.com>
-
- * objdump.c (display_file_offsets): New variable.
- (long_options): Add -F/--file-offsets.
- (objdump_print_addr_with_sym): If displaying file offsets, print
- the offset of the given address.
- (disassemble_bytes): If displaying file offsets, tell the user how
- many zeroes are skipped and the file offset of the point where
- dumping resumes.
- (disassemble_section): Only display the name of the section if
- data is going to be dumped from it.
- (main): Handle new option. Produce error messages if the start or
- stop addresses do not make sense.
- * doc/binutils.texi: Document the new feature.
- * NEWS: Mention the new feature.
-
-2008-02-15 Chu Li <chul@cn.fujitsu.com>
- Nick Clifton <nickc@redhat.com>
-
- PR binutils/5713
- * strings.c (integer_arg): Delete function.
- (string_min): Initialise to 4.
- (main): Use strtoul to parse integer arguments.
- Move check for an invalid string length to after all the arguments
- have been parsed.
- (usage): Use indentation to indicate that -<n> is a another form
- of the --bytes= command line option.
-
-2008-02-12 Nick Clifton <nickc@redhat.com>
-
- * dlltool.c (mcore_elf_cache_filename): Add a const qualifier to
- the argument.
- (scan_obj_filename): Do not drop the const qualifier when calling
- mcore_elf_cache_filename.
- (struct fname_cache): Add const qualifier to filename field.
-
-2008-02-08 H.J. Lu <hongjiu.lu@intel.com>
-
- PR binutils/5713
- * strings.c (main): Set string_min to 4 if it is <= 0.
-
-2008-02-07 Alan Modra <amodra@bigpond.net.au>
-
- * objdump.c (main): Don't pass unadorned NULL to concat.
-
-2008-02-04 H.J. Lu <hongjiu.lu@intel.com>
-
- PR 5715
- * configure: Regenerated.
-
-2008-02-03 Adam Nemet <anemet@caviumnetworks.com>
-
- * readelf.c (get_machine_flags): Handle Octeon.
-
-2008-01-30 Tristan Gingold <gingold@adacore.com>
-
- * readelf.c (dump_relocations): Decode OpenVMS-specific sections.
- (get_ia64_dynamic_type): Decode OpenVMS-specific tags.
- (get_dynamic_type): Handle IA64-specific tags.
- (get_ia64_section_type_name): Handle OpenVMS-specific sections.
- (get_section_type_name): Handle OS-specific sections (and
- particularly IA64 OpenVMS one).
- (get_elf_section_flags): Makes flags static. Add entries for IA64 and
- decode them.
-
-2008-01-29 Nick Clifton <nickc@redhat.com>
-
- * dwarf.c (print_dwarf_vma): New function. Display the value of a
- dwarf_vma type at a specified precision. Use mingw field type
- specifier if necessary.
- (display_debug_loc): Use dwarf_vma type for begin and end values.
- Use print_dwarf_vma to display their values. Use byte_get_signed
- in order to correctly detect the -1 escape value.
- (display_debug_aranges): Likewise.
- (display_debug_ranges): Likewise.
-
-2008-01-29 Alan Modra <amodra@bigpond.net.au>
-
- * dwarf.c (display_debug_loc): Correct test for base address
- entry when 64-bit host dumping 32-bit object.
-
-2008-01-29 Alan Modra <amodra@bigpond.net.au>
-
- * MAINTAINERS: Remove myself as ix86 maintainer. Add for SPU.
-
-2008-01-28 Nick Clifton <nickc@redhat.com>
-
- PR binutils/5529
- * rclex.c (yylex): Also allow the hypen character.
-
-2008-01-28 H.J. Lu <hongjiu.lu@intel.com>
-
- * dwarf.c: Include "elf/common.h".
- (eh_addr_size): Changed to int.
- (dwarf_regnames_i386): New.
- (dwarf_regnames_x86_64): Likewise.
- (dwarf_regnames): Likewise.
- (dwarf_regnames_count): Likewise.
- (init_dwarf_regnames): Likewise.
- (regname): Likewise.
- (frame_display_row): Properly support different address size.
- Call regname to get register name.
- (display_debug_frames): Call regname to get register name.
- Display DW_CFA_def_cfa_register as DW_CFA_def_cfa_register
- instead of DW_CFA_def_cfa_reg.
-
- * dwarf.h (init_dwarf_regnames): New.
-
- * objdump.c: Include "elf-bfd.h".
- (dump_dwarf): Call init_dwarf_regnames on ELF input.
-
- * readelf.c (guess_is_rela): Change argument to int.
- (parse_args): Remove the undocumented upper case options for
- -wX.
- (process_file_header): Call init_dwarf_regnames.
-
-2008-01-25 DJ Delorie <dj@redhat.com>
-
- * readelf.c (process_section_headers): Add m16c handler.
- (is_16bit_abs_reloc): Recognize R_M32C_16.
-
-2008-01-25 Kai Tietz <kai.tietz@onevision.com>
-
- * prdbg.c: Correct formatter style use.
- * readelf.c: Likewise.
- * strings.c: Likewise.
-
-2008-01-25 Nick Clifton <nickc@redhat.com>
-
- * po/ru.po: Updated Russian translation.
-
-2008-01-17 H.J. Lu <hjl.tools@gmail.com>
-
- * MAINTAINERS: Update my email address.
-
-2008-01-14 Nick Clifton <nickc@redhat.com>
-
- * dwarf.c (process_debug_info): Include the CU offset and corrupt
- version value when reporting unrecognised DWARF version numbers.
- (load_debug_info): Remember a failed attempt to load and parse the
- .debug_info section and do not repeat such attempts.
- (display_debug_lines): Check the return value from load_debug_info
- and return whilst displaying a warning message if the load failed.
- (display_debug_loc): Likewise.
- (display_debug_ranges): Likewise.
- (DEBUG_INFO_UNAVAILABLE): Value stored in num_debug_info_entries
- when the .debug_info section could not be loaded/parsed.
- (process_debug_info): Display the length of the compilation unit
- in hex, so that it corresponds with the offsets that will follow.
- Tell the user if the length was 32-bit or 64-bit.
- If a DIE abbreviation could not be found, tell the user the offset
- of the DIE.
- (free_debug_memory): Do not attempt to free any entries in the
- debug_information array if num_debug_info_entries is set to
- DEBUG_INFO_UNAVAILABLE.
-
-2008-01-10 Andreas Schwab <schwab@suse.de>
-
- * readelf.c (is_64bit_abs_reloc): Handle R_S390_64.
-
-2008-01-09 Jakub Zawadzki <darkjames@darkjames.ath.cx>
-
- PR binutils/55326
- * bucomm.c (list_supported_architectures): Free architecture list
- after use.
- * windres.c (set_endianess): Likewise.
- * windmc.c (set_endianess): Likewise.
-
-2008-01-08 Kai Tietz <kai.tietz@onevision.com>
-
- PR binutils/5529
- * binutils/rclex.c: (yylex): Add ':', '_', '\\', and '/' to post
- characters for name tokens.
-
-2008-01-04 Greg McGary <greg@mcgary.org>
-
- * prdbg.c (print_vma): Print as long long, if host supports it.
-
-2008-01-03 Nick Clifton <nickc@redhat.com>
-
- * dwarf.c (read_and_display_attr_value): Prefix values that are
- displayed in hexadecimal with 0x.
- For the DW_AT_import attribute display the abbreviation number and
- tag of the imported DIE.
- (process_debug_info): Warn about lengths that reserved by the
- DWARF3 specification.
- Provide more information when corrupted DIEs are detected.
- Warn if DIE corruption makes the sibling level negative.
-
-For older changes see ChangeLog-2007
-
-Local Variables:
-mode: change-log
-left-margin: 8
-fill-column: 74
-version-control: never
-End:
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
deleted file mode 100644
index 3a1d19a1fa0..00000000000
--- a/binutils/Makefile.am
+++ /dev/null
@@ -1,706 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AUTOMAKE_OPTIONS = cygnus dejagnu
-ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
-
-SUBDIRS = doc po
-
-tooldir = $(exec_prefix)/$(target_alias)
-
-## These aren't set by automake, because they appear in
-## bfd/acinclude.m4, which is included by binutils/acinclude.m4, and
-## thus is not seen by automake.
-CC_FOR_BUILD = @CC_FOR_BUILD@
-EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
-
-YACC = `if [ -f ../bison/bison ]; then echo ../bison/bison -y -L$(srcdir)/../bison/; else echo @YACC@; fi`
-YFLAGS = -d
-LEX = `if [ -f ../flex/flex ]; then echo ../flex/flex; else echo @LEX@; fi`
-
-WARN_CFLAGS = @WARN_CFLAGS@
-NO_WERROR = @NO_WERROR@
-AM_CFLAGS = $(WARN_CFLAGS)
-LIBICONV = @LIBICONV@
-
-# these two are almost the same program
-AR_PROG=ar
-RANLIB_PROG=ranlib
-
-# objcopy and strip should be the same program
-OBJCOPY_PROG=objcopy
-STRIP_PROG=strip-new
-
-STRINGS_PROG=strings
-
-READELF_PROG=readelf
-
-# These should all be the same program too.
-SIZE_PROG=size
-NM_PROG=nm-new
-OBJDUMP_PROG=objdump
-
-# This is the demangler, as a standalone program.
-# Note: This one is used as the installed name too, unlike the above.
-DEMANGLER_PROG=cxxfilt
-
-ADDR2LINE_PROG=addr2line
-
-NLMCONV_PROG=nlmconv
-DLLTOOL_PROG=dlltool
-WINDRES_PROG=windres
-WINDMC_PROG=windmc
-DLLWRAP_PROG=dllwrap
-
-SRCONV_PROG=srconv$(EXEEXT) sysdump$(EXEEXT) coffdump$(EXEEXT)
-
-bin_PROGRAMS = $(SIZE_PROG) $(OBJDUMP_PROG) $(AR_PROG) $(STRINGS_PROG) $(RANLIB_PROG) $(OBJCOPY_PROG) @BUILD_NLMCONV@ @BUILD_SRCONV@ @BUILD_DLLTOOL@ @BUILD_WINDRES@ @BUILD_WINDMC@ $(ADDR2LINE_PROG) $(READELF_PROG) @BUILD_DLLWRAP@ @BUILD_INSTALL_MISC@
-
-## We need a special rule to install the programs which are built with
-## -new, and to rename cxxfilt to c++filt.
-RENAMED_PROGS = $(NM_PROG) $(STRIP_PROG) $(DEMANGLER_PROG)
-noinst_PROGRAMS = $(RENAMED_PROGS) @BUILD_MISC@
-
-EXTRA_PROGRAMS = $(NLMCONV_PROG) srconv sysdump coffdump $(DLLTOOL_PROG) $(WINDRES_PROG) $(WINDMC_PROG) $(DLLWRAP_PROG)
-
-# Stuff that goes in tooldir/ if appropriate.
-TOOL_PROGS = nm-new strip-new ar ranlib dlltool objdump objcopy
-
-BASEDIR = $(srcdir)/..
-BFDDIR = $(BASEDIR)/bfd
-INCDIR = $(BASEDIR)/include
-
-MKDEP = gcc -MM
-
-INCLUDES = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) \
- @HDEFINES@ \
- @INCINTL@ \
- -DLOCALEDIR="\"$(datadir)/locale\"" \
- -Dbin_dummy_emulation=$(EMULATION_VECTOR)
-
-HFILES = \
- arsup.h binemul.h bucomm.h budbg.h \
- coffgrok.h debug.h dlltool.h dwarf.h nlmconv.h \
- sysdep.h unwind-ia64.h windres.h winduni.h windint.h \
- windmc.h
-
-GENERATED_HFILES = arparse.h sysroff.h sysinfo.h defparse.h rcparse.h mcparse.h
-
-CFILES = \
- addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
- coffdump.c coffgrok.c cxxfilt.c \
- dwarf.c debug.c dlltool.c dllwrap.c \
- emul_aix.c emul_vanilla.c filemode.c \
- ieee.c is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \
- nlmconv.c nm.c not-ranlib.c not-strip.c \
- objcopy.c objdump.c prdbg.c \
- rclex.c rdcoff.c rddbg.c readelf.c rename.c \
- resbin.c rescoff.c resrc.c resres.c \
- size.c srconv.c stabs.c strings.c sysdump.c \
- unwind-ia64.c version.c \
- windres.c winduni.c wrstabs.c \
- windmc.c mclex.c
-
-GENERATED_CFILES = \
- arparse.c arlex.c sysroff.c sysinfo.c syslex.c \
- defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
-
-DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
-
-# Code shared by all the binutils.
-BULIBS = bucomm.c version.c filemode.c
-
-BFDLIB = ../bfd/libbfd.la
-
-OPCODES = ../opcodes/libopcodes.la
-
-LIBIBERTY = ../libiberty/libiberty.a
-
-.PHONY: install-html install-html-am install-html-recursive
-
-install-html: install-html-recursive
-
-install-html-recursive:
- @failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
- dot_seen=no; \
- target=`echo $@ | sed s/-recursive//`; \
- list='$(SUBDIRS)'; for subdir in $$list; do \
- echo "Making $$target in $$subdir"; \
- if test "$$subdir" = "."; then \
- dot_seen=yes; \
- local_target="$$target-am"; \
- else \
- local_target="$$target"; \
- fi; \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
- || eval $$failcom; \
- done; \
- if test "$$dot_seen" = "no"; then \
- $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
- fi; test -z "$$fail"
-
-POTFILES = $(CFILES) $(DEBUG_SRCS) $(HFILES)
-po/POTFILES.in: @MAINT@ Makefile
- for f in $(POTFILES); do echo $$f; done | LC_ALL=C sort > tmp \
- && mv tmp $(srcdir)/po/POTFILES.in
-
-EXPECT = expect
-RUNTEST = runtest
-
-CC_FOR_TARGET = ` \
- if [ -f $$r/../gcc/xgcc ] ; then \
- if [ -f $$r/../newlib/Makefile ] ; then \
- echo $$r/../gcc/xgcc -B$$r/../gcc/ -idirafter $$r/../newlib/targ-include -idirafter $${srcroot}/../newlib/libc/include -nostdinc; \
- else \
- echo $$r/../gcc/xgcc -B$$r/../gcc/; \
- fi; \
- else \
- if [ "@host@" = "@target@" ] ; then \
- echo $(CC); \
- else \
- echo gcc | sed '$(transform)'; \
- fi; \
- fi`
-
-check-DEJAGNU: site.exp
- srcdir=`cd $(srcdir) && pwd`; export srcdir; \
- r=`pwd`; export r; \
- EXPECT=$(EXPECT); export EXPECT; \
- runtest=$(RUNTEST); \
- if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
- CC_FOR_TARGET="$(CC_FOR_TARGET)" CFLAGS_FOR_TARGET="$(CFLAGS)" \
- $$runtest --tool $(DEJATOOL) --srcdir $${srcdir}/testsuite \
- $(RUNTESTFLAGS); \
- else echo "WARNING: could not find \`runtest'" 1>&2; :;\
- fi
-
-installcheck:
- /bin/sh $(srcdir)/sanity.sh $(bindir)
-
-# There's no global DEPENDENCIES. So, we must explicitly list everything
-# which depends on libintl, since we don't know whether LIBINTL_DEP will be
-# non-empty until configure time. Ugh!
-size_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES)
-nm_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-ar_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-strings_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-strip_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-ranlib_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-cxxfilt_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-objcopy_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-nlmconv_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-srconv_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-sysdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-coffdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-dlltool_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-windres_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-windmc_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-addr2line_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
-dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
-
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
-
-size_SOURCES = size.c $(BULIBS)
-
-objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
-
-strings_SOURCES = strings.c $(BULIBS)
-
-readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c
-readelf_LDADD = $(LIBINTL) $(LIBIBERTY)
-
-strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
-
-nm_new_SOURCES = nm.c $(BULIBS)
-
-objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS)
-objdump_LDADD = $(OPCODES) $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
-
-objdump.o:objdump.c
- $(COMPILE) -c $(OBJDUMP_DEFS) $(srcdir)/objdump.c
-
-cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
-
-ar_SOURCES = arparse.y arlex.l ar.c not-ranlib.c arsup.c rename.c binemul.c \
- emul_$(EMULATION).c $(BULIBS)
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-
-ranlib_SOURCES = ar.c is-ranlib.c arparse.y arlex.l arsup.c rename.c \
- binemul.c emul_$(EMULATION).c $(BULIBS)
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-
-addr2line_SOURCES = addr2line.c $(BULIBS)
-
-# The following is commented out for the conversion to automake.
-# This rule creates a single binary that switches between ar and ranlib
-# by looking at argv[0]. Use this kludge to save some disk space.
-# However, you have to install things by hand.
-# (That is after 'make install', replace the installed ranlib by a link to ar.)
-# Alternatively, you can install ranlib.sh as ranlib.
-# ar_with_ranlib: $(ADDL_DEPS) ar.o maybe-ranlib.o
-# $(HLDENV) $(CC) $(HLDFLAGS) $(CFLAGS) $(LDFLAGS) -o $(AR_PROG) ar.o maybe-ranlib.o $(ADDL_LIBS) $(EXTRALIBS)
-# -rm -f $(RANLIB_PROG)
-# -ln $(AR_PROG) $(RANLIB_PROG)
-#
-# objcopy and strip in one binary that uses argv[0] to decide its action.
-#
-#objcopy_with_strip: $(ADDL_DEPS) objcopy.o maybe-strip.o
-# $(HLDENV) $(CC) $(HLDFLAGS) $(CFLAGS) $(LDFLAGS) -o $(OBJCOPY_PROG) objcopy.o maybe-strip.o $(ADDL_LIBS) $(EXTRALIBS)
-# -rm -f $(STRIP_PROG)
-# -ln $(OBJCOPY_PROG) $(STRIP_PROG)
-
-sysroff.c: sysinfo$(EXEEXT_FOR_BUILD) sysroff.info
- ./sysinfo$(EXEEXT_FOR_BUILD) -c <$(srcdir)/sysroff.info >sysroff.c
- ./sysinfo$(EXEEXT_FOR_BUILD) -i <$(srcdir)/sysroff.info >>sysroff.c
- ./sysinfo$(EXEEXT_FOR_BUILD) -g <$(srcdir)/sysroff.info >>sysroff.c
-
-sysroff.h: sysinfo$(EXEEXT_FOR_BUILD) sysroff.info
- ./sysinfo$(EXEEXT_FOR_BUILD) -d <$(srcdir)/sysroff.info >sysroff.h
-
-sysinfo$(EXEEXT_FOR_BUILD): sysinfo.o syslex.o
- $(CC_FOR_BUILD) $(CFLAGS) $(LDFLAGS) -o $@ sysinfo.o syslex.o
-
-syslex.o:
- if [ -r syslex.c ]; then \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) syslex.c -Wno-error ; \
- else \
- $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS) $(srcdir)/syslex.c -Wno-error ;\
- fi
-
-sysinfo.o:
- if [ -r sysinfo.c ]; then \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) sysinfo.c -Wno-error ; \
- else \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) $(srcdir)/sysinfo.c -Wno-error ; \
- fi
-
-bin2c$(EXEEXT_FOR_BUILD):
- $(CC_FOR_BUILD) -o $@ $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) $(srcdir)/bin2c.c $(srcdir)/version.c
-
-embedspu: embedspu.sh
- sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@
- chmod a+x $@
-
-# We need these for parallel make.
-arparse.h: arparse.c
-defparse.h: defparse.c
-nlmheader.h: nlmheader.c
-rcparse.h: rcparse.c
-mcparse.h: mcparse.c
-sysinfo.h: sysinfo.c
-
-# Disable -Werror, if it has been enabled, since old versions of bison/
-# yacc will produce working code which contain compile time warnings.
-arparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-arlex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-sysroff.o:
- $(COMPILE) -c $< $(NO_WERROR)
-defparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-deflex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-nlmheader.o:
- $(COMPILE) -c $< $(NO_WERROR)
-rcparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-mcparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-rclex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-mclex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-
-srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
-
-dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-
-dlltool.o:
- $(COMPILE) -c $(DLLTOOL_DEFS) $(srcdir)/dlltool.c
-
-rescoff.o:
- $(COMPILE) -c $(DLLTOOL_DEFS) $(srcdir)/rescoff.c
-
-coffdump_SOURCES = coffdump.c coffgrok.c $(BULIBS)
-
-sysdump_SOURCES = sysdump.c $(BULIBS)
-
-# coff/sym.h and coff/ecoff.h won't be found by the automatic dependency
-# scripts, since they are only included conditionally.
-nlmconv.o: nlmconv.c $(INCDIR)/coff/sym.h $(INCDIR)/coff/ecoff.h
- ldname=`echo ld | sed '$(transform)'`; \
- $(COMPILE) -c -DLD_NAME="\"$${ldname}\"" @NLMCONV_DEFS@ $(srcdir)/nlmconv.c
-
-nlmconv_SOURCES = nlmconv.c nlmheader.y $(BULIBS)
-
-windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
- winduni.c resres.c $(BULIBS)
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL) $(LIBICONV)
-
-windmc_SOURCES = windmc.c mcparse.y mclex.c \
- winduni.c $(BULIBS)
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL) $(LIBICONV)
-
-dllwrap_SOURCES = dllwrap.c version.c
-dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
-
-
-EXTRA_DIST = arparse.c arparse.h arlex.c nlmheader.c sysinfo.c sysinfo.h \
- syslex.c deflex.c defparse.h defparse.c rcparse.h rcparse.c \
- mcparse.h mcparse.c
-
-diststuff: $(EXTRA_DIST) info
-all: info
-
-DISTCLEANFILES = sysroff.c sysroff.h site.exp site.bak
-
-# Targets to rebuild dependencies in this Makefile.
-# Have to get rid of DEP1 here so that "$?" later includes all of $(CFILES).
-DEP: dep.sed $(CFILES) $(HFILES) $(GENERATED_CFILES) $(GENERATED_HFILES) config.h
- rm -f DEP1
- $(MAKE) MKDEP="$(MKDEP)" DEP1
- sed -f dep.sed < DEP1 > DEPA
- echo '# IF YOU PUT ANYTHING HERE IT WILL GO AWAY' >> DEPA
- if grep ' /' DEPA > /dev/null 2> /dev/null; then \
- echo 'make DEP failed!'; exit 1; \
- else \
- mv -f DEPA $@; \
- fi
-
-DEP1: $(CFILES) $(GENERATED_CFILES)
- echo '# DO NOT DELETE THIS LINE -- mkdep uses it.' > DEP2
- echo '# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.' >> DEP2
- $(MKDEP) $(INCLUDES) $(CFLAGS) $? >> DEP2
- mv -f DEP2 $@
-
-dep.sed: dep-in.sed config.status
- objdir=`pwd`; \
- sed <$(srcdir)/dep-in.sed >dep.sed \
- -e 's!@INCDIR@!$(INCDIR)!' \
- -e 's!@BFDDIR@!$(BFDDIR)!' \
- -e 's!@SRCDIR@!$(srcdir)!' \
- -e "s!@OBJDIR@!$${objdir}!" \
- -e 's!@TOPDIR@!'`echo $(srcdir) | sed -e s,/binutils$$,,`'!'
-
-dep: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < Makefile > tmp-Makefile
- cat DEP >> tmp-Makefile
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile Makefile
-
-dep-in: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < $(srcdir)/Makefile.in > tmp-Makefile.in
- cat DEP >> tmp-Makefile.in
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile.in $(srcdir)/Makefile.in
-
-dep-am: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < $(srcdir)/Makefile.am > tmp-Makefile.am
- cat DEP >> tmp-Makefile.am
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile.am $(srcdir)/Makefile.am
-
-.PHONY: dep dep-in dep-am
-
-###
-
-MOSTLYCLEANFILES = sysinfo$(EXEEXT_FOR_BUILD) bin2c$(EXEEXT_FOR_BUILD) \
- binutils.log binutils.sum abcdefgh*
-mostlyclean-local:
- -rm -rf tmpdir
-
-CLEANFILES = dep.sed DEP DEPA DEP1 DEP2
-
-.PHONY: install-exec-local
-
-install-exec-local: install-binPROGRAMS $(bin_PROGRAMS) $(noinst_PROGRAMS)
- @list='$(RENAMED_PROGS)'; for p in $$list; do \
- if test -f $$p$(EXEEXT); then \
- echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p$(EXEEXT) $(bindir)/`echo $$p|sed -e 's/-new//' -e 's/cxxfilt/$(DEMANGLER_NAME)/'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
- $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p$(EXEEXT) $(DESTDIR)$(bindir)/`echo $$p|sed -e 's/-new//' -e 's/cxxfilt/$(DEMANGLER_NAME)/'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
- else :; fi; \
- done
- $(mkinstalldirs) $(DESTDIR)$(tooldir)/bin
- for i in $(TOOL_PROGS); do \
- if [ -f $$i$(EXEEXT) ]; then \
- j=`echo $$i | sed -e 's/-new//'`; \
- k=`echo $$j | sed '$(transform)'`; \
- if [ "$(bindir)/$$k" != "$(tooldir)/bin/$$j" ]; then \
- rm -f $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT); \
- ln $(DESTDIR)$(bindir)/$$k$(EXEEXT) $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT) >/dev/null 2>/dev/null \
- || $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$i$(EXEEXT) $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT); \
- fi; \
- else true; \
- fi; \
- done
-
-# What appears below is generated by a hacked mkdep using gcc -MM.
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
-addr2line.o: addr2line.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- bucomm.h
-ar.o: ar.c sysdep.h config.h $(INCDIR)/ansidecl.h ../bfd/bfdver.h \
- $(INCDIR)/fopen-same.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/progress.h $(INCDIR)/aout/ar.h $(BFDDIR)/libbfd.h \
- $(INCDIR)/hashtab.h bucomm.h arsup.h $(INCDIR)/filenames.h \
- binemul.h
-arsup.o: arsup.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/filenames.h bucomm.h \
- arsup.h
-bin2c.o: bin2c.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-binemul.o: binemul.c binemul.h sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-bucomm.o: bucomm.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/filenames.h $(BFDDIR)/libbfd.h \
- $(INCDIR)/hashtab.h bucomm.h
-coffdump.o: coffdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h coffgrok.h
-coffgrok.o: coffgrok.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h \
- $(INCDIR)/bfdlink.h bucomm.h coffgrok.h
-cxxfilt.o: cxxfilt.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- $(INCDIR)/safe-ctype.h bucomm.h
-dwarf.o: dwarf.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h bucomm.h $(INCDIR)/elf/common.h \
- $(INCDIR)/elf/dwarf2.h dwarf.h
-debug.o: debug.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h debug.h
-dlltool.o: dlltool.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- $(INCDIR)/dyn-string.h bucomm.h dlltool.h $(INCDIR)/safe-ctype.h
-dllwrap.o: dllwrap.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/dyn-string.h bucomm.h
-emul_aix.o: emul_aix.c binemul.h sysdep.h config.h \
- $(INCDIR)/ansidecl.h ../bfd/bfdver.h $(INCDIR)/fopen-same.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- bucomm.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/internal.h \
- $(INCDIR)/coff/xcoff.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h \
- $(BFDDIR)/libxcoff.h
-emul_vanilla.o: emul_vanilla.c binemul.h sysdep.h config.h \
- $(INCDIR)/ansidecl.h ../bfd/bfdver.h $(INCDIR)/fopen-same.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- bucomm.h
-filemode.o: filemode.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-ieee.o: ieee.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/ieee.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h debug.h \
- budbg.h $(INCDIR)/filenames.h
-is-ranlib.o: is-ranlib.c
-is-strip.o: is-strip.c
-maybe-ranlib.o: maybe-ranlib.c
-maybe-strip.o: maybe-strip.c
-nlmconv.o: nlmconv.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(BFDDIR)/libnlm.h \
- $(INCDIR)/nlm/common.h $(INCDIR)/nlm/internal.h $(INCDIR)/nlm/external.h \
- nlmconv.h bucomm.h
-nm.o: nm.c sysdep.h config.h $(INCDIR)/ansidecl.h ../bfd/bfdver.h \
- $(INCDIR)/fopen-same.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h $(INCDIR)/progress.h $(INCDIR)/aout/stab_gnu.h \
- $(INCDIR)/aout/stab.def $(INCDIR)/aout/ranlib.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
- $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \
- $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/common.h \
- bucomm.h
-not-ranlib.o: not-ranlib.c
-not-strip.o: not-strip.c
-objcopy.o: objcopy.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/progress.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h $(BFDDIR)/elf-bfd.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/bfdlink.h $(BFDDIR)/libbfd.h $(INCDIR)/hashtab.h
-objdump.o: objdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(BFDDIR)/elf-bfd.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/bfdlink.h $(INCDIR)/progress.h bucomm.h dwarf.h \
- $(INCDIR)/safe-ctype.h $(INCDIR)/dis-asm.h ../bfd/bfd.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h debug.h budbg.h $(INCDIR)/aout/aout64.h
-prdbg.o: prdbg.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- debug.h budbg.h
-rclex.o: rclex.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windres.h \
- winduni.h windint.h rcparse.h
-rdcoff.o: rdcoff.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/coff/internal.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- debug.h budbg.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h
-rddbg.o: rddbg.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h debug.h budbg.h
-readelf.o: readelf.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h dwarf.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/elf/h8.h $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/alpha.h \
- $(INCDIR)/elf/arc.h $(INCDIR)/elf/arm.h $(INCDIR)/elf/avr.h \
- $(INCDIR)/elf/bfin.h $(INCDIR)/elf/cr16.h $(INCDIR)/elf/cris.h \
- $(INCDIR)/elf/crx.h $(INCDIR)/elf/d10v.h $(INCDIR)/elf/d30v.h \
- $(INCDIR)/elf/dlx.h $(INCDIR)/elf/fr30.h $(INCDIR)/elf/frv.h \
- $(INCDIR)/elf/hppa.h $(INCDIR)/elf/i386.h $(INCDIR)/elf/i370.h \
- $(INCDIR)/elf/i860.h $(INCDIR)/elf/i960.h $(INCDIR)/elf/ia64.h \
- $(INCDIR)/elf/ip2k.h $(INCDIR)/elf/iq2000.h $(INCDIR)/elf/m32c.h \
- $(INCDIR)/elf/m32r.h $(INCDIR)/elf/m68k.h $(INCDIR)/elf/m68hc11.h \
- $(INCDIR)/elf/mcore.h $(INCDIR)/elf/mep.h $(INCDIR)/elf/mips.h \
- $(INCDIR)/elf/mmix.h $(INCDIR)/elf/mn10200.h $(INCDIR)/elf/mn10300.h \
- $(INCDIR)/elf/mt.h $(INCDIR)/elf/msp430.h $(INCDIR)/elf/or32.h \
- $(INCDIR)/elf/pj.h $(INCDIR)/elf/ppc.h $(INCDIR)/elf/ppc64.h \
- $(INCDIR)/elf/s390.h $(INCDIR)/elf/score.h $(INCDIR)/elf/sh.h \
- $(INCDIR)/elf/sparc.h $(INCDIR)/elf/spu.h $(INCDIR)/elf/v850.h \
- $(INCDIR)/elf/vax.h $(INCDIR)/elf/x86-64.h $(INCDIR)/elf/xstormy16.h \
- $(INCDIR)/elf/xtensa.h $(INCDIR)/aout/ar.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h unwind-ia64.h
-rename.o: rename.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-resbin.o: resbin.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h
-rescoff.o: rescoff.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h \
- $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h
-resrc.o: resrc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windres.h \
- winduni.h windint.h
-resres.o: resres.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h
-size.o: size.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h
-srconv.o: srconv.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h sysroff.h \
- coffgrok.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h \
- sysroff.c
-stabs.o: stabs.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h debug.h budbg.h $(INCDIR)/filenames.h \
- $(INCDIR)/aout/aout64.h $(INCDIR)/aout/stab_gnu.h $(INCDIR)/aout/stab.def
-strings.o: strings.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h bucomm.h
-sysdump.o: sysdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/safe-ctype.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- sysroff.h sysroff.c $(INCDIR)/ansidecl.h
-unwind-ia64.o: unwind-ia64.c unwind-ia64.h $(INCDIR)/elf/ia64.h \
- $(INCDIR)/elf/reloc-macros.h $(INCDIR)/ansidecl.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h
-version.o: version.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-windres.o: windres.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
- windres.h winduni.h windint.h
-winduni.o: winduni.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h winduni.h $(INCDIR)/safe-ctype.h
-wrstabs.o: wrstabs.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h bucomm.h \
- debug.h budbg.h $(INCDIR)/aout/aout64.h $(INCDIR)/aout/stab_gnu.h \
- $(INCDIR)/aout/stab.def
-windmc.o: windmc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
- windmc.h winduni.h windint.h
-mclex.o: mclex.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windmc.h \
- winduni.h mcparse.h
-arparse.o: arparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h arsup.h
-arlex.o: arlex.c $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h arparse.h
-sysroff.o: sysroff.c
-sysinfo.o: sysinfo.c
-syslex.o: syslex.c config.h sysinfo.h
-defparse.o: defparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h dlltool.h
-deflex.o: deflex.c $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- defparse.h dlltool.h $(INCDIR)/ansidecl.h
-nlmheader.o: nlmheader.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h $(INCDIR)/safe-ctype.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- $(INCDIR)/nlm/common.h $(INCDIR)/nlm/internal.h bucomm.h \
- nlmconv.h
-rcparse.o: rcparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h \
- $(INCDIR)/safe-ctype.h
-mcparse.o: mcparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windmc.h winduni.h $(INCDIR)/safe-ctype.h
-# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
deleted file mode 100644
index 14b973218f4..00000000000
--- a/binutils/Makefile.in
+++ /dev/null
@@ -1,1462 +0,0 @@
-# Makefile.in generated by automake 1.9.6 from Makefile.am.
-# @configure_input@
-
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005 Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-@SET_MAKE@
-
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-top_builddir = .
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-INSTALL = @INSTALL@
-install_sh_DATA = $(install_sh) -c -m 644
-install_sh_PROGRAM = $(install_sh) -c
-install_sh_SCRIPT = $(install_sh) -c
-INSTALL_HEADER = $(INSTALL_DATA)
-transform = $(program_transform_name)
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-build_triplet = @build@
-host_triplet = @host@
-target_triplet = @target@
-bin_PROGRAMS = $(am__EXEEXT_6) $(am__EXEEXT_7) $(am__EXEEXT_8) \
- $(am__EXEEXT_9) $(am__EXEEXT_10) $(am__EXEEXT_11) \
- @BUILD_NLMCONV@ @BUILD_SRCONV@ @BUILD_DLLTOOL@ @BUILD_WINDRES@ \
- @BUILD_WINDMC@ $(am__EXEEXT_12) $(am__EXEEXT_13) \
- @BUILD_DLLWRAP@ @BUILD_INSTALL_MISC@ $(am__empty)
-noinst_PROGRAMS = $(am__EXEEXT_17) @BUILD_MISC@
-EXTRA_PROGRAMS = $(am__EXEEXT_1) srconv$(EXEEXT) sysdump$(EXEEXT) \
- coffdump$(EXEEXT) $(am__EXEEXT_2) $(am__EXEEXT_3) \
- $(am__EXEEXT_4) $(am__EXEEXT_5)
-DIST_COMMON = $(srcdir)/../config.guess $(srcdir)/../config.sub NEWS \
- README ChangeLog $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
- $(top_srcdir)/configure $(am__configure_deps) \
- $(srcdir)/config.in $(srcdir)/../mkinstalldirs \
- $(top_srcdir)/po/Make-in arparse.h arparse.c arlex.c \
- defparse.h defparse.c deflex.c nlmheader.h nlmheader.c \
- arparse.h arparse.c arlex.c mcparse.h mcparse.c rcparse.h \
- rcparse.c $(srcdir)/../ylwrap $(srcdir)/../ltmain.sh \
- $(srcdir)/../config.guess $(srcdir)/../config.sub
-subdir = .
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
- $(top_srcdir)/../bfd/warning.m4 \
- $(top_srcdir)/../config/depstand.m4 \
- $(top_srcdir)/../config/gettext-sister.m4 \
- $(top_srcdir)/../config/iconv.m4 \
- $(top_srcdir)/../config/lead-dot.m4 \
- $(top_srcdir)/../config/lib-ld.m4 \
- $(top_srcdir)/../config/lib-link.m4 \
- $(top_srcdir)/../config/lib-prefix.m4 \
- $(top_srcdir)/../config/nls.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../config/po.m4 \
- $(top_srcdir)/../config/proginstall.m4 \
- $(top_srcdir)/../config/progtest.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/configure.in
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
- $(ACLOCAL_M4)
-am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
- configure.lineno configure.status.lineno
-mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
-CONFIG_HEADER = config.h
-CONFIG_CLEAN_FILES = po/Makefile.in
-am__EXEEXT_1 = nlmconv$(EXEEXT)
-am__EXEEXT_2 = dlltool$(EXEEXT)
-am__EXEEXT_3 = windres$(EXEEXT)
-am__EXEEXT_4 = windmc$(EXEEXT)
-am__EXEEXT_5 = dllwrap$(EXEEXT)
-am__EXEEXT_6 = size$(EXEEXT)
-am__EXEEXT_7 = objdump$(EXEEXT)
-am__EXEEXT_8 = ar$(EXEEXT)
-am__EXEEXT_9 = strings$(EXEEXT)
-am__EXEEXT_10 = ranlib$(EXEEXT)
-am__EXEEXT_11 = objcopy$(EXEEXT)
-am__EXEEXT_12 = addr2line$(EXEEXT)
-am__EXEEXT_13 = readelf$(EXEEXT)
-am__installdirs = "$(DESTDIR)$(bindir)"
-binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
-am__EXEEXT_14 = nm-new$(EXEEXT)
-am__EXEEXT_15 = strip-new$(EXEEXT)
-am__EXEEXT_16 = cxxfilt$(EXEEXT)
-am__EXEEXT_17 = $(am__EXEEXT_14) $(am__EXEEXT_15) $(am__EXEEXT_16)
-PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
-am__objects_1 = bucomm.$(OBJEXT) version.$(OBJEXT) filemode.$(OBJEXT)
-am_addr2line_OBJECTS = addr2line.$(OBJEXT) $(am__objects_1)
-addr2line_OBJECTS = $(am_addr2line_OBJECTS)
-addr2line_LDADD = $(LDADD)
-am__DEPENDENCIES_1 = ../bfd/libbfd.la
-am__DEPENDENCIES_2 = ../libiberty/libiberty.a
-am__DEPENDENCIES_3 =
-am_ar_OBJECTS = arparse.$(OBJEXT) arlex.$(OBJEXT) ar.$(OBJEXT) \
- not-ranlib.$(OBJEXT) arsup.$(OBJEXT) rename.$(OBJEXT) \
- binemul.$(OBJEXT) emul_$(EMULATION).$(OBJEXT) $(am__objects_1)
-ar_OBJECTS = $(am_ar_OBJECTS)
-am_coffdump_OBJECTS = coffdump.$(OBJEXT) coffgrok.$(OBJEXT) \
- $(am__objects_1)
-coffdump_OBJECTS = $(am_coffdump_OBJECTS)
-coffdump_LDADD = $(LDADD)
-am_cxxfilt_OBJECTS = cxxfilt.$(OBJEXT) $(am__objects_1)
-cxxfilt_OBJECTS = $(am_cxxfilt_OBJECTS)
-cxxfilt_LDADD = $(LDADD)
-am_dlltool_OBJECTS = dlltool.$(OBJEXT) defparse.$(OBJEXT) \
- deflex.$(OBJEXT) $(am__objects_1)
-dlltool_OBJECTS = $(am_dlltool_OBJECTS)
-am_dllwrap_OBJECTS = dllwrap.$(OBJEXT) version.$(OBJEXT)
-dllwrap_OBJECTS = $(am_dllwrap_OBJECTS)
-am_nlmconv_OBJECTS = nlmconv.$(OBJEXT) nlmheader.$(OBJEXT) \
- $(am__objects_1)
-nlmconv_OBJECTS = $(am_nlmconv_OBJECTS)
-nlmconv_LDADD = $(LDADD)
-am_nm_new_OBJECTS = nm.$(OBJEXT) $(am__objects_1)
-nm_new_OBJECTS = $(am_nm_new_OBJECTS)
-nm_new_LDADD = $(LDADD)
-am__objects_2 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \
- ieee.$(OBJEXT) rdcoff.$(OBJEXT)
-am__objects_3 = $(am__objects_2) wrstabs.$(OBJEXT)
-am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \
- rename.$(OBJEXT) $(am__objects_3) $(am__objects_1)
-objcopy_OBJECTS = $(am_objcopy_OBJECTS)
-objcopy_LDADD = $(LDADD)
-am_objdump_OBJECTS = objdump.$(OBJEXT) dwarf.$(OBJEXT) prdbg.$(OBJEXT) \
- $(am__objects_2) $(am__objects_1)
-objdump_OBJECTS = $(am_objdump_OBJECTS)
-am__DEPENDENCIES_4 = ../opcodes/libopcodes.la
-am_ranlib_OBJECTS = ar.$(OBJEXT) is-ranlib.$(OBJEXT) arparse.$(OBJEXT) \
- arlex.$(OBJEXT) arsup.$(OBJEXT) rename.$(OBJEXT) \
- binemul.$(OBJEXT) emul_$(EMULATION).$(OBJEXT) $(am__objects_1)
-ranlib_OBJECTS = $(am_ranlib_OBJECTS)
-am_readelf_OBJECTS = readelf.$(OBJEXT) version.$(OBJEXT) \
- unwind-ia64.$(OBJEXT) dwarf.$(OBJEXT)
-readelf_OBJECTS = $(am_readelf_OBJECTS)
-am_size_OBJECTS = size.$(OBJEXT) $(am__objects_1)
-size_OBJECTS = $(am_size_OBJECTS)
-size_LDADD = $(LDADD)
-am_srconv_OBJECTS = srconv.$(OBJEXT) coffgrok.$(OBJEXT) \
- $(am__objects_1)
-srconv_OBJECTS = $(am_srconv_OBJECTS)
-srconv_LDADD = $(LDADD)
-am_strings_OBJECTS = strings.$(OBJEXT) $(am__objects_1)
-strings_OBJECTS = $(am_strings_OBJECTS)
-strings_LDADD = $(LDADD)
-am_strip_new_OBJECTS = objcopy.$(OBJEXT) is-strip.$(OBJEXT) \
- rename.$(OBJEXT) $(am__objects_3) $(am__objects_1)
-strip_new_OBJECTS = $(am_strip_new_OBJECTS)
-strip_new_LDADD = $(LDADD)
-am_sysdump_OBJECTS = sysdump.$(OBJEXT) $(am__objects_1)
-sysdump_OBJECTS = $(am_sysdump_OBJECTS)
-sysdump_LDADD = $(LDADD)
-am_windmc_OBJECTS = windmc.$(OBJEXT) mcparse.$(OBJEXT) mclex.$(OBJEXT) \
- winduni.$(OBJEXT) $(am__objects_1)
-windmc_OBJECTS = $(am_windmc_OBJECTS)
-am_windres_OBJECTS = windres.$(OBJEXT) resrc.$(OBJEXT) \
- rescoff.$(OBJEXT) resbin.$(OBJEXT) rcparse.$(OBJEXT) \
- rclex.$(OBJEXT) winduni.$(OBJEXT) resres.$(OBJEXT) \
- $(am__objects_1)
-windres_OBJECTS = $(am_windres_OBJECTS)
-DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
-depcomp =
-am__depfiles_maybe =
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
- $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
- $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
- $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
- $(AM_LDFLAGS) $(LDFLAGS) -o $@
-LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS)
-LTLEXCOMPILE = $(LIBTOOL) --mode=compile $(LEX) $(LFLAGS) $(AM_LFLAGS)
-YLWRAP = $(top_srcdir)/../ylwrap
-YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS)
-LTYACCCOMPILE = $(LIBTOOL) --mode=compile $(YACC) $(YFLAGS) \
- $(AM_YFLAGS)
-SOURCES = $(addr2line_SOURCES) $(ar_SOURCES) $(coffdump_SOURCES) \
- $(cxxfilt_SOURCES) $(dlltool_SOURCES) $(dllwrap_SOURCES) \
- $(nlmconv_SOURCES) $(nm_new_SOURCES) $(objcopy_SOURCES) \
- $(objdump_SOURCES) $(ranlib_SOURCES) $(readelf_SOURCES) \
- $(size_SOURCES) $(srconv_SOURCES) $(strings_SOURCES) \
- $(strip_new_SOURCES) $(sysdump_SOURCES) $(windmc_SOURCES) \
- $(windres_SOURCES)
-RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
- html-recursive info-recursive install-data-recursive \
- install-exec-recursive install-info-recursive \
- install-recursive installcheck-recursive installdirs-recursive \
- pdf-recursive ps-recursive uninstall-info-recursive \
- uninstall-recursive
-ETAGS = etags
-CTAGS = ctags
-DEJATOOL = $(PACKAGE)
-RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
-DIST_SUBDIRS = $(SUBDIRS)
-ACLOCAL = @ACLOCAL@
-ALLOCA = @ALLOCA@
-AMDEP_FALSE = @AMDEP_FALSE@
-AMDEP_TRUE = @AMDEP_TRUE@
-AMTAR = @AMTAR@
-AR = @AR@
-AUTOCONF = @AUTOCONF@
-AUTOHEADER = @AUTOHEADER@
-AUTOMAKE = @AUTOMAKE@
-AWK = @AWK@
-BUILD_DLLTOOL = @BUILD_DLLTOOL@
-BUILD_DLLWRAP = @BUILD_DLLWRAP@
-BUILD_INSTALL_MISC = @BUILD_INSTALL_MISC@
-BUILD_MISC = @BUILD_MISC@
-BUILD_NLMCONV = @BUILD_NLMCONV@
-BUILD_SRCONV = @BUILD_SRCONV@
-BUILD_WINDMC = @BUILD_WINDMC@
-BUILD_WINDRES = @BUILD_WINDRES@
-CATALOGS = @CATALOGS@
-CATOBJEXT = @CATOBJEXT@
-CC = @CC@
-CCDEPMODE = @CCDEPMODE@
-CC_FOR_BUILD = @CC_FOR_BUILD@
-CFLAGS = @CFLAGS@
-CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@
-CYGPATH_W = @CYGPATH_W@
-DATADIRNAME = @DATADIRNAME@
-DEFS = @DEFS@
-DEMANGLER_NAME = @DEMANGLER_NAME@
-DEPDIR = @DEPDIR@
-DLLTOOL_DEFS = @DLLTOOL_DEFS@
-DUMPBIN = @DUMPBIN@
-ECHO_C = @ECHO_C@
-ECHO_N = @ECHO_N@
-ECHO_T = @ECHO_T@
-EGREP = @EGREP@
-EMULATION = @EMULATION@
-EMULATION_VECTOR = @EMULATION_VECTOR@
-EXEEXT = @EXEEXT@
-EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
-FGREP = @FGREP@
-GENCAT = @GENCAT@
-GENINSRC_NEVER_FALSE = @GENINSRC_NEVER_FALSE@
-GENINSRC_NEVER_TRUE = @GENINSRC_NEVER_TRUE@
-GMSGFMT = @GMSGFMT@
-GREP = @GREP@
-HDEFINES = @HDEFINES@
-INCINTL = @INCINTL@
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-INSTOBJEXT = @INSTOBJEXT@
-LD = @LD@
-LDFLAGS = @LDFLAGS@
-LEX = `if [ -f ../flex/flex ]; then echo ../flex/flex; else echo @LEX@; fi`
-LEXLIB = @LEXLIB@
-LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
-LIBICONV = @LIBICONV@
-LIBINTL = @LIBINTL@
-LIBINTL_DEP = @LIBINTL_DEP@
-LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
-LIBTOOL = @LIBTOOL@
-LN_S = @LN_S@
-LTLIBICONV = @LTLIBICONV@
-LTLIBOBJS = @LTLIBOBJS@
-MAINT = @MAINT@
-MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
-MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
-MAKEINFO = @MAKEINFO@
-MKINSTALLDIRS = @MKINSTALLDIRS@
-MSGFMT = @MSGFMT@
-MSGMERGE = @MSGMERGE@
-NLMCONV_DEFS = @NLMCONV_DEFS@
-NM = @NM@
-NO_WERROR = @NO_WERROR@
-OBJDUMP_DEFS = @OBJDUMP_DEFS@
-OBJEXT = @OBJEXT@
-PACKAGE = @PACKAGE@
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
-PACKAGE_NAME = @PACKAGE_NAME@
-PACKAGE_STRING = @PACKAGE_STRING@
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
-PACKAGE_VERSION = @PACKAGE_VERSION@
-PATH_SEPARATOR = @PATH_SEPARATOR@
-POSUB = @POSUB@
-RANLIB = @RANLIB@
-SED = @SED@
-SET_MAKE = @SET_MAKE@
-SHELL = @SHELL@
-STRIP = @STRIP@
-USE_NLS = @USE_NLS@
-VERSION = @VERSION@
-WARN_CFLAGS = @WARN_CFLAGS@
-XGETTEXT = @XGETTEXT@
-YACC = `if [ -f ../bison/bison ]; then echo ../bison/bison -y -L$(srcdir)/../bison/; else echo @YACC@; fi`
-ac_ct_AR = @ac_ct_AR@
-ac_ct_CC = @ac_ct_CC@
-ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
-ac_ct_RANLIB = @ac_ct_RANLIB@
-ac_ct_STRIP = @ac_ct_STRIP@
-am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
-am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
-am__include = @am__include@
-am__leading_dot = @am__leading_dot@
-am__quote = @am__quote@
-am__tar = @am__tar@
-am__untar = @am__untar@
-bindir = @bindir@
-build = @build@
-build_alias = @build_alias@
-build_cpu = @build_cpu@
-build_os = @build_os@
-build_vendor = @build_vendor@
-datadir = @datadir@
-datarootdir = @datarootdir@
-docdir = @docdir@
-exec_prefix = @exec_prefix@
-host = @host@
-host_alias = @host_alias@
-host_cpu = @host_cpu@
-host_os = @host_os@
-host_vendor = @host_vendor@
-htmldir = @htmldir@
-includedir = @includedir@
-infodir = @infodir@
-install_sh = @install_sh@
-libdir = @libdir@
-libexecdir = @libexecdir@
-localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
-mandir = @mandir@
-mkdir_p = @mkdir_p@
-oldincludedir = @oldincludedir@
-prefix = @prefix@
-program_transform_name = @program_transform_name@
-sbindir = @sbindir@
-sharedstatedir = @sharedstatedir@
-sysconfdir = @sysconfdir@
-target = @target@
-target_alias = @target_alias@
-target_cpu = @target_cpu@
-target_os = @target_os@
-target_vendor = @target_vendor@
-AUTOMAKE_OPTIONS = cygnus dejagnu
-ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
-SUBDIRS = doc po
-tooldir = $(exec_prefix)/$(target_alias)
-YFLAGS = -d
-AM_CFLAGS = $(WARN_CFLAGS)
-
-# these two are almost the same program
-AR_PROG = ar
-RANLIB_PROG = ranlib
-
-# objcopy and strip should be the same program
-OBJCOPY_PROG = objcopy
-STRIP_PROG = strip-new
-STRINGS_PROG = strings
-READELF_PROG = readelf
-
-# These should all be the same program too.
-SIZE_PROG = size
-NM_PROG = nm-new
-OBJDUMP_PROG = objdump
-
-# This is the demangler, as a standalone program.
-# Note: This one is used as the installed name too, unlike the above.
-DEMANGLER_PROG = cxxfilt
-ADDR2LINE_PROG = addr2line
-NLMCONV_PROG = nlmconv
-DLLTOOL_PROG = dlltool
-WINDRES_PROG = windres
-WINDMC_PROG = windmc
-DLLWRAP_PROG = dllwrap
-SRCONV_PROG = srconv$(EXEEXT) sysdump$(EXEEXT) coffdump$(EXEEXT)
-RENAMED_PROGS = $(NM_PROG) $(STRIP_PROG) $(DEMANGLER_PROG)
-
-# Stuff that goes in tooldir/ if appropriate.
-TOOL_PROGS = nm-new strip-new ar ranlib dlltool objdump objcopy
-BASEDIR = $(srcdir)/..
-BFDDIR = $(BASEDIR)/bfd
-INCDIR = $(BASEDIR)/include
-MKDEP = gcc -MM
-INCLUDES = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) \
- @HDEFINES@ \
- @INCINTL@ \
- -DLOCALEDIR="\"$(datadir)/locale\"" \
- -Dbin_dummy_emulation=$(EMULATION_VECTOR)
-
-HFILES = \
- arsup.h binemul.h bucomm.h budbg.h \
- coffgrok.h debug.h dlltool.h dwarf.h nlmconv.h \
- sysdep.h unwind-ia64.h windres.h winduni.h windint.h \
- windmc.h
-
-GENERATED_HFILES = arparse.h sysroff.h sysinfo.h defparse.h rcparse.h mcparse.h
-CFILES = \
- addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
- coffdump.c coffgrok.c cxxfilt.c \
- dwarf.c debug.c dlltool.c dllwrap.c \
- emul_aix.c emul_vanilla.c filemode.c \
- ieee.c is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \
- nlmconv.c nm.c not-ranlib.c not-strip.c \
- objcopy.c objdump.c prdbg.c \
- rclex.c rdcoff.c rddbg.c readelf.c rename.c \
- resbin.c rescoff.c resrc.c resres.c \
- size.c srconv.c stabs.c strings.c sysdump.c \
- unwind-ia64.c version.c \
- windres.c winduni.c wrstabs.c \
- windmc.c mclex.c
-
-GENERATED_CFILES = \
- arparse.c arlex.c sysroff.c sysinfo.c syslex.c \
- defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
-
-DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
-
-# Code shared by all the binutils.
-BULIBS = bucomm.c version.c filemode.c
-BFDLIB = ../bfd/libbfd.la
-OPCODES = ../opcodes/libopcodes.la
-LIBIBERTY = ../libiberty/libiberty.a
-POTFILES = $(CFILES) $(DEBUG_SRCS) $(HFILES)
-EXPECT = expect
-RUNTEST = runtest
-CC_FOR_TARGET = ` \
- if [ -f $$r/../gcc/xgcc ] ; then \
- if [ -f $$r/../newlib/Makefile ] ; then \
- echo $$r/../gcc/xgcc -B$$r/../gcc/ -idirafter $$r/../newlib/targ-include -idirafter $${srcroot}/../newlib/libc/include -nostdinc; \
- else \
- echo $$r/../gcc/xgcc -B$$r/../gcc/; \
- fi; \
- else \
- if [ "@host@" = "@target@" ] ; then \
- echo $(CC); \
- else \
- echo gcc | sed '$(transform)'; \
- fi; \
- fi`
-
-
-# There's no global DEPENDENCIES. So, we must explicitly list everything
-# which depends on libintl, since we don't know whether LIBINTL_DEP will be
-# non-empty until configure time. Ugh!
-size_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES)
-nm_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-ar_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-strings_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-strip_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-ranlib_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-cxxfilt_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-objcopy_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-nlmconv_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-srconv_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-sysdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-coffdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-dlltool_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-windres_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-windmc_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-addr2line_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
-dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
-size_SOURCES = size.c $(BULIBS)
-objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
-strings_SOURCES = strings.c $(BULIBS)
-readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c
-readelf_LDADD = $(LIBINTL) $(LIBIBERTY)
-strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
-nm_new_SOURCES = nm.c $(BULIBS)
-objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS)
-objdump_LDADD = $(OPCODES) $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
-cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
-ar_SOURCES = arparse.y arlex.l ar.c not-ranlib.c arsup.c rename.c binemul.c \
- emul_$(EMULATION).c $(BULIBS)
-
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-ranlib_SOURCES = ar.c is-ranlib.c arparse.y arlex.l arsup.c rename.c \
- binemul.c emul_$(EMULATION).c $(BULIBS)
-
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-addr2line_SOURCES = addr2line.c $(BULIBS)
-srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
-dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
-coffdump_SOURCES = coffdump.c coffgrok.c $(BULIBS)
-sysdump_SOURCES = sysdump.c $(BULIBS)
-nlmconv_SOURCES = nlmconv.c nlmheader.y $(BULIBS)
-windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
- winduni.c resres.c $(BULIBS)
-
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL) $(LIBICONV)
-windmc_SOURCES = windmc.c mcparse.y mclex.c \
- winduni.c $(BULIBS)
-
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL) $(LIBICONV)
-dllwrap_SOURCES = dllwrap.c version.c
-dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
-EXTRA_DIST = arparse.c arparse.h arlex.c nlmheader.c sysinfo.c sysinfo.h \
- syslex.c deflex.c defparse.h defparse.c rcparse.h rcparse.c \
- mcparse.h mcparse.c
-
-DISTCLEANFILES = sysroff.c sysroff.h site.exp site.bak
-
-###
-MOSTLYCLEANFILES = sysinfo$(EXEEXT_FOR_BUILD) bin2c$(EXEEXT_FOR_BUILD) \
- binutils.log binutils.sum abcdefgh*
-
-CLEANFILES = dep.sed DEP DEPA DEP1 DEP2
-all: config.h
- $(MAKE) $(AM_MAKEFLAGS) all-recursive
-
-.SUFFIXES:
-.SUFFIXES: .c .l .lo .o .obj .y
-am--refresh:
- @:
-$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
- @for dep in $?; do \
- case '$(am__configure_deps)' in \
- *$$dep*) \
- echo ' cd $(srcdir) && $(AUTOMAKE) --cygnus '; \
- cd $(srcdir) && $(AUTOMAKE) --cygnus \
- && exit 0; \
- exit 1;; \
- esac; \
- done; \
- echo ' cd $(top_srcdir) && $(AUTOMAKE) --cygnus Makefile'; \
- cd $(top_srcdir) && \
- $(AUTOMAKE) --cygnus Makefile
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- @case '$?' in \
- *config.status*) \
- echo ' $(SHELL) ./config.status'; \
- $(SHELL) ./config.status;; \
- *) \
- echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
- cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
- esac;
-
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
- $(SHELL) ./config.status --recheck
-
-$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
- cd $(srcdir) && $(AUTOCONF)
-$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
- cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
-
-config.h: stamp-h1
- @if test ! -f $@; then \
- rm -f stamp-h1; \
- $(MAKE) stamp-h1; \
- else :; fi
-
-stamp-h1: $(srcdir)/config.in $(top_builddir)/config.status
- @rm -f stamp-h1
- cd $(top_builddir) && $(SHELL) ./config.status config.h
-$(srcdir)/config.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
- cd $(top_srcdir) && $(AUTOHEADER)
- rm -f stamp-h1
- touch $@
-
-distclean-hdr:
- -rm -f config.h stamp-h1
-po/Makefile.in: $(top_builddir)/config.status $(top_srcdir)/po/Make-in
- cd $(top_builddir) && $(SHELL) ./config.status $@
-install-binPROGRAMS: $(bin_PROGRAMS)
- @$(NORMAL_INSTALL)
- test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
- @list='$(bin_PROGRAMS)'; for p in $$list; do \
- p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
- if test -f $$p \
- || test -f $$p1 \
- ; then \
- f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
- $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
- else :; fi; \
- done
-
-uninstall-binPROGRAMS:
- @$(NORMAL_UNINSTALL)
- @list='$(bin_PROGRAMS)'; for p in $$list; do \
- f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
- rm -f "$(DESTDIR)$(bindir)/$$f"; \
- done
-
-clean-binPROGRAMS:
- @list='$(bin_PROGRAMS)'; for p in $$list; do \
- f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
- echo " rm -f $$p $$f"; \
- rm -f $$p $$f ; \
- done
-
-clean-noinstPROGRAMS:
- @list='$(noinst_PROGRAMS)'; for p in $$list; do \
- f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
- echo " rm -f $$p $$f"; \
- rm -f $$p $$f ; \
- done
-addr2line$(EXEEXT): $(addr2line_OBJECTS) $(addr2line_DEPENDENCIES)
- @rm -f addr2line$(EXEEXT)
- $(LINK) $(addr2line_LDFLAGS) $(addr2line_OBJECTS) $(addr2line_LDADD) $(LIBS)
-ar$(EXEEXT): $(ar_OBJECTS) $(ar_DEPENDENCIES)
- @rm -f ar$(EXEEXT)
- $(LINK) $(ar_LDFLAGS) $(ar_OBJECTS) $(ar_LDADD) $(LIBS)
-coffdump$(EXEEXT): $(coffdump_OBJECTS) $(coffdump_DEPENDENCIES)
- @rm -f coffdump$(EXEEXT)
- $(LINK) $(coffdump_LDFLAGS) $(coffdump_OBJECTS) $(coffdump_LDADD) $(LIBS)
-cxxfilt$(EXEEXT): $(cxxfilt_OBJECTS) $(cxxfilt_DEPENDENCIES)
- @rm -f cxxfilt$(EXEEXT)
- $(LINK) $(cxxfilt_LDFLAGS) $(cxxfilt_OBJECTS) $(cxxfilt_LDADD) $(LIBS)
-dlltool$(EXEEXT): $(dlltool_OBJECTS) $(dlltool_DEPENDENCIES)
- @rm -f dlltool$(EXEEXT)
- $(LINK) $(dlltool_LDFLAGS) $(dlltool_OBJECTS) $(dlltool_LDADD) $(LIBS)
-dllwrap$(EXEEXT): $(dllwrap_OBJECTS) $(dllwrap_DEPENDENCIES)
- @rm -f dllwrap$(EXEEXT)
- $(LINK) $(dllwrap_LDFLAGS) $(dllwrap_OBJECTS) $(dllwrap_LDADD) $(LIBS)
-nlmconv$(EXEEXT): $(nlmconv_OBJECTS) $(nlmconv_DEPENDENCIES)
- @rm -f nlmconv$(EXEEXT)
- $(LINK) $(nlmconv_LDFLAGS) $(nlmconv_OBJECTS) $(nlmconv_LDADD) $(LIBS)
-nm-new$(EXEEXT): $(nm_new_OBJECTS) $(nm_new_DEPENDENCIES)
- @rm -f nm-new$(EXEEXT)
- $(LINK) $(nm_new_LDFLAGS) $(nm_new_OBJECTS) $(nm_new_LDADD) $(LIBS)
-objcopy$(EXEEXT): $(objcopy_OBJECTS) $(objcopy_DEPENDENCIES)
- @rm -f objcopy$(EXEEXT)
- $(LINK) $(objcopy_LDFLAGS) $(objcopy_OBJECTS) $(objcopy_LDADD) $(LIBS)
-objdump$(EXEEXT): $(objdump_OBJECTS) $(objdump_DEPENDENCIES)
- @rm -f objdump$(EXEEXT)
- $(LINK) $(objdump_LDFLAGS) $(objdump_OBJECTS) $(objdump_LDADD) $(LIBS)
-ranlib$(EXEEXT): $(ranlib_OBJECTS) $(ranlib_DEPENDENCIES)
- @rm -f ranlib$(EXEEXT)
- $(LINK) $(ranlib_LDFLAGS) $(ranlib_OBJECTS) $(ranlib_LDADD) $(LIBS)
-readelf$(EXEEXT): $(readelf_OBJECTS) $(readelf_DEPENDENCIES)
- @rm -f readelf$(EXEEXT)
- $(LINK) $(readelf_LDFLAGS) $(readelf_OBJECTS) $(readelf_LDADD) $(LIBS)
-size$(EXEEXT): $(size_OBJECTS) $(size_DEPENDENCIES)
- @rm -f size$(EXEEXT)
- $(LINK) $(size_LDFLAGS) $(size_OBJECTS) $(size_LDADD) $(LIBS)
-srconv$(EXEEXT): $(srconv_OBJECTS) $(srconv_DEPENDENCIES)
- @rm -f srconv$(EXEEXT)
- $(LINK) $(srconv_LDFLAGS) $(srconv_OBJECTS) $(srconv_LDADD) $(LIBS)
-strings$(EXEEXT): $(strings_OBJECTS) $(strings_DEPENDENCIES)
- @rm -f strings$(EXEEXT)
- $(LINK) $(strings_LDFLAGS) $(strings_OBJECTS) $(strings_LDADD) $(LIBS)
-strip-new$(EXEEXT): $(strip_new_OBJECTS) $(strip_new_DEPENDENCIES)
- @rm -f strip-new$(EXEEXT)
- $(LINK) $(strip_new_LDFLAGS) $(strip_new_OBJECTS) $(strip_new_LDADD) $(LIBS)
-sysdump$(EXEEXT): $(sysdump_OBJECTS) $(sysdump_DEPENDENCIES)
- @rm -f sysdump$(EXEEXT)
- $(LINK) $(sysdump_LDFLAGS) $(sysdump_OBJECTS) $(sysdump_LDADD) $(LIBS)
-windmc$(EXEEXT): $(windmc_OBJECTS) $(windmc_DEPENDENCIES)
- @rm -f windmc$(EXEEXT)
- $(LINK) $(windmc_LDFLAGS) $(windmc_OBJECTS) $(windmc_LDADD) $(LIBS)
-windres$(EXEEXT): $(windres_OBJECTS) $(windres_DEPENDENCIES)
- @rm -f windres$(EXEEXT)
- $(LINK) $(windres_LDFLAGS) $(windres_OBJECTS) $(windres_LDADD) $(LIBS)
-
-mostlyclean-compile:
- -rm -f *.$(OBJEXT)
-
-distclean-compile:
- -rm -f *.tab.c
-
-.c.o:
- $(COMPILE) -c $<
-
-.c.obj:
- $(COMPILE) -c `$(CYGPATH_W) '$<'`
-
-.c.lo:
- $(LTCOMPILE) -c -o $@ $<
-
-.l.c:
- $(SHELL) $(YLWRAP) $< $(LEX_OUTPUT_ROOT).c $@ -- $(LEXCOMPILE)
-
-.y.c:
- $(SHELL) $(YLWRAP) $< y.tab.c $@ y.tab.h $*.h y.output $*.output -- $(YACCCOMPILE)
-
-mostlyclean-libtool:
- -rm -f *.lo
-
-clean-libtool:
- -rm -rf .libs _libs
-
-distclean-libtool:
- -rm -f libtool
-uninstall-info-am:
-
-# This directory's subdirectories are mostly independent; you can cd
-# into them and run `make' without going through this Makefile.
-# To change the values of `make' variables: instead of editing Makefiles,
-# (1) if the variable is set in `config.status', edit `config.status'
-# (which will cause the Makefiles to be regenerated when you run `make');
-# (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
- @failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
- dot_seen=no; \
- target=`echo $@ | sed s/-recursive//`; \
- list='$(SUBDIRS)'; for subdir in $$list; do \
- echo "Making $$target in $$subdir"; \
- if test "$$subdir" = "."; then \
- dot_seen=yes; \
- local_target="$$target-am"; \
- else \
- local_target="$$target"; \
- fi; \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
- || eval $$failcom; \
- done; \
- if test "$$dot_seen" = "no"; then \
- $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
- fi; test -z "$$fail"
-
-mostlyclean-recursive clean-recursive distclean-recursive \
-maintainer-clean-recursive:
- @failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
- dot_seen=no; \
- case "$@" in \
- distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
- *) list='$(SUBDIRS)' ;; \
- esac; \
- rev=''; for subdir in $$list; do \
- if test "$$subdir" = "."; then :; else \
- rev="$$subdir $$rev"; \
- fi; \
- done; \
- rev="$$rev ."; \
- target=`echo $@ | sed s/-recursive//`; \
- for subdir in $$rev; do \
- echo "Making $$target in $$subdir"; \
- if test "$$subdir" = "."; then \
- local_target="$$target-am"; \
- else \
- local_target="$$target"; \
- fi; \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
- || eval $$failcom; \
- done && test -z "$$fail"
-tags-recursive:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
- done
-ctags-recursive:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
- done
-
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) ' { files[$$0] = 1; } \
- END { for (i in files) print i; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: tags-recursive $(HEADERS) $(SOURCES) config.in $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- tags=; \
- here=`pwd`; \
- if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
- include_option=--etags-include; \
- empty_fix=.; \
- else \
- include_option=--include; \
- empty_fix=; \
- fi; \
- list='$(SUBDIRS)'; for subdir in $$list; do \
- if test "$$subdir" = .; then :; else \
- test ! -f $$subdir/TAGS || \
- tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
- fi; \
- done; \
- list='$(SOURCES) $(HEADERS) config.in $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) ' { files[$$0] = 1; } \
- END { for (i in files) print i; }'`; \
- if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
- test -n "$$unique" || unique=$$empty_fix; \
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- $$tags $$unique; \
- fi
-ctags: CTAGS
-CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.in $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- tags=; \
- here=`pwd`; \
- list='$(SOURCES) $(HEADERS) config.in $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) ' { files[$$0] = 1; } \
- END { for (i in files) print i; }'`; \
- test -z "$(CTAGS_ARGS)$$tags$$unique" \
- || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
- $$tags $$unique
-
-GTAGS:
- here=`$(am__cd) $(top_builddir) && pwd` \
- && cd $(top_srcdir) \
- && gtags -i $(GTAGS_ARGS) $$here
-
-distclean-tags:
- -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-site.exp: Makefile
- @echo 'Making a new site.exp file...'
- @echo '## these variables are automatically generated by make ##' >site.tmp
- @echo '# Do not edit here. If you wish to override these values' >>site.tmp
- @echo '# edit the last section' >>site.tmp
- @echo 'set srcdir $(srcdir)' >>site.tmp
- @echo "set objdir `pwd`" >>site.tmp
- @echo 'set build_alias "$(build_alias)"' >>site.tmp
- @echo 'set build_triplet $(build_triplet)' >>site.tmp
- @echo 'set host_alias "$(host_alias)"' >>site.tmp
- @echo 'set host_triplet $(host_triplet)' >>site.tmp
- @echo 'set target_alias "$(target_alias)"' >>site.tmp
- @echo 'set target_triplet $(target_triplet)' >>site.tmp
- @echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp
- @test ! -f site.exp || \
- sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
- @-rm -f site.bak
- @test ! -f site.exp || mv site.exp site.bak
- @mv site.tmp site.exp
-
-distclean-DEJAGNU:
- -rm -f site.exp site.bak
- -l='$(DEJATOOL)'; for tool in $$l; do \
- rm -f $$tool.sum $$tool.log; \
- done
-check-am:
- $(MAKE) $(AM_MAKEFLAGS) check-DEJAGNU
-check: check-recursive
-all-am: Makefile $(PROGRAMS) config.h
-installdirs: installdirs-recursive
-installdirs-am:
- for dir in "$(DESTDIR)$(bindir)"; do \
- test -z "$$dir" || $(mkdir_p) "$$dir"; \
- done
-install: install-recursive
-install-exec: install-exec-recursive
-install-data: install-data-recursive
-uninstall: uninstall-recursive
-
-install-am: all-am
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- `test -z '$(STRIP)' || \
- echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
-mostlyclean-generic:
- -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
-
-clean-generic:
- -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
-
-distclean-generic:
- -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
- -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
-
-maintainer-clean-generic:
- @echo "This command is intended for maintainers to use"
- @echo "it deletes files that may require special tools to rebuild."
- -rm -f arlex.c
- -rm -f arparse.c
- -rm -f arparse.h
- -rm -f deflex.c
- -rm -f defparse.c
- -rm -f defparse.h
- -rm -f mcparse.c
- -rm -f mcparse.h
- -rm -f nlmheader.c
- -rm -f nlmheader.h
- -rm -f rcparse.c
- -rm -f rcparse.h
-clean: clean-recursive
-
-clean-am: clean-binPROGRAMS clean-generic clean-libtool \
- clean-noinstPROGRAMS mostlyclean-am
-
-distclean: distclean-recursive
- -rm -f $(am__CONFIG_DISTCLEAN_FILES)
- -rm -f Makefile
-distclean-am: clean-am distclean-DEJAGNU distclean-compile \
- distclean-generic distclean-hdr distclean-libtool \
- distclean-tags
-
-dvi: dvi-recursive
-
-dvi-am:
-
-html: html-recursive
-
-info: info-recursive
-
-info-am:
-
-install-data-am:
-
-install-exec-am: install-binPROGRAMS install-exec-local
-
-install-info: install-info-recursive
-
-install-man:
-
-installcheck-am:
-
-maintainer-clean: maintainer-clean-recursive
- -rm -f $(am__CONFIG_DISTCLEAN_FILES)
- -rm -rf $(top_srcdir)/autom4te.cache
- -rm -f Makefile
-maintainer-clean-am: distclean-am maintainer-clean-generic
-
-mostlyclean: mostlyclean-recursive
-
-mostlyclean-am: mostlyclean-compile mostlyclean-generic \
- mostlyclean-libtool mostlyclean-local
-
-pdf: pdf-recursive
-
-pdf-am:
-
-ps: ps-recursive
-
-ps-am:
-
-uninstall-am: uninstall-binPROGRAMS
-
-uninstall-info: uninstall-info-recursive
-
-.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am am--refresh check \
- check-DEJAGNU check-am clean clean-binPROGRAMS clean-generic \
- clean-libtool clean-noinstPROGRAMS clean-recursive ctags \
- ctags-recursive distclean distclean-DEJAGNU distclean-compile \
- distclean-generic distclean-hdr distclean-libtool \
- distclean-recursive distclean-tags dvi dvi-am html html-am \
- info info-am install install-am install-binPROGRAMS \
- install-data install-data-am install-exec install-exec-am \
- install-exec-local install-info install-info-am install-man \
- install-strip installcheck installcheck-am installdirs \
- installdirs-am maintainer-clean maintainer-clean-generic \
- maintainer-clean-recursive mostlyclean mostlyclean-compile \
- mostlyclean-generic mostlyclean-libtool mostlyclean-local \
- mostlyclean-recursive pdf pdf-am ps ps-am tags tags-recursive \
- uninstall uninstall-am uninstall-binPROGRAMS uninstall-info-am
-
-
-.PHONY: install-html install-html-am install-html-recursive
-
-install-html: install-html-recursive
-
-install-html-recursive:
- @failcom='exit 1'; \
- for f in x $$MAKEFLAGS; do \
- case $$f in \
- *=* | --[!k]*);; \
- *k*) failcom='fail=yes';; \
- esac; \
- done; \
- dot_seen=no; \
- target=`echo $@ | sed s/-recursive//`; \
- list='$(SUBDIRS)'; for subdir in $$list; do \
- echo "Making $$target in $$subdir"; \
- if test "$$subdir" = "."; then \
- dot_seen=yes; \
- local_target="$$target-am"; \
- else \
- local_target="$$target"; \
- fi; \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
- || eval $$failcom; \
- done; \
- if test "$$dot_seen" = "no"; then \
- $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
- fi; test -z "$$fail"
-po/POTFILES.in: @MAINT@ Makefile
- for f in $(POTFILES); do echo $$f; done | LC_ALL=C sort > tmp \
- && mv tmp $(srcdir)/po/POTFILES.in
-
-check-DEJAGNU: site.exp
- srcdir=`cd $(srcdir) && pwd`; export srcdir; \
- r=`pwd`; export r; \
- EXPECT=$(EXPECT); export EXPECT; \
- runtest=$(RUNTEST); \
- if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
- CC_FOR_TARGET="$(CC_FOR_TARGET)" CFLAGS_FOR_TARGET="$(CFLAGS)" \
- $$runtest --tool $(DEJATOOL) --srcdir $${srcdir}/testsuite \
- $(RUNTESTFLAGS); \
- else echo "WARNING: could not find \`runtest'" 1>&2; :;\
- fi
-
-installcheck:
- /bin/sh $(srcdir)/sanity.sh $(bindir)
-
-objdump.o:objdump.c
- $(COMPILE) -c $(OBJDUMP_DEFS) $(srcdir)/objdump.c
-
-# The following is commented out for the conversion to automake.
-# This rule creates a single binary that switches between ar and ranlib
-# by looking at argv[0]. Use this kludge to save some disk space.
-# However, you have to install things by hand.
-# (That is after 'make install', replace the installed ranlib by a link to ar.)
-# Alternatively, you can install ranlib.sh as ranlib.
-# ar_with_ranlib: $(ADDL_DEPS) ar.o maybe-ranlib.o
-# $(HLDENV) $(CC) $(HLDFLAGS) $(CFLAGS) $(LDFLAGS) -o $(AR_PROG) ar.o maybe-ranlib.o $(ADDL_LIBS) $(EXTRALIBS)
-# -rm -f $(RANLIB_PROG)
-# -ln $(AR_PROG) $(RANLIB_PROG)
-#
-# objcopy and strip in one binary that uses argv[0] to decide its action.
-#
-#objcopy_with_strip: $(ADDL_DEPS) objcopy.o maybe-strip.o
-# $(HLDENV) $(CC) $(HLDFLAGS) $(CFLAGS) $(LDFLAGS) -o $(OBJCOPY_PROG) objcopy.o maybe-strip.o $(ADDL_LIBS) $(EXTRALIBS)
-# -rm -f $(STRIP_PROG)
-# -ln $(OBJCOPY_PROG) $(STRIP_PROG)
-
-sysroff.c: sysinfo$(EXEEXT_FOR_BUILD) sysroff.info
- ./sysinfo$(EXEEXT_FOR_BUILD) -c <$(srcdir)/sysroff.info >sysroff.c
- ./sysinfo$(EXEEXT_FOR_BUILD) -i <$(srcdir)/sysroff.info >>sysroff.c
- ./sysinfo$(EXEEXT_FOR_BUILD) -g <$(srcdir)/sysroff.info >>sysroff.c
-
-sysroff.h: sysinfo$(EXEEXT_FOR_BUILD) sysroff.info
- ./sysinfo$(EXEEXT_FOR_BUILD) -d <$(srcdir)/sysroff.info >sysroff.h
-
-sysinfo$(EXEEXT_FOR_BUILD): sysinfo.o syslex.o
- $(CC_FOR_BUILD) $(CFLAGS) $(LDFLAGS) -o $@ sysinfo.o syslex.o
-
-syslex.o:
- if [ -r syslex.c ]; then \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) syslex.c -Wno-error ; \
- else \
- $(CC_FOR_BUILD) -c -I. -I$(srcdir) $(AM_CFLAGS) $(CFLAGS) $(srcdir)/syslex.c -Wno-error ;\
- fi
-
-sysinfo.o:
- if [ -r sysinfo.c ]; then \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) sysinfo.c -Wno-error ; \
- else \
- $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) $(srcdir)/sysinfo.c -Wno-error ; \
- fi
-
-bin2c$(EXEEXT_FOR_BUILD):
- $(CC_FOR_BUILD) -o $@ $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) $(srcdir)/bin2c.c $(srcdir)/version.c
-
-embedspu: embedspu.sh
- sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@
- chmod a+x $@
-
-# We need these for parallel make.
-arparse.h: arparse.c
-defparse.h: defparse.c
-nlmheader.h: nlmheader.c
-rcparse.h: rcparse.c
-mcparse.h: mcparse.c
-sysinfo.h: sysinfo.c
-
-# Disable -Werror, if it has been enabled, since old versions of bison/
-# yacc will produce working code which contain compile time warnings.
-arparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-arlex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-sysroff.o:
- $(COMPILE) -c $< $(NO_WERROR)
-defparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-deflex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-nlmheader.o:
- $(COMPILE) -c $< $(NO_WERROR)
-rcparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-mcparse.o:
- $(COMPILE) -c $< $(NO_WERROR)
-rclex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-mclex.o:
- $(COMPILE) -c $< $(NO_WERROR)
-
-dlltool.o:
- $(COMPILE) -c $(DLLTOOL_DEFS) $(srcdir)/dlltool.c
-
-rescoff.o:
- $(COMPILE) -c $(DLLTOOL_DEFS) $(srcdir)/rescoff.c
-
-# coff/sym.h and coff/ecoff.h won't be found by the automatic dependency
-# scripts, since they are only included conditionally.
-nlmconv.o: nlmconv.c $(INCDIR)/coff/sym.h $(INCDIR)/coff/ecoff.h
- ldname=`echo ld | sed '$(transform)'`; \
- $(COMPILE) -c -DLD_NAME="\"$${ldname}\"" @NLMCONV_DEFS@ $(srcdir)/nlmconv.c
-
-diststuff: $(EXTRA_DIST) info
-all: info
-
-# Targets to rebuild dependencies in this Makefile.
-# Have to get rid of DEP1 here so that "$?" later includes all of $(CFILES).
-DEP: dep.sed $(CFILES) $(HFILES) $(GENERATED_CFILES) $(GENERATED_HFILES) config.h
- rm -f DEP1
- $(MAKE) MKDEP="$(MKDEP)" DEP1
- sed -f dep.sed < DEP1 > DEPA
- echo '# IF YOU PUT ANYTHING HERE IT WILL GO AWAY' >> DEPA
- if grep ' /' DEPA > /dev/null 2> /dev/null; then \
- echo 'make DEP failed!'; exit 1; \
- else \
- mv -f DEPA $@; \
- fi
-
-DEP1: $(CFILES) $(GENERATED_CFILES)
- echo '# DO NOT DELETE THIS LINE -- mkdep uses it.' > DEP2
- echo '# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.' >> DEP2
- $(MKDEP) $(INCLUDES) $(CFLAGS) $? >> DEP2
- mv -f DEP2 $@
-
-dep.sed: dep-in.sed config.status
- objdir=`pwd`; \
- sed <$(srcdir)/dep-in.sed >dep.sed \
- -e 's!@INCDIR@!$(INCDIR)!' \
- -e 's!@BFDDIR@!$(BFDDIR)!' \
- -e 's!@SRCDIR@!$(srcdir)!' \
- -e "s!@OBJDIR@!$${objdir}!" \
- -e 's!@TOPDIR@!'`echo $(srcdir) | sed -e s,/binutils$$,,`'!'
-
-dep: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < Makefile > tmp-Makefile
- cat DEP >> tmp-Makefile
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile Makefile
-
-dep-in: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < $(srcdir)/Makefile.in > tmp-Makefile.in
- cat DEP >> tmp-Makefile.in
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile.in $(srcdir)/Makefile.in
-
-dep-am: DEP
- sed -e '/^..DO NOT DELETE THIS LINE/,$$d' < $(srcdir)/Makefile.am > tmp-Makefile.am
- cat DEP >> tmp-Makefile.am
- $(SHELL) $(srcdir)/../move-if-change tmp-Makefile.am $(srcdir)/Makefile.am
-
-.PHONY: dep dep-in dep-am
-mostlyclean-local:
- -rm -rf tmpdir
-
-.PHONY: install-exec-local
-
-install-exec-local: install-binPROGRAMS $(bin_PROGRAMS) $(noinst_PROGRAMS)
- @list='$(RENAMED_PROGS)'; for p in $$list; do \
- if test -f $$p$(EXEEXT); then \
- echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p$(EXEEXT) $(bindir)/`echo $$p|sed -e 's/-new//' -e 's/cxxfilt/$(DEMANGLER_NAME)/'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
- $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p$(EXEEXT) $(DESTDIR)$(bindir)/`echo $$p|sed -e 's/-new//' -e 's/cxxfilt/$(DEMANGLER_NAME)/'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
- else :; fi; \
- done
- $(mkinstalldirs) $(DESTDIR)$(tooldir)/bin
- for i in $(TOOL_PROGS); do \
- if [ -f $$i$(EXEEXT) ]; then \
- j=`echo $$i | sed -e 's/-new//'`; \
- k=`echo $$j | sed '$(transform)'`; \
- if [ "$(bindir)/$$k" != "$(tooldir)/bin/$$j" ]; then \
- rm -f $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT); \
- ln $(DESTDIR)$(bindir)/$$k$(EXEEXT) $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT) >/dev/null 2>/dev/null \
- || $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$i$(EXEEXT) $(DESTDIR)$(tooldir)/bin/$$j$(EXEEXT); \
- fi; \
- else true; \
- fi; \
- done
-
-# What appears below is generated by a hacked mkdep using gcc -MM.
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
-addr2line.o: addr2line.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- bucomm.h
-ar.o: ar.c sysdep.h config.h $(INCDIR)/ansidecl.h ../bfd/bfdver.h \
- $(INCDIR)/fopen-same.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/progress.h $(INCDIR)/aout/ar.h $(BFDDIR)/libbfd.h \
- $(INCDIR)/hashtab.h bucomm.h arsup.h $(INCDIR)/filenames.h \
- binemul.h
-arsup.o: arsup.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/filenames.h bucomm.h \
- arsup.h
-bin2c.o: bin2c.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-binemul.o: binemul.c binemul.h sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-bucomm.o: bucomm.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/filenames.h $(BFDDIR)/libbfd.h \
- $(INCDIR)/hashtab.h bucomm.h
-coffdump.o: coffdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h coffgrok.h
-coffgrok.o: coffgrok.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h \
- $(INCDIR)/bfdlink.h bucomm.h coffgrok.h
-cxxfilt.o: cxxfilt.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- $(INCDIR)/safe-ctype.h bucomm.h
-dwarf.o: dwarf.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h bucomm.h $(INCDIR)/elf/common.h \
- $(INCDIR)/elf/dwarf2.h dwarf.h
-debug.o: debug.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h debug.h
-dlltool.o: dlltool.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- $(INCDIR)/dyn-string.h bucomm.h dlltool.h $(INCDIR)/safe-ctype.h
-dllwrap.o: dllwrap.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/dyn-string.h bucomm.h
-emul_aix.o: emul_aix.c binemul.h sysdep.h config.h \
- $(INCDIR)/ansidecl.h ../bfd/bfdver.h $(INCDIR)/fopen-same.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- bucomm.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/internal.h \
- $(INCDIR)/coff/xcoff.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h \
- $(BFDDIR)/libxcoff.h
-emul_vanilla.o: emul_vanilla.c binemul.h sysdep.h config.h \
- $(INCDIR)/ansidecl.h ../bfd/bfdver.h $(INCDIR)/fopen-same.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- bucomm.h
-filemode.o: filemode.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-ieee.o: ieee.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/ieee.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h debug.h \
- budbg.h $(INCDIR)/filenames.h
-is-ranlib.o: is-ranlib.c
-is-strip.o: is-strip.c
-maybe-ranlib.o: maybe-ranlib.c
-maybe-strip.o: maybe-strip.c
-nlmconv.o: nlmconv.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(BFDDIR)/libnlm.h \
- $(INCDIR)/nlm/common.h $(INCDIR)/nlm/internal.h $(INCDIR)/nlm/external.h \
- nlmconv.h bucomm.h
-nm.o: nm.c sysdep.h config.h $(INCDIR)/ansidecl.h ../bfd/bfdver.h \
- $(INCDIR)/fopen-same.h ../bfd/bfd.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/symcat.h $(INCDIR)/progress.h $(INCDIR)/aout/stab_gnu.h \
- $(INCDIR)/aout/stab.def $(INCDIR)/aout/ranlib.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
- $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \
- $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/common.h \
- bucomm.h
-not-ranlib.o: not-ranlib.c
-not-strip.o: not-strip.c
-objcopy.o: objcopy.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/progress.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h $(BFDDIR)/elf-bfd.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/bfdlink.h $(BFDDIR)/libbfd.h $(INCDIR)/hashtab.h
-objdump.o: objdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(BFDDIR)/elf-bfd.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/bfdlink.h $(INCDIR)/progress.h bucomm.h dwarf.h \
- $(INCDIR)/safe-ctype.h $(INCDIR)/dis-asm.h ../bfd/bfd.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h debug.h budbg.h $(INCDIR)/aout/aout64.h
-prdbg.o: prdbg.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/demangle.h $(INCDIR)/libiberty.h \
- debug.h budbg.h
-rclex.o: rclex.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windres.h \
- winduni.h windint.h rcparse.h
-rdcoff.o: rdcoff.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/coff/internal.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- debug.h budbg.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h
-rddbg.o: rddbg.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h debug.h budbg.h
-readelf.o: readelf.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h dwarf.h \
- $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
- $(INCDIR)/elf/h8.h $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/alpha.h \
- $(INCDIR)/elf/arc.h $(INCDIR)/elf/arm.h $(INCDIR)/elf/avr.h \
- $(INCDIR)/elf/bfin.h $(INCDIR)/elf/cr16.h $(INCDIR)/elf/cris.h \
- $(INCDIR)/elf/crx.h $(INCDIR)/elf/d10v.h $(INCDIR)/elf/d30v.h \
- $(INCDIR)/elf/dlx.h $(INCDIR)/elf/fr30.h $(INCDIR)/elf/frv.h \
- $(INCDIR)/elf/hppa.h $(INCDIR)/elf/i386.h $(INCDIR)/elf/i370.h \
- $(INCDIR)/elf/i860.h $(INCDIR)/elf/i960.h $(INCDIR)/elf/ia64.h \
- $(INCDIR)/elf/ip2k.h $(INCDIR)/elf/iq2000.h $(INCDIR)/elf/m32c.h \
- $(INCDIR)/elf/m32r.h $(INCDIR)/elf/m68k.h $(INCDIR)/elf/m68hc11.h \
- $(INCDIR)/elf/mcore.h $(INCDIR)/elf/mep.h $(INCDIR)/elf/mips.h \
- $(INCDIR)/elf/mmix.h $(INCDIR)/elf/mn10200.h $(INCDIR)/elf/mn10300.h \
- $(INCDIR)/elf/mt.h $(INCDIR)/elf/msp430.h $(INCDIR)/elf/or32.h \
- $(INCDIR)/elf/pj.h $(INCDIR)/elf/ppc.h $(INCDIR)/elf/ppc64.h \
- $(INCDIR)/elf/s390.h $(INCDIR)/elf/score.h $(INCDIR)/elf/sh.h \
- $(INCDIR)/elf/sparc.h $(INCDIR)/elf/spu.h $(INCDIR)/elf/v850.h \
- $(INCDIR)/elf/vax.h $(INCDIR)/elf/x86-64.h $(INCDIR)/elf/xstormy16.h \
- $(INCDIR)/elf/xtensa.h $(INCDIR)/aout/ar.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h unwind-ia64.h
-rename.o: rename.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-resbin.o: resbin.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h
-rescoff.o: rescoff.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h \
- $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h
-resrc.o: resrc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windres.h \
- winduni.h windint.h
-resres.o: resres.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h
-size.o: size.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h
-srconv.o: srconv.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h sysroff.h \
- coffgrok.h $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- $(INCDIR)/coff/internal.h $(BFDDIR)/libcoff.h $(INCDIR)/bfdlink.h \
- sysroff.c
-stabs.o: stabs.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/demangle.h \
- $(INCDIR)/libiberty.h debug.h budbg.h $(INCDIR)/filenames.h \
- $(INCDIR)/aout/aout64.h $(INCDIR)/aout/stab_gnu.h $(INCDIR)/aout/stab.def
-strings.o: strings.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h bucomm.h
-sysdump.o: sysdump.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/safe-ctype.h \
- $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h bucomm.h \
- sysroff.h sysroff.c $(INCDIR)/ansidecl.h
-unwind-ia64.o: unwind-ia64.c unwind-ia64.h $(INCDIR)/elf/ia64.h \
- $(INCDIR)/elf/reloc-macros.h $(INCDIR)/ansidecl.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h
-version.o: version.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h
-windres.o: windres.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
- windres.h winduni.h windint.h
-winduni.o: winduni.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h bucomm.h winduni.h $(INCDIR)/safe-ctype.h
-wrstabs.o: wrstabs.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h bucomm.h \
- debug.h budbg.h $(INCDIR)/aout/aout64.h $(INCDIR)/aout/stab_gnu.h \
- $(INCDIR)/aout/stab.def
-windmc.o: windmc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
- windmc.h winduni.h windint.h
-mclex.o: mclex.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h windmc.h \
- winduni.h mcparse.h
-arparse.o: arparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h arsup.h
-arlex.o: arlex.c $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h arparse.h
-sysroff.o: sysroff.c
-sysinfo.o: sysinfo.c
-syslex.o: syslex.c config.h sysinfo.h
-defparse.o: defparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h dlltool.h
-deflex.o: deflex.c $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h \
- defparse.h dlltool.h $(INCDIR)/ansidecl.h
-nlmheader.o: nlmheader.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h $(INCDIR)/safe-ctype.h \
- ../bfd/bfd.h $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
- $(INCDIR)/nlm/common.h $(INCDIR)/nlm/internal.h bucomm.h \
- nlmconv.h
-rcparse.o: rcparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windres.h winduni.h windint.h \
- $(INCDIR)/safe-ctype.h
-mcparse.o: mcparse.c sysdep.h config.h $(INCDIR)/ansidecl.h \
- ../bfd/bfdver.h $(INCDIR)/fopen-same.h ../bfd/bfd.h \
- $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h $(INCDIR)/libiberty.h \
- $(INCDIR)/ansidecl.h windmc.h winduni.h $(INCDIR)/safe-ctype.h
-# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
deleted file mode 100644
index 505402bf663..00000000000
--- a/binutils/dlltool.c
+++ /dev/null
@@ -1,3678 +0,0 @@
-/* dlltool.c -- tool to generate stuff for PE style DLLs
- Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
-
- This file is part of GNU Binutils.
-
- 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 program allows you to build the files necessary to create
- DLLs to run on a system which understands PE format image files.
- (eg, Windows NT)
-
- See "Peering Inside the PE: A Tour of the Win32 Portable Executable
- File Format", MSJ 1994, Volume 9 for more information.
- Also see "Microsoft Portable Executable and Common Object File Format,
- Specification 4.1" for more information.
-
- A DLL contains an export table which contains the information
- which the runtime loader needs to tie up references from a
- referencing program.
-
- The export table is generated by this program by reading
- in a .DEF file or scanning the .a and .o files which will be in the
- DLL. A .o file can contain information in special ".drectve" sections
- with export information.
-
- A DEF file contains any number of the following commands:
-
-
- NAME <name> [ , <base> ]
- The result is going to be <name>.EXE
-
- LIBRARY <name> [ , <base> ]
- The result is going to be <name>.DLL
-
- EXPORTS ( ( ( <name1> [ = <name2> ] )
- | ( <name1> = <module-name> . <external-name>))
- [ @ <integer> ] [ NONAME ] [CONSTANT] [DATA] [PRIVATE] ) *
- Declares name1 as an exported symbol from the
- DLL, with optional ordinal number <integer>.
- Or declares name1 as an alias (forward) of the function <external-name>
- in the DLL <module-name>.
-
- IMPORTS ( ( <internal-name> = <module-name> . <integer> )
- | ( [ <internal-name> = ] <module-name> . <external-name> )) *
- Declares that <external-name> or the exported function whose ordinal number
- is <integer> is to be imported from the file <module-name>. If
- <internal-name> is specified then this is the name that the imported
- function will be refereed to in the body of the DLL.
-
- DESCRIPTION <string>
- Puts <string> into output .exp file in the .rdata section
-
- [STACKSIZE|HEAPSIZE] <number-reserve> [ , <number-commit> ]
- Generates --stack|--heap <number-reserve>,<number-commit>
- in the output .drectve section. The linker will
- see this and act upon it.
-
- [CODE|DATA] <attr>+
- SECTIONS ( <sectionname> <attr>+ )*
- <attr> = READ | WRITE | EXECUTE | SHARED
- Generates --attr <sectionname> <attr> in the output
- .drectve section. The linker will see this and act
- upon it.
-
-
- A -export:<name> in a .drectve section in an input .o or .a
- file to this program is equivalent to a EXPORTS <name>
- in a .DEF file.
-
-
-
- The program generates output files with the prefix supplied
- on the command line, or in the def file, or taken from the first
- supplied argument.
-
- The .exp.s file contains the information necessary to export
- the routines in the DLL. The .lib.s file contains the information
- necessary to use the DLL's routines from a referencing program.
-
-
-
- Example:
-
- file1.c:
- asm (".section .drectve");
- asm (".ascii \"-export:adef\"");
-
- void adef (char * s)
- {
- printf ("hello from the dll %s\n", s);
- }
-
- void bdef (char * s)
- {
- printf ("hello from the dll and the other entry point %s\n", s);
- }
-
- file2.c:
- asm (".section .drectve");
- asm (".ascii \"-export:cdef\"");
- asm (".ascii \"-export:ddef\"");
-
- void cdef (char * s)
- {
- printf ("hello from the dll %s\n", s);
- }
-
- void ddef (char * s)
- {
- printf ("hello from the dll and the other entry point %s\n", s);
- }
-
- int printf (void)
- {
- return 9;
- }
-
- themain.c:
- int main (void)
- {
- cdef ();
- return 0;
- }
-
- thedll.def
-
- LIBRARY thedll
- HEAPSIZE 0x40000, 0x2000
- EXPORTS bdef @ 20
- cdef @ 30 NONAME
-
- SECTIONS donkey READ WRITE
- aardvark EXECUTE
-
- # Compile up the parts of the dll and the program
-
- gcc -c file1.c file2.c themain.c
-
- # Optional: put the dll objects into a library
- # (you don't have to, you could name all the object
- # files on the dlltool line)
-
- ar qcv thedll.in file1.o file2.o
- ranlib thedll.in
-
- # Run this tool over the DLL's .def file and generate an exports
- # file (thedll.o) and an imports file (thedll.a).
- # (You may have to use -S to tell dlltool where to find the assembler).
-
- dlltool --def thedll.def --output-exp thedll.o --output-lib thedll.a
-
- # Build the dll with the library and the export table
-
- ld -o thedll.dll thedll.o thedll.in
-
- # Link the executable with the import library
-
- gcc -o themain.exe themain.o thedll.a
-
- This example can be extended if relocations are needed in the DLL:
-
- # Compile up the parts of the dll and the program
-
- gcc -c file1.c file2.c themain.c
-
- # Run this tool over the DLL's .def file and generate an imports file.
-
- dlltool --def thedll.def --output-lib thedll.lib
-
- # Link the executable with the import library and generate a base file
- # at the same time
-
- gcc -o themain.exe themain.o thedll.lib -Wl,--base-file -Wl,themain.base
-
- # Run this tool over the DLL's .def file and generate an exports file
- # which includes the relocations from the base file.
-
- dlltool --def thedll.def --base-file themain.base --output-exp thedll.exp
-
- # Build the dll with file1.o, file2.o and the export table
-
- ld -o thedll.dll thedll.exp file1.o file2.o */
-
-/* .idata section description
-
- The .idata section is the import table. It is a collection of several
- subsections used to keep the pieces for each dll together: .idata$[234567].
- IE: Each dll's .idata$2's are catenated together, each .idata$3's, etc.
-
- .idata$2 = Import Directory Table
- = array of IMAGE_IMPORT_DESCRIPTOR's.
-
- DWORD Import Lookup Table; - pointer to .idata$4
- DWORD TimeDateStamp; - currently always 0
- DWORD ForwarderChain; - currently always 0
- DWORD Name; - pointer to dll's name
- PIMAGE_THUNK_DATA FirstThunk; - pointer to .idata$5
-
- .idata$3 = null terminating entry for .idata$2.
-
- .idata$4 = Import Lookup Table
- = array of array of pointers to hint name table.
- There is one for each dll being imported from, and each dll's set is
- terminated by a trailing NULL.
-
- .idata$5 = Import Address Table
- = array of array of pointers to hint name table.
- There is one for each dll being imported from, and each dll's set is
- terminated by a trailing NULL.
- Initially, this table is identical to the Import Lookup Table. However,
- at load time, the loader overwrites the entries with the address of the
- function.
-
- .idata$6 = Hint Name Table
- = Array of { short, asciz } entries, one for each imported function.
- The `short' is the function's ordinal number.
-
- .idata$7 = dll name (eg: "kernel32.dll"). (.idata$6 for ppc). */
-
-/* AIX requires this to be the first thing in the file. */
-#ifndef __GNUC__
-# ifdef _AIX
- #pragma alloca
-#endif
-#endif
-
-#define show_allnames 0
-
-#define PAGE_SIZE 4096
-#define PAGE_MASK (-PAGE_SIZE)
-#include "sysdep.h"
-#include "bfd.h"
-#include "libiberty.h"
-#include "getopt.h"
-#include "demangle.h"
-#include "dyn-string.h"
-#include "bucomm.h"
-#include "dlltool.h"
-#include "safe-ctype.h"
-
-#include <time.h>
-#include <sys/stat.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#ifdef DLLTOOL_ARM
-#include "coff/arm.h"
-#include "coff/internal.h"
-#endif
-#ifdef DLLTOOL_MX86_64
-#include "coff/x86_64.h"
-#endif
-
-/* Forward references. */
-static char *look_for_prog (const char *, const char *, int);
-static char *deduce_name (const char *);
-
-#ifdef DLLTOOL_MCORE_ELF
-static void mcore_elf_cache_filename (const char *);
-static void mcore_elf_gen_out_file (void);
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#else /* ! HAVE_SYS_WAIT_H */
-#if ! defined (_WIN32) || defined (__CYGWIN32__)
-#ifndef WIFEXITED
-#define WIFEXITED(w) (((w) & 0377) == 0)
-#endif
-#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w) & 0377) != 0177 && ((w) & ~0377) == 0)
-#endif
-#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0177)
-#endif
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) >> 8) & 0377)
-#endif
-#else /* defined (_WIN32) && ! defined (__CYGWIN32__) */
-#ifndef WIFEXITED
-#define WIFEXITED(w) (((w) & 0xff) == 0)
-#endif
-#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w) & 0xff) != 0 && ((w) & 0xff) != 0x7f)
-#endif
-#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0x7f)
-#endif
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) & 0xff00) >> 8)
-#endif
-#endif /* defined (_WIN32) && ! defined (__CYGWIN32__) */
-#endif /* ! HAVE_SYS_WAIT_H */
-
-/* ifunc and ihead data structures: ttk@cygnus.com 1997
-
- When IMPORT declarations are encountered in a .def file the
- function import information is stored in a structure referenced by
- the global variable IMPORT_LIST. The structure is a linked list
- containing the names of the dll files each function is imported
- from and a linked list of functions being imported from that dll
- file. This roughly parallels the structure of the .idata section
- in the PE object file.
-
- The contents of .def file are interpreted from within the
- process_def_file function. Every time an IMPORT declaration is
- encountered, it is broken up into its component parts and passed to
- def_import. IMPORT_LIST is initialized to NULL in function main. */
-
-typedef struct ifunct
-{
- char * name; /* Name of function being imported. */
- int ord; /* Two-byte ordinal value associated with function. */
- struct ifunct *next;
-} ifunctype;
-
-typedef struct iheadt
-{
- char *dllname; /* Name of dll file imported from. */
- long nfuncs; /* Number of functions in list. */
- struct ifunct *funchead; /* First function in list. */
- struct ifunct *functail; /* Last function in list. */
- struct iheadt *next; /* Next dll file in list. */
-} iheadtype;
-
-/* Structure containing all import information as defined in .def file
- (qv "ihead structure"). */
-
-static iheadtype *import_list = NULL;
-
-static char *as_name = NULL;
-static char * as_flags = "";
-
-static char *tmp_prefix;
-
-static int no_idata4;
-static int no_idata5;
-static char *exp_name;
-static char *imp_name;
-static char *head_label;
-static char *imp_name_lab;
-static char *dll_name;
-
-static int add_indirect = 0;
-static int add_underscore = 0;
-static int add_stdcall_underscore = 0;
-static int dontdeltemps = 0;
-
-/* TRUE if we should export all symbols. Otherwise, we only export
- symbols listed in .drectve sections or in the def file. */
-static bfd_boolean export_all_symbols;
-
-/* TRUE if we should exclude the symbols in DEFAULT_EXCLUDES when
- exporting all symbols. */
-static bfd_boolean do_default_excludes = TRUE;
-
-/* Default symbols to exclude when exporting all the symbols. */
-static const char *default_excludes = "DllMain@12,DllEntryPoint@0,impure_ptr";
-
-/* TRUE if we should add __imp_<SYMBOL> to import libraries for backward
- compatibility to old Cygwin releases. */
-static bfd_boolean create_compat_implib;
-
-static char *def_file;
-
-extern char * program_name;
-
-static int machine;
-static int killat;
-static int add_stdcall_alias;
-static const char *ext_prefix_alias;
-static int verbose;
-static FILE *output_def;
-static FILE *base_file;
-
-#ifdef DLLTOOL_DEFAULT_ARM
-static const char *mname = "arm";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_ARM_EPOC
-static const char *mname = "arm-epoc";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_ARM_WINCE
-static const char *mname = "arm-wince";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_I386
-static const char *mname = "i386";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_MX86_64
-static const char *mname = "i386:x86-64";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_PPC
-static const char *mname = "ppc";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_SH
-static const char *mname = "sh";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_MIPS
-static const char *mname = "mips";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_MCORE
-static const char * mname = "mcore-le";
-#endif
-
-#ifdef DLLTOOL_DEFAULT_MCORE_ELF
-static const char * mname = "mcore-elf";
-static char * mcore_elf_out_file = NULL;
-static char * mcore_elf_linker = NULL;
-static char * mcore_elf_linker_flags = NULL;
-
-#define DRECTVE_SECTION_NAME ((machine == MMCORE_ELF || machine == MMCORE_ELF_LE) ? ".exports" : ".drectve")
-#endif
-
-#ifndef DRECTVE_SECTION_NAME
-#define DRECTVE_SECTION_NAME ".drectve"
-#endif
-
-/* What's the right name for this ? */
-#define PATHMAX 250
-
-/* External name alias numbering starts here. */
-#define PREFIX_ALIAS_BASE 20000
-
-char *tmp_asm_buf;
-char *tmp_head_s_buf;
-char *tmp_head_o_buf;
-char *tmp_tail_s_buf;
-char *tmp_tail_o_buf;
-char *tmp_stub_buf;
-
-#define TMP_ASM dlltmp (&tmp_asm_buf, "%sc.s")
-#define TMP_HEAD_S dlltmp (&tmp_head_s_buf, "%sh.s")
-#define TMP_HEAD_O dlltmp (&tmp_head_o_buf, "%sh.o")
-#define TMP_TAIL_S dlltmp (&tmp_tail_s_buf, "%st.s")
-#define TMP_TAIL_O dlltmp (&tmp_tail_o_buf, "%st.o")
-#define TMP_STUB dlltmp (&tmp_stub_buf, "%ss")
-
-/* This bit of assembly does jmp * .... */
-static const unsigned char i386_jtab[] =
-{
- 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90
-};
-
-static const unsigned char arm_jtab[] =
-{
- 0x00, 0xc0, 0x9f, 0xe5, /* ldr ip, [pc] */
- 0x00, 0xf0, 0x9c, 0xe5, /* ldr pc, [ip] */
- 0, 0, 0, 0
-};
-
-static const unsigned char arm_interwork_jtab[] =
-{
- 0x04, 0xc0, 0x9f, 0xe5, /* ldr ip, [pc] */
- 0x00, 0xc0, 0x9c, 0xe5, /* ldr ip, [ip] */
- 0x1c, 0xff, 0x2f, 0xe1, /* bx ip */
- 0, 0, 0, 0
-};
-
-static const unsigned char thumb_jtab[] =
-{
- 0x40, 0xb4, /* push {r6} */
- 0x02, 0x4e, /* ldr r6, [pc, #8] */
- 0x36, 0x68, /* ldr r6, [r6] */
- 0xb4, 0x46, /* mov ip, r6 */
- 0x40, 0xbc, /* pop {r6} */
- 0x60, 0x47, /* bx ip */
- 0, 0, 0, 0
-};
-
-static const unsigned char mcore_be_jtab[] =
-{
- 0x71, 0x02, /* lrw r1,2 */
- 0x81, 0x01, /* ld.w r1,(r1,0) */
- 0x00, 0xC1, /* jmp r1 */
- 0x12, 0x00, /* nop */
- 0x00, 0x00, 0x00, 0x00 /* <address> */
-};
-
-static const unsigned char mcore_le_jtab[] =
-{
- 0x02, 0x71, /* lrw r1,2 */
- 0x01, 0x81, /* ld.w r1,(r1,0) */
- 0xC1, 0x00, /* jmp r1 */
- 0x00, 0x12, /* nop */
- 0x00, 0x00, 0x00, 0x00 /* <address> */
-};
-
-/* This is the glue sequence for PowerPC PE. There is a
- tocrel16-tocdefn reloc against the first instruction.
- We also need a IMGLUE reloc against the glue function
- to restore the toc saved by the third instruction in
- the glue. */
-static const unsigned char ppc_jtab[] =
-{
- 0x00, 0x00, 0x62, 0x81, /* lwz r11,0(r2) */
- /* Reloc TOCREL16 __imp_xxx */
- 0x00, 0x00, 0x8B, 0x81, /* lwz r12,0(r11) */
- 0x04, 0x00, 0x41, 0x90, /* stw r2,4(r1) */
- 0xA6, 0x03, 0x89, 0x7D, /* mtctr r12 */
- 0x04, 0x00, 0x4B, 0x80, /* lwz r2,4(r11) */
- 0x20, 0x04, 0x80, 0x4E /* bctr */
-};
-
-#ifdef DLLTOOL_PPC
-/* The glue instruction, picks up the toc from the stw in
- the above code: "lwz r2,4(r1)". */
-static bfd_vma ppc_glue_insn = 0x80410004;
-#endif
-
-struct mac
- {
- const char *type;
- const char *how_byte;
- const char *how_short;
- const char *how_long;
- const char *how_asciz;
- const char *how_comment;
- const char *how_jump;
- const char *how_global;
- const char *how_space;
- const char *how_align_short;
- const char *how_align_long;
- const char *how_default_as_switches;
- const char *how_bfd_target;
- enum bfd_architecture how_bfd_arch;
- const unsigned char *how_jtab;
- int how_jtab_size; /* Size of the jtab entry. */
- int how_jtab_roff; /* Offset into it for the ind 32 reloc into idata 5. */
- };
-
-static const struct mac
-mtable[] =
-{
- {
-#define MARM 0
- "arm", ".byte", ".short", ".long", ".asciz", "@",
- "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",
- ".global", ".space", ".align\t2",".align\t4", "-mapcs-32",
- "pe-arm-little", bfd_arch_arm,
- arm_jtab, sizeof (arm_jtab), 8
- }
- ,
- {
-#define M386 1
- "i386", ".byte", ".short", ".long", ".asciz", "#",
- "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
- "pe-i386",bfd_arch_i386,
- i386_jtab, sizeof (i386_jtab), 2
- }
- ,
- {
-#define MPPC 2
- "ppc", ".byte", ".short", ".long", ".asciz", "#",
- "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
- "pe-powerpcle",bfd_arch_powerpc,
- ppc_jtab, sizeof (ppc_jtab), 0
- }
- ,
- {
-#define MTHUMB 3
- "thumb", ".byte", ".short", ".long", ".asciz", "@",
- "push\t{r6}\n\tldr\tr6, [pc, #8]\n\tldr\tr6, [r6]\n\tmov\tip, r6\n\tpop\t{r6}\n\tbx\tip",
- ".global", ".space", ".align\t2",".align\t4", "-mthumb-interwork",
- "pe-arm-little", bfd_arch_arm,
- thumb_jtab, sizeof (thumb_jtab), 12
- }
- ,
-#define MARM_INTERWORK 4
- {
- "arm_interwork", ".byte", ".short", ".long", ".asciz", "@",
- "ldr\tip,[pc]\n\tldr\tip,[ip]\n\tbx\tip\n\t.long",
- ".global", ".space", ".align\t2",".align\t4", "-mthumb-interwork",
- "pe-arm-little", bfd_arch_arm,
- arm_interwork_jtab, sizeof (arm_interwork_jtab), 12
- }
- ,
- {
-#define MMCORE_BE 5
- "mcore-be", ".byte", ".short", ".long", ".asciz", "//",
- "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",
- ".global", ".space", ".align\t2",".align\t4", "",
- "pe-mcore-big", bfd_arch_mcore,
- mcore_be_jtab, sizeof (mcore_be_jtab), 8
- }
- ,
- {
-#define MMCORE_LE 6
- "mcore-le", ".byte", ".short", ".long", ".asciz", "//",
- "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",
- ".global", ".space", ".align\t2",".align\t4", "-EL",
- "pe-mcore-little", bfd_arch_mcore,
- mcore_le_jtab, sizeof (mcore_le_jtab), 8
- }
- ,
- {
-#define MMCORE_ELF 7
- "mcore-elf-be", ".byte", ".short", ".long", ".asciz", "//",
- "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",
- ".global", ".space", ".align\t2",".align\t4", "",
- "elf32-mcore-big", bfd_arch_mcore,
- mcore_be_jtab, sizeof (mcore_be_jtab), 8
- }
- ,
- {
-#define MMCORE_ELF_LE 8
- "mcore-elf-le", ".byte", ".short", ".long", ".asciz", "//",
- "lrw r1,[1f]\n\tld.w r1,(r1,0)\n\tjmp r1\n\tnop\n1:.long",
- ".global", ".space", ".align\t2",".align\t4", "-EL",
- "elf32-mcore-little", bfd_arch_mcore,
- mcore_le_jtab, sizeof (mcore_le_jtab), 8
- }
- ,
- {
-#define MARM_EPOC 9
- "arm-epoc", ".byte", ".short", ".long", ".asciz", "@",
- "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",
- ".global", ".space", ".align\t2",".align\t4", "",
- "epoc-pe-arm-little", bfd_arch_arm,
- arm_jtab, sizeof (arm_jtab), 8
- }
- ,
- {
-#define MARM_WINCE 10
- "arm-wince", ".byte", ".short", ".long", ".asciz", "@",
- "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",
- ".global", ".space", ".align\t2",".align\t4", "-mapcs-32",
- "pe-arm-wince-little", bfd_arch_arm,
- arm_jtab, sizeof (arm_jtab), 8
- }
- ,
- {
-#define MX86 11
- "i386:x86-64", ".byte", ".short", ".long", ".asciz", "#",
- "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
- "pe-x86-64",bfd_arch_i386,
- i386_jtab, sizeof (i386_jtab), 2
- }
- ,
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-};
-
-typedef struct dlist
-{
- char *text;
- struct dlist *next;
-}
-dlist_type;
-
-typedef struct export
- {
- const char *name;
- const char *internal_name;
- const char *import_name;
- int ordinal;
- int constant;
- int noname; /* Don't put name in image file. */
- int private; /* Don't put reference in import lib. */
- int data;
- int hint;
- int forward; /* Number of forward label, 0 means no forward. */
- struct export *next;
- }
-export_type;
-
-/* A list of symbols which we should not export. */
-
-struct string_list
-{
- struct string_list *next;
- char *string;
-};
-
-static struct string_list *excludes;
-
-static const char *rvaafter (int);
-static const char *rvabefore (int);
-static const char *asm_prefix (int, const char *);
-static void process_def_file (const char *);
-static void new_directive (char *);
-static void append_import (const char *, const char *, int);
-static void run (const char *, char *);
-static void scan_drectve_symbols (bfd *);
-static void scan_filtered_symbols (bfd *, void *, long, unsigned int);
-static void add_excludes (const char *);
-static bfd_boolean match_exclude (const char *);
-static void set_default_excludes (void);
-static long filter_symbols (bfd *, void *, long, unsigned int);
-static void scan_all_symbols (bfd *);
-static void scan_open_obj_file (bfd *);
-static void scan_obj_file (const char *);
-static void dump_def_info (FILE *);
-static int sfunc (const void *, const void *);
-static void flush_page (FILE *, long *, int, int);
-static void gen_def_file (void);
-static void generate_idata_ofile (FILE *);
-static void assemble_file (const char *, const char *);
-static void gen_exp_file (void);
-static const char *xlate (const char *);
-static char *make_label (const char *, const char *);
-static char *make_imp_label (const char *, const char *);
-static bfd *make_one_lib_file (export_type *, int);
-static bfd *make_head (void);
-static bfd *make_tail (void);
-static void gen_lib_file (void);
-static int pfunc (const void *, const void *);
-static int nfunc (const void *, const void *);
-static void remove_null_names (export_type **);
-static void process_duplicates (export_type **);
-static void fill_ordinals (export_type **);
-static void mangle_defs (void);
-static void usage (FILE *, int);
-static void inform (const char *, ...) ATTRIBUTE_PRINTF_1;
-static void set_dll_name_from_def (const char *);
-
-static char *
-prefix_encode (char *start, unsigned code)
-{
- static char alpha[26] = "abcdefghijklmnopqrstuvwxyz";
- static char buf[32];
- char *p;
- strcpy (buf, start);
- p = strchr (buf, '\0');
- do
- *p++ = alpha[code % sizeof (alpha)];
- while ((code /= sizeof (alpha)) != 0);
- *p = '\0';
- return buf;
-}
-
-static char *
-dlltmp (char **buf, const char *fmt)
-{
- if (!*buf)
- {
- *buf = malloc (strlen (tmp_prefix) + 64);
- sprintf (*buf, fmt, tmp_prefix);
- }
- return *buf;
-}
-
-static void
-inform VPARAMS ((const char * message, ...))
-{
- VA_OPEN (args, message);
- VA_FIXEDARG (args, const char *, message);
-
- if (!verbose)
- return;
-
- report (message, args);
-
- VA_CLOSE (args);
-}
-
-static const char *
-rvaafter (int machine)
-{
- switch (machine)
- {
- case MARM:
- case M386:
- case MX86:
- case MPPC:
- case MTHUMB:
- case MARM_INTERWORK:
- case MMCORE_BE:
- case MMCORE_LE:
- case MMCORE_ELF:
- case MMCORE_ELF_LE:
- case MARM_EPOC:
- case MARM_WINCE:
- break;
- default:
- /* xgettext:c-format */
- fatal (_("Internal error: Unknown machine type: %d"), machine);
- break;
- }
- return "";
-}
-
-static const char *
-rvabefore (int machine)
-{
- switch (machine)
- {
- case MARM:
- case M386:
- case MX86:
- case MPPC:
- case MTHUMB:
- case MARM_INTERWORK:
- case MMCORE_BE:
- case MMCORE_LE:
- case MMCORE_ELF:
- case MMCORE_ELF_LE:
- case MARM_EPOC:
- case MARM_WINCE:
- return ".rva\t";
- default:
- /* xgettext:c-format */
- fatal (_("Internal error: Unknown machine type: %d"), machine);
- break;
- }
- return "";
-}
-
-static const char *
-asm_prefix (int machine, const char *name)
-{
- switch (machine)
- {
- case MARM:
- case MPPC:
- case MTHUMB:
- case MARM_INTERWORK:
- case MMCORE_BE:
- case MMCORE_LE:
- case MMCORE_ELF:
- case MMCORE_ELF_LE:
- case MARM_EPOC:
- case MARM_WINCE:
- break;
- case M386:
- case MX86:
- /* Symbol names starting with ? do not have a leading underscore. */
- if (name && *name == '?')
- break;
- else
- return "_";
- default:
- /* xgettext:c-format */
- fatal (_("Internal error: Unknown machine type: %d"), machine);
- break;
- }
- return "";
-}
-
-#define ASM_BYTE mtable[machine].how_byte
-#define ASM_SHORT mtable[machine].how_short
-#define ASM_LONG mtable[machine].how_long
-#define ASM_TEXT mtable[machine].how_asciz
-#define ASM_C mtable[machine].how_comment
-#define ASM_JUMP mtable[machine].how_jump
-#define ASM_GLOBAL mtable[machine].how_global
-#define ASM_SPACE mtable[machine].how_space
-#define ASM_ALIGN_SHORT mtable[machine].how_align_short
-#define ASM_RVA_BEFORE rvabefore (machine)
-#define ASM_RVA_AFTER rvaafter (machine)
-#define ASM_PREFIX(NAME) asm_prefix (machine, (NAME))
-#define ASM_ALIGN_LONG mtable[machine].how_align_long
-#define HOW_BFD_READ_TARGET 0 /* Always default. */
-#define HOW_BFD_WRITE_TARGET mtable[machine].how_bfd_target
-#define HOW_BFD_ARCH mtable[machine].how_bfd_arch
-#define HOW_JTAB mtable[machine].how_jtab
-#define HOW_JTAB_SIZE mtable[machine].how_jtab_size
-#define HOW_JTAB_ROFF mtable[machine].how_jtab_roff
-#define ASM_SWITCHES mtable[machine].how_default_as_switches
-
-static char **oav;
-
-static void
-process_def_file (const char *name)
-{
- FILE *f = fopen (name, FOPEN_RT);
-
- if (!f)
- /* xgettext:c-format */
- fatal (_("Can't open def file: %s"), name);
-
- yyin = f;
-
- /* xgettext:c-format */
- inform (_("Processing def file: %s"), name);
-
- yyparse ();
-
- inform (_("Processed def file"));
-}
-
-/**********************************************************************/
-
-/* Communications with the parser. */
-
-static int d_nfuncs; /* Number of functions exported. */
-static int d_named_nfuncs; /* Number of named functions exported. */
-static int d_low_ord; /* Lowest ordinal index. */
-static int d_high_ord; /* Highest ordinal index. */
-static export_type *d_exports; /* List of exported functions. */
-static export_type **d_exports_lexically; /* Vector of exported functions in alpha order. */
-static dlist_type *d_list; /* Descriptions. */
-static dlist_type *a_list; /* Stuff to go in directives. */
-static int d_nforwards = 0; /* Number of forwarded exports. */
-
-static int d_is_dll;
-static int d_is_exe;
-
-int
-yyerror (const char * err ATTRIBUTE_UNUSED)
-{
- /* xgettext:c-format */
- non_fatal (_("Syntax error in def file %s:%d"), def_file, linenumber);
-
- return 0;
-}
-
-void
-def_exports (const char *name, const char *internal_name, int ordinal,
- int noname, int constant, int data, int private)
-{
- struct export *p = (struct export *) xmalloc (sizeof (*p));
-
- p->name = name;
- p->internal_name = internal_name ? internal_name : name;
- p->import_name = name;
- p->ordinal = ordinal;
- p->constant = constant;
- p->noname = noname;
- p->private = private;
- p->data = data;
- p->next = d_exports;
- d_exports = p;
- d_nfuncs++;
-
- if ((internal_name != NULL)
- && (strchr (internal_name, '.') != NULL))
- p->forward = ++d_nforwards;
- else
- p->forward = 0; /* no forward */
-}
-
-static void
-set_dll_name_from_def (const char * name)
-{
- const char* image_basename = lbasename (name);
- if (image_basename != name)
- non_fatal (_("%s: Path components stripped from image name, '%s'."),
- def_file, name);
- dll_name = xstrdup (image_basename);
-}
-
-void
-def_name (const char *name, int base)
-{
- /* xgettext:c-format */
- inform (_("NAME: %s base: %x"), name, base);
-
- if (d_is_dll)
- non_fatal (_("Can't have LIBRARY and NAME"));
-
- /* If --dllname not provided, use the one in the DEF file.
- FIXME: Is this appropriate for executables? */
- if (! dll_name)
- set_dll_name_from_def (name);
- d_is_exe = 1;
-}
-
-void
-def_library (const char *name, int base)
-{
- /* xgettext:c-format */
- inform (_("LIBRARY: %s base: %x"), name, base);
-
- if (d_is_exe)
- non_fatal (_("Can't have LIBRARY and NAME"));
-
- /* If --dllname not provided, use the one in the DEF file. */
- if (! dll_name)
- set_dll_name_from_def (name);
- d_is_dll = 1;
-}
-
-void
-def_description (const char *desc)
-{
- dlist_type *d = (dlist_type *) xmalloc (sizeof (dlist_type));
- d->text = xstrdup (desc);
- d->next = d_list;
- d_list = d;
-}
-
-static void
-new_directive (char *dir)
-{
- dlist_type *d = (dlist_type *) xmalloc (sizeof (dlist_type));
- d->text = xstrdup (dir);
- d->next = a_list;
- a_list = d;
-}
-
-void
-def_heapsize (int reserve, int commit)
-{
- char b[200];
- if (commit > 0)
- sprintf (b, "-heap 0x%x,0x%x ", reserve, commit);
- else
- sprintf (b, "-heap 0x%x ", reserve);
- new_directive (xstrdup (b));
-}
-
-void
-def_stacksize (int reserve, int commit)
-{
- char b[200];
- if (commit > 0)
- sprintf (b, "-stack 0x%x,0x%x ", reserve, commit);
- else
- sprintf (b, "-stack 0x%x ", reserve);
- new_directive (xstrdup (b));
-}
-
-/* append_import simply adds the given import definition to the global
- import_list. It is used by def_import. */
-
-static void
-append_import (const char *symbol_name, const char *dll_name, int func_ordinal)
-{
- iheadtype **pq;
- iheadtype *q;
-
- for (pq = &import_list; *pq != NULL; pq = &(*pq)->next)
- {
- if (strcmp ((*pq)->dllname, dll_name) == 0)
- {
- q = *pq;
- q->functail->next = xmalloc (sizeof (ifunctype));
- q->functail = q->functail->next;
- q->functail->ord = func_ordinal;
- q->functail->name = xstrdup (symbol_name);
- q->functail->next = NULL;
- q->nfuncs++;
- return;
- }
- }
-
- q = xmalloc (sizeof (iheadtype));
- q->dllname = xstrdup (dll_name);
- q->nfuncs = 1;
- q->funchead = xmalloc (sizeof (ifunctype));
- q->functail = q->funchead;
- q->next = NULL;
- q->functail->name = xstrdup (symbol_name);
- q->functail->ord = func_ordinal;
- q->functail->next = NULL;
-
- *pq = q;
-}
-
-/* def_import is called from within defparse.y when an IMPORT
- declaration is encountered. Depending on the form of the
- declaration, the module name may or may not need ".dll" to be
- appended to it, the name of the function may be stored in internal
- or entry, and there may or may not be an ordinal value associated
- with it. */
-
-/* A note regarding the parse modes:
- In defparse.y we have to accept import declarations which follow
- any one of the following forms:
- <func_name_in_app> = <dll_name>.<func_name_in_dll>
- <func_name_in_app> = <dll_name>.<number>
- <dll_name>.<func_name_in_dll>
- <dll_name>.<number>
- Furthermore, the dll's name may or may not end with ".dll", which
- complicates the parsing a little. Normally the dll's name is
- passed to def_import() in the "module" parameter, but when it ends
- with ".dll" it gets passed in "module" sans ".dll" and that needs
- to be reappended.
-
- def_import gets five parameters:
- APP_NAME - the name of the function in the application, if
- present, or NULL if not present.
- MODULE - the name of the dll, possibly sans extension (ie, '.dll').
- DLLEXT - the extension of the dll, if present, NULL if not present.
- ENTRY - the name of the function in the dll, if present, or NULL.
- ORD_VAL - the numerical tag of the function in the dll, if present,
- or NULL. Exactly one of <entry> or <ord_val> must be
- present (i.e., not NULL). */
-
-void
-def_import (const char *app_name, const char *module, const char *dllext,
- const char *entry, int ord_val)
-{
- const char *application_name;
- char *buf;
-
- if (entry != NULL)
- application_name = entry;
- else
- {
- if (app_name != NULL)
- application_name = app_name;
- else
- application_name = "";
- }
-
- if (dllext != NULL)
- {
- buf = (char *) alloca (strlen (module) + strlen (dllext) + 2);
- sprintf (buf, "%s.%s", module, dllext);
- module = buf;
- }
-
- append_import (application_name, module, ord_val);
-}
-
-void
-def_version (int major, int minor)
-{
- printf ("VERSION %d.%d\n", major, minor);
-}
-
-void
-def_section (const char *name, int attr)
-{
- char buf[200];
- char atts[5];
- char *d = atts;
- if (attr & 1)
- *d++ = 'R';
-
- if (attr & 2)
- *d++ = 'W';
- if (attr & 4)
- *d++ = 'X';
- if (attr & 8)
- *d++ = 'S';
- *d++ = 0;
- sprintf (buf, "-attr %s %s", name, atts);
- new_directive (xstrdup (buf));
-}
-
-void
-def_code (int attr)
-{
-
- def_section ("CODE", attr);
-}
-
-void
-def_data (int attr)
-{
- def_section ("DATA", attr);
-}
-
-/**********************************************************************/
-
-static void
-run (const char *what, char *args)
-{
- char *s;
- int pid, wait_status;
- int i;
- const char **argv;
- char *errmsg_fmt, *errmsg_arg;
- char *temp_base = choose_temp_base ();
-
- inform ("run: %s %s", what, args);
-
- /* Count the args */
- i = 0;
- for (s = args; *s; s++)
- if (*s == ' ')
- i++;
- i++;
- argv = alloca (sizeof (char *) * (i + 3));
- i = 0;
- argv[i++] = what;
- s = args;
- while (1)
- {
- while (*s == ' ')
- ++s;
- argv[i++] = s;
- while (*s != ' ' && *s != 0)
- s++;
- if (*s == 0)
- break;
- *s++ = 0;
- }
- argv[i++] = NULL;
-
- pid = pexecute (argv[0], (char * const *) argv, program_name, temp_base,
- &errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH);
-
- if (pid == -1)
- {
- inform (strerror (errno));
-
- fatal (errmsg_fmt, errmsg_arg);
- }
-
- pid = pwait (pid, & wait_status, 0);
-
- if (pid == -1)
- {
- /* xgettext:c-format */
- fatal (_("wait: %s"), strerror (errno));
- }
- else if (WIFSIGNALED (wait_status))
- {
- /* xgettext:c-format */
- fatal (_("subprocess got fatal signal %d"), WTERMSIG (wait_status));
- }
- else if (WIFEXITED (wait_status))
- {
- if (WEXITSTATUS (wait_status) != 0)
- /* xgettext:c-format */
- non_fatal (_("%s exited with status %d"),
- what, WEXITSTATUS (wait_status));
- }
- else
- abort ();
-}
-
-/* Look for a list of symbols to export in the .drectve section of
- ABFD. Pass each one to def_exports. */
-
-static void
-scan_drectve_symbols (bfd *abfd)
-{
- asection * s;
- int size;
- char * buf;
- char * p;
- char * e;
-
- /* Look for .drectve's */
- s = bfd_get_section_by_name (abfd, DRECTVE_SECTION_NAME);
-
- if (s == NULL)
- return;
-
- size = bfd_get_section_size (s);
- buf = xmalloc (size);
-
- bfd_get_section_contents (abfd, s, buf, 0, size);
-
- /* xgettext:c-format */
- inform (_("Sucking in info from %s section in %s"),
- DRECTVE_SECTION_NAME, bfd_get_filename (abfd));
-
- /* Search for -export: strings. The exported symbols can optionally
- have type tags (eg., -export:foo,data), so handle those as well.
- Currently only data tag is supported. */
- p = buf;
- e = buf + size;
- while (p < e)
- {
- if (p[0] == '-'
- && CONST_STRNEQ (p, "-export:"))
- {
- char * name;
- char * c;
- flagword flags = BSF_FUNCTION;
-
- p += 8;
- name = p;
- while (p < e && *p != ',' && *p != ' ' && *p != '-')
- p++;
- c = xmalloc (p - name + 1);
- memcpy (c, name, p - name);
- c[p - name] = 0;
- if (p < e && *p == ',') /* found type tag. */
- {
- char *tag_start = ++p;
- while (p < e && *p != ' ' && *p != '-')
- p++;
- if (CONST_STRNEQ (tag_start, "data"))
- flags &= ~BSF_FUNCTION;
- }
-
- /* FIXME: The 5th arg is for the `constant' field.
- What should it be? Not that it matters since it's not
- currently useful. */
- def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION), 0);
-
- if (add_stdcall_alias && strchr (c, '@'))
- {
- int lead_at = (*c == '@') ;
- char *exported_name = xstrdup (c + lead_at);
- char *atsym = strchr (exported_name, '@');
- *atsym = '\0';
- /* Note: stdcall alias symbols can never be data. */
- def_exports (exported_name, xstrdup (c), -1, 0, 0, 0, 0);
- }
- }
- else
- p++;
- }
- free (buf);
-}
-
-/* Look through the symbols in MINISYMS, and add each one to list of
- symbols to export. */
-
-static void
-scan_filtered_symbols (bfd *abfd, void *minisyms, long symcount,
- unsigned int size)
-{
- asymbol *store;
- bfd_byte *from, *fromend;
-
- store = bfd_make_empty_symbol (abfd);
- if (store == NULL)
- bfd_fatal (bfd_get_filename (abfd));
-
- from = (bfd_byte *) minisyms;
- fromend = from + symcount * size;
- for (; from < fromend; from += size)
- {
- asymbol *sym;
- const char *symbol_name;
-
- sym = bfd_minisymbol_to_symbol (abfd, FALSE, from, store);
- if (sym == NULL)
- bfd_fatal (bfd_get_filename (abfd));
-
- symbol_name = bfd_asymbol_name (sym);
- if (bfd_get_symbol_leading_char (abfd) == symbol_name[0])
- ++symbol_name;
-
- def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
- ! (sym->flags & BSF_FUNCTION), 0);
-
- if (add_stdcall_alias && strchr (symbol_name, '@'))
- {
- int lead_at = (*symbol_name == '@');
- char *exported_name = xstrdup (symbol_name + lead_at);
- char *atsym = strchr (exported_name, '@');
- *atsym = '\0';
- /* Note: stdcall alias symbols can never be data. */
- def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0, 0);
- }
- }
-}
-
-/* Add a list of symbols to exclude. */
-
-static void
-add_excludes (const char *new_excludes)
-{
- char *local_copy;
- char *exclude_string;
-
- local_copy = xstrdup (new_excludes);
-
- exclude_string = strtok (local_copy, ",:");
- for (; exclude_string; exclude_string = strtok (NULL, ",:"))
- {
- struct string_list *new_exclude;
-
- new_exclude = ((struct string_list *)
- xmalloc (sizeof (struct string_list)));
- new_exclude->string = (char *) xmalloc (strlen (exclude_string) + 2);
- /* Don't add a leading underscore for fastcall symbols. */
- if (*exclude_string == '@')
- sprintf (new_exclude->string, "%s", exclude_string);
- else
- sprintf (new_exclude->string, "_%s", exclude_string);
- new_exclude->next = excludes;
- excludes = new_exclude;
-
- /* xgettext:c-format */
- inform (_("Excluding symbol: %s"), exclude_string);
- }
-
- free (local_copy);
-}
-
-/* See if STRING is on the list of symbols to exclude. */
-
-static bfd_boolean
-match_exclude (const char *string)
-{
- struct string_list *excl_item;
-
- for (excl_item = excludes; excl_item; excl_item = excl_item->next)
- if (strcmp (string, excl_item->string) == 0)
- return TRUE;
- return FALSE;
-}
-
-/* Add the default list of symbols to exclude. */
-
-static void
-set_default_excludes (void)
-{
- add_excludes (default_excludes);
-}
-
-/* Choose which symbols to export. */
-
-static long
-filter_symbols (bfd *abfd, void *minisyms, long symcount, unsigned int size)
-{
- bfd_byte *from, *fromend, *to;
- asymbol *store;
-
- store = bfd_make_empty_symbol (abfd);
- if (store == NULL)
- bfd_fatal (bfd_get_filename (abfd));
-
- from = (bfd_byte *) minisyms;
- fromend = from + symcount * size;
- to = (bfd_byte *) minisyms;
-
- for (; from < fromend; from += size)
- {
- int keep = 0;
- asymbol *sym;
-
- sym = bfd_minisymbol_to_symbol (abfd, FALSE, (const void *) from, store);
- if (sym == NULL)
- bfd_fatal (bfd_get_filename (abfd));
-
- /* Check for external and defined only symbols. */
- keep = (((sym->flags & BSF_GLOBAL) != 0
- || (sym->flags & BSF_WEAK) != 0
- || bfd_is_com_section (sym->section))
- && ! bfd_is_und_section (sym->section));
-
- keep = keep && ! match_exclude (sym->name);
-
- if (keep)
- {
- memcpy (to, from, size);
- to += size;
- }
- }
-
- return (to - (bfd_byte *) minisyms) / size;
-}
-
-/* Export all symbols in ABFD, except for ones we were told not to
- export. */
-
-static void
-scan_all_symbols (bfd *abfd)
-{
- long symcount;
- void *minisyms;
- unsigned int size;
-
- /* Ignore bfds with an import descriptor table. We assume that any
- such BFD contains symbols which are exported from another DLL,
- and we don't want to reexport them from here. */
- if (bfd_get_section_by_name (abfd, ".idata$4"))
- return;
-
- if (! (bfd_get_file_flags (abfd) & HAS_SYMS))
- {
- /* xgettext:c-format */
- non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
- return;
- }
-
- symcount = bfd_read_minisymbols (abfd, FALSE, &minisyms, &size);
- if (symcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- if (symcount == 0)
- {
- /* xgettext:c-format */
- non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
- return;
- }
-
- /* Discard the symbols we don't want to export. It's OK to do this
- in place; we'll free the storage anyway. */
-
- symcount = filter_symbols (abfd, minisyms, symcount, size);
- scan_filtered_symbols (abfd, minisyms, symcount, size);
-
- free (minisyms);
-}
-
-/* Look at the object file to decide which symbols to export. */
-
-static void
-scan_open_obj_file (bfd *abfd)
-{
- if (export_all_symbols)
- scan_all_symbols (abfd);
- else
- scan_drectve_symbols (abfd);
-
- /* FIXME: we ought to read in and block out the base relocations. */
-
- /* xgettext:c-format */
- inform (_("Done reading %s"), bfd_get_filename (abfd));
-}
-
-static void
-scan_obj_file (const char *filename)
-{
- bfd * f = bfd_openr (filename, 0);
-
- if (!f)
- /* xgettext:c-format */
- fatal (_("Unable to open object file: %s"), filename);
-
- /* xgettext:c-format */
- inform (_("Scanning object file %s"), filename);
-
- if (bfd_check_format (f, bfd_archive))
- {
- bfd *arfile = bfd_openr_next_archived_file (f, 0);
- while (arfile)
- {
- if (bfd_check_format (arfile, bfd_object))
- scan_open_obj_file (arfile);
- bfd_close (arfile);
- arfile = bfd_openr_next_archived_file (f, arfile);
- }
-
-#ifdef DLLTOOL_MCORE_ELF
- if (mcore_elf_out_file)
- inform (_("Cannot produce mcore-elf dll from archive file: %s"), filename);
-#endif
- }
- else if (bfd_check_format (f, bfd_object))
- {
- scan_open_obj_file (f);
-
-#ifdef DLLTOOL_MCORE_ELF
- if (mcore_elf_out_file)
- mcore_elf_cache_filename (filename);
-#endif
- }
-
- bfd_close (f);
-}
-
-/**********************************************************************/
-
-static void
-dump_def_info (FILE *f)
-{
- int i;
- export_type *exp;
- fprintf (f, "%s ", ASM_C);
- for (i = 0; oav[i]; i++)
- fprintf (f, "%s ", oav[i]);
- fprintf (f, "\n");
- for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
- {
- fprintf (f, "%s %d = %s %s @ %d %s%s%s%s\n",
- ASM_C,
- i,
- exp->name,
- exp->internal_name,
- exp->ordinal,
- exp->noname ? "NONAME " : "",
- exp->private ? "PRIVATE " : "",
- exp->constant ? "CONSTANT" : "",
- exp->data ? "DATA" : "");
- }
-}
-
-/* Generate the .exp file. */
-
-static int
-sfunc (const void *a, const void *b)
-{
- return *(const long *) a - *(const long *) b;
-}
-
-static void
-flush_page (FILE *f, long *need, int page_addr, int on_page)
-{
- int i;
-
- /* Flush this page. */
- fprintf (f, "\t%s\t0x%08x\t%s Starting RVA for chunk\n",
- ASM_LONG,
- page_addr,
- ASM_C);
- fprintf (f, "\t%s\t0x%x\t%s Size of block\n",
- ASM_LONG,
- (on_page * 2) + (on_page & 1) * 2 + 8,
- ASM_C);
-
- for (i = 0; i < on_page; i++)
- {
- unsigned long needed = need[i];
-
- if (needed)
- needed = ((needed - page_addr) | 0x3000) & 0xffff;
-
- fprintf (f, "\t%s\t0x%lx\n", ASM_SHORT, needed);
- }
-
- /* And padding */
- if (on_page & 1)
- fprintf (f, "\t%s\t0x%x\n", ASM_SHORT, 0 | 0x0000);
-}
-
-static void
-gen_def_file (void)
-{
- int i;
- export_type *exp;
-
- inform (_("Adding exports to output file"));
-
- fprintf (output_def, ";");
- for (i = 0; oav[i]; i++)
- fprintf (output_def, " %s", oav[i]);
-
- fprintf (output_def, "\nEXPORTS\n");
-
- for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
- {
- char *quote = strchr (exp->name, '.') ? "\"" : "";
- char *res = cplus_demangle (exp->internal_name, DMGL_ANSI | DMGL_PARAMS);
-
- if (res)
- {
- fprintf (output_def,";\t%s\n", res);
- free (res);
- }
-
- if (strcmp (exp->name, exp->internal_name) == 0)
- {
- fprintf (output_def, "\t%s%s%s @ %d%s%s%s\n",
- quote,
- exp->name,
- quote,
- exp->ordinal,
- exp->noname ? " NONAME" : "",
- exp->private ? "PRIVATE " : "",
- exp->data ? " DATA" : "");
- }
- else
- {
- char * quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
- /* char *alias = */
- fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s%s\n",
- quote,
- exp->name,
- quote,
- quote1,
- exp->internal_name,
- quote1,
- exp->ordinal,
- exp->noname ? " NONAME" : "",
- exp->private ? "PRIVATE " : "",
- exp->data ? " DATA" : "");
- }
- }
-
- inform (_("Added exports to output file"));
-}
-
-/* generate_idata_ofile generates the portable assembly source code
- for the idata sections. It appends the source code to the end of
- the file. */
-
-static void
-generate_idata_ofile (FILE *filvar)
-{
- iheadtype *headptr;
- ifunctype *funcptr;
- int headindex;
- int funcindex;
- int nheads;
-
- if (import_list == NULL)
- return;
-
- fprintf (filvar, "%s Import data sections\n", ASM_C);
- fprintf (filvar, "\n\t.section\t.idata$2\n");
- fprintf (filvar, "\t%s\tdoi_idata\n", ASM_GLOBAL);
- fprintf (filvar, "doi_idata:\n");
-
- nheads = 0;
- for (headptr = import_list; headptr != NULL; headptr = headptr->next)
- {
- fprintf (filvar, "\t%slistone%d%s\t%s %s\n",
- ASM_RVA_BEFORE, nheads, ASM_RVA_AFTER,
- ASM_C, headptr->dllname);
- fprintf (filvar, "\t%s\t0\n", ASM_LONG);
- fprintf (filvar, "\t%s\t0\n", ASM_LONG);
- fprintf (filvar, "\t%sdllname%d%s\n",
- ASM_RVA_BEFORE, nheads, ASM_RVA_AFTER);
- fprintf (filvar, "\t%slisttwo%d%s\n\n",
- ASM_RVA_BEFORE, nheads, ASM_RVA_AFTER);
- nheads++;
- }
-
- fprintf (filvar, "\t%s\t0\n", ASM_LONG); /* NULL record at */
- fprintf (filvar, "\t%s\t0\n", ASM_LONG); /* end of idata$2 */
- fprintf (filvar, "\t%s\t0\n", ASM_LONG); /* section */
- fprintf (filvar, "\t%s\t0\n", ASM_LONG);
- fprintf (filvar, "\t%s\t0\n", ASM_LONG);
-
- fprintf (filvar, "\n\t.section\t.idata$4\n");
- headindex = 0;
- for (headptr = import_list; headptr != NULL; headptr = headptr->next)
- {
- fprintf (filvar, "listone%d:\n", headindex);
- for (funcindex = 0; funcindex < headptr->nfuncs; funcindex++)
-#ifdef DLLTOOL_MX86_64
- fprintf (filvar, "\t%sfuncptr%d_%d%s\n%s\t0\n",
- ASM_RVA_BEFORE, headindex, funcindex, ASM_RVA_AFTER,ASM_LONG);
-#else
- fprintf (filvar, "\t%sfuncptr%d_%d%s\n",
- ASM_RVA_BEFORE, headindex, funcindex, ASM_RVA_AFTER);
-#endif
-#ifdef DLLTOOL_MX86_64
- fprintf (filvar, "\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG); /* NULL terminating list. */
-#else
- fprintf (filvar, "\t%s\t0\n", ASM_LONG); /* NULL terminating list. */
-#endif
- headindex++;
- }
-
- fprintf (filvar, "\n\t.section\t.idata$5\n");
- headindex = 0;
- for (headptr = import_list; headptr != NULL; headptr = headptr->next)
- {
- fprintf (filvar, "listtwo%d:\n", headindex);
- for (funcindex = 0; funcindex < headptr->nfuncs; funcindex++)
-#ifdef DLLTOOL_MX86_64
- fprintf (filvar, "\t%sfuncptr%d_%d%s\n%s\t0\n",
- ASM_RVA_BEFORE, headindex, funcindex, ASM_RVA_AFTER,ASM_LONG);
-#else
- fprintf (filvar, "\t%sfuncptr%d_%d%s\n",
- ASM_RVA_BEFORE, headindex, funcindex, ASM_RVA_AFTER);
-#endif
-#ifdef DLLTOOL_MX86_64
- fprintf (filvar, "\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG); /* NULL terminating list. */
-#else
- fprintf (filvar, "\t%s\t0\n", ASM_LONG); /* NULL terminating list. */
-#endif
- headindex++;
- }
-
- fprintf (filvar, "\n\t.section\t.idata$6\n");
- headindex = 0;
- for (headptr = import_list; headptr != NULL; headptr = headptr->next)
- {
- funcindex = 0;
- for (funcptr = headptr->funchead; funcptr != NULL;
- funcptr = funcptr->next)
- {
- fprintf (filvar,"funcptr%d_%d:\n", headindex, funcindex);
- fprintf (filvar,"\t%s\t%d\n", ASM_SHORT,
- ((funcptr->ord) & 0xFFFF));
- fprintf (filvar,"\t%s\t\"%s\"\n", ASM_TEXT, funcptr->name);
- fprintf (filvar,"\t%s\t0\n", ASM_BYTE);
- funcindex++;
- }
- headindex++;
- }
-
- fprintf (filvar, "\n\t.section\t.idata$7\n");
- headindex = 0;
- for (headptr = import_list; headptr != NULL; headptr = headptr->next)
- {
- fprintf (filvar,"dllname%d:\n", headindex);
- fprintf (filvar,"\t%s\t\"%s\"\n", ASM_TEXT, headptr->dllname);
- fprintf (filvar,"\t%s\t0\n", ASM_BYTE);
- headindex++;
- }
-}
-
-/* Assemble the specified file. */
-static void
-assemble_file (const char * source, const char * dest)
-{
- char * cmd;
-
- cmd = (char *) alloca (strlen (ASM_SWITCHES) + strlen (as_flags)
- + strlen (source) + strlen (dest) + 50);
-
- sprintf (cmd, "%s %s -o %s %s", ASM_SWITCHES, as_flags, dest, source);
-
- run (as_name, cmd);
-}
-
-static void
-gen_exp_file (void)
-{
- FILE *f;
- int i;
- export_type *exp;
- dlist_type *dl;
-
- /* xgettext:c-format */
- inform (_("Generating export file: %s"), exp_name);
-
- f = fopen (TMP_ASM, FOPEN_WT);
- if (!f)
- /* xgettext:c-format */
- fatal (_("Unable to open temporary assembler file: %s"), TMP_ASM);
-
- /* xgettext:c-format */
- inform (_("Opened temporary file: %s"), TMP_ASM);
-
- dump_def_info (f);
-
- if (d_exports)
- {
- fprintf (f, "\t.section .edata\n\n");
- fprintf (f, "\t%s 0 %s Allways 0\n", ASM_LONG, ASM_C);
- fprintf (f, "\t%s 0x%lx %s Time and date\n", ASM_LONG,
- (unsigned long) time(0), ASM_C);
- fprintf (f, "\t%s 0 %s Major and Minor version\n", ASM_LONG, ASM_C);
- fprintf (f, "\t%sname%s %s Ptr to name of dll\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
- fprintf (f, "\t%s %d %s Starting ordinal of exports\n", ASM_LONG, d_low_ord, ASM_C);
-
-
- fprintf (f, "\t%s %d %s Number of functions\n", ASM_LONG, d_high_ord - d_low_ord + 1, ASM_C);
- fprintf(f,"\t%s named funcs %d, low ord %d, high ord %d\n",
- ASM_C,
- d_named_nfuncs, d_low_ord, d_high_ord);
- fprintf (f, "\t%s %d %s Number of names\n", ASM_LONG,
- show_allnames ? d_high_ord - d_low_ord + 1 : d_named_nfuncs, ASM_C);
- fprintf (f, "\t%safuncs%s %s Address of functions\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
-
- fprintf (f, "\t%sanames%s %s Address of Name Pointer Table\n",
- ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
-
- fprintf (f, "\t%sanords%s %s Address of ordinals\n", ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
-
- fprintf (f, "name: %s \"%s\"\n", ASM_TEXT, dll_name);
-
-
- fprintf(f,"%s Export address Table\n", ASM_C);
- fprintf(f,"\t%s\n", ASM_ALIGN_LONG);
- fprintf (f, "afuncs:\n");
- i = d_low_ord;
-
- for (exp = d_exports; exp; exp = exp->next)
- {
- if (exp->ordinal != i)
- {
- while (i < exp->ordinal)
- {
- fprintf(f,"\t%s\t0\n", ASM_LONG);
- i++;
- }
- }
-
- if (exp->forward == 0)
- {
- if (exp->internal_name[0] == '@')
- fprintf (f, "\t%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
- exp->internal_name, ASM_RVA_AFTER, ASM_C, exp->ordinal);
- else
- fprintf (f, "\t%s%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
- ASM_PREFIX (exp->internal_name),
- exp->internal_name, ASM_RVA_AFTER, ASM_C, exp->ordinal);
- }
- else
- fprintf (f, "\t%sf%d%s\t%s %d\n", ASM_RVA_BEFORE,
- exp->forward, ASM_RVA_AFTER, ASM_C, exp->ordinal);
- i++;
- }
-
- fprintf (f,"%s Export Name Pointer Table\n", ASM_C);
- fprintf (f, "anames:\n");
-
- for (i = 0; (exp = d_exports_lexically[i]); i++)
- {
- if (!exp->noname || show_allnames)
- fprintf (f, "\t%sn%d%s\n",
- ASM_RVA_BEFORE, exp->ordinal, ASM_RVA_AFTER);
- }
-
- fprintf (f,"%s Export Ordinal Table\n", ASM_C);
- fprintf (f, "anords:\n");
- for (i = 0; (exp = d_exports_lexically[i]); i++)
- {
- if (!exp->noname || show_allnames)
- fprintf (f, "\t%s %d\n", ASM_SHORT, exp->ordinal - d_low_ord);
- }
-
- fprintf(f,"%s Export Name Table\n", ASM_C);
- for (i = 0; (exp = d_exports_lexically[i]); i++)
- {
- if (!exp->noname || show_allnames)
- fprintf (f, "n%d: %s \"%s\"\n",
- exp->ordinal, ASM_TEXT, xlate (exp->name));
- if (exp->forward != 0)
- fprintf (f, "f%d: %s \"%s\"\n",
- exp->forward, ASM_TEXT, exp->internal_name);
- }
-
- if (a_list)
- {
- fprintf (f, "\t.section %s\n", DRECTVE_SECTION_NAME);
- for (dl = a_list; dl; dl = dl->next)
- {
- fprintf (f, "\t%s\t\"%s\"\n", ASM_TEXT, dl->text);
- }
- }
-
- if (d_list)
- {
- fprintf (f, "\t.section .rdata\n");
- for (dl = d_list; dl; dl = dl->next)
- {
- char *p;
- int l;
-
- /* We don't output as ascii because there can
- be quote characters in the string. */
- l = 0;
- for (p = dl->text; *p; p++)
- {
- if (l == 0)
- fprintf (f, "\t%s\t", ASM_BYTE);
- else
- fprintf (f, ",");
- fprintf (f, "%d", *p);
- if (p[1] == 0)
- {
- fprintf (f, ",0\n");
- break;
- }
- if (++l == 10)
- {
- fprintf (f, "\n");
- l = 0;
- }
- }
- }
- }
- }
-
-
- /* Add to the output file a way of getting to the exported names
- without using the import library. */
- if (add_indirect)
- {
- fprintf (f, "\t.section\t.rdata\n");
- for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
- if (!exp->noname || show_allnames)
- {
- /* We use a single underscore for MS compatibility, and a
- double underscore for backward compatibility with old
- cygwin releases. */
- if (create_compat_implib)
- fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
- fprintf (f, "\t%s\t_imp__%s\n", ASM_GLOBAL, exp->name);
- if (create_compat_implib)
- fprintf (f, "__imp_%s:\n", exp->name);
- fprintf (f, "_imp__%s:\n", exp->name);
- fprintf (f, "\t%s\t%s\n", ASM_LONG, exp->name);
- }
- }
-
- /* Dump the reloc section if a base file is provided. */
- if (base_file)
- {
- int addr;
- long need[PAGE_SIZE];
- long page_addr;
- int numbytes;
- int num_entries;
- long *copy;
- int j;
- int on_page;
- fprintf (f, "\t.section\t.init\n");
- fprintf (f, "lab:\n");
-
- fseek (base_file, 0, SEEK_END);
- numbytes = ftell (base_file);
- fseek (base_file, 0, SEEK_SET);
- copy = xmalloc (numbytes);
- fread (copy, 1, numbytes, base_file);
- num_entries = numbytes / sizeof (long);
-
-
- fprintf (f, "\t.section\t.reloc\n");
- if (num_entries)
- {
- int src;
- int dst = 0;
- int last = -1;
- qsort (copy, num_entries, sizeof (long), sfunc);
- /* Delete duplicates */
- for (src = 0; src < num_entries; src++)
- {
- if (last != copy[src])
- last = copy[dst++] = copy[src];
- }
- num_entries = dst;
- addr = copy[0];
- page_addr = addr & PAGE_MASK; /* work out the page addr */
- on_page = 0;
- for (j = 0; j < num_entries; j++)
- {
- addr = copy[j];
- if ((addr & PAGE_MASK) != page_addr)
- {
- flush_page (f, need, page_addr, on_page);
- on_page = 0;
- page_addr = addr & PAGE_MASK;
- }
- need[on_page++] = addr;
- }
- flush_page (f, need, page_addr, on_page);
-
-/* fprintf (f, "\t%s\t0,0\t%s End\n", ASM_LONG, ASM_C);*/
- }
- }
-
- generate_idata_ofile (f);
-
- fclose (f);
-
- /* Assemble the file. */
- assemble_file (TMP_ASM, exp_name);
-
- if (dontdeltemps == 0)
- unlink (TMP_ASM);
-
- inform (_("Generated exports file"));
-}
-
-static const char *
-xlate (const char *name)
-{
- int lead_at = (*name == '@');
-
- if (!lead_at && (add_underscore
- || (add_stdcall_underscore
- && strchr (name, '@'))))
- {
- char *copy = xmalloc (strlen (name) + 2);
-
- copy[0] = '_';
- strcpy (copy + 1, name);
- name = copy;
- }
-
- if (killat)
- {
- char *p;
-
- name += lead_at;
- p = strchr (name, '@');
- if (p)
- *p = 0;
- }
- return name;
-}
-
-typedef struct
-{
- int id;
- const char *name;
- int flags;
- int align;
- asection *sec;
- asymbol *sym;
- asymbol **sympp;
- int size;
- unsigned char *data;
-} sinfo;
-
-#ifndef DLLTOOL_PPC
-
-#define TEXT 0
-#define DATA 1
-#define BSS 2
-#define IDATA7 3
-#define IDATA5 4
-#define IDATA4 5
-#define IDATA6 6
-
-#define NSECS 7
-
-#define TEXT_SEC_FLAGS \
- (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS)
-#define DATA_SEC_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_DATA)
-#define BSS_SEC_FLAGS SEC_ALLOC
-
-#define INIT_SEC_DATA(id, name, flags, align) \
- { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
-static sinfo secdata[NSECS] =
-{
- INIT_SEC_DATA (TEXT, ".text", TEXT_SEC_FLAGS, 2),
- INIT_SEC_DATA (DATA, ".data", DATA_SEC_FLAGS, 2),
- INIT_SEC_DATA (BSS, ".bss", BSS_SEC_FLAGS, 2),
- INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
- INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
- INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
- INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1)
-};
-
-#else
-
-/* Sections numbered to make the order the same as other PowerPC NT
- compilers. This also keeps funny alignment thingies from happening. */
-#define TEXT 0
-#define PDATA 1
-#define RDATA 2
-#define IDATA5 3
-#define IDATA4 4
-#define IDATA6 5
-#define IDATA7 6
-#define DATA 7
-#define BSS 8
-
-#define NSECS 9
-
-static sinfo secdata[NSECS] =
-{
- { TEXT, ".text", SEC_CODE | SEC_HAS_CONTENTS, 3},
- { PDATA, ".pdata", SEC_HAS_CONTENTS, 2},
- { RDATA, ".reldata", SEC_HAS_CONTENTS, 2},
- { IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2},
- { IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2},
- { IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1},
- { IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2},
- { DATA, ".data", SEC_DATA, 2},
- { BSS, ".bss", 0, 2}
-};
-
-#endif
-
-/* This is what we're trying to make. We generate the imp symbols with
- both single and double underscores, for compatibility.
-
- .text
- .global _GetFileVersionInfoSizeW@8
- .global __imp_GetFileVersionInfoSizeW@8
-_GetFileVersionInfoSizeW@8:
- jmp * __imp_GetFileVersionInfoSizeW@8
- .section .idata$7 # To force loading of head
- .long __version_a_head
-# Import Address Table
- .section .idata$5
-__imp_GetFileVersionInfoSizeW@8:
- .rva ID2
-
-# Import Lookup Table
- .section .idata$4
- .rva ID2
-# Hint/Name table
- .section .idata$6
-ID2: .short 2
- .asciz "GetFileVersionInfoSizeW"
-
-
- For the PowerPC, here's the variation on the above scheme:
-
-# Rather than a simple "jmp *", the code to get to the dll function
-# looks like:
- .text
- lwz r11,[tocv]__imp_function_name(r2)
-# RELOC: 00000000 TOCREL16,TOCDEFN __imp_function_name
- lwz r12,0(r11)
- stw r2,4(r1)
- mtctr r12
- lwz r2,4(r11)
- bctr */
-
-static char *
-make_label (const char *prefix, const char *name)
-{
- int len = strlen (ASM_PREFIX (name)) + strlen (prefix) + strlen (name);
- char *copy = xmalloc (len + 1);
-
- strcpy (copy, ASM_PREFIX (name));
- strcat (copy, prefix);
- strcat (copy, name);
- return copy;
-}
-
-static char *
-make_imp_label (const char *prefix, const char *name)
-{
- int len;
- char *copy;
-
- if (name[0] == '@')
- {
- len = strlen (prefix) + strlen (name);
- copy = xmalloc (len + 1);
- strcpy (copy, prefix);
- strcat (copy, name);
- }
- else
- {
- len = strlen (ASM_PREFIX (name)) + strlen (prefix) + strlen (name);
- copy = xmalloc (len + 1);
- strcpy (copy, prefix);
- strcat (copy, ASM_PREFIX (name));
- strcat (copy, name);
- }
- return copy;
-}
-
-static bfd *
-make_one_lib_file (export_type *exp, int i)
-{
- bfd * abfd;
- asymbol * exp_label;
- asymbol * iname = 0;
- asymbol * iname2;
- asymbol * iname_lab;
- asymbol ** iname_lab_pp;
- asymbol ** iname_pp;
-#ifdef DLLTOOL_PPC
- asymbol ** fn_pp;
- asymbol ** toc_pp;
-#define EXTRA 2
-#endif
-#ifndef EXTRA
-#define EXTRA 0
-#endif
- asymbol * ptrs[NSECS + 4 + EXTRA + 1];
- flagword applicable;
- char * outname = xmalloc (strlen (TMP_STUB) + 10);
- int oidx = 0;
-
-
- sprintf (outname, "%s%05d.o", TMP_STUB, i);
-
- abfd = bfd_openw (outname, HOW_BFD_WRITE_TARGET);
-
- if (!abfd)
- /* xgettext:c-format */
- fatal (_("bfd_open failed open stub file: %s"), outname);
-
- /* xgettext:c-format */
- inform (_("Creating stub file: %s"), outname);
-
- bfd_set_format (abfd, bfd_object);
- bfd_set_arch_mach (abfd, HOW_BFD_ARCH, 0);
-
-#ifdef DLLTOOL_ARM
- if (machine == MARM_INTERWORK || machine == MTHUMB)
- bfd_set_private_flags (abfd, F_INTERWORK);
-#endif
-
- applicable = bfd_applicable_section_flags (abfd);
-
- /* First make symbols for the sections. */
- for (i = 0; i < NSECS; i++)
- {
- sinfo *si = secdata + i;
-
- if (si->id != i)
- abort();
- si->sec = bfd_make_section_old_way (abfd, si->name);
- bfd_set_section_flags (abfd,
- si->sec,
- si->flags & applicable);
-
- bfd_set_section_alignment(abfd, si->sec, si->align);
- si->sec->output_section = si->sec;
- si->sym = bfd_make_empty_symbol(abfd);
- si->sym->name = si->sec->name;
- si->sym->section = si->sec;
- si->sym->flags = BSF_LOCAL;
- si->sym->value = 0;
- ptrs[oidx] = si->sym;
- si->sympp = ptrs + oidx;
- si->size = 0;
- si->data = NULL;
-
- oidx++;
- }
-
- if (! exp->data)
- {
- exp_label = bfd_make_empty_symbol (abfd);
- exp_label->name = make_imp_label ("", exp->name);
-
- /* On PowerPC, the function name points to a descriptor in
- the rdata section, the first element of which is a
- pointer to the code (..function_name), and the second
- points to the .toc. */
-#ifdef DLLTOOL_PPC
- if (machine == MPPC)
- exp_label->section = secdata[RDATA].sec;
- else
-#endif
- exp_label->section = secdata[TEXT].sec;
-
- exp_label->flags = BSF_GLOBAL;
- exp_label->value = 0;
-
-#ifdef DLLTOOL_ARM
- if (machine == MTHUMB)
- bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
-#endif
- ptrs[oidx++] = exp_label;
- }
-
- /* Generate imp symbols with one underscore for Microsoft
- compatibility, and with two underscores for backward
- compatibility with old versions of cygwin. */
- if (create_compat_implib)
- {
- iname = bfd_make_empty_symbol (abfd);
- iname->name = make_imp_label ("___imp", exp->name);
- iname->section = secdata[IDATA5].sec;
- iname->flags = BSF_GLOBAL;
- iname->value = 0;
- }
-
- iname2 = bfd_make_empty_symbol (abfd);
- iname2->name = make_imp_label ("__imp_", exp->name);
- iname2->section = secdata[IDATA5].sec;
- iname2->flags = BSF_GLOBAL;
- iname2->value = 0;
-
- iname_lab = bfd_make_empty_symbol (abfd);
-
- iname_lab->name = head_label;
- iname_lab->section = (asection *) &bfd_und_section;
- iname_lab->flags = 0;
- iname_lab->value = 0;
-
- iname_pp = ptrs + oidx;
- if (create_compat_implib)
- ptrs[oidx++] = iname;
- ptrs[oidx++] = iname2;
-
- iname_lab_pp = ptrs + oidx;
- ptrs[oidx++] = iname_lab;
-
-#ifdef DLLTOOL_PPC
- /* The symbol referring to the code (.text). */
- {
- asymbol *function_name;
-
- function_name = bfd_make_empty_symbol(abfd);
- function_name->name = make_label ("..", exp->name);
- function_name->section = secdata[TEXT].sec;
- function_name->flags = BSF_GLOBAL;
- function_name->value = 0;
-
- fn_pp = ptrs + oidx;
- ptrs[oidx++] = function_name;
- }
-
- /* The .toc symbol. */
- {
- asymbol *toc_symbol;
-
- toc_symbol = bfd_make_empty_symbol (abfd);
- toc_symbol->name = make_label (".", "toc");
- toc_symbol->section = (asection *)&bfd_und_section;
- toc_symbol->flags = BSF_GLOBAL;
- toc_symbol->value = 0;
-
- toc_pp = ptrs + oidx;
- ptrs[oidx++] = toc_symbol;
- }
-#endif
-
- ptrs[oidx] = 0;
-
- for (i = 0; i < NSECS; i++)
- {
- sinfo *si = secdata + i;
- asection *sec = si->sec;
- arelent *rel;
- arelent **rpp;
-
- switch (i)
- {
- case TEXT:
- if (! exp->data)
- {
- si->size = HOW_JTAB_SIZE;
- si->data = xmalloc (HOW_JTAB_SIZE);
- memcpy (si->data, HOW_JTAB, HOW_JTAB_SIZE);
-
- /* Add the reloc into idata$5. */
- rel = xmalloc (sizeof (arelent));
-
- rpp = xmalloc (sizeof (arelent *) * 2);
- rpp[0] = rel;
- rpp[1] = 0;
-
- rel->address = HOW_JTAB_ROFF;
- rel->addend = 0;
-
- if (machine == MPPC)
- {
- rel->howto = bfd_reloc_type_lookup (abfd,
- BFD_RELOC_16_GOTOFF);
- rel->sym_ptr_ptr = iname_pp;
- }
- else if (machine == MX86)
- {
- rel->howto = bfd_reloc_type_lookup (abfd,
- BFD_RELOC_32_PCREL);
- rel->sym_ptr_ptr = iname_pp;
- }
- else
- {
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- rel->sym_ptr_ptr = secdata[IDATA5].sympp;
- }
- sec->orelocation = rpp;
- sec->reloc_count = 1;
- }
- break;
- case IDATA4:
- case IDATA5:
- /* An idata$4 or idata$5 is one word long, and has an
- rva to idata$6. */
-
-#ifdef DLLTOOL_MX86_64
- si->data = xmalloc (8);
- si->size = 8;
-
- if (exp->noname)
- {
- si->data[0] = exp->ordinal ;
- si->data[1] = exp->ordinal >> 8;
- si->data[2] = exp->ordinal >> 16;
- si->data[3] = exp->ordinal >> 24;
- si->data[4] = 0;
- si->data[5] = 0;
- si->data[6] = 0;
- si->data[7] = 0x80;
- }
- else
- {
- sec->reloc_count = 1;
- memset (si->data, 0, si->size);
- rel = xmalloc (sizeof (arelent));
- rpp = xmalloc (sizeof (arelent *) * 2);
- rpp[0] = rel;
- rpp[1] = 0;
- rel->address = 0;
- rel->addend = 0;
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
- rel->sym_ptr_ptr = secdata[IDATA6].sympp;
- sec->orelocation = rpp;
- }
-#else
- si->data = xmalloc (4);
- si->size = 4;
-
- if (exp->noname)
- {
- si->data[0] = exp->ordinal ;
- si->data[1] = exp->ordinal >> 8;
- si->data[2] = exp->ordinal >> 16;
- si->data[3] = 0x80;
- }
- else
- {
- sec->reloc_count = 1;
- memset (si->data, 0, si->size);
- rel = xmalloc (sizeof (arelent));
- rpp = xmalloc (sizeof (arelent *) * 2);
- rpp[0] = rel;
- rpp[1] = 0;
- rel->address = 0;
- rel->addend = 0;
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
- rel->sym_ptr_ptr = secdata[IDATA6].sympp;
- sec->orelocation = rpp;
- }
-#endif
- break;
-
- case IDATA6:
- if (!exp->noname)
- {
- /* This used to add 1 to exp->hint. I don't know
- why it did that, and it does not match what I see
- in programs compiled with the MS tools. */
- int idx = exp->hint;
- si->size = strlen (xlate (exp->import_name)) + 3;
- si->data = xmalloc (si->size);
- si->data[0] = idx & 0xff;
- si->data[1] = idx >> 8;
- strcpy ((char *) si->data + 2, xlate (exp->import_name));
- }
- break;
- case IDATA7:
- si->size = 4;
- si->data = xmalloc (4);
- memset (si->data, 0, si->size);
- rel = xmalloc (sizeof (arelent));
- rpp = xmalloc (sizeof (arelent *) * 2);
- rpp[0] = rel;
- rel->address = 0;
- rel->addend = 0;
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_RVA);
- rel->sym_ptr_ptr = iname_lab_pp;
- sec->orelocation = rpp;
- sec->reloc_count = 1;
- break;
-
-#ifdef DLLTOOL_PPC
- case PDATA:
- {
- /* The .pdata section is 5 words long.
- Think of it as:
- struct
- {
- bfd_vma BeginAddress, [0x00]
- EndAddress, [0x04]
- ExceptionHandler, [0x08]
- HandlerData, [0x0c]
- PrologEndAddress; [0x10]
- }; */
-
- /* So this pdata section setups up this as a glue linkage to
- a dll routine. There are a number of house keeping things
- we need to do:
-
- 1. In the name of glue trickery, the ADDR32 relocs for 0,
- 4, and 0x10 are set to point to the same place:
- "..function_name".
- 2. There is one more reloc needed in the pdata section.
- The actual glue instruction to restore the toc on
- return is saved as the offset in an IMGLUE reloc.
- So we need a total of four relocs for this section.
-
- 3. Lastly, the HandlerData field is set to 0x03, to indicate
- that this is a glue routine. */
- arelent *imglue, *ba_rel, *ea_rel, *pea_rel;
-
- /* Alignment must be set to 2**2 or you get extra stuff. */
- bfd_set_section_alignment(abfd, sec, 2);
-
- si->size = 4 * 5;
- si->data = xmalloc (si->size);
- memset (si->data, 0, si->size);
- rpp = xmalloc (sizeof (arelent *) * 5);
- rpp[0] = imglue = xmalloc (sizeof (arelent));
- rpp[1] = ba_rel = xmalloc (sizeof (arelent));
- rpp[2] = ea_rel = xmalloc (sizeof (arelent));
- rpp[3] = pea_rel = xmalloc (sizeof (arelent));
- rpp[4] = 0;
-
- /* Stick the toc reload instruction in the glue reloc. */
- bfd_put_32(abfd, ppc_glue_insn, (char *) &imglue->address);
-
- imglue->addend = 0;
- imglue->howto = bfd_reloc_type_lookup (abfd,
- BFD_RELOC_32_GOTOFF);
- imglue->sym_ptr_ptr = fn_pp;
-
- ba_rel->address = 0;
- ba_rel->addend = 0;
- ba_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- ba_rel->sym_ptr_ptr = fn_pp;
-
- bfd_put_32 (abfd, 0x18, si->data + 0x04);
- ea_rel->address = 4;
- ea_rel->addend = 0;
- ea_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- ea_rel->sym_ptr_ptr = fn_pp;
-
- /* Mark it as glue. */
- bfd_put_32 (abfd, 0x03, si->data + 0x0c);
-
- /* Mark the prolog end address. */
- bfd_put_32 (abfd, 0x0D, si->data + 0x10);
- pea_rel->address = 0x10;
- pea_rel->addend = 0;
- pea_rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- pea_rel->sym_ptr_ptr = fn_pp;
-
- sec->orelocation = rpp;
- sec->reloc_count = 4;
- break;
- }
- case RDATA:
- /* Each external function in a PowerPC PE file has a two word
- descriptor consisting of:
- 1. The address of the code.
- 2. The address of the appropriate .toc
- We use relocs to build this. */
- si->size = 8;
- si->data = xmalloc (8);
- memset (si->data, 0, si->size);
-
- rpp = xmalloc (sizeof (arelent *) * 3);
- rpp[0] = rel = xmalloc (sizeof (arelent));
- rpp[1] = xmalloc (sizeof (arelent));
- rpp[2] = 0;
-
- rel->address = 0;
- rel->addend = 0;
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- rel->sym_ptr_ptr = fn_pp;
-
- rel = rpp[1];
-
- rel->address = 4;
- rel->addend = 0;
- rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
- rel->sym_ptr_ptr = toc_pp;
-
- sec->orelocation = rpp;
- sec->reloc_count = 2;
- break;
-#endif /* DLLTOOL_PPC */
- }
- }
-
- {
- bfd_vma vma = 0;
- /* Size up all the sections. */
- for (i = 0; i < NSECS; i++)
- {
- sinfo *si = secdata + i;
-
- bfd_set_section_size (abfd, si->sec, si->size);
- bfd_set_section_vma (abfd, si->sec, vma);
- }
- }
- /* Write them out. */
- for (i = 0; i < NSECS; i++)
- {
- sinfo *si = secdata + i;
-
- if (i == IDATA5 && no_idata5)
- continue;
-
- if (i == IDATA4 && no_idata4)
- continue;
-
- bfd_set_section_contents (abfd, si->sec,
- si->data, 0,
- si->size);
- }
-
- bfd_set_symtab (abfd, ptrs, oidx);
- bfd_close (abfd);
- abfd = bfd_openr (outname, HOW_BFD_READ_TARGET);
- return abfd;
-}
-
-static bfd *
-make_head (void)
-{
- FILE *f = fopen (TMP_HEAD_S, FOPEN_WT);
-
- if (f == NULL)
- {
- fatal (_("failed to open temporary head file: %s"), TMP_HEAD_S);
- return NULL;
- }
-
- fprintf (f, "%s IMAGE_IMPORT_DESCRIPTOR\n", ASM_C);
- fprintf (f, "\t.section .idata$2\n");
-
- fprintf(f,"\t%s\t%s\n", ASM_GLOBAL,head_label);
-
- fprintf (f, "%s:\n", head_label);
-
- fprintf (f, "\t%shname%s\t%sPtr to image import by name list\n",
- ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
-
- fprintf (f, "\t%sthis should be the timestamp, but NT sometimes\n", ASM_C);
- fprintf (f, "\t%sdoesn't load DLLs when this is set.\n", ASM_C);
- fprintf (f, "\t%s\t0\t%s loaded time\n", ASM_LONG, ASM_C);
- fprintf (f, "\t%s\t0\t%s Forwarder chain\n", ASM_LONG, ASM_C);
- fprintf (f, "\t%s__%s_iname%s\t%s imported dll's name\n",
- ASM_RVA_BEFORE,
- imp_name_lab,
- ASM_RVA_AFTER,
- ASM_C);
- fprintf (f, "\t%sfthunk%s\t%s pointer to firstthunk\n",
- ASM_RVA_BEFORE,
- ASM_RVA_AFTER, ASM_C);
-
- fprintf (f, "%sStuff for compatibility\n", ASM_C);
-
- if (!no_idata5)
- {
- fprintf (f, "\t.section\t.idata$5\n");
-#ifdef DLLTOOL_MX86_64
- fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG); /* NULL terminating list. */
-#else
- fprintf (f,"\t%s\t0\n", ASM_LONG); /* NULL terminating list. */
-#endif
- fprintf (f, "fthunk:\n");
- }
-
- if (!no_idata4)
- {
- fprintf (f, "\t.section\t.idata$4\n");
- fprintf (f, "\t%s\t0\n", ASM_LONG);
- fprintf (f, "\t.section .idata$4\n");
- fprintf (f, "hname:\n");
- }
-
- fclose (f);
-
- assemble_file (TMP_HEAD_S, TMP_HEAD_O);
-
- return bfd_openr (TMP_HEAD_O, HOW_BFD_READ_TARGET);
-}
-
-static bfd *
-make_tail (void)
-{
- FILE *f = fopen (TMP_TAIL_S, FOPEN_WT);
-
- if (f == NULL)
- {
- fatal (_("failed to open temporary tail file: %s"), TMP_TAIL_S);
- return NULL;
- }
-
- if (!no_idata4)
- {
- fprintf (f, "\t.section .idata$4\n");
-#ifdef DLLTOOL_MX86_64
- fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG); /* NULL terminating list. */
-#else
- fprintf (f,"\t%s\t0\n", ASM_LONG); /* NULL terminating list. */
-#endif
- }
-
- if (!no_idata5)
- {
- fprintf (f, "\t.section .idata$5\n");
-#ifdef DLLTOOL_MX86_64
- fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG); /* NULL terminating list. */
-#else
- fprintf (f,"\t%s\t0\n", ASM_LONG); /* NULL terminating list. */
-#endif
- }
-
-#ifdef DLLTOOL_PPC
- /* Normally, we need to see a null descriptor built in idata$3 to
- act as the terminator for the list. The ideal way, I suppose,
- would be to mark this section as a comdat type 2 section, so
- only one would appear in the final .exe (if our linker supported
- comdat, that is) or cause it to be inserted by something else (say
- crt0). */
-
- fprintf (f, "\t.section .idata$3\n");
- fprintf (f, "\t%s\t0\n", ASM_LONG);
- fprintf (f, "\t%s\t0\n", ASM_LONG);
- fprintf (f, "\t%s\t0\n", ASM_LONG);
- fprintf (f, "\t%s\t0\n", ASM_LONG);
- fprintf (f, "\t%s\t0\n", ASM_LONG);
-#endif
-
-#ifdef DLLTOOL_PPC
- /* Other PowerPC NT compilers use idata$6 for the dllname, so I
- do too. Original, huh? */
- fprintf (f, "\t.section .idata$6\n");
-#else
- fprintf (f, "\t.section .idata$7\n");
-#endif
-
- fprintf (f, "\t%s\t__%s_iname\n", ASM_GLOBAL, imp_name_lab);
- fprintf (f, "__%s_iname:\t%s\t\"%s\"\n",
- imp_name_lab, ASM_TEXT, dll_name);
-
- fclose (f);
-
- assemble_file (TMP_TAIL_S, TMP_TAIL_O);
-
- return bfd_openr (TMP_TAIL_O, HOW_BFD_READ_TARGET);
-}
-
-static void
-gen_lib_file (void)
-{
- int i;
- export_type *exp;
- bfd *ar_head;
- bfd *ar_tail;
- bfd *outarch;
- bfd * head = 0;
-
- unlink (imp_name);
-
- outarch = bfd_openw (imp_name, HOW_BFD_WRITE_TARGET);
-
- if (!outarch)
- /* xgettext:c-format */
- fatal (_("Can't open .lib file: %s"), imp_name);
-
- /* xgettext:c-format */
- inform (_("Creating library file: %s"), imp_name);
-
- bfd_set_format (outarch, bfd_archive);
- outarch->has_armap = 1;
- outarch->is_thin_archive = 0;
-
- /* Work out a reasonable size of things to put onto one line. */
- ar_head = make_head ();
- ar_tail = make_tail();
-
- if (ar_head == NULL || ar_tail == NULL)
- return;
-
- for (i = 0; (exp = d_exports_lexically[i]); i++)
- {
- bfd *n;
- /* Don't add PRIVATE entries to import lib. */
- if (exp->private)
- continue;
- n = make_one_lib_file (exp, i);
- n->archive_next = head;
- head = n;
- if (ext_prefix_alias)
- {
- export_type alias_exp;
-
- assert (i < PREFIX_ALIAS_BASE);
- alias_exp.name = make_imp_label (ext_prefix_alias, exp->name);
- alias_exp.internal_name = exp->internal_name;
- alias_exp.import_name = exp->name;
- alias_exp.ordinal = exp->ordinal;
- alias_exp.constant = exp->constant;
- alias_exp.noname = exp->noname;
- alias_exp.private = exp->private;
- alias_exp.data = exp->data;
- alias_exp.hint = exp->hint;
- alias_exp.forward = exp->forward;
- alias_exp.next = exp->next;
- n = make_one_lib_file (&alias_exp, i + PREFIX_ALIAS_BASE);
- n->archive_next = head;
- head = n;
- }
- }
-
- /* Now stick them all into the archive. */
- ar_head->archive_next = head;
- ar_tail->archive_next = ar_head;
- head = ar_tail;
-
- if (! bfd_set_archive_head (outarch, head))
- bfd_fatal ("bfd_set_archive_head");
-
- if (! bfd_close (outarch))
- bfd_fatal (imp_name);
-
- while (head != NULL)
- {
- bfd *n = head->archive_next;
- bfd_close (head);
- head = n;
- }
-
- /* Delete all the temp files. */
- if (dontdeltemps == 0)
- {
- unlink (TMP_HEAD_O);
- unlink (TMP_HEAD_S);
- unlink (TMP_TAIL_O);
- unlink (TMP_TAIL_S);
- }
-
- if (dontdeltemps < 2)
- {
- char *name;
-
- name = (char *) alloca (strlen (TMP_STUB) + 10);
- for (i = 0; (exp = d_exports_lexically[i]); i++)
- {
- /* Don't delete non-existent stubs for PRIVATE entries. */
- if (exp->private)
- continue;
- sprintf (name, "%s%05d.o", TMP_STUB, i);
- if (unlink (name) < 0)
- /* xgettext:c-format */
- non_fatal (_("cannot delete %s: %s"), name, strerror (errno));
- if (ext_prefix_alias)
- {
- sprintf (name, "%s%05d.o", TMP_STUB, i + PREFIX_ALIAS_BASE);
- if (unlink (name) < 0)
- /* xgettext:c-format */
- non_fatal (_("cannot delete %s: %s"), name, strerror (errno));
- }
- }
- }
-
- inform (_("Created lib file"));
-}
-
-/* Run through the information gathered from the .o files and the
- .def file and work out the best stuff. */
-
-static int
-pfunc (const void *a, const void *b)
-{
- export_type *ap = *(export_type **) a;
- export_type *bp = *(export_type **) b;
- if (ap->ordinal == bp->ordinal)
- return 0;
-
- /* Unset ordinals go to the bottom. */
- if (ap->ordinal == -1)
- return 1;
- if (bp->ordinal == -1)
- return -1;
- return (ap->ordinal - bp->ordinal);
-}
-
-static int
-nfunc (const void *a, const void *b)
-{
- export_type *ap = *(export_type **) a;
- export_type *bp = *(export_type **) b;
- const char *an = ap->name;
- const char *bn = bp->name;
-
- if (killat)
- {
- an = (an[0] == '@') ? an + 1 : an;
- bn = (bn[0] == '@') ? bn + 1 : bn;
- }
-
- return (strcmp (an, bn));
-}
-
-static void
-remove_null_names (export_type **ptr)
-{
- int src;
- int dst;
-
- for (dst = src = 0; src < d_nfuncs; src++)
- {
- if (ptr[src])
- {
- ptr[dst] = ptr[src];
- dst++;
- }
- }
- d_nfuncs = dst;
-}
-
-static void
-process_duplicates (export_type **d_export_vec)
-{
- int more = 1;
- int i;
-
- while (more)
- {
- more = 0;
- /* Remove duplicates. */
- qsort (d_export_vec, d_nfuncs, sizeof (export_type *), nfunc);
-
- for (i = 0; i < d_nfuncs - 1; i++)
- {
- if (strcmp (d_export_vec[i]->name,
- d_export_vec[i + 1]->name) == 0)
- {
- export_type *a = d_export_vec[i];
- export_type *b = d_export_vec[i + 1];
-
- more = 1;
-
- /* xgettext:c-format */
- inform (_("Warning, ignoring duplicate EXPORT %s %d,%d"),
- a->name, a->ordinal, b->ordinal);
-
- if (a->ordinal != -1
- && b->ordinal != -1)
- /* xgettext:c-format */
- fatal (_("Error, duplicate EXPORT with ordinals: %s"),
- a->name);
-
- /* Merge attributes. */
- b->ordinal = a->ordinal > 0 ? a->ordinal : b->ordinal;
- b->constant |= a->constant;
- b->noname |= a->noname;
- b->data |= a->data;
- d_export_vec[i] = 0;
- }
-
- remove_null_names (d_export_vec);
- }
- }
-
- /* Count the names. */
- for (i = 0; i < d_nfuncs; i++)
- if (!d_export_vec[i]->noname)
- d_named_nfuncs++;
-}
-
-static void
-fill_ordinals (export_type **d_export_vec)
-{
- int lowest = -1;
- int i;
- char *ptr;
- int size = 65536;
-
- qsort (d_export_vec, d_nfuncs, sizeof (export_type *), pfunc);
-
- /* Fill in the unset ordinals with ones from our range. */
- ptr = (char *) xmalloc (size);
-
- memset (ptr, 0, size);
-
- /* Mark in our large vector all the numbers that are taken. */
- for (i = 0; i < d_nfuncs; i++)
- {
- if (d_export_vec[i]->ordinal != -1)
- {
- ptr[d_export_vec[i]->ordinal] = 1;
-
- if (lowest == -1 || d_export_vec[i]->ordinal < lowest)
- lowest = d_export_vec[i]->ordinal;
- }
- }
-
- /* Start at 1 for compatibility with MS toolchain. */
- if (lowest == -1)
- lowest = 1;
-
- /* Now fill in ordinals where the user wants us to choose. */
- for (i = 0; i < d_nfuncs; i++)
- {
- if (d_export_vec[i]->ordinal == -1)
- {
- int j;
-
- /* First try within or after any user supplied range. */
- for (j = lowest; j < size; j++)
- if (ptr[j] == 0)
- {
- ptr[j] = 1;
- d_export_vec[i]->ordinal = j;
- goto done;
- }
-
- /* Then try before the range. */
- for (j = lowest; j >0; j--)
- if (ptr[j] == 0)
- {
- ptr[j] = 1;
- d_export_vec[i]->ordinal = j;
- goto done;
- }
- done:;
- }
- }
-
- free (ptr);
-
- /* And resort. */
- qsort (d_export_vec, d_nfuncs, sizeof (export_type *), pfunc);
-
- /* Work out the lowest and highest ordinal numbers. */
- if (d_nfuncs)
- {
- if (d_export_vec[0])
- d_low_ord = d_export_vec[0]->ordinal;
- if (d_export_vec[d_nfuncs-1])
- d_high_ord = d_export_vec[d_nfuncs-1]->ordinal;
- }
-}
-
-static void
-mangle_defs (void)
-{
- /* First work out the minimum ordinal chosen. */
- export_type *exp;
-
- int i;
- int hint = 0;
- export_type **d_export_vec = xmalloc (sizeof (export_type *) * d_nfuncs);
-
- inform (_("Processing definitions"));
-
- for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
- d_export_vec[i] = exp;
-
- process_duplicates (d_export_vec);
- fill_ordinals (d_export_vec);
-
- /* Put back the list in the new order. */
- d_exports = 0;
- for (i = d_nfuncs - 1; i >= 0; i--)
- {
- d_export_vec[i]->next = d_exports;
- d_exports = d_export_vec[i];
- }
-
- /* Build list in alpha order. */
- d_exports_lexically = (export_type **)
- xmalloc (sizeof (export_type *) * (d_nfuncs + 1));
-
- for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
- d_exports_lexically[i] = exp;
-
- d_exports_lexically[i] = 0;
-
- qsort (d_exports_lexically, i, sizeof (export_type *), nfunc);
-
- /* Fill exp entries with their hint values. */
- for (i = 0; i < d_nfuncs; i++)
- if (!d_exports_lexically[i]->noname || show_allnames)
- d_exports_lexically[i]->hint = hint++;
-
- inform (_("Processed definitions"));
-}
-
-static void
-usage (FILE *file, int status)
-{
- /* xgetext:c-format */
- fprintf (file, _("Usage %s <option(s)> <object-file(s)>\n"), program_name);
- /* xgetext:c-format */
- fprintf (file, _(" -m --machine <machine> Create as DLL for <machine>. [default: %s]\n"), mname);
- fprintf (file, _(" possible <machine>: arm[_interwork], i386, mcore[-elf]{-le|-be}, ppc, thumb\n"));
- fprintf (file, _(" -e --output-exp <outname> Generate an export file.\n"));
- fprintf (file, _(" -l --output-lib <outname> Generate an interface library.\n"));
- fprintf (file, _(" -a --add-indirect Add dll indirects to export file.\n"));
- fprintf (file, _(" -D --dllname <name> Name of input dll to put into interface lib.\n"));
- fprintf (file, _(" -d --input-def <deffile> Name of .def file to be read in.\n"));
- fprintf (file, _(" -z --output-def <deffile> Name of .def file to be created.\n"));
- fprintf (file, _(" --export-all-symbols Export all symbols to .def\n"));
- fprintf (file, _(" --no-export-all-symbols Only export listed symbols\n"));
- fprintf (file, _(" --exclude-symbols <list> Don't export <list>\n"));
- fprintf (file, _(" --no-default-excludes Clear default exclude symbols\n"));
- fprintf (file, _(" -b --base-file <basefile> Read linker generated base file.\n"));
- fprintf (file, _(" -x --no-idata4 Don't generate idata$4 section.\n"));
- fprintf (file, _(" -c --no-idata5 Don't generate idata$5 section.\n"));
- fprintf (file, _(" -U --add-underscore Add underscores to all symbols in interface library.\n"));
- fprintf (file, _(" --add-stdcall-underscore Add underscores to stdcall symbols in interface library.\n"));
- fprintf (file, _(" -k --kill-at Kill @<n> from exported names.\n"));
- fprintf (file, _(" -A --add-stdcall-alias Add aliases without @<n>.\n"));
- fprintf (file, _(" -p --ext-prefix-alias <prefix> Add aliases with <prefix>.\n"));
- fprintf (file, _(" -S --as <name> Use <name> for assembler.\n"));
- fprintf (file, _(" -f --as-flags <flags> Pass <flags> to the assembler.\n"));
- fprintf (file, _(" -C --compat-implib Create backward compatible import library.\n"));
- fprintf (file, _(" -n --no-delete Keep temp files (repeat for extra preservation).\n"));
- fprintf (file, _(" -t --temp-prefix <prefix> Use <prefix> to construct temp file names.\n"));
- fprintf (file, _(" -v --verbose Be verbose.\n"));
- fprintf (file, _(" -V --version Display the program version.\n"));
- fprintf (file, _(" -h --help Display this information.\n"));
- fprintf (file, _(" @<file> Read options from <file>.\n"));
-#ifdef DLLTOOL_MCORE_ELF
- fprintf (file, _(" -M --mcore-elf <outname> Process mcore-elf object files into <outname>.\n"));
- fprintf (file, _(" -L --linker <name> Use <name> as the linker.\n"));
- fprintf (file, _(" -F --linker-flags <flags> Pass <flags> to the linker.\n"));
-#endif
- if (REPORT_BUGS_TO[0] && status == 0)
- fprintf (file, _("Report bugs to %s\n"), REPORT_BUGS_TO);
- exit (status);
-}
-
-#define OPTION_EXPORT_ALL_SYMS 150
-#define OPTION_NO_EXPORT_ALL_SYMS (OPTION_EXPORT_ALL_SYMS + 1)
-#define OPTION_EXCLUDE_SYMS (OPTION_NO_EXPORT_ALL_SYMS + 1)
-#define OPTION_NO_DEFAULT_EXCLUDES (OPTION_EXCLUDE_SYMS + 1)
-#define OPTION_ADD_STDCALL_UNDERSCORE (OPTION_NO_DEFAULT_EXCLUDES + 1)
-
-static const struct option long_options[] =
-{
- {"no-delete", no_argument, NULL, 'n'},
- {"dllname", required_argument, NULL, 'D'},
- {"no-idata4", no_argument, NULL, 'x'},
- {"no-idata5", no_argument, NULL, 'c'},
- {"output-exp", required_argument, NULL, 'e'},
- {"output-def", required_argument, NULL, 'z'},
- {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL_SYMS},
- {"no-export-all-symbols", no_argument, NULL, OPTION_NO_EXPORT_ALL_SYMS},
- {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMS},
- {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
- {"output-lib", required_argument, NULL, 'l'},
- {"def", required_argument, NULL, 'd'}, /* for compatibility with older versions */
- {"input-def", required_argument, NULL, 'd'},
- {"add-underscore", no_argument, NULL, 'U'},
- {"add-stdcall-underscore", no_argument, NULL, OPTION_ADD_STDCALL_UNDERSCORE},
- {"kill-at", no_argument, NULL, 'k'},
- {"add-stdcall-alias", no_argument, NULL, 'A'},
- {"ext-prefix-alias", required_argument, NULL, 'p'},
- {"verbose", no_argument, NULL, 'v'},
- {"version", no_argument, NULL, 'V'},
- {"help", no_argument, NULL, 'h'},
- {"machine", required_argument, NULL, 'm'},
- {"add-indirect", no_argument, NULL, 'a'},
- {"base-file", required_argument, NULL, 'b'},
- {"as", required_argument, NULL, 'S'},
- {"as-flags", required_argument, NULL, 'f'},
- {"mcore-elf", required_argument, NULL, 'M'},
- {"compat-implib", no_argument, NULL, 'C'},
- {"temp-prefix", required_argument, NULL, 't'},
- {NULL,0,NULL,0}
-};
-
-int main (int, char **);
-
-int
-main (int ac, char **av)
-{
- int c;
- int i;
- char *firstarg = 0;
- program_name = av[0];
- oav = av;
-
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
- setlocale (LC_MESSAGES, "");
-#endif
-#if defined (HAVE_SETLOCALE)
- setlocale (LC_CTYPE, "");
-#endif
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- expandargv (&ac, &av);
-
- while ((c = getopt_long (ac, av,
-#ifdef DLLTOOL_MCORE_ELF
- "m:e:l:aD:d:z:b:xp:cCuUkAS:f:nvVHhM:L:F:",
-#else
- "m:e:l:aD:d:z:b:xp:cCuUkAS:f:nvVHh",
-#endif
- long_options, 0))
- != EOF)
- {
- switch (c)
- {
- case OPTION_EXPORT_ALL_SYMS:
- export_all_symbols = TRUE;
- break;
- case OPTION_NO_EXPORT_ALL_SYMS:
- export_all_symbols = FALSE;
- break;
- case OPTION_EXCLUDE_SYMS:
- add_excludes (optarg);
- break;
- case OPTION_NO_DEFAULT_EXCLUDES:
- do_default_excludes = FALSE;
- break;
- case OPTION_ADD_STDCALL_UNDERSCORE:
- add_stdcall_underscore = 1;
- break;
- case 'x':
- no_idata4 = 1;
- break;
- case 'c':
- no_idata5 = 1;
- break;
- case 'S':
- as_name = optarg;
- break;
- case 't':
- tmp_prefix = optarg;
- break;
- case 'f':
- as_flags = optarg;
- break;
-
- /* Ignored for compatibility. */
- case 'u':
- break;
- case 'a':
- add_indirect = 1;
- break;
- case 'z':
- output_def = fopen (optarg, FOPEN_WT);
- break;
- case 'D':
- dll_name = (char*) lbasename (optarg);
- if (dll_name != optarg)
- non_fatal (_("Path components stripped from dllname, '%s'."),
- optarg);
- break;
- case 'l':
- imp_name = optarg;
- break;
- case 'e':
- exp_name = optarg;
- break;
- case 'H':
- case 'h':
- usage (stdout, 0);
- break;
- case 'm':
- mname = optarg;
- break;
- case 'v':
- verbose = 1;
- break;
- case 'V':
- print_version (program_name);
- break;
- case 'U':
- add_underscore = 1;
- break;
- case 'k':
- killat = 1;
- break;
- case 'A':
- add_stdcall_alias = 1;
- break;
- case 'p':
- ext_prefix_alias = optarg;
- break;
- case 'd':
- def_file = optarg;
- break;
- case 'n':
- dontdeltemps++;
- break;
- case 'b':
- base_file = fopen (optarg, FOPEN_RB);
-
- if (!base_file)
- /* xgettext:c-format */
- fatal (_("Unable to open base-file: %s"), optarg);
-
- break;
-#ifdef DLLTOOL_MCORE_ELF
- case 'M':
- mcore_elf_out_file = optarg;
- break;
- case 'L':
- mcore_elf_linker = optarg;
- break;
- case 'F':
- mcore_elf_linker_flags = optarg;
- break;
-#endif
- case 'C':
- create_compat_implib = 1;
- break;
- default:
- usage (stderr, 1);
- break;
- }
- }
-
- if (!tmp_prefix)
- tmp_prefix = prefix_encode ("d", getpid ());
-
- for (i = 0; mtable[i].type; i++)
- if (strcmp (mtable[i].type, mname) == 0)
- break;
-
- if (!mtable[i].type)
- /* xgettext:c-format */
- fatal (_("Machine '%s' not supported"), mname);
-
- machine = i;
-
- if (!dll_name && exp_name)
- {
- /* If we are inferring dll_name from exp_name,
- strip off any path components, without emitting
- a warning. */
- const char* exp_basename = lbasename (exp_name);
- const int len = strlen (exp_basename) + 5;
- dll_name = xmalloc (len);
- strcpy (dll_name, exp_basename);
- strcat (dll_name, ".dll");
- }
-
- if (as_name == NULL)
- as_name = deduce_name ("as");
-
- /* Don't use the default exclude list if we're reading only the
- symbols in the .drectve section. The default excludes are meant
- to avoid exporting DLL entry point and Cygwin32 impure_ptr. */
- if (! export_all_symbols)
- do_default_excludes = FALSE;
-
- if (do_default_excludes)
- set_default_excludes ();
-
- if (def_file)
- process_def_file (def_file);
-
- while (optind < ac)
- {
- if (!firstarg)
- firstarg = av[optind];
- scan_obj_file (av[optind]);
- optind++;
- }
-
- mangle_defs ();
-
- if (exp_name)
- gen_exp_file ();
-
- if (imp_name)
- {
- /* Make imp_name safe for use as a label. */
- char *p;
-
- imp_name_lab = xstrdup (imp_name);
- for (p = imp_name_lab; *p; p++)
- {
- if (!ISALNUM (*p))
- *p = '_';
- }
- head_label = make_label("_head_", imp_name_lab);
- gen_lib_file ();
- }
-
- if (output_def)
- gen_def_file ();
-
-#ifdef DLLTOOL_MCORE_ELF
- if (mcore_elf_out_file)
- mcore_elf_gen_out_file ();
-#endif
-
- return 0;
-}
-
-/* Look for the program formed by concatenating PROG_NAME and the
- string running from PREFIX to END_PREFIX. If the concatenated
- string contains a '/', try appending EXECUTABLE_SUFFIX if it is
- appropriate. */
-
-static char *
-look_for_prog (const char *prog_name, const char *prefix, int end_prefix)
-{
- struct stat s;
- char *cmd;
-
- cmd = xmalloc (strlen (prefix)
- + strlen (prog_name)
-#ifdef HAVE_EXECUTABLE_SUFFIX
- + strlen (EXECUTABLE_SUFFIX)
-#endif
- + 10);
- strcpy (cmd, prefix);
-
- sprintf (cmd + end_prefix, "%s", prog_name);
-
- if (strchr (cmd, '/') != NULL)
- {
- int found;
-
- found = (stat (cmd, &s) == 0
-#ifdef HAVE_EXECUTABLE_SUFFIX
- || stat (strcat (cmd, EXECUTABLE_SUFFIX), &s) == 0
-#endif
- );
-
- if (! found)
- {
- /* xgettext:c-format */
- inform (_("Tried file: %s"), cmd);
- free (cmd);
- return NULL;
- }
- }
-
- /* xgettext:c-format */
- inform (_("Using file: %s"), cmd);
-
- return cmd;
-}
-
-/* Deduce the name of the program we are want to invoke.
- PROG_NAME is the basic name of the program we want to run,
- eg "as" or "ld". The catch is that we might want actually
- run "i386-pe-as" or "ppc-pe-ld".
-
- If argv[0] contains the full path, then try to find the program
- in the same place, with and then without a target-like prefix.
-
- Given, argv[0] = /usr/local/bin/i586-cygwin32-dlltool,
- deduce_name("as") uses the following search order:
-
- /usr/local/bin/i586-cygwin32-as
- /usr/local/bin/as
- as
-
- If there's an EXECUTABLE_SUFFIX, it'll use that as well; for each
- name, it'll try without and then with EXECUTABLE_SUFFIX.
-
- Given, argv[0] = i586-cygwin32-dlltool, it will not even try "as"
- as the fallback, but rather return i586-cygwin32-as.
-
- Oh, and given, argv[0] = dlltool, it'll return "as".
-
- Returns a dynamically allocated string. */
-
-static char *
-deduce_name (const char *prog_name)
-{
- char *cmd;
- char *dash, *slash, *cp;
-
- dash = NULL;
- slash = NULL;
- for (cp = program_name; *cp != '\0'; ++cp)
- {
- if (*cp == '-')
- dash = cp;
- if (
-#if defined(__DJGPP__) || defined (__CYGWIN__) || defined(__WIN32__)
- *cp == ':' || *cp == '\\' ||
-#endif
- *cp == '/')
- {
- slash = cp;
- dash = NULL;
- }
- }
-
- cmd = NULL;
-
- if (dash != NULL)
- {
- /* First, try looking for a prefixed PROG_NAME in the
- PROGRAM_NAME directory, with the same prefix as PROGRAM_NAME. */
- cmd = look_for_prog (prog_name, program_name, dash - program_name + 1);
- }
-
- if (slash != NULL && cmd == NULL)
- {
- /* Next, try looking for a PROG_NAME in the same directory as
- that of this program. */
- cmd = look_for_prog (prog_name, program_name, slash - program_name + 1);
- }
-
- if (cmd == NULL)
- {
- /* Just return PROG_NAME as is. */
- cmd = xstrdup (prog_name);
- }
-
- return cmd;
-}
-
-#ifdef DLLTOOL_MCORE_ELF
-typedef struct fname_cache
-{
- const char * filename;
- struct fname_cache * next;
-}
-fname_cache;
-
-static fname_cache fnames;
-
-static void
-mcore_elf_cache_filename (const char * filename)
-{
- fname_cache * ptr;
-
- ptr = & fnames;
-
- while (ptr->next != NULL)
- ptr = ptr->next;
-
- ptr->filename = filename;
- ptr->next = (fname_cache *) malloc (sizeof (fname_cache));
- if (ptr->next != NULL)
- ptr->next->next = NULL;
-}
-
-#define MCORE_ELF_TMP_OBJ "mcoreelf.o"
-#define MCORE_ELF_TMP_EXP "mcoreelf.exp"
-#define MCORE_ELF_TMP_LIB "mcoreelf.lib"
-
-static void
-mcore_elf_gen_out_file (void)
-{
- fname_cache * ptr;
- dyn_string_t ds;
-
- /* Step one. Run 'ld -r' on the input object files in order to resolve
- any internal references and to generate a single .exports section. */
- ptr = & fnames;
-
- ds = dyn_string_new (100);
- dyn_string_append_cstr (ds, "-r ");
-
- if (mcore_elf_linker_flags != NULL)
- dyn_string_append_cstr (ds, mcore_elf_linker_flags);
-
- while (ptr->next != NULL)
- {
- dyn_string_append_cstr (ds, ptr->filename);
- dyn_string_append_cstr (ds, " ");
-
- ptr = ptr->next;
- }
-
- dyn_string_append_cstr (ds, "-o ");
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_OBJ);
-
- if (mcore_elf_linker == NULL)
- mcore_elf_linker = deduce_name ("ld");
-
- run (mcore_elf_linker, ds->s);
-
- dyn_string_delete (ds);
-
- /* Step two. Create a .exp file and a .lib file from the temporary file.
- Do this by recursively invoking dlltool... */
- ds = dyn_string_new (100);
-
- dyn_string_append_cstr (ds, "-S ");
- dyn_string_append_cstr (ds, as_name);
-
- dyn_string_append_cstr (ds, " -e ");
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_EXP);
- dyn_string_append_cstr (ds, " -l ");
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_LIB);
- dyn_string_append_cstr (ds, " " );
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_OBJ);
-
- if (verbose)
- dyn_string_append_cstr (ds, " -v");
-
- if (dontdeltemps)
- {
- dyn_string_append_cstr (ds, " -n");
-
- if (dontdeltemps > 1)
- dyn_string_append_cstr (ds, " -n");
- }
-
- /* XXX - FIME: ought to check/copy other command line options as well. */
- run (program_name, ds->s);
-
- dyn_string_delete (ds);
-
- /* Step four. Feed the .exp and object files to ld -shared to create the dll. */
- ds = dyn_string_new (100);
-
- dyn_string_append_cstr (ds, "-shared ");
-
- if (mcore_elf_linker_flags)
- dyn_string_append_cstr (ds, mcore_elf_linker_flags);
-
- dyn_string_append_cstr (ds, " ");
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_EXP);
- dyn_string_append_cstr (ds, " ");
- dyn_string_append_cstr (ds, MCORE_ELF_TMP_OBJ);
- dyn_string_append_cstr (ds, " -o ");
- dyn_string_append_cstr (ds, mcore_elf_out_file);
-
- run (mcore_elf_linker, ds->s);
-
- dyn_string_delete (ds);
-
- if (dontdeltemps == 0)
- unlink (MCORE_ELF_TMP_EXP);
-
- if (dontdeltemps < 2)
- unlink (MCORE_ELF_TMP_OBJ);
-}
-#endif /* DLLTOOL_MCORE_ELF */
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
deleted file mode 100644
index 3a5ef0ff3e9..00000000000
--- a/binutils/dwarf.c
+++ /dev/null
@@ -1,4642 +0,0 @@
-/* dwarf.c -- display DWARF contents of a BFD binary file
- Copyright 2005, 2006, 2007, 2008
- Free Software Foundation, Inc.
-
- This file is part of GNU Binutils.
-
- 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"
-#include "libiberty.h"
-#include "bfd.h"
-#include "bucomm.h"
-#include "elf/common.h"
-#include "elf/dwarf2.h"
-#include "dwarf.h"
-
-static int have_frame_base;
-static int need_base_address;
-
-static unsigned int last_pointer_size = 0;
-static int warned_about_missing_comp_units = FALSE;
-
-static unsigned int num_debug_info_entries = 0;
-static debug_info *debug_information = NULL;
-/* Special value for num_debug_info_entries to indicate
- that the .debug_info section could not be loaded/parsed. */
-#define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
-
-int eh_addr_size;
-
-int do_debug_info;
-int do_debug_abbrevs;
-int do_debug_lines;
-int do_debug_lines_decoded;
-int do_debug_pubnames;
-int do_debug_aranges;
-int do_debug_ranges;
-int do_debug_frames;
-int do_debug_frames_interp;
-int do_debug_macinfo;
-int do_debug_str;
-int do_debug_loc;
-int do_wide;
-
-dwarf_vma (*byte_get) (unsigned char *, int);
-
-dwarf_vma
-byte_get_little_endian (unsigned char *field, int size)
-{
- switch (size)
- {
- case 1:
- return *field;
-
- case 2:
- return ((unsigned int) (field[0]))
- | (((unsigned int) (field[1])) << 8);
-
- case 4:
- return ((unsigned long) (field[0]))
- | (((unsigned long) (field[1])) << 8)
- | (((unsigned long) (field[2])) << 16)
- | (((unsigned long) (field[3])) << 24);
-
- case 8:
- if (sizeof (dwarf_vma) == 8)
- return ((dwarf_vma) (field[0]))
- | (((dwarf_vma) (field[1])) << 8)
- | (((dwarf_vma) (field[2])) << 16)
- | (((dwarf_vma) (field[3])) << 24)
- | (((dwarf_vma) (field[4])) << 32)
- | (((dwarf_vma) (field[5])) << 40)
- | (((dwarf_vma) (field[6])) << 48)
- | (((dwarf_vma) (field[7])) << 56);
- else if (sizeof (dwarf_vma) == 4)
- /* We want to extract data from an 8 byte wide field and
- place it into a 4 byte wide field. Since this is a little
- endian source we can just use the 4 byte extraction code. */
- return ((unsigned long) (field[0]))
- | (((unsigned long) (field[1])) << 8)
- | (((unsigned long) (field[2])) << 16)
- | (((unsigned long) (field[3])) << 24);
-
- default:
- error (_("Unhandled data length: %d\n"), size);
- abort ();
- }
-}
-
-dwarf_vma
-byte_get_big_endian (unsigned char *field, int size)
-{
- switch (size)
- {
- case 1:
- return *field;
-
- case 2:
- return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
-
- case 4:
- return ((unsigned long) (field[3]))
- | (((unsigned long) (field[2])) << 8)
- | (((unsigned long) (field[1])) << 16)
- | (((unsigned long) (field[0])) << 24);
-
- case 8:
- if (sizeof (dwarf_vma) == 8)
- return ((dwarf_vma) (field[7]))
- | (((dwarf_vma) (field[6])) << 8)
- | (((dwarf_vma) (field[5])) << 16)
- | (((dwarf_vma) (field[4])) << 24)
- | (((dwarf_vma) (field[3])) << 32)
- | (((dwarf_vma) (field[2])) << 40)
- | (((dwarf_vma) (field[1])) << 48)
- | (((dwarf_vma) (field[0])) << 56);
- else if (sizeof (dwarf_vma) == 4)
- {
- /* Although we are extracing data from an 8 byte wide field,
- we are returning only 4 bytes of data. */
- field += 4;
- return ((unsigned long) (field[3]))
- | (((unsigned long) (field[2])) << 8)
- | (((unsigned long) (field[1])) << 16)
- | (((unsigned long) (field[0])) << 24);
- }
-
- default:
- error (_("Unhandled data length: %d\n"), size);
- abort ();
- }
-}
-
-static dwarf_vma
-byte_get_signed (unsigned char *field, int size)
-{
- dwarf_vma x = byte_get (field, size);
-
- switch (size)
- {
- case 1:
- return (x ^ 0x80) - 0x80;
- case 2:
- return (x ^ 0x8000) - 0x8000;
- case 4:
- return (x ^ 0x80000000) - 0x80000000;
- case 8:
- return x;
- default:
- abort ();
- }
-}
-
-/* Print a dwarf_vma value (typically an address, offset or length) in
- hexadecimal format, followed by a space. The length of the value (and
- hence the precision displayed) is determined by the byte_size parameter. */
-
-static void
-print_dwarf_vma (dwarf_vma val, unsigned byte_size)
-{
- static char buff[18];
-
- /* Printf does not have a way of specifiying a maximum field width for an
- integer value, so we print the full value into a buffer and then select
- the precision we need. */
-#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
-#ifndef __MSVCRT__
- snprintf (buff, sizeof (buff), "%16.16llx ", val);
-#else
- snprintf (buff, sizeof (buff), "%016I64x ", val);
-#endif
-#else
- snprintf (buff, sizeof (buff), "%16.16lx ", val);
-#endif
-
- printf (buff + (byte_size == 4 ? 8 : 0));
-}
-
-static unsigned long int
-read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
-{
- unsigned long int result = 0;
- unsigned int num_read = 0;
- unsigned int shift = 0;
- unsigned char byte;
-
- do
- {
- byte = *data++;
- num_read++;
-
- result |= ((unsigned long int) (byte & 0x7f)) << shift;
-
- shift += 7;
-
- }
- while (byte & 0x80);
-
- if (length_return != NULL)
- *length_return = num_read;
-
- if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
- result |= -1L << shift;
-
- return result;
-}
-
-typedef struct State_Machine_Registers
-{
- unsigned long address;
- unsigned int file;
- unsigned int line;
- unsigned int column;
- int is_stmt;
- int basic_block;
- int end_sequence;
-/* This variable hold the number of the last entry seen
- in the File Table. */
- unsigned int last_file_entry;
-} SMR;
-
-static SMR state_machine_regs;
-
-static void
-reset_state_machine (int is_stmt)
-{
- state_machine_regs.address = 0;
- state_machine_regs.file = 1;
- state_machine_regs.line = 1;
- state_machine_regs.column = 0;
- state_machine_regs.is_stmt = is_stmt;
- state_machine_regs.basic_block = 0;
- state_machine_regs.end_sequence = 0;
- state_machine_regs.last_file_entry = 0;
-}
-
-/* Handled an extend line op.
- Returns the number of bytes read. */
-
-static int
-process_extended_line_op (unsigned char *data, int is_stmt)
-{
- unsigned char op_code;
- unsigned int bytes_read;
- unsigned int len;
- unsigned char *name;
- unsigned long adr;
-
- len = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
-
- if (len == 0)
- {
- warn (_("badly formed extended line op encountered!\n"));
- return bytes_read;
- }
-
- len += bytes_read;
- op_code = *data++;
-
- printf (_(" Extended opcode %d: "), op_code);
-
- switch (op_code)
- {
- case DW_LNE_end_sequence:
- printf (_("End of Sequence\n\n"));
- reset_state_machine (is_stmt);
- break;
-
- case DW_LNE_set_address:
- adr = byte_get (data, len - bytes_read - 1);
- printf (_("set Address to 0x%lx\n"), adr);
- state_machine_regs.address = adr;
- break;
-
- case DW_LNE_define_file:
- printf (_(" define new File Table entry\n"));
- printf (_(" Entry\tDir\tTime\tSize\tName\n"));
-
- printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
- name = data;
- data += strlen ((char *) data) + 1;
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- data += bytes_read;
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- data += bytes_read;
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- printf (_("%s\n\n"), name);
- break;
-
- /* HP extensions. */
- case DW_LNE_HP_negate_is_UV_update:
- printf ("DW_LNE_HP_negate_is_UV_update");
- break;
- case DW_LNE_HP_push_context:
- printf ("DW_LNE_HP_push_context");
- break;
- case DW_LNE_HP_pop_context:
- printf ("DW_LNE_HP_pop_context");
- break;
- case DW_LNE_HP_set_file_line_column:
- printf ("DW_LNE_HP_set_file_line_column");
- break;
- case DW_LNE_HP_set_routine_name:
- printf ("DW_LNE_HP_set_routine_name");
- break;
- case DW_LNE_HP_set_sequence:
- printf ("DW_LNE_HP_set_sequence");
- break;
- case DW_LNE_HP_negate_post_semantics:
- printf ("DW_LNE_HP_negate_post_semantics");
- break;
- case DW_LNE_HP_negate_function_exit:
- printf ("DW_LNE_HP_negate_function_exit");
- break;
- case DW_LNE_HP_negate_front_end_logical:
- printf ("DW_LNE_HP_negate_front_end_logical");
- break;
- case DW_LNE_HP_define_proc:
- printf ("DW_LNE_HP_define_proc");
- break;
-
- default:
- if (op_code >= DW_LNE_lo_user
- /* The test against DW_LNW_hi_user is redundant due to
- the limited range of the unsigned char data type used
- for op_code. */
- /*&& op_code <= DW_LNE_hi_user*/)
- printf (_("user defined: length %d\n"), len - bytes_read);
- else
- printf (_("UNKNOWN: length %d\n"), len - bytes_read);
- break;
- }
-
- return len;
-}
-
-static const char *
-fetch_indirect_string (unsigned long offset)
-{
- struct dwarf_section *section = &debug_displays [str].section;
-
- if (section->start == NULL)
- return _("<no .debug_str section>");
-
- /* DWARF sections under Mach-O have non-zero addresses. */
- offset -= section->address;
- if (offset > section->size)
- {
- warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
- return _("<offset is too big>");
- }
-
- return (const char *) section->start + offset;
-}
-
-/* FIXME: There are better and more efficient ways to handle
- these structures. For now though, I just want something that
- is simple to implement. */
-typedef struct abbrev_attr
-{
- unsigned long attribute;
- unsigned long form;
- struct abbrev_attr *next;
-}
-abbrev_attr;
-
-typedef struct abbrev_entry
-{
- unsigned long entry;
- unsigned long tag;
- int children;
- struct abbrev_attr *first_attr;
- struct abbrev_attr *last_attr;
- struct abbrev_entry *next;
-}
-abbrev_entry;
-
-static abbrev_entry *first_abbrev = NULL;
-static abbrev_entry *last_abbrev = NULL;
-
-static void
-free_abbrevs (void)
-{
- abbrev_entry *abbrev;
-
- for (abbrev = first_abbrev; abbrev;)
- {
- abbrev_entry *next = abbrev->next;
- abbrev_attr *attr;
-
- for (attr = abbrev->first_attr; attr;)
- {
- abbrev_attr *next = attr->next;
-
- free (attr);
- attr = next;
- }
-
- free (abbrev);
- abbrev = next;
- }
-
- last_abbrev = first_abbrev = NULL;
-}
-
-static void
-add_abbrev (unsigned long number, unsigned long tag, int children)
-{
- abbrev_entry *entry;
-
- entry = malloc (sizeof (*entry));
-
- if (entry == NULL)
- /* ugg */
- return;
-
- entry->entry = number;
- entry->tag = tag;
- entry->children = children;
- entry->first_attr = NULL;
- entry->last_attr = NULL;
- entry->next = NULL;
-
- if (first_abbrev == NULL)
- first_abbrev = entry;
- else
- last_abbrev->next = entry;
-
- last_abbrev = entry;
-}
-
-static void
-add_abbrev_attr (unsigned long attribute, unsigned long form)
-{
- abbrev_attr *attr;
-
- attr = malloc (sizeof (*attr));
-
- if (attr == NULL)
- /* ugg */
- return;
-
- attr->attribute = attribute;
- attr->form = form;
- attr->next = NULL;
-
- if (last_abbrev->first_attr == NULL)
- last_abbrev->first_attr = attr;
- else
- last_abbrev->last_attr->next = attr;
-
- last_abbrev->last_attr = attr;
-}
-
-/* Processes the (partial) contents of a .debug_abbrev section.
- Returns NULL if the end of the section was encountered.
- Returns the address after the last byte read if the end of
- an abbreviation set was found. */
-
-static unsigned char *
-process_abbrev_section (unsigned char *start, unsigned char *end)
-{
- if (first_abbrev != NULL)
- return NULL;
-
- while (start < end)
- {
- unsigned int bytes_read;
- unsigned long entry;
- unsigned long tag;
- unsigned long attribute;
- int children;
-
- entry = read_leb128 (start, & bytes_read, 0);
- start += bytes_read;
-
- /* A single zero is supposed to end the section according
- to the standard. If there's more, then signal that to
- the caller. */
- if (entry == 0)
- return start == end ? NULL : start;
-
- tag = read_leb128 (start, & bytes_read, 0);
- start += bytes_read;
-
- children = *start++;
-
- add_abbrev (entry, tag, children);
-
- do
- {
- unsigned long form;
-
- attribute = read_leb128 (start, & bytes_read, 0);
- start += bytes_read;
-
- form = read_leb128 (start, & bytes_read, 0);
- start += bytes_read;
-
- if (attribute != 0)
- add_abbrev_attr (attribute, form);
- }
- while (attribute != 0);
- }
-
- return NULL;
-}
-
-static char *
-get_TAG_name (unsigned long tag)
-{
- switch (tag)
- {
- case DW_TAG_padding: return "DW_TAG_padding";
- case DW_TAG_array_type: return "DW_TAG_array_type";
- case DW_TAG_class_type: return "DW_TAG_class_type";
- case DW_TAG_entry_point: return "DW_TAG_entry_point";
- case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
- case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
- case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
- case DW_TAG_label: return "DW_TAG_label";
- case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
- case DW_TAG_member: return "DW_TAG_member";
- case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
- case DW_TAG_reference_type: return "DW_TAG_reference_type";
- case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
- case DW_TAG_string_type: return "DW_TAG_string_type";
- case DW_TAG_structure_type: return "DW_TAG_structure_type";
- case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
- case DW_TAG_typedef: return "DW_TAG_typedef";
- case DW_TAG_union_type: return "DW_TAG_union_type";
- case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
- case DW_TAG_variant: return "DW_TAG_variant";
- case DW_TAG_common_block: return "DW_TAG_common_block";
- case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
- case DW_TAG_inheritance: return "DW_TAG_inheritance";
- case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
- case DW_TAG_module: return "DW_TAG_module";
- case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
- case DW_TAG_set_type: return "DW_TAG_set_type";
- case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
- case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
- case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
- case DW_TAG_base_type: return "DW_TAG_base_type";
- case DW_TAG_catch_block: return "DW_TAG_catch_block";
- case DW_TAG_const_type: return "DW_TAG_const_type";
- case DW_TAG_constant: return "DW_TAG_constant";
- case DW_TAG_enumerator: return "DW_TAG_enumerator";
- case DW_TAG_file_type: return "DW_TAG_file_type";
- case DW_TAG_friend: return "DW_TAG_friend";
- case DW_TAG_namelist: return "DW_TAG_namelist";
- case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
- case DW_TAG_packed_type: return "DW_TAG_packed_type";
- case DW_TAG_subprogram: return "DW_TAG_subprogram";
- case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
- case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
- case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
- case DW_TAG_try_block: return "DW_TAG_try_block";
- case DW_TAG_variant_part: return "DW_TAG_variant_part";
- case DW_TAG_variable: return "DW_TAG_variable";
- case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
- case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
- case DW_TAG_format_label: return "DW_TAG_format_label";
- case DW_TAG_function_template: return "DW_TAG_function_template";
- case DW_TAG_class_template: return "DW_TAG_class_template";
- /* DWARF 2.1 values. */
- case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
- case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
- case DW_TAG_interface_type: return "DW_TAG_interface_type";
- case DW_TAG_namespace: return "DW_TAG_namespace";
- case DW_TAG_imported_module: return "DW_TAG_imported_module";
- case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
- case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
- case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
- /* UPC values. */
- case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
- case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
- case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
- default:
- {
- static char buffer[100];
-
- snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
- return buffer;
- }
- }
-}
-
-static char *
-get_FORM_name (unsigned long form)
-{
- switch (form)
- {
- case DW_FORM_addr: return "DW_FORM_addr";
- case DW_FORM_block2: return "DW_FORM_block2";
- case DW_FORM_block4: return "DW_FORM_block4";
- case DW_FORM_data2: return "DW_FORM_data2";
- case DW_FORM_data4: return "DW_FORM_data4";
- case DW_FORM_data8: return "DW_FORM_data8";
- case DW_FORM_string: return "DW_FORM_string";
- case DW_FORM_block: return "DW_FORM_block";
- case DW_FORM_block1: return "DW_FORM_block1";
- case DW_FORM_data1: return "DW_FORM_data1";
- case DW_FORM_flag: return "DW_FORM_flag";
- case DW_FORM_sdata: return "DW_FORM_sdata";
- case DW_FORM_strp: return "DW_FORM_strp";
- case DW_FORM_udata: return "DW_FORM_udata";
- case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
- case DW_FORM_ref1: return "DW_FORM_ref1";
- case DW_FORM_ref2: return "DW_FORM_ref2";
- case DW_FORM_ref4: return "DW_FORM_ref4";
- case DW_FORM_ref8: return "DW_FORM_ref8";
- case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
- case DW_FORM_indirect: return "DW_FORM_indirect";
- default:
- {
- static char buffer[100];
-
- snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
- return buffer;
- }
- }
-}
-
-static unsigned char *
-display_block (unsigned char *data, unsigned long length)
-{
- printf (_(" %lu byte block: "), length);
-
- while (length --)
- printf ("%lx ", (unsigned long) byte_get (data++, 1));
-
- return data;
-}
-
-static int
-decode_location_expression (unsigned char * data,
- unsigned int pointer_size,
- unsigned long length,
- unsigned long cu_offset)
-{
- unsigned op;
- unsigned int bytes_read;
- unsigned long uvalue;
- unsigned char *end = data + length;
- int need_frame_base = 0;
-
- while (data < end)
- {
- op = *data++;
-
- switch (op)
- {
- case DW_OP_addr:
- printf ("DW_OP_addr: %lx",
- (unsigned long) byte_get (data, pointer_size));
- data += pointer_size;
- break;
- case DW_OP_deref:
- printf ("DW_OP_deref");
- break;
- case DW_OP_const1u:
- printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
- break;
- case DW_OP_const1s:
- printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
- break;
- case DW_OP_const2u:
- printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
- data += 2;
- break;
- case DW_OP_const2s:
- printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
- data += 2;
- break;
- case DW_OP_const4u:
- printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
- data += 4;
- break;
- case DW_OP_const4s:
- printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
- data += 4;
- break;
- case DW_OP_const8u:
- printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
- (unsigned long) byte_get (data + 4, 4));
- data += 8;
- break;
- case DW_OP_const8s:
- printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
- (long) byte_get (data + 4, 4));
- data += 8;
- break;
- case DW_OP_constu:
- printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- break;
- case DW_OP_consts:
- printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
- data += bytes_read;
- break;
- case DW_OP_dup:
- printf ("DW_OP_dup");
- break;
- case DW_OP_drop:
- printf ("DW_OP_drop");
- break;
- case DW_OP_over:
- printf ("DW_OP_over");
- break;
- case DW_OP_pick:
- printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
- break;
- case DW_OP_swap:
- printf ("DW_OP_swap");
- break;
- case DW_OP_rot:
- printf ("DW_OP_rot");
- break;
- case DW_OP_xderef:
- printf ("DW_OP_xderef");
- break;
- case DW_OP_abs:
- printf ("DW_OP_abs");
- break;
- case DW_OP_and:
- printf ("DW_OP_and");
- break;
- case DW_OP_div:
- printf ("DW_OP_div");
- break;
- case DW_OP_minus:
- printf ("DW_OP_minus");
- break;
- case DW_OP_mod:
- printf ("DW_OP_mod");
- break;
- case DW_OP_mul:
- printf ("DW_OP_mul");
- break;
- case DW_OP_neg:
- printf ("DW_OP_neg");
- break;
- case DW_OP_not:
- printf ("DW_OP_not");
- break;
- case DW_OP_or:
- printf ("DW_OP_or");
- break;
- case DW_OP_plus:
- printf ("DW_OP_plus");
- break;
- case DW_OP_plus_uconst:
- printf ("DW_OP_plus_uconst: %lu",
- read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- break;
- case DW_OP_shl:
- printf ("DW_OP_shl");
- break;
- case DW_OP_shr:
- printf ("DW_OP_shr");
- break;
- case DW_OP_shra:
- printf ("DW_OP_shra");
- break;
- case DW_OP_xor:
- printf ("DW_OP_xor");
- break;
- case DW_OP_bra:
- printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
- data += 2;
- break;
- case DW_OP_eq:
- printf ("DW_OP_eq");
- break;
- case DW_OP_ge:
- printf ("DW_OP_ge");
- break;
- case DW_OP_gt:
- printf ("DW_OP_gt");
- break;
- case DW_OP_le:
- printf ("DW_OP_le");
- break;
- case DW_OP_lt:
- printf ("DW_OP_lt");
- break;
- case DW_OP_ne:
- printf ("DW_OP_ne");
- break;
- case DW_OP_skip:
- printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
- data += 2;
- break;
-
- case DW_OP_lit0:
- case DW_OP_lit1:
- case DW_OP_lit2:
- case DW_OP_lit3:
- case DW_OP_lit4:
- case DW_OP_lit5:
- case DW_OP_lit6:
- case DW_OP_lit7:
- case DW_OP_lit8:
- case DW_OP_lit9:
- case DW_OP_lit10:
- case DW_OP_lit11:
- case DW_OP_lit12:
- case DW_OP_lit13:
- case DW_OP_lit14:
- case DW_OP_lit15:
- case DW_OP_lit16:
- case DW_OP_lit17:
- case DW_OP_lit18:
- case DW_OP_lit19:
- case DW_OP_lit20:
- case DW_OP_lit21:
- case DW_OP_lit22:
- case DW_OP_lit23:
- case DW_OP_lit24:
- case DW_OP_lit25:
- case DW_OP_lit26:
- case DW_OP_lit27:
- case DW_OP_lit28:
- case DW_OP_lit29:
- case DW_OP_lit30:
- case DW_OP_lit31:
- printf ("DW_OP_lit%d", op - DW_OP_lit0);
- break;
-
- case DW_OP_reg0:
- case DW_OP_reg1:
- case DW_OP_reg2:
- case DW_OP_reg3:
- case DW_OP_reg4:
- case DW_OP_reg5:
- case DW_OP_reg6:
- case DW_OP_reg7:
- case DW_OP_reg8:
- case DW_OP_reg9:
- case DW_OP_reg10:
- case DW_OP_reg11:
- case DW_OP_reg12:
- case DW_OP_reg13:
- case DW_OP_reg14:
- case DW_OP_reg15:
- case DW_OP_reg16:
- case DW_OP_reg17:
- case DW_OP_reg18:
- case DW_OP_reg19:
- case DW_OP_reg20:
- case DW_OP_reg21:
- case DW_OP_reg22:
- case DW_OP_reg23:
- case DW_OP_reg24:
- case DW_OP_reg25:
- case DW_OP_reg26:
- case DW_OP_reg27:
- case DW_OP_reg28:
- case DW_OP_reg29:
- case DW_OP_reg30:
- case DW_OP_reg31:
- printf ("DW_OP_reg%d", op - DW_OP_reg0);
- break;
-
- case DW_OP_breg0:
- case DW_OP_breg1:
- case DW_OP_breg2:
- case DW_OP_breg3:
- case DW_OP_breg4:
- case DW_OP_breg5:
- case DW_OP_breg6:
- case DW_OP_breg7:
- case DW_OP_breg8:
- case DW_OP_breg9:
- case DW_OP_breg10:
- case DW_OP_breg11:
- case DW_OP_breg12:
- case DW_OP_breg13:
- case DW_OP_breg14:
- case DW_OP_breg15:
- case DW_OP_breg16:
- case DW_OP_breg17:
- case DW_OP_breg18:
- case DW_OP_breg19:
- case DW_OP_breg20:
- case DW_OP_breg21:
- case DW_OP_breg22:
- case DW_OP_breg23:
- case DW_OP_breg24:
- case DW_OP_breg25:
- case DW_OP_breg26:
- case DW_OP_breg27:
- case DW_OP_breg28:
- case DW_OP_breg29:
- case DW_OP_breg30:
- case DW_OP_breg31:
- printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
- read_leb128 (data, &bytes_read, 1));
- data += bytes_read;
- break;
-
- case DW_OP_regx:
- printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- break;
- case DW_OP_fbreg:
- need_frame_base = 1;
- printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
- data += bytes_read;
- break;
- case DW_OP_bregx:
- uvalue = read_leb128 (data, &bytes_read, 0);
- data += bytes_read;
- printf ("DW_OP_bregx: %lu %ld", uvalue,
- read_leb128 (data, &bytes_read, 1));
- data += bytes_read;
- break;
- case DW_OP_piece:
- printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- break;
- case DW_OP_deref_size:
- printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
- break;
- case DW_OP_xderef_size:
- printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
- break;
- case DW_OP_nop:
- printf ("DW_OP_nop");
- break;
-
- /* DWARF 3 extensions. */
- case DW_OP_push_object_address:
- printf ("DW_OP_push_object_address");
- break;
- case DW_OP_call2:
- /* XXX: Strictly speaking for 64-bit DWARF3 files
- this ought to be an 8-byte wide computation. */
- printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
- data += 2;
- break;
- case DW_OP_call4:
- /* XXX: Strictly speaking for 64-bit DWARF3 files
- this ought to be an 8-byte wide computation. */
- printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
- data += 4;
- break;
- case DW_OP_call_ref:
- /* XXX: Strictly speaking for 64-bit DWARF3 files
- this ought to be an 8-byte wide computation. */
- printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset);
- data += 4;
- break;
- case DW_OP_form_tls_address:
- printf ("DW_OP_form_tls_address");
- break;
- case DW_OP_call_frame_cfa:
- printf ("DW_OP_call_frame_cfa");
- break;
- case DW_OP_bit_piece:
- printf ("DW_OP_bit_piece: ");
- printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
- data += bytes_read;
- break;
-
- /* GNU extensions. */
- case DW_OP_GNU_push_tls_address:
- printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
- break;
- case DW_OP_GNU_uninit:
- printf ("DW_OP_GNU_uninit");
- /* FIXME: Is there data associated with this OP ? */
- break;
-
- /* HP extensions. */
- case DW_OP_HP_is_value:
- printf ("DW_OP_HP_is_value");
- /* FIXME: Is there data associated with this OP ? */
- break;
- case DW_OP_HP_fltconst4:
- printf ("DW_OP_HP_fltconst4");
- /* FIXME: Is there data associated with this OP ? */
- break;
- case DW_OP_HP_fltconst8:
- printf ("DW_OP_HP_fltconst8");
- /* FIXME: Is there data associated with this OP ? */
- break;
- case DW_OP_HP_mod_range:
- printf ("DW_OP_HP_mod_range");
- /* FIXME: Is there data associated with this OP ? */
- break;
- case DW_OP_HP_unmod_range:
- printf ("DW_OP_HP_unmod_range");
- /* FIXME: Is there data associated with this OP ? */
- break;
- case DW_OP_HP_tls:
- printf ("DW_OP_HP_tls");
- /* FIXME: Is there data associated with this OP ? */
- break;
-
- /* PGI (STMicroelectronics) extensions. */
- case DW_OP_PGI_omp_thread_num:
- /* Pushes the thread number for the current thread as it would be
- returned by the standard OpenMP library function:
- omp_get_thread_num(). The "current thread" is the thread for
- which the expression is being evaluated. */
- printf ("DW_OP_PGI_omp_thread_num");
- break;
-
- default:
- if (op >= DW_OP_lo_user
- && op <= DW_OP_hi_user)
- printf (_("(User defined location op)"));
- else
- printf (_("(Unknown location op)"));
- /* No way to tell where the next op is, so just bail. */
- return need_frame_base;
- }
-
- /* Separate the ops. */
- if (data < end)
- printf ("; ");
- }
-
- return need_frame_base;
-}
-
-static unsigned char *
-read_and_display_attr_value (unsigned long attribute,
- unsigned long form,
- unsigned char * data,
- unsigned long cu_offset,
- unsigned long pointer_size,
- unsigned long offset_size,
- int dwarf_version,
- debug_info * debug_info_p,
- int do_loc,
- struct dwarf_section * section)
-{
- unsigned long uvalue = 0;
- unsigned char *block_start = NULL;
- unsigned char * orig_data = data;
- unsigned int bytes_read;
-
- switch (form)
- {
- default:
- break;
-
- case DW_FORM_ref_addr:
- if (dwarf_version == 2)
- {
- uvalue = byte_get (data, pointer_size);
- data += pointer_size;
- }
- else if (dwarf_version == 3)
- {
- uvalue = byte_get (data, offset_size);
- data += offset_size;
- }
- else
- {
- error (_("Internal error: DWARF version is not 2 or 3.\n"));
- }
- break;
-
- case DW_FORM_addr:
- uvalue = byte_get (data, pointer_size);
- data += pointer_size;
- break;
-
- case DW_FORM_strp:
- uvalue = byte_get (data, offset_size);
- data += offset_size;
- break;
-
- case DW_FORM_ref1:
- case DW_FORM_flag:
- case DW_FORM_data1:
- uvalue = byte_get (data++, 1);
- break;
-
- case DW_FORM_ref2:
- case DW_FORM_data2:
- uvalue = byte_get (data, 2);
- data += 2;
- break;
-
- case DW_FORM_ref4:
- case DW_FORM_data4:
- uvalue = byte_get (data, 4);
- data += 4;
- break;
-
- case DW_FORM_sdata:
- uvalue = read_leb128 (data, & bytes_read, 1);
- data += bytes_read;
- break;
-
- case DW_FORM_ref_udata:
- case DW_FORM_udata:
- uvalue = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- break;
-
- case DW_FORM_indirect:
- form = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- if (!do_loc)
- printf (" %s", get_FORM_name (form));
- return read_and_display_attr_value (attribute, form, data,
- cu_offset, pointer_size,
- offset_size, dwarf_version,
- debug_info_p, do_loc,
- section);
- }
-
- switch (form)
- {
- case DW_FORM_ref_addr:
- if (!do_loc)
- printf (" <0x%lx>", uvalue);
- break;
-
- case DW_FORM_ref1:
- case DW_FORM_ref2:
- case DW_FORM_ref4:
- case DW_FORM_ref_udata:
- if (!do_loc)
- printf (" <0x%lx>", uvalue + cu_offset);
- break;
-
- case DW_FORM_data4:
- case DW_FORM_addr:
- if (!do_loc)
- printf (" 0x%lx", uvalue);
- break;
-
- case DW_FORM_flag:
- case DW_FORM_data1:
- case DW_FORM_data2:
- case DW_FORM_sdata:
- case DW_FORM_udata:
- if (!do_loc)
- printf (" %ld", uvalue);
- break;
-
- case DW_FORM_ref8:
- case DW_FORM_data8:
- if (!do_loc)
- {
- uvalue = byte_get (data, 4);
- printf (" 0x%lx", uvalue);
- printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
- }
- if ((do_loc || do_debug_loc || do_debug_ranges)
- && num_debug_info_entries == 0)
- {
- if (sizeof (uvalue) == 8)
- uvalue = byte_get (data, 8);
- else
- error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
- }
- data += 8;
- break;
-
- case DW_FORM_string:
- if (!do_loc)
- printf (" %s", data);
- data += strlen ((char *) data) + 1;
- break;
-
- case DW_FORM_block:
- uvalue = read_leb128 (data, & bytes_read, 0);
- block_start = data + bytes_read;
- if (do_loc)
- data = block_start + uvalue;
- else
- data = display_block (block_start, uvalue);
- break;
-
- case DW_FORM_block1:
- uvalue = byte_get (data, 1);
- block_start = data + 1;
- if (do_loc)
- data = block_start + uvalue;
- else
- data = display_block (block_start, uvalue);
- break;
-
- case DW_FORM_block2:
- uvalue = byte_get (data, 2);
- block_start = data + 2;
- if (do_loc)
- data = block_start + uvalue;
- else
- data = display_block (block_start, uvalue);
- break;
-
- case DW_FORM_block4:
- uvalue = byte_get (data, 4);
- block_start = data + 4;
- if (do_loc)
- data = block_start + uvalue;
- else
- data = display_block (block_start, uvalue);
- break;
-
- case DW_FORM_strp:
- if (!do_loc)
- printf (_(" (indirect string, offset: 0x%lx): %s"),
- uvalue, fetch_indirect_string (uvalue));
- break;
-
- case DW_FORM_indirect:
- /* Handled above. */
- break;
-
- default:
- warn (_("Unrecognized form: %lu\n"), form);
- break;
- }
-
- if ((do_loc || do_debug_loc || do_debug_ranges)
- && num_debug_info_entries == 0)
- {
- switch (attribute)
- {
- case DW_AT_frame_base:
- have_frame_base = 1;
- case DW_AT_location:
- case DW_AT_string_length:
- case DW_AT_return_addr:
- case DW_AT_data_member_location:
- case DW_AT_vtable_elem_location:
- case DW_AT_segment:
- case DW_AT_static_link:
- case DW_AT_use_location:
- if (form == DW_FORM_data4 || form == DW_FORM_data8)
- {
- /* Process location list. */
- unsigned int max = debug_info_p->max_loc_offsets;
- unsigned int num = debug_info_p->num_loc_offsets;
-
- if (max == 0 || num >= max)
- {
- max += 1024;
- debug_info_p->loc_offsets
- = xcrealloc (debug_info_p->loc_offsets,
- max, sizeof (*debug_info_p->loc_offsets));
- debug_info_p->have_frame_base
- = xcrealloc (debug_info_p->have_frame_base,
- max, sizeof (*debug_info_p->have_frame_base));
- debug_info_p->max_loc_offsets = max;
- }
- debug_info_p->loc_offsets [num] = uvalue;
- debug_info_p->have_frame_base [num] = have_frame_base;
- debug_info_p->num_loc_offsets++;
- }
- break;
-
- case DW_AT_low_pc:
- if (need_base_address)
- debug_info_p->base_address = uvalue;
- break;
-
- case DW_AT_ranges:
- if (form == DW_FORM_data4 || form == DW_FORM_data8)
- {
- /* Process range list. */
- unsigned int max = debug_info_p->max_range_lists;
- unsigned int num = debug_info_p->num_range_lists;
-
- if (max == 0 || num >= max)
- {
- max += 1024;
- debug_info_p->range_lists
- = xcrealloc (debug_info_p->range_lists,
- max, sizeof (*debug_info_p->range_lists));
- debug_info_p->max_range_lists = max;
- }
- debug_info_p->range_lists [num] = uvalue;
- debug_info_p->num_range_lists++;
- }
- break;
-
- default:
- break;
- }
- }
-
- if (do_loc)
- return data;
-
- /* For some attributes we can display further information. */
- printf ("\t");
-
- switch (attribute)
- {
- case DW_AT_inline:
- switch (uvalue)
- {
- case DW_INL_not_inlined:
- printf (_("(not inlined)"));
- break;
- case DW_INL_inlined:
- printf (_("(inlined)"));
- break;
- case DW_INL_declared_not_inlined:
- printf (_("(declared as inline but ignored)"));
- break;
- case DW_INL_declared_inlined:
- printf (_("(declared as inline and inlined)"));
- break;
- default:
- printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
- break;
- }
- break;
-
- case DW_AT_language:
- switch (uvalue)
- {
- /* Ordered by the numeric value of these constants. */
- case DW_LANG_C89: printf ("(ANSI C)"); break;
- case DW_LANG_C: printf ("(non-ANSI C)"); break;
- case DW_LANG_Ada83: printf ("(Ada)"); break;
- case DW_LANG_C_plus_plus: printf ("(C++)"); break;
- case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
- case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
- case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
- case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
- case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
- case DW_LANG_Modula2: printf ("(Modula 2)"); break;
- /* DWARF 2.1 values. */
- case DW_LANG_Java: printf ("(Java)"); break;
- case DW_LANG_C99: printf ("(ANSI C99)"); break;
- case DW_LANG_Ada95: printf ("(ADA 95)"); break;
- case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
- /* DWARF 3 values. */
- case DW_LANG_PLI: printf ("(PLI)"); break;
- case DW_LANG_ObjC: printf ("(Objective C)"); break;
- case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
- case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
- case DW_LANG_D: printf ("(D)"); break;
- /* MIPS extension. */
- case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
- /* UPC extension. */
- case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
- default:
- if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
- printf ("(implementation defined: %lx)", uvalue);
- else
- printf ("(Unknown: %lx)", uvalue);
- break;
- }
- break;
-
- case DW_AT_encoding:
- switch (uvalue)
- {
- case DW_ATE_void: printf ("(void)"); break;
- case DW_ATE_address: printf ("(machine address)"); break;
- case DW_ATE_boolean: printf ("(boolean)"); break;
- case DW_ATE_complex_float: printf ("(complex float)"); break;
- case DW_ATE_float: printf ("(float)"); break;
- case DW_ATE_signed: printf ("(signed)"); break;
- case DW_ATE_signed_char: printf ("(signed char)"); break;
- case DW_ATE_unsigned: printf ("(unsigned)"); break;
- case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
- /* DWARF 2.1 values: */
- case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
- case DW_ATE_decimal_float: printf ("(decimal float)"); break;
- /* DWARF 3 values: */
- case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
- case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
- case DW_ATE_edited: printf ("(edited)"); break;
- case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
- case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
- /* HP extensions: */
- case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
- case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
- case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
- case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
- case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
- case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
- case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
-
- default:
- if (uvalue >= DW_ATE_lo_user
- && uvalue <= DW_ATE_hi_user)
- printf ("(user defined type)");
- else
- printf ("(unknown type)");
- break;
- }
- break;
-
- case DW_AT_accessibility:
- switch (uvalue)
- {
- case DW_ACCESS_public: printf ("(public)"); break;
- case DW_ACCESS_protected: printf ("(protected)"); break;
- case DW_ACCESS_private: printf ("(private)"); break;
- default:
- printf ("(unknown accessibility)");
- break;
- }
- break;
-
- case DW_AT_visibility:
- switch (uvalue)
- {
- case DW_VIS_local: printf ("(local)"); break;
- case DW_VIS_exported: printf ("(exported)"); break;
- case DW_VIS_qualified: printf ("(qualified)"); break;
- default: printf ("(unknown visibility)"); break;
- }
- break;
-
- case DW_AT_virtuality:
- switch (uvalue)
- {
- case DW_VIRTUALITY_none: printf ("(none)"); break;
- case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
- case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
- default: printf ("(unknown virtuality)"); break;
- }
- break;
-
- case DW_AT_identifier_case:
- switch (uvalue)
- {
- case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
- case DW_ID_up_case: printf ("(up_case)"); break;
- case DW_ID_down_case: printf ("(down_case)"); break;
- case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
- default: printf ("(unknown case)"); break;
- }
- break;
-
- case DW_AT_calling_convention:
- switch (uvalue)
- {
- case DW_CC_normal: printf ("(normal)"); break;
- case DW_CC_program: printf ("(program)"); break;
- case DW_CC_nocall: printf ("(nocall)"); break;
- default:
- if (uvalue >= DW_CC_lo_user
- && uvalue <= DW_CC_hi_user)
- printf ("(user defined)");
- else
- printf ("(unknown convention)");
- }
- break;
-
- case DW_AT_ordering:
- switch (uvalue)
- {
- case -1: printf ("(undefined)"); break;
- case 0: printf ("(row major)"); break;
- case 1: printf ("(column major)"); break;
- }
- break;
-
- case DW_AT_frame_base:
- have_frame_base = 1;
- case DW_AT_location:
- case DW_AT_string_length:
- case DW_AT_return_addr:
- case DW_AT_data_member_location:
- case DW_AT_vtable_elem_location:
- case DW_AT_segment:
- case DW_AT_static_link:
- case DW_AT_use_location:
- if (form == DW_FORM_data4 || form == DW_FORM_data8)
- printf (_("(location list)"));
- /* Fall through. */
- case DW_AT_allocated:
- case DW_AT_associated:
- case DW_AT_data_location:
- case DW_AT_stride:
- case DW_AT_upper_bound:
- case DW_AT_lower_bound:
- if (block_start)
- {
- int need_frame_base;
-
- printf ("(");
- need_frame_base = decode_location_expression (block_start,
- pointer_size,
- uvalue,
- cu_offset);
- printf (")");
- if (need_frame_base && !have_frame_base)
- printf (_(" [without DW_AT_frame_base]"));
- }
- break;
-
- case DW_AT_import:
- {
- if (form == DW_FORM_ref1
- || form == DW_FORM_ref2
- || form == DW_FORM_ref4)
- uvalue += cu_offset;
-
- if (uvalue >= section->size)
- warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
- uvalue, (unsigned long) (orig_data - section->start));
- else
- {
- unsigned long abbrev_number;
- abbrev_entry * entry;
-
- abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
-
- printf ("[Abbrev Number: %ld", abbrev_number);
- for (entry = first_abbrev; entry != NULL; entry = entry->next)
- if (entry->entry == abbrev_number)
- break;
- if (entry != NULL)
- printf (" (%s)", get_TAG_name (entry->tag));
- printf ("]");
- }
- }
- break;
-
- default:
- break;
- }
-
- return data;
-}
-
-static char *
-get_AT_name (unsigned long attribute)
-{
- switch (attribute)
- {
- case DW_AT_sibling: return "DW_AT_sibling";
- case DW_AT_location: return "DW_AT_location";
- case DW_AT_name: return "DW_AT_name";
- case DW_AT_ordering: return "DW_AT_ordering";
- case DW_AT_subscr_data: return "DW_AT_subscr_data";
- case DW_AT_byte_size: return "DW_AT_byte_size";
- case DW_AT_bit_offset: return "DW_AT_bit_offset";
- case DW_AT_bit_size: return "DW_AT_bit_size";
- case DW_AT_element_list: return "DW_AT_element_list";
- case DW_AT_stmt_list: return "DW_AT_stmt_list";
- case DW_AT_low_pc: return "DW_AT_low_pc";
- case DW_AT_high_pc: return "DW_AT_high_pc";
- case DW_AT_language: return "DW_AT_language";
- case DW_AT_member: return "DW_AT_member";
- case DW_AT_discr: return "DW_AT_discr";
- case DW_AT_discr_value: return "DW_AT_discr_value";
- case DW_AT_visibility: return "DW_AT_visibility";
- case DW_AT_import: return "DW_AT_import";
- case DW_AT_string_length: return "DW_AT_string_length";
- case DW_AT_common_reference: return "DW_AT_common_reference";
- case DW_AT_comp_dir: return "DW_AT_comp_dir";
- case DW_AT_const_value: return "DW_AT_const_value";
- case DW_AT_containing_type: return "DW_AT_containing_type";
- case DW_AT_default_value: return "DW_AT_default_value";
- case DW_AT_inline: return "DW_AT_inline";
- case DW_AT_is_optional: return "DW_AT_is_optional";
- case DW_AT_lower_bound: return "DW_AT_lower_bound";
- case DW_AT_producer: return "DW_AT_producer";
- case DW_AT_prototyped: return "DW_AT_prototyped";
- case DW_AT_return_addr: return "DW_AT_return_addr";
- case DW_AT_start_scope: return "DW_AT_start_scope";
- case DW_AT_stride_size: return "DW_AT_stride_size";
- case DW_AT_upper_bound: return "DW_AT_upper_bound";
- case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
- case DW_AT_accessibility: return "DW_AT_accessibility";
- case DW_AT_address_class: return "DW_AT_address_class";
- case DW_AT_artificial: return "DW_AT_artificial";
- case DW_AT_base_types: return "DW_AT_base_types";
- case DW_AT_calling_convention: return "DW_AT_calling_convention";
- case DW_AT_count: return "DW_AT_count";
- case DW_AT_data_member_location: return "DW_AT_data_member_location";
- case DW_AT_decl_column: return "DW_AT_decl_column";
- case DW_AT_decl_file: return "DW_AT_decl_file";
- case DW_AT_decl_line: return "DW_AT_decl_line";
- case DW_AT_declaration: return "DW_AT_declaration";
- case DW_AT_discr_list: return "DW_AT_discr_list";
- case DW_AT_encoding: return "DW_AT_encoding";
- case DW_AT_external: return "DW_AT_external";
- case DW_AT_frame_base: return "DW_AT_frame_base";
- case DW_AT_friend: return "DW_AT_friend";
- case DW_AT_identifier_case: return "DW_AT_identifier_case";
- case DW_AT_macro_info: return "DW_AT_macro_info";
- case DW_AT_namelist_items: return "DW_AT_namelist_items";
- case DW_AT_priority: return "DW_AT_priority";
- case DW_AT_segment: return "DW_AT_segment";
- case DW_AT_specification: return "DW_AT_specification";
- case DW_AT_static_link: return "DW_AT_static_link";
- case DW_AT_type: return "DW_AT_type";
- case DW_AT_use_location: return "DW_AT_use_location";
- case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
- case DW_AT_virtuality: return "DW_AT_virtuality";
- case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
- /* DWARF 2.1 values. */
- case DW_AT_allocated: return "DW_AT_allocated";
- case DW_AT_associated: return "DW_AT_associated";
- case DW_AT_data_location: return "DW_AT_data_location";
- case DW_AT_stride: return "DW_AT_stride";
- case DW_AT_entry_pc: return "DW_AT_entry_pc";
- case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
- case DW_AT_extension: return "DW_AT_extension";
- case DW_AT_ranges: return "DW_AT_ranges";
- case DW_AT_trampoline: return "DW_AT_trampoline";
- case DW_AT_call_column: return "DW_AT_call_column";
- case DW_AT_call_file: return "DW_AT_call_file";
- case DW_AT_call_line: return "DW_AT_call_line";
- case DW_AT_description: return "DW_AT_description";
- case DW_AT_binary_scale: return "DW_AT_binary_scale";
- case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
- case DW_AT_small: return "DW_AT_small";
- case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
- case DW_AT_digit_count: return "DW_AT_digit_count";
- case DW_AT_picture_string: return "DW_AT_picture_string";
- case DW_AT_mutable: return "DW_AT_mutable";
- case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
- case DW_AT_explicit: return "DW_AT_explicit";
- case DW_AT_object_pointer: return "DW_AT_object_pointer";
- case DW_AT_endianity: return "DW_AT_endianity";
- case DW_AT_elemental: return "DW_AT_elemental";
- case DW_AT_pure: return "DW_AT_pure";
- case DW_AT_recursive: return "DW_AT_recursive";
-
- /* HP and SGI/MIPS extensions. */
- case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
- case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
- case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
- case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
- case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
- case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
- case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
- case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
- case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
- case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
-
- /* HP Extensions. */
- case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
- case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
- case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
- case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
- case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
- case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
- case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
- case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
- case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
- case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
- case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
- case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
- case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
-
- /* One value is shared by the MIPS and HP extensions: */
- case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
-
- /* GNU extensions. */
- case DW_AT_sf_names: return "DW_AT_sf_names";
- case DW_AT_src_info: return "DW_AT_src_info";
- case DW_AT_mac_info: return "DW_AT_mac_info";
- case DW_AT_src_coords: return "DW_AT_src_coords";
- case DW_AT_body_begin: return "DW_AT_body_begin";
- case DW_AT_body_end: return "DW_AT_body_end";
- case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
-
- /* UPC extension. */
- case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
-
- /* PGI (STMicroelectronics) extensions. */
- case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
- case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
- case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
-
- default:
- {
- static char buffer[100];
-
- snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
- attribute);
- return buffer;
- }
- }
-}
-
-static unsigned char *
-read_and_display_attr (unsigned long attribute,
- unsigned long form,
- unsigned char * data,
- unsigned long cu_offset,
- unsigned long pointer_size,
- unsigned long offset_size,
- int dwarf_version,
- debug_info * debug_info_p,
- int do_loc,
- struct dwarf_section * section)
-{
- if (!do_loc)
- printf (" %-18s:", get_AT_name (attribute));
- data = read_and_display_attr_value (attribute, form, data, cu_offset,
- pointer_size, offset_size,
- dwarf_version, debug_info_p,
- do_loc, section);
- if (!do_loc)
- printf ("\n");
- return data;
-}
-
-
-/* Process the contents of a .debug_info section. If do_loc is non-zero
- then we are scanning for location lists and we do not want to display
- anything to the user. */
-
-static int
-process_debug_info (struct dwarf_section *section,
- void *file,
- int do_loc)
-{
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
- unsigned char *section_begin;
- unsigned int unit;
- unsigned int num_units = 0;
-
- if ((do_loc || do_debug_loc || do_debug_ranges)
- && num_debug_info_entries == 0)
- {
- unsigned long length;
-
- /* First scan the section to get the number of comp units. */
- for (section_begin = start, num_units = 0; section_begin < end;
- num_units ++)
- {
- /* Read the first 4 bytes. For a 32-bit DWARF section, this
- will be the length. For a 64-bit DWARF section, it'll be
- the escape code 0xffffffff followed by an 8 byte length. */
- length = byte_get (section_begin, 4);
-
- if (length == 0xffffffff)
- {
- length = byte_get (section_begin + 4, 8);
- section_begin += length + 12;
- }
- else if (length >= 0xfffffff0 && length < 0xffffffff)
- {
- warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
- return 0;
- }
- else
- section_begin += length + 4;
-
- /* Negative values are illegal, they may even cause infinite
- looping. This can happen if we can't accurately apply
- relocations to an object file. */
- if ((signed long) length <= 0)
- {
- warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
- return 0;
- }
- }
-
- if (num_units == 0)
- {
- error (_("No comp units in %s section ?"), section->name);
- return 0;
- }
-
- /* Then allocate an array to hold the information. */
- debug_information = cmalloc (num_units,
- sizeof (* debug_information));
- if (debug_information == NULL)
- {
- error (_("Not enough memory for a debug info array of %u entries"),
- num_units);
- return 0;
- }
- }
-
- if (!do_loc)
- {
- printf (_("The section %s contains:\n\n"), section->name);
-
- load_debug_section (str, file);
- }
-
- load_debug_section (abbrev, file);
- if (debug_displays [abbrev].section.start == NULL)
- {
- warn (_("Unable to locate %s section!\n"),
- debug_displays [abbrev].section.name);
- return 0;
- }
-
- for (section_begin = start, unit = 0; start < end; unit++)
- {
- DWARF2_Internal_CompUnit compunit;
- unsigned char *hdrptr;
- unsigned char *cu_abbrev_offset_ptr;
- unsigned char *tags;
- int level;
- unsigned long cu_offset;
- int offset_size;
- int initial_length_size;
-
- hdrptr = start;
-
- compunit.cu_length = byte_get (hdrptr, 4);
- hdrptr += 4;
-
- if (compunit.cu_length == 0xffffffff)
- {
- compunit.cu_length = byte_get (hdrptr, 8);
- hdrptr += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- compunit.cu_version = byte_get (hdrptr, 2);
- hdrptr += 2;
-
- cu_offset = start - section_begin;
-
- cu_abbrev_offset_ptr = hdrptr;
- compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
- hdrptr += offset_size;
-
- compunit.cu_pointer_size = byte_get (hdrptr, 1);
- hdrptr += 1;
- if ((do_loc || do_debug_loc || do_debug_ranges)
- && num_debug_info_entries == 0)
- {
- debug_information [unit].cu_offset = cu_offset;
- debug_information [unit].pointer_size
- = compunit.cu_pointer_size;
- debug_information [unit].base_address = 0;
- debug_information [unit].loc_offsets = NULL;
- debug_information [unit].have_frame_base = NULL;
- debug_information [unit].max_loc_offsets = 0;
- debug_information [unit].num_loc_offsets = 0;
- debug_information [unit].range_lists = NULL;
- debug_information [unit].max_range_lists= 0;
- debug_information [unit].num_range_lists = 0;
- }
-
- if (!do_loc)
- {
- printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
- printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length,
- initial_length_size == 8 ? "64-bit" : "32-bit");
- printf (_(" Version: %d\n"), compunit.cu_version);
- printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
- printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
- }
-
- if (cu_offset + compunit.cu_length + initial_length_size
- > section->size)
- {
- warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
- cu_offset, compunit.cu_length);
- break;
- }
- tags = hdrptr;
- start += compunit.cu_length + initial_length_size;
-
- if (compunit.cu_version != 2 && compunit.cu_version != 3)
- {
- warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
- cu_offset, compunit.cu_version);
- continue;
- }
-
- free_abbrevs ();
-
- /* Process the abbrevs used by this compilation unit. DWARF
- sections under Mach-O have non-zero addresses. */
- if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
- warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
- (unsigned long) compunit.cu_abbrev_offset,
- (unsigned long) debug_displays [abbrev].section.size);
- else
- process_abbrev_section
- ((unsigned char *) debug_displays [abbrev].section.start
- + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
- (unsigned char *) debug_displays [abbrev].section.start
- + debug_displays [abbrev].section.size);
-
- level = 0;
- while (tags < start)
- {
- unsigned int bytes_read;
- unsigned long abbrev_number;
- unsigned long die_offset;
- abbrev_entry *entry;
- abbrev_attr *attr;
-
- die_offset = tags - section_begin;
-
- abbrev_number = read_leb128 (tags, & bytes_read, 0);
- tags += bytes_read;
-
- /* A null DIE marks the end of a list of siblings. */
- if (abbrev_number == 0)
- {
- --level;
- if (level < 0)
- {
- static unsigned num_bogus_warns = 0;
-
- if (num_bogus_warns < 3)
- {
- warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
- die_offset);
- num_bogus_warns ++;
- if (num_bogus_warns == 3)
- warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
- }
- }
- continue;
- }
-
- if (!do_loc)
- printf (_(" <%d><%lx>: Abbrev Number: %lu"),
- level, die_offset, abbrev_number);
-
- /* Scan through the abbreviation list until we reach the
- correct entry. */
- for (entry = first_abbrev;
- entry && entry->entry != abbrev_number;
- entry = entry->next)
- continue;
-
- if (entry == NULL)
- {
- if (!do_loc)
- {
- printf ("\n");
- fflush (stdout);
- }
- warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
- die_offset, abbrev_number);
- return 0;
- }
-
- if (!do_loc)
- printf (_(" (%s)\n"), get_TAG_name (entry->tag));
-
- switch (entry->tag)
- {
- default:
- need_base_address = 0;
- break;
- case DW_TAG_compile_unit:
- need_base_address = 1;
- break;
- case DW_TAG_entry_point:
- case DW_TAG_subprogram:
- need_base_address = 0;
- /* Assuming that there is no DW_AT_frame_base. */
- have_frame_base = 0;
- break;
- }
-
- for (attr = entry->first_attr; attr; attr = attr->next)
- {
- if (! do_loc)
- /* Show the offset from where the tag was extracted. */
- printf (" <%2lx>", (unsigned long)(tags - section_begin));
-
- tags = read_and_display_attr (attr->attribute,
- attr->form,
- tags, cu_offset,
- compunit.cu_pointer_size,
- offset_size,
- compunit.cu_version,
- debug_information + unit,
- do_loc, section);
- }
-
- if (entry->children)
- ++level;
- }
- }
-
- /* Set num_debug_info_entries here so that it can be used to check if
- we need to process .debug_loc and .debug_ranges sections. */
- if ((do_loc || do_debug_loc || do_debug_ranges)
- && num_debug_info_entries == 0)
- num_debug_info_entries = num_units;
-
- if (!do_loc)
- {
- printf ("\n");
- }
-
- return 1;
-}
-
-/* Locate and scan the .debug_info section in the file and record the pointer
- sizes and offsets for the compilation units in it. Usually an executable
- will have just one pointer size, but this is not guaranteed, and so we try
- not to make any assumptions. Returns zero upon failure, or the number of
- compilation units upon success. */
-
-static unsigned int
-load_debug_info (void * file)
-{
- /* Reset the last pointer size so that we can issue correct error
- messages if we are displaying the contents of more than one section. */
- last_pointer_size = 0;
- warned_about_missing_comp_units = FALSE;
-
- /* If we have already tried and failed to load the .debug_info
- section then do not bother to repear the task. */
- if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
- return 0;
-
- /* If we already have the information there is nothing else to do. */
- if (num_debug_info_entries > 0)
- return num_debug_info_entries;
-
- if (load_debug_section (info, file)
- && process_debug_info (&debug_displays [info].section, file, 1))
- return num_debug_info_entries;
-
- num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
- return 0;
-}
-
-static int
-display_debug_lines_raw (struct dwarf_section *section,
- unsigned char *data,
- unsigned char *end)
-{
- unsigned char *start = section->start;
-
- printf (_("Raw dump of debug contents of section %s:\n\n"),
- section->name);
-
- while (data < end)
- {
- DWARF2_Internal_LineInfo info;
- unsigned char *standard_opcodes;
- unsigned char *end_of_sequence;
- unsigned char *hdrptr;
- unsigned long hdroff;
- int initial_length_size;
- int offset_size;
- int i;
-
- hdrptr = data;
- hdroff = hdrptr - start;
-
- /* Check the length of the block. */
- info.li_length = byte_get (hdrptr, 4);
- hdrptr += 4;
-
- if (info.li_length == 0xffffffff)
- {
- /* This section is 64-bit DWARF 3. */
- info.li_length = byte_get (hdrptr, 8);
- hdrptr += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- if (info.li_length + initial_length_size > section->size)
- {
- warn
- (_("The line info appears to be corrupt - the section is too small\n"));
- return 0;
- }
-
- /* Check its version number. */
- info.li_version = byte_get (hdrptr, 2);
- hdrptr += 2;
- if (info.li_version != 2 && info.li_version != 3)
- {
- warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
- return 0;
- }
-
- info.li_prologue_length = byte_get (hdrptr, offset_size);
- hdrptr += offset_size;
- info.li_min_insn_length = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_default_is_stmt = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_line_base = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_line_range = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_opcode_base = byte_get (hdrptr, 1);
- hdrptr++;
-
- /* Sign extend the line base field. */
- info.li_line_base <<= 24;
- info.li_line_base >>= 24;
-
- printf (_(" Offset: 0x%lx\n"), hdroff);
- printf (_(" Length: %ld\n"), info.li_length);
- printf (_(" DWARF Version: %d\n"), info.li_version);
- printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
- printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
- printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
- printf (_(" Line Base: %d\n"), info.li_line_base);
- printf (_(" Line Range: %d\n"), info.li_line_range);
- printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
-
- end_of_sequence = data + info.li_length + initial_length_size;
-
- reset_state_machine (info.li_default_is_stmt);
-
- /* Display the contents of the Opcodes table. */
- standard_opcodes = hdrptr;
-
- printf (_("\n Opcodes:\n"));
-
- for (i = 1; i < info.li_opcode_base; i++)
- printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
-
- /* Display the contents of the Directory table. */
- data = standard_opcodes + info.li_opcode_base - 1;
-
- if (*data == 0)
- printf (_("\n The Directory Table is empty.\n"));
- else
- {
- printf (_("\n The Directory Table:\n"));
-
- while (*data != 0)
- {
- printf (_(" %s\n"), data);
-
- data += strlen ((char *) data) + 1;
- }
- }
-
- /* Skip the NUL at the end of the table. */
- data++;
-
- /* Display the contents of the File Name table. */
- if (*data == 0)
- printf (_("\n The File Name Table is empty.\n"));
- else
- {
- printf (_("\n The File Name Table:\n"));
- printf (_(" Entry\tDir\tTime\tSize\tName\n"));
-
- while (*data != 0)
- {
- unsigned char *name;
- unsigned int bytes_read;
-
- printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
- name = data;
-
- data += strlen ((char *) data) + 1;
-
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- data += bytes_read;
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- data += bytes_read;
- printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
- data += bytes_read;
- printf (_("%s\n"), name);
- }
- }
-
- /* Skip the NUL at the end of the table. */
- data++;
-
- /* Now display the statements. */
- printf (_("\n Line Number Statements:\n"));
-
- while (data < end_of_sequence)
- {
- unsigned char op_code;
- int adv;
- unsigned long int uladv;
- unsigned int bytes_read;
-
- op_code = *data++;
-
- if (op_code >= info.li_opcode_base)
- {
- op_code -= info.li_opcode_base;
- uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
- state_machine_regs.address += uladv;
- printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
- op_code, uladv, state_machine_regs.address);
- adv = (op_code % info.li_line_range) + info.li_line_base;
- state_machine_regs.line += adv;
- printf (_(" and Line by %d to %d\n"),
- adv, state_machine_regs.line);
- }
- else switch (op_code)
- {
- case DW_LNS_extended_op:
- data += process_extended_line_op (data, info.li_default_is_stmt);
- break;
-
- case DW_LNS_copy:
- printf (_(" Copy\n"));
- break;
-
- case DW_LNS_advance_pc:
- uladv = read_leb128 (data, & bytes_read, 0);
- uladv *= info.li_min_insn_length;
- data += bytes_read;
- state_machine_regs.address += uladv;
- printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
- state_machine_regs.address);
- break;
-
- case DW_LNS_advance_line:
- adv = read_leb128 (data, & bytes_read, 1);
- data += bytes_read;
- state_machine_regs.line += adv;
- printf (_(" Advance Line by %d to %d\n"), adv,
- state_machine_regs.line);
- break;
-
- case DW_LNS_set_file:
- adv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- printf (_(" Set File Name to entry %d in the File Name Table\n"),
- adv);
- state_machine_regs.file = adv;
- break;
-
- case DW_LNS_set_column:
- uladv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- printf (_(" Set column to %lu\n"), uladv);
- state_machine_regs.column = uladv;
- break;
-
- case DW_LNS_negate_stmt:
- adv = state_machine_regs.is_stmt;
- adv = ! adv;
- printf (_(" Set is_stmt to %d\n"), adv);
- state_machine_regs.is_stmt = adv;
- break;
-
- case DW_LNS_set_basic_block:
- printf (_(" Set basic block\n"));
- state_machine_regs.basic_block = 1;
- break;
-
- case DW_LNS_const_add_pc:
- uladv = (((255 - info.li_opcode_base) / info.li_line_range)
- * info.li_min_insn_length);
- state_machine_regs.address += uladv;
- printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
- state_machine_regs.address);
- break;
-
- case DW_LNS_fixed_advance_pc:
- uladv = byte_get (data, 2);
- data += 2;
- state_machine_regs.address += uladv;
- printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
- uladv, state_machine_regs.address);
- break;
-
- case DW_LNS_set_prologue_end:
- printf (_(" Set prologue_end to true\n"));
- break;
-
- case DW_LNS_set_epilogue_begin:
- printf (_(" Set epilogue_begin to true\n"));
- break;
-
- case DW_LNS_set_isa:
- uladv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- printf (_(" Set ISA to %lu\n"), uladv);
- break;
-
- default:
- printf (_(" Unknown opcode %d with operands: "), op_code);
-
- for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
- {
- printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
- i == 1 ? "" : ", ");
- data += bytes_read;
- }
- putchar ('\n');
- break;
- }
- }
- putchar ('\n');
- }
-
- return 1;
-}
-
-typedef struct
-{
- unsigned char *name;
- unsigned int directory_index;
- unsigned int modification_date;
- unsigned int length;
-} File_Entry;
-
-/* Output a decoded representation of the .debug_line section. */
-
-static int
-display_debug_lines_decoded (struct dwarf_section *section,
- unsigned char *data,
- unsigned char *end)
-{
- printf (_("Decoded dump of debug contents of section %s:\n\n"),
- section->name);
-
- while (data < end)
- {
- /* This loop amounts to one iteration per compilation unit. */
- DWARF2_Internal_LineInfo info;
- unsigned char *standard_opcodes;
- unsigned char *end_of_sequence;
- unsigned char *hdrptr;
- int initial_length_size;
- int offset_size;
- int i;
- File_Entry *file_table = NULL;
- unsigned char **directory_table = NULL;
- unsigned int prev_line = 0;
-
- hdrptr = data;
-
- /* Extract information from the Line Number Program Header.
- (section 6.2.4 in the Dwarf3 doc). */
-
- /* Get the length of this CU's line number information block. */
- info.li_length = byte_get (hdrptr, 4);
- hdrptr += 4;
-
- if (info.li_length == 0xffffffff)
- {
- /* This section is 64-bit DWARF 3. */
- info.li_length = byte_get (hdrptr, 8);
- hdrptr += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- if (info.li_length + initial_length_size > section->size)
- {
- warn (_("The line info appears to be corrupt - "
- "the section is too small\n"));
- return 0;
- }
-
- /* Get this CU's Line Number Block version number. */
- info.li_version = byte_get (hdrptr, 2);
- hdrptr += 2;
- if (info.li_version != 2 && info.li_version != 3)
- {
- warn (_("Only DWARF version 2 and 3 line info is currently "
- "supported.\n"));
- return 0;
- }
-
- info.li_prologue_length = byte_get (hdrptr, offset_size);
- hdrptr += offset_size;
- info.li_min_insn_length = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_default_is_stmt = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_line_base = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_line_range = byte_get (hdrptr, 1);
- hdrptr++;
- info.li_opcode_base = byte_get (hdrptr, 1);
- hdrptr++;
-
- /* Sign extend the line base field. */
- info.li_line_base <<= 24;
- info.li_line_base >>= 24;
-
- /* Find the end of this CU's Line Number Information Block. */
- end_of_sequence = data + info.li_length + initial_length_size;
-
- reset_state_machine (info.li_default_is_stmt);
-
- /* Save a pointer to the contents of the Opcodes table. */
- standard_opcodes = hdrptr;
-
- /* Traverse the Directory table just to count entries. */
- data = standard_opcodes + info.li_opcode_base - 1;
- if (*data != 0)
- {
- unsigned int n_directories = 0;
- unsigned char *ptr_directory_table = data;
- int i;
-
- while (*data != 0)
- {
- data += strlen ((char *) data) + 1;
- n_directories++;
- }
-
- /* Go through the directory table again to save the directories. */
- directory_table = xmalloc (n_directories * sizeof (unsigned char *));
-
- i = 0;
- while (*ptr_directory_table != 0)
- {
- directory_table[i] = ptr_directory_table;
- ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
- i++;
- }
- }
- /* Skip the NUL at the end of the table. */
- data++;
-
- /* Traverse the File Name table just to count the entries. */
- if (*data != 0)
- {
- unsigned int n_files = 0;
- unsigned char *ptr_file_name_table = data;
- int i;
-
- while (*data != 0)
- {
- unsigned int bytes_read;
-
- /* Skip Name, directory index, last modification time and length
- of file. */
- data += strlen ((char *) data) + 1;
- read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
-
- n_files++;
- }
-
- /* Go through the file table again to save the strings. */
- file_table = xmalloc (n_files * sizeof (File_Entry));
-
- i = 0;
- while (*ptr_file_name_table != 0)
- {
- unsigned int bytes_read;
-
- file_table[i].name = ptr_file_name_table;
- ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
-
- /* We are not interested in directory, time or size. */
- file_table[i].directory_index = read_leb128 (ptr_file_name_table,
- & bytes_read, 0);
- ptr_file_name_table += bytes_read;
- file_table[i].modification_date = read_leb128 (ptr_file_name_table,
- & bytes_read, 0);
- ptr_file_name_table += bytes_read;
- file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
- ptr_file_name_table += bytes_read;
- i++;
- }
- i = 0;
-
- /* Print the Compilation Unit's name and a header. */
- if (directory_table == NULL)
- {
- printf (_("CU: %s:\n"), file_table[0].name);
- printf (_("File name Line number Starting address\n"));
- }
- else
- {
- if (do_wide || strlen ((char *) directory_table[0]) < 76)
- {
- printf (_("CU: %s/%s:\n"), directory_table[0],
- file_table[0].name);
- }
- else
- {
- printf (_("%s:\n"), file_table[0].name);
- }
- printf (_("File name Line number Starting address\n"));
- }
- }
-
- /* Skip the NUL at the end of the table. */
- data++;
-
- /* This loop iterates through the Dwarf Line Number Program. */
- while (data < end_of_sequence)
- {
- unsigned char op_code;
- int adv;
- unsigned long int uladv;
- unsigned int bytes_read;
- int is_special_opcode = 0;
-
- op_code = *data++;
- prev_line = state_machine_regs.line;
-
- if (op_code >= info.li_opcode_base)
- {
- op_code -= info.li_opcode_base;
- uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
- state_machine_regs.address += uladv;
-
- adv = (op_code % info.li_line_range) + info.li_line_base;
- state_machine_regs.line += adv;
- is_special_opcode = 1;
- }
- else switch (op_code)
- {
- case DW_LNS_extended_op:
- {
- unsigned int ext_op_code_len;
- unsigned int bytes_read;
- unsigned char ext_op_code;
- unsigned char *op_code_data = data;
-
- ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
- op_code_data += bytes_read;
-
- if (ext_op_code_len == 0)
- {
- warn (_("badly formed extended line op encountered!\n"));
- break;
- }
- ext_op_code_len += bytes_read;
- ext_op_code = *op_code_data++;
-
- switch (ext_op_code)
- {
- case DW_LNE_end_sequence:
- reset_state_machine (info.li_default_is_stmt);
- break;
- case DW_LNE_set_address:
- state_machine_regs.address =
- byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
- break;
- case DW_LNE_define_file:
- {
- unsigned int dir_index = 0;
-
- ++state_machine_regs.last_file_entry;
- op_code_data += strlen ((char *) op_code_data) + 1;
- dir_index = read_leb128 (op_code_data, & bytes_read, 0);
- op_code_data += bytes_read;
- read_leb128 (op_code_data, & bytes_read, 0);
- op_code_data += bytes_read;
- read_leb128 (op_code_data, & bytes_read, 0);
-
- printf (_("%s:\n"), directory_table[dir_index]);
- break;
- }
- default:
- printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
- break;
- }
- data += ext_op_code_len;
- break;
- }
- case DW_LNS_copy:
- break;
-
- case DW_LNS_advance_pc:
- uladv = read_leb128 (data, & bytes_read, 0);
- uladv *= info.li_min_insn_length;
- data += bytes_read;
- state_machine_regs.address += uladv;
- break;
-
- case DW_LNS_advance_line:
- adv = read_leb128 (data, & bytes_read, 1);
- data += bytes_read;
- state_machine_regs.line += adv;
- break;
-
- case DW_LNS_set_file:
- adv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- state_machine_regs.file = adv;
- if (file_table[state_machine_regs.file - 1].directory_index == 0)
- {
- /* If directory index is 0, that means current directory. */
- printf (_("\n./%s:[++]\n"),
- file_table[state_machine_regs.file - 1].name);
- }
- else
- {
- /* The directory index starts counting at 1. */
- printf (_("\n%s/%s:\n"),
- directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
- file_table[state_machine_regs.file - 1].name);
- }
- break;
-
- case DW_LNS_set_column:
- uladv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- state_machine_regs.column = uladv;
- break;
-
- case DW_LNS_negate_stmt:
- adv = state_machine_regs.is_stmt;
- adv = ! adv;
- state_machine_regs.is_stmt = adv;
- break;
-
- case DW_LNS_set_basic_block:
- state_machine_regs.basic_block = 1;
- break;
-
- case DW_LNS_const_add_pc:
- uladv = (((255 - info.li_opcode_base) / info.li_line_range)
- * info.li_min_insn_length);
- state_machine_regs.address += uladv;
- break;
-
- case DW_LNS_fixed_advance_pc:
- uladv = byte_get (data, 2);
- data += 2;
- state_machine_regs.address += uladv;
- break;
-
- case DW_LNS_set_prologue_end:
- break;
-
- case DW_LNS_set_epilogue_begin:
- break;
-
- case DW_LNS_set_isa:
- uladv = read_leb128 (data, & bytes_read, 0);
- data += bytes_read;
- printf (_(" Set ISA to %lu\n"), uladv);
- break;
-
- default:
- printf (_(" Unknown opcode %d with operands: "), op_code);
-
- for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
- {
- printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
- i == 1 ? "" : ", ");
- data += bytes_read;
- }
- putchar ('\n');
- break;
- }
-
- /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
- to the DWARF address/line matrix. */
- if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
- || (op_code == DW_LNS_copy))
- {
- const unsigned int MAX_FILENAME_LENGTH = 35;
- char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
- char *newFileName = NULL;
- size_t fileNameLength = strlen (fileName);
-
- if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
- {
- newFileName = xmalloc (MAX_FILENAME_LENGTH + 1);
- /* Truncate file name */
- strncpy (newFileName,
- fileName + fileNameLength - MAX_FILENAME_LENGTH,
- MAX_FILENAME_LENGTH + 1);
- }
- else
- {
- newFileName = xmalloc (fileNameLength + 1);
- strncpy (newFileName, fileName, fileNameLength + 1);
- }
-
- if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
- {
- printf (_("%-35s %11d %#18lx\n"), newFileName,
- state_machine_regs.line, state_machine_regs.address);
- }
- else
- {
- printf (_("%s %11d %#18lx\n"), newFileName,
- state_machine_regs.line, state_machine_regs.address);
- }
-
- if (op_code == DW_LNE_end_sequence)
- printf ("\n");
-
- free (newFileName);
- }
- }
- free (file_table);
- file_table = NULL;
- free (directory_table);
- directory_table = NULL;
- putchar ('\n');
- }
-
- return 1;
-}
-
-static int
-display_debug_lines (struct dwarf_section *section, void *file)
-{
- unsigned char *data = section->start;
- unsigned char *end = data + section->size;
- int retValRaw = 0;
- int retValDecoded = 0;
-
- if (load_debug_info (file) == 0)
- {
- warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
- section->name);
- return 0;
- }
-
- if (do_debug_lines)
- retValRaw = display_debug_lines_raw (section, data, end);
-
- if (do_debug_lines_decoded)
- retValDecoded = display_debug_lines_decoded (section, data, end);
-
- if ((do_debug_lines && !retValRaw)
- || (do_debug_lines_decoded && !retValDecoded))
- return 0;
-
- return 1;
-}
-
-static debug_info *
-find_debug_info_for_offset (unsigned long offset)
-{
- unsigned int i;
-
- if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
- return NULL;
-
- for (i = 0; i < num_debug_info_entries; i++)
- if (debug_information[i].cu_offset == offset)
- return debug_information + i;
-
- return NULL;
-}
-
-static int
-display_debug_pubnames (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- DWARF2_Internal_PubNames pubnames;
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
-
- /* It does not matter if this load fails,
- we test for that later on. */
- load_debug_info (file);
-
- printf (_("Contents of the %s section:\n\n"), section->name);
-
- while (start < end)
- {
- unsigned char *data;
- unsigned long offset;
- int offset_size, initial_length_size;
-
- data = start;
-
- pubnames.pn_length = byte_get (data, 4);
- data += 4;
- if (pubnames.pn_length == 0xffffffff)
- {
- pubnames.pn_length = byte_get (data, 8);
- data += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- pubnames.pn_version = byte_get (data, 2);
- data += 2;
-
- pubnames.pn_offset = byte_get (data, offset_size);
- data += offset_size;
-
- if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
- && num_debug_info_entries > 0
- && find_debug_info_for_offset (pubnames.pn_offset) == NULL)
- warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
- pubnames.pn_offset, section->name);
-
- pubnames.pn_size = byte_get (data, offset_size);
- data += offset_size;
-
- start += pubnames.pn_length + initial_length_size;
-
- if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
- {
- static int warned = 0;
-
- if (! warned)
- {
- warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
- warned = 1;
- }
-
- continue;
- }
-
- printf (_(" Length: %ld\n"),
- pubnames.pn_length);
- printf (_(" Version: %d\n"),
- pubnames.pn_version);
- printf (_(" Offset into .debug_info section: 0x%lx\n"),
- pubnames.pn_offset);
- printf (_(" Size of area in .debug_info section: %ld\n"),
- pubnames.pn_size);
-
- printf (_("\n Offset\tName\n"));
-
- do
- {
- offset = byte_get (data, offset_size);
-
- if (offset != 0)
- {
- data += offset_size;
- printf (" %-6ld\t\t%s\n", offset, data);
- data += strlen ((char *) data) + 1;
- }
- }
- while (offset != 0);
- }
-
- printf ("\n");
- return 1;
-}
-
-static int
-display_debug_macinfo (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
- unsigned char *curr = start;
- unsigned int bytes_read;
- enum dwarf_macinfo_record_type op;
-
- printf (_("Contents of the %s section:\n\n"), section->name);
-
- while (curr < end)
- {
- unsigned int lineno;
- const char *string;
-
- op = *curr;
- curr++;
-
- switch (op)
- {
- case DW_MACINFO_start_file:
- {
- unsigned int filenum;
-
- lineno = read_leb128 (curr, & bytes_read, 0);
- curr += bytes_read;
- filenum = read_leb128 (curr, & bytes_read, 0);
- curr += bytes_read;
-
- printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
- lineno, filenum);
- }
- break;
-
- case DW_MACINFO_end_file:
- printf (_(" DW_MACINFO_end_file\n"));
- break;
-
- case DW_MACINFO_define:
- lineno = read_leb128 (curr, & bytes_read, 0);
- curr += bytes_read;
- string = (char *) curr;
- curr += strlen (string) + 1;
- printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
- lineno, string);
- break;
-
- case DW_MACINFO_undef:
- lineno = read_leb128 (curr, & bytes_read, 0);
- curr += bytes_read;
- string = (char *) curr;
- curr += strlen (string) + 1;
- printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
- lineno, string);
- break;
-
- case DW_MACINFO_vendor_ext:
- {
- unsigned int constant;
-
- constant = read_leb128 (curr, & bytes_read, 0);
- curr += bytes_read;
- string = (char *) curr;
- curr += strlen (string) + 1;
- printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
- constant, string);
- }
- break;
- }
- }
-
- return 1;
-}
-
-static int
-display_debug_abbrev (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- abbrev_entry *entry;
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
-
- printf (_("Contents of the %s section:\n\n"), section->name);
-
- do
- {
- free_abbrevs ();
-
- start = process_abbrev_section (start, end);
-
- if (first_abbrev == NULL)
- continue;
-
- printf (_(" Number TAG\n"));
-
- for (entry = first_abbrev; entry; entry = entry->next)
- {
- abbrev_attr *attr;
-
- printf (_(" %ld %s [%s]\n"),
- entry->entry,
- get_TAG_name (entry->tag),
- entry->children ? _("has children") : _("no children"));
-
- for (attr = entry->first_attr; attr; attr = attr->next)
- printf (_(" %-18s %s\n"),
- get_AT_name (attr->attribute),
- get_FORM_name (attr->form));
- }
- }
- while (start);
-
- printf ("\n");
-
- return 1;
-}
-
-static int
-display_debug_loc (struct dwarf_section *section, void *file)
-{
- unsigned char *start = section->start;
- unsigned char *section_end;
- unsigned long bytes;
- unsigned char *section_begin = start;
- unsigned int num_loc_list = 0;
- unsigned long last_offset = 0;
- unsigned int first = 0;
- unsigned int i;
- unsigned int j;
- int seen_first_offset = 0;
- int use_debug_info = 1;
- unsigned char *next;
-
- bytes = section->size;
- section_end = start + bytes;
-
- if (bytes == 0)
- {
- printf (_("\nThe %s section is empty.\n"), section->name);
- return 0;
- }
-
- if (load_debug_info (file) == 0)
- {
- warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
- section->name);
- return 0;
- }
-
- /* Check the order of location list in .debug_info section. If
- offsets of location lists are in the ascending order, we can
- use `debug_information' directly. */
- for (i = 0; i < num_debug_info_entries; i++)
- {
- unsigned int num;
-
- num = debug_information [i].num_loc_offsets;
- num_loc_list += num;
-
- /* Check if we can use `debug_information' directly. */
- if (use_debug_info && num != 0)
- {
- if (!seen_first_offset)
- {
- /* This is the first location list. */
- last_offset = debug_information [i].loc_offsets [0];
- first = i;
- seen_first_offset = 1;
- j = 1;
- }
- else
- j = 0;
-
- for (; j < num; j++)
- {
- if (last_offset >
- debug_information [i].loc_offsets [j])
- {
- use_debug_info = 0;
- break;
- }
- last_offset = debug_information [i].loc_offsets [j];
- }
- }
- }
-
- if (!use_debug_info)
- /* FIXME: Should we handle this case? */
- error (_("Location lists in .debug_info section aren't in ascending order!\n"));
-
- if (!seen_first_offset)
- error (_("No location lists in .debug_info section!\n"));
-
- /* DWARF sections under Mach-O have non-zero addresses. */
- if (debug_information [first].num_loc_offsets > 0
- && debug_information [first].loc_offsets [0] != section->address)
- warn (_("Location lists in %s section start at 0x%lx\n"),
- section->name, debug_information [first].loc_offsets [0]);
-
- printf (_("Contents of the %s section:\n\n"), section->name);
- printf (_(" Offset Begin End Expression\n"));
-
- seen_first_offset = 0;
- for (i = first; i < num_debug_info_entries; i++)
- {
- dwarf_vma begin;
- dwarf_vma end;
- unsigned short length;
- unsigned long offset;
- unsigned int pointer_size;
- unsigned long cu_offset;
- unsigned long base_address;
- int need_frame_base;
- int has_frame_base;
-
- pointer_size = debug_information [i].pointer_size;
- cu_offset = debug_information [i].cu_offset;
-
- for (j = 0; j < debug_information [i].num_loc_offsets; j++)
- {
- has_frame_base = debug_information [i].have_frame_base [j];
- /* DWARF sections under Mach-O have non-zero addresses. */
- offset = debug_information [i].loc_offsets [j] - section->address;
- next = section_begin + offset;
- base_address = debug_information [i].base_address;
-
- if (!seen_first_offset)
- seen_first_offset = 1;
- else
- {
- if (start < next)
- warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
- (unsigned long) (start - section_begin),
- (unsigned long) (next - section_begin));
- else if (start > next)
- warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
- (unsigned long) (start - section_begin),
- (unsigned long) (next - section_begin));
- }
- start = next;
-
- if (offset >= bytes)
- {
- warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
- offset);
- continue;
- }
-
- while (1)
- {
- if (start + 2 * pointer_size > section_end)
- {
- warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
- offset);
- break;
- }
-
- /* Note: we use sign extension here in order to be sure that
- we can detect the -1 escape value. Sign extension into the
- top 32 bits of a 32-bit address will not affect the values
- that we display since we always show hex values, and always
- the bottom 32-bits. */
- begin = byte_get_signed (start, pointer_size);
- start += pointer_size;
- end = byte_get_signed (start, pointer_size);
- start += pointer_size;
-
- printf (" %8.8lx ", offset);
-
- if (begin == 0 && end == 0)
- {
- printf (_("<End of list>\n"));
- break;
- }
-
- /* Check base address specifiers. */
- if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
- {
- base_address = end;
- print_dwarf_vma (begin, pointer_size);
- print_dwarf_vma (end, pointer_size);
- printf (_("(base address)\n"));
- continue;
- }
-
- if (start + 2 > section_end)
- {
- warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
- offset);
- break;
- }
-
- length = byte_get (start, 2);
- start += 2;
-
- if (start + length > section_end)
- {
- warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
- offset);
- break;
- }
-
- print_dwarf_vma (begin + base_address, pointer_size);
- print_dwarf_vma (end + base_address, pointer_size);
-
- putchar ('(');
- need_frame_base = decode_location_expression (start,
- pointer_size,
- length,
- cu_offset);
- putchar (')');
-
- if (need_frame_base && !has_frame_base)
- printf (_(" [without DW_AT_frame_base]"));
-
- if (begin == end)
- fputs (_(" (start == end)"), stdout);
- else if (begin > end)
- fputs (_(" (start > end)"), stdout);
-
- putchar ('\n');
-
- start += length;
- }
- }
- }
-
- if (start < section_end)
- warn (_("There are %ld unused bytes at the end of section %s\n"),
- (long) (section_end - start), section->name);
- return 1;
-}
-
-static int
-display_debug_str (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- unsigned char *start = section->start;
- unsigned long bytes = section->size;
- dwarf_vma addr = section->address;
-
- if (bytes == 0)
- {
- printf (_("\nThe %s section is empty.\n"), section->name);
- return 0;
- }
-
- printf (_("Contents of the %s section:\n\n"), section->name);
-
- while (bytes)
- {
- int j;
- int k;
- int lbytes;
-
- lbytes = (bytes > 16 ? 16 : bytes);
-
- printf (" 0x%8.8lx ", (unsigned long) addr);
-
- for (j = 0; j < 16; j++)
- {
- if (j < lbytes)
- printf ("%2.2x", start[j]);
- else
- printf (" ");
-
- if ((j & 3) == 3)
- printf (" ");
- }
-
- for (j = 0; j < lbytes; j++)
- {
- k = start[j];
- if (k >= ' ' && k < 0x80)
- printf ("%c", k);
- else
- printf (".");
- }
-
- putchar ('\n');
-
- start += lbytes;
- addr += lbytes;
- bytes -= lbytes;
- }
-
- putchar ('\n');
-
- return 1;
-}
-
-static int
-display_debug_info (struct dwarf_section *section, void *file)
-{
- return process_debug_info (section, file, 0);
-}
-
-
-static int
-display_debug_aranges (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
-
- printf (_("The section %s contains:\n\n"), section->name);
-
- /* It does not matter if this load fails,
- we test for that later on. */
- load_debug_info (file);
-
- while (start < end)
- {
- unsigned char *hdrptr;
- DWARF2_Internal_ARange arange;
- unsigned char *ranges;
- dwarf_vma length;
- dwarf_vma address;
- unsigned char address_size;
- int excess;
- int offset_size;
- int initial_length_size;
-
- hdrptr = start;
-
- arange.ar_length = byte_get (hdrptr, 4);
- hdrptr += 4;
-
- if (arange.ar_length == 0xffffffff)
- {
- arange.ar_length = byte_get (hdrptr, 8);
- hdrptr += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- arange.ar_version = byte_get (hdrptr, 2);
- hdrptr += 2;
-
- arange.ar_info_offset = byte_get (hdrptr, offset_size);
- hdrptr += offset_size;
-
- if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
- && num_debug_info_entries > 0
- && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
- warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
- arange.ar_info_offset, section->name);
-
- arange.ar_pointer_size = byte_get (hdrptr, 1);
- hdrptr += 1;
-
- arange.ar_segment_size = byte_get (hdrptr, 1);
- hdrptr += 1;
-
- if (arange.ar_version != 2 && arange.ar_version != 3)
- {
- warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
- break;
- }
-
- printf (_(" Length: %ld\n"), arange.ar_length);
- printf (_(" Version: %d\n"), arange.ar_version);
- printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
- printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
- printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
-
- address_size = arange.ar_pointer_size + arange.ar_segment_size;
-
- /* The DWARF spec does not require that the address size be a power
- of two, but we do. This will have to change if we ever encounter
- an uneven architecture. */
- if ((address_size & (address_size - 1)) != 0)
- {
- warn (_("Pointer size + Segment size is not a power of two.\n"));
- break;
- }
-
- if (address_size > 4)
- printf (_("\n Address Length\n"));
- else
- printf (_("\n Address Length\n"));
-
- ranges = hdrptr;
-
- /* Must pad to an alignment boundary that is twice the address size. */
- excess = (hdrptr - start) % (2 * address_size);
- if (excess)
- ranges += (2 * address_size) - excess;
-
- start += arange.ar_length + initial_length_size;
-
- while (ranges + 2 * address_size <= start)
- {
- address = byte_get (ranges, address_size);
-
- ranges += address_size;
-
- length = byte_get (ranges, address_size);
-
- ranges += address_size;
-
- print_dwarf_vma (address, address_size);
- print_dwarf_vma (length, address_size);
- putchar ('\n');
- }
- }
-
- printf ("\n");
-
- return 1;
-}
-
-static int
-display_debug_ranges (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- unsigned char *start = section->start;
- unsigned char *section_end;
- unsigned long bytes;
- unsigned char *section_begin = start;
- unsigned int num_range_list = 0;
- unsigned long last_offset = 0;
- unsigned int first = 0;
- unsigned int i;
- unsigned int j;
- int seen_first_offset = 0;
- int use_debug_info = 1;
- unsigned char *next;
-
- bytes = section->size;
- section_end = start + bytes;
-
- if (bytes == 0)
- {
- printf (_("\nThe %s section is empty.\n"), section->name);
- return 0;
- }
-
- if (load_debug_info (file) == 0)
- {
- warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
- section->name);
- return 0;
- }
-
- /* Check the order of range list in .debug_info section. If
- offsets of range lists are in the ascending order, we can
- use `debug_information' directly. */
- for (i = 0; i < num_debug_info_entries; i++)
- {
- unsigned int num;
-
- num = debug_information [i].num_range_lists;
- num_range_list += num;
-
- /* Check if we can use `debug_information' directly. */
- if (use_debug_info && num != 0)
- {
- if (!seen_first_offset)
- {
- /* This is the first range list. */
- last_offset = debug_information [i].range_lists [0];
- first = i;
- seen_first_offset = 1;
- j = 1;
- }
- else
- j = 0;
-
- for (; j < num; j++)
- {
- if (last_offset >
- debug_information [i].range_lists [j])
- {
- use_debug_info = 0;
- break;
- }
- last_offset = debug_information [i].range_lists [j];
- }
- }
- }
-
- if (!use_debug_info)
- /* FIXME: Should we handle this case? */
- error (_("Range lists in .debug_info section aren't in ascending order!\n"));
-
- if (!seen_first_offset)
- error (_("No range lists in .debug_info section!\n"));
-
- /* DWARF sections under Mach-O have non-zero addresses. */
- if (debug_information [first].num_range_lists > 0
- && debug_information [first].range_lists [0] != section->address)
- warn (_("Range lists in %s section start at 0x%lx\n"),
- section->name, debug_information [first].range_lists [0]);
-
- printf (_("Contents of the %s section:\n\n"), section->name);
- printf (_(" Offset Begin End\n"));
-
- seen_first_offset = 0;
- for (i = first; i < num_debug_info_entries; i++)
- {
- dwarf_vma begin;
- dwarf_vma end;
- unsigned long offset;
- unsigned int pointer_size;
- unsigned long base_address;
-
- pointer_size = debug_information [i].pointer_size;
-
- for (j = 0; j < debug_information [i].num_range_lists; j++)
- {
- /* DWARF sections under Mach-O have non-zero addresses. */
- offset = debug_information [i].range_lists [j] - section->address;
- next = section_begin + offset;
- base_address = debug_information [i].base_address;
-
- if (!seen_first_offset)
- seen_first_offset = 1;
- else
- {
- if (start < next)
- warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
- (unsigned long) (start - section_begin),
- (unsigned long) (next - section_begin), section->name);
- else if (start > next)
- warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
- (unsigned long) (start - section_begin),
- (unsigned long) (next - section_begin), section->name);
- }
- start = next;
-
- while (1)
- {
- /* Note: we use sign extension here in order to be sure that
- we can detect the -1 escape value. Sign extension into the
- top 32 bits of a 32-bit address will not affect the values
- that we display since we always show hex values, and always
- the bottom 32-bits. */
- begin = byte_get_signed (start, pointer_size);
- start += pointer_size;
- end = byte_get_signed (start, pointer_size);
- start += pointer_size;
-
- printf (" %8.8lx ", offset);
-
- if (begin == 0 && end == 0)
- {
- printf (_("<End of list>\n"));
- break;
- }
-
- print_dwarf_vma (begin, pointer_size);
- print_dwarf_vma (end, pointer_size);
-
- /* Check base address specifiers. */
- if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
- {
- base_address = end;
- printf ("(base address)\n");
- continue;
- }
-
- if (begin == end)
- fputs (_("(start == end)"), stdout);
- else if (begin > end)
- fputs (_("(start > end)"), stdout);
-
- putchar ('\n');
- }
- }
- }
- putchar ('\n');
- return 1;
-}
-
-typedef struct Frame_Chunk
-{
- struct Frame_Chunk *next;
- unsigned char *chunk_start;
- int ncols;
- /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
- short int *col_type;
- int *col_offset;
- char *augmentation;
- unsigned int code_factor;
- int data_factor;
- unsigned long pc_begin;
- unsigned long pc_range;
- int cfa_reg;
- int cfa_offset;
- int ra;
- unsigned char fde_encoding;
- unsigned char cfa_exp;
-}
-Frame_Chunk;
-
-/* A marker for a col_type that means this column was never referenced
- in the frame info. */
-#define DW_CFA_unreferenced (-1)
-
-static void
-frame_need_space (Frame_Chunk *fc, int reg)
-{
- int prev = fc->ncols;
-
- if (reg < fc->ncols)
- return;
-
- fc->ncols = reg + 1;
- fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
- fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
-
- while (prev < fc->ncols)
- {
- fc->col_type[prev] = DW_CFA_unreferenced;
- fc->col_offset[prev] = 0;
- prev++;
- }
-}
-
-static const char *const dwarf_regnames_i386[] =
-{
- "eax", "ecx", "edx", "ebx",
- "esp", "ebp", "esi", "edi",
- "eip", "eflags", NULL,
- "st0", "st1", "st2", "st3",
- "st4", "st5", "st6", "st7",
- NULL, NULL,
- "xmm0", "xmm1", "xmm2", "xmm3",
- "xmm4", "xmm5", "xmm6", "xmm7",
- "mm0", "mm1", "mm2", "mm3",
- "mm4", "mm5", "mm6", "mm7",
- "fcw", "fsw", "mxcsr",
- "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
- "tr", "ldtr"
-};
-
-static const char *const dwarf_regnames_x86_64[] =
-{
- "rax", "rdx", "rcx", "rbx",
- "rsi", "rdi", "rbp", "rsp",
- "r8", "r9", "r10", "r11",
- "r12", "r13", "r14", "r15",
- "rip",
- "xmm0", "xmm1", "xmm2", "xmm3",
- "xmm4", "xmm5", "xmm6", "xmm7",
- "xmm8", "xmm9", "xmm10", "xmm11",
- "xmm12", "xmm13", "xmm14", "xmm15",
- "st0", "st1", "st2", "st3",
- "st4", "st5", "st6", "st7",
- "mm0", "mm1", "mm2", "mm3",
- "mm4", "mm5", "mm6", "mm7",
- "rflags",
- "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
- "fs.base", "gs.base", NULL, NULL,
- "tr", "ldtr",
- "mxcsr", "fcw", "fsw"
-};
-
-static const char *const *dwarf_regnames;
-static unsigned int dwarf_regnames_count;
-
-void
-init_dwarf_regnames (unsigned int e_machine)
-{
- switch (e_machine)
- {
- case EM_386:
- case EM_486:
- dwarf_regnames = dwarf_regnames_i386;
- dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
- break;
-
- case EM_X86_64:
- dwarf_regnames = dwarf_regnames_x86_64;
- dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
- break;
-
- default:
- break;
- }
-}
-
-static const char *
-regname (unsigned int regno, int row)
-{
- static char reg[64];
- if (dwarf_regnames
- && regno < dwarf_regnames_count
- && dwarf_regnames [regno] != NULL)
- {
- if (row)
- return dwarf_regnames [regno];
- snprintf (reg, sizeof (reg), "r%d (%s)", regno,
- dwarf_regnames [regno]);
- }
- else
- snprintf (reg, sizeof (reg), "r%d", regno);
- return reg;
-}
-
-static void
-frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
-{
- int r;
- char tmp[100];
-
- if (*max_regs < fc->ncols)
- *max_regs = fc->ncols;
-
- if (*need_col_headers)
- {
- static const char *loc = " LOC";
-
- *need_col_headers = 0;
-
- printf ("%-*s CFA ", eh_addr_size * 2, loc);
-
- for (r = 0; r < *max_regs; r++)
- if (fc->col_type[r] != DW_CFA_unreferenced)
- {
- if (r == fc->ra)
- printf ("ra ");
- else
- printf ("%-5s ", regname (r, 1));
- }
-
- printf ("\n");
- }
-
- printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
- if (fc->cfa_exp)
- strcpy (tmp, "exp");
- else
- sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
- printf ("%-8s ", tmp);
-
- for (r = 0; r < fc->ncols; r++)
- {
- if (fc->col_type[r] != DW_CFA_unreferenced)
- {
- switch (fc->col_type[r])
- {
- case DW_CFA_undefined:
- strcpy (tmp, "u");
- break;
- case DW_CFA_same_value:
- strcpy (tmp, "s");
- break;
- case DW_CFA_offset:
- sprintf (tmp, "c%+d", fc->col_offset[r]);
- break;
- case DW_CFA_val_offset:
- sprintf (tmp, "v%+d", fc->col_offset[r]);
- break;
- case DW_CFA_register:
- sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
- break;
- case DW_CFA_expression:
- strcpy (tmp, "exp");
- break;
- case DW_CFA_val_expression:
- strcpy (tmp, "vexp");
- break;
- default:
- strcpy (tmp, "n/a");
- break;
- }
- printf ("%-5s ", tmp);
- }
- }
- printf ("\n");
-}
-
-static int
-size_of_encoded_value (int encoding)
-{
- switch (encoding & 0x7)
- {
- default: /* ??? */
- case 0: return eh_addr_size;
- case 2: return 2;
- case 3: return 4;
- case 4: return 8;
- }
-}
-
-static dwarf_vma
-get_encoded_value (unsigned char *data, int encoding)
-{
- int size = size_of_encoded_value (encoding);
-
- if (encoding & DW_EH_PE_signed)
- return byte_get_signed (data, size);
- else
- return byte_get (data, size);
-}
-
-#define GET(N) byte_get (start, N); start += N
-#define LEB() read_leb128 (start, & length_return, 0); start += length_return
-#define SLEB() read_leb128 (start, & length_return, 1); start += length_return
-
-static int
-display_debug_frames (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- unsigned char *start = section->start;
- unsigned char *end = start + section->size;
- unsigned char *section_start = start;
- Frame_Chunk *chunks = 0;
- Frame_Chunk *remembered_state = 0;
- Frame_Chunk *rs;
- int is_eh = strcmp (section->name, ".eh_frame") == 0;
- unsigned int length_return;
- int max_regs = 0;
-
- printf (_("The section %s contains:\n"), section->name);
-
- while (start < end)
- {
- unsigned char *saved_start;
- unsigned char *block_end;
- unsigned long length;
- unsigned long cie_id;
- Frame_Chunk *fc;
- Frame_Chunk *cie;
- int need_col_headers = 1;
- unsigned char *augmentation_data = NULL;
- unsigned long augmentation_data_len = 0;
- int encoded_ptr_size = eh_addr_size;
- int offset_size;
- int initial_length_size;
-
- saved_start = start;
- length = byte_get (start, 4); start += 4;
-
- if (length == 0)
- {
- printf ("\n%08lx ZERO terminator\n\n",
- (unsigned long)(saved_start - section_start));
- continue;
- }
-
- if (length == 0xffffffff)
- {
- length = byte_get (start, 8);
- start += 8;
- offset_size = 8;
- initial_length_size = 12;
- }
- else
- {
- offset_size = 4;
- initial_length_size = 4;
- }
-
- block_end = saved_start + length + initial_length_size;
- if (block_end > end)
- {
- warn ("Invalid length %#08lx in FDE at %#08lx\n",
- length, (unsigned long)(saved_start - section_start));
- block_end = end;
- }
- cie_id = byte_get (start, offset_size); start += offset_size;
-
- if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
- {
- int version;
-
- fc = xmalloc (sizeof (Frame_Chunk));
- memset (fc, 0, sizeof (Frame_Chunk));
-
- fc->next = chunks;
- chunks = fc;
- fc->chunk_start = saved_start;
- fc->ncols = 0;
- fc->col_type = xmalloc (sizeof (short int));
- fc->col_offset = xmalloc (sizeof (int));
- frame_need_space (fc, max_regs - 1);
-
- version = *start++;
-
- fc->augmentation = (char *) start;
- start = (unsigned char *) strchr ((char *) start, '\0') + 1;
-
- if (fc->augmentation[0] == 'z')
- {
- fc->code_factor = LEB ();
- fc->data_factor = SLEB ();
- if (version == 1)
- {
- fc->ra = GET (1);
- }
- else
- {
- fc->ra = LEB ();
- }
- augmentation_data_len = LEB ();
- augmentation_data = start;
- start += augmentation_data_len;
- }
- else if (strcmp (fc->augmentation, "eh") == 0)
- {
- start += eh_addr_size;
- fc->code_factor = LEB ();
- fc->data_factor = SLEB ();
- if (version == 1)
- {
- fc->ra = GET (1);
- }
- else
- {
- fc->ra = LEB ();
- }
- }
- else
- {
- fc->code_factor = LEB ();
- fc->data_factor = SLEB ();
- if (version == 1)
- {
- fc->ra = GET (1);
- }
- else
- {
- fc->ra = LEB ();
- }
- }
- cie = fc;
-
- if (do_debug_frames_interp)
- printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
- (unsigned long)(saved_start - section_start), length, cie_id,
- fc->augmentation, fc->code_factor, fc->data_factor,
- fc->ra);
- else
- {
- printf ("\n%08lx %08lx %08lx CIE\n",
- (unsigned long)(saved_start - section_start), length, cie_id);
- printf (" Version: %d\n", version);
- printf (" Augmentation: \"%s\"\n", fc->augmentation);
- printf (" Code alignment factor: %u\n", fc->code_factor);
- printf (" Data alignment factor: %d\n", fc->data_factor);
- printf (" Return address column: %d\n", fc->ra);
-
- if (augmentation_data_len)
- {
- unsigned long i;
- printf (" Augmentation data: ");
- for (i = 0; i < augmentation_data_len; ++i)
- printf (" %02x", augmentation_data[i]);
- putchar ('\n');
- }
- putchar ('\n');
- }
-
- if (augmentation_data_len)
- {
- unsigned char *p, *q;
- p = (unsigned char *) fc->augmentation + 1;
- q = augmentation_data;
-
- while (1)
- {
- if (*p == 'L')
- q++;
- else if (*p == 'P')
- q += 1 + size_of_encoded_value (*q);
- else if (*p == 'R')
- fc->fde_encoding = *q++;
- else
- break;
- p++;
- }
-
- if (fc->fde_encoding)
- encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
- }
-
- frame_need_space (fc, fc->ra);
- }
- else
- {
- unsigned char *look_for;
- static Frame_Chunk fde_fc;
-
- fc = & fde_fc;
- memset (fc, 0, sizeof (Frame_Chunk));
-
- look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
-
- for (cie = chunks; cie ; cie = cie->next)
- if (cie->chunk_start == look_for)
- break;
-
- if (!cie)
- {
- warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
- cie_id, (unsigned long)(saved_start - section_start));
- fc->ncols = 0;
- fc->col_type = xmalloc (sizeof (short int));
- fc->col_offset = xmalloc (sizeof (int));
- frame_need_space (fc, max_regs - 1);
- cie = fc;
- fc->augmentation = "";
- fc->fde_encoding = 0;
- }
- else
- {
- fc->ncols = cie->ncols;
- fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
- fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
- memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
- memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
- fc->augmentation = cie->augmentation;
- fc->code_factor = cie->code_factor;
- fc->data_factor = cie->data_factor;
- fc->cfa_reg = cie->cfa_reg;
- fc->cfa_offset = cie->cfa_offset;
- fc->ra = cie->ra;
- frame_need_space (fc, max_regs - 1);
- fc->fde_encoding = cie->fde_encoding;
- }
-
- if (fc->fde_encoding)
- encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
-
- fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
- if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
- fc->pc_begin += section->address + (start - section_start);
- start += encoded_ptr_size;
- fc->pc_range = byte_get (start, encoded_ptr_size);
- start += encoded_ptr_size;
-
- if (cie->augmentation[0] == 'z')
- {
- augmentation_data_len = LEB ();
- augmentation_data = start;
- start += augmentation_data_len;
- }
-
- printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
- (unsigned long)(saved_start - section_start), length, cie_id,
- (unsigned long)(cie->chunk_start - section_start),
- fc->pc_begin, fc->pc_begin + fc->pc_range);
- if (! do_debug_frames_interp && augmentation_data_len)
- {
- unsigned long i;
-
- printf (" Augmentation data: ");
- for (i = 0; i < augmentation_data_len; ++i)
- printf (" %02x", augmentation_data[i]);
- putchar ('\n');
- putchar ('\n');
- }
- }
-
- /* At this point, fc is the current chunk, cie (if any) is set, and
- we're about to interpret instructions for the chunk. */
- /* ??? At present we need to do this always, since this sizes the
- fc->col_type and fc->col_offset arrays, which we write into always.
- We should probably split the interpreted and non-interpreted bits
- into two different routines, since there's so much that doesn't
- really overlap between them. */
- if (1 || do_debug_frames_interp)
- {
- /* Start by making a pass over the chunk, allocating storage
- and taking note of what registers are used. */
- unsigned char *tmp = start;
-
- while (start < block_end)
- {
- unsigned op, opa;
- unsigned long reg, tmp;
-
- op = *start++;
- opa = op & 0x3f;
- if (op & 0xc0)
- op &= 0xc0;
-
- /* Warning: if you add any more cases to this switch, be
- sure to add them to the corresponding switch below. */
- switch (op)
- {
- case DW_CFA_advance_loc:
- break;
- case DW_CFA_offset:
- LEB ();
- frame_need_space (fc, opa);
- fc->col_type[opa] = DW_CFA_undefined;
- break;
- case DW_CFA_restore:
- frame_need_space (fc, opa);
- fc->col_type[opa] = DW_CFA_undefined;
- break;
- case DW_CFA_set_loc:
- start += encoded_ptr_size;
- break;
- case DW_CFA_advance_loc1:
- start += 1;
- break;
- case DW_CFA_advance_loc2:
- start += 2;
- break;
- case DW_CFA_advance_loc4:
- start += 4;
- break;
- case DW_CFA_offset_extended:
- case DW_CFA_val_offset:
- reg = LEB (); LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_restore_extended:
- reg = LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_undefined:
- reg = LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_same_value:
- reg = LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_register:
- reg = LEB (); LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_def_cfa:
- LEB (); LEB ();
- break;
- case DW_CFA_def_cfa_register:
- LEB ();
- break;
- case DW_CFA_def_cfa_offset:
- LEB ();
- break;
- case DW_CFA_def_cfa_expression:
- tmp = LEB ();
- start += tmp;
- break;
- case DW_CFA_expression:
- case DW_CFA_val_expression:
- reg = LEB ();
- tmp = LEB ();
- start += tmp;
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_offset_extended_sf:
- case DW_CFA_val_offset_sf:
- reg = LEB (); SLEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
- break;
- case DW_CFA_def_cfa_sf:
- LEB (); SLEB ();
- break;
- case DW_CFA_def_cfa_offset_sf:
- SLEB ();
- break;
- case DW_CFA_MIPS_advance_loc8:
- start += 8;
- break;
- case DW_CFA_GNU_args_size:
- LEB ();
- break;
- case DW_CFA_GNU_negative_offset_extended:
- reg = LEB (); LEB ();
- frame_need_space (fc, reg);
- fc->col_type[reg] = DW_CFA_undefined;
-
- default:
- break;
- }
- }
- start = tmp;
- }
-
- /* Now we know what registers are used, make a second pass over
- the chunk, this time actually printing out the info. */
-
- while (start < block_end)
- {
- unsigned op, opa;
- unsigned long ul, reg, roffs;
- long l, ofs;
- dwarf_vma vma;
-
- op = *start++;
- opa = op & 0x3f;
- if (op & 0xc0)
- op &= 0xc0;
-
- /* Warning: if you add any more cases to this switch, be
- sure to add them to the corresponding switch above. */
- switch (op)
- {
- case DW_CFA_advance_loc:
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_advance_loc: %d to %08lx\n",
- opa * fc->code_factor,
- fc->pc_begin + opa * fc->code_factor);
- fc->pc_begin += opa * fc->code_factor;
- break;
-
- case DW_CFA_offset:
- roffs = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_offset: %s at cfa%+ld\n",
- regname (opa, 0), roffs * fc->data_factor);
- fc->col_type[opa] = DW_CFA_offset;
- fc->col_offset[opa] = roffs * fc->data_factor;
- break;
-
- case DW_CFA_restore:
- if (! do_debug_frames_interp)
- printf (" DW_CFA_restore: %s\n", regname (opa, 0));
- fc->col_type[opa] = cie->col_type[opa];
- fc->col_offset[opa] = cie->col_offset[opa];
- break;
-
- case DW_CFA_set_loc:
- vma = get_encoded_value (start, fc->fde_encoding);
- if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
- vma += section->address + (start - section_start);
- start += encoded_ptr_size;
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
- fc->pc_begin = vma;
- break;
-
- case DW_CFA_advance_loc1:
- ofs = byte_get (start, 1); start += 1;
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
- ofs * fc->code_factor,
- fc->pc_begin + ofs * fc->code_factor);
- fc->pc_begin += ofs * fc->code_factor;
- break;
-
- case DW_CFA_advance_loc2:
- ofs = byte_get (start, 2); start += 2;
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
- ofs * fc->code_factor,
- fc->pc_begin + ofs * fc->code_factor);
- fc->pc_begin += ofs * fc->code_factor;
- break;
-
- case DW_CFA_advance_loc4:
- ofs = byte_get (start, 4); start += 4;
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
- ofs * fc->code_factor,
- fc->pc_begin + ofs * fc->code_factor);
- fc->pc_begin += ofs * fc->code_factor;
- break;
-
- case DW_CFA_offset_extended:
- reg = LEB ();
- roffs = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
- regname (reg, 0), roffs * fc->data_factor);
- fc->col_type[reg] = DW_CFA_offset;
- fc->col_offset[reg] = roffs * fc->data_factor;
- break;
-
- case DW_CFA_val_offset:
- reg = LEB ();
- roffs = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
- regname (reg, 0), roffs * fc->data_factor);
- fc->col_type[reg] = DW_CFA_val_offset;
- fc->col_offset[reg] = roffs * fc->data_factor;
- break;
-
- case DW_CFA_restore_extended:
- reg = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_restore_extended: %s\n",
- regname (reg, 0));
- fc->col_type[reg] = cie->col_type[reg];
- fc->col_offset[reg] = cie->col_offset[reg];
- break;
-
- case DW_CFA_undefined:
- reg = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_undefined: %s\n", regname (reg, 0));
- fc->col_type[reg] = DW_CFA_undefined;
- fc->col_offset[reg] = 0;
- break;
-
- case DW_CFA_same_value:
- reg = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_same_value: %s\n", regname (reg, 0));
- fc->col_type[reg] = DW_CFA_same_value;
- fc->col_offset[reg] = 0;
- break;
-
- case DW_CFA_register:
- reg = LEB ();
- roffs = LEB ();
- if (! do_debug_frames_interp)
- {
- printf (" DW_CFA_register: %s in ",
- regname (reg, 0));
- puts (regname (roffs, 0));
- }
- fc->col_type[reg] = DW_CFA_register;
- fc->col_offset[reg] = roffs;
- break;
-
- case DW_CFA_remember_state:
- if (! do_debug_frames_interp)
- printf (" DW_CFA_remember_state\n");
- rs = xmalloc (sizeof (Frame_Chunk));
- rs->ncols = fc->ncols;
- rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
- rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
- memcpy (rs->col_type, fc->col_type, rs->ncols);
- memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
- rs->next = remembered_state;
- remembered_state = rs;
- break;
-
- case DW_CFA_restore_state:
- if (! do_debug_frames_interp)
- printf (" DW_CFA_restore_state\n");
- rs = remembered_state;
- if (rs)
- {
- remembered_state = rs->next;
- frame_need_space (fc, rs->ncols - 1);
- memcpy (fc->col_type, rs->col_type, rs->ncols);
- memcpy (fc->col_offset, rs->col_offset,
- rs->ncols * sizeof (int));
- free (rs->col_type);
- free (rs->col_offset);
- free (rs);
- }
- else if (do_debug_frames_interp)
- printf ("Mismatched DW_CFA_restore_state\n");
- break;
-
- case DW_CFA_def_cfa:
- fc->cfa_reg = LEB ();
- fc->cfa_offset = LEB ();
- fc->cfa_exp = 0;
- if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa: %s ofs %d\n",
- regname (fc->cfa_reg, 0), fc->cfa_offset);
- break;
-
- case DW_CFA_def_cfa_register:
- fc->cfa_reg = LEB ();
- fc->cfa_exp = 0;
- if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa_register: %s\n",
- regname (fc->cfa_reg, 0));
- break;
-
- case DW_CFA_def_cfa_offset:
- fc->cfa_offset = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
- break;
-
- case DW_CFA_nop:
- if (! do_debug_frames_interp)
- printf (" DW_CFA_nop\n");
- break;
-
- case DW_CFA_def_cfa_expression:
- ul = LEB ();
- if (! do_debug_frames_interp)
- {
- printf (" DW_CFA_def_cfa_expression (");
- decode_location_expression (start, eh_addr_size, ul, 0);
- printf (")\n");
- }
- fc->cfa_exp = 1;
- start += ul;
- break;
-
- case DW_CFA_expression:
- reg = LEB ();
- ul = LEB ();
- if (! do_debug_frames_interp)
- {
- printf (" DW_CFA_expression: %s (",
- regname (reg, 0));
- decode_location_expression (start, eh_addr_size,
- ul, 0);
- printf (")\n");
- }
- fc->col_type[reg] = DW_CFA_expression;
- start += ul;
- break;
-
- case DW_CFA_val_expression:
- reg = LEB ();
- ul = LEB ();
- if (! do_debug_frames_interp)
- {
- printf (" DW_CFA_val_expression: %s (",
- regname (reg, 0));
- decode_location_expression (start, eh_addr_size, ul, 0);
- printf (")\n");
- }
- fc->col_type[reg] = DW_CFA_val_expression;
- start += ul;
- break;
-
- case DW_CFA_offset_extended_sf:
- reg = LEB ();
- l = SLEB ();
- frame_need_space (fc, reg);
- if (! do_debug_frames_interp)
- printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
- regname (reg, 0), l * fc->data_factor);
- fc->col_type[reg] = DW_CFA_offset;
- fc->col_offset[reg] = l * fc->data_factor;
- break;
-
- case DW_CFA_val_offset_sf:
- reg = LEB ();
- l = SLEB ();
- frame_need_space (fc, reg);
- if (! do_debug_frames_interp)
- printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
- regname (reg, 0), l * fc->data_factor);
- fc->col_type[reg] = DW_CFA_val_offset;
- fc->col_offset[reg] = l * fc->data_factor;
- break;
-
- case DW_CFA_def_cfa_sf:
- fc->cfa_reg = LEB ();
- fc->cfa_offset = SLEB ();
- fc->cfa_offset = fc->cfa_offset * fc->data_factor;
- fc->cfa_exp = 0;
- if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
- regname (fc->cfa_reg, 0), fc->cfa_offset);
- break;
-
- case DW_CFA_def_cfa_offset_sf:
- fc->cfa_offset = SLEB ();
- fc->cfa_offset = fc->cfa_offset * fc->data_factor;
- if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
- break;
-
- case DW_CFA_MIPS_advance_loc8:
- ofs = byte_get (start, 8); start += 8;
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
- else
- printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
- ofs * fc->code_factor,
- fc->pc_begin + ofs * fc->code_factor);
- fc->pc_begin += ofs * fc->code_factor;
- break;
-
- case DW_CFA_GNU_window_save:
- if (! do_debug_frames_interp)
- printf (" DW_CFA_GNU_window_save\n");
- break;
-
- case DW_CFA_GNU_args_size:
- ul = LEB ();
- if (! do_debug_frames_interp)
- printf (" DW_CFA_GNU_args_size: %ld\n", ul);
- break;
-
- case DW_CFA_GNU_negative_offset_extended:
- reg = LEB ();
- l = - LEB ();
- frame_need_space (fc, reg);
- if (! do_debug_frames_interp)
- printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
- regname (reg, 0), l * fc->data_factor);
- fc->col_type[reg] = DW_CFA_offset;
- fc->col_offset[reg] = l * fc->data_factor;
- break;
-
- default:
- if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
- printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
- else
- warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
- start = block_end;
- }
- }
-
- if (do_debug_frames_interp)
- frame_display_row (fc, &need_col_headers, &max_regs);
-
- start = block_end;
- }
-
- printf ("\n");
-
- return 1;
-}
-
-#undef GET
-#undef LEB
-#undef SLEB
-
-static int
-display_debug_not_supported (struct dwarf_section *section,
- void *file ATTRIBUTE_UNUSED)
-{
- printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
- section->name);
-
- return 1;
-}
-
-void *
-cmalloc (size_t nmemb, size_t size)
-{
- /* Check for overflow. */
- if (nmemb >= ~(size_t) 0 / size)
- return NULL;
- else
- return malloc (nmemb * size);
-}
-
-void *
-xcmalloc (size_t nmemb, size_t size)
-{
- /* Check for overflow. */
- if (nmemb >= ~(size_t) 0 / size)
- return NULL;
- else
- return xmalloc (nmemb * size);
-}
-
-void *
-xcrealloc (void *ptr, size_t nmemb, size_t size)
-{
- /* Check for overflow. */
- if (nmemb >= ~(size_t) 0 / size)
- return NULL;
- else
- return xrealloc (ptr, nmemb * size);
-}
-
-void
-error (const char *message, ...)
-{
- va_list args;
-
- va_start (args, message);
- fprintf (stderr, _("%s: Error: "), program_name);
- vfprintf (stderr, message, args);
- va_end (args);
-}
-
-void
-warn (const char *message, ...)
-{
- va_list args;
-
- va_start (args, message);
- fprintf (stderr, _("%s: Warning: "), program_name);
- vfprintf (stderr, message, args);
- va_end (args);
-}
-
-void
-free_debug_memory (void)
-{
- enum dwarf_section_display_enum i;
-
- free_abbrevs ();
-
- for (i = 0; i < max; i++)
- free_debug_section (i);
-
- if (debug_information != NULL)
- {
- if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
- {
- for (i = 0; i < num_debug_info_entries; i++)
- {
- if (!debug_information [i].max_loc_offsets)
- {
- free (debug_information [i].loc_offsets);
- free (debug_information [i].have_frame_base);
- }
- if (!debug_information [i].max_range_lists)
- free (debug_information [i].range_lists);
- }
- }
-
- free (debug_information);
- debug_information = NULL;
- num_debug_info_entries = 0;
- }
-}
-
-struct dwarf_section_display debug_displays[] =
-{
- { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
- display_debug_abbrev, 0, 0 },
- { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
- display_debug_aranges, 0, 0 },
- { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
- display_debug_frames, 1, 0 },
- { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
- display_debug_info, 1, 0 },
- { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
- display_debug_lines, 0, 0 },
- { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
- display_debug_pubnames, 0, 0 },
- { { ".eh_frame", "", NULL, NULL, 0, 0 },
- display_debug_frames, 1, 1 },
- { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
- display_debug_macinfo, 0, 0 },
- { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
- display_debug_str, 0, 0 },
- { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
- display_debug_loc, 0, 0 },
- { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
- display_debug_pubnames, 0, 0 },
- { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
- display_debug_ranges, 0, 0 },
- { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
- display_debug_not_supported, 0, 0 },
- { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
- display_debug_not_supported, 0, 0 },
- { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
- display_debug_not_supported, 0, 0 },
- { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
- display_debug_not_supported, 0, 0 }
-};
diff --git a/binutils/objdump.c b/binutils/objdump.c
deleted file mode 100644
index d4c32c03a24..00000000000
--- a/binutils/objdump.c
+++ /dev/null
@@ -1,3395 +0,0 @@
-/* objdump.c -- dump information about an object file.
- Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
- Free Software Foundation, Inc.
-
- This file is part of GNU Binutils.
-
- 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, 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, 51 Franklin Street - Fifth Floor, Boston,
- MA 02110-1301, USA. */
-
-
-/* Objdump overview.
-
- Objdump displays information about one or more object files, either on
- their own, or inside libraries. It is commonly used as a disassembler,
- but it can also display information about file headers, symbol tables,
- relocations, debugging directives and more.
-
- The flow of execution is as follows:
-
- 1. Command line arguments are checked for control switches and the
- information to be displayed is selected.
-
- 2. Any remaining arguments are assumed to be object files, and they are
- processed in order by display_bfd(). If the file is an archive each
- of its elements is processed in turn.
-
- 3. The file's target architecture and binary file format are determined
- by bfd_check_format(). If they are recognised, then dump_bfd() is
- called.
-
- 4. dump_bfd() in turn calls separate functions to display the requested
- item(s) of information(s). For example disassemble_data() is called if
- a disassembly has been requested.
-
- When disassembling the code loops through blocks of instructions bounded
- by symbols, calling disassemble_bytes() on each block. The actual
- disassembling is done by the libopcodes library, via a function pointer
- supplied by the disassembler() function. */
-
-#include "sysdep.h"
-#include "bfd.h"
-#include "elf-bfd.h"
-#include "progress.h"
-#include "bucomm.h"
-#include "dwarf.h"
-#include "getopt.h"
-#include "safe-ctype.h"
-#include "dis-asm.h"
-#include "libiberty.h"
-#include "demangle.h"
-#include "debug.h"
-#include "budbg.h"
-
-#ifdef HAVE_MMAP
-#include <sys/mman.h>
-#endif
-
-#include <sys/stat.h>
-
-/* Internal headers for the ELF .stab-dump code - sorry. */
-#define BYTES_IN_WORD 32
-#include "aout/aout64.h"
-
-/* Exit status. */
-static int exit_status = 0;
-
-static char *default_target = NULL; /* Default at runtime. */
-
-/* The following variables are set based on arguments passed on the
- command line. */
-static int show_version = 0; /* Show the version number. */
-static int dump_section_contents; /* -s */
-static int dump_section_headers; /* -h */
-static bfd_boolean dump_file_header; /* -f */
-static int dump_symtab; /* -t */
-static int dump_dynamic_symtab; /* -T */
-static int dump_reloc_info; /* -r */
-static int dump_dynamic_reloc_info; /* -R */
-static int dump_ar_hdrs; /* -a */
-static int dump_private_headers; /* -p */
-static int prefix_addresses; /* --prefix-addresses */
-static int with_line_numbers; /* -l */
-static bfd_boolean with_source_code; /* -S */
-static int show_raw_insn; /* --show-raw-insn */
-static int dump_dwarf_section_info; /* --dwarf */
-static int dump_stab_section_info; /* --stabs */
-static int do_demangle; /* -C, --demangle */
-static bfd_boolean disassemble; /* -d */
-static bfd_boolean disassemble_all; /* -D */
-static int disassemble_zeroes; /* --disassemble-zeroes */
-static bfd_boolean formats_info; /* -i */
-static int wide_output; /* -w */
-static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
-static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
-static int dump_debugging; /* --debugging */
-static int dump_debugging_tags; /* --debugging-tags */
-static int dump_special_syms = 0; /* --special-syms */
-static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
-static int file_start_context = 0; /* --file-start-context */
-static bfd_boolean display_file_offsets;/* -F */
-
-/* Pointer to an array of section names provided by
- one or more "-j secname" command line options. */
-static char **only;
-/* The total number of slots in the only[] array. */
-static size_t only_size = 0;
-/* The number of occupied slots in the only[] array. */
-static size_t only_used = 0;
-
-/* Variables for handling include file path table. */
-static const char **include_paths;
-static int include_path_count;
-
-/* Extra info to pass to the section disassembler and address printing
- function. */
-struct objdump_disasm_info
-{
- bfd * abfd;
- asection * sec;
- bfd_boolean require_sec;
- arelent ** dynrelbuf;
- long dynrelcount;
- disassembler_ftype disassemble_fn;
- arelent * reloc;
-};
-
-/* Architecture to disassemble for, or default if NULL. */
-static char *machine = NULL;
-
-/* Target specific options to the disassembler. */
-static char *disassembler_options = NULL;
-
-/* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
-static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
-
-/* The symbol table. */
-static asymbol **syms;
-
-/* Number of symbols in `syms'. */
-static long symcount = 0;
-
-/* The sorted symbol table. */
-static asymbol **sorted_syms;
-
-/* Number of symbols in `sorted_syms'. */
-static long sorted_symcount = 0;
-
-/* The dynamic symbol table. */
-static asymbol **dynsyms;
-
-/* The synthetic symbol table. */
-static asymbol *synthsyms;
-static long synthcount = 0;
-
-/* Number of symbols in `dynsyms'. */
-static long dynsymcount = 0;
-
-static bfd_byte *stabs;
-static bfd_size_type stab_size;
-
-static char *strtab;
-static bfd_size_type stabstr_size;
-
-static bfd_boolean is_relocatable = FALSE;
-
-static void
-usage (FILE *stream, int status)
-{
- fprintf (stream, _("Usage: %s <option(s)> <file(s)>\n"), program_name);
- fprintf (stream, _(" Display information from object <file(s)>.\n"));
- fprintf (stream, _(" At least one of the following switches must be given:\n"));
- fprintf (stream, _("\
- -a, --archive-headers Display archive header information\n\
- -f, --file-headers Display the contents of the overall file header\n\
- -p, --private-headers Display object format specific file header contents\n\
- -h, --[section-]headers Display the contents of the section headers\n\
- -x, --all-headers Display the contents of all headers\n\
- -d, --disassemble Display assembler contents of executable sections\n\
- -D, --disassemble-all Display assembler contents of all sections\n\
- -S, --source Intermix source code with disassembly\n\
- -s, --full-contents Display the full contents of all sections requested\n\
- -g, --debugging Display debug information in object file\n\
- -e, --debugging-tags Display debug information using ctags style\n\
- -G, --stabs Display (in raw form) any STABS info in the file\n\
- -W, --dwarf Display DWARF info in the file\n\
- -t, --syms Display the contents of the symbol table(s)\n\
- -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
- -r, --reloc Display the relocation entries in the file\n\
- -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
- @<file> Read options from <file>\n\
- -v, --version Display this program's version number\n\
- -i, --info List object formats and architectures supported\n\
- -H, --help Display this information\n\
-"));
- if (status != 2)
- {
- fprintf (stream, _("\n The following switches are optional:\n"));
- fprintf (stream, _("\
- -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
- -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
- -j, --section=NAME Only display information for section NAME\n\
- -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
- -EB --endian=big Assume big endian format when disassembling\n\
- -EL --endian=little Assume little endian format when disassembling\n\
- --file-start-context Include context from start of file (with -S)\n\
- -I, --include=DIR Add DIR to search list for source files\n\
- -l, --line-numbers Include line numbers and filenames in output\n\
- -F, --file-offsets Include file offsets when displaying information\n\
- -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
- The STYLE, if specified, can be `auto', `gnu',\n\
- `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
- or `gnat'\n\
- -w, --wide Format output for more than 80 columns\n\
- -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
- --start-address=ADDR Only process data whose address is >= ADDR\n\
- --stop-address=ADDR Only process data whose address is <= ADDR\n\
- --prefix-addresses Print complete address alongside disassembly\n\
- --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
- --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
- --special-syms Include special symbols in symbol dumps\n\
-\n"));
- list_supported_targets (program_name, stream);
- list_supported_architectures (program_name, stream);
-
- disassembler_usage (stream);
- }
- if (REPORT_BUGS_TO[0] && status == 0)
- fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
- exit (status);
-}
-
-/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
-enum option_values
- {
- OPTION_ENDIAN=150,
- OPTION_START_ADDRESS,
- OPTION_STOP_ADDRESS,
- OPTION_ADJUST_VMA
- };
-
-static struct option long_options[]=
-{
- {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
- {"all-headers", no_argument, NULL, 'x'},
- {"private-headers", no_argument, NULL, 'p'},
- {"architecture", required_argument, NULL, 'm'},
- {"archive-headers", no_argument, NULL, 'a'},
- {"debugging", no_argument, NULL, 'g'},
- {"debugging-tags", no_argument, NULL, 'e'},
- {"demangle", optional_argument, NULL, 'C'},
- {"disassemble", no_argument, NULL, 'd'},
- {"disassemble-all", no_argument, NULL, 'D'},
- {"disassembler-options", required_argument, NULL, 'M'},
- {"disassemble-zeroes", no_argument, NULL, 'z'},
- {"dynamic-reloc", no_argument, NULL, 'R'},
- {"dynamic-syms", no_argument, NULL, 'T'},
- {"endian", required_argument, NULL, OPTION_ENDIAN},
- {"file-headers", no_argument, NULL, 'f'},
- {"file-offsets", no_argument, NULL, 'F'},
- {"file-start-context", no_argument, &file_start_context, 1},
- {"full-contents", no_argument, NULL, 's'},
- {"headers", no_argument, NULL, 'h'},
- {"help", no_argument, NULL, 'H'},
- {"info", no_argument, NULL, 'i'},
- {"line-numbers", no_argument, NULL, 'l'},
- {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
- {"prefix-addresses", no_argument, &prefix_addresses, 1},
- {"reloc", no_argument, NULL, 'r'},
- {"section", required_argument, NULL, 'j'},
- {"section-headers", no_argument, NULL, 'h'},
- {"show-raw-insn", no_argument, &show_raw_insn, 1},
- {"source", no_argument, NULL, 'S'},
- {"special-syms", no_argument, &dump_special_syms, 1},
- {"include", required_argument, NULL, 'I'},
- {"dwarf", no_argument, NULL, 'W'},
- {"stabs", no_argument, NULL, 'G'},
- {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
- {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
- {"syms", no_argument, NULL, 't'},
- {"target", required_argument, NULL, 'b'},
- {"version", no_argument, NULL, 'V'},
- {"wide", no_argument, NULL, 'w'},
- {0, no_argument, 0, 0}
-};
-
-static void
-nonfatal (const char *msg)
-{
- bfd_nonfatal (msg);
- exit_status = 1;
-}
-
-static void
-dump_section_header (bfd *abfd, asection *section,
- void *ignored ATTRIBUTE_UNUSED)
-{
- char *comma = "";
- unsigned int opb = bfd_octets_per_byte (abfd);
-
- /* Ignore linker created section. See elfNN_ia64_object_p in
- bfd/elfxx-ia64.c. */
- if (section->flags & SEC_LINKER_CREATED)
- return;
-
- printf ("%3d %-13s %08lx ", section->index,
- bfd_get_section_name (abfd, section),
- (unsigned long) bfd_section_size (abfd, section) / opb);
- bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section));
- printf (" ");
- bfd_printf_vma (abfd, section->lma);
- printf (" %08lx 2**%u", (unsigned long) section->filepos,
- bfd_get_section_alignment (abfd, section));
- if (! wide_output)
- printf ("\n ");
- printf (" ");
-
-#define PF(x, y) \
- if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
-
- PF (SEC_HAS_CONTENTS, "CONTENTS");
- PF (SEC_ALLOC, "ALLOC");
- PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
- PF (SEC_LOAD, "LOAD");
- PF (SEC_RELOC, "RELOC");
- PF (SEC_READONLY, "READONLY");
- PF (SEC_CODE, "CODE");
- PF (SEC_DATA, "DATA");
- PF (SEC_ROM, "ROM");
- PF (SEC_DEBUGGING, "DEBUGGING");
- PF (SEC_NEVER_LOAD, "NEVER_LOAD");
- PF (SEC_EXCLUDE, "EXCLUDE");
- PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
- if (bfd_get_arch (abfd) == bfd_arch_tic54x)
- {
- PF (SEC_TIC54X_BLOCK, "BLOCK");
- PF (SEC_TIC54X_CLINK, "CLINK");
- }
- PF (SEC_SMALL_DATA, "SMALL_DATA");
- if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
- PF (SEC_COFF_SHARED, "SHARED");
- PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
- PF (SEC_GROUP, "GROUP");
-
- if ((section->flags & SEC_LINK_ONCE) != 0)
- {
- const char *ls;
- struct coff_comdat_info *comdat;
-
- switch (section->flags & SEC_LINK_DUPLICATES)
- {
- default:
- abort ();
- case SEC_LINK_DUPLICATES_DISCARD:
- ls = "LINK_ONCE_DISCARD";
- break;
- case SEC_LINK_DUPLICATES_ONE_ONLY:
- ls = "LINK_ONCE_ONE_ONLY";
- break;
- case SEC_LINK_DUPLICATES_SAME_SIZE:
- ls = "LINK_ONCE_SAME_SIZE";
- break;
- case SEC_LINK_DUPLICATES_SAME_CONTENTS:
- ls = "LINK_ONCE_SAME_CONTENTS";
- break;
- }
- printf ("%s%s", comma, ls);
-
- comdat = bfd_coff_get_comdat_section (abfd, section);
- if (comdat != NULL)
- printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol);
-
- comma = ", ";
- }
-
- printf ("\n");
-#undef PF
-}
-
-static void
-dump_headers (bfd *abfd)
-{
- printf (_("Sections:\n"));
-
-#ifndef BFD64
- printf (_("Idx Name Size VMA LMA File off Algn"));
-#else
- /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
- if (bfd_get_arch_size (abfd) == 32)
- printf (_("Idx Name Size VMA LMA File off Algn"));
- else
- printf (_("Idx Name Size VMA LMA File off Algn"));
-#endif
-
- if (wide_output)
- printf (_(" Flags"));
- if (abfd->flags & HAS_LOAD_PAGE)
- printf (_(" Pg"));
- printf ("\n");
-
- bfd_map_over_sections (abfd, dump_section_header, NULL);
-}
-
-static asymbol **
-slurp_symtab (bfd *abfd)
-{
- asymbol **sy = NULL;
- long storage;
-
- if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
- {
- symcount = 0;
- return NULL;
- }
-
- storage = bfd_get_symtab_upper_bound (abfd);
- if (storage < 0)
- bfd_fatal (bfd_get_filename (abfd));
- if (storage)
- sy = xmalloc (storage);
-
- symcount = bfd_canonicalize_symtab (abfd, sy);
- if (symcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
- return sy;
-}
-
-/* Read in the dynamic symbols. */
-
-static asymbol **
-slurp_dynamic_symtab (bfd *abfd)
-{
- asymbol **sy = NULL;
- long storage;
-
- storage = bfd_get_dynamic_symtab_upper_bound (abfd);
- if (storage < 0)
- {
- if (!(bfd_get_file_flags (abfd) & DYNAMIC))
- {
- non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
- dynsymcount = 0;
- return NULL;
- }
-
- bfd_fatal (bfd_get_filename (abfd));
- }
- if (storage)
- sy = xmalloc (storage);
-
- dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
- if (dynsymcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
- return sy;
-}
-
-/* Filter out (in place) symbols that are useless for disassembly.
- COUNT is the number of elements in SYMBOLS.
- Return the number of useful symbols. */
-
-static long
-remove_useless_symbols (asymbol **symbols, long count)
-{
- asymbol **in_ptr = symbols, **out_ptr = symbols;
-
- while (--count >= 0)
- {
- asymbol *sym = *in_ptr++;
-
- if (sym->name == NULL || sym->name[0] == '\0')
- continue;
- if (sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM))
- continue;
- if (bfd_is_und_section (sym->section)
- || bfd_is_com_section (sym->section))
- continue;
-
- *out_ptr++ = sym;
- }
- return out_ptr - symbols;
-}
-
-/* Sort symbols into value order. */
-
-static int
-compare_symbols (const void *ap, const void *bp)
-{
- const asymbol *a = * (const asymbol **) ap;
- const asymbol *b = * (const asymbol **) bp;
- const char *an;
- const char *bn;
- size_t anl;
- size_t bnl;
- bfd_boolean af;
- bfd_boolean bf;
- flagword aflags;
- flagword bflags;
-
- if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
- return 1;
- else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
- return -1;
-
- if (a->section > b->section)
- return 1;
- else if (a->section < b->section)
- return -1;
-
- an = bfd_asymbol_name (a);
- bn = bfd_asymbol_name (b);
- anl = strlen (an);
- bnl = strlen (bn);
-
- /* The symbols gnu_compiled and gcc2_compiled convey no real
- information, so put them after other symbols with the same value. */
- af = (strstr (an, "gnu_compiled") != NULL
- || strstr (an, "gcc2_compiled") != NULL);
- bf = (strstr (bn, "gnu_compiled") != NULL
- || strstr (bn, "gcc2_compiled") != NULL);
-
- if (af && ! bf)
- return 1;
- if (! af && bf)
- return -1;
-
- /* We use a heuristic for the file name, to try to sort it after
- more useful symbols. It may not work on non Unix systems, but it
- doesn't really matter; the only difference is precisely which
- symbol names get printed. */
-
-#define file_symbol(s, sn, snl) \
- (((s)->flags & BSF_FILE) != 0 \
- || ((sn)[(snl) - 2] == '.' \
- && ((sn)[(snl) - 1] == 'o' \
- || (sn)[(snl) - 1] == 'a')))
-
- af = file_symbol (a, an, anl);
- bf = file_symbol (b, bn, bnl);
-
- if (af && ! bf)
- return 1;
- if (! af && bf)
- return -1;
-
- /* Try to sort global symbols before local symbols before function
- symbols before debugging symbols. */
-
- aflags = a->flags;
- bflags = b->flags;
-
- if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
- {
- if ((aflags & BSF_DEBUGGING) != 0)
- return 1;
- else
- return -1;
- }
- if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
- {
- if ((aflags & BSF_FUNCTION) != 0)
- return -1;
- else
- return 1;
- }
- if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
- {
- if ((aflags & BSF_LOCAL) != 0)
- return 1;
- else
- return -1;
- }
- if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
- {
- if ((aflags & BSF_GLOBAL) != 0)
- return -1;
- else
- return 1;
- }
-
- /* Symbols that start with '.' might be section names, so sort them
- after symbols that don't start with '.'. */
- if (an[0] == '.' && bn[0] != '.')
- return 1;
- if (an[0] != '.' && bn[0] == '.')
- return -1;
-
- /* Finally, if we can't distinguish them in any other way, try to
- get consistent results by sorting the symbols by name. */
- return strcmp (an, bn);
-}
-
-/* Sort relocs into address order. */
-
-static int
-compare_relocs (const void *ap, const void *bp)
-{
- const arelent *a = * (const arelent **) ap;
- const arelent *b = * (const arelent **) bp;
-
- if (a->address > b->address)
- return 1;
- else if (a->address < b->address)
- return -1;
-
- /* So that associated relocations tied to the same address show up
- in the correct order, we don't do any further sorting. */
- if (a > b)
- return 1;
- else if (a < b)
- return -1;
- else
- return 0;
-}
-
-/* Print an address (VMA) to the output stream in INFO.
- If SKIP_ZEROES is TRUE, omit leading zeroes. */
-
-static void
-objdump_print_value (bfd_vma vma, struct disassemble_info *info,
- bfd_boolean skip_zeroes)
-{
- char buf[30];
- char *p;
- struct objdump_disasm_info *aux;
-
- aux = (struct objdump_disasm_info *) info->application_data;
- bfd_sprintf_vma (aux->abfd, buf, vma);
- if (! skip_zeroes)
- p = buf;
- else
- {
- for (p = buf; *p == '0'; ++p)
- ;
- if (*p == '\0')
- --p;
- }
- (*info->fprintf_func) (info->stream, "%s", p);
-}
-
-/* Print the name of a symbol. */
-
-static void
-objdump_print_symname (bfd *abfd, struct disassemble_info *info,
- asymbol *sym)
-{
- char *alloc;
- const char *name;
-
- alloc = NULL;
- name = bfd_asymbol_name (sym);
- if (do_demangle && name[0] != '\0')
- {
- /* Demangle the name. */
- alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
- if (alloc != NULL)
- name = alloc;
- }
-
- if (info != NULL)
- (*info->fprintf_func) (info->stream, "%s", name);
- else
- printf ("%s", name);
-
- if (alloc != NULL)
- free (alloc);
-}
-
-/* Locate a symbol given a bfd and a section (from INFO->application_data),
- and a VMA. If INFO->application_data->require_sec is TRUE, then always
- require the symbol to be in the section. Returns NULL if there is no
- suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
- of the symbol in sorted_syms. */
-
-static asymbol *
-find_symbol_for_address (bfd_vma vma,
- struct disassemble_info *info,
- long *place)
-{
- /* @@ Would it speed things up to cache the last two symbols returned,
- and maybe their address ranges? For many processors, only one memory
- operand can be present at a time, so the 2-entry cache wouldn't be
- constantly churned by code doing heavy memory accesses. */
-
- /* Indices in `sorted_syms'. */
- long min = 0;
- long max = sorted_symcount;
- long thisplace;
- struct objdump_disasm_info *aux;
- bfd *abfd;
- asection *sec;
- unsigned int opb;
- bfd_boolean want_section;
-
- if (sorted_symcount < 1)
- return NULL;
-
- aux = (struct objdump_disasm_info *) info->application_data;
- abfd = aux->abfd;
- sec = aux->sec;
- opb = bfd_octets_per_byte (abfd);
-
- /* Perform a binary search looking for the closest symbol to the
- required value. We are searching the range (min, max]. */
- while (min + 1 < max)
- {
- asymbol *sym;
-
- thisplace = (max + min) / 2;
- sym = sorted_syms[thisplace];
-
- if (bfd_asymbol_value (sym) > vma)
- max = thisplace;
- else if (bfd_asymbol_value (sym) < vma)
- min = thisplace;
- else
- {
- min = thisplace;
- break;
- }
- }
-
- /* The symbol we want is now in min, the low end of the range we
- were searching. If there are several symbols with the same
- value, we want the first one. */
- thisplace = min;
- while (thisplace > 0
- && (bfd_asymbol_value (sorted_syms[thisplace])
- == bfd_asymbol_value (sorted_syms[thisplace - 1])))
- --thisplace;
-
- /* Prefer a symbol in the current section if we have multple symbols
- with the same value, as can occur with overlays or zero size
- sections. */
- min = thisplace;
- while (min < max
- && (bfd_asymbol_value (sorted_syms[min])
- == bfd_asymbol_value (sorted_syms[thisplace])))
- {
- if (sorted_syms[min]->section == sec
- && info->symbol_is_valid (sorted_syms[min], info))
- {
- thisplace = min;
-
- if (place != NULL)
- *place = thisplace;
-
- return sorted_syms[thisplace];
- }
- ++min;
- }
-
- /* If the file is relocatable, and the symbol could be from this
- section, prefer a symbol from this section over symbols from
- others, even if the other symbol's value might be closer.
-
- Note that this may be wrong for some symbol references if the
- sections have overlapping memory ranges, but in that case there's
- no way to tell what's desired without looking at the relocation
- table.
-
- Also give the target a chance to reject symbols. */
- want_section = (aux->require_sec
- || ((abfd->flags & HAS_RELOC) != 0
- && vma >= bfd_get_section_vma (abfd, sec)
- && vma < (bfd_get_section_vma (abfd, sec)
- + bfd_section_size (abfd, sec) / opb)));
- if ((sorted_syms[thisplace]->section != sec && want_section)
- || !info->symbol_is_valid (sorted_syms[thisplace], info))
- {
- long i;
- long newplace = sorted_symcount;
-
- for (i = min - 1; i >= 0; i--)
- {
- if ((sorted_syms[i]->section == sec || !want_section)
- && info->symbol_is_valid (sorted_syms[i], info))
- {
- if (newplace == sorted_symcount)
- newplace = i;
-
- if (bfd_asymbol_value (sorted_syms[i])
- != bfd_asymbol_value (sorted_syms[newplace]))
- break;
-
- /* Remember this symbol and keep searching until we reach
- an earlier address. */
- newplace = i;
- }
- }
-
- if (newplace != sorted_symcount)
- thisplace = newplace;
- else
- {
- /* We didn't find a good symbol with a smaller value.
- Look for one with a larger value. */
- for (i = thisplace + 1; i < sorted_symcount; i++)
- {
- if ((sorted_syms[i]->section == sec || !want_section)
- && info->symbol_is_valid (sorted_syms[i], info))
- {
- thisplace = i;
- break;
- }
- }
- }
-
- if ((sorted_syms[thisplace]->section != sec && want_section)
- || !info->symbol_is_valid (sorted_syms[thisplace], info))
- /* There is no suitable symbol. */
- return NULL;
- }
-
- if (place != NULL)
- *place = thisplace;
-
- return sorted_syms[thisplace];
-}
-
-/* Print an address and the offset to the nearest symbol. */
-
-static void
-objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
- bfd_vma vma, struct disassemble_info *info,
- bfd_boolean skip_zeroes)
-{
- objdump_print_value (vma, info, skip_zeroes);
-
- if (sym == NULL)
- {
- bfd_vma secaddr;
-
- (*info->fprintf_func) (info->stream, " <%s",
- bfd_get_section_name (abfd, sec));
- secaddr = bfd_get_section_vma (abfd, sec);
- if (vma < secaddr)
- {
- (*info->fprintf_func) (info->stream, "-0x");
- objdump_print_value (secaddr - vma, info, TRUE);
- }
- else if (vma > secaddr)
- {
- (*info->fprintf_func) (info->stream, "+0x");
- objdump_print_value (vma - secaddr, info, TRUE);
- }
- (*info->fprintf_func) (info->stream, ">");
- }
- else
- {
- (*info->fprintf_func) (info->stream, " <");
- objdump_print_symname (abfd, info, sym);
- if (bfd_asymbol_value (sym) > vma)
- {
- (*info->fprintf_func) (info->stream, "-0x");
- objdump_print_value (bfd_asymbol_value (sym) - vma, info, TRUE);
- }
- else if (vma > bfd_asymbol_value (sym))
- {
- (*info->fprintf_func) (info->stream, "+0x");
- objdump_print_value (vma - bfd_asymbol_value (sym), info, TRUE);
- }
- (*info->fprintf_func) (info->stream, ">");
- }
-
- if (display_file_offsets)
- info->fprintf_func (info->stream, _(" (File Offset: 0x%lx)"),
- (long int)(sec->filepos + (vma - sec->vma)));
-}
-
-/* Print an address (VMA), symbolically if possible.
- If SKIP_ZEROES is TRUE, don't output leading zeroes. */
-
-static void
-objdump_print_addr (bfd_vma vma,
- struct disassemble_info *info,
- bfd_boolean skip_zeroes)
-{
- struct objdump_disasm_info *aux;
- asymbol *sym = NULL;
- bfd_boolean skip_find = FALSE;
-
- aux = (struct objdump_disasm_info *) info->application_data;
-
- if (sorted_symcount < 1)
- {
- (*info->fprintf_func) (info->stream, "0x");
- objdump_print_value (vma, info, skip_zeroes);
-
- if (display_file_offsets)
- info->fprintf_func (info->stream, _(" (File Offset: 0x%lx)"),
- (long int)(aux->sec->filepos + (vma - aux->sec->vma)));
- return;
- }
-
- if (aux->reloc != NULL
- && aux->reloc->sym_ptr_ptr != NULL
- && * aux->reloc->sym_ptr_ptr != NULL)
- {
- sym = * aux->reloc->sym_ptr_ptr;
-
- /* Adjust the vma to the reloc. */
- vma += bfd_asymbol_value (sym);
-
- if (bfd_is_und_section (bfd_get_section (sym)))
- skip_find = TRUE;
- }
-
- if (!skip_find)
- sym = find_symbol_for_address (vma, info, NULL);
-
- objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
- skip_zeroes);
-}
-
-/* Print VMA to INFO. This function is passed to the disassembler
- routine. */
-
-static void
-objdump_print_address (bfd_vma vma, struct disassemble_info *info)
-{
- objdump_print_addr (vma, info, ! prefix_addresses);
-}
-
-/* Determine if the given address has a symbol associated with it. */
-
-static int
-objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * info)
-{
- asymbol * sym;
-
- sym = find_symbol_for_address (vma, info, NULL);
-
- return (sym != NULL && (bfd_asymbol_value (sym) == vma));
-}
-
-/* Hold the last function name and the last line number we displayed
- in a disassembly. */
-
-static char *prev_functionname;
-static unsigned int prev_line;
-
-/* We keep a list of all files that we have seen when doing a
- disassembly with source, so that we know how much of the file to
- display. This can be important for inlined functions. */
-
-struct print_file_list
-{
- struct print_file_list *next;
- const char *filename;
- const char *modname;
- const char *map;
- size_t mapsize;
- const char **linemap;
- unsigned maxline;
- unsigned last_line;
- int first;
-};
-
-static struct print_file_list *print_files;
-
-/* The number of preceding context lines to show when we start
- displaying a file for the first time. */
-
-#define SHOW_PRECEDING_CONTEXT_LINES (5)
-
-/* Read a complete file into memory. */
-
-static const char *
-slurp_file (const char *fn, size_t *size)
-{
-#ifdef HAVE_MMAP
- int ps = getpagesize ();
- size_t msize;
-#endif
- const char *map;
- struct stat st;
- int fd = open (fn, O_RDONLY | O_BINARY);
-
- if (fd < 0)
- return NULL;
- if (fstat (fd, &st) < 0)
- return NULL;
- *size = st.st_size;
-#ifdef HAVE_MMAP
- msize = (*size + ps - 1) & ~(ps - 1);
- map = mmap (NULL, msize, PROT_READ, MAP_SHARED, fd, 0);
- if (map != (char *)-1L)
- {
- close(fd);
- return map;
- }
-#endif
- map = malloc (*size);
- if (!map || (size_t) read (fd, (char *)map, *size) != *size)
- {
- free ((void *)map);
- map = NULL;
- }
- close (fd);
- return map;
-}
-
-#define line_map_decrease 5
-
-/* Precompute array of lines for a mapped file. */
-
-static const char **
-index_file (const char *map, size_t size, unsigned int *maxline)
-{
- const char *p, *lstart, *end;
- int chars_per_line = 45; /* First iteration will use 40. */
- unsigned int lineno;
- const char **linemap = NULL;
- unsigned long line_map_size = 0;
-
- lineno = 0;
- lstart = map;
- end = map + size;
-
- for (p = map; p < end; p++)
- {
- if (*p == '\n')
- {
- if (p + 1 < end && p[1] == '\r')
- p++;
- }
- else if (*p == '\r')
- {
- if (p + 1 < end && p[1] == '\n')
- p++;
- }
- else
- continue;
-
- /* End of line found. */
-
- if (linemap == NULL || line_map_size < lineno + 1)
- {
- unsigned long newsize;
-
- chars_per_line -= line_map_decrease;
- if (chars_per_line <= 1)
- chars_per_line = 1;
- line_map_size = size / chars_per_line + 1;
- if (line_map_size < lineno + 1)
- line_map_size = lineno + 1;
- newsize = line_map_size * sizeof (char *);
- linemap = xrealloc (linemap, newsize);
- }
-
- linemap[lineno++] = lstart;
- lstart = p + 1;
- }
-
- *maxline = lineno;
- return linemap;
-}
-
-/* Tries to open MODNAME, and if successful adds a node to print_files
- linked list and returns that node. Returns NULL on failure. */
-
-static struct print_file_list *
-try_print_file_open (const char *origname, const char *modname)
-{
- struct print_file_list *p;
-
- p = xmalloc (sizeof (struct print_file_list));
-
- p->map = slurp_file (modname, &p->mapsize);
- if (p->map == NULL)
- {
- free (p);
- return NULL;
- }
-
- p->linemap = index_file (p->map, p->mapsize, &p->maxline);
- p->last_line = 0;
- p->filename = origname;
- p->modname = modname;
- p->next = print_files;
- p->first = 1;
- print_files = p;
- return p;
-}
-
-/* If the the source file, as described in the symtab, is not found
- try to locate it in one of the paths specified with -I
- If found, add location to print_files linked list. */
-
-static struct print_file_list *
-update_source_path (const char *filename)
-{
- struct print_file_list *p;
- const char *fname;
- int i;
-
- if (filename == NULL)
- return NULL;
-
- p = try_print_file_open (filename, filename);
- if (p != NULL)
- return p;
-
- if (include_path_count == 0)
- return NULL;
-
- /* Get the name of the file. */
- fname = strrchr (filename, '/');
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
- {
- /* We could have a mixed forward/back slash case. */
- char *backslash = strrchr (filename, '\\');
- if (fname == NULL || (backslash != NULL && backslash > fname))
- fname = backslash;
- if (fname == NULL && filename[0] != '\0' && filename[1] == ':')
- fname = filename + 1;
- }
-#endif
- if (fname == NULL)
- fname = filename;
- else
- ++fname;
-
- /* If file exists under a new path, we need to add it to the list
- so that show_line knows about it. */
- for (i = 0; i < include_path_count; i++)
- {
- char *modname = concat (include_paths[i], "/", fname, (const char *) 0);
-
- p = try_print_file_open (filename, modname);
- if (p)
- return p;
-
- free (modname);
- }
-
- return NULL;
-}
-
-/* Print a source file line. */
-
-static void
-print_line (struct print_file_list *p, unsigned int line)
-{
- const char *l;
- size_t len;
-
- --line;
- if (line >= p->maxline)
- return;
- l = p->linemap [line];
- /* Test fwrite return value to quiet glibc warning. */
- len = strcspn (l, "\n\r");
- if (len == 0 || fwrite (l, len, 1, stdout) == 1)
- putchar ('\n');
-}
-
-/* Print a range of source code lines. */
-
-static void
-dump_lines (struct print_file_list *p, unsigned int start, unsigned int end)
-{
- if (p->map == NULL)
- return;
- while (start <= end)
- {
- print_line (p, start);
- start++;
- }
-}
-
-/* Show the line number, or the source line, in a disassembly
- listing. */
-
-static void
-show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
-{
- const char *filename;
- const char *functionname;
- unsigned int line;
-
- if (! with_line_numbers && ! with_source_code)
- return;
-
- if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename,
- &functionname, &line))
- return;
-
- if (filename != NULL && *filename == '\0')
- filename = NULL;
- if (functionname != NULL && *functionname == '\0')
- functionname = NULL;
-
- if (with_line_numbers)
- {
- if (functionname != NULL
- && (prev_functionname == NULL
- || strcmp (functionname, prev_functionname) != 0))
- printf ("%s():\n", functionname);
- if (line > 0 && line != prev_line)
- printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
- }
-
- if (with_source_code
- && filename != NULL
- && line > 0)
- {
- struct print_file_list **pp, *p;
- unsigned l;
-
- for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
- if (strcmp ((*pp)->filename, filename) == 0)
- break;
- p = *pp;
-
- if (p == NULL)
- p = update_source_path (filename);
-
- if (p != NULL && line != p->last_line)
- {
- if (file_start_context && p->first)
- l = 1;
- else
- {
- l = line - SHOW_PRECEDING_CONTEXT_LINES;
- if (l >= line)
- l = 1;
- if (p->last_line >= l && p->last_line <= line)
- l = p->last_line + 1;
- }
- dump_lines (p, l, line);
- p->last_line = line;
- p->first = 0;
- }
- }
-
- if (functionname != NULL
- && (prev_functionname == NULL
- || strcmp (functionname, prev_functionname) != 0))
- {
- if (prev_functionname != NULL)
- free (prev_functionname);
- prev_functionname = xmalloc (strlen (functionname) + 1);
- strcpy (prev_functionname, functionname);
- }
-
- if (line > 0 && line != prev_line)
- prev_line = line;
-}
-
-/* Pseudo FILE object for strings. */
-typedef struct
-{
- char *buffer;
- size_t pos;
- size_t alloc;
-} SFILE;
-
-/* sprintf to a "stream". */
-
-static int ATTRIBUTE_PRINTF_2
-objdump_sprintf (SFILE *f, const char *format, ...)
-{
- size_t n;
- va_list args;
-
- while (1)
- {
- size_t space = f->alloc - f->pos;
-
- va_start (args, format);
- n = vsnprintf (f->buffer + f->pos, space, format, args);
- va_end (args);
-
- if (space > n)
- break;
-
- f->alloc = (f->alloc + n) * 2;
- f->buffer = xrealloc (f->buffer, f->alloc);
- }
- f->pos += n;
-
- return n;
-}
-
-/* Returns TRUE if the specified section should be dumped. */
-
-static bfd_boolean
-process_section_p (asection * section)
-{
- size_t i;
-
- if (only == NULL)
- return TRUE;
-
- for (i = 0; i < only_used; i++)
- if (strcmp (only [i], section->name) == 0)
- return TRUE;
-
- return FALSE;
-}
-
-
-/* The number of zeroes we want to see before we start skipping them.
- The number is arbitrarily chosen. */
-
-#define DEFAULT_SKIP_ZEROES 8
-
-/* The number of zeroes to skip at the end of a section. If the
- number of zeroes at the end is between SKIP_ZEROES_AT_END and
- SKIP_ZEROES, they will be disassembled. If there are fewer than
- SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
- attempt to avoid disassembling zeroes inserted by section
- alignment. */
-
-#define DEFAULT_SKIP_ZEROES_AT_END 3
-
-/* Disassemble some data in memory between given values. */
-
-static void
-disassemble_bytes (struct disassemble_info * info,
- disassembler_ftype disassemble_fn,
- bfd_boolean insns,
- bfd_byte * data,
- bfd_vma start_offset,
- bfd_vma stop_offset,
- bfd_vma rel_offset,
- arelent *** relppp,
- arelent ** relppend)
-{
- struct objdump_disasm_info *aux;
- asection *section;
- int octets_per_line;
- bfd_boolean done_dot;
- int skip_addr_chars;
- bfd_vma addr_offset;
- unsigned int opb = info->octets_per_byte;
- unsigned int skip_zeroes = info->skip_zeroes;
- unsigned int skip_zeroes_at_end = info->skip_zeroes_at_end;
- int octets = opb;
- SFILE sfile;
-
- aux = (struct objdump_disasm_info *) info->application_data;
- section = aux->sec;
-
- sfile.alloc = 120;
- sfile.buffer = xmalloc (sfile.alloc);
- sfile.pos = 0;
-
- if (insns)
- octets_per_line = 4;
- else
- octets_per_line = 16;
-
- /* Figure out how many characters to skip at the start of an
- address, to make the disassembly look nicer. We discard leading
- zeroes in chunks of 4, ensuring that there is always a leading
- zero remaining. */
- skip_addr_chars = 0;
- if (! prefix_addresses)
- {
- char buf[30];
- char *s;
-
- bfd_sprintf_vma
- (aux->abfd, buf,
- (section->vma
- + bfd_section_size (section->owner, section) / opb));
- s = buf;
- while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
- && s[4] == '0')
- {
- skip_addr_chars += 4;
- s += 4;
- }
- }
-
- info->insn_info_valid = 0;
-
- done_dot = FALSE;
- addr_offset = start_offset;
- while (addr_offset < stop_offset)
- {
- bfd_vma z;
- bfd_boolean need_nl = FALSE;
- int previous_octets;
-
- /* Remember the length of the previous instruction. */
- previous_octets = octets;
- octets = 0;
-
- /* If we see more than SKIP_ZEROES octets of zeroes, we just
- print `...'. */
- for (z = addr_offset * opb; z < stop_offset * opb; z++)
- if (data[z] != 0)
- break;
- if (! disassemble_zeroes
- && (info->insn_info_valid == 0
- || info->branch_delay_insns == 0)
- && (z - addr_offset * opb >= skip_zeroes
- || (z == stop_offset * opb &&
- z - addr_offset * opb < skip_zeroes_at_end)))
- {
- /* If there are more nonzero octets to follow, we only skip
- zeroes in multiples of 4, to try to avoid running over
- the start of an instruction which happens to start with
- zero. */
- if (z != stop_offset * opb)
- z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
-
- octets = z - addr_offset * opb;
-
- /* If we are going to display more data, and we are displaying
- file offsets, then tell the user how many zeroes we skip
- and the file offset from where we resume dumping. */
- if (display_file_offsets && ((addr_offset + (octets / opb)) < stop_offset))
- printf ("\t... (skipping %d zeroes, resuming at file offset: 0x%lx)\n",
- octets / opb,
- (unsigned long) (section->filepos
- + (addr_offset + (octets / opb))));
- else
- printf ("\t...\n");
- }
- else
- {
- char buf[50];
- int bpc = 0;
- int pb = 0;
-
- done_dot = FALSE;
-
- if (with_line_numbers || with_source_code)
- show_line (aux->abfd, section, addr_offset);
-
- if (! prefix_addresses)
- {
- char *s;
-
- bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
- for (s = buf + skip_addr_chars; *s == '0'; s++)
- *s = ' ';
- if (*s == '\0')
- *--s = '0';
- printf ("%s:\t", buf + skip_addr_chars);
- }
- else
- {
- aux->require_sec = TRUE;
- objdump_print_address (section->vma + addr_offset, info);
- aux->require_sec = FALSE;
- putchar (' ');
- }
-
- if (insns)
- {
- sfile.pos = 0;
- info->fprintf_func = (fprintf_ftype) objdump_sprintf;
- info->stream = &sfile;
- info->bytes_per_line = 0;
- info->bytes_per_chunk = 0;
- info->flags = 0;
-
- if (info->disassembler_needs_relocs
- && (bfd_get_file_flags (aux->abfd) & EXEC_P) == 0
- && (bfd_get_file_flags (aux->abfd) & DYNAMIC) == 0
- && *relppp < relppend)
- {
- bfd_signed_vma distance_to_rel;
-
- distance_to_rel = (**relppp)->address
- - (rel_offset + addr_offset);
-
- /* Check to see if the current reloc is associated with
- the instruction that we are about to disassemble. */
- if (distance_to_rel == 0
- /* FIXME: This is wrong. We are trying to catch
- relocs that are addressed part way through the
- current instruction, as might happen with a packed
- VLIW instruction. Unfortunately we do not know the
- length of the current instruction since we have not
- disassembled it yet. Instead we take a guess based
- upon the length of the previous instruction. The
- proper solution is to have a new target-specific
- disassembler function which just returns the length
- of an instruction at a given address without trying
- to display its disassembly. */
- || (distance_to_rel > 0
- && distance_to_rel < (bfd_signed_vma) (previous_octets/ opb)))
- {
- info->flags = INSN_HAS_RELOC;
- aux->reloc = **relppp;
- }
- else
- aux->reloc = NULL;
- }
-
- octets = (*disassemble_fn) (section->vma + addr_offset, info);
- info->fprintf_func = (fprintf_ftype) fprintf;
- info->stream = stdout;
- if (info->bytes_per_line != 0)
- octets_per_line = info->bytes_per_line;
- if (octets < 0)
- {
- if (sfile.pos)
- printf ("%s\n", sfile.buffer);
- break;
- }
- }
- else
- {
- bfd_vma j;
-
- octets = octets_per_line;
- if (addr_offset + octets / opb > stop_offset)
- octets = (stop_offset - addr_offset) * opb;
-
- for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
- {
- if (ISPRINT (data[j]))
- buf[j - addr_offset * opb] = data[j];
- else
- buf[j - addr_offset * opb] = '.';
- }
- buf[j - addr_offset * opb] = '\0';
- }
-
- if (prefix_addresses
- ? show_raw_insn > 0
- : show_raw_insn >= 0)
- {
- bfd_vma j;
-
- /* If ! prefix_addresses and ! wide_output, we print
- octets_per_line octets per line. */
- pb = octets;
- if (pb > octets_per_line && ! prefix_addresses && ! wide_output)
- pb = octets_per_line;
-
- if (info->bytes_per_chunk)
- bpc = info->bytes_per_chunk;
- else
- bpc = 1;
-
- for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
- {
- int k;
-
- if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
- {
- for (k = bpc - 1; k >= 0; k--)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- else
- {
- for (k = 0; k < bpc; k++)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- }
-
- for (; pb < octets_per_line; pb += bpc)
- {
- int k;
-
- for (k = 0; k < bpc; k++)
- printf (" ");
- putchar (' ');
- }
-
- /* Separate raw data from instruction by extra space. */
- if (insns)
- putchar ('\t');
- else
- printf (" ");
- }
-
- if (! insns)
- printf ("%s", buf);
- else if (sfile.pos)
- printf ("%s", sfile.buffer);
-
- if (prefix_addresses
- ? show_raw_insn > 0
- : show_raw_insn >= 0)
- {
- while (pb < octets)
- {
- bfd_vma j;
- char *s;
-
- putchar ('\n');
- j = addr_offset * opb + pb;
-
- bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
- for (s = buf + skip_addr_chars; *s == '0'; s++)
- *s = ' ';
- if (*s == '\0')
- *--s = '0';
- printf ("%s:\t", buf + skip_addr_chars);
-
- pb += octets_per_line;
- if (pb > octets)
- pb = octets;
- for (; j < addr_offset * opb + pb; j += bpc)
- {
- int k;
-
- if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
- {
- for (k = bpc - 1; k >= 0; k--)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- else
- {
- for (k = 0; k < bpc; k++)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- }
- }
- }
-
- if (!wide_output)
- putchar ('\n');
- else
- need_nl = TRUE;
- }
-
- while ((*relppp) < relppend
- && (**relppp)->address < rel_offset + addr_offset + octets / opb)
- {
- if (dump_reloc_info || dump_dynamic_reloc_info)
- {
- arelent *q;
-
- q = **relppp;
-
- if (wide_output)
- putchar ('\t');
- else
- printf ("\t\t\t");
-
- objdump_print_value (section->vma - rel_offset + q->address,
- info, TRUE);
-
- if (q->howto == NULL)
- printf (": *unknown*\t");
- else if (q->howto->name)
- printf (": %s\t", q->howto->name);
- else
- printf (": %d\t", q->howto->type);
-
- if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
- printf ("*unknown*");
- else
- {
- const char *sym_name;
-
- sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
- if (sym_name != NULL && *sym_name != '\0')
- objdump_print_symname (aux->abfd, info, *q->sym_ptr_ptr);
- else
- {
- asection *sym_sec;
-
- sym_sec = bfd_get_section (*q->sym_ptr_ptr);
- sym_name = bfd_get_section_name (aux->abfd, sym_sec);
- if (sym_name == NULL || *sym_name == '\0')
- sym_name = "*unknown*";
- printf ("%s", sym_name);
- }
- }
-
- if (q->addend)
- {
- printf ("+0x");
- objdump_print_value (q->addend, info, TRUE);
- }
-
- printf ("\n");
- need_nl = FALSE;
- }
- ++(*relppp);
- }
-
- if (need_nl)
- printf ("\n");
-
- addr_offset += octets / opb;
- }
-
- free (sfile.buffer);
-}
-
-static void
-disassemble_section (bfd *abfd, asection *section, void *info)
-{
- struct disassemble_info * pinfo = (struct disassemble_info *) info;
- struct objdump_disasm_info * paux;
- unsigned int opb = pinfo->octets_per_byte;
- bfd_byte * data = NULL;
- bfd_size_type datasize = 0;
- arelent ** rel_pp = NULL;
- arelent ** rel_ppstart = NULL;
- arelent ** rel_ppend;
- unsigned long stop_offset;
- asymbol * sym = NULL;
- long place = 0;
- long rel_count;
- bfd_vma rel_offset;
- unsigned long addr_offset;
-
- /* Sections that do not contain machine
- code are not normally disassembled. */
- if (! disassemble_all
- && only == NULL
- && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
- != (SEC_CODE | SEC_HAS_CONTENTS)))
- return;
-
- if (! process_section_p (section))
- return;
-
- datasize = bfd_get_section_size (section);
- if (datasize == 0)
- return;
-
- /* Decide which set of relocs to use. Load them if necessary. */
- paux = (struct objdump_disasm_info *) pinfo->application_data;
- if (paux->dynrelbuf)
- {
- rel_pp = paux->dynrelbuf;
- rel_count = paux->dynrelcount;
- /* Dynamic reloc addresses are absolute, non-dynamic are section
- relative. REL_OFFSET specifies the reloc address corresponding
- to the start of this section. */
- rel_offset = section->vma;
- }
- else
- {
- rel_count = 0;
- rel_pp = NULL;
- rel_offset = 0;
-
- if ((section->flags & SEC_RELOC) != 0
- && (dump_reloc_info || pinfo->disassembler_needs_relocs))
- {
- long relsize;
-
- relsize = bfd_get_reloc_upper_bound (abfd, section);
- if (relsize < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- if (relsize > 0)
- {
- rel_ppstart = rel_pp = xmalloc (relsize);
- rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms);
- if (rel_count < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- /* Sort the relocs by address. */
- qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs);
- }
- }
-
- }
- rel_ppend = rel_pp + rel_count;
-
- data = xmalloc (datasize);
-
- bfd_get_section_contents (abfd, section, data, 0, datasize);
-
- paux->sec = section;
- pinfo->buffer = data;
- pinfo->buffer_vma = section->vma;
- pinfo->buffer_length = datasize;
- pinfo->section = section;
-
- if (start_address == (bfd_vma) -1
- || start_address < pinfo->buffer_vma)
- addr_offset = 0;
- else
- addr_offset = start_address - pinfo->buffer_vma;
-
- if (stop_address == (bfd_vma) -1)
- stop_offset = datasize / opb;
- else
- {
- if (stop_address < pinfo->buffer_vma)
- stop_offset = 0;
- else
- stop_offset = stop_address - pinfo->buffer_vma;
- if (stop_offset > pinfo->buffer_length / opb)
- stop_offset = pinfo->buffer_length / opb;
- }
-
- /* Skip over the relocs belonging to addresses below the
- start address. */
- while (rel_pp < rel_ppend
- && (*rel_pp)->address < rel_offset + addr_offset)
- ++rel_pp;
-
- if (addr_offset < stop_offset)
- printf (_("\nDisassembly of section %s:\n"), section->name);
-
- /* Find the nearest symbol forwards from our current position. */
- paux->require_sec = TRUE;
- sym = find_symbol_for_address (section->vma + addr_offset, info, &place);
- paux->require_sec = FALSE;
-
- /* Disassemble a block of instructions up to the address associated with
- the symbol we have just found. Then print the symbol and find the
- next symbol on. Repeat until we have disassembled the entire section
- or we have reached the end of the address range we are interested in. */
- while (addr_offset < stop_offset)
- {
- bfd_vma addr;
- asymbol *nextsym;
- unsigned long nextstop_offset;
- bfd_boolean insns;
-
- addr = section->vma + addr_offset;
-
- if (sym != NULL && bfd_asymbol_value (sym) <= addr)
- {
- int x;
-
- for (x = place;
- (x < sorted_symcount
- && (bfd_asymbol_value (sorted_syms[x]) <= addr));
- ++x)
- continue;
-
- pinfo->symbols = sorted_syms + place;
- pinfo->num_symbols = x - place;
- pinfo->symtab_pos = place;
- }
- else
- {
- pinfo->symbols = NULL;
- pinfo->num_symbols = 0;
- pinfo->symtab_pos = -1;
- }
-
- if (! prefix_addresses)
- {
- pinfo->fprintf_func (pinfo->stream, "\n");
- objdump_print_addr_with_sym (abfd, section, sym, addr,
- pinfo, FALSE);
- pinfo->fprintf_func (pinfo->stream, ":\n");
- }
-
- if (sym != NULL && bfd_asymbol_value (sym) > addr)
- nextsym = sym;
- else if (sym == NULL)
- nextsym = NULL;
- else
- {
-#define is_valid_next_sym(SYM) \
- ((SYM)->section == section \
- && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
- && pinfo->symbol_is_valid (SYM, pinfo))
-
- /* Search forward for the next appropriate symbol in
- SECTION. Note that all the symbols are sorted
- together into one big array, and that some sections
- may have overlapping addresses. */
- while (place < sorted_symcount
- && ! is_valid_next_sym (sorted_syms [place]))
- ++place;
-
- if (place >= sorted_symcount)
- nextsym = NULL;
- else
- nextsym = sorted_syms[place];
- }
-
- if (sym != NULL && bfd_asymbol_value (sym) > addr)
- nextstop_offset = bfd_asymbol_value (sym) - section->vma;
- else if (nextsym == NULL)
- nextstop_offset = stop_offset;
- else
- nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
-
- if (nextstop_offset > stop_offset)
- nextstop_offset = stop_offset;
-
- /* If a symbol is explicitly marked as being an object
- rather than a function, just dump the bytes without
- disassembling them. */
- if (disassemble_all
- || sym == NULL
- || bfd_asymbol_value (sym) > addr
- || ((sym->flags & BSF_OBJECT) == 0
- && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
- == NULL)
- && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
- == NULL))
- || (sym->flags & BSF_FUNCTION) != 0)
- insns = TRUE;
- else
- insns = FALSE;
-
- disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
- addr_offset, nextstop_offset,
- rel_offset, &rel_pp, rel_ppend);
-
- addr_offset = nextstop_offset;
- sym = nextsym;
- }
-
- free (data);
-
- if (rel_ppstart != NULL)
- free (rel_ppstart);
-}
-
-/* Disassemble the contents of an object file. */
-
-static void
-disassemble_data (bfd *abfd)
-{
- struct disassemble_info disasm_info;
- struct objdump_disasm_info aux;
- long i;
-
- print_files = NULL;
- prev_functionname = NULL;
- prev_line = -1;
-
- /* We make a copy of syms to sort. We don't want to sort syms
- because that will screw up the relocs. */
- sorted_symcount = symcount ? symcount : dynsymcount;
- sorted_syms = xmalloc ((sorted_symcount + synthcount) * sizeof (asymbol *));
- memcpy (sorted_syms, symcount ? syms : dynsyms,
- sorted_symcount * sizeof (asymbol *));
-
- sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
-
- for (i = 0; i < synthcount; ++i)
- {
- sorted_syms[sorted_symcount] = synthsyms + i;
- ++sorted_symcount;
- }
-
- /* Sort the symbols into section and symbol order. */
- qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
-
- init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
-
- disasm_info.application_data = (void *) &aux;
- aux.abfd = abfd;
- aux.require_sec = FALSE;
- aux.dynrelbuf = NULL;
- aux.dynrelcount = 0;
- aux.reloc = NULL;
-
- disasm_info.print_address_func = objdump_print_address;
- disasm_info.symbol_at_address_func = objdump_symbol_at_address;
-
- if (machine != NULL)
- {
- const bfd_arch_info_type *info = bfd_scan_arch (machine);
-
- if (info == NULL)
- fatal (_("Can't use supplied machine %s"), machine);
-
- abfd->arch_info = info;
- }
-
- if (endian != BFD_ENDIAN_UNKNOWN)
- {
- struct bfd_target *xvec;
-
- xvec = xmalloc (sizeof (struct bfd_target));
- memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
- xvec->byteorder = endian;
- abfd->xvec = xvec;
- }
-
- /* Use libopcodes to locate a suitable disassembler. */
- aux.disassemble_fn = disassembler (abfd);
- if (!aux.disassemble_fn)
- {
- non_fatal (_("Can't disassemble for architecture %s\n"),
- bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
- exit_status = 1;
- return;
- }
-
- disasm_info.flavour = bfd_get_flavour (abfd);
- disasm_info.arch = bfd_get_arch (abfd);
- disasm_info.mach = bfd_get_mach (abfd);
- disasm_info.disassembler_options = disassembler_options;
- disasm_info.octets_per_byte = bfd_octets_per_byte (abfd);
- disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
- disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
- disasm_info.disassembler_needs_relocs = FALSE;
-
- if (bfd_big_endian (abfd))
- disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
- else if (bfd_little_endian (abfd))
- disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
- else
- /* ??? Aborting here seems too drastic. We could default to big or little
- instead. */
- disasm_info.endian = BFD_ENDIAN_UNKNOWN;
-
- /* Allow the target to customize the info structure. */
- disassemble_init_for_target (& disasm_info);
-
- /* Pre-load the dynamic relocs if we are going
- to be dumping them along with the disassembly. */
- if (dump_dynamic_reloc_info)
- {
- long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
-
- if (relsize < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- if (relsize > 0)
- {
- aux.dynrelbuf = xmalloc (relsize);
- aux.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd,
- aux.dynrelbuf,
- dynsyms);
- if (aux.dynrelcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- /* Sort the relocs by address. */
- qsort (aux.dynrelbuf, aux.dynrelcount, sizeof (arelent *),
- compare_relocs);
- }
- }
- disasm_info.symtab = sorted_syms;
- disasm_info.symtab_size = sorted_symcount;
-
- bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
-
- if (aux.dynrelbuf != NULL)
- free (aux.dynrelbuf);
- free (sorted_syms);
-}
-
-int
-load_debug_section (enum dwarf_section_display_enum debug, void *file)
-{
- struct dwarf_section *section = &debug_displays [debug].section;
- bfd *abfd = file;
- asection *sec;
- bfd_boolean ret;
- int section_is_compressed;
-
- /* If it is already loaded, do nothing. */
- if (section->start != NULL)
- return 1;
-
- /* Locate the debug section. */
- sec = bfd_get_section_by_name (abfd, section->uncompressed_name);
- if (sec != NULL)
- section->name = section->uncompressed_name;
- else
- {
- sec = bfd_get_section_by_name (abfd, section->compressed_name);
- if (sec != NULL)
- section->name = section->compressed_name;
- }
- if (sec == NULL)
- return 0;
- section_is_compressed = section->name == section->compressed_name;
-
- /* Compute a bias to be added to offsets found within the DWARF debug
- information. These offsets are meant to be relative to the start of
- the dwarf section, and hence the bias should be 0. For MACH-O however
- a dwarf section is really just a region of a much larger section and so
- the bias is the address of the start of that area within the larger
- section. This test is important for PE and COFF based targets which
- use DWARF debug information, since unlike ELF, they do not allow the
- dwarf sections to be placed at address 0. */
- if (bfd_get_flavour (abfd) == bfd_target_mach_o_flavour)
- section->address = bfd_get_section_vma (abfd, sec);
- else
- section->address = 0;
-
- section->size = bfd_get_section_size (sec);
- section->start = xmalloc (section->size);
-
- if (is_relocatable && debug_displays [debug].relocate)
- ret = bfd_simple_get_relocated_section_contents (abfd,
- sec,
- section->start,
- syms) != NULL;
- else
- ret = bfd_get_section_contents (abfd, sec, section->start, 0,
- section->size);
-
- if (! ret)
- {
- free_debug_section (debug);
- printf (_("\nCan't get contents for section '%s'.\n"),
- section->name);
- return 0;
- }
-
- if (section_is_compressed)
- {
- bfd_size_type size = section->size;
- if (! bfd_uncompress_section_contents (&section->start, &size))
- {
- free_debug_section (debug);
- printf (_("\nCan't uncompress section '%s'.\n"), section->name);
- return 0;
- }
- section->size = size;
- }
-
- return ret;
-}
-
-void
-free_debug_section (enum dwarf_section_display_enum debug)
-{
- struct dwarf_section *section = &debug_displays [debug].section;
-
- if (section->start == NULL)
- return;
-
- free ((char *) section->start);
- section->start = NULL;
- section->address = 0;
- section->size = 0;
-}
-
-static void
-dump_dwarf_section (bfd *abfd, asection *section,
- void *arg ATTRIBUTE_UNUSED)
-{
- const char *name = bfd_get_section_name (abfd, section);
- const char *match;
- enum dwarf_section_display_enum i;
-
- if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
- match = ".debug_info";
- else
- match = name;
-
- for (i = 0; i < max; i++)
- if (strcmp (debug_displays [i].section.uncompressed_name, match) == 0
- || strcmp (debug_displays [i].section.compressed_name, match) == 0)
- {
- if (!debug_displays [i].eh_frame)
- {
- struct dwarf_section *sec = &debug_displays [i].section;
-
- if (load_debug_section (i, abfd))
- {
- debug_displays [i].display (sec, abfd);
-
- if (i != info && i != abbrev)
- free_debug_section (i);
- }
- }
- break;
- }
-}
-
-static const char *mach_o_uncompressed_dwarf_sections [] = {
- "LC_SEGMENT.__DWARFA.__debug_abbrev", /* .debug_abbrev */
- "LC_SEGMENT.__DWARFA.__debug_aranges", /* .debug_aranges */
- "LC_SEGMENT.__DWARFA.__debug_frame", /* .debug_frame */
- "LC_SEGMENT.__DWARFA.__debug_info", /* .debug_info */
- "LC_SEGMENT.__DWARFA.__debug_line", /* .debug_line */
- "LC_SEGMENT.__DWARFA.__debug_pubnames", /* .debug_pubnames */
- ".eh_frame", /* .eh_frame */
- "LC_SEGMENT.__DWARFA.__debug_macinfo", /* .debug_macinfo */
- "LC_SEGMENT.__DWARFA.__debug_str", /* .debug_str */
- "LC_SEGMENT.__DWARFA.__debug_loc", /* .debug_loc */
- "LC_SEGMENT.__DWARFA.__debug_pubtypes", /* .debug_pubtypes */
- "LC_SEGMENT.__DWARFA.__debug_ranges", /* .debug_ranges */
- "LC_SEGMENT.__DWARFA.__debug_static_func", /* .debug_static_func */
- "LC_SEGMENT.__DWARFA.__debug_static_vars", /* .debug_static_vars */
- "LC_SEGMENT.__DWARFA.__debug_types", /* .debug_types */
- "LC_SEGMENT.__DWARFA.__debug_weaknames" /* .debug_weaknames */
-};
-
-static const char *mach_o_compressed_dwarf_sections [] = {
- "LC_SEGMENT.__DWARFA.__zdebug_abbrev", /* .zdebug_abbrev */
- "LC_SEGMENT.__DWARFA.__zdebug_aranges", /* .zdebug_aranges */
- "LC_SEGMENT.__DWARFA.__zdebug_frame", /* .zdebug_frame */
- "LC_SEGMENT.__DWARFA.__zdebug_info", /* .zdebug_info */
- "LC_SEGMENT.__DWARFA.__zdebug_line", /* .zdebug_line */
- "LC_SEGMENT.__DWARFA.__zdebug_pubnames", /* .zdebug_pubnames */
- ".eh_frame", /* .eh_frame */
- "LC_SEGMENT.__DWARFA.__zdebug_macinfo", /* .zdebug_macinfo */
- "LC_SEGMENT.__DWARFA.__zdebug_str", /* .zdebug_str */
- "LC_SEGMENT.__DWARFA.__zdebug_loc", /* .zdebug_loc */
- "LC_SEGMENT.__DWARFA.__zdebug_pubtypes", /* .zdebug_pubtypes */
- "LC_SEGMENT.__DWARFA.__zdebug_ranges", /* .zdebug_ranges */
- "LC_SEGMENT.__DWARFA.__zdebug_static_func", /* .zdebug_static_func */
- "LC_SEGMENT.__DWARFA.__zdebug_static_vars", /* .zdebug_static_vars */
- "LC_SEGMENT.__DWARFA.__zdebug_types", /* .zdebug_types */
- "LC_SEGMENT.__DWARFA.__zdebug_weaknames" /* .zdebug_weaknames */
-};
-
-static const char *generic_uncompressed_dwarf_sections [max];
-static const char *generic_compressed_dwarf_sections [max];
-
-static void
-check_mach_o_dwarf (bfd *abfd)
-{
- static enum bfd_flavour old_flavour = bfd_target_unknown_flavour;
- enum bfd_flavour current_flavour = bfd_get_flavour (abfd);
- enum dwarf_section_display_enum i;
-
- if (generic_uncompressed_dwarf_sections [0] == NULL)
- for (i = 0; i < max; i++)
- {
- generic_uncompressed_dwarf_sections [i]
- = debug_displays[i].section.uncompressed_name;
- generic_compressed_dwarf_sections [i]
- = debug_displays[i].section.compressed_name;
- }
-
- if (old_flavour != current_flavour)
- {
- if (current_flavour == bfd_target_mach_o_flavour)
- for (i = 0; i < max; i++)
- {
- debug_displays[i].section.uncompressed_name
- = mach_o_uncompressed_dwarf_sections [i];
- debug_displays[i].section.compressed_name
- = mach_o_compressed_dwarf_sections [i];
- }
- else if (old_flavour == bfd_target_mach_o_flavour)
- for (i = 0; i < max; i++)
- {
- debug_displays[i].section.uncompressed_name
- = generic_uncompressed_dwarf_sections [i];
- debug_displays[i].section.compressed_name
- = generic_compressed_dwarf_sections [i];
- }
-
- old_flavour = current_flavour;
- }
-}
-
-/* Dump the dwarf debugging information. */
-
-static void
-dump_dwarf (bfd *abfd)
-{
- is_relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
-
- /* FIXME: bfd_get_arch_size may return -1. We assume that 64bit
- targets will return 64. */
- eh_addr_size = bfd_get_arch_size (abfd) == 64 ? 8 : 4;
-
- if (bfd_big_endian (abfd))
- byte_get = byte_get_big_endian;
- else if (bfd_little_endian (abfd))
- byte_get = byte_get_little_endian;
- else
- abort ();
-
- check_mach_o_dwarf (abfd);
-
- if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
- {
- const struct elf_backend_data *bed = get_elf_backend_data (abfd);
- init_dwarf_regnames (bed->elf_machine_code);
- }
-
- bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
-
- free_debug_memory ();
-}
-
-/* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
- it. Return NULL on failure. */
-
-static char *
-read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr)
-{
- asection *stabsect;
- bfd_size_type size;
- char *contents;
-
- stabsect = bfd_get_section_by_name (abfd, sect_name);
- if (stabsect == NULL)
- {
- printf (_("No %s section present\n\n"), sect_name);
- return FALSE;
- }
-
- size = bfd_section_size (abfd, stabsect);
- contents = xmalloc (size);
-
- if (! bfd_get_section_contents (abfd, stabsect, contents, 0, size))
- {
- non_fatal (_("Reading %s section of %s failed: %s"),
- sect_name, bfd_get_filename (abfd),
- bfd_errmsg (bfd_get_error ()));
- free (contents);
- exit_status = 1;
- return NULL;
- }
-
- *size_ptr = size;
-
- return contents;
-}
-
-/* Stabs entries use a 12 byte format:
- 4 byte string table index
- 1 byte stab type
- 1 byte stab other field
- 2 byte stab desc field
- 4 byte stab value
- FIXME: This will have to change for a 64 bit object format. */
-
-#define STRDXOFF (0)
-#define TYPEOFF (4)
-#define OTHEROFF (5)
-#define DESCOFF (6)
-#define VALOFF (8)
-#define STABSIZE (12)
-
-/* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
- using string table section STRSECT_NAME (in `strtab'). */
-
-static void
-print_section_stabs (bfd *abfd,
- const char *stabsect_name,
- unsigned *string_offset_ptr)
-{
- int i;
- unsigned file_string_table_offset = 0;
- unsigned next_file_string_table_offset = *string_offset_ptr;
- bfd_byte *stabp, *stabs_end;
-
- stabp = stabs;
- stabs_end = stabp + stab_size;
-
- printf (_("Contents of %s section:\n\n"), stabsect_name);
- printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
-
- /* Loop through all symbols and print them.
-
- We start the index at -1 because there is a dummy symbol on
- the front of stabs-in-{coff,elf} sections that supplies sizes. */
- for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++)
- {
- const char *name;
- unsigned long strx;
- unsigned char type, other;
- unsigned short desc;
- bfd_vma value;
-
- strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
- type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
- other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
- desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
- value = bfd_h_get_32 (abfd, stabp + VALOFF);
-
- printf ("\n%-6d ", i);
- /* Either print the stab name, or, if unnamed, print its number
- again (makes consistent formatting for tools like awk). */
- name = bfd_get_stab_name (type);
- if (name != NULL)
- printf ("%-6s", name);
- else if (type == N_UNDF)
- printf ("HdrSym");
- else
- printf ("%-6d", type);
- printf (" %-6d %-6d ", other, desc);
- bfd_printf_vma (abfd, value);
- printf (" %-6lu", strx);
-
- /* Symbols with type == 0 (N_UNDF) specify the length of the
- string table associated with this file. We use that info
- to know how to relocate the *next* file's string table indices. */
- if (type == N_UNDF)
- {
- file_string_table_offset = next_file_string_table_offset;
- next_file_string_table_offset += value;
- }
- else
- {
- /* Using the (possibly updated) string table offset, print the
- string (if any) associated with this symbol. */
- if ((strx + file_string_table_offset) < stabstr_size)
- printf (" %s", &strtab[strx + file_string_table_offset]);
- else
- printf (" *");
- }
- }
- printf ("\n\n");
- *string_offset_ptr = next_file_string_table_offset;
-}
-
-typedef struct
-{
- const char * section_name;
- const char * string_section_name;
- unsigned string_offset;
-}
-stab_section_names;
-
-static void
-find_stabs_section (bfd *abfd, asection *section, void *names)
-{
- int len;
- stab_section_names * sought = (stab_section_names *) names;
-
- /* Check for section names for which stabsect_name is a prefix, to
- handle .stab.N, etc. */
- len = strlen (sought->section_name);
-
- /* If the prefix matches, and the files section name ends with a
- nul or a digit, then we match. I.e., we want either an exact
- match or a section followed by a number. */
- if (strncmp (sought->section_name, section->name, len) == 0
- && (section->name[len] == 0
- || (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
- {
- if (strtab == NULL)
- strtab = read_section_stabs (abfd, sought->string_section_name,
- &stabstr_size);
-
- if (strtab)
- {
- stabs = (bfd_byte *) read_section_stabs (abfd, section->name,
- &stab_size);
- if (stabs)
- print_section_stabs (abfd, section->name, &sought->string_offset);
- }
- }
-}
-
-static void
-dump_stabs_section (bfd *abfd, char *stabsect_name, char *strsect_name)
-{
- stab_section_names s;
-
- s.section_name = stabsect_name;
- s.string_section_name = strsect_name;
- s.string_offset = 0;
-
- bfd_map_over_sections (abfd, find_stabs_section, & s);
-
- free (strtab);
- strtab = NULL;
-}
-
-/* Dump the any sections containing stabs debugging information. */
-
-static void
-dump_stabs (bfd *abfd)
-{
- dump_stabs_section (abfd, ".stab", ".stabstr");
- dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr");
- dump_stabs_section (abfd, ".stab.index", ".stab.indexstr");
- dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
-}
-
-static void
-dump_bfd_header (bfd *abfd)
-{
- char *comma = "";
-
- printf (_("architecture: %s, "),
- bfd_printable_arch_mach (bfd_get_arch (abfd),
- bfd_get_mach (abfd)));
- printf (_("flags 0x%08x:\n"), abfd->flags);
-
-#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
- PF (HAS_RELOC, "HAS_RELOC");
- PF (EXEC_P, "EXEC_P");
- PF (HAS_LINENO, "HAS_LINENO");
- PF (HAS_DEBUG, "HAS_DEBUG");
- PF (HAS_SYMS, "HAS_SYMS");
- PF (HAS_LOCALS, "HAS_LOCALS");
- PF (DYNAMIC, "DYNAMIC");
- PF (WP_TEXT, "WP_TEXT");
- PF (D_PAGED, "D_PAGED");
- PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
- PF (HAS_LOAD_PAGE, "HAS_LOAD_PAGE");
- printf (_("\nstart address 0x"));
- bfd_printf_vma (abfd, abfd->start_address);
- printf ("\n");
-}
-
-
-static void
-dump_bfd_private_header (bfd *abfd)
-{
- bfd_print_private_bfd_data (abfd, stdout);
-}
-
-
-/* Display a section in hexadecimal format with associated characters.
- Each line prefixed by the zero padded address. */
-
-static void
-dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED)
-{
- bfd_byte *data = 0;
- bfd_size_type datasize;
- bfd_size_type addr_offset;
- bfd_size_type start_offset;
- bfd_size_type stop_offset;
- unsigned int opb = bfd_octets_per_byte (abfd);
- /* Bytes per line. */
- const int onaline = 16;
- char buf[64];
- int count;
- int width;
-
- if ((section->flags & SEC_HAS_CONTENTS) == 0)
- return;
-
- if (! process_section_p (section))
- return;
-
- if ((datasize = bfd_section_size (abfd, section)) == 0)
- return;
-
- /* Compute the address range to display. */
- if (start_address == (bfd_vma) -1
- || start_address < section->vma)
- start_offset = 0;
- else
- start_offset = start_address - section->vma;
-
- if (stop_address == (bfd_vma) -1)
- stop_offset = datasize / opb;
- else
- {
- if (stop_address < section->vma)
- stop_offset = 0;
- else
- stop_offset = stop_address - section->vma;
-
- if (stop_offset > datasize / opb)
- stop_offset = datasize / opb;
- }
-
- if (start_offset >= stop_offset)
- return;
-
- printf (_("Contents of section %s:"), section->name);
- if (display_file_offsets)
- printf (_(" (Starting at file offset: 0x%lx)"),
- (unsigned long) (section->filepos + start_offset));
- printf ("\n");
-
- data = xmalloc (datasize);
-
- bfd_get_section_contents (abfd, section, data, 0, datasize);
-
- width = 4;
-
- bfd_sprintf_vma (abfd, buf, start_offset + section->vma);
- if (strlen (buf) >= sizeof (buf))
- abort ();
-
- count = 0;
- while (buf[count] == '0' && buf[count+1] != '\0')
- count++;
- count = strlen (buf) - count;
- if (count > width)
- width = count;
-
- bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1);
- if (strlen (buf) >= sizeof (buf))
- abort ();
-
- count = 0;
- while (buf[count] == '0' && buf[count+1] != '\0')
- count++;
- count = strlen (buf) - count;
- if (count > width)
- width = count;
-
- for (addr_offset = start_offset;
- addr_offset < stop_offset; addr_offset += onaline / opb)
- {
- bfd_size_type j;
-
- bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma));
- count = strlen (buf);
- if ((size_t) count >= sizeof (buf))
- abort ();
-
- putchar (' ');
- while (count < width)
- {
- putchar ('0');
- count++;
- }
- fputs (buf + count - width, stdout);
- putchar (' ');
-
- for (j = addr_offset * opb;
- j < addr_offset * opb + onaline; j++)
- {
- if (j < stop_offset * opb)
- printf ("%02x", (unsigned) (data[j]));
- else
- printf (" ");
- if ((j & 3) == 3)
- printf (" ");
- }
-
- printf (" ");
- for (j = addr_offset * opb;
- j < addr_offset * opb + onaline; j++)
- {
- if (j >= stop_offset * opb)
- printf (" ");
- else
- printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
- }
- putchar ('\n');
- }
- free (data);
-}
-
-/* Actually display the various requested regions. */
-
-static void
-dump_data (bfd *abfd)
-{
- bfd_map_over_sections (abfd, dump_section, NULL);
-}
-
-/* Should perhaps share code and display with nm? */
-
-static void
-dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic)
-{
- asymbol **current;
- long max;
- long count;
-
- if (dynamic)
- {
- current = dynsyms;
- max = dynsymcount;
- printf ("DYNAMIC SYMBOL TABLE:\n");
- }
- else
- {
- current = syms;
- max = symcount;
- printf ("SYMBOL TABLE:\n");
- }
-
- if (max == 0)
- printf (_("no symbols\n"));
-
- for (count = 0; count < max; count++)
- {
- bfd *cur_bfd;
-
- if (*current == NULL)
- printf (_("no information for symbol number %ld\n"), count);
-
- else if ((cur_bfd = bfd_asymbol_bfd (*current)) == NULL)
- printf (_("could not determine the type of symbol number %ld\n"),
- count);
-
- else if (process_section_p ((* current)->section)
- && (dump_special_syms
- || !bfd_is_target_special_symbol (cur_bfd, *current)))
- {
- const char *name = (*current)->name;
-
- if (do_demangle && name != NULL && *name != '\0')
- {
- char *alloc;
-
- /* If we want to demangle the name, we demangle it
- here, and temporarily clobber it while calling
- bfd_print_symbol. FIXME: This is a gross hack. */
- alloc = bfd_demangle (cur_bfd, name, DMGL_ANSI | DMGL_PARAMS);
- if (alloc != NULL)
- (*current)->name = alloc;
- bfd_print_symbol (cur_bfd, stdout, *current,
- bfd_print_symbol_all);
- if (alloc != NULL)
- {
- (*current)->name = name;
- free (alloc);
- }
- }
- else
- bfd_print_symbol (cur_bfd, stdout, *current,
- bfd_print_symbol_all);
- printf ("\n");
- }
-
- current++;
- }
- printf ("\n\n");
-}
-
-static void
-dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
-{
- arelent **p;
- char *last_filename, *last_functionname;
- unsigned int last_line;
-
- /* Get column headers lined up reasonably. */
- {
- static int width;
-
- if (width == 0)
- {
- char buf[30];
-
- bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
- width = strlen (buf) - 7;
- }
- printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
- }
-
- last_filename = NULL;
- last_functionname = NULL;
- last_line = 0;
-
- for (p = relpp; relcount && *p != NULL; p++, relcount--)
- {
- arelent *q = *p;
- const char *filename, *functionname;
- unsigned int line;
- const char *sym_name;
- const char *section_name;
-
- if (start_address != (bfd_vma) -1
- && q->address < start_address)
- continue;
- if (stop_address != (bfd_vma) -1
- && q->address > stop_address)
- continue;
-
- if (with_line_numbers
- && sec != NULL
- && bfd_find_nearest_line (abfd, sec, syms, q->address,
- &filename, &functionname, &line))
- {
- if (functionname != NULL
- && (last_functionname == NULL
- || strcmp (functionname, last_functionname) != 0))
- {
- printf ("%s():\n", functionname);
- if (last_functionname != NULL)
- free (last_functionname);
- last_functionname = xstrdup (functionname);
- }
-
- if (line > 0
- && (line != last_line
- || (filename != NULL
- && last_filename != NULL
- && strcmp (filename, last_filename) != 0)))
- {
- printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
- last_line = line;
- if (last_filename != NULL)
- free (last_filename);
- if (filename == NULL)
- last_filename = NULL;
- else
- last_filename = xstrdup (filename);
- }
- }
-
- if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
- {
- sym_name = (*(q->sym_ptr_ptr))->name;
- section_name = (*(q->sym_ptr_ptr))->section->name;
- }
- else
- {
- sym_name = NULL;
- section_name = NULL;
- }
-
- bfd_printf_vma (abfd, q->address);
- if (q->howto == NULL)
- printf (" *unknown* ");
- else if (q->howto->name)
- printf (" %-16s ", q->howto->name);
- else
- printf (" %-16d ", q->howto->type);
- if (sym_name)
- objdump_print_symname (abfd, NULL, *q->sym_ptr_ptr);
- else
- {
- if (section_name == NULL)
- section_name = "*unknown*";
- printf ("[%s]", section_name);
- }
-
- if (q->addend)
- {
- printf ("+0x");
- bfd_printf_vma (abfd, q->addend);
- }
-
- printf ("\n");
- }
-}
-
-static void
-dump_relocs_in_section (bfd *abfd,
- asection *section,
- void *dummy ATTRIBUTE_UNUSED)
-{
- arelent **relpp;
- long relcount;
- long relsize;
-
- if ( bfd_is_abs_section (section)
- || bfd_is_und_section (section)
- || bfd_is_com_section (section)
- || (! process_section_p (section))
- || ((section->flags & SEC_RELOC) == 0))
- return;
-
- relsize = bfd_get_reloc_upper_bound (abfd, section);
- if (relsize < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- printf ("RELOCATION RECORDS FOR [%s]:", section->name);
-
- if (relsize == 0)
- {
- printf (" (none)\n\n");
- return;
- }
-
- relpp = xmalloc (relsize);
- relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
-
- if (relcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
- else if (relcount == 0)
- printf (" (none)\n\n");
- else
- {
- printf ("\n");
- dump_reloc_set (abfd, section, relpp, relcount);
- printf ("\n\n");
- }
- free (relpp);
-}
-
-static void
-dump_relocs (bfd *abfd)
-{
- bfd_map_over_sections (abfd, dump_relocs_in_section, NULL);
-}
-
-static void
-dump_dynamic_relocs (bfd *abfd)
-{
- long relsize;
- arelent **relpp;
- long relcount;
-
- relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
- if (relsize < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- printf ("DYNAMIC RELOCATION RECORDS");
-
- if (relsize == 0)
- printf (" (none)\n\n");
- else
- {
- relpp = xmalloc (relsize);
- relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
-
- if (relcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
- else if (relcount == 0)
- printf (" (none)\n\n");
- else
- {
- printf ("\n");
- dump_reloc_set (abfd, NULL, relpp, relcount);
- printf ("\n\n");
- }
- free (relpp);
- }
-}
-
-/* Creates a table of paths, to search for source files. */
-
-static void
-add_include_path (const char *path)
-{
- if (path[0] == 0)
- return;
- include_path_count++;
- include_paths = xrealloc (include_paths,
- include_path_count * sizeof (*include_paths));
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
- if (path[1] == ':' && path[2] == 0)
- path = concat (path, ".", (const char *) 0);
-#endif
- include_paths[include_path_count - 1] = path;
-}
-
-static void
-adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
- asection *section,
- void *arg)
-{
- if ((section->flags & SEC_DEBUGGING) == 0)
- {
- bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
- section->vma += adjust_section_vma;
- if (*has_reloc_p)
- section->lma += adjust_section_vma;
- }
-}
-
-/* Dump selected contents of ABFD. */
-
-static void
-dump_bfd (bfd *abfd)
-{
- /* If we are adjusting section VMA's, change them all now. Changing
- the BFD information is a hack. However, we must do it, or
- bfd_find_nearest_line will not do the right thing. */
- if (adjust_section_vma != 0)
- {
- bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
- bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
- }
-
- if (! dump_debugging_tags)
- printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd),
- abfd->xvec->name);
- if (dump_ar_hdrs)
- print_arelt_descr (stdout, abfd, TRUE);
- if (dump_file_header)
- dump_bfd_header (abfd);
- if (dump_private_headers)
- dump_bfd_private_header (abfd);
- if (! dump_debugging_tags)
- putchar ('\n');
- if (dump_section_headers)
- dump_headers (abfd);
-
- if (dump_symtab
- || dump_reloc_info
- || disassemble
- || dump_debugging
- || dump_dwarf_section_info)
- syms = slurp_symtab (abfd);
- if (dump_dynamic_symtab || dump_dynamic_reloc_info
- || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
- dynsyms = slurp_dynamic_symtab (abfd);
- if (disassemble)
- {
- synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
- dynsymcount, dynsyms, &synthsyms);
- if (synthcount < 0)
- synthcount = 0;
- }
-
- if (dump_symtab)
- dump_symbols (abfd, FALSE);
- if (dump_dynamic_symtab)
- dump_symbols (abfd, TRUE);
- if (dump_dwarf_section_info)
- dump_dwarf (abfd);
- if (dump_stab_section_info)
- dump_stabs (abfd);
- if (dump_reloc_info && ! disassemble)
- dump_relocs (abfd);
- if (dump_dynamic_reloc_info && ! disassemble)
- dump_dynamic_relocs (abfd);
- if (dump_section_contents)
- dump_data (abfd);
- if (disassemble)
- disassemble_data (abfd);
-
- if (dump_debugging)
- {
- void *dhandle;
-
- dhandle = read_debugging_info (abfd, syms, symcount, TRUE);
- if (dhandle != NULL)
- {
- if (!print_debugging_info (stdout, dhandle, abfd, syms,
- bfd_demangle,
- dump_debugging_tags ? TRUE : FALSE))
- {
- non_fatal (_("%s: printing debugging information failed"),
- bfd_get_filename (abfd));
- exit_status = 1;
- }
- }
- /* PR 6483: If there was no STABS or IEEE debug
- info in the file, try DWARF instead. */
- else if (! dump_dwarf_section_info)
- {
- dump_dwarf (abfd);
- }
- }
-
- if (syms)
- {
- free (syms);
- syms = NULL;
- }
-
- if (dynsyms)
- {
- free (dynsyms);
- dynsyms = NULL;
- }
-
- if (synthsyms)
- {
- free (synthsyms);
- synthsyms = NULL;
- }
-
- symcount = 0;
- dynsymcount = 0;
- synthcount = 0;
-}
-
-static void
-display_bfd (bfd *abfd)
-{
- char **matching;
-
- if (bfd_check_format_matches (abfd, bfd_object, &matching))
- {
- dump_bfd (abfd);
- return;
- }
-
- if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
- {
- nonfatal (bfd_get_filename (abfd));
- list_matching_formats (matching);
- free (matching);
- return;
- }
-
- if (bfd_get_error () != bfd_error_file_not_recognized)
- {
- nonfatal (bfd_get_filename (abfd));
- return;
- }
-
- if (bfd_check_format_matches (abfd, bfd_core, &matching))
- {
- dump_bfd (abfd);
- return;
- }
-
- nonfatal (bfd_get_filename (abfd));
-
- if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
- {
- list_matching_formats (matching);
- free (matching);
- }
-}
-
-static void
-display_file (char *filename, char *target)
-{
- bfd *file;
- bfd *arfile = NULL;
-
- if (get_file_size (filename) < 1)
- {
- exit_status = 1;
- return;
- }
-
- file = bfd_openr (filename, target);
- if (file == NULL)
- {
- nonfatal (filename);
- return;
- }
-
- /* If the file is an archive, process all of its elements. */
- if (bfd_check_format (file, bfd_archive))
- {
- bfd *last_arfile = NULL;
-
- printf (_("In archive %s:\n"), bfd_get_filename (file));
- for (;;)
- {
- bfd_set_error (bfd_error_no_error);
-
- arfile = bfd_openr_next_archived_file (file, arfile);
- if (arfile == NULL)
- {
- if (bfd_get_error () != bfd_error_no_more_archived_files)
- nonfatal (bfd_get_filename (file));
- break;
- }
-
- display_bfd (arfile);
-
- if (last_arfile != NULL)
- bfd_close (last_arfile);
- last_arfile = arfile;
- }
-
- if (last_arfile != NULL)
- bfd_close (last_arfile);
- }
- else
- display_bfd (file);
-
- bfd_close (file);
-}
-
-int
-main (int argc, char **argv)
-{
- int c;
- char *target = default_target;
- bfd_boolean seenflag = FALSE;
-
-#if defined (HAVE_SETLOCALE)
-#if defined (HAVE_LC_MESSAGES)
- setlocale (LC_MESSAGES, "");
-#endif
- setlocale (LC_CTYPE, "");
-#endif
-
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- program_name = *argv;
- xmalloc_set_program_name (program_name);
-
- START_PROGRESS (program_name, 0);
-
- expandargv (&argc, &argv);
-
- bfd_init ();
- set_default_bfd_target ();
-
- while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW",
- long_options, (int *) 0))
- != EOF)
- {
- switch (c)
- {
- case 0:
- break; /* We've been given a long option. */
- case 'm':
- machine = optarg;
- break;
- case 'M':
- if (disassembler_options)
- /* Ignore potential memory leak for now. */
- disassembler_options = concat (disassembler_options, ",",
- optarg, (const char *) NULL);
- else
- disassembler_options = optarg;
- break;
- case 'j':
- if (only_used == only_size)
- {
- only_size += 8;
- only = xrealloc (only, only_size * sizeof (char *));
- }
- only [only_used++] = optarg;
- break;
- case 'F':
- display_file_offsets = TRUE;
- break;
- case 'l':
- with_line_numbers = TRUE;
- break;
- case 'b':
- target = optarg;
- break;
- case 'C':
- do_demangle = TRUE;
- if (optarg != NULL)
- {
- enum demangling_styles style;
-
- style = cplus_demangle_name_to_style (optarg);
- if (style == unknown_demangling)
- fatal (_("unknown demangling style `%s'"),
- optarg);
-
- cplus_demangle_set_style (style);
- }
- break;
- case 'w':
- wide_output = TRUE;
- break;
- case OPTION_ADJUST_VMA:
- adjust_section_vma = parse_vma (optarg, "--adjust-vma");
- break;
- case OPTION_START_ADDRESS:
- start_address = parse_vma (optarg, "--start-address");
- if ((stop_address != (bfd_vma) -1) && stop_address <= start_address)
- fatal (_("error: the start address should be before the end address"));
- break;
- case OPTION_STOP_ADDRESS:
- stop_address = parse_vma (optarg, "--stop-address");
- if ((start_address != (bfd_vma) -1) && stop_address <= start_address)
- fatal (_("error: the stop address should be after the start address"));
- break;
- case 'E':
- if (strcmp (optarg, "B") == 0)
- endian = BFD_ENDIAN_BIG;
- else if (strcmp (optarg, "L") == 0)
- endian = BFD_ENDIAN_LITTLE;
- else
- {
- non_fatal (_("unrecognized -E option"));
- usage (stderr, 1);
- }
- break;
- case OPTION_ENDIAN:
- if (strncmp (optarg, "big", strlen (optarg)) == 0)
- endian = BFD_ENDIAN_BIG;
- else if (strncmp (optarg, "little", strlen (optarg)) == 0)
- endian = BFD_ENDIAN_LITTLE;
- else
- {
- non_fatal (_("unrecognized --endian type `%s'"), optarg);
- usage (stderr, 1);
- }
- break;
-
- case 'f':
- dump_file_header = TRUE;
- seenflag = TRUE;
- break;
- case 'i':
- formats_info = TRUE;
- seenflag = TRUE;
- break;
- case 'I':
- add_include_path (optarg);
- break;
- case 'p':
- dump_private_headers = TRUE;
- seenflag = TRUE;
- break;
- case 'x':
- dump_private_headers = TRUE;
- dump_symtab = TRUE;
- dump_reloc_info = TRUE;
- dump_file_header = TRUE;
- dump_ar_hdrs = TRUE;
- dump_section_headers = TRUE;
- seenflag = TRUE;
- break;
- case 't':
- dump_symtab = TRUE;
- seenflag = TRUE;
- break;
- case 'T':
- dump_dynamic_symtab = TRUE;
- seenflag = TRUE;
- break;
- case 'd':
- disassemble = TRUE;
- seenflag = TRUE;
- break;
- case 'z':
- disassemble_zeroes = TRUE;
- break;
- case 'D':
- disassemble = TRUE;
- disassemble_all = TRUE;
- seenflag = TRUE;
- break;
- case 'S':
- disassemble = TRUE;
- with_source_code = TRUE;
- seenflag = TRUE;
- break;
- case 'g':
- dump_debugging = 1;
- seenflag = TRUE;
- break;
- case 'e':
- dump_debugging = 1;
- dump_debugging_tags = 1;
- do_demangle = TRUE;
- seenflag = TRUE;
- break;
- case 'W':
- dump_dwarf_section_info = TRUE;
- seenflag = TRUE;
- do_debug_info = 1;
- do_debug_abbrevs = 1;
- do_debug_lines = 1;
- do_debug_pubnames = 1;
- do_debug_aranges = 1;
- do_debug_ranges = 1;
- do_debug_frames = 1;
- do_debug_macinfo = 1;
- do_debug_str = 1;
- do_debug_loc = 1;
- break;
- case 'G':
- dump_stab_section_info = TRUE;
- seenflag = TRUE;
- break;
- case 's':
- dump_section_contents = TRUE;
- seenflag = TRUE;
- break;
- case 'r':
- dump_reloc_info = TRUE;
- seenflag = TRUE;
- break;
- case 'R':
- dump_dynamic_reloc_info = TRUE;
- seenflag = TRUE;
- break;
- case 'a':
- dump_ar_hdrs = TRUE;
- seenflag = TRUE;
- break;
- case 'h':
- dump_section_headers = TRUE;
- seenflag = TRUE;
- break;
- case 'H':
- usage (stdout, 0);
- seenflag = TRUE;
- case 'v':
- case 'V':
- show_version = TRUE;
- seenflag = TRUE;
- break;
-
- default:
- usage (stderr, 1);
- }
- }
-
- if (show_version)
- print_version ("objdump");
-
- if (!seenflag)
- usage (stderr, 2);
-
- if (formats_info)
- exit_status = display_info ();
- else
- {
- if (optind == argc)
- display_file ("a.out", target);
- else
- for (; optind < argc;)
- display_file (argv[optind++], target);
- }
-
- END_PROGRESS (program_name);
-
- return exit_status;
-}
diff --git a/binutils/readelf.c b/binutils/readelf.c
deleted file mode 100644
index c260e9ab3a7..00000000000
--- a/binutils/readelf.c
+++ /dev/null
@@ -1,10851 +0,0 @@
-/* readelf.c -- display contents of an ELF format file
- Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008 Free Software Foundation, Inc.
-
- Originally developed by Eric Youngdale <eric@andante.jic.com>
- Modifications by Nick Clifton <nickc@redhat.com>
-
- This file is part of GNU Binutils.
-
- 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. */
-
-/* The difference between readelf and objdump:
-
- Both programs are capable of displaying the contents of ELF format files,
- so why does the binutils project have two file dumpers ?
-
- The reason is that objdump sees an ELF file through a BFD filter of the
- world; if BFD has a bug where, say, it disagrees about a machine constant
- in e_flags, then the odds are good that it will remain internally
- consistent. The linker sees it the BFD way, objdump sees it the BFD way,
- GAS sees it the BFD way. There was need for a tool to go find out what
- the file actually says.
-
- This is why the readelf program does not link against the BFD library - it
- exists as an independent program to help verify the correct working of BFD.
-
- There is also the case that readelf can provide more information about an
- ELF file than is provided by objdump. In particular it can display DWARF
- debugging information which (at the moment) objdump cannot. */
-
-#include "config.h"
-#include "sysdep.h"
-#include <assert.h>
-#include <sys/stat.h>
-#include <time.h>
-#ifdef HAVE_ZLIB_H
-#include <zlib.h>
-#endif
-
-/* for PATH_MAX */
-#ifdef HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-#ifndef PATH_MAX
-/* for MAXPATHLEN */
-# ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-# endif
-# ifndef PATH_MAX
-# ifdef MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# else
-# define PATH_MAX 1024
-# endif
-# endif
-#endif
-
-#if __GNUC__ >= 2
-/* Define BFD64 here, even if our default architecture is 32 bit ELF
- as this will allow us to read in and parse 64bit and 32bit ELF files.
- Only do this if we believe that the compiler can support a 64 bit
- data type. For now we only rely on GCC being able to do this. */
-#define BFD64
-#endif
-
-#include "bfd.h"
-#include "bucomm.h"
-#include "dwarf.h"
-
-#include "elf/common.h"
-#include "elf/external.h"
-#include "elf/internal.h"
-
-
-/* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
- we can obtain the H8 reloc numbers. We need these for the
- get_reloc_size() function. We include h8.h again after defining
- RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
-
-#include "elf/h8.h"
-#undef _ELF_H8_H
-
-/* Undo the effects of #including reloc-macros.h. */
-
-#undef START_RELOC_NUMBERS
-#undef RELOC_NUMBER
-#undef FAKE_RELOC
-#undef EMPTY_RELOC
-#undef END_RELOC_NUMBERS
-#undef _RELOC_MACROS_H
-
-/* The following headers use the elf/reloc-macros.h file to
- automatically generate relocation recognition functions
- such as elf_mips_reloc_type() */
-
-#define RELOC_MACROS_GEN_FUNC
-
-#include "elf/alpha.h"
-#include "elf/arc.h"
-#include "elf/arm.h"
-#include "elf/avr.h"
-#include "elf/bfin.h"
-#include "elf/cr16.h"
-#include "elf/cris.h"
-#include "elf/crx.h"
-#include "elf/d10v.h"
-#include "elf/d30v.h"
-#include "elf/dlx.h"
-#include "elf/fr30.h"
-#include "elf/frv.h"
-#include "elf/h8.h"
-#include "elf/hppa.h"
-#include "elf/i386.h"
-#include "elf/i370.h"
-#include "elf/i860.h"
-#include "elf/i960.h"
-#include "elf/ia64.h"
-#include "elf/ip2k.h"
-#include "elf/iq2000.h"
-#include "elf/m32c.h"
-#include "elf/m32r.h"
-#include "elf/m68k.h"
-#include "elf/m68hc11.h"
-#include "elf/mcore.h"
-#include "elf/mep.h"
-#include "elf/mips.h"
-#include "elf/mmix.h"
-#include "elf/mn10200.h"
-#include "elf/mn10300.h"
-#include "elf/mt.h"
-#include "elf/msp430.h"
-#include "elf/or32.h"
-#include "elf/pj.h"
-#include "elf/ppc.h"
-#include "elf/ppc64.h"
-#include "elf/s390.h"
-#include "elf/score.h"
-#include "elf/sh.h"
-#include "elf/sparc.h"
-#include "elf/spu.h"
-#include "elf/v850.h"
-#include "elf/vax.h"
-#include "elf/x86-64.h"
-#include "elf/xstormy16.h"
-#include "elf/xtensa.h"
-
-#include "aout/ar.h"
-
-#include "getopt.h"
-#include "libiberty.h"
-#include "safe-ctype.h"
-
-char *program_name = "readelf";
-int do_wide;
-static long archive_file_offset;
-static unsigned long archive_file_size;
-static unsigned long dynamic_addr;
-static bfd_size_type dynamic_size;
-static unsigned int dynamic_nent;
-static char *dynamic_strings;
-static unsigned long dynamic_strings_length;
-static char *string_table;
-static unsigned long string_table_length;
-static unsigned long num_dynamic_syms;
-static Elf_Internal_Sym *dynamic_symbols;
-static Elf_Internal_Syminfo *dynamic_syminfo;
-static unsigned long dynamic_syminfo_offset;
-static unsigned int dynamic_syminfo_nent;
-static char program_interpreter[PATH_MAX];
-static bfd_vma dynamic_info[DT_JMPREL + 1];
-static bfd_vma dynamic_info_DT_GNU_HASH;
-static bfd_vma version_info[16];
-static Elf_Internal_Ehdr elf_header;
-static Elf_Internal_Shdr *section_headers;
-static Elf_Internal_Phdr *program_headers;
-static Elf_Internal_Dyn *dynamic_section;
-static Elf_Internal_Shdr *symtab_shndx_hdr;
-static int show_name;
-static int do_dynamic;
-static int do_syms;
-static int do_reloc;
-static int do_sections;
-static int do_section_groups;
-static int do_section_details;
-static int do_segments;
-static int do_unwind;
-static int do_using_dynamic;
-static int do_header;
-static int do_dump;
-static int do_version;
-static int do_histogram;
-static int do_debugging;
-static int do_arch;
-static int do_notes;
-static int do_archive_index;
-static int is_32bit_elf;
-
-struct group_list
-{
- struct group_list *next;
- unsigned int section_index;
-};
-
-struct group
-{
- struct group_list *root;
- unsigned int group_index;
-};
-
-static size_t group_count;
-static struct group *section_groups;
-static struct group **section_headers_groups;
-
-
-/* Flag bits indicating particular types of dump. */
-#define HEX_DUMP (1 << 0) /* The -x command line switch. */
-#define DISASS_DUMP (1 << 1) /* The -i command line switch. */
-#define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
-#define STRING_DUMP (1 << 3) /* The -p command line switch. */
-
-typedef unsigned char dump_type;
-
-/* A linked list of the section names for which dumps were requested. */
-struct dump_list_entry
-{
- char *name;
- dump_type type;
- struct dump_list_entry *next;
-};
-static struct dump_list_entry *dump_sects_byname;
-
-/* A dynamic array of flags indicating for which sections a dump
- has been requested via command line switches. */
-static dump_type * cmdline_dump_sects = NULL;
-static unsigned int num_cmdline_dump_sects = 0;
-
-/* A dynamic array of flags indicating for which sections a dump of
- some kind has been requested. It is reset on a per-object file
- basis and then initialised from the cmdline_dump_sects array,
- the results of interpreting the -w switch, and the
- dump_sects_byname list. */
-static dump_type * dump_sects = NULL;
-static unsigned int num_dump_sects = 0;
-
-
-/* How to print a vma value. */
-typedef enum print_mode
-{
- HEX,
- DEC,
- DEC_5,
- UNSIGNED,
- PREFIX_HEX,
- FULL_HEX,
- LONG_HEX
-}
-print_mode;
-
-static void (*byte_put) (unsigned char *, bfd_vma, int);
-
-#define UNKNOWN -1
-
-#define SECTION_NAME(X) \
- ((X) == NULL ? "<none>" \
- : string_table == NULL ? "<no-name>" \
- : ((X)->sh_name >= string_table_length ? "<corrupt>" \
- : string_table + (X)->sh_name))
-
-#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
-
-#define BYTE_GET(field) byte_get (field, sizeof (field))
-
-#define GET_ELF_SYMBOLS(file, section) \
- (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
- : get_64bit_elf_symbols (file, section))
-
-#define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
-/* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
- already been called and verified that the string exists. */
-#define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
-
-/* This is just a bit of syntatic sugar. */
-#define streq(a,b) (strcmp ((a), (b)) == 0)
-#define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
-#define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
-
-static void *
-get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
- const char *reason)
-{
- void *mvar;
-
- if (size == 0 || nmemb == 0)
- return NULL;
-
- if (fseek (file, archive_file_offset + offset, SEEK_SET))
- {
- error (_("Unable to seek to 0x%lx for %s\n"),
- (unsigned long) archive_file_offset + offset, reason);
- return NULL;
- }
-
- mvar = var;
- if (mvar == NULL)
- {
- /* Check for overflow. */
- if (nmemb < (~(size_t) 0 - 1) / size)
- /* + 1 so that we can '\0' terminate invalid string table sections. */
- mvar = malloc (size * nmemb + 1);
-
- if (mvar == NULL)
- {
- error (_("Out of memory allocating 0x%lx bytes for %s\n"),
- (unsigned long)(size * nmemb), reason);
- return NULL;
- }
-
- ((char *) mvar)[size * nmemb] = '\0';
- }
-
- if (fread (mvar, size, nmemb, file) != nmemb)
- {
- error (_("Unable to read in 0x%lx bytes of %s\n"),
- (unsigned long)(size * nmemb), reason);
- if (mvar != var)
- free (mvar);
- return NULL;
- }
-
- return mvar;
-}
-
-static void
-byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
-{
- switch (size)
- {
- case 8:
- field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
- field[6] = ((value >> 24) >> 24) & 0xff;
- field[5] = ((value >> 24) >> 16) & 0xff;
- field[4] = ((value >> 24) >> 8) & 0xff;
- /* Fall through. */
- case 4:
- field[3] = (value >> 24) & 0xff;
- field[2] = (value >> 16) & 0xff;
- /* Fall through. */
- case 2:
- field[1] = (value >> 8) & 0xff;
- /* Fall through. */
- case 1:
- field[0] = value & 0xff;
- break;
-
- default:
- error (_("Unhandled data length: %d\n"), size);
- abort ();
- }
-}
-
-/* Print a VMA value. */
-static int
-print_vma (bfd_vma vma, print_mode mode)
-{
- int nc = 0;
-
- switch (mode)
- {
- case FULL_HEX:
- nc = printf ("0x");
- /* Drop through. */
-
- case LONG_HEX:
-#ifdef BFD64
- if (is_32bit_elf)
- return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
-#endif
- printf_vma (vma);
- return nc + 16;
-
- case DEC_5:
- if (vma <= 99999)
- return printf ("%5" BFD_VMA_FMT "d", vma);
- /* Drop through. */
-
- case PREFIX_HEX:
- nc = printf ("0x");
- /* Drop through. */
-
- case HEX:
- return nc + printf ("%" BFD_VMA_FMT "x", vma);
-
- case DEC:
- return printf ("%" BFD_VMA_FMT "d", vma);
-
- case UNSIGNED:
- return printf ("%" BFD_VMA_FMT "u", vma);
- }
- return 0;
-}
-
-/* Display a symbol on stdout. Handles the display of
- non-printing characters.
- If DO_WIDE is not true then format the symbol to be
- at most WIDTH characters, truncating as necessary.
- If WIDTH is negative then format the string to be
- exactly - WIDTH characters, truncating or padding
- as necessary. */
-
-static void
-print_symbol (int width, const char *symbol)
-{
- const char * format_string;
- const char * c;
-
- if (do_wide)
- {
- format_string = "%.*s";
- /* Set the width to a very large value. This simplifies the code below. */
- width = INT_MAX;
- }
- else if (width < 0)
- {
- format_string = "%-*.*2s";
- /* Keep the width positive. This also helps. */
- width = - width;
- }
- else
- {
- format_string = "%-.*s";
- }
-
- while (width)
- {
- int len;
-
- c = symbol;
-
- /* Look for non-printing symbols inside the symbol's name.
- This test is triggered in particular by the names generated
- by the assembler for local labels. */
- while (ISPRINT (* c))
- c++;
-
- len = c - symbol;
-
- if (len)
- {
- if (len > width)
- len = width;
-
- printf (format_string, len, symbol);
-
- width -= len;
- }
-
- if (* c == 0 || width == 0)
- break;
-
- /* Now display the non-printing character, if
- there is room left in which to dipslay it. */
- if (*c < 32)
- {
- if (width < 2)
- break;
-
- printf ("^%c", *c + 0x40);
-
- width -= 2;
- }
- else
- {
- if (width < 6)
- break;
-
- printf ("<0x%.2x>", *c);
-
- width -= 6;
- }
-
- symbol = c + 1;
- }
-}
-
-static void
-byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
-{
- switch (size)
- {
- case 8:
- field[7] = value & 0xff;
- field[6] = (value >> 8) & 0xff;
- field[5] = (value >> 16) & 0xff;
- field[4] = (value >> 24) & 0xff;
- value >>= 16;
- value >>= 16;
- /* Fall through. */
- case 4:
- field[3] = value & 0xff;
- field[2] = (value >> 8) & 0xff;
- value >>= 16;
- /* Fall through. */
- case 2:
- field[1] = value & 0xff;
- value >>= 8;
- /* Fall through. */
- case 1:
- field[0] = value & 0xff;
- break;
-
- default:
- error (_("Unhandled data length: %d\n"), size);
- abort ();
- }
-}
-
-/* Return a pointer to section NAME, or NULL if no such section exists. */
-
-static Elf_Internal_Shdr *
-find_section (const char *name)
-{
- unsigned int i;
-
- for (i = 0; i < elf_header.e_shnum; i++)
- if (streq (SECTION_NAME (section_headers + i), name))
- return section_headers + i;
-
- return NULL;
-}
-
-/* Guess the relocation size commonly used by the specific machines. */
-
-static int
-guess_is_rela (unsigned int e_machine)
-{
- switch (e_machine)
- {
- /* Targets that use REL relocations. */
- case EM_386:
- case EM_486:
- case EM_960:
- case EM_ARM:
- case EM_D10V:
- case EM_CYGNUS_D10V:
- case EM_DLX:
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- case EM_CYGNUS_M32R:
- case EM_OPENRISC:
- case EM_OR32:
- case EM_SCORE:
- return FALSE;
-
- /* Targets that use RELA relocations. */
- case EM_68K:
- case EM_860:
- case EM_ALPHA:
- case EM_ALTERA_NIOS2:
- case EM_AVR:
- case EM_AVR_OLD:
- case EM_BLACKFIN:
- case EM_CR16:
- case EM_CR16_OLD:
- case EM_CRIS:
- case EM_CRX:
- case EM_D30V:
- case EM_CYGNUS_D30V:
- case EM_FR30:
- case EM_CYGNUS_FR30:
- case EM_CYGNUS_FRV:
- case EM_H8S:
- case EM_H8_300:
- case EM_H8_300H:
- case EM_IA_64:
- case EM_IP2K:
- case EM_IP2K_OLD:
- case EM_IQ2000:
- case EM_M32C_OLD:
- case EM_M32C:
- case EM_M32R:
- case EM_MCORE:
- case EM_CYGNUS_MEP:
- case EM_MMIX:
- case EM_MN10200:
- case EM_CYGNUS_MN10200:
- case EM_MN10300:
- case EM_CYGNUS_MN10300:
- case EM_MSP430:
- case EM_MSP430_OLD:
- case EM_MT:
- case EM_NIOS32:
- case EM_PPC64:
- case EM_PPC:
- case EM_S390:
- case EM_S390_OLD:
- case EM_SH:
- case EM_SPARC:
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- case EM_SPU:
- case EM_V850:
- case EM_CYGNUS_V850:
- case EM_VAX:
- case EM_X86_64:
- case EM_XSTORMY16:
- case EM_XTENSA:
- case EM_XTENSA_OLD:
- return TRUE;
-
- case EM_68HC05:
- case EM_68HC08:
- case EM_68HC11:
- case EM_68HC16:
- case EM_FX66:
- case EM_ME16:
- case EM_MMA:
- case EM_NCPU:
- case EM_NDR1:
- case EM_PCP:
- case EM_ST100:
- case EM_ST19:
- case EM_ST7:
- case EM_ST9PLUS:
- case EM_STARCORE:
- case EM_SVX:
- case EM_TINYJ:
- default:
- warn (_("Don't know about relocations on this machine architecture\n"));
- return FALSE;
- }
-}
-
-static int
-slurp_rela_relocs (FILE *file,
- unsigned long rel_offset,
- unsigned long rel_size,
- Elf_Internal_Rela **relasp,
- unsigned long *nrelasp)
-{
- Elf_Internal_Rela *relas;
- unsigned long nrelas;
- unsigned int i;
-
- if (is_32bit_elf)
- {
- Elf32_External_Rela *erelas;
-
- erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
- if (!erelas)
- return 0;
-
- nrelas = rel_size / sizeof (Elf32_External_Rela);
-
- relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
-
- if (relas == NULL)
- {
- free (erelas);
- error (_("out of memory parsing relocs\n"));
- return 0;
- }
-
- for (i = 0; i < nrelas; i++)
- {
- relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
- relas[i].r_info = BYTE_GET (erelas[i].r_info);
- relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
- }
-
- free (erelas);
- }
- else
- {
- Elf64_External_Rela *erelas;
-
- erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
- if (!erelas)
- return 0;
-
- nrelas = rel_size / sizeof (Elf64_External_Rela);
-
- relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
-
- if (relas == NULL)
- {
- free (erelas);
- error (_("out of memory parsing relocs\n"));
- return 0;
- }
-
- for (i = 0; i < nrelas; i++)
- {
- relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
- relas[i].r_info = BYTE_GET (erelas[i].r_info);
- relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
- }
-
- free (erelas);
- }
- *relasp = relas;
- *nrelasp = nrelas;
- return 1;
-}
-
-static int
-slurp_rel_relocs (FILE *file,
- unsigned long rel_offset,
- unsigned long rel_size,
- Elf_Internal_Rela **relsp,
- unsigned long *nrelsp)
-{
- Elf_Internal_Rela *rels;
- unsigned long nrels;
- unsigned int i;
-
- if (is_32bit_elf)
- {
- Elf32_External_Rel *erels;
-
- erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
- if (!erels)
- return 0;
-
- nrels = rel_size / sizeof (Elf32_External_Rel);
-
- rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
-
- if (rels == NULL)
- {
- free (erels);
- error (_("out of memory parsing relocs\n"));
- return 0;
- }
-
- for (i = 0; i < nrels; i++)
- {
- rels[i].r_offset = BYTE_GET (erels[i].r_offset);
- rels[i].r_info = BYTE_GET (erels[i].r_info);
- rels[i].r_addend = 0;
- }
-
- free (erels);
- }
- else
- {
- Elf64_External_Rel *erels;
-
- erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
- if (!erels)
- return 0;
-
- nrels = rel_size / sizeof (Elf64_External_Rel);
-
- rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
-
- if (rels == NULL)
- {
- free (erels);
- error (_("out of memory parsing relocs\n"));
- return 0;
- }
-
- for (i = 0; i < nrels; i++)
- {
- rels[i].r_offset = BYTE_GET (erels[i].r_offset);
- rels[i].r_info = BYTE_GET (erels[i].r_info);
- rels[i].r_addend = 0;
- }
-
- free (erels);
- }
- *relsp = rels;
- *nrelsp = nrels;
- return 1;
-}
-
-/* Returns the reloc type extracted from the reloc info field. */
-
-static unsigned int
-get_reloc_type (bfd_vma reloc_info)
-{
- if (is_32bit_elf)
- return ELF32_R_TYPE (reloc_info);
-
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- /* Note: We assume that reloc_info has already been adjusted for us. */
- return ELF64_MIPS_R_TYPE (reloc_info);
-
- case EM_SPARCV9:
- return ELF64_R_TYPE_ID (reloc_info);
-
- default:
- return ELF64_R_TYPE (reloc_info);
- }
-}
-
-/* Return the symbol index extracted from the reloc info field. */
-
-static bfd_vma
-get_reloc_symindex (bfd_vma reloc_info)
-{
- return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
-}
-
-/* Display the contents of the relocation data found at the specified
- offset. */
-
-static void
-dump_relocations (FILE *file,
- unsigned long rel_offset,
- unsigned long rel_size,
- Elf_Internal_Sym *symtab,
- unsigned long nsyms,
- char *strtab,
- unsigned long strtablen,
- int is_rela)
-{
- unsigned int i;
- Elf_Internal_Rela *rels;
-
-
- if (is_rela == UNKNOWN)
- is_rela = guess_is_rela (elf_header.e_machine);
-
- if (is_rela)
- {
- if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
- return;
- }
- else
- {
- if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
- return;
- }
-
- if (is_32bit_elf)
- {
- if (is_rela)
- {
- if (do_wide)
- printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
- else
- printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
- }
- else
- {
- if (do_wide)
- printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
- else
- printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
- }
- }
- else
- {
- if (is_rela)
- {
- if (do_wide)
- printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
- else
- printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
- }
- else
- {
- if (do_wide)
- printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
- else
- printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
- }
- }
-
- for (i = 0; i < rel_size; i++)
- {
- const char *rtype;
- bfd_vma offset;
- bfd_vma info;
- bfd_vma symtab_index;
- bfd_vma type;
-
- offset = rels[i].r_offset;
- info = rels[i].r_info;
-
- /* The #ifdef BFD64 below is to prevent a compile time warning.
- We know that if we do not have a 64 bit data type that we
- will never execute this code anyway. */
-#ifdef BFD64
- if (!is_32bit_elf
- && elf_header.e_machine == EM_MIPS
- && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
- {
- /* In little-endian objects, r_info isn't really a 64-bit
- little-endian value: it has a 32-bit little-endian
- symbol index followed by four individual byte fields.
- Reorder INFO accordingly. */
- info = (((info & 0xffffffff) << 32)
- | ((info >> 56) & 0xff)
- | ((info >> 40) & 0xff00)
- | ((info >> 24) & 0xff0000)
- | ((info >> 8) & 0xff000000));
- }
-#endif /* BFD64 */
-
- type = get_reloc_type (info);
- symtab_index = get_reloc_symindex (info);
-
- if (is_32bit_elf)
- {
- printf ("%8.8lx %8.8lx ",
- (unsigned long) offset & 0xffffffff,
- (unsigned long) info & 0xffffffff);
- }
- else
- {
-#if BFD_HOST_64BIT_LONG
- printf (do_wide
- ? "%16.16lx %16.16lx "
- : "%12.12lx %12.12lx ",
- offset, info);
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
- printf (do_wide
- ? "%16.16llx %16.16llx "
- : "%12.12llx %12.12llx ",
- offset, info);
-#else
- printf (do_wide
- ? "%16.16I64x %16.16I64x "
- : "%12.12I64x %12.12I64x ",
- offset, info);
-#endif
-#else
- printf (do_wide
- ? "%8.8lx%8.8lx %8.8lx%8.8lx "
- : "%4.4lx%8.8lx %4.4lx%8.8lx ",
- _bfd_int64_high (offset),
- _bfd_int64_low (offset),
- _bfd_int64_high (info),
- _bfd_int64_low (info));
-#endif
- }
-
- switch (elf_header.e_machine)
- {
- default:
- rtype = NULL;
- break;
-
- case EM_M32R:
- case EM_CYGNUS_M32R:
- rtype = elf_m32r_reloc_type (type);
- break;
-
- case EM_386:
- case EM_486:
- rtype = elf_i386_reloc_type (type);
- break;
-
- case EM_68HC11:
- case EM_68HC12:
- rtype = elf_m68hc11_reloc_type (type);
- break;
-
- case EM_68K:
- rtype = elf_m68k_reloc_type (type);
- break;
-
- case EM_960:
- rtype = elf_i960_reloc_type (type);
- break;
-
- case EM_AVR:
- case EM_AVR_OLD:
- rtype = elf_avr_reloc_type (type);
- break;
-
- case EM_OLD_SPARCV9:
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- case EM_SPARC:
- rtype = elf_sparc_reloc_type (type);
- break;
-
- case EM_SPU:
- rtype = elf_spu_reloc_type (type);
- break;
-
- case EM_V850:
- case EM_CYGNUS_V850:
- rtype = v850_reloc_type (type);
- break;
-
- case EM_D10V:
- case EM_CYGNUS_D10V:
- rtype = elf_d10v_reloc_type (type);
- break;
-
- case EM_D30V:
- case EM_CYGNUS_D30V:
- rtype = elf_d30v_reloc_type (type);
- break;
-
- case EM_DLX:
- rtype = elf_dlx_reloc_type (type);
- break;
-
- case EM_SH:
- rtype = elf_sh_reloc_type (type);
- break;
-
- case EM_MN10300:
- case EM_CYGNUS_MN10300:
- rtype = elf_mn10300_reloc_type (type);
- break;
-
- case EM_MN10200:
- case EM_CYGNUS_MN10200:
- rtype = elf_mn10200_reloc_type (type);
- break;
-
- case EM_FR30:
- case EM_CYGNUS_FR30:
- rtype = elf_fr30_reloc_type (type);
- break;
-
- case EM_CYGNUS_FRV:
- rtype = elf_frv_reloc_type (type);
- break;
-
- case EM_MCORE:
- rtype = elf_mcore_reloc_type (type);
- break;
-
- case EM_MMIX:
- rtype = elf_mmix_reloc_type (type);
- break;
-
- case EM_MSP430:
- case EM_MSP430_OLD:
- rtype = elf_msp430_reloc_type (type);
- break;
-
- case EM_PPC:
- rtype = elf_ppc_reloc_type (type);
- break;
-
- case EM_PPC64:
- rtype = elf_ppc64_reloc_type (type);
- break;
-
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- rtype = elf_mips_reloc_type (type);
- break;
-
- case EM_ALPHA:
- rtype = elf_alpha_reloc_type (type);
- break;
-
- case EM_ARM:
- rtype = elf_arm_reloc_type (type);
- break;
-
- case EM_ARC:
- rtype = elf_arc_reloc_type (type);
- break;
-
- case EM_PARISC:
- rtype = elf_hppa_reloc_type (type);
- break;
-
- case EM_H8_300:
- case EM_H8_300H:
- case EM_H8S:
- rtype = elf_h8_reloc_type (type);
- break;
-
- case EM_OPENRISC:
- case EM_OR32:
- rtype = elf_or32_reloc_type (type);
- break;
-
- case EM_PJ:
- case EM_PJ_OLD:
- rtype = elf_pj_reloc_type (type);
- break;
- case EM_IA_64:
- rtype = elf_ia64_reloc_type (type);
- break;
-
- case EM_CRIS:
- rtype = elf_cris_reloc_type (type);
- break;
-
- case EM_860:
- rtype = elf_i860_reloc_type (type);
- break;
-
- case EM_X86_64:
- rtype = elf_x86_64_reloc_type (type);
- break;
-
- case EM_S370:
- rtype = i370_reloc_type (type);
- break;
-
- case EM_S390_OLD:
- case EM_S390:
- rtype = elf_s390_reloc_type (type);
- break;
-
- case EM_SCORE:
- rtype = elf_score_reloc_type (type);
- break;
-
- case EM_XSTORMY16:
- rtype = elf_xstormy16_reloc_type (type);
- break;
-
- case EM_CRX:
- rtype = elf_crx_reloc_type (type);
- break;
-
- case EM_VAX:
- rtype = elf_vax_reloc_type (type);
- break;
-
- case EM_IP2K:
- case EM_IP2K_OLD:
- rtype = elf_ip2k_reloc_type (type);
- break;
-
- case EM_IQ2000:
- rtype = elf_iq2000_reloc_type (type);
- break;
-
- case EM_XTENSA_OLD:
- case EM_XTENSA:
- rtype = elf_xtensa_reloc_type (type);
- break;
-
- case EM_M32C_OLD:
- case EM_M32C:
- rtype = elf_m32c_reloc_type (type);
- break;
-
- case EM_MT:
- rtype = elf_mt_reloc_type (type);
- break;
-
- case EM_BLACKFIN:
- rtype = elf_bfin_reloc_type (type);
- break;
-
- case EM_CYGNUS_MEP:
- rtype = elf_mep_reloc_type (type);
- break;
-
- case EM_CR16:
- case EM_CR16_OLD:
- rtype = elf_cr16_reloc_type (type);
- break;
- }
-
- if (rtype == NULL)
- printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
- else
- printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
-
- if (elf_header.e_machine == EM_ALPHA
- && rtype != NULL
- && streq (rtype, "R_ALPHA_LITUSE")
- && is_rela)
- {
- switch (rels[i].r_addend)
- {
- case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
- case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
- case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
- case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
- case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
- case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
- case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
- default: rtype = NULL;
- }
- if (rtype)
- printf (" (%s)", rtype);
- else
- {
- putchar (' ');
- printf (_("<unknown addend: %lx>"),
- (unsigned long) rels[i].r_addend);
- }
- }
- else if (symtab_index)
- {
- if (symtab == NULL || symtab_index >= nsyms)
- printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
- else
- {
- Elf_Internal_Sym *psym;
-
- psym = symtab + symtab_index;
-
- printf (" ");
- print_vma (psym->st_value, LONG_HEX);
- printf (is_32bit_elf ? " " : " ");
-
- if (psym->st_name == 0)
- {
- const char *sec_name = "<null>";
- char name_buf[40];
-
- if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
- {
- if (psym->st_shndx < elf_header.e_shnum)
- sec_name
- = SECTION_NAME (section_headers + psym->st_shndx);
- else if (psym->st_shndx == SHN_ABS)
- sec_name = "ABS";
- else if (psym->st_shndx == SHN_COMMON)
- sec_name = "COMMON";
- else if (elf_header.e_machine == EM_MIPS
- && psym->st_shndx == SHN_MIPS_SCOMMON)
- sec_name = "SCOMMON";
- else if (elf_header.e_machine == EM_MIPS
- && psym->st_shndx == SHN_MIPS_SUNDEFINED)
- sec_name = "SUNDEF";
- else if (elf_header.e_machine == EM_X86_64
- && psym->st_shndx == SHN_X86_64_LCOMMON)
- sec_name = "LARGE_COMMON";
- else if (elf_header.e_machine == EM_IA_64
- && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
- && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
- sec_name = "ANSI_COM";
- else if (elf_header.e_machine == EM_IA_64
- && (elf_header.e_ident[EI_OSABI]
- == ELFOSABI_OPENVMS)
- && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
- sec_name = "VMS_SYMVEC";
- else
- {
- sprintf (name_buf, "<section 0x%x>",
- (unsigned int) psym->st_shndx);
- sec_name = name_buf;
- }
- }
- print_symbol (22, sec_name);
- }
- else if (strtab == NULL)
- printf (_("<string table index: %3ld>"), psym->st_name);
- else if (psym->st_name >= strtablen)
- printf (_("<corrupt string table index: %3ld>"), psym->st_name);
- else
- print_symbol (22, strtab + psym->st_name);
-
- if (is_rela)
- printf (" + %lx", (unsigned long) rels[i].r_addend);
- }
- }
- else if (is_rela)
- {
- printf ("%*c", is_32bit_elf ?
- (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
- print_vma (rels[i].r_addend, LONG_HEX);
- }
-
- if (elf_header.e_machine == EM_SPARCV9
- && rtype != NULL
- && streq (rtype, "R_SPARC_OLO10"))
- printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
-
- putchar ('\n');
-
-#ifdef BFD64
- if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
- {
- bfd_vma type2 = ELF64_MIPS_R_TYPE2 (info);
- bfd_vma type3 = ELF64_MIPS_R_TYPE3 (info);
- const char *rtype2 = elf_mips_reloc_type (type2);
- const char *rtype3 = elf_mips_reloc_type (type3);
-
- printf (" Type2: ");
-
- if (rtype2 == NULL)
- printf (_("unrecognized: %-7lx"),
- (unsigned long) type2 & 0xffffffff);
- else
- printf ("%-17.17s", rtype2);
-
- printf ("\n Type3: ");
-
- if (rtype3 == NULL)
- printf (_("unrecognized: %-7lx"),
- (unsigned long) type3 & 0xffffffff);
- else
- printf ("%-17.17s", rtype3);
-
- putchar ('\n');
- }
-#endif /* BFD64 */
- }
-
- free (rels);
-}
-
-static const char *
-get_mips_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
- case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
- case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
- case DT_MIPS_IVERSION: return "MIPS_IVERSION";
- case DT_MIPS_FLAGS: return "MIPS_FLAGS";
- case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
- case DT_MIPS_MSYM: return "MIPS_MSYM";
- case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
- case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
- case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
- case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
- case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
- case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
- case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
- case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
- case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
- case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
- case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
- case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
- case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
- case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
- case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
- case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
- case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
- case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
- case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
- case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
- case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
- case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
- case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
- case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
- case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
- case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
- case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
- case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
- case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
- case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
- case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
- case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
- case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
- case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
- case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
- case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_sparc64_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_SPARC_REGISTER: return "SPARC_REGISTER";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_ppc_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_PPC_GOT: return "PPC_GOT";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_ppc64_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_PPC64_GLINK: return "PPC64_GLINK";
- case DT_PPC64_OPD: return "PPC64_OPD";
- case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_parisc_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
- case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
- case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
- case DT_HP_UX10_INIT: return "HP_UX10_INIT";
- case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
- case DT_HP_PREINIT: return "HP_PREINIT";
- case DT_HP_PREINITSZ: return "HP_PREINITSZ";
- case DT_HP_NEEDED: return "HP_NEEDED";
- case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
- case DT_HP_CHECKSUM: return "HP_CHECKSUM";
- case DT_HP_GST_SIZE: return "HP_GST_SIZE";
- case DT_HP_GST_VERSION: return "HP_GST_VERSION";
- case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
- case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
- case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
- case DT_HP_FILTERED: return "HP_FILTERED";
- case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
- case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
- case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
- case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
- case DT_PLT: return "PLT";
- case DT_PLT_SIZE: return "PLT_SIZE";
- case DT_DLT: return "DLT";
- case DT_DLT_SIZE: return "DLT_SIZE";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_ia64_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
- case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
- case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
- case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
- case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
- case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
- case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
- case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
- case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
- case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
- case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
- case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
- case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
- case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
- case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
- case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
- case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
- case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
- case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
- case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
- case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
- case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
- case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
- case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
- case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
- case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
- case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
- case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
- case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
- case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
- case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_alpha_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
- default:
- return NULL;
- }
-}
-
-static const char *
-get_score_dynamic_type (unsigned long type)
-{
- switch (type)
- {
- case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
- case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
- case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
- case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
- case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
- case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
- default:
- return NULL;
- }
-}
-
-
-static const char *
-get_dynamic_type (unsigned long type)
-{
- static char buff[64];
-
- switch (type)
- {
- case DT_NULL: return "NULL";
- case DT_NEEDED: return "NEEDED";
- case DT_PLTRELSZ: return "PLTRELSZ";
- case DT_PLTGOT: return "PLTGOT";
- case DT_HASH: return "HASH";
- case DT_STRTAB: return "STRTAB";
- case DT_SYMTAB: return "SYMTAB";
- case DT_RELA: return "RELA";
- case DT_RELASZ: return "RELASZ";
- case DT_RELAENT: return "RELAENT";
- case DT_STRSZ: return "STRSZ";
- case DT_SYMENT: return "SYMENT";
- case DT_INIT: return "INIT";
- case DT_FINI: return "FINI";
- case DT_SONAME: return "SONAME";
- case DT_RPATH: return "RPATH";
- case DT_SYMBOLIC: return "SYMBOLIC";
- case DT_REL: return "REL";
- case DT_RELSZ: return "RELSZ";
- case DT_RELENT: return "RELENT";
- case DT_PLTREL: return "PLTREL";
- case DT_DEBUG: return "DEBUG";
- case DT_TEXTREL: return "TEXTREL";
- case DT_JMPREL: return "JMPREL";
- case DT_BIND_NOW: return "BIND_NOW";
- case DT_INIT_ARRAY: return "INIT_ARRAY";
- case DT_FINI_ARRAY: return "FINI_ARRAY";
- case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
- case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
- case DT_RUNPATH: return "RUNPATH";
- case DT_FLAGS: return "FLAGS";
-
- case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
- case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
-
- case DT_CHECKSUM: return "CHECKSUM";
- case DT_PLTPADSZ: return "PLTPADSZ";
- case DT_MOVEENT: return "MOVEENT";
- case DT_MOVESZ: return "MOVESZ";
- case DT_FEATURE: return "FEATURE";
- case DT_POSFLAG_1: return "POSFLAG_1";
- case DT_SYMINSZ: return "SYMINSZ";
- case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
-
- case DT_ADDRRNGLO: return "ADDRRNGLO";
- case DT_CONFIG: return "CONFIG";
- case DT_DEPAUDIT: return "DEPAUDIT";
- case DT_AUDIT: return "AUDIT";
- case DT_PLTPAD: return "PLTPAD";
- case DT_MOVETAB: return "MOVETAB";
- case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
-
- case DT_VERSYM: return "VERSYM";
-
- case DT_TLSDESC_GOT: return "TLSDESC_GOT";
- case DT_TLSDESC_PLT: return "TLSDESC_PLT";
- case DT_RELACOUNT: return "RELACOUNT";
- case DT_RELCOUNT: return "RELCOUNT";
- case DT_FLAGS_1: return "FLAGS_1";
- case DT_VERDEF: return "VERDEF";
- case DT_VERDEFNUM: return "VERDEFNUM";
- case DT_VERNEED: return "VERNEED";
- case DT_VERNEEDNUM: return "VERNEEDNUM";
-
- case DT_AUXILIARY: return "AUXILIARY";
- case DT_USED: return "USED";
- case DT_FILTER: return "FILTER";
-
- case DT_GNU_PRELINKED: return "GNU_PRELINKED";
- case DT_GNU_CONFLICT: return "GNU_CONFLICT";
- case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
- case DT_GNU_LIBLIST: return "GNU_LIBLIST";
- case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
- case DT_GNU_HASH: return "GNU_HASH";
-
- default:
- if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- result = get_mips_dynamic_type (type);
- break;
- case EM_SPARCV9:
- result = get_sparc64_dynamic_type (type);
- break;
- case EM_PPC:
- result = get_ppc_dynamic_type (type);
- break;
- case EM_PPC64:
- result = get_ppc64_dynamic_type (type);
- break;
- case EM_IA_64:
- result = get_ia64_dynamic_type (type);
- break;
- case EM_ALPHA:
- result = get_alpha_dynamic_type (type);
- break;
- case EM_SCORE:
- result = get_score_dynamic_type (type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
- }
- else if (((type >= DT_LOOS) && (type <= DT_HIOS))
- || (elf_header.e_machine == EM_PARISC
- && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_PARISC:
- result = get_parisc_dynamic_type (type);
- break;
- case EM_IA_64:
- result = get_ia64_dynamic_type (type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
- type);
- }
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
-
- return buff;
- }
-}
-
-static char *
-get_file_type (unsigned e_type)
-{
- static char buff[32];
-
- switch (e_type)
- {
- case ET_NONE: return _("NONE (None)");
- case ET_REL: return _("REL (Relocatable file)");
- case ET_EXEC: return _("EXEC (Executable file)");
- case ET_DYN: return _("DYN (Shared object file)");
- case ET_CORE: return _("CORE (Core file)");
-
- default:
- if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
- snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
- else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
- snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
- return buff;
- }
-}
-
-static char *
-get_machine_name (unsigned e_machine)
-{
- static char buff[64]; /* XXX */
-
- switch (e_machine)
- {
- case EM_NONE: return _("None");
- case EM_M32: return "WE32100";
- case EM_SPARC: return "Sparc";
- case EM_SPU: return "SPU";
- case EM_386: return "Intel 80386";
- case EM_68K: return "MC68000";
- case EM_88K: return "MC88000";
- case EM_486: return "Intel 80486";
- case EM_860: return "Intel 80860";
- case EM_MIPS: return "MIPS R3000";
- case EM_S370: return "IBM System/370";
- case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
- case EM_OLD_SPARCV9: return "Sparc v9 (old)";
- case EM_PARISC: return "HPPA";
- case EM_PPC_OLD: return "Power PC (old)";
- case EM_SPARC32PLUS: return "Sparc v8+" ;
- case EM_960: return "Intel 90860";
- case EM_PPC: return "PowerPC";
- case EM_PPC64: return "PowerPC64";
- case EM_V800: return "NEC V800";
- case EM_FR20: return "Fujitsu FR20";
- case EM_RH32: return "TRW RH32";
- case EM_MCORE: return "MCORE";
- case EM_ARM: return "ARM";
- case EM_OLD_ALPHA: return "Digital Alpha (old)";
- case EM_SH: return "Renesas / SuperH SH";
- case EM_SPARCV9: return "Sparc v9";
- case EM_TRICORE: return "Siemens Tricore";
- case EM_ARC: return "ARC";
- case EM_H8_300: return "Renesas H8/300";
- case EM_H8_300H: return "Renesas H8/300H";
- case EM_H8S: return "Renesas H8S";
- case EM_H8_500: return "Renesas H8/500";
- case EM_IA_64: return "Intel IA-64";
- case EM_MIPS_X: return "Stanford MIPS-X";
- case EM_COLDFIRE: return "Motorola Coldfire";
- case EM_68HC12: return "Motorola M68HC12";
- case EM_ALPHA: return "Alpha";
- case EM_CYGNUS_D10V:
- case EM_D10V: return "d10v";
- case EM_CYGNUS_D30V:
- case EM_D30V: return "d30v";
- case EM_CYGNUS_M32R:
- case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
- case EM_CYGNUS_V850:
- case EM_V850: return "NEC v850";
- case EM_CYGNUS_MN10300:
- case EM_MN10300: return "mn10300";
- case EM_CYGNUS_MN10200:
- case EM_MN10200: return "mn10200";
- case EM_CYGNUS_FR30:
- case EM_FR30: return "Fujitsu FR30";
- case EM_CYGNUS_FRV: return "Fujitsu FR-V";
- case EM_PJ_OLD:
- case EM_PJ: return "picoJava";
- case EM_MMA: return "Fujitsu Multimedia Accelerator";
- case EM_PCP: return "Siemens PCP";
- case EM_NCPU: return "Sony nCPU embedded RISC processor";
- case EM_NDR1: return "Denso NDR1 microprocesspr";
- case EM_STARCORE: return "Motorola Star*Core processor";
- case EM_ME16: return "Toyota ME16 processor";
- case EM_ST100: return "STMicroelectronics ST100 processor";
- case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
- case EM_FX66: return "Siemens FX66 microcontroller";
- case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
- case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
- case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
- case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
- case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
- case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
- case EM_SVX: return "Silicon Graphics SVx";
- case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
- case EM_VAX: return "Digital VAX";
- case EM_AVR_OLD:
- case EM_AVR: return "Atmel AVR 8-bit microcontroller";
- case EM_CRIS: return "Axis Communications 32-bit embedded processor";
- case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
- case EM_FIREPATH: return "Element 14 64-bit DSP processor";
- case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
- case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
- case EM_HUANY: return "Harvard Universitys's machine-independent object format";
- case EM_PRISM: return "Vitesse Prism";
- case EM_X86_64: return "Advanced Micro Devices X86-64";
- case EM_S390_OLD:
- case EM_S390: return "IBM S/390";
- case EM_SCORE: return "SUNPLUS S+Core";
- case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
- case EM_OPENRISC:
- case EM_OR32: return "OpenRISC";
- case EM_CRX: return "National Semiconductor CRX microprocessor";
- case EM_DLX: return "OpenDLX";
- case EM_IP2K_OLD:
- case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
- case EM_IQ2000: return "Vitesse IQ2000";
- case EM_XTENSA_OLD:
- case EM_XTENSA: return "Tensilica Xtensa Processor";
- case EM_M32C_OLD:
- case EM_M32C: return "Renesas M32c";
- case EM_MT: return "Morpho Techologies MT processor";
- case EM_BLACKFIN: return "Analog Devices Blackfin";
- case EM_NIOS32: return "Altera Nios";
- case EM_ALTERA_NIOS2: return "Altera Nios II";
- case EM_XC16X: return "Infineon Technologies xc16x";
- case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
- case EM_CR16:
- case EM_CR16_OLD: return "National Semiconductor's CR16";
- default:
- snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
- return buff;
- }
-}
-
-static void
-decode_ARM_machine_flags (unsigned e_flags, char buf[])
-{
- unsigned eabi;
- int unknown = 0;
-
- eabi = EF_ARM_EABI_VERSION (e_flags);
- e_flags &= ~ EF_ARM_EABIMASK;
-
- /* Handle "generic" ARM flags. */
- if (e_flags & EF_ARM_RELEXEC)
- {
- strcat (buf, ", relocatable executable");
- e_flags &= ~ EF_ARM_RELEXEC;
- }
-
- if (e_flags & EF_ARM_HASENTRY)
- {
- strcat (buf, ", has entry point");
- e_flags &= ~ EF_ARM_HASENTRY;
- }
-
- /* Now handle EABI specific flags. */
- switch (eabi)
- {
- default:
- strcat (buf, ", <unrecognized EABI>");
- if (e_flags)
- unknown = 1;
- break;
-
- case EF_ARM_EABI_VER1:
- strcat (buf, ", Version1 EABI");
- while (e_flags)
- {
- unsigned flag;
-
- /* Process flags one bit at a time. */
- flag = e_flags & - e_flags;
- e_flags &= ~ flag;
-
- switch (flag)
- {
- case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
- strcat (buf, ", sorted symbol tables");
- break;
-
- default:
- unknown = 1;
- break;
- }
- }
- break;
-
- case EF_ARM_EABI_VER2:
- strcat (buf, ", Version2 EABI");
- while (e_flags)
- {
- unsigned flag;
-
- /* Process flags one bit at a time. */
- flag = e_flags & - e_flags;
- e_flags &= ~ flag;
-
- switch (flag)
- {
- case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
- strcat (buf, ", sorted symbol tables");
- break;
-
- case EF_ARM_DYNSYMSUSESEGIDX:
- strcat (buf, ", dynamic symbols use segment index");
- break;
-
- case EF_ARM_MAPSYMSFIRST:
- strcat (buf, ", mapping symbols precede others");
- break;
-
- default:
- unknown = 1;
- break;
- }
- }
- break;
-
- case EF_ARM_EABI_VER3:
- strcat (buf, ", Version3 EABI");
- break;
-
- case EF_ARM_EABI_VER4:
- strcat (buf, ", Version4 EABI");
- goto eabi;
-
- case EF_ARM_EABI_VER5:
- strcat (buf, ", Version5 EABI");
- eabi:
- while (e_flags)
- {
- unsigned flag;
-
- /* Process flags one bit at a time. */
- flag = e_flags & - e_flags;
- e_flags &= ~ flag;
-
- switch (flag)
- {
- case EF_ARM_BE8:
- strcat (buf, ", BE8");
- break;
-
- case EF_ARM_LE8:
- strcat (buf, ", LE8");
- break;
-
- default:
- unknown = 1;
- break;
- }
- }
- break;
-
- case EF_ARM_EABI_UNKNOWN:
- strcat (buf, ", GNU EABI");
- while (e_flags)
- {
- unsigned flag;
-
- /* Process flags one bit at a time. */
- flag = e_flags & - e_flags;
- e_flags &= ~ flag;
-
- switch (flag)
- {
- case EF_ARM_INTERWORK:
- strcat (buf, ", interworking enabled");
- break;
-
- case EF_ARM_APCS_26:
- strcat (buf, ", uses APCS/26");
- break;
-
- case EF_ARM_APCS_FLOAT:
- strcat (buf, ", uses APCS/float");
- break;
-
- case EF_ARM_PIC:
- strcat (buf, ", position independent");
- break;
-
- case EF_ARM_ALIGN8:
- strcat (buf, ", 8 bit structure alignment");
- break;
-
- case EF_ARM_NEW_ABI:
- strcat (buf, ", uses new ABI");
- break;
-
- case EF_ARM_OLD_ABI:
- strcat (buf, ", uses old ABI");
- break;
-
- case EF_ARM_SOFT_FLOAT:
- strcat (buf, ", software FP");
- break;
-
- case EF_ARM_VFP_FLOAT:
- strcat (buf, ", VFP");
- break;
-
- case EF_ARM_MAVERICK_FLOAT:
- strcat (buf, ", Maverick FP");
- break;
-
- default:
- unknown = 1;
- break;
- }
- }
- }
-
- if (unknown)
- strcat (buf,", <unknown>");
-}
-
-static char *
-get_machine_flags (unsigned e_flags, unsigned e_machine)
-{
- static char buf[1024];
-
- buf[0] = '\0';
-
- if (e_flags)
- {
- switch (e_machine)
- {
- default:
- break;
-
- case EM_ARM:
- decode_ARM_machine_flags (e_flags, buf);
- break;
-
- case EM_CYGNUS_FRV:
- switch (e_flags & EF_FRV_CPU_MASK)
- {
- case EF_FRV_CPU_GENERIC:
- break;
-
- default:
- strcat (buf, ", fr???");
- break;
-
- case EF_FRV_CPU_FR300:
- strcat (buf, ", fr300");
- break;
-
- case EF_FRV_CPU_FR400:
- strcat (buf, ", fr400");
- break;
- case EF_FRV_CPU_FR405:
- strcat (buf, ", fr405");
- break;
-
- case EF_FRV_CPU_FR450:
- strcat (buf, ", fr450");
- break;
-
- case EF_FRV_CPU_FR500:
- strcat (buf, ", fr500");
- break;
- case EF_FRV_CPU_FR550:
- strcat (buf, ", fr550");
- break;
-
- case EF_FRV_CPU_SIMPLE:
- strcat (buf, ", simple");
- break;
- case EF_FRV_CPU_TOMCAT:
- strcat (buf, ", tomcat");
- break;
- }
- break;
-
- case EM_68K:
- if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
- strcat (buf, ", m68000");
- else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
- strcat (buf, ", cpu32");
- else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
- strcat (buf, ", fido_a");
- else
- {
- char const *isa = _("unknown");
- char const *mac = _("unknown mac");
- char const *additional = NULL;
-
- switch (e_flags & EF_M68K_CF_ISA_MASK)
- {
- case EF_M68K_CF_ISA_A_NODIV:
- isa = "A";
- additional = ", nodiv";
- break;
- case EF_M68K_CF_ISA_A:
- isa = "A";
- break;
- case EF_M68K_CF_ISA_A_PLUS:
- isa = "A+";
- break;
- case EF_M68K_CF_ISA_B_NOUSP:
- isa = "B";
- additional = ", nousp";
- break;
- case EF_M68K_CF_ISA_B:
- isa = "B";
- break;
- }
- strcat (buf, ", cf, isa ");
- strcat (buf, isa);
- if (additional)
- strcat (buf, additional);
- if (e_flags & EF_M68K_CF_FLOAT)
- strcat (buf, ", float");
- switch (e_flags & EF_M68K_CF_MAC_MASK)
- {
- case 0:
- mac = NULL;
- break;
- case EF_M68K_CF_MAC:
- mac = "mac";
- break;
- case EF_M68K_CF_EMAC:
- mac = "emac";
- break;
- }
- if (mac)
- {
- strcat (buf, ", ");
- strcat (buf, mac);
- }
- }
- break;
-
- case EM_PPC:
- if (e_flags & EF_PPC_EMB)
- strcat (buf, ", emb");
-
- if (e_flags & EF_PPC_RELOCATABLE)
- strcat (buf, ", relocatable");
-
- if (e_flags & EF_PPC_RELOCATABLE_LIB)
- strcat (buf, ", relocatable-lib");
- break;
-
- case EM_V850:
- case EM_CYGNUS_V850:
- switch (e_flags & EF_V850_ARCH)
- {
- case E_V850E1_ARCH:
- strcat (buf, ", v850e1");
- break;
- case E_V850E_ARCH:
- strcat (buf, ", v850e");
- break;
- case E_V850_ARCH:
- strcat (buf, ", v850");
- break;
- default:
- strcat (buf, ", unknown v850 architecture variant");
- break;
- }
- break;
-
- case EM_M32R:
- case EM_CYGNUS_M32R:
- if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
- strcat (buf, ", m32r");
- break;
-
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- if (e_flags & EF_MIPS_NOREORDER)
- strcat (buf, ", noreorder");
-
- if (e_flags & EF_MIPS_PIC)
- strcat (buf, ", pic");
-
- if (e_flags & EF_MIPS_CPIC)
- strcat (buf, ", cpic");
-
- if (e_flags & EF_MIPS_UCODE)
- strcat (buf, ", ugen_reserved");
-
- if (e_flags & EF_MIPS_ABI2)
- strcat (buf, ", abi2");
-
- if (e_flags & EF_MIPS_OPTIONS_FIRST)
- strcat (buf, ", odk first");
-
- if (e_flags & EF_MIPS_32BITMODE)
- strcat (buf, ", 32bitmode");
-
- switch ((e_flags & EF_MIPS_MACH))
- {
- case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
- case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
- case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
- case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
- case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
- case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
- case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
- case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
- case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
- case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
- case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
- case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
- case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
- case 0:
- /* We simply ignore the field in this case to avoid confusion:
- MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
- extension. */
- break;
- default: strcat (buf, ", unknown CPU"); break;
- }
-
- switch ((e_flags & EF_MIPS_ABI))
- {
- case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
- case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
- case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
- case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
- case 0:
- /* We simply ignore the field in this case to avoid confusion:
- MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
- This means it is likely to be an o32 file, but not for
- sure. */
- break;
- default: strcat (buf, ", unknown ABI"); break;
- }
-
- if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
- strcat (buf, ", mdmx");
-
- if (e_flags & EF_MIPS_ARCH_ASE_M16)
- strcat (buf, ", mips16");
-
- switch ((e_flags & EF_MIPS_ARCH))
- {
- case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
- case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
- case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
- case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
- case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
- case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
- case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
- case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
- case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
- default: strcat (buf, ", unknown ISA"); break;
- }
-
- break;
-
- case EM_SH:
- switch ((e_flags & EF_SH_MACH_MASK))
- {
- case EF_SH1: strcat (buf, ", sh1"); break;
- case EF_SH2: strcat (buf, ", sh2"); break;
- case EF_SH3: strcat (buf, ", sh3"); break;
- case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
- case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
- case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
- case EF_SH3E: strcat (buf, ", sh3e"); break;
- case EF_SH4: strcat (buf, ", sh4"); break;
- case EF_SH5: strcat (buf, ", sh5"); break;
- case EF_SH2E: strcat (buf, ", sh2e"); break;
- case EF_SH4A: strcat (buf, ", sh4a"); break;
- case EF_SH2A: strcat (buf, ", sh2a"); break;
- case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
- case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
- case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
- case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
- case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
- case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
- case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
- case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
- case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
- default: strcat (buf, ", unknown ISA"); break;
- }
-
- break;
-
- case EM_SPARCV9:
- if (e_flags & EF_SPARC_32PLUS)
- strcat (buf, ", v8+");
-
- if (e_flags & EF_SPARC_SUN_US1)
- strcat (buf, ", ultrasparcI");
-
- if (e_flags & EF_SPARC_SUN_US3)
- strcat (buf, ", ultrasparcIII");
-
- if (e_flags & EF_SPARC_HAL_R1)
- strcat (buf, ", halr1");
-
- if (e_flags & EF_SPARC_LEDATA)
- strcat (buf, ", ledata");
-
- if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
- strcat (buf, ", tso");
-
- if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
- strcat (buf, ", pso");
-
- if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
- strcat (buf, ", rmo");
- break;
-
- case EM_PARISC:
- switch (e_flags & EF_PARISC_ARCH)
- {
- case EFA_PARISC_1_0:
- strcpy (buf, ", PA-RISC 1.0");
- break;
- case EFA_PARISC_1_1:
- strcpy (buf, ", PA-RISC 1.1");
- break;
- case EFA_PARISC_2_0:
- strcpy (buf, ", PA-RISC 2.0");
- break;
- default:
- break;
- }
- if (e_flags & EF_PARISC_TRAPNIL)
- strcat (buf, ", trapnil");
- if (e_flags & EF_PARISC_EXT)
- strcat (buf, ", ext");
- if (e_flags & EF_PARISC_LSB)
- strcat (buf, ", lsb");
- if (e_flags & EF_PARISC_WIDE)
- strcat (buf, ", wide");
- if (e_flags & EF_PARISC_NO_KABP)
- strcat (buf, ", no kabp");
- if (e_flags & EF_PARISC_LAZYSWAP)
- strcat (buf, ", lazyswap");
- break;
-
- case EM_PJ:
- case EM_PJ_OLD:
- if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
- strcat (buf, ", new calling convention");
-
- if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
- strcat (buf, ", gnu calling convention");
- break;
-
- case EM_IA_64:
- if ((e_flags & EF_IA_64_ABI64))
- strcat (buf, ", 64-bit");
- else
- strcat (buf, ", 32-bit");
- if ((e_flags & EF_IA_64_REDUCEDFP))
- strcat (buf, ", reduced fp model");
- if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
- strcat (buf, ", no function descriptors, constant gp");
- else if ((e_flags & EF_IA_64_CONS_GP))
- strcat (buf, ", constant gp");
- if ((e_flags & EF_IA_64_ABSOLUTE))
- strcat (buf, ", absolute");
- break;
-
- case EM_VAX:
- if ((e_flags & EF_VAX_NONPIC))
- strcat (buf, ", non-PIC");
- if ((e_flags & EF_VAX_DFLOAT))
- strcat (buf, ", D-Float");
- if ((e_flags & EF_VAX_GFLOAT))
- strcat (buf, ", G-Float");
- break;
- }
- }
-
- return buf;
-}
-
-static const char *
-get_osabi_name (unsigned int osabi)
-{
- static char buff[32];
-
- switch (osabi)
- {
- case ELFOSABI_NONE: return "UNIX - System V";
- case ELFOSABI_HPUX: return "UNIX - HP-UX";
- case ELFOSABI_NETBSD: return "UNIX - NetBSD";
- case ELFOSABI_LINUX: return "UNIX - Linux";
- case ELFOSABI_HURD: return "GNU/Hurd";
- case ELFOSABI_SOLARIS: return "UNIX - Solaris";
- case ELFOSABI_AIX: return "UNIX - AIX";
- case ELFOSABI_IRIX: return "UNIX - IRIX";
- case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
- case ELFOSABI_TRU64: return "UNIX - TRU64";
- case ELFOSABI_MODESTO: return "Novell - Modesto";
- case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
- case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
- case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
- case ELFOSABI_AROS: return "AROS";
- case ELFOSABI_STANDALONE: return _("Standalone App");
- case ELFOSABI_ARM: return "ARM";
- default:
- snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
- return buff;
- }
-}
-
-static const char *
-get_arm_segment_type (unsigned long type)
-{
- switch (type)
- {
- case PT_ARM_EXIDX:
- return "EXIDX";
- default:
- break;
- }
-
- return NULL;
-}
-
-static const char *
-get_mips_segment_type (unsigned long type)
-{
- switch (type)
- {
- case PT_MIPS_REGINFO:
- return "REGINFO";
- case PT_MIPS_RTPROC:
- return "RTPROC";
- case PT_MIPS_OPTIONS:
- return "OPTIONS";
- default:
- break;
- }
-
- return NULL;
-}
-
-static const char *
-get_parisc_segment_type (unsigned long type)
-{
- switch (type)
- {
- case PT_HP_TLS: return "HP_TLS";
- case PT_HP_CORE_NONE: return "HP_CORE_NONE";
- case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
- case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
- case PT_HP_CORE_COMM: return "HP_CORE_COMM";
- case PT_HP_CORE_PROC: return "HP_CORE_PROC";
- case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
- case PT_HP_CORE_STACK: return "HP_CORE_STACK";
- case PT_HP_CORE_SHM: return "HP_CORE_SHM";
- case PT_HP_CORE_MMF: return "HP_CORE_MMF";
- case PT_HP_PARALLEL: return "HP_PARALLEL";
- case PT_HP_FASTBIND: return "HP_FASTBIND";
- case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
- case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
- case PT_HP_STACK: return "HP_STACK";
- case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
- case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
- case PT_PARISC_UNWIND: return "PARISC_UNWIND";
- case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
- default:
- break;
- }
-
- return NULL;
-}
-
-static const char *
-get_ia64_segment_type (unsigned long type)
-{
- switch (type)
- {
- case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
- case PT_IA_64_UNWIND: return "IA_64_UNWIND";
- case PT_HP_TLS: return "HP_TLS";
- case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
- case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
- case PT_IA_64_HP_STACK: return "HP_STACK";
- default:
- break;
- }
-
- return NULL;
-}
-
-static const char *
-get_segment_type (unsigned long p_type)
-{
- static char buff[32];
-
- switch (p_type)
- {
- case PT_NULL: return "NULL";
- case PT_LOAD: return "LOAD";
- case PT_DYNAMIC: return "DYNAMIC";
- case PT_INTERP: return "INTERP";
- case PT_NOTE: return "NOTE";
- case PT_SHLIB: return "SHLIB";
- case PT_PHDR: return "PHDR";
- case PT_TLS: return "TLS";
-
- case PT_GNU_EH_FRAME:
- return "GNU_EH_FRAME";
- case PT_GNU_STACK: return "GNU_STACK";
- case PT_GNU_RELRO: return "GNU_RELRO";
-
- default:
- if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_ARM:
- result = get_arm_segment_type (p_type);
- break;
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- result = get_mips_segment_type (p_type);
- break;
- case EM_PARISC:
- result = get_parisc_segment_type (p_type);
- break;
- case EM_IA_64:
- result = get_ia64_segment_type (p_type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
- }
- else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_PARISC:
- result = get_parisc_segment_type (p_type);
- break;
- case EM_IA_64:
- result = get_ia64_segment_type (p_type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
- }
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
-
- return buff;
- }
-}
-
-static const char *
-get_mips_section_type_name (unsigned int sh_type)
-{
- switch (sh_type)
- {
- case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
- case SHT_MIPS_MSYM: return "MIPS_MSYM";
- case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
- case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
- case SHT_MIPS_UCODE: return "MIPS_UCODE";
- case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
- case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
- case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
- case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
- case SHT_MIPS_RELD: return "MIPS_RELD";
- case SHT_MIPS_IFACE: return "MIPS_IFACE";
- case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
- case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
- case SHT_MIPS_SHDR: return "MIPS_SHDR";
- case SHT_MIPS_FDESC: return "MIPS_FDESC";
- case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
- case SHT_MIPS_DENSE: return "MIPS_DENSE";
- case SHT_MIPS_PDESC: return "MIPS_PDESC";
- case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
- case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
- case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
- case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
- case SHT_MIPS_LINE: return "MIPS_LINE";
- case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
- case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
- case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
- case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
- case SHT_MIPS_DWARF: return "MIPS_DWARF";
- case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
- case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
- case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
- case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
- case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
- case SHT_MIPS_XLATE: return "MIPS_XLATE";
- case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
- case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
- case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
- case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
- case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *
-get_parisc_section_type_name (unsigned int sh_type)
-{
- switch (sh_type)
- {
- case SHT_PARISC_EXT: return "PARISC_EXT";
- case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
- case SHT_PARISC_DOC: return "PARISC_DOC";
- case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
- case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
- case SHT_PARISC_STUBS: return "PARISC_STUBS";
- case SHT_PARISC_DLKM: return "PARISC_DLKM";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *
-get_ia64_section_type_name (unsigned int sh_type)
-{
- /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
- if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
- return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
-
- switch (sh_type)
- {
- case SHT_IA_64_EXT: return "IA_64_EXT";
- case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
- case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
- case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
- case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
- case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
- case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
- case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
- case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
- case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *
-get_x86_64_section_type_name (unsigned int sh_type)
-{
- switch (sh_type)
- {
- case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *
-get_arm_section_type_name (unsigned int sh_type)
-{
- switch (sh_type)
- {
- case SHT_ARM_EXIDX:
- return "ARM_EXIDX";
- case SHT_ARM_PREEMPTMAP:
- return "ARM_PREEMPTMAP";
- case SHT_ARM_ATTRIBUTES:
- return "ARM_ATTRIBUTES";
- default:
- break;
- }
- return NULL;
-}
-
-static const char *
-get_section_type_name (unsigned int sh_type)
-{
- static char buff[32];
-
- switch (sh_type)
- {
- case SHT_NULL: return "NULL";
- case SHT_PROGBITS: return "PROGBITS";
- case SHT_SYMTAB: return "SYMTAB";
- case SHT_STRTAB: return "STRTAB";
- case SHT_RELA: return "RELA";
- case SHT_HASH: return "HASH";
- case SHT_DYNAMIC: return "DYNAMIC";
- case SHT_NOTE: return "NOTE";
- case SHT_NOBITS: return "NOBITS";
- case SHT_REL: return "REL";
- case SHT_SHLIB: return "SHLIB";
- case SHT_DYNSYM: return "DYNSYM";
- case SHT_INIT_ARRAY: return "INIT_ARRAY";
- case SHT_FINI_ARRAY: return "FINI_ARRAY";
- case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
- case SHT_GNU_HASH: return "GNU_HASH";
- case SHT_GROUP: return "GROUP";
- case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
- case SHT_GNU_verdef: return "VERDEF";
- case SHT_GNU_verneed: return "VERNEED";
- case SHT_GNU_versym: return "VERSYM";
- case 0x6ffffff0: return "VERSYM";
- case 0x6ffffffc: return "VERDEF";
- case 0x7ffffffd: return "AUXILIARY";
- case 0x7fffffff: return "FILTER";
- case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
-
- default:
- if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- result = get_mips_section_type_name (sh_type);
- break;
- case EM_PARISC:
- result = get_parisc_section_type_name (sh_type);
- break;
- case EM_IA_64:
- result = get_ia64_section_type_name (sh_type);
- break;
- case EM_X86_64:
- result = get_x86_64_section_type_name (sh_type);
- break;
- case EM_ARM:
- result = get_arm_section_type_name (sh_type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
- }
- else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
- {
- const char *result;
-
- switch (elf_header.e_machine)
- {
- case EM_IA_64:
- result = get_ia64_section_type_name (sh_type);
- break;
- default:
- result = NULL;
- break;
- }
-
- if (result != NULL)
- return result;
-
- sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
- }
- else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
- sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
-
- return buff;
- }
-}
-
-#define OPTION_DEBUG_DUMP 512
-
-static struct option options[] =
-{
- {"all", no_argument, 0, 'a'},
- {"file-header", no_argument, 0, 'h'},
- {"program-headers", no_argument, 0, 'l'},
- {"headers", no_argument, 0, 'e'},
- {"histogram", no_argument, 0, 'I'},
- {"segments", no_argument, 0, 'l'},
- {"sections", no_argument, 0, 'S'},
- {"section-headers", no_argument, 0, 'S'},
- {"section-groups", no_argument, 0, 'g'},
- {"section-details", no_argument, 0, 't'},
- {"full-section-name",no_argument, 0, 'N'},
- {"symbols", no_argument, 0, 's'},
- {"syms", no_argument, 0, 's'},
- {"relocs", no_argument, 0, 'r'},
- {"notes", no_argument, 0, 'n'},
- {"dynamic", no_argument, 0, 'd'},
- {"arch-specific", no_argument, 0, 'A'},
- {"version-info", no_argument, 0, 'V'},
- {"use-dynamic", no_argument, 0, 'D'},
- {"unwind", no_argument, 0, 'u'},
- {"archive-index", no_argument, 0, 'c'},
- {"hex-dump", required_argument, 0, 'x'},
- {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
- {"string-dump", required_argument, 0, 'p'},
-#ifdef SUPPORT_DISASSEMBLY
- {"instruction-dump", required_argument, 0, 'i'},
-#endif
-
- {"version", no_argument, 0, 'v'},
- {"wide", no_argument, 0, 'W'},
- {"help", no_argument, 0, 'H'},
- {0, no_argument, 0, 0}
-};
-
-static void
-usage (FILE *stream)
-{
- fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
- fprintf (stream, _(" Display information about the contents of ELF format files\n"));
- fprintf (stream, _(" Options are:\n\
- -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
- -h --file-header Display the ELF file header\n\
- -l --program-headers Display the program headers\n\
- --segments An alias for --program-headers\n\
- -S --section-headers Display the sections' header\n\
- --sections An alias for --section-headers\n\
- -g --section-groups Display the section groups\n\
- -t --section-details Display the section details\n\
- -e --headers Equivalent to: -h -l -S\n\
- -s --syms Display the symbol table\n\
- --symbols An alias for --syms\n\
- -n --notes Display the core notes (if present)\n\
- -r --relocs Display the relocations (if present)\n\
- -u --unwind Display the unwind info (if present)\n\
- -d --dynamic Display the dynamic section (if present)\n\
- -V --version-info Display the version sections (if present)\n\
- -A --arch-specific Display architecture specific information (if any).\n\
- -c --archive-index Display the symbol/file index in an archive\n\
- -D --use-dynamic Use the dynamic section info when displaying symbols\n\
- -x --hex-dump=<number|name>\n\
- Dump the contents of section <number|name> as bytes\n\
- -p --string-dump=<number|name>\n\
- Dump the contents of section <number|name> as strings\n\
- -w[lLiaprmfFsoR] or\n\
- --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
- Display the contents of DWARF2 debug sections\n"));
-#ifdef SUPPORT_DISASSEMBLY
- fprintf (stream, _("\
- -i --instruction-dump=<number|name>\n\
- Disassemble the contents of section <number|name>\n"));
-#endif
- fprintf (stream, _("\
- -I --histogram Display histogram of bucket list lengths\n\
- -W --wide Allow output width to exceed 80 characters\n\
- @<file> Read options from <file>\n\
- -H --help Display this information\n\
- -v --version Display the version number of readelf\n"));
-
- if (REPORT_BUGS_TO[0] && stream == stdout)
- fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
-
- exit (stream == stdout ? 0 : 1);
-}
-
-/* Record the fact that the user wants the contents of section number
- SECTION to be displayed using the method(s) encoded as flags bits
- in TYPE. Note, TYPE can be zero if we are creating the array for
- the first time. */
-
-static void
-request_dump_bynumber (unsigned int section, dump_type type)
-{
- if (section >= num_dump_sects)
- {
- dump_type *new_dump_sects;
-
- new_dump_sects = calloc (section + 1, sizeof (* dump_sects));
-
- if (new_dump_sects == NULL)
- error (_("Out of memory allocating dump request table.\n"));
- else
- {
- /* Copy current flag settings. */
- memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
-
- free (dump_sects);
-
- dump_sects = new_dump_sects;
- num_dump_sects = section + 1;
- }
- }
-
- if (dump_sects)
- dump_sects[section] |= type;
-
- return;
-}
-
-/* Request a dump by section name. */
-
-static void
-request_dump_byname (const char *section, dump_type type)
-{
- struct dump_list_entry *new_request;
-
- new_request = malloc (sizeof (struct dump_list_entry));
- if (!new_request)
- error (_("Out of memory allocating dump request table.\n"));
-
- new_request->name = strdup (section);
- if (!new_request->name)
- error (_("Out of memory allocating dump request table.\n"));
-
- new_request->type = type;
-
- new_request->next = dump_sects_byname;
- dump_sects_byname = new_request;
-}
-
-static void
-parse_args (int argc, char **argv)
-{
- int c;
-
- if (argc < 2)
- usage (stderr);
-
- while ((c = getopt_long
- (argc, argv, "ADHINSVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF)
- {
- char *cp;
- int section;
-
- switch (c)
- {
- case 0:
- /* Long options. */
- break;
- case 'H':
- usage (stdout);
- break;
-
- case 'a':
- do_syms++;
- do_reloc++;
- do_unwind++;
- do_dynamic++;
- do_header++;
- do_sections++;
- do_section_groups++;
- do_segments++;
- do_version++;
- do_histogram++;
- do_arch++;
- do_notes++;
- break;
- case 'g':
- do_section_groups++;
- break;
- case 't':
- case 'N':
- do_sections++;
- do_section_details++;
- break;
- case 'e':
- do_header++;
- do_sections++;
- do_segments++;
- break;
- case 'A':
- do_arch++;
- break;
- case 'D':
- do_using_dynamic++;
- break;
- case 'r':
- do_reloc++;
- break;
- case 'u':
- do_unwind++;
- break;
- case 'h':
- do_header++;
- break;
- case 'l':
- do_segments++;
- break;
- case 's':
- do_syms++;
- break;
- case 'S':
- do_sections++;
- break;
- case 'd':
- do_dynamic++;
- break;
- case 'I':
- do_histogram++;
- break;
- case 'n':
- do_notes++;
- break;
- case 'c':
- do_archive_index++;
- break;
- case 'x':
- do_dump++;
- section = strtoul (optarg, & cp, 0);
- if (! *cp && section >= 0)
- request_dump_bynumber (section, HEX_DUMP);
- else
- request_dump_byname (optarg, HEX_DUMP);
- break;
- case 'p':
- do_dump++;
- section = strtoul (optarg, & cp, 0);
- if (! *cp && section >= 0)
- request_dump_bynumber (section, STRING_DUMP);
- else
- request_dump_byname (optarg, STRING_DUMP);
- break;
- case 'w':
- do_dump++;
- if (optarg == 0)
- do_debugging = 1;
- else
- {
- unsigned int index = 0;
-
- do_debugging = 0;
-
- while (optarg[index])
- switch (optarg[index++])
- {
- case 'i':
- do_debug_info = 1;
- break;
-
- case 'a':
- do_debug_abbrevs = 1;
- break;
-
- case 'l':
- do_debug_lines = 1;
- break;
-
- case 'L':
- do_debug_lines_decoded = 1;
- break;
-
- case 'p':
- do_debug_pubnames = 1;
- break;
-
- case 'r':
- do_debug_aranges = 1;
- break;
-
- case 'R':
- do_debug_ranges = 1;
- break;
-
- case 'F':
- do_debug_frames_interp = 1;
- case 'f':
- do_debug_frames = 1;
- break;
-
- case 'm':
- do_debug_macinfo = 1;
- break;
-
- case 's':
- do_debug_str = 1;
- break;
-
- case 'o':
- do_debug_loc = 1;
- break;
-
- default:
- warn (_("Unrecognized debug option '%s'\n"), optarg);
- break;
- }
- }
- break;
- case OPTION_DEBUG_DUMP:
- do_dump++;
- if (optarg == 0)
- do_debugging = 1;
- else
- {
- typedef struct
- {
- const char * option;
- int * variable;
- }
- debug_dump_long_opts;
-
- debug_dump_long_opts opts_table [] =
- {
- /* Please keep this table alpha- sorted. */
- { "Ranges", & do_debug_ranges },
- { "abbrev", & do_debug_abbrevs },
- { "aranges", & do_debug_aranges },
- { "frames", & do_debug_frames },
- { "frames-interp", & do_debug_frames_interp },
- { "info", & do_debug_info },
- { "line", & do_debug_lines }, /* For backwards compatibility. */
- { "rawline", & do_debug_lines },
- { "decodedline", & do_debug_lines_decoded },
- { "loc", & do_debug_loc },
- { "macro", & do_debug_macinfo },
- { "pubnames", & do_debug_pubnames },
- /* This entry is for compatability
- with earlier versions of readelf. */
- { "ranges", & do_debug_aranges },
- { "str", & do_debug_str },
- { NULL, NULL }
- };
-
- const char *p;
-
- do_debugging = 0;
-
- p = optarg;
- while (*p)
- {
- debug_dump_long_opts * entry;
-
- for (entry = opts_table; entry->option; entry++)
- {
- size_t len = strlen (entry->option);
-
- if (strneq (p, entry->option, len)
- && (p[len] == ',' || p[len] == '\0'))
- {
- * entry->variable = 1;
-
- /* The --debug-dump=frames-interp option also
- enables the --debug-dump=frames option. */
- if (do_debug_frames_interp)
- do_debug_frames = 1;
-
- p += len;
- break;
- }
- }
-
- if (entry->option == NULL)
- {
- warn (_("Unrecognized debug option '%s'\n"), p);
- p = strchr (p, ',');
- if (p == NULL)
- break;
- }
-
- if (*p == ',')
- p++;
- }
- }
- break;
-#ifdef SUPPORT_DISASSEMBLY
- case 'i':
- do_dump++;
- section = strtoul (optarg, & cp, 0);
- if (! *cp && section >= 0)
- request_dump_bynumber (section, DISASS_DUMP);
- else
- request_dump_byname (optarg, DISASS_DUMP);
-#endif
- case 'v':
- print_version (program_name);
- break;
- case 'V':
- do_version++;
- break;
- case 'W':
- do_wide++;
- break;
- default:
- /* xgettext:c-format */
- error (_("Invalid option '-%c'\n"), c);
- /* Drop through. */
- case '?':
- usage (stderr);
- }
- }
-
- if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
- && !do_segments && !do_header && !do_dump && !do_version
- && !do_histogram && !do_debugging && !do_arch && !do_notes
- && !do_section_groups && !do_archive_index)
- usage (stderr);
- else if (argc < 3)
- {
- warn (_("Nothing to do.\n"));
- usage (stderr);
- }
-}
-
-static const char *
-get_elf_class (unsigned int elf_class)
-{
- static char buff[32];
-
- switch (elf_class)
- {
- case ELFCLASSNONE: return _("none");
- case ELFCLASS32: return "ELF32";
- case ELFCLASS64: return "ELF64";
- default:
- snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
- return buff;
- }
-}
-
-static const char *
-get_data_encoding (unsigned int encoding)
-{
- static char buff[32];
-
- switch (encoding)
- {
- case ELFDATANONE: return _("none");
- case ELFDATA2LSB: return _("2's complement, little endian");
- case ELFDATA2MSB: return _("2's complement, big endian");
- default:
- snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
- return buff;
- }
-}
-
-/* Decode the data held in 'elf_header'. */
-
-static int
-process_file_header (void)
-{
- if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
- || elf_header.e_ident[EI_MAG1] != ELFMAG1
- || elf_header.e_ident[EI_MAG2] != ELFMAG2
- || elf_header.e_ident[EI_MAG3] != ELFMAG3)
- {
- error
- (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
- return 0;
- }
-
- init_dwarf_regnames (elf_header.e_machine);
-
- if (do_header)
- {
- int i;
-
- printf (_("ELF Header:\n"));
- printf (_(" Magic: "));
- for (i = 0; i < EI_NIDENT; i++)
- printf ("%2.2x ", elf_header.e_ident[i]);
- printf ("\n");
- printf (_(" Class: %s\n"),
- get_elf_class (elf_header.e_ident[EI_CLASS]));
- printf (_(" Data: %s\n"),
- get_data_encoding (elf_header.e_ident[EI_DATA]));
- printf (_(" Version: %d %s\n"),
- elf_header.e_ident[EI_VERSION],
- (elf_header.e_ident[EI_VERSION] == EV_CURRENT
- ? "(current)"
- : (elf_header.e_ident[EI_VERSION] != EV_NONE
- ? "<unknown: %lx>"
- : "")));
- printf (_(" OS/ABI: %s\n"),
- get_osabi_name (elf_header.e_ident[EI_OSABI]));
- printf (_(" ABI Version: %d\n"),
- elf_header.e_ident[EI_ABIVERSION]);
- printf (_(" Type: %s\n"),
- get_file_type (elf_header.e_type));
- printf (_(" Machine: %s\n"),
- get_machine_name (elf_header.e_machine));
- printf (_(" Version: 0x%lx\n"),
- (unsigned long) elf_header.e_version);
-
- printf (_(" Entry point address: "));
- print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
- printf (_("\n Start of program headers: "));
- print_vma ((bfd_vma) elf_header.e_phoff, DEC);
- printf (_(" (bytes into file)\n Start of section headers: "));
- print_vma ((bfd_vma) elf_header.e_shoff, DEC);
- printf (_(" (bytes into file)\n"));
-
- printf (_(" Flags: 0x%lx%s\n"),
- (unsigned long) elf_header.e_flags,
- get_machine_flags (elf_header.e_flags, elf_header.e_machine));
- printf (_(" Size of this header: %ld (bytes)\n"),
- (long) elf_header.e_ehsize);
- printf (_(" Size of program headers: %ld (bytes)\n"),
- (long) elf_header.e_phentsize);
- printf (_(" Number of program headers: %ld\n"),
- (long) elf_header.e_phnum);
- printf (_(" Size of section headers: %ld (bytes)\n"),
- (long) elf_header.e_shentsize);
- printf (_(" Number of section headers: %ld"),
- (long) elf_header.e_shnum);
- if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
- printf (" (%ld)", (long) section_headers[0].sh_size);
- putc ('\n', stdout);
- printf (_(" Section header string table index: %ld"),
- (long) elf_header.e_shstrndx);
- if (section_headers != NULL
- && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
- printf (" (%u)", section_headers[0].sh_link);
- else if (elf_header.e_shstrndx >= elf_header.e_shnum)
- printf (" <corrupt: out of range>");
- putc ('\n', stdout);
- }
-
- if (section_headers != NULL)
- {
- if (elf_header.e_shnum == SHN_UNDEF)
- elf_header.e_shnum = section_headers[0].sh_size;
- if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
- elf_header.e_shstrndx = section_headers[0].sh_link;
- else if (elf_header.e_shstrndx >= elf_header.e_shnum)
- elf_header.e_shstrndx = SHN_UNDEF;
- free (section_headers);
- section_headers = NULL;
- }
-
- return 1;
-}
-
-
-static int
-get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
-{
- Elf32_External_Phdr *phdrs;
- Elf32_External_Phdr *external;
- Elf_Internal_Phdr *internal;
- unsigned int i;
-
- phdrs = get_data (NULL, file, elf_header.e_phoff,
- elf_header.e_phentsize, elf_header.e_phnum,
- _("program headers"));
- if (!phdrs)
- return 0;
-
- for (i = 0, internal = program_headers, external = phdrs;
- i < elf_header.e_phnum;
- i++, internal++, external++)
- {
- internal->p_type = BYTE_GET (external->p_type);
- internal->p_offset = BYTE_GET (external->p_offset);
- internal->p_vaddr = BYTE_GET (external->p_vaddr);
- internal->p_paddr = BYTE_GET (external->p_paddr);
- internal->p_filesz = BYTE_GET (external->p_filesz);
- internal->p_memsz = BYTE_GET (external->p_memsz);
- internal->p_flags = BYTE_GET (external->p_flags);
- internal->p_align = BYTE_GET (external->p_align);
- }
-
- free (phdrs);
-
- return 1;
-}
-
-static int
-get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
-{
- Elf64_External_Phdr *phdrs;
- Elf64_External_Phdr *external;
- Elf_Internal_Phdr *internal;
- unsigned int i;
-
- phdrs = get_data (NULL, file, elf_header.e_phoff,
- elf_header.e_phentsize, elf_header.e_phnum,
- _("program headers"));
- if (!phdrs)
- return 0;
-
- for (i = 0, internal = program_headers, external = phdrs;
- i < elf_header.e_phnum;
- i++, internal++, external++)
- {
- internal->p_type = BYTE_GET (external->p_type);
- internal->p_flags = BYTE_GET (external->p_flags);
- internal->p_offset = BYTE_GET (external->p_offset);
- internal->p_vaddr = BYTE_GET (external->p_vaddr);
- internal->p_paddr = BYTE_GET (external->p_paddr);
- internal->p_filesz = BYTE_GET (external->p_filesz);
- internal->p_memsz = BYTE_GET (external->p_memsz);
- internal->p_align = BYTE_GET (external->p_align);
- }
-
- free (phdrs);
-
- return 1;
-}
-
-/* Returns 1 if the program headers were read into `program_headers'. */
-
-static int
-get_program_headers (FILE *file)
-{
- Elf_Internal_Phdr *phdrs;
-
- /* Check cache of prior read. */
- if (program_headers != NULL)
- return 1;
-
- phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
-
- if (phdrs == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- if (is_32bit_elf
- ? get_32bit_program_headers (file, phdrs)
- : get_64bit_program_headers (file, phdrs))
- {
- program_headers = phdrs;
- return 1;
- }
-
- free (phdrs);
- return 0;
-}
-
-/* Returns 1 if the program headers were loaded. */
-
-static int
-process_program_headers (FILE *file)
-{
- Elf_Internal_Phdr *segment;
- unsigned int i;
-
- if (elf_header.e_phnum == 0)
- {
- if (do_segments)
- printf (_("\nThere are no program headers in this file.\n"));
- return 0;
- }
-
- if (do_segments && !do_header)
- {
- printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
- printf (_("Entry point "));
- print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
- printf (_("\nThere are %d program headers, starting at offset "),
- elf_header.e_phnum);
- print_vma ((bfd_vma) elf_header.e_phoff, DEC);
- printf ("\n");
- }
-
- if (! get_program_headers (file))
- return 0;
-
- if (do_segments)
- {
- if (elf_header.e_phnum > 1)
- printf (_("\nProgram Headers:\n"));
- else
- printf (_("\nProgram Headers:\n"));
-
- if (is_32bit_elf)
- printf
- (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
- else if (do_wide)
- printf
- (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
- else
- {
- printf
- (_(" Type Offset VirtAddr PhysAddr\n"));
- printf
- (_(" FileSiz MemSiz Flags Align\n"));
- }
- }
-
- dynamic_addr = 0;
- dynamic_size = 0;
-
- for (i = 0, segment = program_headers;
- i < elf_header.e_phnum;
- i++, segment++)
- {
- if (do_segments)
- {
- printf (" %-14.14s ", get_segment_type (segment->p_type));
-
- if (is_32bit_elf)
- {
- printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
- printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
- printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
- printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
- printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
- printf ("%c%c%c ",
- (segment->p_flags & PF_R ? 'R' : ' '),
- (segment->p_flags & PF_W ? 'W' : ' '),
- (segment->p_flags & PF_X ? 'E' : ' '));
- printf ("%#lx", (unsigned long) segment->p_align);
- }
- else if (do_wide)
- {
- if ((unsigned long) segment->p_offset == segment->p_offset)
- printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
- else
- {
- print_vma (segment->p_offset, FULL_HEX);
- putchar (' ');
- }
-
- print_vma (segment->p_vaddr, FULL_HEX);
- putchar (' ');
- print_vma (segment->p_paddr, FULL_HEX);
- putchar (' ');
-
- if ((unsigned long) segment->p_filesz == segment->p_filesz)
- printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
- else
- {
- print_vma (segment->p_filesz, FULL_HEX);
- putchar (' ');
- }
-
- if ((unsigned long) segment->p_memsz == segment->p_memsz)
- printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
- else
- {
- print_vma (segment->p_offset, FULL_HEX);
- }
-
- printf (" %c%c%c ",
- (segment->p_flags & PF_R ? 'R' : ' '),
- (segment->p_flags & PF_W ? 'W' : ' '),
- (segment->p_flags & PF_X ? 'E' : ' '));
-
- if ((unsigned long) segment->p_align == segment->p_align)
- printf ("%#lx", (unsigned long) segment->p_align);
- else
- {
- print_vma (segment->p_align, PREFIX_HEX);
- }
- }
- else
- {
- print_vma (segment->p_offset, FULL_HEX);
- putchar (' ');
- print_vma (segment->p_vaddr, FULL_HEX);
- putchar (' ');
- print_vma (segment->p_paddr, FULL_HEX);
- printf ("\n ");
- print_vma (segment->p_filesz, FULL_HEX);
- putchar (' ');
- print_vma (segment->p_memsz, FULL_HEX);
- printf (" %c%c%c ",
- (segment->p_flags & PF_R ? 'R' : ' '),
- (segment->p_flags & PF_W ? 'W' : ' '),
- (segment->p_flags & PF_X ? 'E' : ' '));
- print_vma (segment->p_align, HEX);
- }
- }
-
- switch (segment->p_type)
- {
- case PT_DYNAMIC:
- if (dynamic_addr)
- error (_("more than one dynamic segment\n"));
-
- /* By default, assume that the .dynamic section is the first
- section in the DYNAMIC segment. */
- dynamic_addr = segment->p_offset;
- dynamic_size = segment->p_filesz;
-
- /* Try to locate the .dynamic section. If there is
- a section header table, we can easily locate it. */
- if (section_headers != NULL)
- {
- Elf_Internal_Shdr *sec;
-
- sec = find_section (".dynamic");
- if (sec == NULL || sec->sh_size == 0)
- {
- error (_("no .dynamic section in the dynamic segment\n"));
- break;
- }
-
- if (sec->sh_type == SHT_NOBITS)
- {
- dynamic_size = 0;
- break;
- }
-
- dynamic_addr = sec->sh_offset;
- dynamic_size = sec->sh_size;
-
- if (dynamic_addr < segment->p_offset
- || dynamic_addr > segment->p_offset + segment->p_filesz)
- warn (_("the .dynamic section is not contained"
- " within the dynamic segment\n"));
- else if (dynamic_addr > segment->p_offset)
- warn (_("the .dynamic section is not the first section"
- " in the dynamic segment.\n"));
- }
- break;
-
- case PT_INTERP:
- if (fseek (file, archive_file_offset + (long) segment->p_offset,
- SEEK_SET))
- error (_("Unable to find program interpreter name\n"));
- else
- {
- char fmt [32];
- int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX);
-
- if (ret >= (int) sizeof (fmt) || ret < 0)
- error (_("Internal error: failed to create format string to display program interpreter\n"));
-
- program_interpreter[0] = 0;
- if (fscanf (file, fmt, program_interpreter) <= 0)
- error (_("Unable to read program interpreter name\n"));
-
- if (do_segments)
- printf (_("\n [Requesting program interpreter: %s]"),
- program_interpreter);
- }
- break;
- }
-
- if (do_segments)
- putc ('\n', stdout);
- }
-
- if (do_segments && section_headers != NULL && string_table != NULL)
- {
- printf (_("\n Section to Segment mapping:\n"));
- printf (_(" Segment Sections...\n"));
-
- for (i = 0; i < elf_header.e_phnum; i++)
- {
- unsigned int j;
- Elf_Internal_Shdr *section;
-
- segment = program_headers + i;
- section = section_headers + 1;
-
- printf (" %2.2d ", i);
-
- for (j = 1; j < elf_header.e_shnum; j++, section++)
- {
- if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment))
- printf ("%s ", SECTION_NAME (section));
- }
-
- putc ('\n',stdout);
- }
- }
-
- return 1;
-}
-
-
-/* Find the file offset corresponding to VMA by using the program headers. */
-
-static long
-offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
-{
- Elf_Internal_Phdr *seg;
-
- if (! get_program_headers (file))
- {
- warn (_("Cannot interpret virtual addresses without program headers.\n"));
- return (long) vma;
- }
-
- for (seg = program_headers;
- seg < program_headers + elf_header.e_phnum;
- ++seg)
- {
- if (seg->p_type != PT_LOAD)
- continue;
-
- if (vma >= (seg->p_vaddr & -seg->p_align)
- && vma + size <= seg->p_vaddr + seg->p_filesz)
- return vma - seg->p_vaddr + seg->p_offset;
- }
-
- warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
- (unsigned long) vma);
- return (long) vma;
-}
-
-
-static int
-get_32bit_section_headers (FILE *file, unsigned int num)
-{
- Elf32_External_Shdr *shdrs;
- Elf_Internal_Shdr *internal;
- unsigned int i;
-
- shdrs = get_data (NULL, file, elf_header.e_shoff,
- elf_header.e_shentsize, num, _("section headers"));
- if (!shdrs)
- return 0;
-
- section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
-
- if (section_headers == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- for (i = 0, internal = section_headers;
- i < num;
- i++, internal++)
- {
- internal->sh_name = BYTE_GET (shdrs[i].sh_name);
- internal->sh_type = BYTE_GET (shdrs[i].sh_type);
- internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
- internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
- internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
- internal->sh_size = BYTE_GET (shdrs[i].sh_size);
- internal->sh_link = BYTE_GET (shdrs[i].sh_link);
- internal->sh_info = BYTE_GET (shdrs[i].sh_info);
- internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
- internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
- }
-
- free (shdrs);
-
- return 1;
-}
-
-static int
-get_64bit_section_headers (FILE *file, unsigned int num)
-{
- Elf64_External_Shdr *shdrs;
- Elf_Internal_Shdr *internal;
- unsigned int i;
-
- shdrs = get_data (NULL, file, elf_header.e_shoff,
- elf_header.e_shentsize, num, _("section headers"));
- if (!shdrs)
- return 0;
-
- section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
-
- if (section_headers == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- for (i = 0, internal = section_headers;
- i < num;
- i++, internal++)
- {
- internal->sh_name = BYTE_GET (shdrs[i].sh_name);
- internal->sh_type = BYTE_GET (shdrs[i].sh_type);
- internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
- internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
- internal->sh_size = BYTE_GET (shdrs[i].sh_size);
- internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
- internal->sh_link = BYTE_GET (shdrs[i].sh_link);
- internal->sh_info = BYTE_GET (shdrs[i].sh_info);
- internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
- internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
- }
-
- free (shdrs);
-
- return 1;
-}
-
-static Elf_Internal_Sym *
-get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
-{
- unsigned long number;
- Elf32_External_Sym *esyms;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym *isyms;
- Elf_Internal_Sym *psym;
- unsigned int j;
-
- esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
- _("symbols"));
- if (!esyms)
- return NULL;
-
- shndx = NULL;
- if (symtab_shndx_hdr != NULL
- && (symtab_shndx_hdr->sh_link
- == (unsigned long) (section - section_headers)))
- {
- shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
- 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
- if (!shndx)
- {
- free (esyms);
- return NULL;
- }
- }
-
- number = section->sh_size / section->sh_entsize;
- isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
-
- if (isyms == NULL)
- {
- error (_("Out of memory\n"));
- if (shndx)
- free (shndx);
- free (esyms);
- return NULL;
- }
-
- for (j = 0, psym = isyms;
- j < number;
- j++, psym++)
- {
- psym->st_name = BYTE_GET (esyms[j].st_name);
- psym->st_value = BYTE_GET (esyms[j].st_value);
- psym->st_size = BYTE_GET (esyms[j].st_size);
- psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
- if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
- psym->st_shndx
- = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
- else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
- psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
- psym->st_info = BYTE_GET (esyms[j].st_info);
- psym->st_other = BYTE_GET (esyms[j].st_other);
- }
-
- if (shndx)
- free (shndx);
- free (esyms);
-
- return isyms;
-}
-
-static Elf_Internal_Sym *
-get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
-{
- unsigned long number;
- Elf64_External_Sym *esyms;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym *isyms;
- Elf_Internal_Sym *psym;
- unsigned int j;
-
- esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
- _("symbols"));
- if (!esyms)
- return NULL;
-
- shndx = NULL;
- if (symtab_shndx_hdr != NULL
- && (symtab_shndx_hdr->sh_link
- == (unsigned long) (section - section_headers)))
- {
- shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
- 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
- if (!shndx)
- {
- free (esyms);
- return NULL;
- }
- }
-
- number = section->sh_size / section->sh_entsize;
- isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
-
- if (isyms == NULL)
- {
- error (_("Out of memory\n"));
- if (shndx)
- free (shndx);
- free (esyms);
- return NULL;
- }
-
- for (j = 0, psym = isyms;
- j < number;
- j++, psym++)
- {
- psym->st_name = BYTE_GET (esyms[j].st_name);
- psym->st_info = BYTE_GET (esyms[j].st_info);
- psym->st_other = BYTE_GET (esyms[j].st_other);
- psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
- if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
- psym->st_shndx
- = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
- else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
- psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
- psym->st_value = BYTE_GET (esyms[j].st_value);
- psym->st_size = BYTE_GET (esyms[j].st_size);
- }
-
- if (shndx)
- free (shndx);
- free (esyms);
-
- return isyms;
-}
-
-static const char *
-get_elf_section_flags (bfd_vma sh_flags)
-{
- static char buff[1024];
- char *p = buff;
- int field_size = is_32bit_elf ? 8 : 16;
- int index, size = sizeof (buff) - (field_size + 4 + 1);
- bfd_vma os_flags = 0;
- bfd_vma proc_flags = 0;
- bfd_vma unknown_flags = 0;
- static const struct
- {
- const char *str;
- int len;
- }
- flags [] =
- {
- { "WRITE", 5 },
- { "ALLOC", 5 },
- { "EXEC", 4 },
- { "MERGE", 5 },
- { "STRINGS", 7 },
- { "INFO LINK", 9 },
- { "LINK ORDER", 10 },
- { "OS NONCONF", 10 },
- { "GROUP", 5 },
- { "TLS", 3 },
- /* IA-64 specific. */
- { "SHORT", 5 },
- { "NORECOV", 7 },
- /* IA-64 OpenVMS specific. */
- { "VMS_GLOBAL", 10 },
- { "VMS_OVERLAID", 12 },
- { "VMS_SHARED", 10 },
- { "VMS_VECTOR", 10 },
- { "VMS_ALLOC_64BIT", 15 },
- { "VMS_PROTECTED", 13}
- };
-
- if (do_section_details)
- {
- sprintf (buff, "[%*.*lx]: ",
- field_size, field_size, (unsigned long) sh_flags);
- p += field_size + 4;
- }
-
- while (sh_flags)
- {
- bfd_vma flag;
-
- flag = sh_flags & - sh_flags;
- sh_flags &= ~ flag;
-
- if (do_section_details)
- {
- switch (flag)
- {
- case SHF_WRITE: index = 0; break;
- case SHF_ALLOC: index = 1; break;
- case SHF_EXECINSTR: index = 2; break;
- case SHF_MERGE: index = 3; break;
- case SHF_STRINGS: index = 4; break;
- case SHF_INFO_LINK: index = 5; break;
- case SHF_LINK_ORDER: index = 6; break;
- case SHF_OS_NONCONFORMING: index = 7; break;
- case SHF_GROUP: index = 8; break;
- case SHF_TLS: index = 9; break;
-
- default:
- index = -1;
- if (elf_header.e_machine == EM_IA_64)
- {
- if (flag == SHF_IA_64_SHORT)
- index = 10;
- else if (flag == SHF_IA_64_NORECOV)
- index = 11;
-#ifdef BFD64
- else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
- switch (flag)
- {
- case SHF_IA_64_VMS_GLOBAL: index = 12; break;
- case SHF_IA_64_VMS_OVERLAID: index = 13; break;
- case SHF_IA_64_VMS_SHARED: index = 14; break;
- case SHF_IA_64_VMS_VECTOR: index = 15; break;
- case SHF_IA_64_VMS_ALLOC_64BIT: index = 16; break;
- case SHF_IA_64_VMS_PROTECTED: index = 17; break;
- default: break;
- }
-#endif
- }
- break;
- }
-
- if (index != -1)
- {
- if (p != buff + field_size + 4)
- {
- if (size < (10 + 2))
- abort ();
- size -= 2;
- *p++ = ',';
- *p++ = ' ';
- }
-
- size -= flags [index].len;
- p = stpcpy (p, flags [index].str);
- }
- else if (flag & SHF_MASKOS)
- os_flags |= flag;
- else if (flag & SHF_MASKPROC)
- proc_flags |= flag;
- else
- unknown_flags |= flag;
- }
- else
- {
- switch (flag)
- {
- case SHF_WRITE: *p = 'W'; break;
- case SHF_ALLOC: *p = 'A'; break;
- case SHF_EXECINSTR: *p = 'X'; break;
- case SHF_MERGE: *p = 'M'; break;
- case SHF_STRINGS: *p = 'S'; break;
- case SHF_INFO_LINK: *p = 'I'; break;
- case SHF_LINK_ORDER: *p = 'L'; break;
- case SHF_OS_NONCONFORMING: *p = 'O'; break;
- case SHF_GROUP: *p = 'G'; break;
- case SHF_TLS: *p = 'T'; break;
-
- default:
- if (elf_header.e_machine == EM_X86_64
- && flag == SHF_X86_64_LARGE)
- *p = 'l';
- else if (flag & SHF_MASKOS)
- {
- *p = 'o';
- sh_flags &= ~ SHF_MASKOS;
- }
- else if (flag & SHF_MASKPROC)
- {
- *p = 'p';
- sh_flags &= ~ SHF_MASKPROC;
- }
- else
- *p = 'x';
- break;
- }
- p++;
- }
- }
-
- if (do_section_details)
- {
- if (os_flags)
- {
- size -= 5 + field_size;
- if (p != buff + field_size + 4)
- {
- if (size < (2 + 1))
- abort ();
- size -= 2;
- *p++ = ',';
- *p++ = ' ';
- }
- sprintf (p, "OS (%*.*lx)", field_size, field_size,
- (unsigned long) os_flags);
- p += 5 + field_size;
- }
- if (proc_flags)
- {
- size -= 7 + field_size;
- if (p != buff + field_size + 4)
- {
- if (size < (2 + 1))
- abort ();
- size -= 2;
- *p++ = ',';
- *p++ = ' ';
- }
- sprintf (p, "PROC (%*.*lx)", field_size, field_size,
- (unsigned long) proc_flags);
- p += 7 + field_size;
- }
- if (unknown_flags)
- {
- size -= 10 + field_size;
- if (p != buff + field_size + 4)
- {
- if (size < (2 + 1))
- abort ();
- size -= 2;
- *p++ = ',';
- *p++ = ' ';
- }
- sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
- (unsigned long) unknown_flags);
- p += 10 + field_size;
- }
- }
-
- *p = '\0';
- return buff;
-}
-
-static int
-process_section_headers (FILE *file)
-{
- Elf_Internal_Shdr *section;
- unsigned int i;
-
- section_headers = NULL;
-
- if (elf_header.e_shnum == 0)
- {
- if (do_sections)
- printf (_("\nThere are no sections in this file.\n"));
-
- return 1;
- }
-
- if (do_sections && !do_header)
- printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
- elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
-
- if (is_32bit_elf)
- {
- if (! get_32bit_section_headers (file, elf_header.e_shnum))
- return 0;
- }
- else if (! get_64bit_section_headers (file, elf_header.e_shnum))
- return 0;
-
- /* Read in the string table, so that we have names to display. */
- if (elf_header.e_shstrndx != SHN_UNDEF
- && elf_header.e_shstrndx < elf_header.e_shnum)
- {
- section = section_headers + elf_header.e_shstrndx;
-
- if (section->sh_size != 0)
- {
- string_table = get_data (NULL, file, section->sh_offset,
- 1, section->sh_size, _("string table"));
-
- string_table_length = string_table != NULL ? section->sh_size : 0;
- }
- }
-
- /* Scan the sections for the dynamic symbol table
- and dynamic string table and debug sections. */
- dynamic_symbols = NULL;
- dynamic_strings = NULL;
- dynamic_syminfo = NULL;
- symtab_shndx_hdr = NULL;
-
- eh_addr_size = is_32bit_elf ? 4 : 8;
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
- FDE addresses. However, the ABI also has a semi-official ILP32
- variant for which the normal FDE address size rules apply.
-
- GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
- section, where XX is the size of longs in bits. Unfortunately,
- earlier compilers provided no way of distinguishing ILP32 objects
- from LP64 objects, so if there's any doubt, we should assume that
- the official LP64 form is being used. */
- if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
- && find_section (".gcc_compiled_long32") == NULL)
- eh_addr_size = 8;
- break;
-
- case EM_H8_300:
- case EM_H8_300H:
- switch (elf_header.e_flags & EF_H8_MACH)
- {
- case E_H8_MACH_H8300:
- case E_H8_MACH_H8300HN:
- case E_H8_MACH_H8300SN:
- case E_H8_MACH_H8300SXN:
- eh_addr_size = 2;
- break;
- case E_H8_MACH_H8300H:
- case E_H8_MACH_H8300S:
- case E_H8_MACH_H8300SX:
- eh_addr_size = 4;
- break;
- }
- break;
-
- case EM_M32C_OLD:
- case EM_M32C:
- switch (elf_header.e_flags & EF_M32C_CPU_MASK)
- {
- case EF_M32C_CPU_M16C:
- eh_addr_size = 2;
- break;
- }
- break;
- }
-
-#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
- do \
- { \
- size_t expected_entsize \
- = is_32bit_elf ? size32 : size64; \
- if (section->sh_entsize != expected_entsize) \
- error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
- i, (unsigned long int) section->sh_entsize, \
- (unsigned long int) expected_entsize); \
- section->sh_entsize = expected_entsize; \
- } \
- while (0)
-#define CHECK_ENTSIZE(section, i, type) \
- CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
- sizeof (Elf64_External_##type))
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- char *name = SECTION_NAME (section);
-
- if (section->sh_type == SHT_DYNSYM)
- {
- if (dynamic_symbols != NULL)
- {
- error (_("File contains multiple dynamic symbol tables\n"));
- continue;
- }
-
- CHECK_ENTSIZE (section, i, Sym);
- num_dynamic_syms = section->sh_size / section->sh_entsize;
- dynamic_symbols = GET_ELF_SYMBOLS (file, section);
- }
- else if (section->sh_type == SHT_STRTAB
- && streq (name, ".dynstr"))
- {
- if (dynamic_strings != NULL)
- {
- error (_("File contains multiple dynamic string tables\n"));
- continue;
- }
-
- dynamic_strings = get_data (NULL, file, section->sh_offset,
- 1, section->sh_size, _("dynamic strings"));
- dynamic_strings_length = section->sh_size;
- }
- else if (section->sh_type == SHT_SYMTAB_SHNDX)
- {
- if (symtab_shndx_hdr != NULL)
- {
- error (_("File contains multiple symtab shndx tables\n"));
- continue;
- }
- symtab_shndx_hdr = section;
- }
- else if (section->sh_type == SHT_SYMTAB)
- CHECK_ENTSIZE (section, i, Sym);
- else if (section->sh_type == SHT_GROUP)
- CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
- else if (section->sh_type == SHT_REL)
- CHECK_ENTSIZE (section, i, Rel);
- else if (section->sh_type == SHT_RELA)
- CHECK_ENTSIZE (section, i, Rela);
- else if ((do_debugging || do_debug_info || do_debug_abbrevs
- || do_debug_lines || do_debug_lines_decoded || do_debug_pubnames
- || do_debug_aranges || do_debug_frames || do_debug_macinfo
- || do_debug_str || do_debug_loc || do_debug_ranges)
- && (const_strneq (name, ".debug_")
- || const_strneq (name, ".zdebug_")))
- {
- if (name[1] == 'z')
- name += sizeof (".zdebug_") - 1;
- else
- name += sizeof (".debug_") - 1;
-
- if (do_debugging
- || (do_debug_info && streq (name, "info"))
- || (do_debug_abbrevs && streq (name, "abbrev"))
- || ((do_debug_lines || do_debug_lines_decoded)
- && streq (name, "line"))
- || (do_debug_pubnames && streq (name, "pubnames"))
- || (do_debug_aranges && streq (name, "aranges"))
- || (do_debug_ranges && streq (name, "ranges"))
- || (do_debug_frames && streq (name, "frame"))
- || (do_debug_macinfo && streq (name, "macinfo"))
- || (do_debug_str && streq (name, "str"))
- || (do_debug_loc && streq (name, "loc"))
- )
- request_dump_bynumber (i, DEBUG_DUMP);
- }
- /* Linkonce section to be combined with .debug_info at link time. */
- else if ((do_debugging || do_debug_info)
- && const_strneq (name, ".gnu.linkonce.wi."))
- request_dump_bynumber (i, DEBUG_DUMP);
- else if (do_debug_frames && streq (name, ".eh_frame"))
- request_dump_bynumber (i, DEBUG_DUMP);
- }
-
- if (! do_sections)
- return 1;
-
- if (elf_header.e_shnum > 1)
- printf (_("\nSection Headers:\n"));
- else
- printf (_("\nSection Header:\n"));
-
- if (is_32bit_elf)
- {
- if (do_section_details)
- {
- printf (_(" [Nr] Name\n"));
- printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
- }
- else
- printf
- (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
- }
- else if (do_wide)
- {
- if (do_section_details)
- {
- printf (_(" [Nr] Name\n"));
- printf (_(" Type Address Off Size ES Lk Inf Al\n"));
- }
- else
- printf
- (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
- }
- else
- {
- if (do_section_details)
- {
- printf (_(" [Nr] Name\n"));
- printf (_(" Type Address Offset Link\n"));
- printf (_(" Size EntSize Info Align\n"));
- }
- else
- {
- printf (_(" [Nr] Name Type Address Offset\n"));
- printf (_(" Size EntSize Flags Link Info Align\n"));
- }
- }
-
- if (do_section_details)
- printf (_(" Flags\n"));
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- if (do_section_details)
- {
- printf (" [%2u] %s\n",
- i,
- SECTION_NAME (section));
- if (is_32bit_elf || do_wide)
- printf (" %-15.15s ",
- get_section_type_name (section->sh_type));
- }
- else
- printf (" [%2u] %-17.17s %-15.15s ",
- i,
- SECTION_NAME (section),
- get_section_type_name (section->sh_type));
-
- if (is_32bit_elf)
- {
- print_vma (section->sh_addr, LONG_HEX);
-
- printf ( " %6.6lx %6.6lx %2.2lx",
- (unsigned long) section->sh_offset,
- (unsigned long) section->sh_size,
- (unsigned long) section->sh_entsize);
-
- if (do_section_details)
- fputs (" ", stdout);
- else
- printf (" %3s ", get_elf_section_flags (section->sh_flags));
-
- printf ("%2u %3u %2lu\n",
- section->sh_link,
- section->sh_info,
- (unsigned long) section->sh_addralign);
- }
- else if (do_wide)
- {
- print_vma (section->sh_addr, LONG_HEX);
-
- if ((long) section->sh_offset == section->sh_offset)
- printf (" %6.6lx", (unsigned long) section->sh_offset);
- else
- {
- putchar (' ');
- print_vma (section->sh_offset, LONG_HEX);
- }
-
- if ((unsigned long) section->sh_size == section->sh_size)
- printf (" %6.6lx", (unsigned long) section->sh_size);
- else
- {
- putchar (' ');
- print_vma (section->sh_size, LONG_HEX);
- }
-
- if ((unsigned long) section->sh_entsize == section->sh_entsize)
- printf (" %2.2lx", (unsigned long) section->sh_entsize);
- else
- {
- putchar (' ');
- print_vma (section->sh_entsize, LONG_HEX);
- }
-
- if (do_section_details)
- fputs (" ", stdout);
- else
- printf (" %3s ", get_elf_section_flags (section->sh_flags));
-
- printf ("%2u %3u ", section->sh_link, section->sh_info);
-
- if ((unsigned long) section->sh_addralign == section->sh_addralign)
- printf ("%2lu\n", (unsigned long) section->sh_addralign);
- else
- {
- print_vma (section->sh_addralign, DEC);
- putchar ('\n');
- }
- }
- else if (do_section_details)
- {
- printf (" %-15.15s ",
- get_section_type_name (section->sh_type));
- print_vma (section->sh_addr, LONG_HEX);
- if ((long) section->sh_offset == section->sh_offset)
- printf (" %16.16lx", (unsigned long) section->sh_offset);
- else
- {
- printf (" ");
- print_vma (section->sh_offset, LONG_HEX);
- }
- printf (" %u\n ", section->sh_link);
- print_vma (section->sh_size, LONG_HEX);
- putchar (' ');
- print_vma (section->sh_entsize, LONG_HEX);
-
- printf (" %-16u %lu\n",
- section->sh_info,
- (unsigned long) section->sh_addralign);
- }
- else
- {
- putchar (' ');
- print_vma (section->sh_addr, LONG_HEX);
- if ((long) section->sh_offset == section->sh_offset)
- printf (" %8.8lx", (unsigned long) section->sh_offset);
- else
- {
- printf (" ");
- print_vma (section->sh_offset, LONG_HEX);
- }
- printf ("\n ");
- print_vma (section->sh_size, LONG_HEX);
- printf (" ");
- print_vma (section->sh_entsize, LONG_HEX);
-
- printf (" %3s ", get_elf_section_flags (section->sh_flags));
-
- printf (" %2u %3u %lu\n",
- section->sh_link,
- section->sh_info,
- (unsigned long) section->sh_addralign);
- }
-
- if (do_section_details)
- printf (" %s\n", get_elf_section_flags (section->sh_flags));
- }
-
- if (!do_section_details)
- printf (_("Key to Flags:\n\
- W (write), A (alloc), X (execute), M (merge), S (strings)\n\
- I (info), L (link order), G (group), x (unknown)\n\
- O (extra OS processing required) o (OS specific), p (processor specific)\n"));
-
- return 1;
-}
-
-static const char *
-get_group_flags (unsigned int flags)
-{
- static char buff[32];
- switch (flags)
- {
- case GRP_COMDAT:
- return "COMDAT";
-
- default:
- snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
- break;
- }
- return buff;
-}
-
-static int
-process_section_groups (FILE *file)
-{
- Elf_Internal_Shdr *section;
- unsigned int i;
- struct group *group;
- Elf_Internal_Shdr *symtab_sec, *strtab_sec;
- Elf_Internal_Sym *symtab;
- char *strtab;
- size_t strtab_size;
-
- /* Don't process section groups unless needed. */
- if (!do_unwind && !do_section_groups)
- return 1;
-
- if (elf_header.e_shnum == 0)
- {
- if (do_section_groups)
- printf (_("\nThere are no sections in this file.\n"));
-
- return 1;
- }
-
- if (section_headers == NULL)
- {
- error (_("Section headers are not available!\n"));
- abort ();
- }
-
- section_headers_groups = calloc (elf_header.e_shnum,
- sizeof (struct group *));
-
- if (section_headers_groups == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- /* Scan the sections for the group section. */
- group_count = 0;
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- if (section->sh_type == SHT_GROUP)
- group_count++;
-
- if (group_count == 0)
- {
- if (do_section_groups)
- printf (_("\nThere are no section groups in this file.\n"));
-
- return 1;
- }
-
- section_groups = calloc (group_count, sizeof (struct group));
-
- if (section_groups == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- symtab_sec = NULL;
- strtab_sec = NULL;
- symtab = NULL;
- strtab = NULL;
- strtab_size = 0;
- for (i = 0, section = section_headers, group = section_groups;
- i < elf_header.e_shnum;
- i++, section++)
- {
- if (section->sh_type == SHT_GROUP)
- {
- char *name = SECTION_NAME (section);
- char *group_name;
- unsigned char *start, *indices;
- unsigned int entry, j, size;
- Elf_Internal_Shdr *sec;
- Elf_Internal_Sym *sym;
-
- /* Get the symbol table. */
- if (section->sh_link >= elf_header.e_shnum
- || ((sec = section_headers + section->sh_link)->sh_type
- != SHT_SYMTAB))
- {
- error (_("Bad sh_link in group section `%s'\n"), name);
- continue;
- }
-
- if (symtab_sec != sec)
- {
- symtab_sec = sec;
- if (symtab)
- free (symtab);
- symtab = GET_ELF_SYMBOLS (file, symtab_sec);
- }
-
- sym = symtab + section->sh_info;
-
- if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
- {
- if (sym->st_shndx == 0
- || sym->st_shndx >= elf_header.e_shnum)
- {
- error (_("Bad sh_info in group section `%s'\n"), name);
- continue;
- }
-
- group_name = SECTION_NAME (section_headers + sym->st_shndx);
- strtab_sec = NULL;
- if (strtab)
- free (strtab);
- strtab = NULL;
- strtab_size = 0;
- }
- else
- {
- /* Get the string table. */
- if (symtab_sec->sh_link >= elf_header.e_shnum)
- {
- strtab_sec = NULL;
- if (strtab)
- free (strtab);
- strtab = NULL;
- strtab_size = 0;
- }
- else if (strtab_sec
- != (sec = section_headers + symtab_sec->sh_link))
- {
- strtab_sec = sec;
- if (strtab)
- free (strtab);
- strtab = get_data (NULL, file, strtab_sec->sh_offset,
- 1, strtab_sec->sh_size,
- _("string table"));
- strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
- }
- group_name = sym->st_name < strtab_size
- ? strtab + sym->st_name : "<corrupt>";
- }
-
- start = get_data (NULL, file, section->sh_offset,
- 1, section->sh_size, _("section data"));
-
- indices = start;
- size = (section->sh_size / section->sh_entsize) - 1;
- entry = byte_get (indices, 4);
- indices += 4;
-
- if (do_section_groups)
- {
- printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
- get_group_flags (entry), i, name, group_name, size);
-
- printf (_(" [Index] Name\n"));
- }
-
- group->group_index = i;
-
- for (j = 0; j < size; j++)
- {
- struct group_list *g;
-
- entry = byte_get (indices, 4);
- indices += 4;
-
- if (entry >= elf_header.e_shnum)
- {
- error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
- entry, i, elf_header.e_shnum - 1);
- continue;
- }
-
- if (section_headers_groups [entry] != NULL)
- {
- if (entry)
- {
- error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
- entry, i,
- section_headers_groups [entry]->group_index);
- continue;
- }
- else
- {
- /* Intel C/C++ compiler may put section 0 in a
- section group. We just warn it the first time
- and ignore it afterwards. */
- static int warned = 0;
- if (!warned)
- {
- error (_("section 0 in group section [%5u]\n"),
- section_headers_groups [entry]->group_index);
- warned++;
- }
- }
- }
-
- section_headers_groups [entry] = group;
-
- if (do_section_groups)
- {
- sec = section_headers + entry;
- printf (" [%5u] %s\n", entry, SECTION_NAME (sec));
- }
-
- g = xmalloc (sizeof (struct group_list));
- g->section_index = entry;
- g->next = group->root;
- group->root = g;
- }
-
- if (start)
- free (start);
-
- group++;
- }
- }
-
- if (symtab)
- free (symtab);
- if (strtab)
- free (strtab);
- return 1;
-}
-
-static struct
-{
- const char *name;
- int reloc;
- int size;
- int rela;
-} dynamic_relocations [] =
-{
- { "REL", DT_REL, DT_RELSZ, FALSE },
- { "RELA", DT_RELA, DT_RELASZ, TRUE },
- { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
-};
-
-/* Process the reloc section. */
-
-static int
-process_relocs (FILE *file)
-{
- unsigned long rel_size;
- unsigned long rel_offset;
-
-
- if (!do_reloc)
- return 1;
-
- if (do_using_dynamic)
- {
- int is_rela;
- const char *name;
- int has_dynamic_reloc;
- unsigned int i;
-
- has_dynamic_reloc = 0;
-
- for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
- {
- is_rela = dynamic_relocations [i].rela;
- name = dynamic_relocations [i].name;
- rel_size = dynamic_info [dynamic_relocations [i].size];
- rel_offset = dynamic_info [dynamic_relocations [i].reloc];
-
- has_dynamic_reloc |= rel_size;
-
- if (is_rela == UNKNOWN)
- {
- if (dynamic_relocations [i].reloc == DT_JMPREL)
- switch (dynamic_info[DT_PLTREL])
- {
- case DT_REL:
- is_rela = FALSE;
- break;
- case DT_RELA:
- is_rela = TRUE;
- break;
- }
- }
-
- if (rel_size)
- {
- printf
- (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
- name, rel_offset, rel_size);
-
- dump_relocations (file,
- offset_from_vma (file, rel_offset, rel_size),
- rel_size,
- dynamic_symbols, num_dynamic_syms,
- dynamic_strings, dynamic_strings_length, is_rela);
- }
- }
-
- if (! has_dynamic_reloc)
- printf (_("\nThere are no dynamic relocations in this file.\n"));
- }
- else
- {
- Elf_Internal_Shdr *section;
- unsigned long i;
- int found = 0;
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- if ( section->sh_type != SHT_RELA
- && section->sh_type != SHT_REL)
- continue;
-
- rel_offset = section->sh_offset;
- rel_size = section->sh_size;
-
- if (rel_size)
- {
- Elf_Internal_Shdr *strsec;
- int is_rela;
-
- printf (_("\nRelocation section "));
-
- if (string_table == NULL)
- printf ("%d", section->sh_name);
- else
- printf (_("'%s'"), SECTION_NAME (section));
-
- printf (_(" at offset 0x%lx contains %lu entries:\n"),
- rel_offset, (unsigned long) (rel_size / section->sh_entsize));
-
- is_rela = section->sh_type == SHT_RELA;
-
- if (section->sh_link != 0
- && section->sh_link < elf_header.e_shnum)
- {
- Elf_Internal_Shdr *symsec;
- Elf_Internal_Sym *symtab;
- unsigned long nsyms;
- unsigned long strtablen = 0;
- char *strtab = NULL;
-
- symsec = section_headers + section->sh_link;
- if (symsec->sh_type != SHT_SYMTAB
- && symsec->sh_type != SHT_DYNSYM)
- continue;
-
- nsyms = symsec->sh_size / symsec->sh_entsize;
- symtab = GET_ELF_SYMBOLS (file, symsec);
-
- if (symtab == NULL)
- continue;
-
- if (symsec->sh_link != 0
- && symsec->sh_link < elf_header.e_shnum)
- {
- strsec = section_headers + symsec->sh_link;
-
- strtab = get_data (NULL, file, strsec->sh_offset,
- 1, strsec->sh_size,
- _("string table"));
- strtablen = strtab == NULL ? 0 : strsec->sh_size;
- }
-
- dump_relocations (file, rel_offset, rel_size,
- symtab, nsyms, strtab, strtablen, is_rela);
- if (strtab)
- free (strtab);
- free (symtab);
- }
- else
- dump_relocations (file, rel_offset, rel_size,
- NULL, 0, NULL, 0, is_rela);
-
- found = 1;
- }
- }
-
- if (! found)
- printf (_("\nThere are no relocations in this file.\n"));
- }
-
- return 1;
-}
-
-/* Process the unwind section. */
-
-#include "unwind-ia64.h"
-
-/* An absolute address consists of a section and an offset. If the
- section is NULL, the offset itself is the address, otherwise, the
- address equals to LOAD_ADDRESS(section) + offset. */
-
-struct absaddr
- {
- unsigned short section;
- bfd_vma offset;
- };
-
-#define ABSADDR(a) \
- ((a).section \
- ? section_headers [(a).section].sh_addr + (a).offset \
- : (a).offset)
-
-struct ia64_unw_aux_info
- {
- struct ia64_unw_table_entry
- {
- struct absaddr start;
- struct absaddr end;
- struct absaddr info;
- }
- *table; /* Unwind table. */
- unsigned long table_len; /* Length of unwind table. */
- unsigned char *info; /* Unwind info. */
- unsigned long info_size; /* Size of unwind info. */
- bfd_vma info_addr; /* starting address of unwind info. */
- bfd_vma seg_base; /* Starting address of segment. */
- Elf_Internal_Sym *symtab; /* The symbol table. */
- unsigned long nsyms; /* Number of symbols. */
- char *strtab; /* The string table. */
- unsigned long strtab_size; /* Size of string table. */
- };
-
-static void
-find_symbol_for_address (Elf_Internal_Sym *symtab,
- unsigned long nsyms,
- const char *strtab,
- unsigned long strtab_size,
- struct absaddr addr,
- const char **symname,
- bfd_vma *offset)
-{
- bfd_vma dist = 0x100000;
- Elf_Internal_Sym *sym, *best = NULL;
- unsigned long i;
-
- for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
- {
- if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
- && sym->st_name != 0
- && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
- && addr.offset >= sym->st_value
- && addr.offset - sym->st_value < dist)
- {
- best = sym;
- dist = addr.offset - sym->st_value;
- if (!dist)
- break;
- }
- }
- if (best)
- {
- *symname = (best->st_name >= strtab_size
- ? "<corrupt>" : strtab + best->st_name);
- *offset = dist;
- return;
- }
- *symname = NULL;
- *offset = addr.offset;
-}
-
-static void
-dump_ia64_unwind (struct ia64_unw_aux_info *aux)
-{
- struct ia64_unw_table_entry *tp;
- int in_body;
-
- for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
- {
- bfd_vma stamp;
- bfd_vma offset;
- const unsigned char *dp;
- const unsigned char *head;
- const char *procname;
-
- find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
- aux->strtab_size, tp->start, &procname, &offset);
-
- fputs ("\n<", stdout);
-
- if (procname)
- {
- fputs (procname, stdout);
-
- if (offset)
- printf ("+%lx", (unsigned long) offset);
- }
-
- fputs (">: [", stdout);
- print_vma (tp->start.offset, PREFIX_HEX);
- fputc ('-', stdout);
- print_vma (tp->end.offset, PREFIX_HEX);
- printf ("], info at +0x%lx\n",
- (unsigned long) (tp->info.offset - aux->seg_base));
-
- head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
- stamp = byte_get ((unsigned char *) head, sizeof (stamp));
-
- printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
- (unsigned) UNW_VER (stamp),
- (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
- UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
- UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
- (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
-
- if (UNW_VER (stamp) != 1)
- {
- printf ("\tUnknown version.\n");
- continue;
- }
-
- in_body = 0;
- for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
- dp = unw_decode (dp, in_body, & in_body);
- }
-}
-
-static int
-slurp_ia64_unwind_table (FILE *file,
- struct ia64_unw_aux_info *aux,
- Elf_Internal_Shdr *sec)
-{
- unsigned long size, nrelas, i;
- Elf_Internal_Phdr *seg;
- struct ia64_unw_table_entry *tep;
- Elf_Internal_Shdr *relsec;
- Elf_Internal_Rela *rela, *rp;
- unsigned char *table, *tp;
- Elf_Internal_Sym *sym;
- const char *relname;
-
- /* First, find the starting address of the segment that includes
- this section: */
-
- if (elf_header.e_phnum)
- {
- if (! get_program_headers (file))
- return 0;
-
- for (seg = program_headers;
- seg < program_headers + elf_header.e_phnum;
- ++seg)
- {
- if (seg->p_type != PT_LOAD)
- continue;
-
- if (sec->sh_addr >= seg->p_vaddr
- && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
- {
- aux->seg_base = seg->p_vaddr;
- break;
- }
- }
- }
-
- /* Second, build the unwind table from the contents of the unwind section: */
- size = sec->sh_size;
- table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
- if (!table)
- return 0;
-
- aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
- tep = aux->table;
- for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
- {
- tep->start.section = SHN_UNDEF;
- tep->end.section = SHN_UNDEF;
- tep->info.section = SHN_UNDEF;
- if (is_32bit_elf)
- {
- tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
- tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
- tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
- }
- else
- {
- tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
- tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
- tep->info.offset = BYTE_GET ((unsigned char *) tp + 16);
- }
- tep->start.offset += aux->seg_base;
- tep->end.offset += aux->seg_base;
- tep->info.offset += aux->seg_base;
- }
- free (table);
-
- /* Third, apply any relocations to the unwind table: */
- for (relsec = section_headers;
- relsec < section_headers + elf_header.e_shnum;
- ++relsec)
- {
- if (relsec->sh_type != SHT_RELA
- || relsec->sh_info >= elf_header.e_shnum
- || section_headers + relsec->sh_info != sec)
- continue;
-
- if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
- & rela, & nrelas))
- return 0;
-
- for (rp = rela; rp < rela + nrelas; ++rp)
- {
- relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
- sym = aux->symtab + get_reloc_symindex (rp->r_info);
-
- if (! const_strneq (relname, "R_IA64_SEGREL"))
- {
- warn (_("Skipping unexpected relocation type %s\n"), relname);
- continue;
- }
-
- i = rp->r_offset / (3 * eh_addr_size);
-
- switch (rp->r_offset/eh_addr_size % 3)
- {
- case 0:
- aux->table[i].start.section = sym->st_shndx;
- aux->table[i].start.offset += rp->r_addend + sym->st_value;
- break;
- case 1:
- aux->table[i].end.section = sym->st_shndx;
- aux->table[i].end.offset += rp->r_addend + sym->st_value;
- break;
- case 2:
- aux->table[i].info.section = sym->st_shndx;
- aux->table[i].info.offset += rp->r_addend + sym->st_value;
- break;
- default:
- break;
- }
- }
-
- free (rela);
- }
-
- aux->table_len = size / (3 * eh_addr_size);
- return 1;
-}
-
-static int
-ia64_process_unwind (FILE *file)
-{
- Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
- unsigned long i, unwcount = 0, unwstart = 0;
- struct ia64_unw_aux_info aux;
-
- memset (& aux, 0, sizeof (aux));
-
- for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
- {
- if (sec->sh_type == SHT_SYMTAB
- && sec->sh_link < elf_header.e_shnum)
- {
- aux.nsyms = sec->sh_size / sec->sh_entsize;
- aux.symtab = GET_ELF_SYMBOLS (file, sec);
-
- strsec = section_headers + sec->sh_link;
- aux.strtab = get_data (NULL, file, strsec->sh_offset,
- 1, strsec->sh_size, _("string table"));
- aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
- }
- else if (sec->sh_type == SHT_IA_64_UNWIND)
- unwcount++;
- }
-
- if (!unwcount)
- printf (_("\nThere are no unwind sections in this file.\n"));
-
- while (unwcount-- > 0)
- {
- char *suffix;
- size_t len, len2;
-
- for (i = unwstart, sec = section_headers + unwstart;
- i < elf_header.e_shnum; ++i, ++sec)
- if (sec->sh_type == SHT_IA_64_UNWIND)
- {
- unwsec = sec;
- break;
- }
-
- unwstart = i + 1;
- len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
-
- if ((unwsec->sh_flags & SHF_GROUP) != 0)
- {
- /* We need to find which section group it is in. */
- struct group_list *g = section_headers_groups [i]->root;
-
- for (; g != NULL; g = g->next)
- {
- sec = section_headers + g->section_index;
-
- if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
- break;
- }
-
- if (g == NULL)
- i = elf_header.e_shnum;
- }
- else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
- {
- /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
- len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
- suffix = SECTION_NAME (unwsec) + len;
- for (i = 0, sec = section_headers; i < elf_header.e_shnum;
- ++i, ++sec)
- if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
- && streq (SECTION_NAME (sec) + len2, suffix))
- break;
- }
- else
- {
- /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
- .IA_64.unwind or BAR -> .IA_64.unwind_info. */
- len = sizeof (ELF_STRING_ia64_unwind) - 1;
- len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
- suffix = "";
- if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
- suffix = SECTION_NAME (unwsec) + len;
- for (i = 0, sec = section_headers; i < elf_header.e_shnum;
- ++i, ++sec)
- if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
- && streq (SECTION_NAME (sec) + len2, suffix))
- break;
- }
-
- if (i == elf_header.e_shnum)
- {
- printf (_("\nCould not find unwind info section for "));
-
- if (string_table == NULL)
- printf ("%d", unwsec->sh_name);
- else
- printf (_("'%s'"), SECTION_NAME (unwsec));
- }
- else
- {
- aux.info_size = sec->sh_size;
- aux.info_addr = sec->sh_addr;
- aux.info = get_data (NULL, file, sec->sh_offset, 1, aux.info_size,
- _("unwind info"));
-
- printf (_("\nUnwind section "));
-
- if (string_table == NULL)
- printf ("%d", unwsec->sh_name);
- else
- printf (_("'%s'"), SECTION_NAME (unwsec));
-
- printf (_(" at offset 0x%lx contains %lu entries:\n"),
- (unsigned long) unwsec->sh_offset,
- (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
-
- (void) slurp_ia64_unwind_table (file, & aux, unwsec);
-
- if (aux.table_len > 0)
- dump_ia64_unwind (& aux);
-
- if (aux.table)
- free ((char *) aux.table);
- if (aux.info)
- free ((char *) aux.info);
- aux.table = NULL;
- aux.info = NULL;
- }
- }
-
- if (aux.symtab)
- free (aux.symtab);
- if (aux.strtab)
- free ((char *) aux.strtab);
-
- return 1;
-}
-
-struct hppa_unw_aux_info
- {
- struct hppa_unw_table_entry
- {
- struct absaddr start;
- struct absaddr end;
- unsigned int Cannot_unwind:1; /* 0 */
- unsigned int Millicode:1; /* 1 */
- unsigned int Millicode_save_sr0:1; /* 2 */
- unsigned int Region_description:2; /* 3..4 */
- unsigned int reserved1:1; /* 5 */
- unsigned int Entry_SR:1; /* 6 */
- unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
- unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
- unsigned int Args_stored:1; /* 16 */
- unsigned int Variable_Frame:1; /* 17 */
- unsigned int Separate_Package_Body:1; /* 18 */
- unsigned int Frame_Extension_Millicode:1; /* 19 */
- unsigned int Stack_Overflow_Check:1; /* 20 */
- unsigned int Two_Instruction_SP_Increment:1; /* 21 */
- unsigned int Ada_Region:1; /* 22 */
- unsigned int cxx_info:1; /* 23 */
- unsigned int cxx_try_catch:1; /* 24 */
- unsigned int sched_entry_seq:1; /* 25 */
- unsigned int reserved2:1; /* 26 */
- unsigned int Save_SP:1; /* 27 */
- unsigned int Save_RP:1; /* 28 */
- unsigned int Save_MRP_in_frame:1; /* 29 */
- unsigned int extn_ptr_defined:1; /* 30 */
- unsigned int Cleanup_defined:1; /* 31 */
-
- unsigned int MPE_XL_interrupt_marker:1; /* 0 */
- unsigned int HP_UX_interrupt_marker:1; /* 1 */
- unsigned int Large_frame:1; /* 2 */
- unsigned int Pseudo_SP_Set:1; /* 3 */
- unsigned int reserved4:1; /* 4 */
- unsigned int Total_frame_size:27; /* 5..31 */
- }
- *table; /* Unwind table. */
- unsigned long table_len; /* Length of unwind table. */
- bfd_vma seg_base; /* Starting address of segment. */
- Elf_Internal_Sym *symtab; /* The symbol table. */
- unsigned long nsyms; /* Number of symbols. */
- char *strtab; /* The string table. */
- unsigned long strtab_size; /* Size of string table. */
- };
-
-static void
-dump_hppa_unwind (struct hppa_unw_aux_info *aux)
-{
- struct hppa_unw_table_entry *tp;
-
- for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
- {
- bfd_vma offset;
- const char *procname;
-
- find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
- aux->strtab_size, tp->start, &procname,
- &offset);
-
- fputs ("\n<", stdout);
-
- if (procname)
- {
- fputs (procname, stdout);
-
- if (offset)
- printf ("+%lx", (unsigned long) offset);
- }
-
- fputs (">: [", stdout);
- print_vma (tp->start.offset, PREFIX_HEX);
- fputc ('-', stdout);
- print_vma (tp->end.offset, PREFIX_HEX);
- printf ("]\n\t");
-
-#define PF(_m) if (tp->_m) printf (#_m " ");
-#define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
- PF(Cannot_unwind);
- PF(Millicode);
- PF(Millicode_save_sr0);
- /* PV(Region_description); */
- PF(Entry_SR);
- PV(Entry_FR);
- PV(Entry_GR);
- PF(Args_stored);
- PF(Variable_Frame);
- PF(Separate_Package_Body);
- PF(Frame_Extension_Millicode);
- PF(Stack_Overflow_Check);
- PF(Two_Instruction_SP_Increment);
- PF(Ada_Region);
- PF(cxx_info);
- PF(cxx_try_catch);
- PF(sched_entry_seq);
- PF(Save_SP);
- PF(Save_RP);
- PF(Save_MRP_in_frame);
- PF(extn_ptr_defined);
- PF(Cleanup_defined);
- PF(MPE_XL_interrupt_marker);
- PF(HP_UX_interrupt_marker);
- PF(Large_frame);
- PF(Pseudo_SP_Set);
- PV(Total_frame_size);
-#undef PF
-#undef PV
- }
-
- printf ("\n");
-}
-
-static int
-slurp_hppa_unwind_table (FILE *file,
- struct hppa_unw_aux_info *aux,
- Elf_Internal_Shdr *sec)
-{
- unsigned long size, unw_ent_size, nentries, nrelas, i;
- Elf_Internal_Phdr *seg;
- struct hppa_unw_table_entry *tep;
- Elf_Internal_Shdr *relsec;
- Elf_Internal_Rela *rela, *rp;
- unsigned char *table, *tp;
- Elf_Internal_Sym *sym;
- const char *relname;
-
- /* First, find the starting address of the segment that includes
- this section. */
-
- if (elf_header.e_phnum)
- {
- if (! get_program_headers (file))
- return 0;
-
- for (seg = program_headers;
- seg < program_headers + elf_header.e_phnum;
- ++seg)
- {
- if (seg->p_type != PT_LOAD)
- continue;
-
- if (sec->sh_addr >= seg->p_vaddr
- && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
- {
- aux->seg_base = seg->p_vaddr;
- break;
- }
- }
- }
-
- /* Second, build the unwind table from the contents of the unwind
- section. */
- size = sec->sh_size;
- table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
- if (!table)
- return 0;
-
- unw_ent_size = 16;
- nentries = size / unw_ent_size;
- size = unw_ent_size * nentries;
-
- tep = aux->table = xcmalloc (nentries, sizeof (aux->table[0]));
-
- for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
- {
- unsigned int tmp1, tmp2;
-
- tep->start.section = SHN_UNDEF;
- tep->end.section = SHN_UNDEF;
-
- tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
- tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
- tmp1 = byte_get ((unsigned char *) tp + 8, 4);
- tmp2 = byte_get ((unsigned char *) tp + 12, 4);
-
- tep->start.offset += aux->seg_base;
- tep->end.offset += aux->seg_base;
-
- tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
- tep->Millicode = (tmp1 >> 30) & 0x1;
- tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
- tep->Region_description = (tmp1 >> 27) & 0x3;
- tep->reserved1 = (tmp1 >> 26) & 0x1;
- tep->Entry_SR = (tmp1 >> 25) & 0x1;
- tep->Entry_FR = (tmp1 >> 21) & 0xf;
- tep->Entry_GR = (tmp1 >> 16) & 0x1f;
- tep->Args_stored = (tmp1 >> 15) & 0x1;
- tep->Variable_Frame = (tmp1 >> 14) & 0x1;
- tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
- tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
- tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
- tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
- tep->Ada_Region = (tmp1 >> 9) & 0x1;
- tep->cxx_info = (tmp1 >> 8) & 0x1;
- tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
- tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
- tep->reserved2 = (tmp1 >> 5) & 0x1;
- tep->Save_SP = (tmp1 >> 4) & 0x1;
- tep->Save_RP = (tmp1 >> 3) & 0x1;
- tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
- tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
- tep->Cleanup_defined = tmp1 & 0x1;
-
- tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
- tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
- tep->Large_frame = (tmp2 >> 29) & 0x1;
- tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
- tep->reserved4 = (tmp2 >> 27) & 0x1;
- tep->Total_frame_size = tmp2 & 0x7ffffff;
- }
- free (table);
-
- /* Third, apply any relocations to the unwind table. */
- for (relsec = section_headers;
- relsec < section_headers + elf_header.e_shnum;
- ++relsec)
- {
- if (relsec->sh_type != SHT_RELA
- || relsec->sh_info >= elf_header.e_shnum
- || section_headers + relsec->sh_info != sec)
- continue;
-
- if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
- & rela, & nrelas))
- return 0;
-
- for (rp = rela; rp < rela + nrelas; ++rp)
- {
- relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
- sym = aux->symtab + get_reloc_symindex (rp->r_info);
-
- /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
- if (! const_strneq (relname, "R_PARISC_SEGREL"))
- {
- warn (_("Skipping unexpected relocation type %s\n"), relname);
- continue;
- }
-
- i = rp->r_offset / unw_ent_size;
-
- switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
- {
- case 0:
- aux->table[i].start.section = sym->st_shndx;
- aux->table[i].start.offset += sym->st_value + rp->r_addend;
- break;
- case 1:
- aux->table[i].end.section = sym->st_shndx;
- aux->table[i].end.offset += sym->st_value + rp->r_addend;
- break;
- default:
- break;
- }
- }
-
- free (rela);
- }
-
- aux->table_len = nentries;
-
- return 1;
-}
-
-static int
-hppa_process_unwind (FILE *file)
-{
- struct hppa_unw_aux_info aux;
- Elf_Internal_Shdr *unwsec = NULL;
- Elf_Internal_Shdr *strsec;
- Elf_Internal_Shdr *sec;
- unsigned long i;
-
- memset (& aux, 0, sizeof (aux));
-
- if (string_table == NULL)
- return 1;
-
- for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
- {
- if (sec->sh_type == SHT_SYMTAB
- && sec->sh_link < elf_header.e_shnum)
- {
- aux.nsyms = sec->sh_size / sec->sh_entsize;
- aux.symtab = GET_ELF_SYMBOLS (file, sec);
-
- strsec = section_headers + sec->sh_link;
- aux.strtab = get_data (NULL, file, strsec->sh_offset,
- 1, strsec->sh_size, _("string table"));
- aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
- }
- else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
- unwsec = sec;
- }
-
- if (!unwsec)
- printf (_("\nThere are no unwind sections in this file.\n"));
-
- for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
- {
- if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
- {
- printf (_("\nUnwind section "));
- printf (_("'%s'"), SECTION_NAME (sec));
-
- printf (_(" at offset 0x%lx contains %lu entries:\n"),
- (unsigned long) sec->sh_offset,
- (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
-
- slurp_hppa_unwind_table (file, &aux, sec);
- if (aux.table_len > 0)
- dump_hppa_unwind (&aux);
-
- if (aux.table)
- free ((char *) aux.table);
- aux.table = NULL;
- }
- }
-
- if (aux.symtab)
- free (aux.symtab);
- if (aux.strtab)
- free ((char *) aux.strtab);
-
- return 1;
-}
-
-static int
-process_unwind (FILE *file)
-{
- struct unwind_handler {
- int machtype;
- int (*handler)(FILE *file);
- } handlers[] = {
- { EM_IA_64, ia64_process_unwind },
- { EM_PARISC, hppa_process_unwind },
- { 0, 0 }
- };
- int i;
-
- if (!do_unwind)
- return 1;
-
- for (i = 0; handlers[i].handler != NULL; i++)
- if (elf_header.e_machine == handlers[i].machtype)
- return handlers[i].handler (file);
-
- printf (_("\nThere are no unwind sections in this file.\n"));
- return 1;
-}
-
-static void
-dynamic_section_mips_val (Elf_Internal_Dyn *entry)
-{
- switch (entry->d_tag)
- {
- case DT_MIPS_FLAGS:
- if (entry->d_un.d_val == 0)
- printf ("NONE\n");
- else
- {
- static const char * opts[] =
- {
- "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
- "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
- "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
- "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
- "RLD_ORDER_SAFE"
- };
- unsigned int cnt;
- int first = 1;
- for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
- if (entry->d_un.d_val & (1 << cnt))
- {
- printf ("%s%s", first ? "" : " ", opts[cnt]);
- first = 0;
- }
- puts ("");
- }
- break;
-
- case DT_MIPS_IVERSION:
- if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
- printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
- else
- printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
- break;
-
- case DT_MIPS_TIME_STAMP:
- {
- char timebuf[20];
- struct tm *tmp;
-
- time_t time = entry->d_un.d_val;
- tmp = gmtime (&time);
- snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
- printf ("Time Stamp: %s\n", timebuf);
- }
- break;
-
- case DT_MIPS_RLD_VERSION:
- case DT_MIPS_LOCAL_GOTNO:
- case DT_MIPS_CONFLICTNO:
- case DT_MIPS_LIBLISTNO:
- case DT_MIPS_SYMTABNO:
- case DT_MIPS_UNREFEXTNO:
- case DT_MIPS_HIPAGENO:
- case DT_MIPS_DELTA_CLASS_NO:
- case DT_MIPS_DELTA_INSTANCE_NO:
- case DT_MIPS_DELTA_RELOC_NO:
- case DT_MIPS_DELTA_SYM_NO:
- case DT_MIPS_DELTA_CLASSSYM_NO:
- case DT_MIPS_COMPACT_SIZE:
- printf ("%ld\n", (long) entry->d_un.d_ptr);
- break;
-
- default:
- printf ("%#lx\n", (unsigned long) entry->d_un.d_ptr);
- }
-}
-
-
-static void
-dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
-{
- switch (entry->d_tag)
- {
- case DT_HP_DLD_FLAGS:
- {
- static struct
- {
- long int bit;
- const char *str;
- }
- flags[] =
- {
- { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
- { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
- { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
- { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
- { DT_HP_BIND_NOW, "HP_BIND_NOW" },
- { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
- { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
- { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
- { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
- { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
- { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
- { DT_HP_GST, "HP_GST" },
- { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
- { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
- { DT_HP_NODELETE, "HP_NODELETE" },
- { DT_HP_GROUP, "HP_GROUP" },
- { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
- };
- int first = 1;
- size_t cnt;
- bfd_vma val = entry->d_un.d_val;
-
- for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
- if (val & flags[cnt].bit)
- {
- if (! first)
- putchar (' ');
- fputs (flags[cnt].str, stdout);
- first = 0;
- val ^= flags[cnt].bit;
- }
-
- if (val != 0 || first)
- {
- if (! first)
- putchar (' ');
- print_vma (val, HEX);
- }
- }
- break;
-
- default:
- print_vma (entry->d_un.d_ptr, PREFIX_HEX);
- break;
- }
- putchar ('\n');
-}
-
-static void
-dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
-{
- switch (entry->d_tag)
- {
- case DT_IA_64_PLT_RESERVE:
- /* First 3 slots reserved. */
- print_vma (entry->d_un.d_ptr, PREFIX_HEX);
- printf (" -- ");
- print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
- break;
-
- default:
- print_vma (entry->d_un.d_ptr, PREFIX_HEX);
- break;
- }
- putchar ('\n');
-}
-
-static int
-get_32bit_dynamic_section (FILE *file)
-{
- Elf32_External_Dyn *edyn, *ext;
- Elf_Internal_Dyn *entry;
-
- edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
- _("dynamic section"));
- if (!edyn)
- return 0;
-
-/* SGI's ELF has more than one section in the DYNAMIC segment, and we
- might not have the luxury of section headers. Look for the DT_NULL
- terminator to determine the number of entries. */
- for (ext = edyn, dynamic_nent = 0;
- (char *) ext < (char *) edyn + dynamic_size;
- ext++)
- {
- dynamic_nent++;
- if (BYTE_GET (ext->d_tag) == DT_NULL)
- break;
- }
-
- dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
- if (dynamic_section == NULL)
- {
- error (_("Out of memory\n"));
- free (edyn);
- return 0;
- }
-
- for (ext = edyn, entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- ext++, entry++)
- {
- entry->d_tag = BYTE_GET (ext->d_tag);
- entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
- }
-
- free (edyn);
-
- return 1;
-}
-
-static int
-get_64bit_dynamic_section (FILE *file)
-{
- Elf64_External_Dyn *edyn, *ext;
- Elf_Internal_Dyn *entry;
-
- edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
- _("dynamic section"));
- if (!edyn)
- return 0;
-
-/* SGI's ELF has more than one section in the DYNAMIC segment, and we
- might not have the luxury of section headers. Look for the DT_NULL
- terminator to determine the number of entries. */
- for (ext = edyn, dynamic_nent = 0;
- (char *) ext < (char *) edyn + dynamic_size;
- ext++)
- {
- dynamic_nent++;
- if (BYTE_GET (ext->d_tag) == DT_NULL)
- break;
- }
-
- dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
- if (dynamic_section == NULL)
- {
- error (_("Out of memory\n"));
- free (edyn);
- return 0;
- }
-
- for (ext = edyn, entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- ext++, entry++)
- {
- entry->d_tag = BYTE_GET (ext->d_tag);
- entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
- }
-
- free (edyn);
-
- return 1;
-}
-
-static void
-print_dynamic_flags (bfd_vma flags)
-{
- int first = 1;
-
- while (flags)
- {
- bfd_vma flag;
-
- flag = flags & - flags;
- flags &= ~ flag;
-
- if (first)
- first = 0;
- else
- putc (' ', stdout);
-
- switch (flag)
- {
- case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
- case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
- case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
- case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
- case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
- default: fputs ("unknown", stdout); break;
- }
- }
- puts ("");
-}
-
-/* Parse and display the contents of the dynamic section. */
-
-static int
-process_dynamic_section (FILE *file)
-{
- Elf_Internal_Dyn *entry;
-
- if (dynamic_size == 0)
- {
- if (do_dynamic)
- printf (_("\nThere is no dynamic section in this file.\n"));
-
- return 1;
- }
-
- if (is_32bit_elf)
- {
- if (! get_32bit_dynamic_section (file))
- return 0;
- }
- else if (! get_64bit_dynamic_section (file))
- return 0;
-
- /* Find the appropriate symbol table. */
- if (dynamic_symbols == NULL)
- {
- for (entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- ++entry)
- {
- Elf_Internal_Shdr section;
-
- if (entry->d_tag != DT_SYMTAB)
- continue;
-
- dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
-
- /* Since we do not know how big the symbol table is,
- we default to reading in the entire file (!) and
- processing that. This is overkill, I know, but it
- should work. */
- section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
-
- if (archive_file_offset != 0)
- section.sh_size = archive_file_size - section.sh_offset;
- else
- {
- if (fseek (file, 0, SEEK_END))
- error (_("Unable to seek to end of file!\n"));
-
- section.sh_size = ftell (file) - section.sh_offset;
- }
-
- if (is_32bit_elf)
- section.sh_entsize = sizeof (Elf32_External_Sym);
- else
- section.sh_entsize = sizeof (Elf64_External_Sym);
-
- num_dynamic_syms = section.sh_size / section.sh_entsize;
- if (num_dynamic_syms < 1)
- {
- error (_("Unable to determine the number of symbols to load\n"));
- continue;
- }
-
- dynamic_symbols = GET_ELF_SYMBOLS (file, &section);
- }
- }
-
- /* Similarly find a string table. */
- if (dynamic_strings == NULL)
- {
- for (entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- ++entry)
- {
- unsigned long offset;
- long str_tab_len;
-
- if (entry->d_tag != DT_STRTAB)
- continue;
-
- dynamic_info[DT_STRTAB] = entry->d_un.d_val;
-
- /* Since we do not know how big the string table is,
- we default to reading in the entire file (!) and
- processing that. This is overkill, I know, but it
- should work. */
-
- offset = offset_from_vma (file, entry->d_un.d_val, 0);
-
- if (archive_file_offset != 0)
- str_tab_len = archive_file_size - offset;
- else
- {
- if (fseek (file, 0, SEEK_END))
- error (_("Unable to seek to end of file\n"));
- str_tab_len = ftell (file) - offset;
- }
-
- if (str_tab_len < 1)
- {
- error
- (_("Unable to determine the length of the dynamic string table\n"));
- continue;
- }
-
- dynamic_strings = get_data (NULL, file, offset, 1, str_tab_len,
- _("dynamic string table"));
- dynamic_strings_length = str_tab_len;
- break;
- }
- }
-
- /* And find the syminfo section if available. */
- if (dynamic_syminfo == NULL)
- {
- unsigned long syminsz = 0;
-
- for (entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- ++entry)
- {
- if (entry->d_tag == DT_SYMINENT)
- {
- /* Note: these braces are necessary to avoid a syntax
- error from the SunOS4 C compiler. */
- assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
- }
- else if (entry->d_tag == DT_SYMINSZ)
- syminsz = entry->d_un.d_val;
- else if (entry->d_tag == DT_SYMINFO)
- dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
- syminsz);
- }
-
- if (dynamic_syminfo_offset != 0 && syminsz != 0)
- {
- Elf_External_Syminfo *extsyminfo, *extsym;
- Elf_Internal_Syminfo *syminfo;
-
- /* There is a syminfo section. Read the data. */
- extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
- syminsz, _("symbol information"));
- if (!extsyminfo)
- return 0;
-
- dynamic_syminfo = malloc (syminsz);
- if (dynamic_syminfo == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
- for (syminfo = dynamic_syminfo, extsym = extsyminfo;
- syminfo < dynamic_syminfo + dynamic_syminfo_nent;
- ++syminfo, ++extsym)
- {
- syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
- syminfo->si_flags = BYTE_GET (extsym->si_flags);
- }
-
- free (extsyminfo);
- }
- }
-
- if (do_dynamic && dynamic_addr)
- printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
- dynamic_addr, dynamic_nent);
- if (do_dynamic)
- printf (_(" Tag Type Name/Value\n"));
-
- for (entry = dynamic_section;
- entry < dynamic_section + dynamic_nent;
- entry++)
- {
- if (do_dynamic)
- {
- const char *dtype;
-
- putchar (' ');
- print_vma (entry->d_tag, FULL_HEX);
- dtype = get_dynamic_type (entry->d_tag);
- printf (" (%s)%*s", dtype,
- ((is_32bit_elf ? 27 : 19)
- - (int) strlen (dtype)),
- " ");
- }
-
- switch (entry->d_tag)
- {
- case DT_FLAGS:
- if (do_dynamic)
- print_dynamic_flags (entry->d_un.d_val);
- break;
-
- case DT_AUXILIARY:
- case DT_FILTER:
- case DT_CONFIG:
- case DT_DEPAUDIT:
- case DT_AUDIT:
- if (do_dynamic)
- {
- switch (entry->d_tag)
- {
- case DT_AUXILIARY:
- printf (_("Auxiliary library"));
- break;
-
- case DT_FILTER:
- printf (_("Filter library"));
- break;
-
- case DT_CONFIG:
- printf (_("Configuration file"));
- break;
-
- case DT_DEPAUDIT:
- printf (_("Dependency audit library"));
- break;
-
- case DT_AUDIT:
- printf (_("Audit library"));
- break;
- }
-
- if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
- printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
- else
- {
- printf (": ");
- print_vma (entry->d_un.d_val, PREFIX_HEX);
- putchar ('\n');
- }
- }
- break;
-
- case DT_FEATURE:
- if (do_dynamic)
- {
- printf (_("Flags:"));
-
- if (entry->d_un.d_val == 0)
- printf (_(" None\n"));
- else
- {
- unsigned long int val = entry->d_un.d_val;
-
- if (val & DTF_1_PARINIT)
- {
- printf (" PARINIT");
- val ^= DTF_1_PARINIT;
- }
- if (val & DTF_1_CONFEXP)
- {
- printf (" CONFEXP");
- val ^= DTF_1_CONFEXP;
- }
- if (val != 0)
- printf (" %lx", val);
- puts ("");
- }
- }
- break;
-
- case DT_POSFLAG_1:
- if (do_dynamic)
- {
- printf (_("Flags:"));
-
- if (entry->d_un.d_val == 0)
- printf (_(" None\n"));
- else
- {
- unsigned long int val = entry->d_un.d_val;
-
- if (val & DF_P1_LAZYLOAD)
- {
- printf (" LAZYLOAD");
- val ^= DF_P1_LAZYLOAD;
- }
- if (val & DF_P1_GROUPPERM)
- {
- printf (" GROUPPERM");
- val ^= DF_P1_GROUPPERM;
- }
- if (val != 0)
- printf (" %lx", val);
- puts ("");
- }
- }
- break;
-
- case DT_FLAGS_1:
- if (do_dynamic)
- {
- printf (_("Flags:"));
- if (entry->d_un.d_val == 0)
- printf (_(" None\n"));
- else
- {
- unsigned long int val = entry->d_un.d_val;
-
- if (val & DF_1_NOW)
- {
- printf (" NOW");
- val ^= DF_1_NOW;
- }
- if (val & DF_1_GLOBAL)
- {
- printf (" GLOBAL");
- val ^= DF_1_GLOBAL;
- }
- if (val & DF_1_GROUP)
- {
- printf (" GROUP");
- val ^= DF_1_GROUP;
- }
- if (val & DF_1_NODELETE)
- {
- printf (" NODELETE");
- val ^= DF_1_NODELETE;
- }
- if (val & DF_1_LOADFLTR)
- {
- printf (" LOADFLTR");
- val ^= DF_1_LOADFLTR;
- }
- if (val & DF_1_INITFIRST)
- {
- printf (" INITFIRST");
- val ^= DF_1_INITFIRST;
- }
- if (val & DF_1_NOOPEN)
- {
- printf (" NOOPEN");
- val ^= DF_1_NOOPEN;
- }
- if (val & DF_1_ORIGIN)
- {
- printf (" ORIGIN");
- val ^= DF_1_ORIGIN;
- }
- if (val & DF_1_DIRECT)
- {
- printf (" DIRECT");
- val ^= DF_1_DIRECT;
- }
- if (val & DF_1_TRANS)
- {
- printf (" TRANS");
- val ^= DF_1_TRANS;
- }
- if (val & DF_1_INTERPOSE)
- {
- printf (" INTERPOSE");
- val ^= DF_1_INTERPOSE;
- }
- if (val & DF_1_NODEFLIB)
- {
- printf (" NODEFLIB");
- val ^= DF_1_NODEFLIB;
- }
- if (val & DF_1_NODUMP)
- {
- printf (" NODUMP");
- val ^= DF_1_NODUMP;
- }
- if (val & DF_1_CONLFAT)
- {
- printf (" CONLFAT");
- val ^= DF_1_CONLFAT;
- }
- if (val != 0)
- printf (" %lx", val);
- puts ("");
- }
- }
- break;
-
- case DT_PLTREL:
- dynamic_info[entry->d_tag] = entry->d_un.d_val;
- if (do_dynamic)
- puts (get_dynamic_type (entry->d_un.d_val));
- break;
-
- case DT_NULL :
- case DT_NEEDED :
- case DT_PLTGOT :
- case DT_HASH :
- case DT_STRTAB :
- case DT_SYMTAB :
- case DT_RELA :
- case DT_INIT :
- case DT_FINI :
- case DT_SONAME :
- case DT_RPATH :
- case DT_SYMBOLIC:
- case DT_REL :
- case DT_DEBUG :
- case DT_TEXTREL :
- case DT_JMPREL :
- case DT_RUNPATH :
- dynamic_info[entry->d_tag] = entry->d_un.d_val;
-
- if (do_dynamic)
- {
- char *name;
-
- if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
- name = GET_DYNAMIC_NAME (entry->d_un.d_val);
- else
- name = NULL;
-
- if (name)
- {
- switch (entry->d_tag)
- {
- case DT_NEEDED:
- printf (_("Shared library: [%s]"), name);
-
- if (streq (name, program_interpreter))
- printf (_(" program interpreter"));
- break;
-
- case DT_SONAME:
- printf (_("Library soname: [%s]"), name);
- break;
-
- case DT_RPATH:
- printf (_("Library rpath: [%s]"), name);
- break;
-
- case DT_RUNPATH:
- printf (_("Library runpath: [%s]"), name);
- break;
-
- default:
- print_vma (entry->d_un.d_val, PREFIX_HEX);
- break;
- }
- }
- else
- print_vma (entry->d_un.d_val, PREFIX_HEX);
-
- putchar ('\n');
- }
- break;
-
- case DT_PLTRELSZ:
- case DT_RELASZ :
- case DT_STRSZ :
- case DT_RELSZ :
- case DT_RELAENT :
- case DT_SYMENT :
- case DT_RELENT :
- dynamic_info[entry->d_tag] = entry->d_un.d_val;
- case DT_PLTPADSZ:
- case DT_MOVEENT :
- case DT_MOVESZ :
- case DT_INIT_ARRAYSZ:
- case DT_FINI_ARRAYSZ:
- case DT_GNU_CONFLICTSZ:
- case DT_GNU_LIBLISTSZ:
- if (do_dynamic)
- {
- print_vma (entry->d_un.d_val, UNSIGNED);
- printf (" (bytes)\n");
- }
- break;
-
- case DT_VERDEFNUM:
- case DT_VERNEEDNUM:
- case DT_RELACOUNT:
- case DT_RELCOUNT:
- if (do_dynamic)
- {
- print_vma (entry->d_un.d_val, UNSIGNED);
- putchar ('\n');
- }
- break;
-
- case DT_SYMINSZ:
- case DT_SYMINENT:
- case DT_SYMINFO:
- case DT_USED:
- case DT_INIT_ARRAY:
- case DT_FINI_ARRAY:
- if (do_dynamic)
- {
- if (entry->d_tag == DT_USED
- && VALID_DYNAMIC_NAME (entry->d_un.d_val))
- {
- char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
-
- if (*name)
- {
- printf (_("Not needed object: [%s]\n"), name);
- break;
- }
- }
-
- print_vma (entry->d_un.d_val, PREFIX_HEX);
- putchar ('\n');
- }
- break;
-
- case DT_BIND_NOW:
- /* The value of this entry is ignored. */
- if (do_dynamic)
- putchar ('\n');
- break;
-
- case DT_GNU_PRELINKED:
- if (do_dynamic)
- {
- struct tm *tmp;
- time_t time = entry->d_un.d_val;
-
- tmp = gmtime (&time);
- printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
-
- }
- break;
-
- case DT_GNU_HASH:
- dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
- if (do_dynamic)
- {
- print_vma (entry->d_un.d_val, PREFIX_HEX);
- putchar ('\n');
- }
- break;
-
- default:
- if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
- version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
- entry->d_un.d_val;
-
- if (do_dynamic)
- {
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- dynamic_section_mips_val (entry);
- break;
- case EM_PARISC:
- dynamic_section_parisc_val (entry);
- break;
- case EM_IA_64:
- dynamic_section_ia64_val (entry);
- break;
- default:
- print_vma (entry->d_un.d_val, PREFIX_HEX);
- putchar ('\n');
- }
- }
- break;
- }
- }
-
- return 1;
-}
-
-static char *
-get_ver_flags (unsigned int flags)
-{
- static char buff[32];
-
- buff[0] = 0;
-
- if (flags == 0)
- return _("none");
-
- if (flags & VER_FLG_BASE)
- strcat (buff, "BASE ");
-
- if (flags & VER_FLG_WEAK)
- {
- if (flags & VER_FLG_BASE)
- strcat (buff, "| ");
-
- strcat (buff, "WEAK ");
- }
-
- if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
- strcat (buff, "| <unknown>");
-
- return buff;
-}
-
-/* Display the contents of the version sections. */
-static int
-process_version_sections (FILE *file)
-{
- Elf_Internal_Shdr *section;
- unsigned i;
- int found = 0;
-
- if (! do_version)
- return 1;
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- switch (section->sh_type)
- {
- case SHT_GNU_verdef:
- {
- Elf_External_Verdef *edefs;
- unsigned int idx;
- unsigned int cnt;
- char *endbuf;
-
- found = 1;
-
- printf
- (_("\nVersion definition section '%s' contains %u entries:\n"),
- SECTION_NAME (section), section->sh_info);
-
- printf (_(" Addr: 0x"));
- printf_vma (section->sh_addr);
- printf (_(" Offset: %#08lx Link: %u (%s)\n"),
- (unsigned long) section->sh_offset, section->sh_link,
- section->sh_link < elf_header.e_shnum
- ? SECTION_NAME (section_headers + section->sh_link)
- : "<corrupt>");
-
- edefs = get_data (NULL, file, section->sh_offset, 1,
- section->sh_size,
- _("version definition section"));
- endbuf = (char *) edefs + section->sh_size;
- if (!edefs)
- break;
-
- for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
- {
- char *vstart;
- Elf_External_Verdef *edef;
- Elf_Internal_Verdef ent;
- Elf_External_Verdaux *eaux;
- Elf_Internal_Verdaux aux;
- int j;
- int isum;
-
- vstart = ((char *) edefs) + idx;
- if (vstart + sizeof (*edef) > endbuf)
- break;
-
- edef = (Elf_External_Verdef *) vstart;
-
- ent.vd_version = BYTE_GET (edef->vd_version);
- ent.vd_flags = BYTE_GET (edef->vd_flags);
- ent.vd_ndx = BYTE_GET (edef->vd_ndx);
- ent.vd_cnt = BYTE_GET (edef->vd_cnt);
- ent.vd_hash = BYTE_GET (edef->vd_hash);
- ent.vd_aux = BYTE_GET (edef->vd_aux);
- ent.vd_next = BYTE_GET (edef->vd_next);
-
- printf (_(" %#06x: Rev: %d Flags: %s"),
- idx, ent.vd_version, get_ver_flags (ent.vd_flags));
-
- printf (_(" Index: %d Cnt: %d "),
- ent.vd_ndx, ent.vd_cnt);
-
- vstart += ent.vd_aux;
-
- eaux = (Elf_External_Verdaux *) vstart;
-
- aux.vda_name = BYTE_GET (eaux->vda_name);
- aux.vda_next = BYTE_GET (eaux->vda_next);
-
- if (VALID_DYNAMIC_NAME (aux.vda_name))
- printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
- else
- printf (_("Name index: %ld\n"), aux.vda_name);
-
- isum = idx + ent.vd_aux;
-
- for (j = 1; j < ent.vd_cnt; j++)
- {
- isum += aux.vda_next;
- vstart += aux.vda_next;
-
- eaux = (Elf_External_Verdaux *) vstart;
- if (vstart + sizeof (*eaux) > endbuf)
- break;
-
- aux.vda_name = BYTE_GET (eaux->vda_name);
- aux.vda_next = BYTE_GET (eaux->vda_next);
-
- if (VALID_DYNAMIC_NAME (aux.vda_name))
- printf (_(" %#06x: Parent %d: %s\n"),
- isum, j, GET_DYNAMIC_NAME (aux.vda_name));
- else
- printf (_(" %#06x: Parent %d, name index: %ld\n"),
- isum, j, aux.vda_name);
- }
- if (j < ent.vd_cnt)
- printf (_(" Version def aux past end of section\n"));
-
- idx += ent.vd_next;
- }
- if (cnt < section->sh_info)
- printf (_(" Version definition past end of section\n"));
-
- free (edefs);
- }
- break;
-
- case SHT_GNU_verneed:
- {
- Elf_External_Verneed *eneed;
- unsigned int idx;
- unsigned int cnt;
- char *endbuf;
-
- found = 1;
-
- printf (_("\nVersion needs section '%s' contains %u entries:\n"),
- SECTION_NAME (section), section->sh_info);
-
- printf (_(" Addr: 0x"));
- printf_vma (section->sh_addr);
- printf (_(" Offset: %#08lx Link: %u (%s)\n"),
- (unsigned long) section->sh_offset, section->sh_link,
- section->sh_link < elf_header.e_shnum
- ? SECTION_NAME (section_headers + section->sh_link)
- : "<corrupt>");
-
- eneed = get_data (NULL, file, section->sh_offset, 1,
- section->sh_size,
- _("version need section"));
- endbuf = (char *) eneed + section->sh_size;
- if (!eneed)
- break;
-
- for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
- {
- Elf_External_Verneed *entry;
- Elf_Internal_Verneed ent;
- int j;
- int isum;
- char *vstart;
-
- vstart = ((char *) eneed) + idx;
- if (vstart + sizeof (*entry) > endbuf)
- break;
-
- entry = (Elf_External_Verneed *) vstart;
-
- ent.vn_version = BYTE_GET (entry->vn_version);
- ent.vn_cnt = BYTE_GET (entry->vn_cnt);
- ent.vn_file = BYTE_GET (entry->vn_file);
- ent.vn_aux = BYTE_GET (entry->vn_aux);
- ent.vn_next = BYTE_GET (entry->vn_next);
-
- printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
-
- if (VALID_DYNAMIC_NAME (ent.vn_file))
- printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
- else
- printf (_(" File: %lx"), ent.vn_file);
-
- printf (_(" Cnt: %d\n"), ent.vn_cnt);
-
- vstart += ent.vn_aux;
-
- for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
- {
- Elf_External_Vernaux *eaux;
- Elf_Internal_Vernaux aux;
-
- if (vstart + sizeof (*eaux) > endbuf)
- break;
- eaux = (Elf_External_Vernaux *) vstart;
-
- aux.vna_hash = BYTE_GET (eaux->vna_hash);
- aux.vna_flags = BYTE_GET (eaux->vna_flags);
- aux.vna_other = BYTE_GET (eaux->vna_other);
- aux.vna_name = BYTE_GET (eaux->vna_name);
- aux.vna_next = BYTE_GET (eaux->vna_next);
-
- if (VALID_DYNAMIC_NAME (aux.vna_name))
- printf (_(" %#06x: Name: %s"),
- isum, GET_DYNAMIC_NAME (aux.vna_name));
- else
- printf (_(" %#06x: Name index: %lx"),
- isum, aux.vna_name);
-
- printf (_(" Flags: %s Version: %d\n"),
- get_ver_flags (aux.vna_flags), aux.vna_other);
-
- isum += aux.vna_next;
- vstart += aux.vna_next;
- }
- if (j < ent.vn_cnt)
- printf (_(" Version need aux past end of section\n"));
-
- idx += ent.vn_next;
- }
- if (cnt < section->sh_info)
- printf (_(" Version need past end of section\n"));
-
- free (eneed);
- }
- break;
-
- case SHT_GNU_versym:
- {
- Elf_Internal_Shdr *link_section;
- int total;
- int cnt;
- unsigned char *edata;
- unsigned short *data;
- char *strtab;
- Elf_Internal_Sym *symbols;
- Elf_Internal_Shdr *string_sec;
- long off;
-
- if (section->sh_link >= elf_header.e_shnum)
- break;
-
- link_section = section_headers + section->sh_link;
- total = section->sh_size / sizeof (Elf_External_Versym);
-
- if (link_section->sh_link >= elf_header.e_shnum)
- break;
-
- found = 1;
-
- symbols = GET_ELF_SYMBOLS (file, link_section);
-
- string_sec = section_headers + link_section->sh_link;
-
- strtab = get_data (NULL, file, string_sec->sh_offset, 1,
- string_sec->sh_size, _("version string table"));
- if (!strtab)
- break;
-
- printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
- SECTION_NAME (section), total);
-
- printf (_(" Addr: "));
- printf_vma (section->sh_addr);
- printf (_(" Offset: %#08lx Link: %u (%s)\n"),
- (unsigned long) section->sh_offset, section->sh_link,
- SECTION_NAME (link_section));
-
- off = offset_from_vma (file,
- version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
- total * sizeof (short));
- edata = get_data (NULL, file, off, total, sizeof (short),
- _("version symbol data"));
- if (!edata)
- {
- free (strtab);
- break;
- }
-
- data = cmalloc (total, sizeof (short));
-
- for (cnt = total; cnt --;)
- data[cnt] = byte_get (edata + cnt * sizeof (short),
- sizeof (short));
-
- free (edata);
-
- for (cnt = 0; cnt < total; cnt += 4)
- {
- int j, nn;
- int check_def, check_need;
- char *name;
-
- printf (" %03x:", cnt);
-
- for (j = 0; (j < 4) && (cnt + j) < total; ++j)
- switch (data[cnt + j])
- {
- case 0:
- fputs (_(" 0 (*local*) "), stdout);
- break;
-
- case 1:
- fputs (_(" 1 (*global*) "), stdout);
- break;
-
- default:
- nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
- data[cnt + j] & 0x8000 ? 'h' : ' ');
-
- check_def = 1;
- check_need = 1;
- if (symbols[cnt + j].st_shndx >= elf_header.e_shnum
- || section_headers[symbols[cnt + j].st_shndx].sh_type
- != SHT_NOBITS)
- {
- if (symbols[cnt + j].st_shndx == SHN_UNDEF)
- check_def = 0;
- else
- check_need = 0;
- }
-
- if (check_need
- && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
- {
- Elf_Internal_Verneed ivn;
- unsigned long offset;
-
- offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
- sizeof (Elf_External_Verneed));
-
- do
- {
- Elf_Internal_Vernaux ivna;
- Elf_External_Verneed evn;
- Elf_External_Vernaux evna;
- unsigned long a_off;
-
- get_data (&evn, file, offset, sizeof (evn), 1,
- _("version need"));
-
- ivn.vn_aux = BYTE_GET (evn.vn_aux);
- ivn.vn_next = BYTE_GET (evn.vn_next);
-
- a_off = offset + ivn.vn_aux;
-
- do
- {
- get_data (&evna, file, a_off, sizeof (evna),
- 1, _("version need aux (2)"));
-
- ivna.vna_next = BYTE_GET (evna.vna_next);
- ivna.vna_other = BYTE_GET (evna.vna_other);
-
- a_off += ivna.vna_next;
- }
- while (ivna.vna_other != data[cnt + j]
- && ivna.vna_next != 0);
-
- if (ivna.vna_other == data[cnt + j])
- {
- ivna.vna_name = BYTE_GET (evna.vna_name);
-
- if (ivna.vna_name >= string_sec->sh_size)
- name = _("*invalid*");
- else
- name = strtab + ivna.vna_name;
- nn += printf ("(%s%-*s",
- name,
- 12 - (int) strlen (name),
- ")");
- check_def = 0;
- break;
- }
-
- offset += ivn.vn_next;
- }
- while (ivn.vn_next);
- }
-
- if (check_def && data[cnt + j] != 0x8001
- && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
- {
- Elf_Internal_Verdef ivd;
- Elf_External_Verdef evd;
- unsigned long offset;
-
- offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
- sizeof evd);
-
- do
- {
- get_data (&evd, file, offset, sizeof (evd), 1,
- _("version def"));
-
- ivd.vd_next = BYTE_GET (evd.vd_next);
- ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
-
- offset += ivd.vd_next;
- }
- while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
- && ivd.vd_next != 0);
-
- if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
- {
- Elf_External_Verdaux evda;
- Elf_Internal_Verdaux ivda;
-
- ivd.vd_aux = BYTE_GET (evd.vd_aux);
-
- get_data (&evda, file,
- offset - ivd.vd_next + ivd.vd_aux,
- sizeof (evda), 1,
- _("version def aux"));
-
- ivda.vda_name = BYTE_GET (evda.vda_name);
-
- if (ivda.vda_name >= string_sec->sh_size)
- name = _("*invalid*");
- else
- name = strtab + ivda.vda_name;
- nn += printf ("(%s%-*s",
- name,
- 12 - (int) strlen (name),
- ")");
- }
- }
-
- if (nn < 18)
- printf ("%*c", 18 - nn, ' ');
- }
-
- putchar ('\n');
- }
-
- free (data);
- free (strtab);
- free (symbols);
- }
- break;
-
- default:
- break;
- }
- }
-
- if (! found)
- printf (_("\nNo version information found in this file.\n"));
-
- return 1;
-}
-
-static const char *
-get_symbol_binding (unsigned int binding)
-{
- static char buff[32];
-
- switch (binding)
- {
- case STB_LOCAL: return "LOCAL";
- case STB_GLOBAL: return "GLOBAL";
- case STB_WEAK: return "WEAK";
- default:
- if (binding >= STB_LOPROC && binding <= STB_HIPROC)
- snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
- binding);
- else if (binding >= STB_LOOS && binding <= STB_HIOS)
- snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
- return buff;
- }
-}
-
-static const char *
-get_symbol_type (unsigned int type)
-{
- static char buff[32];
-
- switch (type)
- {
- case STT_NOTYPE: return "NOTYPE";
- case STT_OBJECT: return "OBJECT";
- case STT_FUNC: return "FUNC";
- case STT_SECTION: return "SECTION";
- case STT_FILE: return "FILE";
- case STT_COMMON: return "COMMON";
- case STT_TLS: return "TLS";
- case STT_RELC: return "RELC";
- case STT_SRELC: return "SRELC";
- default:
- if (type >= STT_LOPROC && type <= STT_HIPROC)
- {
- if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
- return "THUMB_FUNC";
-
- if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
- return "REGISTER";
-
- if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
- return "PARISC_MILLI";
-
- snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
- }
- else if (type >= STT_LOOS && type <= STT_HIOS)
- {
- if (elf_header.e_machine == EM_PARISC)
- {
- if (type == STT_HP_OPAQUE)
- return "HP_OPAQUE";
- if (type == STT_HP_STUB)
- return "HP_STUB";
- }
-
- snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
- }
- else
- snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
- return buff;
- }
-}
-
-static const char *
-get_symbol_visibility (unsigned int visibility)
-{
- switch (visibility)
- {
- case STV_DEFAULT: return "DEFAULT";
- case STV_INTERNAL: return "INTERNAL";
- case STV_HIDDEN: return "HIDDEN";
- case STV_PROTECTED: return "PROTECTED";
- default: abort ();
- }
-}
-
-static const char *
-get_mips_symbol_other (unsigned int other)
-{
- switch (other)
- {
- case STO_OPTIONAL: return "OPTIONAL";
- case STO_MIPS16: return "MIPS16";
- default: return NULL;
- }
-}
-
-static const char *
-get_symbol_other (unsigned int other)
-{
- const char * result = NULL;
- static char buff [32];
-
- if (other == 0)
- return "";
-
- switch (elf_header.e_machine)
- {
- case EM_MIPS:
- result = get_mips_symbol_other (other);
- default:
- break;
- }
-
- if (result)
- return result;
-
- snprintf (buff, sizeof buff, _("<other>: %x"), other);
- return buff;
-}
-
-static const char *
-get_symbol_index_type (unsigned int type)
-{
- static char buff[32];
-
- switch (type)
- {
- case SHN_UNDEF: return "UND";
- case SHN_ABS: return "ABS";
- case SHN_COMMON: return "COM";
- default:
- if (type == SHN_IA_64_ANSI_COMMON
- && elf_header.e_machine == EM_IA_64
- && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
- return "ANSI_COM";
- else if (elf_header.e_machine == EM_X86_64
- && type == SHN_X86_64_LCOMMON)
- return "LARGE_COM";
- else if (type == SHN_MIPS_SCOMMON
- && elf_header.e_machine == EM_MIPS)
- return "SCOM";
- else if (type == SHN_MIPS_SUNDEFINED
- && elf_header.e_machine == EM_MIPS)
- return "SUND";
- else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
- sprintf (buff, "PRC[0x%04x]", type & 0xffff);
- else if (type >= SHN_LOOS && type <= SHN_HIOS)
- sprintf (buff, "OS [0x%04x]", type & 0xffff);
- else if (type >= SHN_LORESERVE)
- sprintf (buff, "RSV[0x%04x]", type & 0xffff);
- else
- sprintf (buff, "%3d", type);
- break;
- }
-
- return buff;
-}
-
-static bfd_vma *
-get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
-{
- unsigned char *e_data;
- bfd_vma *i_data;
-
- e_data = cmalloc (number, ent_size);
-
- if (e_data == NULL)
- {
- error (_("Out of memory\n"));
- return NULL;
- }
-
- if (fread (e_data, ent_size, number, file) != number)
- {
- error (_("Unable to read in dynamic data\n"));
- return NULL;
- }
-
- i_data = cmalloc (number, sizeof (*i_data));
-
- if (i_data == NULL)
- {
- error (_("Out of memory\n"));
- free (e_data);
- return NULL;
- }
-
- while (number--)
- i_data[number] = byte_get (e_data + number * ent_size, ent_size);
-
- free (e_data);
-
- return i_data;
-}
-
-static void
-print_dynamic_symbol (bfd_vma si, unsigned long hn)
-{
- Elf_Internal_Sym *psym;
- int n;
-
- psym = dynamic_symbols + si;
-
- n = print_vma (si, DEC_5);
- if (n < 5)
- fputs (" " + n, stdout);
- printf (" %3lu: ", hn);
- print_vma (psym->st_value, LONG_HEX);
- putchar (' ');
- print_vma (psym->st_size, DEC_5);
-
- printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
- printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
- printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
- /* Check to see if any other bits in the st_other field are set.
- Note - displaying this information disrupts the layout of the
- table being generated, but for the moment this case is very
- rare. */
- if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
- printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
- printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
- if (VALID_DYNAMIC_NAME (psym->st_name))
- print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
- else
- printf (" <corrupt: %14ld>", psym->st_name);
- putchar ('\n');
-}
-
-/* Dump the symbol table. */
-static int
-process_symbol_table (FILE *file)
-{
- Elf_Internal_Shdr *section;
- bfd_vma nbuckets = 0;
- bfd_vma nchains = 0;
- bfd_vma *buckets = NULL;
- bfd_vma *chains = NULL;
- bfd_vma ngnubuckets = 0;
- bfd_vma *gnubuckets = NULL;
- bfd_vma *gnuchains = NULL;
- bfd_vma gnusymidx = 0;
-
- if (! do_syms && !do_histogram)
- return 1;
-
- if (dynamic_info[DT_HASH]
- && (do_histogram
- || (do_using_dynamic && dynamic_strings != NULL)))
- {
- unsigned char nb[8];
- unsigned char nc[8];
- int hash_ent_size = 4;
-
- if ((elf_header.e_machine == EM_ALPHA
- || elf_header.e_machine == EM_S390
- || elf_header.e_machine == EM_S390_OLD)
- && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
- hash_ent_size = 8;
-
- if (fseek (file,
- (archive_file_offset
- + offset_from_vma (file, dynamic_info[DT_HASH],
- sizeof nb + sizeof nc)),
- SEEK_SET))
- {
- error (_("Unable to seek to start of dynamic information\n"));
- return 0;
- }
-
- if (fread (nb, hash_ent_size, 1, file) != 1)
- {
- error (_("Failed to read in number of buckets\n"));
- return 0;
- }
-
- if (fread (nc, hash_ent_size, 1, file) != 1)
- {
- error (_("Failed to read in number of chains\n"));
- return 0;
- }
-
- nbuckets = byte_get (nb, hash_ent_size);
- nchains = byte_get (nc, hash_ent_size);
-
- buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
- chains = get_dynamic_data (file, nchains, hash_ent_size);
-
- if (buckets == NULL || chains == NULL)
- return 0;
- }
-
- if (dynamic_info_DT_GNU_HASH
- && (do_histogram
- || (do_using_dynamic && dynamic_strings != NULL)))
- {
- unsigned char nb[16];
- bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
- bfd_vma buckets_vma;
-
- if (fseek (file,
- (archive_file_offset
- + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
- sizeof nb)),
- SEEK_SET))
- {
- error (_("Unable to seek to start of dynamic information\n"));
- return 0;
- }
-
- if (fread (nb, 16, 1, file) != 1)
- {
- error (_("Failed to read in number of buckets\n"));
- return 0;
- }
-
- ngnubuckets = byte_get (nb, 4);
- gnusymidx = byte_get (nb + 4, 4);
- bitmaskwords = byte_get (nb + 8, 4);
- buckets_vma = dynamic_info_DT_GNU_HASH + 16;
- if (is_32bit_elf)
- buckets_vma += bitmaskwords * 4;
- else
- buckets_vma += bitmaskwords * 8;
-
- if (fseek (file,
- (archive_file_offset
- + offset_from_vma (file, buckets_vma, 4)),
- SEEK_SET))
- {
- error (_("Unable to seek to start of dynamic information\n"));
- return 0;
- }
-
- gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
-
- if (gnubuckets == NULL)
- return 0;
-
- for (i = 0; i < ngnubuckets; i++)
- if (gnubuckets[i] != 0)
- {
- if (gnubuckets[i] < gnusymidx)
- return 0;
-
- if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
- maxchain = gnubuckets[i];
- }
-
- if (maxchain == 0xffffffff)
- return 0;
-
- maxchain -= gnusymidx;
-
- if (fseek (file,
- (archive_file_offset
- + offset_from_vma (file, buckets_vma
- + 4 * (ngnubuckets + maxchain), 4)),
- SEEK_SET))
- {
- error (_("Unable to seek to start of dynamic information\n"));
- return 0;
- }
-
- do
- {
- if (fread (nb, 4, 1, file) != 1)
- {
- error (_("Failed to determine last chain length\n"));
- return 0;
- }
-
- if (maxchain + 1 == 0)
- return 0;
-
- ++maxchain;
- }
- while ((byte_get (nb, 4) & 1) == 0);
-
- if (fseek (file,
- (archive_file_offset
- + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
- SEEK_SET))
- {
- error (_("Unable to seek to start of dynamic information\n"));
- return 0;
- }
-
- gnuchains = get_dynamic_data (file, maxchain, 4);
-
- if (gnuchains == NULL)
- return 0;
- }
-
- if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
- && do_syms
- && do_using_dynamic
- && dynamic_strings != NULL)
- {
- unsigned long hn;
-
- if (dynamic_info[DT_HASH])
- {
- bfd_vma si;
-
- printf (_("\nSymbol table for image:\n"));
- if (is_32bit_elf)
- printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
- else
- printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
-
- for (hn = 0; hn < nbuckets; hn++)
- {
- if (! buckets[hn])
- continue;
-
- for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
- print_dynamic_symbol (si, hn);
- }
- }
-
- if (dynamic_info_DT_GNU_HASH)
- {
- printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
- if (is_32bit_elf)
- printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
- else
- printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
-
- for (hn = 0; hn < ngnubuckets; ++hn)
- if (gnubuckets[hn] != 0)
- {
- bfd_vma si = gnubuckets[hn];
- bfd_vma off = si - gnusymidx;
-
- do
- {
- print_dynamic_symbol (si, hn);
- si++;
- }
- while ((gnuchains[off++] & 1) == 0);
- }
- }
- }
- else if (do_syms && !do_using_dynamic)
- {
- unsigned int i;
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- unsigned int si;
- char *strtab = NULL;
- unsigned long int strtab_size = 0;
- Elf_Internal_Sym *symtab;
- Elf_Internal_Sym *psym;
-
-
- if ( section->sh_type != SHT_SYMTAB
- && section->sh_type != SHT_DYNSYM)
- continue;
-
- printf (_("\nSymbol table '%s' contains %lu entries:\n"),
- SECTION_NAME (section),
- (unsigned long) (section->sh_size / section->sh_entsize));
- if (is_32bit_elf)
- printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
- else
- printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
-
- symtab = GET_ELF_SYMBOLS (file, section);
- if (symtab == NULL)
- continue;
-
- if (section->sh_link == elf_header.e_shstrndx)
- {
- strtab = string_table;
- strtab_size = string_table_length;
- }
- else if (section->sh_link < elf_header.e_shnum)
- {
- Elf_Internal_Shdr *string_sec;
-
- string_sec = section_headers + section->sh_link;
-
- strtab = get_data (NULL, file, string_sec->sh_offset,
- 1, string_sec->sh_size, _("string table"));
- strtab_size = strtab != NULL ? string_sec->sh_size : 0;
- }
-
- for (si = 0, psym = symtab;
- si < section->sh_size / section->sh_entsize;
- si++, psym++)
- {
- printf ("%6d: ", si);
- print_vma (psym->st_value, LONG_HEX);
- putchar (' ');
- print_vma (psym->st_size, DEC_5);
- printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
- printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
- printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
- /* Check to see if any other bits in the st_other field are set.
- Note - displaying this information disrupts the layout of the
- table being generated, but for the moment this case is very rare. */
- if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
- printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
- printf (" %4s ", get_symbol_index_type (psym->st_shndx));
- print_symbol (25, psym->st_name < strtab_size
- ? strtab + psym->st_name : "<corrupt>");
-
- if (section->sh_type == SHT_DYNSYM &&
- version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
- {
- unsigned char data[2];
- unsigned short vers_data;
- unsigned long offset;
- int is_nobits;
- int check_def;
-
- offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
- sizeof data + si * sizeof (vers_data));
-
- get_data (&data, file, offset + si * sizeof (vers_data),
- sizeof (data), 1, _("version data"));
-
- vers_data = byte_get (data, 2);
-
- is_nobits = (psym->st_shndx < elf_header.e_shnum
- && section_headers[psym->st_shndx].sh_type
- == SHT_NOBITS);
-
- check_def = (psym->st_shndx != SHN_UNDEF);
-
- if ((vers_data & 0x8000) || vers_data > 1)
- {
- if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
- && (is_nobits || ! check_def))
- {
- Elf_External_Verneed evn;
- Elf_Internal_Verneed ivn;
- Elf_Internal_Vernaux ivna;
-
- /* We must test both. */
- offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
- sizeof evn);
-
- do
- {
- unsigned long vna_off;
-
- get_data (&evn, file, offset, sizeof (evn), 1,
- _("version need"));
-
- ivn.vn_aux = BYTE_GET (evn.vn_aux);
- ivn.vn_next = BYTE_GET (evn.vn_next);
-
- vna_off = offset + ivn.vn_aux;
-
- do
- {
- Elf_External_Vernaux evna;
-
- get_data (&evna, file, vna_off,
- sizeof (evna), 1,
- _("version need aux (3)"));
-
- ivna.vna_other = BYTE_GET (evna.vna_other);
- ivna.vna_next = BYTE_GET (evna.vna_next);
- ivna.vna_name = BYTE_GET (evna.vna_name);
-
- vna_off += ivna.vna_next;
- }
- while (ivna.vna_other != vers_data
- && ivna.vna_next != 0);
-
- if (ivna.vna_other == vers_data)
- break;
-
- offset += ivn.vn_next;
- }
- while (ivn.vn_next != 0);
-
- if (ivna.vna_other == vers_data)
- {
- printf ("@%s (%d)",
- ivna.vna_name < strtab_size
- ? strtab + ivna.vna_name : "<corrupt>",
- ivna.vna_other);
- check_def = 0;
- }
- else if (! is_nobits)
- error (_("bad dynamic symbol\n"));
- else
- check_def = 1;
- }
-
- if (check_def)
- {
- if (vers_data != 0x8001
- && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
- {
- Elf_Internal_Verdef ivd;
- Elf_Internal_Verdaux ivda;
- Elf_External_Verdaux evda;
- unsigned long offset;
-
- offset = offset_from_vma
- (file,
- version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
- sizeof (Elf_External_Verdef));
-
- do
- {
- Elf_External_Verdef evd;
-
- get_data (&evd, file, offset, sizeof (evd),
- 1, _("version def"));
-
- ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
- ivd.vd_aux = BYTE_GET (evd.vd_aux);
- ivd.vd_next = BYTE_GET (evd.vd_next);
-
- offset += ivd.vd_next;
- }
- while (ivd.vd_ndx != (vers_data & 0x7fff)
- && ivd.vd_next != 0);
-
- offset -= ivd.vd_next;
- offset += ivd.vd_aux;
-
- get_data (&evda, file, offset, sizeof (evda),
- 1, _("version def aux"));
-
- ivda.vda_name = BYTE_GET (evda.vda_name);
-
- if (psym->st_name != ivda.vda_name)
- printf ((vers_data & 0x8000)
- ? "@%s" : "@@%s",
- ivda.vda_name < strtab_size
- ? strtab + ivda.vda_name : "<corrupt>");
- }
- }
- }
- }
-
- putchar ('\n');
- }
-
- free (symtab);
- if (strtab != string_table)
- free (strtab);
- }
- }
- else if (do_syms)
- printf
- (_("\nDynamic symbol information is not available for displaying symbols.\n"));
-
- if (do_histogram && buckets != NULL)
- {
- unsigned long *lengths;
- unsigned long *counts;
- unsigned long hn;
- bfd_vma si;
- unsigned long maxlength = 0;
- unsigned long nzero_counts = 0;
- unsigned long nsyms = 0;
-
- printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
- (unsigned long) nbuckets);
- printf (_(" Length Number %% of total Coverage\n"));
-
- lengths = calloc (nbuckets, sizeof (*lengths));
- if (lengths == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
- for (hn = 0; hn < nbuckets; ++hn)
- {
- for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
- {
- ++nsyms;
- if (maxlength < ++lengths[hn])
- ++maxlength;
- }
- }
-
- counts = calloc (maxlength + 1, sizeof (*counts));
- if (counts == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- for (hn = 0; hn < nbuckets; ++hn)
- ++counts[lengths[hn]];
-
- if (nbuckets > 0)
- {
- unsigned long i;
- printf (" 0 %-10lu (%5.1f%%)\n",
- counts[0], (counts[0] * 100.0) / nbuckets);
- for (i = 1; i <= maxlength; ++i)
- {
- nzero_counts += counts[i] * i;
- printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
- i, counts[i], (counts[i] * 100.0) / nbuckets,
- (nzero_counts * 100.0) / nsyms);
- }
- }
-
- free (counts);
- free (lengths);
- }
-
- if (buckets != NULL)
- {
- free (buckets);
- free (chains);
- }
-
- if (do_histogram && dynamic_info_DT_GNU_HASH)
- {
- unsigned long *lengths;
- unsigned long *counts;
- unsigned long hn;
- unsigned long maxlength = 0;
- unsigned long nzero_counts = 0;
- unsigned long nsyms = 0;
-
- lengths = calloc (ngnubuckets, sizeof (*lengths));
- if (lengths == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
- (unsigned long) ngnubuckets);
- printf (_(" Length Number %% of total Coverage\n"));
-
- for (hn = 0; hn < ngnubuckets; ++hn)
- if (gnubuckets[hn] != 0)
- {
- bfd_vma off, length = 1;
-
- for (off = gnubuckets[hn] - gnusymidx;
- (gnuchains[off] & 1) == 0; ++off)
- ++length;
- lengths[hn] = length;
- if (length > maxlength)
- maxlength = length;
- nsyms += length;
- }
-
- counts = calloc (maxlength + 1, sizeof (*counts));
- if (counts == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- for (hn = 0; hn < ngnubuckets; ++hn)
- ++counts[lengths[hn]];
-
- if (ngnubuckets > 0)
- {
- unsigned long j;
- printf (" 0 %-10lu (%5.1f%%)\n",
- counts[0], (counts[0] * 100.0) / ngnubuckets);
- for (j = 1; j <= maxlength; ++j)
- {
- nzero_counts += counts[j] * j;
- printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
- j, counts[j], (counts[j] * 100.0) / ngnubuckets,
- (nzero_counts * 100.0) / nsyms);
- }
- }
-
- free (counts);
- free (lengths);
- free (gnubuckets);
- free (gnuchains);
- }
-
- return 1;
-}
-
-static int
-process_syminfo (FILE *file ATTRIBUTE_UNUSED)
-{
- unsigned int i;
-
- if (dynamic_syminfo == NULL
- || !do_dynamic)
- /* No syminfo, this is ok. */
- return 1;
-
- /* There better should be a dynamic symbol section. */
- if (dynamic_symbols == NULL || dynamic_strings == NULL)
- return 0;
-
- if (dynamic_addr)
- printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
- dynamic_syminfo_offset, dynamic_syminfo_nent);
-
- printf (_(" Num: Name BoundTo Flags\n"));
- for (i = 0; i < dynamic_syminfo_nent; ++i)
- {
- unsigned short int flags = dynamic_syminfo[i].si_flags;
-
- printf ("%4d: ", i);
- if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
- print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
- else
- printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
- putchar (' ');
-
- switch (dynamic_syminfo[i].si_boundto)
- {
- case SYMINFO_BT_SELF:
- fputs ("SELF ", stdout);
- break;
- case SYMINFO_BT_PARENT:
- fputs ("PARENT ", stdout);
- break;
- default:
- if (dynamic_syminfo[i].si_boundto > 0
- && dynamic_syminfo[i].si_boundto < dynamic_nent
- && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
- {
- print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
- putchar (' ' );
- }
- else
- printf ("%-10d ", dynamic_syminfo[i].si_boundto);
- break;
- }
-
- if (flags & SYMINFO_FLG_DIRECT)
- printf (" DIRECT");
- if (flags & SYMINFO_FLG_PASSTHRU)
- printf (" PASSTHRU");
- if (flags & SYMINFO_FLG_COPY)
- printf (" COPY");
- if (flags & SYMINFO_FLG_LAZYLOAD)
- printf (" LAZYLOAD");
-
- puts ("");
- }
-
- return 1;
-}
-
-#ifdef SUPPORT_DISASSEMBLY
-static int
-disassemble_section (Elf_Internal_Shdr *section, FILE *file)
-{
- printf (_("\nAssembly dump of section %s\n"),
- SECTION_NAME (section));
-
- /* XXX -- to be done --- XXX */
-
- return 1;
-}
-#endif
-
-static int
-dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file)
-{
- Elf_Internal_Shdr *relsec;
- bfd_size_type num_bytes;
- bfd_vma addr;
- char *data;
- char *end;
- char *start;
- char *name = SECTION_NAME (section);
- bfd_boolean some_strings_shown;
-
- num_bytes = section->sh_size;
-
- if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
- {
- printf (_("\nSection '%s' has no data to dump.\n"), name);
- return 0;
- }
-
- addr = section->sh_addr;
-
- start = get_data (NULL, file, section->sh_offset, 1, num_bytes,
- _("section data"));
- if (!start)
- return 0;
-
- printf (_("\nString dump of section '%s':\n"), name);
-
- /* If the section being dumped has relocations against it the user might
- be expecting these relocations to have been applied. Check for this
- case and issue a warning message in order to avoid confusion.
- FIXME: Maybe we ought to have an option that dumps a section with
- relocs applied ? */
- for (relsec = section_headers;
- relsec < section_headers + elf_header.e_shnum;
- ++relsec)
- {
- if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
- || relsec->sh_info >= elf_header.e_shnum
- || section_headers + relsec->sh_info != section
- || relsec->sh_size == 0
- || relsec->sh_link >= elf_header.e_shnum)
- continue;
-
- printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
- break;
- }
-
- data = start;
- end = start + num_bytes;
- some_strings_shown = FALSE;
-
- while (data < end)
- {
- while (!ISPRINT (* data))
- if (++ data >= end)
- break;
-
- if (data < end)
- {
-#ifndef __MSVCRT__
- printf (" [%6tx] %s\n", data - start, data);
-#else
- printf (" [%6Ix] %s\n", (size_t) (data - start), data);
-#endif
- data += strlen (data);
- some_strings_shown = TRUE;
- }
- }
-
- if (! some_strings_shown)
- printf (_(" No strings found in this section."));
-
- free (start);
-
- putchar ('\n');
- return 1;
-}
-
-
-static int
-dump_section_as_bytes (Elf_Internal_Shdr *section, FILE *file)
-{
- Elf_Internal_Shdr *relsec;
- bfd_size_type bytes;
- bfd_vma addr;
- unsigned char *data;
- unsigned char *start;
-
- bytes = section->sh_size;
-
- if (bytes == 0 || section->sh_type == SHT_NOBITS)
- {
- printf (_("\nSection '%s' has no data to dump.\n"),
- SECTION_NAME (section));
- return 0;
- }
- else
- printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
-
- addr = section->sh_addr;
-
- start = get_data (NULL, file, section->sh_offset, 1, bytes,
- _("section data"));
- if (!start)
- return 0;
-
- /* If the section being dumped has relocations against it the user might
- be expecting these relocations to have been applied. Check for this
- case and issue a warning message in order to avoid confusion.
- FIXME: Maybe we ought to have an option that dumps a section with
- relocs applied ? */
- for (relsec = section_headers;
- relsec < section_headers + elf_header.e_shnum;
- ++relsec)
- {
- if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
- || relsec->sh_info >= elf_header.e_shnum
- || section_headers + relsec->sh_info != section
- || relsec->sh_size == 0
- || relsec->sh_link >= elf_header.e_shnum)
- continue;
-
- printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
- break;
- }
-
- data = start;
-
- while (bytes)
- {
- int j;
- int k;
- int lbytes;
-
- lbytes = (bytes > 16 ? 16 : bytes);
-
- printf (" 0x%8.8lx ", (unsigned long) addr);
-
- for (j = 0; j < 16; j++)
- {
- if (j < lbytes)
- printf ("%2.2x", data[j]);
- else
- printf (" ");
-
- if ((j & 3) == 3)
- printf (" ");
- }
-
- for (j = 0; j < lbytes; j++)
- {
- k = data[j];
- if (k >= ' ' && k < 0x7f)
- printf ("%c", k);
- else
- printf (".");
- }
-
- putchar ('\n');
-
- data += lbytes;
- addr += lbytes;
- bytes -= lbytes;
- }
-
- free (start);
-
- putchar ('\n');
- return 1;
-}
-
-/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
- DWARF debug sections. This is a target specific test. Note - we do not
- go through the whole including-target-headers-multiple-times route, (as
- we have already done with <elf/h8.h>) because this would become very
- messy and even then this function would have to contain target specific
- information (the names of the relocs instead of their numeric values).
- FIXME: This is not the correct way to solve this problem. The proper way
- is to have target specific reloc sizing and typing functions created by
- the reloc-macros.h header, in the same way that it already creates the
- reloc naming functions. */
-
-static bfd_boolean
-is_32bit_abs_reloc (unsigned int reloc_type)
-{
- switch (elf_header.e_machine)
- {
- case EM_386:
- case EM_486:
- return reloc_type == 1; /* R_386_32. */
- case EM_68K:
- return reloc_type == 1; /* R_68K_32. */
- case EM_860:
- return reloc_type == 1; /* R_860_32. */
- case EM_ALPHA:
- return reloc_type == 1; /* XXX Is this right ? */
- case EM_ARC:
- return reloc_type == 1; /* R_ARC_32. */
- case EM_ARM:
- return reloc_type == 2; /* R_ARM_ABS32 */
- case EM_AVR_OLD:
- case EM_AVR:
- return reloc_type == 1;
- case EM_BLACKFIN:
- return reloc_type == 0x12; /* R_byte4_data. */
- case EM_CRIS:
- return reloc_type == 3; /* R_CRIS_32. */
- case EM_CR16:
- case EM_CR16_OLD:
- return reloc_type == 3; /* R_CR16_NUM32. */
- case EM_CRX:
- return reloc_type == 15; /* R_CRX_NUM32. */
- case EM_CYGNUS_FRV:
- return reloc_type == 1;
- case EM_CYGNUS_D10V:
- case EM_D10V:
- return reloc_type == 6; /* R_D10V_32. */
- case EM_CYGNUS_D30V:
- case EM_D30V:
- return reloc_type == 12; /* R_D30V_32_NORMAL. */
- case EM_DLX:
- return reloc_type == 3; /* R_DLX_RELOC_32. */
- case EM_CYGNUS_FR30:
- case EM_FR30:
- return reloc_type == 3; /* R_FR30_32. */
- case EM_H8S:
- case EM_H8_300:
- case EM_H8_300H:
- return reloc_type == 1; /* R_H8_DIR32. */
- case EM_IA_64:
- return reloc_type == 0x65; /* R_IA64_SECREL32LSB. */
- case EM_IP2K_OLD:
- case EM_IP2K:
- return reloc_type == 2; /* R_IP2K_32. */
- case EM_IQ2000:
- return reloc_type == 2; /* R_IQ2000_32. */
- case EM_M32C_OLD:
- case EM_M32C:
- return reloc_type == 3; /* R_M32C_32. */
- case EM_M32R:
- return reloc_type == 34; /* R_M32R_32_RELA. */
- case EM_MCORE:
- return reloc_type == 1; /* R_MCORE_ADDR32. */
- case EM_CYGNUS_MEP:
- return reloc_type == 4; /* R_MEP_32. */
- case EM_MIPS:
- return reloc_type == 2; /* R_MIPS_32. */
- case EM_MMIX:
- return reloc_type == 4; /* R_MMIX_32. */
- case EM_CYGNUS_MN10200:
- case EM_MN10200:
- return reloc_type == 1; /* R_MN10200_32. */
- case EM_CYGNUS_MN10300:
- case EM_MN10300:
- return reloc_type == 1; /* R_MN10300_32. */
- case EM_MSP430_OLD:
- case EM_MSP430:
- return reloc_type == 1; /* R_MSP43_32. */
- case EM_MT:
- return reloc_type == 2; /* R_MT_32. */
- case EM_ALTERA_NIOS2:
- case EM_NIOS32:
- return reloc_type == 1; /* R_NIOS_32. */
- case EM_OPENRISC:
- case EM_OR32:
- return reloc_type == 1; /* R_OR32_32. */
- case EM_PARISC:
- return reloc_type == 1; /* R_PARISC_DIR32. */
- case EM_PJ:
- case EM_PJ_OLD:
- return reloc_type == 1; /* R_PJ_DATA_DIR32. */
- case EM_PPC64:
- return reloc_type == 1; /* R_PPC64_ADDR32. */
- case EM_PPC:
- return reloc_type == 1; /* R_PPC_ADDR32. */
- case EM_S370:
- return reloc_type == 1; /* R_I370_ADDR31. */
- case EM_S390_OLD:
- case EM_S390:
- return reloc_type == 4; /* R_S390_32. */
- case EM_SCORE:
- return reloc_type == 8; /* R_SCORE_ABS32. */
- case EM_SH:
- return reloc_type == 1; /* R_SH_DIR32. */
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- case EM_SPARC:
- return reloc_type == 3 /* R_SPARC_32. */
- || reloc_type == 23; /* R_SPARC_UA32. */
- case EM_SPU:
- return reloc_type == 6; /* R_SPU_ADDR32 */
- case EM_CYGNUS_V850:
- case EM_V850:
- return reloc_type == 6; /* R_V850_ABS32. */
- case EM_VAX:
- return reloc_type == 1; /* R_VAX_32. */
- case EM_X86_64:
- return reloc_type == 10; /* R_X86_64_32. */
- case EM_XSTORMY16:
- return reloc_type == 1; /* R_XSTROMY16_32. */
- case EM_XTENSA_OLD:
- case EM_XTENSA:
- return reloc_type == 1; /* R_XTENSA_32. */
-
- default:
- error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
- elf_header.e_machine);
- abort ();
- }
-}
-
-/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
- a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
-
-static bfd_boolean
-is_32bit_pcrel_reloc (unsigned int reloc_type)
-{
- switch (elf_header.e_machine)
- {
- case EM_386:
- case EM_486:
- return reloc_type == 2; /* R_386_PC32. */
- case EM_68K:
- return reloc_type == 4; /* R_68K_PC32. */
- case EM_ALPHA:
- return reloc_type == 10; /* R_ALPHA_SREL32. */
- case EM_ARM:
- return reloc_type == 3; /* R_ARM_REL32 */
- case EM_PARISC:
- return reloc_type == 0; /* R_PARISC_NONE. *//* FIXME: This reloc is generated, but it may be a bug. */
- case EM_PPC:
- return reloc_type == 26; /* R_PPC_REL32. */
- case EM_PPC64:
- return reloc_type == 26; /* R_PPC64_REL32. */
- case EM_S390_OLD:
- case EM_S390:
- return reloc_type == 5; /* R_390_PC32. */
- case EM_SH:
- return reloc_type == 2; /* R_SH_REL32. */
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- case EM_SPARC:
- return reloc_type == 6; /* R_SPARC_DISP32. */
- case EM_SPU:
- return reloc_type == 13; /* R_SPU_REL32. */
- case EM_X86_64:
- return reloc_type == 2; /* R_X86_64_PC32. */
- case EM_XTENSA_OLD:
- case EM_XTENSA:
- return reloc_type == 14; /* R_XTENSA_32_PCREL. */
- default:
- /* Do not abort or issue an error message here. Not all targets use
- pc-relative 32-bit relocs in their DWARF debug information and we
- have already tested for target coverage in is_32bit_abs_reloc. A
- more helpful warning message will be generated by
- debug_apply_relocations anyway, so just return. */
- return FALSE;
- }
-}
-
-/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
- a 64-bit absolute RELA relocation used in DWARF debug sections. */
-
-static bfd_boolean
-is_64bit_abs_reloc (unsigned int reloc_type)
-{
- switch (elf_header.e_machine)
- {
- case EM_ALPHA:
- return reloc_type == 2; /* R_ALPHA_REFQUAD. */
- case EM_IA_64:
- return reloc_type == 0x27; /* R_IA64_DIR64LSB. */
- case EM_PARISC:
- return reloc_type == 80; /* R_PARISC_DIR64. */
- case EM_PPC64:
- return reloc_type == 38; /* R_PPC64_ADDR64. */
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- case EM_SPARC:
- return reloc_type == 54; /* R_SPARC_UA64. */
- case EM_X86_64:
- return reloc_type == 1; /* R_X86_64_64. */
- case EM_S390_OLD:
- case EM_S390:
- return reloc_type == 22; /* R_S390_64 */
- default:
- return FALSE;
- }
-}
-
-/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
- a 16-bit absolute RELA relocation used in DWARF debug sections. */
-
-static bfd_boolean
-is_16bit_abs_reloc (unsigned int reloc_type)
-{
- switch (elf_header.e_machine)
- {
- case EM_AVR_OLD:
- case EM_AVR:
- return reloc_type == 4; /* R_AVR_16. */
- case EM_CYGNUS_D10V:
- case EM_D10V:
- return reloc_type == 3; /* R_D10V_16. */
- case EM_H8S:
- case EM_H8_300:
- case EM_H8_300H:
- return reloc_type == R_H8_DIR16;
- case EM_IP2K_OLD:
- case EM_IP2K:
- return reloc_type == 1; /* R_IP2K_16. */
- case EM_M32C_OLD:
- case EM_M32C:
- return reloc_type == 1; /* R_M32C_16 */
- case EM_MSP430_OLD:
- case EM_MSP430:
- return reloc_type == 5; /* R_MSP430_16_BYTE. */
- case EM_ALTERA_NIOS2:
- case EM_NIOS32:
- return reloc_type == 9; /* R_NIOS_16. */
- default:
- return FALSE;
- }
-}
-
-/* Uncompresses a section that was compressed using zlib, in place.
- * This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
-
-static int
-uncompress_section_contents (unsigned char **buffer, dwarf_size_type *size)
-{
-#ifndef HAVE_ZLIB_H
- /* These are just to quiet gcc. */
- buffer = 0;
- size = 0;
- return FALSE;
-#else
- dwarf_size_type compressed_size = *size;
- unsigned char* compressed_buffer = *buffer;
- dwarf_size_type uncompressed_size;
- unsigned char* uncompressed_buffer;
- z_stream strm;
- int rc;
- dwarf_size_type header_size = 12;
-
- /* Read the zlib header. In this case, it should be "ZLIB" followed
- by the uncompressed section size, 8 bytes in big-endian order. */
- if (compressed_size < header_size
- || ! streq ((char*) compressed_buffer, "ZLIB"))
- return 0;
- uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[11];
-
- /* It is possible the section consists of several compressed
- buffers concatenated together, so we uncompress in a loop. */
- strm.zalloc = NULL;
- strm.zfree = NULL;
- strm.opaque = NULL;
- strm.avail_in = compressed_size - header_size;
- strm.next_in = (Bytef*) compressed_buffer + header_size;
- strm.avail_out = uncompressed_size;
- uncompressed_buffer = xmalloc (uncompressed_size);
-
- rc = inflateInit (&strm);
- while (strm.avail_in > 0)
- {
- if (rc != Z_OK)
- goto fail;
- strm.next_out = ((Bytef*) uncompressed_buffer
- + (uncompressed_size - strm.avail_out));
- rc = inflate (&strm, Z_FINISH);
- if (rc != Z_STREAM_END)
- goto fail;
- rc = inflateReset (&strm);
- }
- rc = inflateEnd (&strm);
- if (rc != Z_OK
- || strm.avail_out != 0)
- goto fail;
-
- free (compressed_buffer);
- *buffer = uncompressed_buffer;
- *size = uncompressed_size;
- return 1;
-
- fail:
- free (uncompressed_buffer);
- return 0;
-#endif /* HAVE_ZLIB_H */
-}
-
-/* Apply relocations to a debug section. */
-
-static void
-debug_apply_relocations (void *file,
- Elf_Internal_Shdr *section,
- unsigned char *start)
-{
- Elf_Internal_Shdr *relsec;
- unsigned char *end = start + section->sh_size;
-
- if (elf_header.e_type != ET_REL)
- return;
-
- /* Find the reloc section associated with the debug section. */
- for (relsec = section_headers;
- relsec < section_headers + elf_header.e_shnum;
- ++relsec)
- {
- bfd_boolean is_rela;
- unsigned long num_relocs;
- Elf_Internal_Rela *relocs, *rp;
- Elf_Internal_Shdr *symsec;
- Elf_Internal_Sym *symtab;
- Elf_Internal_Sym *sym;
-
- if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
- || relsec->sh_info >= elf_header.e_shnum
- || section_headers + relsec->sh_info != section
- || relsec->sh_size == 0
- || relsec->sh_link >= elf_header.e_shnum)
- continue;
-
- is_rela = relsec->sh_type == SHT_RELA;
-
- if (is_rela)
- {
- if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
- & relocs, & num_relocs))
- return;
- }
- else
- {
- if (!slurp_rel_relocs (file, relsec->sh_offset, relsec->sh_size,
- & relocs, & num_relocs))
- return;
- }
-
- /* SH uses RELA but uses in place value instead of the addend field. */
- if (elf_header.e_machine == EM_SH)
- is_rela = FALSE;
-
- symsec = section_headers + relsec->sh_link;
- symtab = GET_ELF_SYMBOLS (file, symsec);
-
- for (rp = relocs; rp < relocs + num_relocs; ++rp)
- {
- bfd_vma addend;
- unsigned int reloc_type;
- unsigned int reloc_size;
- unsigned char * loc;
-
- /* In MIPS little-endian objects, r_info isn't really a
- 64-bit little-endian value: it has a 32-bit little-endian
- symbol index followed by four individual byte fields.
- Reorder INFO accordingly. */
- if (!is_32bit_elf
- && elf_header.e_machine == EM_MIPS
- && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
- rp->r_info = (((rp->r_info & 0xffffffff) << 32)
- | ((rp->r_info >> 56) & 0xff)
- | ((rp->r_info >> 40) & 0xff00)
- | ((rp->r_info >> 24) & 0xff0000)
- | ((rp->r_info >> 8) & 0xff000000));
-
- reloc_type = get_reloc_type (rp->r_info);
-
- if (is_32bit_abs_reloc (reloc_type)
- || is_32bit_pcrel_reloc (reloc_type))
- reloc_size = 4;
- else if (is_64bit_abs_reloc (reloc_type))
- reloc_size = 8;
- else if (is_16bit_abs_reloc (reloc_type))
- reloc_size = 2;
- else
- {
- warn (_("unable to apply unsupported reloc type %d to section %s\n"),
- reloc_type, SECTION_NAME (section));
- continue;
- }
-
- loc = start + rp->r_offset;
- if ((loc + reloc_size) > end)
- {
- warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
- (unsigned long) rp->r_offset,
- SECTION_NAME (section));
- continue;
- }
-
- sym = symtab + get_reloc_symindex (rp->r_info);
-
- /* If the reloc has a symbol associated with it,
- make sure that it is of an appropriate type. */
- if (sym != symtab
- && ELF_ST_TYPE (sym->st_info) != STT_SECTION
- /* Relocations against symbols without type can happen.
- Gcc -feliminate-dwarf2-dups may generate symbols
- without type for debug info. */
- && ELF_ST_TYPE (sym->st_info) != STT_NOTYPE
- /* Relocations against object symbols can happen,
- eg when referencing a global array. For an
- example of this see the _clz.o binary in libgcc.a. */
- && ELF_ST_TYPE (sym->st_info) != STT_OBJECT)
- {
- warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
- get_symbol_type (ELF_ST_TYPE (sym->st_info)),
- (long int)(rp - relocs),
- SECTION_NAME (relsec));
- continue;
- }
-
- addend = is_rela ? rp->r_addend : byte_get (loc, reloc_size);
-
- if (is_32bit_pcrel_reloc (reloc_type))
- byte_put (loc, (addend + sym->st_value) - rp->r_offset,
- reloc_size);
- else
- byte_put (loc, addend + sym->st_value, reloc_size);
- }
-
- free (symtab);
- free (relocs);
- break;
- }
-}
-
-int
-load_debug_section (enum dwarf_section_display_enum debug, void *file)
-{
- struct dwarf_section *section = &debug_displays [debug].section;
- Elf_Internal_Shdr *sec;
- char buf [64];
- int section_is_compressed;
-
- /* If it is already loaded, do nothing. */
- if (section->start != NULL)
- return 1;
-
- /* Locate the debug section. */
- sec = find_section (section->uncompressed_name);
- if (sec != NULL)
- section->name = section->uncompressed_name;
- else
- {
- sec = find_section (section->compressed_name);
- if (sec != NULL)
- section->name = section->compressed_name;
- }
- if (sec == NULL)
- return 0;
- section_is_compressed = section->name == section->compressed_name;
-
- snprintf (buf, sizeof (buf), _("%s section data"), section->name);
- section->address = sec->sh_addr;
- section->size = sec->sh_size;
- section->start = get_data (NULL, file, sec->sh_offset, 1,
- sec->sh_size, buf);
- if (section->start == NULL)
- return 0;
-
- if (section_is_compressed)
- if (! uncompress_section_contents (&section->start, &section->size))
- return 0;
-
- if (debug_displays [debug].relocate)
- debug_apply_relocations (file, sec, section->start);
-
- return 1;
-}
-
-void
-free_debug_section (enum dwarf_section_display_enum debug)
-{
- struct dwarf_section *section = &debug_displays [debug].section;
-
- if (section->start == NULL)
- return;
-
- free ((char *) section->start);
- section->start = NULL;
- section->address = 0;
- section->size = 0;
-}
-
-static int
-display_debug_section (Elf_Internal_Shdr *section, FILE *file)
-{
- char *name = SECTION_NAME (section);
- bfd_size_type length;
- int result = 1;
- enum dwarf_section_display_enum i;
-
- length = section->sh_size;
- if (length == 0)
- {
- printf (_("\nSection '%s' has no debugging data.\n"), name);
- return 0;
- }
-
- if (const_strneq (name, ".gnu.linkonce.wi."))
- name = ".debug_info";
-
- /* See if we know how to display the contents of this section. */
- for (i = 0; i < max; i++)
- if (streq (debug_displays[i].section.uncompressed_name, name)
- || streq (debug_displays[i].section.compressed_name, name))
- {
- struct dwarf_section *sec = &debug_displays [i].section;
-
- if (load_debug_section (i, file))
- {
- result &= debug_displays[i].display (sec, file);
-
- if (i != info && i != abbrev)
- free_debug_section (i);
- }
-
- break;
- }
-
- if (i == max)
- {
- printf (_("Unrecognized debug section: %s\n"), name);
- result = 0;
- }
-
- return result;
-}
-
-/* Set DUMP_SECTS for all sections where dumps were requested
- based on section name. */
-
-static void
-initialise_dumps_byname (void)
-{
- struct dump_list_entry *cur;
-
- for (cur = dump_sects_byname; cur; cur = cur->next)
- {
- unsigned int i;
- int any;
-
- for (i = 0, any = 0; i < elf_header.e_shnum; i++)
- if (streq (SECTION_NAME (section_headers + i), cur->name))
- {
- request_dump_bynumber (i, cur->type);
- any = 1;
- }
-
- if (!any)
- warn (_("Section '%s' was not dumped because it does not exist!\n"),
- cur->name);
- }
-}
-
-static void
-process_section_contents (FILE *file)
-{
- Elf_Internal_Shdr *section;
- unsigned int i;
-
- if (! do_dump)
- return;
-
- initialise_dumps_byname ();
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum && i < num_dump_sects;
- i++, section++)
- {
-#ifdef SUPPORT_DISASSEMBLY
- if (dump_sects[i] & DISASS_DUMP)
- disassemble_section (section, file);
-#endif
- if (dump_sects[i] & HEX_DUMP)
- dump_section_as_bytes (section, file);
-
- if (dump_sects[i] & DEBUG_DUMP)
- display_debug_section (section, file);
-
- if (dump_sects[i] & STRING_DUMP)
- dump_section_as_strings (section, file);
- }
-
- /* Check to see if the user requested a
- dump of a section that does not exist. */
- while (i++ < num_dump_sects)
- if (dump_sects[i])
- warn (_("Section %d was not dumped because it does not exist!\n"), i);
-}
-
-static void
-process_mips_fpe_exception (int mask)
-{
- if (mask)
- {
- int first = 1;
- if (mask & OEX_FPU_INEX)
- fputs ("INEX", stdout), first = 0;
- if (mask & OEX_FPU_UFLO)
- printf ("%sUFLO", first ? "" : "|"), first = 0;
- if (mask & OEX_FPU_OFLO)
- printf ("%sOFLO", first ? "" : "|"), first = 0;
- if (mask & OEX_FPU_DIV0)
- printf ("%sDIV0", first ? "" : "|"), first = 0;
- if (mask & OEX_FPU_INVAL)
- printf ("%sINVAL", first ? "" : "|");
- }
- else
- fputs ("0", stdout);
-}
-
-/* ARM EABI attributes section. */
-typedef struct
-{
- int tag;
- const char *name;
- /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
- int type;
- const char **table;
-} arm_attr_public_tag;
-
-static const char *arm_attr_tag_CPU_arch[] =
- {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
- "v6K", "v7"};
-static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
-static const char *arm_attr_tag_THUMB_ISA_use[] =
- {"No", "Thumb-1", "Thumb-2"};
-static const char *arm_attr_tag_VFP_arch[] =
- {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
-static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1"};
-static const char *arm_attr_tag_NEON_arch[] = {"No", "NEONv1"};
-static const char *arm_attr_tag_ABI_PCS_config[] =
- {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
- "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
-static const char *arm_attr_tag_ABI_PCS_R9_use[] =
- {"V6", "SB", "TLS", "Unused"};
-static const char *arm_attr_tag_ABI_PCS_RW_data[] =
- {"Absolute", "PC-relative", "SB-relative", "None"};
-static const char *arm_attr_tag_ABI_PCS_RO_DATA[] =
- {"Absolute", "PC-relative", "None"};
-static const char *arm_attr_tag_ABI_PCS_GOT_use[] =
- {"None", "direct", "GOT-indirect"};
-static const char *arm_attr_tag_ABI_PCS_wchar_t[] =
- {"None", "??? 1", "2", "??? 3", "4"};
-static const char *arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_denormal[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_number_model[] =
- {"Unused", "Finite", "RTABI", "IEEE 754"};
-static const char *arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
-static const char *arm_attr_tag_ABI_align8_preserved[] =
- {"No", "Yes, except leaf SP", "Yes"};
-static const char *arm_attr_tag_ABI_enum_size[] =
- {"Unused", "small", "int", "forced to int"};
-static const char *arm_attr_tag_ABI_HardFP_use[] =
- {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
-static const char *arm_attr_tag_ABI_VFP_args[] =
- {"AAPCS", "VFP registers", "custom"};
-static const char *arm_attr_tag_ABI_WMMX_args[] =
- {"AAPCS", "WMMX registers", "custom"};
-static const char *arm_attr_tag_ABI_optimization_goals[] =
- {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
- "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
-static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
- {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
- "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
-
-#define LOOKUP(id, name) \
- {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
-static arm_attr_public_tag arm_attr_public_tags[] =
-{
- {4, "CPU_raw_name", 1, NULL},
- {5, "CPU_name", 1, NULL},
- LOOKUP(6, CPU_arch),
- {7, "CPU_arch_profile", 0, NULL},
- LOOKUP(8, ARM_ISA_use),
- LOOKUP(9, THUMB_ISA_use),
- LOOKUP(10, VFP_arch),
- LOOKUP(11, WMMX_arch),
- LOOKUP(12, NEON_arch),
- LOOKUP(13, ABI_PCS_config),
- LOOKUP(14, ABI_PCS_R9_use),
- LOOKUP(15, ABI_PCS_RW_data),
- LOOKUP(16, ABI_PCS_RO_DATA),
- LOOKUP(17, ABI_PCS_GOT_use),
- LOOKUP(18, ABI_PCS_wchar_t),
- LOOKUP(19, ABI_FP_rounding),
- LOOKUP(20, ABI_FP_denormal),
- LOOKUP(21, ABI_FP_exceptions),
- LOOKUP(22, ABI_FP_user_exceptions),
- LOOKUP(23, ABI_FP_number_model),
- LOOKUP(24, ABI_align8_needed),
- LOOKUP(25, ABI_align8_preserved),
- LOOKUP(26, ABI_enum_size),
- LOOKUP(27, ABI_HardFP_use),
- LOOKUP(28, ABI_VFP_args),
- LOOKUP(29, ABI_WMMX_args),
- LOOKUP(30, ABI_optimization_goals),
- LOOKUP(31, ABI_FP_optimization_goals),
- {32, "compatibility", 0, NULL}
-};
-#undef LOOKUP
-
-/* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
- bytes read. */
-static unsigned int
-read_uleb128 (unsigned char *p, unsigned int *plen)
-{
- unsigned char c;
- unsigned int val;
- int shift;
- int len;
-
- val = 0;
- shift = 0;
- len = 0;
- do
- {
- c = *(p++);
- len++;
- val |= ((unsigned int)c & 0x7f) << shift;
- shift += 7;
- }
- while (c & 0x80);
-
- *plen = len;
- return val;
-}
-
-static unsigned char *
-display_arm_attribute (unsigned char *p)
-{
- int tag;
- unsigned int len;
- int val;
- arm_attr_public_tag *attr;
- unsigned i;
- int type;
-
- tag = read_uleb128 (p, &len);
- p += len;
- attr = NULL;
- for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags); i++)
- {
- if (arm_attr_public_tags[i].tag == tag)
- {
- attr = &arm_attr_public_tags[i];
- break;
- }
- }
-
- if (attr)
- {
- printf (" Tag_%s: ", attr->name);
- switch (attr->type)
- {
- case 0:
- switch (tag)
- {
- case 7: /* Tag_CPU_arch_profile. */
- val = read_uleb128 (p, &len);
- p += len;
- switch (val)
- {
- case 0: printf ("None\n"); break;
- case 'A': printf ("Application\n"); break;
- case 'R': printf ("Realtime\n"); break;
- case 'M': printf ("Microcontroller\n"); break;
- default: printf ("??? (%d)\n", val); break;
- }
- break;
-
- case 32: /* Tag_compatibility. */
- val = read_uleb128 (p, &len);
- p += len;
- printf ("flag = %d, vendor = %s\n", val, p);
- p += strlen((char *)p) + 1;
- break;
-
- default:
- abort();
- }
- return p;
-
- case 1:
- case 2:
- type = attr->type;
- break;
-
- default:
- assert (attr->type & 0x80);
- val = read_uleb128 (p, &len);
- p += len;
- type = attr->type & 0x7f;
- if (val >= type)
- printf ("??? (%d)\n", val);
- else
- printf ("%s\n", attr->table[val]);
- return p;
- }
- }
- else
- {
- if (tag & 1)
- type = 1; /* String. */
- else
- type = 2; /* uleb128. */
- printf (" Tag_unknown_%d: ", tag);
- }
-
- if (type == 1)
- {
- printf ("\"%s\"\n", p);
- p += strlen((char *)p) + 1;
- }
- else
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf ("%d (0x%x)\n", val, val);
- }
-
- return p;
-}
-
-static unsigned char *
-display_gnu_attribute (unsigned char * p,
- unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int))
-{
- int tag;
- unsigned int len;
- int val;
- int type;
-
- tag = read_uleb128 (p, &len);
- p += len;
-
- /* Tag_compatibility is the only generic GNU attribute defined at
- present. */
- if (tag == 32)
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf ("flag = %d, vendor = %s\n", val, p);
- p += strlen ((char *) p) + 1;
- return p;
- }
-
- if ((tag & 2) == 0 && display_proc_gnu_attribute)
- return display_proc_gnu_attribute (p, tag);
-
- if (tag & 1)
- type = 1; /* String. */
- else
- type = 2; /* uleb128. */
- printf (" Tag_unknown_%d: ", tag);
-
- if (type == 1)
- {
- printf ("\"%s\"\n", p);
- p += strlen ((char *) p) + 1;
- }
- else
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf ("%d (0x%x)\n", val, val);
- }
-
- return p;
-}
-
-static unsigned char *
-display_power_gnu_attribute (unsigned char *p, int tag)
-{
- int type;
- unsigned int len;
- int val;
-
- if (tag == Tag_GNU_Power_ABI_FP)
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf (" Tag_GNU_Power_ABI_FP: ");
-
- switch (val)
- {
- case 0:
- printf ("Hard or soft float\n");
- break;
- case 1:
- printf ("Hard float\n");
- break;
- case 2:
- printf ("Soft float\n");
- break;
- case 3:
- printf ("Single-precision hard float\n");
- break;
- default:
- printf ("??? (%d)\n", val);
- break;
- }
- return p;
- }
-
- if (tag == Tag_GNU_Power_ABI_Vector)
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf (" Tag_GNU_Power_ABI_Vector: ");
- switch (val)
- {
- case 0:
- printf ("Any\n");
- break;
- case 1:
- printf ("Generic\n");
- break;
- case 2:
- printf ("AltiVec\n");
- break;
- case 3:
- printf ("SPE\n");
- break;
- default:
- printf ("??? (%d)\n", val);
- break;
- }
- return p;
- }
-
- if (tag & 1)
- type = 1; /* String. */
- else
- type = 2; /* uleb128. */
- printf (" Tag_unknown_%d: ", tag);
-
- if (type == 1)
- {
- printf ("\"%s\"\n", p);
- p += strlen ((char *) p) + 1;
- }
- else
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf ("%d (0x%x)\n", val, val);
- }
-
- return p;
-}
-
-static unsigned char *
-display_mips_gnu_attribute (unsigned char *p, int tag)
-{
- int type;
- unsigned int len;
- int val;
-
- if (tag == Tag_GNU_MIPS_ABI_FP)
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf (" Tag_GNU_MIPS_ABI_FP: ");
-
- switch (val)
- {
- case 0:
- printf ("Hard or soft float\n");
- break;
- case 1:
- printf ("Hard float (-mdouble-float)\n");
- break;
- case 2:
- printf ("Hard float (-msingle-float)\n");
- break;
- case 3:
- printf ("Soft float\n");
- break;
- case 4:
- printf ("64-bit float (-mips32r2 -mfp64)\n");
- break;
- default:
- printf ("??? (%d)\n", val);
- break;
- }
- return p;
- }
-
- if (tag & 1)
- type = 1; /* String. */
- else
- type = 2; /* uleb128. */
- printf (" Tag_unknown_%d: ", tag);
-
- if (type == 1)
- {
- printf ("\"%s\"\n", p);
- p += strlen ((char *) p) + 1;
- }
- else
- {
- val = read_uleb128 (p, &len);
- p += len;
- printf ("%d (0x%x)\n", val, val);
- }
-
- return p;
-}
-
-static int
-process_attributes (FILE * file,
- const char * public_name,
- unsigned int proc_type,
- unsigned char * (* display_pub_attribute) (unsigned char *),
- unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int))
-{
- Elf_Internal_Shdr *sect;
- unsigned char *contents;
- unsigned char *p;
- unsigned char *end;
- bfd_vma section_len;
- bfd_vma len;
- unsigned i;
-
- /* Find the section header so that we get the size. */
- for (i = 0, sect = section_headers;
- i < elf_header.e_shnum;
- i++, sect++)
- {
- if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
- continue;
-
- contents = get_data (NULL, file, sect->sh_offset, 1, sect->sh_size,
- _("attributes"));
- if (contents == NULL)
- continue;
-
- p = contents;
- if (*p == 'A')
- {
- len = sect->sh_size - 1;
- p++;
-
- while (len > 0)
- {
- int namelen;
- bfd_boolean public_section;
- bfd_boolean gnu_section;
-
- section_len = byte_get (p, 4);
- p += 4;
-
- if (section_len > len)
- {
- printf (_("ERROR: Bad section length (%d > %d)\n"),
- (int) section_len, (int) len);
- section_len = len;
- }
-
- len -= section_len;
- printf ("Attribute Section: %s\n", p);
-
- if (public_name && streq ((char *) p, public_name))
- public_section = TRUE;
- else
- public_section = FALSE;
-
- if (streq ((char *) p, "gnu"))
- gnu_section = TRUE;
- else
- gnu_section = FALSE;
-
- namelen = strlen ((char *) p) + 1;
- p += namelen;
- section_len -= namelen + 4;
-
- while (section_len > 0)
- {
- int tag = *(p++);
- int val;
- bfd_vma size;
-
- size = byte_get (p, 4);
- if (size > section_len)
- {
- printf (_("ERROR: Bad subsection length (%d > %d)\n"),
- (int) size, (int) section_len);
- size = section_len;
- }
-
- section_len -= size;
- end = p + size - 1;
- p += 4;
-
- switch (tag)
- {
- case 1:
- printf ("File Attributes\n");
- break;
- case 2:
- printf ("Section Attributes:");
- goto do_numlist;
- case 3:
- printf ("Symbol Attributes:");
- do_numlist:
- for (;;)
- {
- unsigned int i;
-
- val = read_uleb128 (p, &i);
- p += i;
- if (val == 0)
- break;
- printf (" %d", val);
- }
- printf ("\n");
- break;
- default:
- printf ("Unknown tag: %d\n", tag);
- public_section = FALSE;
- break;
- }
-
- if (public_section)
- {
- while (p < end)
- p = display_pub_attribute (p);
- }
- else if (gnu_section)
- {
- while (p < end)
- p = display_gnu_attribute (p,
- display_proc_gnu_attribute);
- }
- else
- {
- /* ??? Do something sensible, like dump hex. */
- printf (" Unknown section contexts\n");
- p = end;
- }
- }
- }
- }
- else
- printf (_("Unknown format '%c'\n"), *p);
-
- free (contents);
- }
- return 1;
-}
-
-static int
-process_arm_specific (FILE *file)
-{
- return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
- display_arm_attribute, NULL);
-}
-
-static int
-process_power_specific (FILE *file)
-{
- return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
- display_power_gnu_attribute);
-}
-
-/* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
- Print the Address, Access and Initial fields of an entry at VMA ADDR
- and return the VMA of the next entry. */
-
-static bfd_vma
-print_mips_got_entry (unsigned char *data, bfd_vma pltgot, bfd_vma addr)
-{
- printf (" ");
- print_vma (addr, LONG_HEX);
- printf (" ");
- if (addr < pltgot + 0xfff0)
- printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
- else
- printf ("%10s", "");
- printf (" ");
- if (data == NULL)
- printf ("%*s", is_32bit_elf ? 8 : 16, "<unknown>");
- else
- {
- bfd_vma entry;
-
- entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
- print_vma (entry, LONG_HEX);
- }
- return addr + (is_32bit_elf ? 4 : 8);
-}
-
-static int
-process_mips_specific (FILE *file)
-{
- Elf_Internal_Dyn *entry;
- size_t liblist_offset = 0;
- size_t liblistno = 0;
- size_t conflictsno = 0;
- size_t options_offset = 0;
- size_t conflicts_offset = 0;
- bfd_vma pltgot = 0;
- bfd_vma local_gotno = 0;
- bfd_vma gotsym = 0;
- bfd_vma symtabno = 0;
-
- process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
- display_mips_gnu_attribute);
-
- /* We have a lot of special sections. Thanks SGI! */
- if (dynamic_section == NULL)
- /* No information available. */
- return 0;
-
- for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
- switch (entry->d_tag)
- {
- case DT_MIPS_LIBLIST:
- liblist_offset
- = offset_from_vma (file, entry->d_un.d_val,
- liblistno * sizeof (Elf32_External_Lib));
- break;
- case DT_MIPS_LIBLISTNO:
- liblistno = entry->d_un.d_val;
- break;
- case DT_MIPS_OPTIONS:
- options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
- break;
- case DT_MIPS_CONFLICT:
- conflicts_offset
- = offset_from_vma (file, entry->d_un.d_val,
- conflictsno * sizeof (Elf32_External_Conflict));
- break;
- case DT_MIPS_CONFLICTNO:
- conflictsno = entry->d_un.d_val;
- break;
- case DT_PLTGOT:
- pltgot = entry->d_un.d_val;
- case DT_MIPS_LOCAL_GOTNO:
- local_gotno = entry->d_un.d_val;
- break;
- case DT_MIPS_GOTSYM:
- gotsym = entry->d_un.d_val;
- break;
- case DT_MIPS_SYMTABNO:
- symtabno = entry->d_un.d_val;
- break;
- default:
- break;
- }
-
- if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
- {
- Elf32_External_Lib *elib;
- size_t cnt;
-
- elib = get_data (NULL, file, liblist_offset,
- liblistno, sizeof (Elf32_External_Lib),
- _("liblist"));
- if (elib)
- {
- printf ("\nSection '.liblist' contains %lu entries:\n",
- (unsigned long) liblistno);
- fputs (" Library Time Stamp Checksum Version Flags\n",
- stdout);
-
- for (cnt = 0; cnt < liblistno; ++cnt)
- {
- Elf32_Lib liblist;
- time_t time;
- char timebuf[20];
- struct tm *tmp;
-
- liblist.l_name = BYTE_GET (elib[cnt].l_name);
- time = BYTE_GET (elib[cnt].l_time_stamp);
- liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
- liblist.l_version = BYTE_GET (elib[cnt].l_version);
- liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
-
- tmp = gmtime (&time);
- snprintf (timebuf, sizeof (timebuf),
- "%04u-%02u-%02uT%02u:%02u:%02u",
- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
-
- printf ("%3lu: ", (unsigned long) cnt);
- if (VALID_DYNAMIC_NAME (liblist.l_name))
- print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
- else
- printf ("<corrupt: %9ld>", liblist.l_name);
- printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
- liblist.l_version);
-
- if (liblist.l_flags == 0)
- puts (" NONE");
- else
- {
- static const struct
- {
- const char *name;
- int bit;
- }
- l_flags_vals[] =
- {
- { " EXACT_MATCH", LL_EXACT_MATCH },
- { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
- { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
- { " EXPORTS", LL_EXPORTS },
- { " DELAY_LOAD", LL_DELAY_LOAD },
- { " DELTA", LL_DELTA }
- };
- int flags = liblist.l_flags;
- size_t fcnt;
-
- for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
- if ((flags & l_flags_vals[fcnt].bit) != 0)
- {
- fputs (l_flags_vals[fcnt].name, stdout);
- flags ^= l_flags_vals[fcnt].bit;
- }
- if (flags != 0)
- printf (" %#x", (unsigned int) flags);
-
- puts ("");
- }
- }
-
- free (elib);
- }
- }
-
- if (options_offset != 0)
- {
- Elf_External_Options *eopt;
- Elf_Internal_Shdr *sect = section_headers;
- Elf_Internal_Options *iopt;
- Elf_Internal_Options *option;
- size_t offset;
- int cnt;
-
- /* Find the section header so that we get the size. */
- while (sect->sh_type != SHT_MIPS_OPTIONS)
- ++sect;
-
- eopt = get_data (NULL, file, options_offset, 1, sect->sh_size,
- _("options"));
- if (eopt)
- {
- iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
- if (iopt == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- offset = cnt = 0;
- option = iopt;
-
- while (offset < sect->sh_size)
- {
- Elf_External_Options *eoption;
-
- eoption = (Elf_External_Options *) ((char *) eopt + offset);
-
- option->kind = BYTE_GET (eoption->kind);
- option->size = BYTE_GET (eoption->size);
- option->section = BYTE_GET (eoption->section);
- option->info = BYTE_GET (eoption->info);
-
- offset += option->size;
-
- ++option;
- ++cnt;
- }
-
- printf (_("\nSection '%s' contains %d entries:\n"),
- SECTION_NAME (sect), cnt);
-
- option = iopt;
-
- while (cnt-- > 0)
- {
- size_t len;
-
- switch (option->kind)
- {
- case ODK_NULL:
- /* This shouldn't happen. */
- printf (" NULL %d %lx", option->section, option->info);
- break;
- case ODK_REGINFO:
- printf (" REGINFO ");
- if (elf_header.e_machine == EM_MIPS)
- {
- /* 32bit form. */
- Elf32_External_RegInfo *ereg;
- Elf32_RegInfo reginfo;
-
- ereg = (Elf32_External_RegInfo *) (option + 1);
- reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
- reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
- reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
- reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
- reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
- reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
-
- printf ("GPR %08lx GP 0x%lx\n",
- reginfo.ri_gprmask,
- (unsigned long) reginfo.ri_gp_value);
- printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
- reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
- reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
- }
- else
- {
- /* 64 bit form. */
- Elf64_External_RegInfo *ereg;
- Elf64_Internal_RegInfo reginfo;
-
- ereg = (Elf64_External_RegInfo *) (option + 1);
- reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
- reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
- reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
- reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
- reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
- reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
-
- printf ("GPR %08lx GP 0x",
- reginfo.ri_gprmask);
- printf_vma (reginfo.ri_gp_value);
- printf ("\n");
-
- printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
- reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
- reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
- }
- ++option;
- continue;
- case ODK_EXCEPTIONS:
- fputs (" EXCEPTIONS fpe_min(", stdout);
- process_mips_fpe_exception (option->info & OEX_FPU_MIN);
- fputs (") fpe_max(", stdout);
- process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
- fputs (")", stdout);
-
- if (option->info & OEX_PAGE0)
- fputs (" PAGE0", stdout);
- if (option->info & OEX_SMM)
- fputs (" SMM", stdout);
- if (option->info & OEX_FPDBUG)
- fputs (" FPDBUG", stdout);
- if (option->info & OEX_DISMISS)
- fputs (" DISMISS", stdout);
- break;
- case ODK_PAD:
- fputs (" PAD ", stdout);
- if (option->info & OPAD_PREFIX)
- fputs (" PREFIX", stdout);
- if (option->info & OPAD_POSTFIX)
- fputs (" POSTFIX", stdout);
- if (option->info & OPAD_SYMBOL)
- fputs (" SYMBOL", stdout);
- break;
- case ODK_HWPATCH:
- fputs (" HWPATCH ", stdout);
- if (option->info & OHW_R4KEOP)
- fputs (" R4KEOP", stdout);
- if (option->info & OHW_R8KPFETCH)
- fputs (" R8KPFETCH", stdout);
- if (option->info & OHW_R5KEOP)
- fputs (" R5KEOP", stdout);
- if (option->info & OHW_R5KCVTL)
- fputs (" R5KCVTL", stdout);
- break;
- case ODK_FILL:
- fputs (" FILL ", stdout);
- /* XXX Print content of info word? */
- break;
- case ODK_TAGS:
- fputs (" TAGS ", stdout);
- /* XXX Print content of info word? */
- break;
- case ODK_HWAND:
- fputs (" HWAND ", stdout);
- if (option->info & OHWA0_R4KEOP_CHECKED)
- fputs (" R4KEOP_CHECKED", stdout);
- if (option->info & OHWA0_R4KEOP_CLEAN)
- fputs (" R4KEOP_CLEAN", stdout);
- break;
- case ODK_HWOR:
- fputs (" HWOR ", stdout);
- if (option->info & OHWA0_R4KEOP_CHECKED)
- fputs (" R4KEOP_CHECKED", stdout);
- if (option->info & OHWA0_R4KEOP_CLEAN)
- fputs (" R4KEOP_CLEAN", stdout);
- break;
- case ODK_GP_GROUP:
- printf (" GP_GROUP %#06lx self-contained %#06lx",
- option->info & OGP_GROUP,
- (option->info & OGP_SELF) >> 16);
- break;
- case ODK_IDENT:
- printf (" IDENT %#06lx self-contained %#06lx",
- option->info & OGP_GROUP,
- (option->info & OGP_SELF) >> 16);
- break;
- default:
- /* This shouldn't happen. */
- printf (" %3d ??? %d %lx",
- option->kind, option->section, option->info);
- break;
- }
-
- len = sizeof (*eopt);
- while (len < option->size)
- if (((char *) option)[len] >= ' '
- && ((char *) option)[len] < 0x7f)
- printf ("%c", ((char *) option)[len++]);
- else
- printf ("\\%03o", ((char *) option)[len++]);
-
- fputs ("\n", stdout);
- ++option;
- }
-
- free (eopt);
- }
- }
-
- if (conflicts_offset != 0 && conflictsno != 0)
- {
- Elf32_Conflict *iconf;
- size_t cnt;
-
- if (dynamic_symbols == NULL)
- {
- error (_("conflict list found without a dynamic symbol table\n"));
- return 0;
- }
-
- iconf = cmalloc (conflictsno, sizeof (*iconf));
- if (iconf == NULL)
- {
- error (_("Out of memory\n"));
- return 0;
- }
-
- if (is_32bit_elf)
- {
- Elf32_External_Conflict *econf32;
-
- econf32 = get_data (NULL, file, conflicts_offset,
- conflictsno, sizeof (*econf32), _("conflict"));
- if (!econf32)
- return 0;
-
- for (cnt = 0; cnt < conflictsno; ++cnt)
- iconf[cnt] = BYTE_GET (econf32[cnt]);
-
- free (econf32);
- }
- else
- {
- Elf64_External_Conflict *econf64;
-
- econf64 = get_data (NULL, file, conflicts_offset,
- conflictsno, sizeof (*econf64), _("conflict"));
- if (!econf64)
- return 0;
-
- for (cnt = 0; cnt < conflictsno; ++cnt)
- iconf[cnt] = BYTE_GET (econf64[cnt]);
-
- free (econf64);
- }
-
- printf (_("\nSection '.conflict' contains %lu entries:\n"),
- (unsigned long) conflictsno);
- puts (_(" Num: Index Value Name"));
-
- for (cnt = 0; cnt < conflictsno; ++cnt)
- {
- Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
-
- printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
- print_vma (psym->st_value, FULL_HEX);
- putchar (' ');
- if (VALID_DYNAMIC_NAME (psym->st_name))
- print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
- else
- printf ("<corrupt: %14ld>", psym->st_name);
- putchar ('\n');
- }
-
- free (iconf);
- }
-
- if (pltgot != 0 && local_gotno != 0)
- {
- bfd_vma entry, local_end, global_end;
- size_t i, offset;
- unsigned char *data;
- int addr_size;
-
- entry = pltgot;
- addr_size = (is_32bit_elf ? 4 : 8);
- local_end = pltgot + local_gotno * addr_size;
- global_end = local_end + (symtabno - gotsym) * addr_size;
-
- offset = offset_from_vma (file, pltgot, global_end - pltgot);
- data = get_data (NULL, file, offset, global_end - pltgot, 1, _("GOT"));
- printf (_("\nPrimary GOT:\n"));
- printf (_(" Canonical gp value: "));
- print_vma (pltgot + 0x7ff0, LONG_HEX);
- printf ("\n\n");
-
- printf (_(" Reserved entries:\n"));
- printf (_(" %*s %10s %*s Purpose\n"),
- addr_size * 2, "Address", "Access",
- addr_size * 2, "Initial");
- entry = print_mips_got_entry (data, pltgot, entry);
- printf (" Lazy resolver\n");
- if (data
- && (byte_get (data + entry - pltgot, addr_size)
- >> (addr_size * 8 - 1)) != 0)
- {
- entry = print_mips_got_entry (data, pltgot, entry);
- printf (" Module pointer (GNU extension)\n");
- }
- printf ("\n");
-
- if (entry < local_end)
- {
- printf (_(" Local entries:\n"));
- printf (_(" %*s %10s %*s\n"),
- addr_size * 2, "Address", "Access",
- addr_size * 2, "Initial");
- while (entry < local_end)
- {
- entry = print_mips_got_entry (data, pltgot, entry);
- printf ("\n");
- }
- printf ("\n");
- }
-
- if (gotsym < symtabno)
- {
- int sym_width;
-
- printf (_(" Global entries:\n"));
- printf (_(" %*s %10s %*s %*s %-7s %3s %s\n"),
- addr_size * 2, "Address", "Access",
- addr_size * 2, "Initial",
- addr_size * 2, "Sym.Val.", "Type", "Ndx", "Name");
- sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
- for (i = gotsym; i < symtabno; i++)
- {
- Elf_Internal_Sym *psym;
-
- psym = dynamic_symbols + i;
- entry = print_mips_got_entry (data, pltgot, entry);
- printf (" ");
- print_vma (psym->st_value, LONG_HEX);
- printf (" %-7s %3s ",
- get_symbol_type (ELF_ST_TYPE (psym->st_info)),
- get_symbol_index_type (psym->st_shndx));
- if (VALID_DYNAMIC_NAME (psym->st_name))
- print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
- else
- printf ("<corrupt: %14ld>", psym->st_name);
- printf ("\n");
- }
- printf ("\n");
- }
-
- if (data)
- free (data);
- }
-
- return 1;
-}
-
-static int
-process_gnu_liblist (FILE *file)
-{
- Elf_Internal_Shdr *section, *string_sec;
- Elf32_External_Lib *elib;
- char *strtab;
- size_t strtab_size;
- size_t cnt;
- unsigned i;
-
- if (! do_arch)
- return 0;
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- {
- switch (section->sh_type)
- {
- case SHT_GNU_LIBLIST:
- if (section->sh_link >= elf_header.e_shnum)
- break;
-
- elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
- _("liblist"));
-
- if (elib == NULL)
- break;
- string_sec = section_headers + section->sh_link;
-
- strtab = get_data (NULL, file, string_sec->sh_offset, 1,
- string_sec->sh_size, _("liblist string table"));
- strtab_size = string_sec->sh_size;
-
- if (strtab == NULL
- || section->sh_entsize != sizeof (Elf32_External_Lib))
- {
- free (elib);
- break;
- }
-
- printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
- SECTION_NAME (section),
- (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
-
- puts (" Library Time Stamp Checksum Version Flags");
-
- for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
- ++cnt)
- {
- Elf32_Lib liblist;
- time_t time;
- char timebuf[20];
- struct tm *tmp;
-
- liblist.l_name = BYTE_GET (elib[cnt].l_name);
- time = BYTE_GET (elib[cnt].l_time_stamp);
- liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
- liblist.l_version = BYTE_GET (elib[cnt].l_version);
- liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
-
- tmp = gmtime (&time);
- snprintf (timebuf, sizeof (timebuf),
- "%04u-%02u-%02uT%02u:%02u:%02u",
- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
-
- printf ("%3lu: ", (unsigned long) cnt);
- if (do_wide)
- printf ("%-20s", liblist.l_name < strtab_size
- ? strtab + liblist.l_name : "<corrupt>");
- else
- printf ("%-20.20s", liblist.l_name < strtab_size
- ? strtab + liblist.l_name : "<corrupt>");
- printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
- liblist.l_version, liblist.l_flags);
- }
-
- free (elib);
- }
- }
-
- return 1;
-}
-
-static const char *
-get_note_type (unsigned e_type)
-{
- static char buff[64];
-
- if (elf_header.e_type == ET_CORE)
- switch (e_type)
- {
- case NT_AUXV:
- return _("NT_AUXV (auxiliary vector)");
- case NT_PRSTATUS:
- return _("NT_PRSTATUS (prstatus structure)");
- case NT_FPREGSET:
- return _("NT_FPREGSET (floating point registers)");
- case NT_PRPSINFO:
- return _("NT_PRPSINFO (prpsinfo structure)");
- case NT_TASKSTRUCT:
- return _("NT_TASKSTRUCT (task structure)");
- case NT_PRXFPREG:
- return _("NT_PRXFPREG (user_xfpregs structure)");
- case NT_PPC_VMX:
- return _("NT_PPC_VMX (ppc Altivec registers)");
- case NT_PPC_VSX:
- return _("NT_PPC_VSX (ppc VSX registers)");
- case NT_PSTATUS:
- return _("NT_PSTATUS (pstatus structure)");
- case NT_FPREGS:
- return _("NT_FPREGS (floating point registers)");
- case NT_PSINFO:
- return _("NT_PSINFO (psinfo structure)");
- case NT_LWPSTATUS:
- return _("NT_LWPSTATUS (lwpstatus_t structure)");
- case NT_LWPSINFO:
- return _("NT_LWPSINFO (lwpsinfo_t structure)");
- case NT_WIN32PSTATUS:
- return _("NT_WIN32PSTATUS (win32_pstatus structure)");
- default:
- break;
- }
- else
- switch (e_type)
- {
- case NT_VERSION:
- return _("NT_VERSION (version)");
- case NT_ARCH:
- return _("NT_ARCH (architecture)");
- default:
- break;
- }
-
- snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
- return buff;
-}
-
-static const char *
-get_gnu_elf_note_type (unsigned e_type)
-{
- static char buff[64];
-
- switch (e_type)
- {
- case NT_GNU_ABI_TAG:
- return _("NT_GNU_ABI_TAG (ABI version tag)");
- case NT_GNU_HWCAP:
- return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
- case NT_GNU_BUILD_ID:
- return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
- case NT_GNU_GOLD_VERSION:
- return _("NT_GNU_GOLD_VERSION (gold version)");
- default:
- break;
- }
-
- snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
- return buff;
-}
-
-static const char *
-get_netbsd_elfcore_note_type (unsigned e_type)
-{
- static char buff[64];
-
- if (e_type == NT_NETBSDCORE_PROCINFO)
- {
- /* NetBSD core "procinfo" structure. */
- return _("NetBSD procinfo structure");
- }
-
- /* As of Jan 2002 there are no other machine-independent notes
- defined for NetBSD core files. If the note type is less
- than the start of the machine-dependent note types, we don't
- understand it. */
-
- if (e_type < NT_NETBSDCORE_FIRSTMACH)
- {
- snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
- return buff;
- }
-
- switch (elf_header.e_machine)
- {
- /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
- and PT_GETFPREGS == mach+2. */
-
- case EM_OLD_ALPHA:
- case EM_ALPHA:
- case EM_SPARC:
- case EM_SPARC32PLUS:
- case EM_SPARCV9:
- switch (e_type)
- {
- case NT_NETBSDCORE_FIRSTMACH+0:
- return _("PT_GETREGS (reg structure)");
- case NT_NETBSDCORE_FIRSTMACH+2:
- return _("PT_GETFPREGS (fpreg structure)");
- default:
- break;
- }
- break;
-
- /* On all other arch's, PT_GETREGS == mach+1 and
- PT_GETFPREGS == mach+3. */
- default:
- switch (e_type)
- {
- case NT_NETBSDCORE_FIRSTMACH+1:
- return _("PT_GETREGS (reg structure)");
- case NT_NETBSDCORE_FIRSTMACH+3:
- return _("PT_GETFPREGS (fpreg structure)");
- default:
- break;
- }
- }
-
- snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
- e_type - NT_NETBSDCORE_FIRSTMACH);
- return buff;
-}
-
-/* Note that by the ELF standard, the name field is already null byte
- terminated, and namesz includes the terminating null byte.
- I.E. the value of namesz for the name "FSF" is 4.
-
- If the value of namesz is zero, there is no name present. */
-static int
-process_note (Elf_Internal_Note *pnote)
-{
- const char *name = pnote->namesz ? pnote->namedata : "(NONE)";
- const char *nt;
-
- if (pnote->namesz == 0)
- /* If there is no note name, then use the default set of
- note type strings. */
- nt = get_note_type (pnote->type);
-
- else if (const_strneq (pnote->namedata, "GNU"))
- /* GNU-specific object file notes. */
- nt = get_gnu_elf_note_type (pnote->type);
-
- else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
- /* NetBSD-specific core file notes. */
- nt = get_netbsd_elfcore_note_type (pnote->type);
-
- else if (strneq (pnote->namedata, "SPU/", 4))
- {
- /* SPU-specific core file notes. */
- nt = pnote->namedata + 4;
- name = "SPU";
- }
-
- else
- /* Don't recognize this note name; just use the default set of
- note type strings. */
- nt = get_note_type (pnote->type);
-
- printf (" %s\t\t0x%08lx\t%s\n", name, pnote->descsz, nt);
- return 1;
-}
-
-
-static int
-process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
-{
- Elf_External_Note *pnotes;
- Elf_External_Note *external;
- int res = 1;
-
- if (length <= 0)
- return 0;
-
- pnotes = get_data (NULL, file, offset, 1, length, _("notes"));
- if (!pnotes)
- return 0;
-
- external = pnotes;
-
- printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
- (unsigned long) offset, (unsigned long) length);
- printf (_(" Owner\t\tData size\tDescription\n"));
-
- while (external < (Elf_External_Note *)((char *) pnotes + length))
- {
- Elf_External_Note *next;
- Elf_Internal_Note inote;
- char *temp = NULL;
-
- inote.type = BYTE_GET (external->type);
- inote.namesz = BYTE_GET (external->namesz);
- inote.namedata = external->name;
- inote.descsz = BYTE_GET (external->descsz);
- inote.descdata = inote.namedata + align_power (inote.namesz, 2);
- inote.descpos = offset + (inote.descdata - (char *) pnotes);
-
- next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
-
- if (((char *) next) > (((char *) pnotes) + length))
- {
- warn (_("corrupt note found at offset %lx into core notes\n"),
- (unsigned long) ((char *) external - (char *) pnotes));
- warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
- inote.type, inote.namesz, inote.descsz);
- break;
- }
-
- external = next;
-
- /* Verify that name is null terminated. It appears that at least
- one version of Linux (RedHat 6.0) generates corefiles that don't
- comply with the ELF spec by failing to include the null byte in
- namesz. */
- if (inote.namedata[inote.namesz] != '\0')
- {
- temp = malloc (inote.namesz + 1);
-
- if (temp == NULL)
- {
- error (_("Out of memory\n"));
- res = 0;
- break;
- }
-
- strncpy (temp, inote.namedata, inote.namesz);
- temp[inote.namesz] = 0;
-
- /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
- inote.namedata = temp;
- }
-
- res &= process_note (& inote);
-
- if (temp != NULL)
- {
- free (temp);
- temp = NULL;
- }
- }
-
- free (pnotes);
-
- return res;
-}
-
-static int
-process_corefile_note_segments (FILE *file)
-{
- Elf_Internal_Phdr *segment;
- unsigned int i;
- int res = 1;
-
- if (! get_program_headers (file))
- return 0;
-
- for (i = 0, segment = program_headers;
- i < elf_header.e_phnum;
- i++, segment++)
- {
- if (segment->p_type == PT_NOTE)
- res &= process_corefile_note_segment (file,
- (bfd_vma) segment->p_offset,
- (bfd_vma) segment->p_filesz);
- }
-
- return res;
-}
-
-static int
-process_note_sections (FILE *file)
-{
- Elf_Internal_Shdr *section;
- unsigned long i;
- int res = 1;
-
- for (i = 0, section = section_headers;
- i < elf_header.e_shnum;
- i++, section++)
- if (section->sh_type == SHT_NOTE)
- res &= process_corefile_note_segment (file,
- (bfd_vma) section->sh_offset,
- (bfd_vma) section->sh_size);
-
- return res;
-}
-
-static int
-process_notes (FILE *file)
-{
- /* If we have not been asked to display the notes then do nothing. */
- if (! do_notes)
- return 1;
-
- if (elf_header.e_type != ET_CORE)
- return process_note_sections (file);
-
- /* No program headers means no NOTE segment. */
- if (elf_header.e_phnum > 0)
- return process_corefile_note_segments (file);
-
- printf (_("No note segments present in the core file.\n"));
- return 1;
-}
-
-static int
-process_arch_specific (FILE *file)
-{
- if (! do_arch)
- return 1;
-
- switch (elf_header.e_machine)
- {
- case EM_ARM:
- return process_arm_specific (file);
- case EM_MIPS:
- case EM_MIPS_RS3_LE:
- return process_mips_specific (file);
- break;
- case EM_PPC:
- return process_power_specific (file);
- break;
- default:
- break;
- }
- return 1;
-}
-
-static int
-get_file_header (FILE *file)
-{
- /* Read in the identity array. */
- if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
- return 0;
-
- /* Determine how to read the rest of the header. */
- switch (elf_header.e_ident[EI_DATA])
- {
- default: /* fall through */
- case ELFDATANONE: /* fall through */
- case ELFDATA2LSB:
- byte_get = byte_get_little_endian;
- byte_put = byte_put_little_endian;
- break;
- case ELFDATA2MSB:
- byte_get = byte_get_big_endian;
- byte_put = byte_put_big_endian;
- break;
- }
-
- /* For now we only support 32 bit and 64 bit ELF files. */
- is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
-
- /* Read in the rest of the header. */
- if (is_32bit_elf)
- {
- Elf32_External_Ehdr ehdr32;
-
- if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
- return 0;
-
- elf_header.e_type = BYTE_GET (ehdr32.e_type);
- elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
- elf_header.e_version = BYTE_GET (ehdr32.e_version);
- elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
- elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
- elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
- elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
- elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
- elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
- elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
- elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
- elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
- elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
- }
- else
- {
- Elf64_External_Ehdr ehdr64;
-
- /* If we have been compiled with sizeof (bfd_vma) == 4, then
- we will not be able to cope with the 64bit data found in
- 64 ELF files. Detect this now and abort before we start
- overwriting things. */
- if (sizeof (bfd_vma) < 8)
- {
- error (_("This instance of readelf has been built without support for a\n\
-64 bit data type and so it cannot read 64 bit ELF files.\n"));
- return 0;
- }
-
- if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
- return 0;
-
- elf_header.e_type = BYTE_GET (ehdr64.e_type);
- elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
- elf_header.e_version = BYTE_GET (ehdr64.e_version);
- elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
- elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
- elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
- elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
- elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
- elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
- elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
- elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
- elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
- elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
- }
-
- if (elf_header.e_shoff)
- {
- /* There may be some extensions in the first section header. Don't
- bomb if we can't read it. */
- if (is_32bit_elf)
- get_32bit_section_headers (file, 1);
- else
- get_64bit_section_headers (file, 1);
- }
-
- return 1;
-}
-
-/* Process one ELF object file according to the command line options.
- This file may actually be stored in an archive. The file is
- positioned at the start of the ELF object. */
-
-static int
-process_object (char *file_name, FILE *file)
-{
- unsigned int i;
-
- if (! get_file_header (file))
- {
- error (_("%s: Failed to read file header\n"), file_name);
- return 1;
- }
-
- /* Initialise per file variables. */
- for (i = ARRAY_SIZE (version_info); i--;)
- version_info[i] = 0;
-
- for (i = ARRAY_SIZE (dynamic_info); i--;)
- dynamic_info[i] = 0;
-
- /* Process the file. */
- if (show_name)
- printf (_("\nFile: %s\n"), file_name);
-
- /* Initialise the dump_sects array from the cmdline_dump_sects array.
- Note we do this even if cmdline_dump_sects is empty because we
- must make sure that the dump_sets array is zeroed out before each
- object file is processed. */
- if (num_dump_sects > num_cmdline_dump_sects)
- memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
-
- if (num_cmdline_dump_sects > 0)
- {
- if (num_dump_sects == 0)
- /* A sneaky way of allocating the dump_sects array. */
- request_dump_bynumber (num_cmdline_dump_sects, 0);
-
- assert (num_dump_sects >= num_cmdline_dump_sects);
- memcpy (dump_sects, cmdline_dump_sects,
- num_cmdline_dump_sects * sizeof (* dump_sects));
- }
-
- if (! process_file_header ())
- return 1;
-
- if (! process_section_headers (file))
- {
- /* Without loaded section headers we cannot process lots of
- things. */
- do_unwind = do_version = do_dump = do_arch = 0;
-
- if (! do_using_dynamic)
- do_syms = do_reloc = 0;
- }
-
- if (! process_section_groups (file))
- {
- /* Without loaded section groups we cannot process unwind. */
- do_unwind = 0;
- }
-
- if (process_program_headers (file))
- process_dynamic_section (file);
-
- process_relocs (file);
-
- process_unwind (file);
-
- process_symbol_table (file);
-
- process_syminfo (file);
-
- process_version_sections (file);
-
- process_section_contents (file);
-
- process_notes (file);
-
- process_gnu_liblist (file);
-
- process_arch_specific (file);
-
- if (program_headers)
- {
- free (program_headers);
- program_headers = NULL;
- }
-
- if (section_headers)
- {
- free (section_headers);
- section_headers = NULL;
- }
-
- if (string_table)
- {
- free (string_table);
- string_table = NULL;
- string_table_length = 0;
- }
-
- if (dynamic_strings)
- {
- free (dynamic_strings);
- dynamic_strings = NULL;
- dynamic_strings_length = 0;
- }
-
- if (dynamic_symbols)
- {
- free (dynamic_symbols);
- dynamic_symbols = NULL;
- num_dynamic_syms = 0;
- }
-
- if (dynamic_syminfo)
- {
- free (dynamic_syminfo);
- dynamic_syminfo = NULL;
- }
-
- if (section_headers_groups)
- {
- free (section_headers_groups);
- section_headers_groups = NULL;
- }
-
- if (section_groups)
- {
- struct group_list *g, *next;
-
- for (i = 0; i < group_count; i++)
- {
- for (g = section_groups [i].root; g != NULL; g = next)
- {
- next = g->next;
- free (g);
- }
- }
-
- free (section_groups);
- section_groups = NULL;
- }
-
- free_debug_memory ();
-
- return 0;
-}
-
-/* Process an ELF archive.
- On entry the file is positioned just after the ARMAG string. */
-
-static int
-process_archive (char *file_name, FILE *file)
-{
- struct ar_hdr arhdr;
- size_t got;
- unsigned long size;
- unsigned long index_num = 0;
- unsigned long *index_array = NULL;
- char *sym_table = NULL;
- unsigned long sym_size = 0;
- char *longnames = NULL;
- unsigned long longnames_size = 0;
- size_t file_name_size;
- int ret;
-
- show_name = 1;
-
- got = fread (&arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- return 0;
-
- error (_("%s: failed to read archive header\n"), file_name);
- return 1;
- }
-
- /* See if this is the archive symbol table. */
- if (const_strneq (arhdr.ar_name, "/ ")
- || const_strneq (arhdr.ar_name, "/SYM64/ "))
- {
- size = strtoul (arhdr.ar_size, NULL, 10);
- size = size + (size & 1);
-
- if (do_archive_index)
- {
- unsigned long i;
- /* A buffer used to hold numbers read in from an archive index.
- These are always 4 bytes long and stored in big-endian format. */
-#define SIZEOF_AR_INDEX_NUMBERS 4
- unsigned char integer_buffer[SIZEOF_AR_INDEX_NUMBERS];
- unsigned char * index_buffer;
-
- /* Check the size of the archive index. */
- if (size < SIZEOF_AR_INDEX_NUMBERS)
- {
- error (_("%s: the archive index is empty\n"), file_name);
- return 1;
- }
-
- /* Read the numer of entries in the archive index. */
- got = fread (integer_buffer, 1, sizeof integer_buffer, file);
- if (got != sizeof (integer_buffer))
- {
- error (_("%s: failed to read archive index\n"), file_name);
- return 1;
- }
- index_num = byte_get_big_endian (integer_buffer, sizeof integer_buffer);
- size -= SIZEOF_AR_INDEX_NUMBERS;
-
- /* Read in the archive index. */
- if (size < index_num * SIZEOF_AR_INDEX_NUMBERS)
- {
- error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
- file_name, index_num);
- return 1;
- }
- index_buffer = malloc (index_num * SIZEOF_AR_INDEX_NUMBERS);
- if (index_buffer == NULL)
- {
- error (_("Out of memory whilst trying to read archive symbol index\n"));
- return 1;
- }
- got = fread (index_buffer, SIZEOF_AR_INDEX_NUMBERS, index_num, file);
- if (got != index_num)
- {
- free (index_buffer);
- error (_("%s: failed to read archive index\n"), file_name);
- ret = 1;
- goto out;
- }
- size -= index_num * SIZEOF_AR_INDEX_NUMBERS;
-
- /* Convert the index numbers into the host's numeric format. */
- index_array = malloc (index_num * sizeof (* index_array));
- if (index_array == NULL)
- {
- free (index_buffer);
- error (_("Out of memory whilst trying to convert the archive symbol index\n"));
- return 1;
- }
-
- for (i = 0; i < index_num; i++)
- index_array[i] = byte_get_big_endian ((unsigned char *)(index_buffer + (i * SIZEOF_AR_INDEX_NUMBERS)),
- SIZEOF_AR_INDEX_NUMBERS);
- free (index_buffer);
-
- /* The remaining space in the header is taken up by the symbol table. */
- if (size < 1)
- {
- error (_("%s: the archive has an index but no symbols\n"), file_name);
- ret = 1;
- goto out;
- }
- sym_table = malloc (size);
- sym_size = size;
- if (sym_table == NULL)
- {
- error (_("Out of memory whilst trying to read archive index symbol table\n"));
- ret = 1;
- goto out;
- }
- got = fread (sym_table, 1, size, file);
- if (got != size)
- {
- error (_("%s: failed to read archive index symbol table\n"), file_name);
- ret = 1;
- goto out;
- }
- }
- else
- {
- if (fseek (file, size, SEEK_CUR) != 0)
- {
- error (_("%s: failed to skip archive symbol table\n"), file_name);
- return 1;
- }
- }
-
- got = fread (& arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- {
- ret = 0;
- goto out;
- }
-
- error (_("%s: failed to read archive header following archive index\n"), file_name);
- ret = 1;
- goto out;
- }
- }
- else if (do_archive_index)
- printf (_("%s has no archive index\n"), file_name);
-
- if (const_strneq (arhdr.ar_name, "// "))
- {
- /* This is the archive string table holding long member
- names. */
-
- longnames_size = strtoul (arhdr.ar_size, NULL, 10);
- longnames = malloc (longnames_size);
- if (longnames == NULL)
- {
- error (_("Out of memory reading long symbol names in archive\n"));
- ret = 1;
- goto out;
- }
-
- if (fread (longnames, longnames_size, 1, file) != 1)
- {
- free (longnames);
- error (_("%s: failed to read long symbol name string table\n"), file_name);
- ret = 1;
- goto out;
- }
-
- if ((longnames_size & 1) != 0)
- getc (file);
-
- got = fread (& arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- ret = 0;
- else
- {
- error (_("%s: failed to read archive header following long symbol names\n"), file_name);
- ret = 1;
- }
- goto out;
- }
- }
-
- if (do_archive_index)
- {
- if (sym_table == NULL)
- error (_("%s: unable to dump the index as none was found\n"), file_name);
- else
- {
- unsigned int i, j, k, l;
- char elf_name[16];
- unsigned long current_pos;
-
- printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
- file_name, index_num, sym_size);
- current_pos = ftell (file);
-
- for (i = l = 0; i < index_num; i++)
- {
- if ((i == 0) || ((i > 0) && (index_array[i] != index_array[i - 1])))
- {
- if (fseek (file, index_array[i], SEEK_SET) != 0)
- {
- error (_("%s: failed to seek to next file name\n"), file_name);
- ret = 1;
- goto out;
- }
- got = fread (elf_name, 1, 16, file);
- if (got != 16)
- {
- error (_("%s: failed to read file name\n"), file_name);
- ret = 1;
- goto out;
- }
-
- if (elf_name[0] == '/')
- {
- /* We have a long name. */
- k = j = strtoul (elf_name + 1, NULL, 10);
- while ((j < longnames_size) && (longnames[j] != '/'))
- j++;
- longnames[j] = '\0';
- printf (_("Binary %s contains:\n"), longnames + k);
- longnames[j] = '/';
- }
- else
- {
- j = 0;
- while ((elf_name[j] != '/') && (j < 16))
- j++;
- elf_name[j] = '\0';
- printf(_("Binary %s contains:\n"), elf_name);
- }
- }
- if (l >= sym_size)
- {
- error (_("%s: end of the symbol table reached before the end of the index\n"),
- file_name);
- break;
- }
- printf ("\t%s\n", sym_table + l);
- l += strlen (sym_table + l) + 1;
- }
-
- if (l < sym_size)
- error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
- file_name);
-
- free (index_array);
- index_array = NULL;
- free (sym_table);
- sym_table = NULL;
- if (fseek (file, current_pos, SEEK_SET) != 0)
- {
- error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
- return 1;
- }
- }
-
- if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
- && !do_segments && !do_header && !do_dump && !do_version
- && !do_histogram && !do_debugging && !do_arch && !do_notes
- && !do_section_groups)
- return 0; /* Archive index only. */
- }
-
- file_name_size = strlen (file_name);
- ret = 0;
-
- while (1)
- {
- char *name;
- char *nameend;
- char *namealc;
-
- if (arhdr.ar_name[0] == '/')
- {
- unsigned long off;
-
- off = strtoul (arhdr.ar_name + 1, NULL, 10);
- if (off >= longnames_size)
- {
- error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
- ret = 1;
- break;
- }
-
- name = longnames + off;
- nameend = memchr (name, '/', longnames_size - off);
- }
- else
- {
- name = arhdr.ar_name;
- nameend = memchr (name, '/', 16);
- }
-
- if (nameend == NULL)
- {
- error (_("%s: bad archive file name\n"), file_name);
- ret = 1;
- break;
- }
-
- namealc = malloc (file_name_size + (nameend - name) + 3);
- if (namealc == NULL)
- {
- error (_("Out of memory\n"));
- ret = 1;
- break;
- }
-
- memcpy (namealc, file_name, file_name_size);
- namealc[file_name_size] = '(';
- memcpy (namealc + file_name_size + 1, name, nameend - name);
- namealc[file_name_size + 1 + (nameend - name)] = ')';
- namealc[file_name_size + 2 + (nameend - name)] = '\0';
-
- archive_file_offset = ftell (file);
- archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
-
- ret |= process_object (namealc, file);
-
- free (namealc);
-
- if (fseek (file,
- (archive_file_offset
- + archive_file_size
- + (archive_file_size & 1)),
- SEEK_SET) != 0)
- {
- error (_("%s: failed to seek to next archive header\n"), file_name);
- ret = 1;
- break;
- }
-
- got = fread (&arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- break;
-
- error (_("%s: failed to read archive header\n"), file_name);
- ret = 1;
- break;
- }
- }
-
- out:
- if (index_array != NULL)
- free (index_array);
- if (sym_table != NULL)
- free (sym_table);
- if (longnames != NULL)
- free (longnames);
-
- return ret;
-}
-
-static int
-process_file (char *file_name)
-{
- FILE *file;
- struct stat statbuf;
- char armag[SARMAG];
- int ret;
-
- if (stat (file_name, &statbuf) < 0)
- {
- if (errno == ENOENT)
- error (_("'%s': No such file\n"), file_name);
- else
- error (_("Could not locate '%s'. System error message: %s\n"),
- file_name, strerror (errno));
- return 1;
- }
-
- if (! S_ISREG (statbuf.st_mode))
- {
- error (_("'%s' is not an ordinary file\n"), file_name);
- return 1;
- }
-
- file = fopen (file_name, "rb");
- if (file == NULL)
- {
- error (_("Input file '%s' is not readable.\n"), file_name);
- return 1;
- }
-
- if (fread (armag, SARMAG, 1, file) != 1)
- {
- error (_("%s: Failed to read file's magic number\n"), file_name);
- fclose (file);
- return 1;
- }
-
- if (memcmp (armag, ARMAG, SARMAG) == 0)
- ret = process_archive (file_name, file);
- else
- {
- if (do_archive_index)
- error (_("File %s is not an archive so its index cannot be displayed.\n"),
- file_name);
-
- rewind (file);
- archive_file_size = archive_file_offset = 0;
- ret = process_object (file_name, file);
- }
-
- fclose (file);
-
- return ret;
-}
-
-#ifdef SUPPORT_DISASSEMBLY
-/* Needed by the i386 disassembler. For extra credit, someone could
- fix this so that we insert symbolic addresses here, esp for GOT/PLT
- symbols. */
-
-void
-print_address (unsigned int addr, FILE *outfile)
-{
- fprintf (outfile,"0x%8.8x", addr);
-}
-
-/* Needed by the i386 disassembler. */
-void
-db_task_printsym (unsigned int addr)
-{
- print_address (addr, stderr);
-}
-#endif
-
-int
-main (int argc, char **argv)
-{
- int err;
-
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
- setlocale (LC_MESSAGES, "");
-#endif
-#if defined (HAVE_SETLOCALE)
- setlocale (LC_CTYPE, "");
-#endif
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- expandargv (&argc, &argv);
-
- parse_args (argc, argv);
-
- if (num_dump_sects > 0)
- {
- /* Make a copy of the dump_sects array. */
- cmdline_dump_sects = malloc (num_dump_sects * sizeof (* dump_sects));
- if (cmdline_dump_sects == NULL)
- error (_("Out of memory allocating dump request table.\n"));
- else
- {
- memcpy (cmdline_dump_sects, dump_sects,
- num_dump_sects * sizeof (* dump_sects));
- num_cmdline_dump_sects = num_dump_sects;
- }
- }
-
- if (optind < (argc - 1))
- show_name = 1;
-
- err = 0;
- while (optind < argc)
- err |= process_file (argv[optind++]);
-
- if (dump_sects != NULL)
- free (dump_sects);
- if (cmdline_dump_sects != NULL)
- free (cmdline_dump_sects);
-
- return err;
-}
diff --git a/binutils/resrc.c b/binutils/resrc.c
deleted file mode 100644
index fcd15c70f86..00000000000
--- a/binutils/resrc.c
+++ /dev/null
@@ -1,3345 +0,0 @@
-/* resrc.c -- read and write Windows rc files.
- Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008
- Free Software Foundation, Inc.
- Written by Ian Lance Taylor, Cygnus Support.
- Rewritten by Kai Tietz, Onevision.
-
- This file is part of GNU Binutils.
-
- 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 contains functions that read and write Windows rc files.
- These are text files that represent resources. */
-
-#include "sysdep.h"
-#include "bfd.h"
-#include "bucomm.h"
-#include "libiberty.h"
-#include "safe-ctype.h"
-#include "windres.h"
-
-#include <assert.h>
-#include <errno.h>
-#include <sys/stat.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#else /* ! HAVE_SYS_WAIT_H */
-#if ! defined (_WIN32) || defined (__CYGWIN__)
-#ifndef WIFEXITED
-#define WIFEXITED(w) (((w)&0377) == 0)
-#endif
-#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
-#endif
-#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0177)
-#endif
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) >> 8) & 0377)
-#endif
-#else /* defined (_WIN32) && ! defined (__CYGWIN__) */
-#ifndef WIFEXITED
-#define WIFEXITED(w) (((w) & 0xff) == 0)
-#endif
-#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w) & 0xff) != 0 && ((w) & 0xff) != 0x7f)
-#endif
-#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0x7f)
-#endif
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) & 0xff00) >> 8)
-#endif
-#endif /* defined (_WIN32) && ! defined (__CYGWIN__) */
-#endif /* ! HAVE_SYS_WAIT_H */
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
-
-#if defined (_WIN32) && ! defined (__CYGWIN__)
-#define popen _popen
-#define pclose _pclose
-#endif
-
-/* The default preprocessor. */
-
-#define DEFAULT_PREPROCESSOR "gcc -E -xc -DRC_INVOKED"
-
-/* We read the directory entries in a cursor or icon file into
- instances of this structure. */
-
-struct icondir
-{
- /* Width of image. */
- bfd_byte width;
- /* Height of image. */
- bfd_byte height;
- /* Number of colors in image. */
- bfd_byte colorcount;
- union
- {
- struct
- {
- /* Color planes. */
- unsigned short planes;
- /* Bits per pixel. */
- unsigned short bits;
- } icon;
- struct
- {
- /* X coordinate of hotspot. */
- unsigned short xhotspot;
- /* Y coordinate of hotspot. */
- unsigned short yhotspot;
- } cursor;
- } u;
- /* Bytes in image. */
- unsigned long bytes;
- /* File offset of image. */
- unsigned long offset;
-};
-
-/* The name of the rc file we are reading. */
-
-char *rc_filename;
-
-/* The line number in the rc file. */
-
-int rc_lineno;
-
-/* The pipe we are reading from, so that we can close it if we exit. */
-
-FILE *cpp_pipe;
-
-/* The temporary file used if we're not using popen, so we can delete it
- if we exit. */
-
-static char *cpp_temp_file;
-
-/* Input stream is either a file or a pipe. */
-
-static enum {ISTREAM_PIPE, ISTREAM_FILE} istream_type;
-
-/* As we read the rc file, we attach information to this structure. */
-
-static rc_res_directory *resources;
-
-/* The number of cursor resources we have written out. */
-
-static int cursors;
-
-/* The number of font resources we have written out. */
-
-static int fonts;
-
-/* Font directory information. */
-
-rc_fontdir *fontdirs;
-
-/* Resource info to use for fontdirs. */
-
-rc_res_res_info fontdirs_resinfo;
-
-/* The number of icon resources we have written out. */
-
-static int icons;
-
-/* The windres target bfd . */
-
-static windres_bfd wrtarget =
-{
- (bfd *) NULL, (asection *) NULL, WR_KIND_TARGET
-};
-
-/* Local functions for rcdata based resource definitions. */
-
-static void define_font_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static void define_icon_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static void define_bitmap_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static void define_cursor_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static void define_fontdir_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static void define_messagetable_rcdata (rc_res_id, const rc_res_res_info *,
- rc_rcdata_item *);
-static rc_uint_type rcdata_copy (const rc_rcdata_item *, bfd_byte *);
-static bfd_byte *rcdata_render_as_buffer (const rc_rcdata_item *, rc_uint_type *);
-
-static int run_cmd (char *, const char *);
-static FILE *open_input_stream (char *);
-static FILE *look_for_default
- (char *, const char *, int, const char *, const char *);
-static void close_input_stream (void);
-static void unexpected_eof (const char *);
-static int get_word (FILE *, const char *);
-static unsigned long get_long (FILE *, const char *);
-static void get_data (FILE *, bfd_byte *, rc_uint_type, const char *);
-static void define_fontdirs (void);
-
-/* Run `cmd' and redirect the output to `redir'. */
-
-static int
-run_cmd (char *cmd, const char *redir)
-{
- char *s;
- int pid, wait_status, retcode;
- int i;
- const char **argv;
- char *errmsg_fmt, *errmsg_arg;
- char *temp_base = choose_temp_base ();
- int in_quote;
- char sep;
- int redir_handle = -1;
- int stdout_save = -1;
-
- /* Count the args. */
- i = 0;
-
- for (s = cmd; *s; s++)
- if (*s == ' ')
- i++;
-
- i++;
- argv = alloca (sizeof (char *) * (i + 3));
- i = 0;
- s = cmd;
-
- while (1)
- {
- while (*s == ' ' && *s != 0)
- s++;
-
- if (*s == 0)
- break;
-
- in_quote = (*s == '\'' || *s == '"');
- sep = (in_quote) ? *s++ : ' ';
- argv[i++] = s;
-
- while (*s != sep && *s != 0)
- s++;
-
- if (*s == 0)
- break;
-
- *s++ = 0;
-
- if (in_quote)
- s++;
- }
- argv[i++] = NULL;
-
- /* Setup the redirection. We can't use the usual fork/exec and redirect
- since we may be running on non-POSIX Windows host. */
-
- fflush (stdout);
- fflush (stderr);
-
- /* Open temporary output file. */
- redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT, 0666);
- if (redir_handle == -1)
- fatal (_("can't open temporary file `%s': %s"), redir,
- strerror (errno));
-
- /* Duplicate the stdout file handle so it can be restored later. */
- stdout_save = dup (STDOUT_FILENO);
- if (stdout_save == -1)
- fatal (_("can't redirect stdout: `%s': %s"), redir, strerror (errno));
-
- /* Redirect stdout to our output file. */
- dup2 (redir_handle, STDOUT_FILENO);
-
- pid = pexecute (argv[0], (char * const *) argv, program_name, temp_base,
- &errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH);
-
- /* Restore stdout to its previous setting. */
- dup2 (stdout_save, STDOUT_FILENO);
-
- /* Close response file. */
- close (redir_handle);
-
- if (pid == -1)
- {
- fatal (_("%s %s: %s"), errmsg_fmt, errmsg_arg, strerror (errno));
- return 1;
- }
-
- retcode = 0;
- pid = pwait (pid, &wait_status, 0);
-
- if (pid == -1)
- {
- fatal (_("wait: %s"), strerror (errno));
- retcode = 1;
- }
- else if (WIFSIGNALED (wait_status))
- {
- fatal (_("subprocess got fatal signal %d"), WTERMSIG (wait_status));
- retcode = 1;
- }
- else if (WIFEXITED (wait_status))
- {
- if (WEXITSTATUS (wait_status) != 0)
- {
- fatal (_("%s exited with status %d"), cmd,
- WEXITSTATUS (wait_status));
- retcode = 1;
- }
- }
- else
- retcode = 1;
-
- return retcode;
-}
-
-static FILE *
-open_input_stream (char *cmd)
-{
- if (istream_type == ISTREAM_FILE)
- {
- char *fileprefix;
-
- fileprefix = choose_temp_base ();
- cpp_temp_file = (char *) xmalloc (strlen (fileprefix) + 5);
- sprintf (cpp_temp_file, "%s.irc", fileprefix);
- free (fileprefix);
-
- if (run_cmd (cmd, cpp_temp_file))
- fatal (_("can't execute `%s': %s"), cmd, strerror (errno));
-
- cpp_pipe = fopen (cpp_temp_file, FOPEN_RT);;
- if (cpp_pipe == NULL)
- fatal (_("can't open temporary file `%s': %s"),
- cpp_temp_file, strerror (errno));
-
- if (verbose)
- fprintf (stderr,
- _("Using temporary file `%s' to read preprocessor output\n"),
- cpp_temp_file);
- }
- else
- {
- cpp_pipe = popen (cmd, FOPEN_RT);
- if (cpp_pipe == NULL)
- fatal (_("can't popen `%s': %s"), cmd, strerror (errno));
- if (verbose)
- fprintf (stderr, _("Using popen to read preprocessor output\n"));
- }
-
- xatexit (close_input_stream);
- return cpp_pipe;
-}
-
-/* Determine if FILENAME contains special characters that
- can cause problems unless the entire filename is quoted. */
-
-static int
-filename_need_quotes (const char *filename)
-{
- if (filename == NULL || (filename[0] == '-' && filename[1] == 0))
- return 0;
-
- while (*filename != 0)
- {
- switch (*filename)
- {
- case '&':
- case ' ':
- case '<':
- case '>':
- case '|':
- case '%':
- return 1;
- }
- ++filename;
- }
- return 0;
-}
-
-/* Look for the preprocessor program. */
-
-static FILE *
-look_for_default (char *cmd, const char *prefix, int end_prefix,
- const char *preprocargs, const char *filename)
-{
- char *space;
- int found;
- struct stat s;
- const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
-
- strcpy (cmd, prefix);
-
- sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR);
- space = strchr (cmd + end_prefix, ' ');
- if (space)
- *space = 0;
-
- if (
-#if defined (__DJGPP__) || defined (__CYGWIN__) || defined (_WIN32)
- strchr (cmd, '\\') ||
-#endif
- strchr (cmd, '/'))
- {
- found = (stat (cmd, &s) == 0
-#ifdef HAVE_EXECUTABLE_SUFFIX
- || stat (strcat (cmd, EXECUTABLE_SUFFIX), &s) == 0
-#endif
- );
-
- if (! found)
- {
- if (verbose)
- fprintf (stderr, _("Tried `%s'\n"), cmd);
- return NULL;
- }
- }
-
- strcpy (cmd, prefix);
-
- sprintf (cmd + end_prefix, "%s %s %s%s%s",
- DEFAULT_PREPROCESSOR, preprocargs, fnquotes, filename, fnquotes);
-
- if (verbose)
- fprintf (stderr, _("Using `%s'\n"), cmd);
-
- cpp_pipe = open_input_stream (cmd);
- return cpp_pipe;
-}
-
-/* Read an rc file. */
-
-rc_res_directory *
-read_rc_file (const char *filename, const char *preprocessor,
- const char *preprocargs, int language, int use_temp_file)
-{
- char *cmd;
- const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
-
- if (filename == NULL)
- filename = "-";
- /* Setup the default resource import path taken from input file. */
- else if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
- {
- char *edit, *dir;
-
- if (filename[0] == '/'
- || filename[0] == '\\'
- || filename[1] == ':')
- /* Absolute path. */
- edit = dir = xstrdup (filename);
- else
- {
- /* Relative path. */
- edit = dir = xmalloc (strlen (filename) + 3);
- sprintf (dir, "./%s", filename);
- }
-
- /* Walk dir backwards stopping at the first directory separator. */
- edit += strlen (dir);
- while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
- {
- --edit;
- edit[0] = 0;
- }
-
- /* Cut off trailing slash. */
- --edit;
- edit[0] = 0;
-
- /* Convert all back slashes to forward slashes. */
- while ((edit = strchr (dir, '\\')) != NULL)
- *edit = '/';
-
- windres_add_include_dir (dir);
- }
-
- istream_type = (use_temp_file) ? ISTREAM_FILE : ISTREAM_PIPE;
-
- if (preprocargs == NULL)
- preprocargs = "";
-
- if (preprocessor)
- {
- cmd = xmalloc (strlen (preprocessor)
- + strlen (preprocargs)
- + strlen (filename)
- + strlen (fnquotes) * 2
- + 10);
- sprintf (cmd, "%s %s %s%s%s", preprocessor, preprocargs,
- fnquotes, filename, fnquotes);
-
- cpp_pipe = open_input_stream (cmd);
- }
- else
- {
- char *dash, *slash, *cp;
-
- preprocessor = DEFAULT_PREPROCESSOR;
-
- cmd = xmalloc (strlen (program_name)
- + strlen (preprocessor)
- + strlen (preprocargs)
- + strlen (filename)
- + strlen (fnquotes) * 2
-#ifdef HAVE_EXECUTABLE_SUFFIX
- + strlen (EXECUTABLE_SUFFIX)
-#endif
- + 10);
-
-
- dash = slash = 0;
- for (cp = program_name; *cp; cp++)
- {
- if (*cp == '-')
- dash = cp;
- if (
-#if defined (__DJGPP__) || defined (__CYGWIN__) || defined(_WIN32)
- *cp == ':' || *cp == '\\' ||
-#endif
- *cp == '/')
- {
- slash = cp;
- dash = 0;
- }
- }
-
- cpp_pipe = 0;
-
- if (dash)
- {
- /* First, try looking for a prefixed gcc in the windres
- directory, with the same prefix as windres */
-
- cpp_pipe = look_for_default (cmd, program_name, dash - program_name + 1,
- preprocargs, filename);
- }
-
- if (slash && ! cpp_pipe)
- {
- /* Next, try looking for a gcc in the same directory as
- that windres */
-
- cpp_pipe = look_for_default (cmd, program_name, slash - program_name + 1,
- preprocargs, filename);
- }
-
- if (! cpp_pipe)
- {
- /* Sigh, try the default */
-
- cpp_pipe = look_for_default (cmd, "", 0, preprocargs, filename);
- }
-
- }
-
- free (cmd);
-
- rc_filename = xstrdup (filename);
- rc_lineno = 1;
- if (language != -1)
- rcparse_set_language (language);
- yyparse ();
- rcparse_discard_strings ();
-
- close_input_stream ();
-
- if (fontdirs != NULL)
- define_fontdirs ();
-
- free (rc_filename);
- rc_filename = NULL;
-
- return resources;
-}
-
-/* Close the input stream if it is open. */
-
-static void
-close_input_stream (void)
-{
- if (istream_type == ISTREAM_FILE)
- {
- if (cpp_pipe != NULL)
- fclose (cpp_pipe);
-
- if (cpp_temp_file != NULL)
- {
- int errno_save = errno;
-
- unlink (cpp_temp_file);
- errno = errno_save;
- free (cpp_temp_file);
- }
- }
- else
- {
- if (cpp_pipe != NULL)
- {
- int err;
- err = pclose (cpp_pipe);
- /* We are reading from a pipe, therefore we don't
- know if cpp failed or succeeded until pclose. */
- if (err != 0 || errno == ECHILD)
- {
- /* Since this is also run via xatexit, safeguard. */
- cpp_pipe = NULL;
- cpp_temp_file = NULL;
- fatal (_("preprocessing failed."));
- }
- }
- }
-
- /* Since this is also run via xatexit, safeguard. */
- cpp_pipe = NULL;
- cpp_temp_file = NULL;
-}
-
-/* Report an error while reading an rc file. */
-
-void
-yyerror (const char *msg)
-{
- fatal ("%s:%d: %s", rc_filename, rc_lineno, msg);
-}
-
-/* Issue a warning while reading an rc file. */
-
-void
-rcparse_warning (const char *msg)
-{
- fprintf (stderr, _("%s:%d: %s\n"), rc_filename, rc_lineno, msg);
-}
-
-/* Die if we get an unexpected end of file. */
-
-static void
-unexpected_eof (const char *msg)
-{
- fatal (_("%s: unexpected EOF"), msg);
-}
-
-/* Read a 16 bit word from a file. The data is assumed to be little
- endian. */
-
-static int
-get_word (FILE *e, const char *msg)
-{
- int b1, b2;
-
- b1 = getc (e);
- b2 = getc (e);
- if (feof (e))
- unexpected_eof (msg);
- return ((b2 & 0xff) << 8) | (b1 & 0xff);
-}
-
-/* Read a 32 bit word from a file. The data is assumed to be little
- endian. */
-
-static unsigned long
-get_long (FILE *e, const char *msg)
-{
- int b1, b2, b3, b4;
-
- b1 = getc (e);
- b2 = getc (e);
- b3 = getc (e);
- b4 = getc (e);
- if (feof (e))
- unexpected_eof (msg);
- return (((((((b4 & 0xff) << 8)
- | (b3 & 0xff)) << 8)
- | (b2 & 0xff)) << 8)
- | (b1 & 0xff));
-}
-
-/* Read data from a file. This is a wrapper to do error checking. */
-
-static void
-get_data (FILE *e, bfd_byte *p, rc_uint_type c, const char *msg)
-{
- rc_uint_type got; // $$$d
-
- got = (rc_uint_type) fread (p, 1, c, e);
- if (got == c)
- return;
-
- fatal (_("%s: read of %lu returned %lu"),
- msg, (unsigned long) c, (unsigned long) got);
-}
-
-/* Define an accelerator resource. */
-
-void
-define_accelerator (rc_res_id id, const rc_res_res_info *resinfo,
- rc_accelerator *data)
-{
- rc_res_resource *r;
-
- r = define_standard_resource (&resources, RT_ACCELERATOR, id,
- resinfo->language, 0);
- r->type = RES_TYPE_ACCELERATOR;
- r->u.acc = data;
- r->res_info = *resinfo;
-}
-
-/* Define a bitmap resource. Bitmap data is stored in a file. The
- first 14 bytes of the file are a standard header, which is not
- included in the resource data. */
-
-#define BITMAP_SKIP (14)
-
-void
-define_bitmap (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- FILE *e;
- char *real_filename;
- struct stat s;
- bfd_byte *data;
- rc_uint_type i;
- rc_res_resource *r;
-
- e = open_file_search (filename, FOPEN_RB, "bitmap file", &real_filename);
-
- if (stat (real_filename, &s) < 0)
- fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
- strerror (errno));
-
- data = (bfd_byte *) res_alloc (s.st_size - BITMAP_SKIP);
-
- for (i = 0; i < BITMAP_SKIP; i++)
- getc (e);
-
- get_data (e, data, s.st_size - BITMAP_SKIP, real_filename);
-
- fclose (e);
- free (real_filename);
-
- r = define_standard_resource (&resources, RT_BITMAP, id,
- resinfo->language, 0);
-
- r->type = RES_TYPE_BITMAP;
- r->u.data.length = s.st_size - BITMAP_SKIP;
- r->u.data.data = data;
- r->res_info = *resinfo;
-}
-
-/* Define a cursor resource. A cursor file may contain a set of
- bitmaps, each representing the same cursor at various different
- resolutions. They each get written out with a different ID. The
- real cursor resource is then a group resource which can be used to
- select one of the actual cursors. */
-
-void
-define_cursor (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- FILE *e;
- char *real_filename;
- int type, count, i;
- struct icondir *icondirs;
- int first_cursor;
- rc_res_resource *r;
- rc_group_cursor *first, **pp;
-
- e = open_file_search (filename, FOPEN_RB, "cursor file", &real_filename);
-
- /* A cursor file is basically an icon file. The start of the file
- is a three word structure. The first word is ignored. The
- second word is the type of data. The third word is the number of
- entries. */
-
- get_word (e, real_filename);
- type = get_word (e, real_filename);
- count = get_word (e, real_filename);
- if (type != 2)
- fatal (_("cursor file `%s' does not contain cursor data"), real_filename);
-
- /* Read in the icon directory entries. */
-
- icondirs = (struct icondir *) xmalloc (count * sizeof *icondirs);
-
- for (i = 0; i < count; i++)
- {
- icondirs[i].width = getc (e);
- icondirs[i].height = getc (e);
- icondirs[i].colorcount = getc (e);
- getc (e);
- icondirs[i].u.cursor.xhotspot = get_word (e, real_filename);
- icondirs[i].u.cursor.yhotspot = get_word (e, real_filename);
- icondirs[i].bytes = get_long (e, real_filename);
- icondirs[i].offset = get_long (e, real_filename);
-
- if (feof (e))
- unexpected_eof (real_filename);
- }
-
- /* Define each cursor as a unique resource. */
-
- first_cursor = cursors;
-
- for (i = 0; i < count; i++)
- {
- bfd_byte *data;
- rc_res_id name;
- rc_cursor *c;
-
- if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
- fatal (_("%s: fseek to %lu failed: %s"), real_filename,
- icondirs[i].offset, strerror (errno));
-
- data = (bfd_byte *) res_alloc (icondirs[i].bytes);
-
- get_data (e, data, icondirs[i].bytes, real_filename);
-
- c = (rc_cursor *) res_alloc (sizeof (rc_cursor));
- c->xhotspot = icondirs[i].u.cursor.xhotspot;
- c->yhotspot = icondirs[i].u.cursor.yhotspot;
- c->length = icondirs[i].bytes;
- c->data = data;
-
- ++cursors;
-
- name.named = 0;
- name.u.id = cursors;
-
- r = define_standard_resource (&resources, RT_CURSOR, name,
- resinfo->language, 0);
- r->type = RES_TYPE_CURSOR;
- r->u.cursor = c;
- r->res_info = *resinfo;
- }
-
- fclose (e);
- free (real_filename);
-
- /* Define a cursor group resource. */
-
- first = NULL;
- pp = &first;
- for (i = 0; i < count; i++)
- {
- rc_group_cursor *cg;
-
- cg = (rc_group_cursor *) res_alloc (sizeof (rc_group_cursor));
- cg->next = NULL;
- cg->width = icondirs[i].width;
- cg->height = 2 * icondirs[i].height;
-
- /* FIXME: What should these be set to? */
- cg->planes = 1;
- cg->bits = 1;
-
- cg->bytes = icondirs[i].bytes + 4;
- cg->index = first_cursor + i + 1;
-
- *pp = cg;
- pp = &(*pp)->next;
- }
-
- free (icondirs);
-
- r = define_standard_resource (&resources, RT_GROUP_CURSOR, id,
- resinfo->language, 0);
- r->type = RES_TYPE_GROUP_CURSOR;
- r->u.group_cursor = first;
- r->res_info = *resinfo;
-}
-
-/* Define a dialog resource. */
-
-void
-define_dialog (rc_res_id id, const rc_res_res_info *resinfo,
- const rc_dialog *dialog)
-{
- rc_dialog *copy;
- rc_res_resource *r;
-
- copy = (rc_dialog *) res_alloc (sizeof *copy);
- *copy = *dialog;
-
- r = define_standard_resource (&resources, RT_DIALOG, id,
- resinfo->language, 0);
- r->type = RES_TYPE_DIALOG;
- r->u.dialog = copy;
- r->res_info = *resinfo;
-}
-
-/* Define a dialog control. This does not define a resource, but
- merely allocates and fills in a structure. */
-
-rc_dialog_control *
-define_control (const rc_res_id iid, rc_uint_type id, rc_uint_type x,
- rc_uint_type y, rc_uint_type width, rc_uint_type height,
- const rc_res_id class, rc_uint_type style,
- rc_uint_type exstyle)
-{
- rc_dialog_control *n;
-
- n = (rc_dialog_control *) res_alloc (sizeof (rc_dialog_control));
- n->next = NULL;
- n->id = id;
- n->style = style;
- n->exstyle = exstyle;
- n->x = x;
- n->y = y;
- n->width = width;
- n->height = height;
- n->class = class;
- n->text = iid;
- n->data = NULL;
- n->help = 0;
-
- return n;
-}
-
-rc_dialog_control *
-define_icon_control (rc_res_id iid, rc_uint_type id, rc_uint_type x,
- rc_uint_type y, rc_uint_type style,
- rc_uint_type exstyle, rc_uint_type help,
- rc_rcdata_item *data, rc_dialog_ex *ex)
-{
- rc_dialog_control *n;
- rc_res_id tid;
- rc_res_id cid;
-
- if (style == 0)
- style = SS_ICON | WS_CHILD | WS_VISIBLE;
- res_string_to_id (&tid, "");
- cid.named = 0;
- cid.u.id = CTL_STATIC;
- n = define_control (tid, id, x, y, 0, 0, cid, style, exstyle);
- n->text = iid;
- if (help && ! ex)
- rcparse_warning (_("help ID requires DIALOGEX"));
- if (data && ! ex)
- rcparse_warning (_("control data requires DIALOGEX"));
- n->help = help;
- n->data = data;
-
- return n;
-}
-
-/* Define a font resource. */
-
-void
-define_font (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- FILE *e;
- char *real_filename;
- struct stat s;
- bfd_byte *data;
- rc_res_resource *r;
- long offset;
- long fontdatalength;
- bfd_byte *fontdata;
- rc_fontdir *fd;
- const char *device, *face;
- rc_fontdir **pp;
-
- e = open_file_search (filename, FOPEN_RB, "font file", &real_filename);
-
- if (stat (real_filename, &s) < 0)
- fatal (_("stat failed on font file `%s': %s"), real_filename,
- strerror (errno));
-
- data = (bfd_byte *) res_alloc (s.st_size);
-
- get_data (e, data, s.st_size, real_filename);
-
- fclose (e);
- free (real_filename);
-
- r = define_standard_resource (&resources, RT_FONT, id,
- resinfo->language, 0);
-
- r->type = RES_TYPE_FONT;
- r->u.data.length = s.st_size;
- r->u.data.data = data;
- r->res_info = *resinfo;
-
- /* For each font resource, we must add an entry in the FONTDIR
- resource. The FONTDIR resource includes some strings in the font
- file. To find them, we have to do some magic on the data we have
- read. */
-
- offset = ((((((data[47] << 8)
- | data[46]) << 8)
- | data[45]) << 8)
- | data[44]);
- if (offset > 0 && offset < s.st_size)
- device = (char *) data + offset;
- else
- device = "";
-
- offset = ((((((data[51] << 8)
- | data[50]) << 8)
- | data[49]) << 8)
- | data[48]);
- if (offset > 0 && offset < s.st_size)
- face = (char *) data + offset;
- else
- face = "";
-
- ++fonts;
-
- fontdatalength = 58 + strlen (device) + strlen (face);
- fontdata = (bfd_byte *) res_alloc (fontdatalength);
- memcpy (fontdata, data, 56);
- strcpy ((char *) fontdata + 56, device);
- strcpy ((char *) fontdata + 57 + strlen (device), face);
-
- fd = (rc_fontdir *) res_alloc (sizeof (rc_fontdir));
- fd->next = NULL;
- fd->index = fonts;
- fd->length = fontdatalength;
- fd->data = fontdata;
-
- for (pp = &fontdirs; *pp != NULL; pp = &(*pp)->next)
- ;
- *pp = fd;
-
- /* For the single fontdirs resource, we always use the resource
- information of the last font. I don't know what else to do. */
- fontdirs_resinfo = *resinfo;
-}
-
-static void
-define_font_rcdata (rc_res_id id,const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- r = define_standard_resource (&resources, RT_FONT, id,
- resinfo->language, 0);
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- r->type = RES_TYPE_FONT;
- r->u.data.length = len_data;
- r->u.data.data = pb_data;
- r->res_info = *resinfo;
-}
-
-/* Define the fontdirs resource. This is called after the entire rc
- file has been parsed, if any font resources were seen. */
-
-static void
-define_fontdirs (void)
-{
- rc_res_resource *r;
- rc_res_id id;
-
- id.named = 0;
- id.u.id = 1;
-
- r = define_standard_resource (&resources, RT_FONTDIR, id, 0x409, 0);
-
- r->type = RES_TYPE_FONTDIR;
- r->u.fontdir = fontdirs;
- r->res_info = fontdirs_resinfo;
-}
-
-static bfd_byte *
-rcdata_render_as_buffer (const rc_rcdata_item *data, rc_uint_type *plen)
-{
- const rc_rcdata_item *d;
- bfd_byte *ret = NULL, *pret;
- rc_uint_type len = 0;
-
- for (d = data; d != NULL; d = d->next)
- len += rcdata_copy (d, NULL);
- if (len != 0)
- {
- ret = pret = (bfd_byte *) res_alloc (len);
- for (d = data; d != NULL; d = d->next)
- pret += rcdata_copy (d, pret);
- }
- if (plen)
- *plen = len;
- return ret;
-}
-
-static void
-define_fontdir_rcdata (rc_res_id id,const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_fontdir *fd, *fd_first, *fd_cur;
- rc_uint_type len_data;
- bfd_byte *pb_data;
- rc_uint_type c;
-
- fd_cur = fd_first = NULL;
- r = define_standard_resource (&resources, RT_FONTDIR, id, 0x409, 0);
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- if (pb_data)
- {
- rc_uint_type off = 2;
- c = windres_get_16 (&wrtarget, pb_data, len_data);
- for (; c > 0; c--)
- {
- size_t len;
- rc_uint_type safe_pos = off;
- const struct bin_fontdir_item *bfi;
-
- bfi = (const struct bin_fontdir_item *) pb_data + off;
- fd = (rc_fontdir *) res_alloc (sizeof (rc_fontdir));
- fd->index = windres_get_16 (&wrtarget, bfi->index, len_data - off);
- fd->data = pb_data + off;
- off += 56;
- len = strlen ((char *) bfi->device_name) + 1;
- off += (rc_uint_type) len;
- off += (rc_uint_type) strlen ((char *) bfi->device_name + len) + 1;
- fd->length = (off - safe_pos);
- fd->next = NULL;
- if (fd_first == NULL)
- fd_first = fd;
- else
- fd_cur->next = fd;
- fd_cur = fd;
- }
- }
- r->type = RES_TYPE_FONTDIR;
- r->u.fontdir = fd_first;
- r->res_info = *resinfo;
-}
-
-static void define_messagetable_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- r = define_standard_resource (&resources, RT_MESSAGETABLE, id, resinfo->language, 0);
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
- r->type = RES_TYPE_MESSAGETABLE;
- r->u.data.length = len_data;
- r->u.data.data = pb_data;
- r->res_info = *resinfo;
-}
-
-/* Define an icon resource. An icon file may contain a set of
- bitmaps, each representing the same icon at various different
- resolutions. They each get written out with a different ID. The
- real icon resource is then a group resource which can be used to
- select one of the actual icon bitmaps. */
-
-void
-define_icon (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- FILE *e;
- char *real_filename;
- int type, count, i;
- struct icondir *icondirs;
- int first_icon;
- rc_res_resource *r;
- rc_group_icon *first, **pp;
-
- e = open_file_search (filename, FOPEN_RB, "icon file", &real_filename);
-
- /* The start of an icon file is a three word structure. The first
- word is ignored. The second word is the type of data. The third
- word is the number of entries. */
-
- get_word (e, real_filename);
- type = get_word (e, real_filename);
- count = get_word (e, real_filename);
- if (type != 1)
- fatal (_("icon file `%s' does not contain icon data"), real_filename);
-
- /* Read in the icon directory entries. */
-
- icondirs = (struct icondir *) xmalloc (count * sizeof *icondirs);
-
- for (i = 0; i < count; i++)
- {
- icondirs[i].width = getc (e);
- icondirs[i].height = getc (e);
- icondirs[i].colorcount = getc (e);
- getc (e);
- icondirs[i].u.icon.planes = get_word (e, real_filename);
- icondirs[i].u.icon.bits = get_word (e, real_filename);
- icondirs[i].bytes = get_long (e, real_filename);
- icondirs[i].offset = get_long (e, real_filename);
-
- if (feof (e))
- unexpected_eof (real_filename);
- }
-
- /* Define each icon as a unique resource. */
-
- first_icon = icons;
-
- for (i = 0; i < count; i++)
- {
- bfd_byte *data;
- rc_res_id name;
-
- if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
- fatal (_("%s: fseek to %lu failed: %s"), real_filename,
- icondirs[i].offset, strerror (errno));
-
- data = (bfd_byte *) res_alloc (icondirs[i].bytes);
-
- get_data (e, data, icondirs[i].bytes, real_filename);
-
- ++icons;
-
- name.named = 0;
- name.u.id = icons;
-
- r = define_standard_resource (&resources, RT_ICON, name,
- resinfo->language, 0);
- r->type = RES_TYPE_ICON;
- r->u.data.length = icondirs[i].bytes;
- r->u.data.data = data;
- r->res_info = *resinfo;
- }
-
- fclose (e);
- free (real_filename);
-
- /* Define an icon group resource. */
-
- first = NULL;
- pp = &first;
- for (i = 0; i < count; i++)
- {
- rc_group_icon *cg;
-
- /* For some reason, at least in some files the planes and bits
- are zero. We instead set them from the color. This is
- copied from rcl. */
-
- cg = (rc_group_icon *) res_alloc (sizeof (rc_group_icon));
- cg->next = NULL;
- cg->width = icondirs[i].width;
- cg->height = icondirs[i].height;
- cg->colors = icondirs[i].colorcount;
-
- if (icondirs[i].u.icon.planes)
- cg->planes = icondirs[i].u.icon.planes;
- else
- cg->planes = 1;
-
- if (icondirs[i].u.icon.bits)
- cg->bits = icondirs[i].u.icon.bits;
- else
- {
- cg->bits = 0;
-
- while ((1L << cg->bits) < cg->colors)
- ++cg->bits;
- }
-
- cg->bytes = icondirs[i].bytes;
- cg->index = first_icon + i + 1;
-
- *pp = cg;
- pp = &(*pp)->next;
- }
-
- free (icondirs);
-
- r = define_standard_resource (&resources, RT_GROUP_ICON, id,
- resinfo->language, 0);
- r->type = RES_TYPE_GROUP_ICON;
- r->u.group_icon = first;
- r->res_info = *resinfo;
-}
-
-static void
-define_group_icon_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_group_icon *cg, *first, *cur;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- cur = NULL;
- first = NULL;
-
- while (len_data >= 6)
- {
- int c, i;
- unsigned short type;
- type = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
- if (type != 1)
- fatal (_("unexpected group icon type %d"), type);
- c = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
- len_data -= 6;
- pb_data += 6;
-
- for (i = 0; i < c; i++)
- {
- if (len_data < 14)
- fatal ("too small group icon rcdata");
- cg = (rc_group_icon *) res_alloc (sizeof (rc_group_icon));
- cg->next = NULL;
- cg->width = pb_data[0];
- cg->height = pb_data[1];
- cg->colors = pb_data[2];
- cg->planes = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
- cg->bits = windres_get_16 (&wrtarget, pb_data + 6, len_data - 6);
- cg->bytes = windres_get_32 (&wrtarget, pb_data + 8, len_data - 8);
- cg->index = windres_get_16 (&wrtarget, pb_data + 12, len_data - 12);
- if (! first)
- first = cg;
- else
- cur->next = cg;
- cur = cg;
- pb_data += 14;
- len_data -= 14;
- }
- }
- r = define_standard_resource (&resources, RT_GROUP_ICON, id,
- resinfo->language, 0);
- r->type = RES_TYPE_GROUP_ICON;
- r->u.group_icon = first;
- r->res_info = *resinfo;
-}
-
-static void
-define_group_cursor_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_group_cursor *cg, *first, *cur;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- first = cur = NULL;
-
- while (len_data >= 6)
- {
- int c, i;
- unsigned short type;
- type = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
- if (type != 2)
- fatal (_("unexpected group cursor type %d"), type);
- c = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
- len_data -= 6;
- pb_data += 6;
-
- for (i = 0; i < c; i++)
- {
- if (len_data < 14)
- fatal ("too small group icon rcdata");
- cg = (rc_group_cursor *) res_alloc (sizeof (rc_group_cursor));
- cg->next = NULL;
- cg->width = windres_get_16 (&wrtarget, pb_data, len_data);
- cg->height = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
- cg->planes = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
- cg->bits = windres_get_16 (&wrtarget, pb_data + 6, len_data - 6);
- cg->bytes = windres_get_32 (&wrtarget, pb_data + 8, len_data - 8);
- cg->index = windres_get_16 (&wrtarget, pb_data + 12, len_data - 12);
- if (! first)
- first = cg;
- else
- cur->next = cg;
- cur = cg;
- pb_data += 14;
- len_data -= 14;
- }
- }
-
- r = define_standard_resource (&resources, RT_GROUP_ICON, id,
- resinfo->language, 0);
- r->type = RES_TYPE_GROUP_CURSOR;
- r->u.group_cursor = first;
- r->res_info = *resinfo;
-}
-
-static void
-define_cursor_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_cursor *c;
- rc_res_resource *r;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- c = (rc_cursor *) res_alloc (sizeof (rc_cursor));
- c->xhotspot = windres_get_16 (&wrtarget, pb_data, len_data);
- c->yhotspot = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
- c->length = len_data - BIN_CURSOR_SIZE;
- c->data = (const bfd_byte *) (data + BIN_CURSOR_SIZE);
-
- r = define_standard_resource (&resources, RT_CURSOR, id, resinfo->language, 0);
- r->type = RES_TYPE_CURSOR;
- r->u.cursor = c;
- r->res_info = *resinfo;
-}
-
-static void
-define_bitmap_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- r = define_standard_resource (&resources, RT_BITMAP, id, resinfo->language, 0);
- r->type = RES_TYPE_BITMAP;
- r->u.data.length = len_data;
- r->u.data.data = pb_data;
- r->res_info = *resinfo;
-}
-
-static void
-define_icon_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
- rc_uint_type len_data;
- bfd_byte *pb_data;
-
- pb_data = rcdata_render_as_buffer (data, &len_data);
-
- r = define_standard_resource (&resources, RT_ICON, id, resinfo->language, 0);
- r->type = RES_TYPE_ICON;
- r->u.data.length = len_data;
- r->u.data.data = pb_data;
- r->res_info = *resinfo;
-}
-
-/* Define a menu resource. */
-
-void
-define_menu (rc_res_id id, const rc_res_res_info *resinfo,
- rc_menuitem *menuitems)
-{
- rc_menu *m;
- rc_res_resource *r;
-
- m = (rc_menu *) res_alloc (sizeof (rc_menu));
- m->items = menuitems;
- m->help = 0;
-
- r = define_standard_resource (&resources, RT_MENU, id, resinfo->language, 0);
- r->type = RES_TYPE_MENU;
- r->u.menu = m;
- r->res_info = *resinfo;
-}
-
-/* Define a menu item. This does not define a resource, but merely
- allocates and fills in a structure. */
-
-rc_menuitem *
-define_menuitem (const unichar *text, rc_uint_type menuid, rc_uint_type type,
- rc_uint_type state, rc_uint_type help,
- rc_menuitem *menuitems)
-{
- rc_menuitem *mi;
-
- mi = (rc_menuitem *) res_alloc (sizeof (rc_menuitem));
- mi->next = NULL;
- mi->type = type;
- mi->state = state;
- mi->id = menuid;
- mi->text = unichar_dup (text);
- mi->help = help;
- mi->popup = menuitems;
- return mi;
-}
-
-/* Define a messagetable resource. */
-
-void
-define_messagetable (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- FILE *e;
- char *real_filename;
- struct stat s;
- bfd_byte *data;
- rc_res_resource *r;
-
- e = open_file_search (filename, FOPEN_RB, "messagetable file",
- &real_filename);
-
- if (stat (real_filename, &s) < 0)
- fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
- strerror (errno));
-
- data = (bfd_byte *) res_alloc (s.st_size);
-
- get_data (e, data, s.st_size, real_filename);
-
- fclose (e);
- free (real_filename);
-
- r = define_standard_resource (&resources, RT_MESSAGETABLE, id,
- resinfo->language, 0);
-
- r->type = RES_TYPE_MESSAGETABLE;
- r->u.data.length = s.st_size;
- r->u.data.data = data;
- r->res_info = *resinfo;
-}
-
-/* Define an rcdata resource. */
-
-void
-define_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_resource *r;
-
- r = define_standard_resource (&resources, RT_RCDATA, id,
- resinfo->language, 0);
- r->type = RES_TYPE_RCDATA;
- r->u.rcdata = data;
- r->res_info = *resinfo;
-}
-
-/* Create an rcdata item holding a string. */
-
-rc_rcdata_item *
-define_rcdata_string (const char *string, rc_uint_type len)
-{
- rc_rcdata_item *ri;
- char *s;
-
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
- ri->next = NULL;
- ri->type = RCDATA_STRING;
- ri->u.string.length = len;
- s = (char *) res_alloc (len);
- memcpy (s, string, len);
- ri->u.string.s = s;
-
- return ri;
-}
-
-/* Create an rcdata item holding a unicode string. */
-
-rc_rcdata_item *
-define_rcdata_unistring (const unichar *string, rc_uint_type len)
-{
- rc_rcdata_item *ri;
- unichar *s;
-
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
- ri->next = NULL;
- ri->type = RCDATA_WSTRING;
- ri->u.wstring.length = len;
- s = (unichar *) res_alloc (len * sizeof (unichar));
- memcpy (s, string, len * sizeof (unichar));
- ri->u.wstring.w = s;
-
- return ri;
-}
-
-/* Create an rcdata item holding a number. */
-
-rc_rcdata_item *
-define_rcdata_number (rc_uint_type val, int dword)
-{
- rc_rcdata_item *ri;
-
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
- ri->next = NULL;
- ri->type = dword ? RCDATA_DWORD : RCDATA_WORD;
- ri->u.word = val;
-
- return ri;
-}
-
-/* Define a stringtable resource. This is called for each string
- which appears in a STRINGTABLE statement. */
-
-void
-define_stringtable (const rc_res_res_info *resinfo,
- rc_uint_type stringid, const unichar *string)
-{
- rc_res_id id;
- rc_res_resource *r;
-
- id.named = 0;
- id.u.id = (stringid >> 4) + 1;
- r = define_standard_resource (&resources, RT_STRING, id,
- resinfo->language, 1);
-
- if (r->type == RES_TYPE_UNINITIALIZED)
- {
- int i;
-
- r->type = RES_TYPE_STRINGTABLE;
- r->u.stringtable = ((rc_stringtable *)
- res_alloc (sizeof (rc_stringtable)));
- for (i = 0; i < 16; i++)
- {
- r->u.stringtable->strings[i].length = 0;
- r->u.stringtable->strings[i].string = NULL;
- }
-
- r->res_info = *resinfo;
- }
-
- r->u.stringtable->strings[stringid & 0xf].length = unichar_len (string);
- r->u.stringtable->strings[stringid & 0xf].string = unichar_dup (string);
-}
-
-void
-define_toolbar (rc_res_id id, rc_res_res_info *resinfo, rc_uint_type width, rc_uint_type height,
- rc_toolbar_item *items)
-{
- rc_toolbar *t;
- rc_res_resource *r;
-
- t = (rc_toolbar *) res_alloc (sizeof (rc_toolbar));
- t->button_width = width;
- t->button_height = height;
- t->nitems = 0;
- t->items = items;
- while (items != NULL)
- {
- t->nitems+=1;
- items = items->next;
- }
- r = define_standard_resource (&resources, RT_TOOLBAR, id, resinfo->language, 0);
- r->type = RES_TYPE_TOOLBAR;
- r->u.toolbar = t;
- r->res_info = *resinfo;
-}
-
-/* Define a user data resource where the data is in the rc file. */
-
-void
-define_user_data (rc_res_id id, rc_res_id type,
- const rc_res_res_info *resinfo,
- rc_rcdata_item *data)
-{
- rc_res_id ids[3];
- rc_res_resource *r;
- bfd_byte *pb_data;
- rc_uint_type len_data;
-
- /* We have to check if the binary data is parsed specially. */
- if (type.named == 0)
- {
- switch (type.u.id)
- {
- case RT_FONTDIR:
- define_fontdir_rcdata (id, resinfo, data);
- return;
- case RT_FONT:
- define_font_rcdata (id, resinfo, data);
- return;
- case RT_ICON:
- define_icon_rcdata (id, resinfo, data);
- return;
- case RT_BITMAP:
- define_bitmap_rcdata (id, resinfo, data);
- return;
- case RT_CURSOR:
- define_cursor_rcdata (id, resinfo, data);
- return;
- case RT_GROUP_ICON:
- define_group_icon_rcdata (id, resinfo, data);
- return;
- case RT_GROUP_CURSOR:
- define_group_cursor_rcdata (id, resinfo, data);
- return;
- case RT_MESSAGETABLE:
- define_messagetable_rcdata (id, resinfo, data);
- return;
- default:
- /* Treat as normal user-data. */
- break;
- }
- }
- ids[0] = type;
- ids[1] = id;
- ids[2].named = 0;
- ids[2].u.id = resinfo->language;
-
- r = define_resource (& resources, 3, ids, 0);
- r->type = RES_TYPE_USERDATA;
- r->u.userdata = ((rc_rcdata_item *)
- res_alloc (sizeof (rc_rcdata_item)));
- r->u.userdata->next = NULL;
- r->u.userdata->type = RCDATA_BUFFER;
- pb_data = rcdata_render_as_buffer (data, &len_data);
- r->u.userdata->u.buffer.length = len_data;
- r->u.userdata->u.buffer.data = pb_data;
- r->res_info = *resinfo;
-}
-
-void
-define_rcdata_file (rc_res_id id, const rc_res_res_info *resinfo,
- const char *filename)
-{
- rc_rcdata_item *ri;
- FILE *e;
- char *real_filename;
- struct stat s;
- bfd_byte *data;
-
- e = open_file_search (filename, FOPEN_RB, "file", &real_filename);
-
-
- if (stat (real_filename, &s) < 0)
- fatal (_("stat failed on file `%s': %s"), real_filename,
- strerror (errno));
-
- data = (bfd_byte *) res_alloc (s.st_size);
-
- get_data (e, data, s.st_size, real_filename);
-
- fclose (e);
- free (real_filename);
-
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
- ri->next = NULL;
- ri->type = RCDATA_BUFFER;
- ri->u.buffer.length = s.st_size;
- ri->u.buffer.data = data;
-
- define_rcdata (id, resinfo, ri);
-}
-
-/* Define a user data resource where the data is in a file. */
-
-void
-define_user_file (rc_res_id id, rc_res_id type,
- const rc_res_res_info *resinfo, const char *filename)
-{
- FILE *e;
- char *real_filename;
- struct stat s;
- bfd_byte *data;
- rc_res_id ids[3];
- rc_res_resource *r;
-
- e = open_file_search (filename, FOPEN_RB, "file", &real_filename);
-
- if (stat (real_filename, &s) < 0)
- fatal (_("stat failed on file `%s': %s"), real_filename,
- strerror (errno));
-
- data = (bfd_byte *) res_alloc (s.st_size);
-
- get_data (e, data, s.st_size, real_filename);
-
- fclose (e);
- free (real_filename);
-
- ids[0] = type;
- ids[1] = id;
- ids[2].named = 0;
- ids[2].u.id = resinfo->language;
-
- r = define_resource (&resources, 3, ids, 0);
- r->type = RES_TYPE_USERDATA;
- r->u.userdata = ((rc_rcdata_item *)
- res_alloc (sizeof (rc_rcdata_item)));
- r->u.userdata->next = NULL;
- r->u.userdata->type = RCDATA_BUFFER;
- r->u.userdata->u.buffer.length = s.st_size;
- r->u.userdata->u.buffer.data = data;
- r->res_info = *resinfo;
-}
-
-/* Define a versioninfo resource. */
-
-void
-define_versioninfo (rc_res_id id, rc_uint_type language,
- rc_fixed_versioninfo *fixedverinfo,
- rc_ver_info *verinfo)
-{
- rc_res_resource *r;
-
- r = define_standard_resource (&resources, RT_VERSION, id, language, 0);
- r->type = RES_TYPE_VERSIONINFO;
- r->u.versioninfo = ((rc_versioninfo *)
- res_alloc (sizeof (rc_versioninfo)));
- r->u.versioninfo->fixed = fixedverinfo;
- r->u.versioninfo->var = verinfo;
- r->res_info.language = language;
-}
-
-/* Add string version info to a list of version information. */
-
-rc_ver_info *
-append_ver_stringfileinfo (rc_ver_info *verinfo, const char *language,
- rc_ver_stringinfo *strings)
-{
- rc_ver_info *vi, **pp;
-
- vi = (rc_ver_info *) res_alloc (sizeof (rc_ver_info));
- vi->next = NULL;
- vi->type = VERINFO_STRING;
- unicode_from_ascii ((rc_uint_type *) NULL, &vi->u.string.language, language);
- vi->u.string.strings = strings;
-
- for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)
- ;
- *pp = vi;
-
- return verinfo;
-}
-
-/* Add variable version info to a list of version information. */
-
-rc_ver_info *
-append_ver_varfileinfo (rc_ver_info *verinfo, const unichar *key,
- rc_ver_varinfo *var)
-{
- rc_ver_info *vi, **pp;
-
- vi = (rc_ver_info *) res_alloc (sizeof *vi);
- vi->next = NULL;
- vi->type = VERINFO_VAR;
- vi->u.var.key = unichar_dup (key);
- vi->u.var.var = var;
-
- for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)
- ;
- *pp = vi;
-
- return verinfo;
-}
-
-/* Append version string information to a list. */
-
-rc_ver_stringinfo *
-append_verval (rc_ver_stringinfo *strings, const unichar *key,
- const unichar *value)
-{
- rc_ver_stringinfo *vs, **pp;
-
- vs = (rc_ver_stringinfo *) res_alloc (sizeof (rc_ver_stringinfo));
- vs->next = NULL;
- vs->key = unichar_dup (key);
- vs->value = unichar_dup (value);
-
- for (pp = &strings; *pp != NULL; pp = &(*pp)->next)
- ;
- *pp = vs;
-
- return strings;
-}
-
-/* Append version variable information to a list. */
-
-rc_ver_varinfo *
-append_vertrans (rc_ver_varinfo *var, rc_uint_type language,
- rc_uint_type charset)
-{
- rc_ver_varinfo *vv, **pp;
-
- vv = (rc_ver_varinfo *) res_alloc (sizeof (rc_ver_varinfo));
- vv->next = NULL;
- vv->language = language;
- vv->charset = charset;
-
- for (pp = &var; *pp != NULL; pp = &(*pp)->next)
- ;
- *pp = vv;
-
- return var;
-}
-
-/* Local functions used to write out an rc file. */
-
-static void indent (FILE *, int);
-static void write_rc_directory (FILE *, const rc_res_directory *, const rc_res_id *,
- const rc_res_id *, rc_uint_type *, int);
-static void write_rc_subdir (FILE *, const rc_res_entry *, const rc_res_id *,
- const rc_res_id *, rc_uint_type *, int);
-static void write_rc_resource (FILE *, const rc_res_id *, const rc_res_id *,
- const rc_res_resource *, rc_uint_type *);
-static void write_rc_accelerators (FILE *, const rc_accelerator *);
-static void write_rc_cursor (FILE *, const rc_cursor *);
-static void write_rc_group_cursor (FILE *, const rc_group_cursor *);
-static void write_rc_dialog (FILE *, const rc_dialog *);
-static void write_rc_dialog_control (FILE *, const rc_dialog_control *);
-static void write_rc_fontdir (FILE *, const rc_fontdir *);
-static void write_rc_group_icon (FILE *, const rc_group_icon *);
-static void write_rc_menu (FILE *, const rc_menu *, int);
-static void write_rc_toolbar (FILE *, const rc_toolbar *);
-static void write_rc_menuitems (FILE *, const rc_menuitem *, int, int);
-static void write_rc_messagetable (FILE *, rc_uint_type , const bfd_byte *);
-
-static void write_rc_datablock (FILE *, rc_uint_type , const bfd_byte *, int, int, int);
-static void write_rc_rcdata (FILE *, const rc_rcdata_item *, int);
-static void write_rc_stringtable (FILE *, const rc_res_id *, const rc_stringtable *);
-static void write_rc_versioninfo (FILE *, const rc_versioninfo *);
-
-/* Indent a given number of spaces. */
-
-static void
-indent (FILE *e, int c)
-{
- int i;
-
- for (i = 0; i < c; i++)
- putc (' ', e);
-}
-
-/* Dump the resources we have read in the format of an rc file.
-
- Reasoned by the fact, that some resources need to be stored into file and
- refer to that file, we use the user-data model for that to express it binary
- without the need to store it somewhere externally. */
-
-void
-write_rc_file (const char *filename, const rc_res_directory *resources)
-{
- FILE *e;
- rc_uint_type language;
-
- if (filename == NULL)
- e = stdout;
- else
- {
- e = fopen (filename, FOPEN_WT);
- if (e == NULL)
- fatal (_("can't open `%s' for output: %s"), filename, strerror (errno));
- }
-
- language = (rc_uint_type) ((bfd_signed_vma) -1);
- write_rc_directory (e, resources, (const rc_res_id *) NULL,
- (const rc_res_id *) NULL, &language, 1);
-}
-
-/* Write out a directory. E is the file to write to. RD is the
- directory. TYPE is a pointer to the level 1 ID which serves as the
- resource type. NAME is a pointer to the level 2 ID which serves as
- an individual resource name. LANGUAGE is a pointer to the current
- language. LEVEL is the level in the tree. */
-
-static void
-write_rc_directory (FILE *e, const rc_res_directory *rd,
- const rc_res_id *type, const rc_res_id *name,
- rc_uint_type *language, int level)
-{
- const rc_res_entry *re;
-
- /* Print out some COFF information that rc files can't represent. */
- if (rd->time != 0 || rd->characteristics != 0 || rd->major != 0 || rd->minor != 0)
- {
- wr_printcomment (e, "COFF information not part of RC");
- if (rd->time != 0)
- wr_printcomment (e, "Time stamp: %u", rd->time);
- if (rd->characteristics != 0)
- wr_printcomment (e, "Characteristics: %u", rd->characteristics);
- if (rd->major != 0 || rd->minor != 0)
- wr_printcomment (e, "Version major:%d minor:%d", rd->major, rd->minor);
- }
-
- for (re = rd->entries; re != NULL; re = re->next)
- {
- switch (level)
- {
- case 1:
- /* If we're at level 1, the key of this resource is the
- type. This normally duplicates the information we have
- stored with the resource itself, but we need to remember
- the type if this is a user define resource type. */
- type = &re->id;
- break;
-
- case 2:
- /* If we're at level 2, the key of this resource is the name
- we are going to use in the rc printout. */
- name = &re->id;
- break;
-
- case 3:
- /* If we're at level 3, then this key represents a language.
- Use it to update the current language. */
- if (! re->id.named
- && re->id.u.id != (unsigned long) (unsigned int) *language
- && (re->id.u.id & 0xffff) == re->id.u.id)
- {
- wr_print (e, "LANGUAGE %u, %u\n",
- re->id.u.id & ((1 << SUBLANG_SHIFT) - 1),
- (re->id.u.id >> SUBLANG_SHIFT) & 0xff);
- *language = re->id.u.id;
- }
- break;
-
- default:
- break;
- }
-
- if (re->subdir)
- write_rc_subdir (e, re, type, name, language, level);
- else
- {
- if (level == 3)
- {
- /* This is the normal case: the three levels are
- TYPE/NAME/LANGUAGE. NAME will have been set at level
- 2, and represents the name to use. We probably just
- set LANGUAGE, and it will probably match what the
- resource itself records if anything. */
- write_rc_resource (e, type, name, re->u.res, language);
- }
- else
- {
- wr_printcomment (e, "Resource at unexpected level %d", level);
- write_rc_resource (e, type, (rc_res_id *) NULL, re->u.res,
- language);
- }
- }
- }
- if (rd->entries == NULL)
- {
- wr_print_flush (e);
- }
-}
-
-/* Write out a subdirectory entry. E is the file to write to. RE is
- the subdirectory entry. TYPE and NAME are pointers to higher level
- IDs, or NULL. LANGUAGE is a pointer to the current language.
- LEVEL is the level in the tree. */
-
-static void
-write_rc_subdir (FILE *e, const rc_res_entry *re,
- const rc_res_id *type, const rc_res_id *name,
- rc_uint_type *language, int level)
-{
- fprintf (e, "\n");
- switch (level)
- {
- case 1:
- wr_printcomment (e, "Type: ");
- if (re->id.named)
- res_id_print (e, re->id, 1);
- else
- {
- const char *s;
-
- switch (re->id.u.id)
- {
- case RT_CURSOR: s = "cursor"; break;
- case RT_BITMAP: s = "bitmap"; break;
- case RT_ICON: s = "icon"; break;
- case RT_MENU: s = "menu"; break;
- case RT_DIALOG: s = "dialog"; break;
- case RT_STRING: s = "stringtable"; break;
- case RT_FONTDIR: s = "fontdir"; break;
- case RT_FONT: s = "font"; break;
- case RT_ACCELERATOR: s = "accelerators"; break;
- case RT_RCDATA: s = "rcdata"; break;
- case RT_MESSAGETABLE: s = "messagetable"; break;
- case RT_GROUP_CURSOR: s = "group cursor"; break;
- case RT_GROUP_ICON: s = "group icon"; break;
- case RT_VERSION: s = "version"; break;
- case RT_DLGINCLUDE: s = "dlginclude"; break;
- case RT_PLUGPLAY: s = "plugplay"; break;
- case RT_VXD: s = "vxd"; break;
- case RT_ANICURSOR: s = "anicursor"; break;
- case RT_ANIICON: s = "aniicon"; break;
- case RT_TOOLBAR: s = "toolbar"; break;
- case RT_HTML: s = "html"; break;
- default: s = NULL; break;
- }
-
- if (s != NULL)
- fprintf (e, "%s", s);
- else
- res_id_print (e, re->id, 1);
- }
- break;
-
- case 2:
- wr_printcomment (e, "Name: ");
- res_id_print (e, re->id, 1);
- break;
-
- case 3:
- wr_printcomment (e, "Language: ");
- res_id_print (e, re->id, 1);
- break;
-
- default:
- wr_printcomment (e, "Level %d: ", level);
- res_id_print (e, re->id, 1);
- }
-
- write_rc_directory (e, re->u.dir, type, name, language, level + 1);
-}
-
-/* Write out a single resource. E is the file to write to. TYPE is a
- pointer to the type of the resource. NAME is a pointer to the name
- of the resource; it will be NULL if there is a level mismatch. RES
- is the resource data. LANGUAGE is a pointer to the current
- language. */
-
-static void
-write_rc_resource (FILE *e, const rc_res_id *type,
- const rc_res_id *name, const rc_res_resource *res,
- rc_uint_type *language)
-{
- const char *s;
- int rt;
- int menuex = 0;
-
- switch (res->type)
- {
- default:
- abort ();
-
- case RES_TYPE_ACCELERATOR:
- s = "ACCELERATORS";
- rt = RT_ACCELERATOR;
- break;
-
- case RES_TYPE_BITMAP:
- s = "2 /* RT_BITMAP */";
- rt = RT_BITMAP;
- break;
-
- case RES_TYPE_CURSOR:
- s = "1 /* RT_CURSOR */";
- rt = RT_CURSOR;
- break;
-
- case RES_TYPE_GROUP_CURSOR:
- s = "12 /* RT_GROUP_CURSOR */";
- rt = RT_GROUP_CURSOR;
- break;
-
- case RES_TYPE_DIALOG:
- if (extended_dialog (res->u.dialog))
- s = "DIALOGEX";
- else
- s = "DIALOG";
- rt = RT_DIALOG;
- break;
-
- case RES_TYPE_FONT:
- s = "8 /* RT_FONT */";
- rt = RT_FONT;
- break;
-
- case RES_TYPE_FONTDIR:
- s = "7 /* RT_FONTDIR */";
- rt = RT_FONTDIR;
- break;
-
- case RES_TYPE_ICON:
- s = "3 /* RT_ICON */";
- rt = RT_ICON;
- break;
-
- case RES_TYPE_GROUP_ICON:
- s = "14 /* RT_GROUP_ICON */";
- rt = RT_GROUP_ICON;
- break;
-
- case RES_TYPE_MENU:
- if (extended_menu (res->u.menu))
- {
- s = "MENUEX";
- menuex = 1;
- }
- else
- {
- s = "MENU";
- menuex = 0;
- }
- rt = RT_MENU;
- break;
-
- case RES_TYPE_MESSAGETABLE:
- s = "11 /* RT_MESSAGETABLE */";
- rt = RT_MESSAGETABLE;
- break;
-
- case RES_TYPE_RCDATA:
- s = "RCDATA";
- rt = RT_RCDATA;
- break;
-
- case RES_TYPE_STRINGTABLE:
- s = "STRINGTABLE";
- rt = RT_STRING;
- break;
-
- case RES_TYPE_USERDATA:
- s = NULL;
- rt = 0;
- break;
-
- case RES_TYPE_VERSIONINFO:
- s = "VERSIONINFO";
- rt = RT_VERSION;
- break;
-
- case RES_TYPE_TOOLBAR:
- s = "TOOLBAR";
- rt = RT_TOOLBAR;
- break;
- }
-
- if (rt != 0
- && type != NULL
- && (type->named || type->u.id != (unsigned long) rt))
- {
- wr_printcomment (e, "Unexpected resource type mismatch: ");
- res_id_print (e, *type, 1);
- fprintf (e, " != %d", rt);
- }
-
- if (res->coff_info.codepage != 0)
- wr_printcomment (e, "Code page: %u", res->coff_info.codepage);
- if (res->coff_info.reserved != 0)
- wr_printcomment (e, "COFF reserved value: %u", res->coff_info.reserved);
-
- wr_print (e, "\n");
- if (rt == RT_STRING)
- ;
- else
- {
- if (name != NULL)
- res_id_print (e, *name, 1);
- else
- fprintf (e, "??Unknown-Name??");
- fprintf (e, " ");
- }
-
- if (s != NULL)
- fprintf (e, "%s", s);
- else if (type != NULL)
- {
- if (type->named == 0)
- {
-#define PRINT_RT_NAME(NAME) case NAME: \
- fprintf (e, "%u /* %s */", (unsigned int) NAME, #NAME); \
- break
-
- switch (type->u.id)
- {
- default:
- res_id_print (e, *type, 0);
- break;
-
- PRINT_RT_NAME(RT_MANIFEST);
- PRINT_RT_NAME(RT_ANICURSOR);
- PRINT_RT_NAME(RT_ANIICON);
- PRINT_RT_NAME(RT_RCDATA);
- PRINT_RT_NAME(RT_ICON);
- PRINT_RT_NAME(RT_CURSOR);
- PRINT_RT_NAME(RT_BITMAP);
- PRINT_RT_NAME(RT_PLUGPLAY);
- PRINT_RT_NAME(RT_VXD);
- PRINT_RT_NAME(RT_FONT);
- PRINT_RT_NAME(RT_FONTDIR);
- PRINT_RT_NAME(RT_HTML);
- PRINT_RT_NAME(RT_MESSAGETABLE);
- PRINT_RT_NAME(RT_DLGINCLUDE);
- PRINT_RT_NAME(RT_DLGINIT);
- }
-#undef PRINT_RT_NAME
- }
- else
- res_id_print (e, *type, 1);
- }
- else
- fprintf (e, "??Unknown-Type??");
-
- if (res->res_info.memflags != 0)
- {
- if ((res->res_info.memflags & MEMFLAG_MOVEABLE) != 0)
- fprintf (e, " MOVEABLE");
- if ((res->res_info.memflags & MEMFLAG_PURE) != 0)
- fprintf (e, " PURE");
- if ((res->res_info.memflags & MEMFLAG_PRELOAD) != 0)
- fprintf (e, " PRELOAD");
- if ((res->res_info.memflags & MEMFLAG_DISCARDABLE) != 0)
- fprintf (e, " DISCARDABLE");
- }
-
- if (res->type == RES_TYPE_DIALOG)
- {
- fprintf (e, " %d, %d, %d, %d",
- (int) res->u.dialog->x, (int) res->u.dialog->y,
- (int) res->u.dialog->width, (int) res->u.dialog->height);
- if (res->u.dialog->ex != NULL
- && res->u.dialog->ex->help != 0)
- fprintf (e, ", %u", (unsigned int) res->u.dialog->ex->help);
- }
- else if (res->type == RES_TYPE_TOOLBAR)
- {
- fprintf (e, " %d, %d", (int) res->u.toolbar->button_width,
- (int) res->u.toolbar->button_height);
- }
-
- fprintf (e, "\n");
-
- if ((res->res_info.language != 0 && res->res_info.language != *language)
- || res->res_info.characteristics != 0
- || res->res_info.version != 0)
- {
- int modifiers;
-
- switch (res->type)
- {
- case RES_TYPE_ACCELERATOR:
- case RES_TYPE_DIALOG:
- case RES_TYPE_MENU:
- case RES_TYPE_RCDATA:
- case RES_TYPE_STRINGTABLE:
- modifiers = 1;
- break;
-
- default:
- modifiers = 0;
- break;
- }
-
- if (res->res_info.language != 0 && res->res_info.language != *language)
- fprintf (e, "%sLANGUAGE %d, %d\n",
- modifiers ? "// " : "",
- (int) res->res_info.language & ((1<<SUBLANG_SHIFT)-1),
- (int) (res->res_info.language >> SUBLANG_SHIFT) & 0xff);
- if (res->res_info.characteristics != 0)
- fprintf (e, "%sCHARACTERISTICS %u\n",
- modifiers ? "// " : "",
- (unsigned int) res->res_info.characteristics);
- if (res->res_info.version != 0)
- fprintf (e, "%sVERSION %u\n",
- modifiers ? "// " : "",
- (unsigned int) res->res_info.version);
- }
-
- switch (res->type)
- {
- default:
- abort ();
-
- case RES_TYPE_ACCELERATOR:
- write_rc_accelerators (e, res->u.acc);
- break;
-
- case RES_TYPE_CURSOR:
- write_rc_cursor (e, res->u.cursor);
- break;
-
- case RES_TYPE_GROUP_CURSOR:
- write_rc_group_cursor (e, res->u.group_cursor);
- break;
-
- case RES_TYPE_DIALOG:
- write_rc_dialog (e, res->u.dialog);
- break;
-
- case RES_TYPE_FONTDIR:
- write_rc_fontdir (e, res->u.fontdir);
- break;
-
- case RES_TYPE_GROUP_ICON:
- write_rc_group_icon (e, res->u.group_icon);
- break;
-
- case RES_TYPE_MENU:
- write_rc_menu (e, res->u.menu, menuex);
- break;
-
- case RES_TYPE_RCDATA:
- write_rc_rcdata (e, res->u.rcdata, 0);
- break;
-
- case RES_TYPE_STRINGTABLE:
- write_rc_stringtable (e, name, res->u.stringtable);
- break;
-
- case RES_TYPE_USERDATA:
- write_rc_rcdata (e, res->u.userdata, 0);
- break;
-
- case RES_TYPE_TOOLBAR:
- write_rc_toolbar (e, res->u.toolbar);
- break;
-
- case RES_TYPE_VERSIONINFO:
- write_rc_versioninfo (e, res->u.versioninfo);
- break;
-
- case RES_TYPE_BITMAP:
- case RES_TYPE_FONT:
- case RES_TYPE_ICON:
- write_rc_datablock (e, res->u.data.length, res->u.data.data, 0, 1, 0);
- break;
- case RES_TYPE_MESSAGETABLE:
- write_rc_messagetable (e, res->u.data.length, res->u.data.data);
- break;
- }
-}
-
-/* Write out accelerator information. */
-
-static void
-write_rc_accelerators (FILE *e, const rc_accelerator *accelerators)
-{
- const rc_accelerator *acc;
-
- fprintf (e, "BEGIN\n");
- for (acc = accelerators; acc != NULL; acc = acc->next)
- {
- int printable;
-
- fprintf (e, " ");
-
- if ((acc->key & 0x7f) == acc->key
- && ISPRINT (acc->key)
- && (acc->flags & ACC_VIRTKEY) == 0)
- {
- fprintf (e, "\"%c\"", (char) acc->key);
- printable = 1;
- }
- else
- {
- fprintf (e, "%d", (int) acc->key);
- printable = 0;
- }
-
- fprintf (e, ", %d", (int) acc->id);
-
- if (! printable)
- {
- if ((acc->flags & ACC_VIRTKEY) != 0)
- fprintf (e, ", VIRTKEY");
- else
- fprintf (e, ", ASCII");
- }
-
- if ((acc->flags & ACC_SHIFT) != 0)
- fprintf (e, ", SHIFT");
- if ((acc->flags & ACC_CONTROL) != 0)
- fprintf (e, ", CONTROL");
- if ((acc->flags & ACC_ALT) != 0)
- fprintf (e, ", ALT");
-
- fprintf (e, "\n");
- }
-
- fprintf (e, "END\n");
-}
-
-/* Write out cursor information. This would normally be in a separate
- file, which the rc file would include. */
-
-static void
-write_rc_cursor (FILE *e, const rc_cursor *cursor)
-{
- fprintf (e, "BEGIN\n");
- indent (e, 2);
- fprintf (e, " 0x%x, 0x%x,\t/* Hotspot x: %d, y: %d. */\n",
- (unsigned int) cursor->xhotspot, (unsigned int) cursor->yhotspot,
- (int) cursor->xhotspot, (int) cursor->yhotspot);
- write_rc_datablock (e, (rc_uint_type) cursor->length, (const bfd_byte *) cursor->data,
- 0, 0, 0);
- fprintf (e, "END\n");
-}
-
-/* Write out group cursor data. This would normally be built from the
- cursor data. */
-
-static void
-write_rc_group_cursor (FILE *e, const rc_group_cursor *group_cursor)
-{
- const rc_group_cursor *gc;
- int c;
-
- for (c = 0, gc = group_cursor; gc != NULL; gc = gc->next, c++)
- ;
- fprintf (e, "BEGIN\n");
-
- indent (e, 2);
- fprintf (e, "0, 2, %d%s\t /* Having %d items. */\n", c, (c != 0 ? "," : ""), c);
- indent (e, 4);
- fprintf (e, "/* width, height, planes, bits, bytes, index. */\n");
-
- for (c = 1, gc = group_cursor; gc != NULL; gc = gc->next, c++)
- {
- indent (e, 4);
- fprintf (e, "%d, %d, %d, %d, 0x%xL, %d%s /* Element %d. */\n",
- (int) gc->width, (int) gc->height, (int) gc->planes, (int) gc->bits,
- (unsigned int) gc->bytes, (int) gc->index, (gc->next != NULL ? "," : ""), c);
- fprintf (e, "/* width: %d; height %d; planes %d; bits %d. */\n",
- (int) gc->width, (int) gc->height, (int) gc->planes,
- (int) gc->bits);
- }
- fprintf (e, "END\n");
-}
-
-/* Write dialog data. */
-
-static void
-write_rc_dialog (FILE *e, const rc_dialog *dialog)
-{
- const rc_dialog_control *control;
-
- fprintf (e, "STYLE 0x%x\n", dialog->style);
-
- if (dialog->exstyle != 0)
- fprintf (e, "EXSTYLE 0x%x\n", (unsigned int) dialog->exstyle);
-
- if ((dialog->class.named && dialog->class.u.n.length > 0)
- || dialog->class.u.id != 0)
- {
- fprintf (e, "CLASS ");
- res_id_print (e, dialog->class, 1);
- fprintf (e, "\n");
- }
-
- if (dialog->caption != NULL)
- {
- fprintf (e, "CAPTION ");
- unicode_print_quoted (e, dialog->caption, -1);
- fprintf (e, "\n");
- }
-
- if ((dialog->menu.named && dialog->menu.u.n.length > 0)
- || dialog->menu.u.id != 0)
- {
- fprintf (e, "MENU ");
- res_id_print (e, dialog->menu, 0);
- fprintf (e, "\n");
- }
-
- if (dialog->font != NULL)
- {
- fprintf (e, "FONT %d, ", (int) dialog->pointsize);
- unicode_print_quoted (e, dialog->font, -1);
- if (dialog->ex != NULL
- && (dialog->ex->weight != 0
- || dialog->ex->italic != 0
- || dialog->ex->charset != 1))
- fprintf (e, ", %d, %d, %d",
- (int) dialog->ex->weight,
- (int) dialog->ex->italic,
- (int) dialog->ex->charset);
- fprintf (e, "\n");
- }
-
- fprintf (e, "BEGIN\n");
-
- for (control = dialog->controls; control != NULL; control = control->next)
- write_rc_dialog_control (e, control);
-
- fprintf (e, "END\n");
-}
-
-/* For each predefined control keyword, this table provides the class
- and the style. */
-
-struct control_info
-{
- const char *name;
- unsigned short class;
- unsigned long style;
-};
-
-static const struct control_info control_info[] =
-{
- { "AUTO3STATE", CTL_BUTTON, BS_AUTO3STATE },
- { "AUTOCHECKBOX", CTL_BUTTON, BS_AUTOCHECKBOX },
- { "AUTORADIOBUTTON", CTL_BUTTON, BS_AUTORADIOBUTTON },
- { "CHECKBOX", CTL_BUTTON, BS_CHECKBOX },
- { "COMBOBOX", CTL_COMBOBOX, (unsigned long) -1 },
- { "CTEXT", CTL_STATIC, SS_CENTER },
- { "DEFPUSHBUTTON", CTL_BUTTON, BS_DEFPUSHBUTTON },
- { "EDITTEXT", CTL_EDIT, (unsigned long) -1 },
- { "GROUPBOX", CTL_BUTTON, BS_GROUPBOX },
- { "ICON", CTL_STATIC, SS_ICON },
- { "LISTBOX", CTL_LISTBOX, (unsigned long) -1 },
- { "LTEXT", CTL_STATIC, SS_LEFT },
- { "PUSHBOX", CTL_BUTTON, BS_PUSHBOX },
- { "PUSHBUTTON", CTL_BUTTON, BS_PUSHBUTTON },
- { "RADIOBUTTON", CTL_BUTTON, BS_RADIOBUTTON },
- { "RTEXT", CTL_STATIC, SS_RIGHT },
- { "SCROLLBAR", CTL_SCROLLBAR, (unsigned long) -1 },
- { "STATE3", CTL_BUTTON, BS_3STATE },
- /* It's important that USERBUTTON come after all the other button
- types, so that it won't be matched too early. */
- { "USERBUTTON", CTL_BUTTON, (unsigned long) -1 },
- { NULL, 0, 0 }
-};
-
-/* Write a dialog control. */
-
-static void
-write_rc_dialog_control (FILE *e, const rc_dialog_control *control)
-{
- const struct control_info *ci;
-
- fprintf (e, " ");
-
- if (control->class.named)
- ci = NULL;
- else
- {
- for (ci = control_info; ci->name != NULL; ++ci)
- if (ci->class == control->class.u.id
- && (ci->style == (unsigned long) -1
- || ci->style == (control->style & 0xff)))
- break;
- }
- if (ci == NULL)
- fprintf (e, "CONTROL");
- else if (ci->name != NULL)
- fprintf (e, "%s", ci->name);
- else
- {
- fprintf (e, "CONTROL");
- ci = NULL;
- }
-
- if (control->text.named || control->text.u.id != 0)
- {
- fprintf (e, " ");
- res_id_print (e, control->text, 1);
- fprintf (e, ",");
- }
-
- fprintf (e, " %d, ", (int) control->id);
-
- if (ci == NULL)
- {
- if (control->class.named)
- fprintf (e, "\"");
- res_id_print (e, control->class, 0);
- if (control->class.named)
- fprintf (e, "\"");
- fprintf (e, ", 0x%x, ", (unsigned int) control->style);
- }
-
- fprintf (e, "%d, %d", (int) control->x, (int) control->y);
-
- if (control->style != SS_ICON
- || control->exstyle != 0
- || control->width != 0
- || control->height != 0
- || control->help != 0)
- {
- fprintf (e, ", %d, %d", (int) control->width, (int) control->height);
-
- /* FIXME: We don't need to print the style if it is the default.
- More importantly, in certain cases we actually need to turn
- off parts of the forced style, by using NOT. */
- if (ci != NULL)
- fprintf (e, ", 0x%x", (unsigned int) control->style);
-
- if (control->exstyle != 0 || control->help != 0)
- fprintf (e, ", 0x%x, %u", (unsigned int) control->exstyle,
- (unsigned int) control->help);
- }
-
- fprintf (e, "\n");
-
- if (control->data != NULL)
- write_rc_rcdata (e, control->data, 2);
-}
-
-/* Write out font directory data. This would normally be built from
- the font data. */
-
-static void
-write_rc_fontdir (FILE *e, const rc_fontdir *fontdir)
-{
- const rc_fontdir *fc;
- int c;
-
- for (c = 0, fc = fontdir; fc != NULL; fc = fc->next, c++)
- ;
- fprintf (e, "BEGIN\n");
- indent (e, 2);
- fprintf (e, "%d%s\t /* Has %d elements. */\n", c, (c != 0 ? "," : ""), c);
- for (c = 1, fc = fontdir; fc != NULL; fc = fc->next, c++)
- {
- indent (e, 4);
- fprintf (e, "%d,\t/* Font no %d with index %d. */\n",
- (int) fc->index, c, (int) fc->index);
- write_rc_datablock (e, (rc_uint_type) fc->length - 2,
- (const bfd_byte *) fc->data + 4,fc->next != NULL,
- 0, 0);
- }
- fprintf (e, "END\n");
-}
-
-/* Write out group icon data. This would normally be built from the
- icon data. */
-
-static void
-write_rc_group_icon (FILE *e, const rc_group_icon *group_icon)
-{
- const rc_group_icon *gi;
- int c;
-
- for (c = 0, gi = group_icon; gi != NULL; gi = gi->next, c++)
- ;
-
- fprintf (e, "BEGIN\n");
- indent (e, 2);
- fprintf (e, " 0, 1, %d%s\t /* Has %d elements. */\n", c, (c != 0 ? "," : ""), c);
-
- indent (e, 4);
- fprintf (e, "/* \"width height colors pad\", planes, bits, bytes, index. */\n");
- for (c = 1, gi = group_icon; gi != NULL; gi = gi->next, c++)
- {
- indent (e, 4);
- fprintf (e, "\"\\%03o\\%03o\\%03o\\%03o\", %d, %d, 0x%xL, %d%s\t/* Element no %d. */\n",
- gi->width, gi->height, gi->colors, 0, (int) gi->planes, (int) gi->bits,
- (unsigned int) gi->bytes, (int) gi->index, (gi->next != NULL ? "," : ""), c);
- }
- fprintf (e, "END\n");
-}
-
-/* Write out a menu resource. */
-
-static void
-write_rc_menu (FILE *e, const rc_menu *menu, int menuex)
-{
- if (menu->help != 0)
- fprintf (e, "// Help ID: %u\n", (unsigned int) menu->help);
- write_rc_menuitems (e, menu->items, menuex, 0);
-}
-
-static void
-write_rc_toolbar (FILE *e, const rc_toolbar *tb)
-{
- rc_toolbar_item *it;
- indent (e, 0);
- fprintf (e, "BEGIN\n");
- it = tb->items;
- while(it != NULL)
- {
- indent (e, 2);
- if (it->id.u.id == 0)
- fprintf (e, "SEPARATOR\n");
- else
- fprintf (e, "BUTTON %d\n", (int) it->id.u.id);
- it = it->next;
- }
- indent (e, 0);
- fprintf (e, "END\n");
-}
-
-/* Write out menuitems. */
-
-static void
-write_rc_menuitems (FILE *e, const rc_menuitem *menuitems, int menuex,
- int ind)
-{
- const rc_menuitem *mi;
-
- indent (e, ind);
- fprintf (e, "BEGIN\n");
-
- for (mi = menuitems; mi != NULL; mi = mi->next)
- {
- indent (e, ind + 2);
-
- if (mi->popup == NULL)
- fprintf (e, "MENUITEM");
- else
- fprintf (e, "POPUP");
-
- if (! menuex
- && mi->popup == NULL
- && mi->text == NULL
- && mi->type == 0
- && mi->id == 0)
- {
- fprintf (e, " SEPARATOR\n");
- continue;
- }
-
- if (mi->text == NULL)
- fprintf (e, " \"\"");
- else
- {
- fprintf (e, " ");
- unicode_print_quoted (e, mi->text, -1);
- }
-
- if (! menuex)
- {
- if (mi->popup == NULL)
- fprintf (e, ", %d", (int) mi->id);
-
- if ((mi->type & MENUITEM_CHECKED) != 0)
- fprintf (e, ", CHECKED");
- if ((mi->type & MENUITEM_GRAYED) != 0)
- fprintf (e, ", GRAYED");
- if ((mi->type & MENUITEM_HELP) != 0)
- fprintf (e, ", HELP");
- if ((mi->type & MENUITEM_INACTIVE) != 0)
- fprintf (e, ", INACTIVE");
- if ((mi->type & MENUITEM_MENUBARBREAK) != 0)
- fprintf (e, ", MENUBARBREAK");
- if ((mi->type & MENUITEM_MENUBREAK) != 0)
- fprintf (e, ", MENUBREAK");
- }
- else
- {
- if (mi->id != 0 || mi->type != 0 || mi->state != 0 || mi->help != 0)
- {
- fprintf (e, ", %d", (int) mi->id);
- if (mi->type != 0 || mi->state != 0 || mi->help != 0)
- {
- fprintf (e, ", %u", (unsigned int) mi->type);
- if (mi->state != 0 || mi->help != 0)
- {
- fprintf (e, ", %u", (unsigned int) mi->state);
- if (mi->help != 0)
- fprintf (e, ", %u", (unsigned int) mi->help);
- }
- }
- }
- }
-
- fprintf (e, "\n");
-
- if (mi->popup != NULL)
- write_rc_menuitems (e, mi->popup, menuex, ind + 2);
- }
-
- indent (e, ind);
- fprintf (e, "END\n");
-}
-
-static int
-test_rc_datablock_unicode (rc_uint_type length, const bfd_byte *data)
-{
- rc_uint_type i;
- if ((length & 1) != 0)
- return 0;
-
- for (i = 0; i < length; i += 2)
- {
- if (data[i] == 0 && data[i + 1] == 0 && (i + 2) < length)
- return 0;
- if (data[i] == 0xff && data[i + 1] == 0xff)
- return 0;
- }
- return 1;
-}
-
-static int
-test_rc_datablock_text (rc_uint_type length, const bfd_byte *data)
-{
- int has_nl;
- rc_uint_type c;
- rc_uint_type i;
-
- if (length <= 1)
- return 0;
-
- has_nl = 0;
- for (i = 0, c = 0; i < length; i++)
- {
- if (! ISPRINT (data[i]) && data[i] != '\n'
- && ! (data[i] == '\r' && (i + 1) < length && data[i + 1] == '\n')
- && data[i] != '\t'
- && ! (data[i] == 0 && (i + 1) != length))
- {
- if (data[i] <= 7)
- return 0;
- c++;
- }
- else if (data[i] == '\n') has_nl++;
- }
- if (length > 80 && ! has_nl)
- return 0;
- c = (((c * 10000) + (i / 100) - 1)) / i;
- if (c >= 150)
- return 0;
- return 1;
-}
-
-static void
-write_rc_messagetable (FILE *e, rc_uint_type length, const bfd_byte *data)
-{
- int has_error = 0;
- const struct bin_messagetable *mt;
- fprintf (e, "BEGIN\n");
-
- write_rc_datablock (e, length, data, 0, 0, 0);
-
- fprintf (e, "\n");
- wr_printcomment (e, "MC syntax dump");
- if (length < BIN_MESSAGETABLE_SIZE)
- has_error = 1;
- else
- do {
- rc_uint_type m, i;
- mt = (const struct bin_messagetable *) data;
- m = windres_get_32 (&wrtarget, mt->cblocks, length);
- if (length < (BIN_MESSAGETABLE_SIZE + m * BIN_MESSAGETABLE_BLOCK_SIZE))
- {
- has_error = 1;
- break;
- }
- for (i = 0; i < m; i++)
- {
- rc_uint_type low, high, offset;
- const struct bin_messagetable_item *mti;
-
- low = windres_get_32 (&wrtarget, mt->items[i].lowid, 4);
- high = windres_get_32 (&wrtarget, mt->items[i].highid, 4);
- offset = windres_get_32 (&wrtarget, mt->items[i].offset, 4);
- while (low <= high)
- {
- rc_uint_type elen, flags;
- if ((offset + BIN_MESSAGETABLE_ITEM_SIZE) > length)
- {
- has_error = 1;
- break;
- }
- mti = (const struct bin_messagetable_item *) &data[offset];
- elen = windres_get_16 (&wrtarget, mti->length, 2);
- flags = windres_get_16 (&wrtarget, mti->flags, 2);
- if ((offset + elen) > length)
- {
- has_error = 1;
- break;
- }
- wr_printcomment (e, "MessageId = 0x%x", low);
- wr_printcomment (e, "");
- if ((flags & MESSAGE_RESOURCE_UNICODE) == MESSAGE_RESOURCE_UNICODE)
- unicode_print (e, (const unichar *) mti->data,
- (elen - BIN_MESSAGETABLE_ITEM_SIZE) / 2);
- else
- ascii_print (e, (const char *) mti->data,
- (elen - BIN_MESSAGETABLE_ITEM_SIZE));
- wr_printcomment (e,"");
- ++low;
- offset += elen;
- }
- }
- } while (0);
- if (has_error)
- wr_printcomment (e, "Illegal data");
- wr_print_flush (e);
- fprintf (e, "END\n");
-}
-
-static void
-write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_next,
- int hasblock, int show_comment)
-{
- int plen;
-
- if (hasblock)
- fprintf (e, "BEGIN\n");
-
- if (show_comment == -1)
- {
- if (test_rc_datablock_text(length, data))
- {
- rc_uint_type i, c;
- for (i = 0; i < length;)
- {
- indent (e, 2);
- fprintf (e, "\"");
-
- for (c = 0; i < length && c < 160 && data[i] != '\n'; c++, i++)
- ;
- if (i < length && data[i] == '\n')
- ++i, ++c;
- ascii_print (e, (const char *) &data[i - c], c);
- fprintf (e, "\"");
- if (i < length)
- fprintf (e, "\n");
- }
-
- if (i == 0)
- {
- indent (e, 2);
- fprintf (e, "\"\"");
- }
- if (has_next)
- fprintf (e, ",");
- fprintf (e, "\n");
- if (hasblock)
- fprintf (e, "END\n");
- return;
- }
- if (test_rc_datablock_unicode (length, data))
- {
- rc_uint_type i, c;
- for (i = 0; i < length;)
- {
- const unichar *u;
-
- u = (const unichar *) &data[i];
- indent (e, 2);
- fprintf (e, "L\"");
-
- for (c = 0; i < length && c < 160 && u[c] != '\n'; c++, i += 2)
- ;
- if (i < length && u[c] == '\n')
- i += 2, ++c;
- unicode_print (e, u, c);
- fprintf (e, "\"");
- if (i < length)
- fprintf (e, "\n");
- }
-
- if (i == 0)
- {
- indent (e, 2);
- fprintf (e, "L\"\"");
- }
- if (has_next)
- fprintf (e, ",");
- fprintf (e, "\n");
- if (hasblock)
- fprintf (e, "END\n");
- return;
- }
-
- show_comment = 0;
- }
-
- if (length != 0)
- {
- rc_uint_type i, max_row;
- int first = 1;
-
- max_row = (show_comment ? 4 : 8);
- indent (e, 2);
- for (i = 0; i + 3 < length;)
- {
- rc_uint_type k;
- rc_uint_type comment_start;
-
- comment_start = i;
-
- if (! first)
- indent (e, 2);
-
- for (k = 0; k < max_row && i + 3 < length; k++, i += 4)
- {
- if (k == 0)
- plen = fprintf (e, "0x%lxL",
- (unsigned long) windres_get_32 (&wrtarget, data + i, length - i));
- else
- plen = fprintf (e, " 0x%lxL",
- (unsigned long) windres_get_32 (&wrtarget, data + i, length - i)) - 1;
- if (has_next || (i + 4) < length)
- {
- if (plen>0 && plen < 11)
- indent (e, 11 - plen);
- fprintf (e, ",");
- }
- }
- if (show_comment)
- {
- fprintf (e, "\t/* ");
- ascii_print (e, (const char *) &data[comment_start], i - comment_start);
- fprintf (e, ". */");
- }
- fprintf (e, "\n");
- first = 0;
- }
-
- if (i + 1 < length)
- {
- if (! first)
- indent (e, 2);
- plen = fprintf (e, "0x%x",
- (int) windres_get_16 (&wrtarget, data + i, length - i));
- if (has_next || i + 2 < length)
- {
- if (plen > 0 && plen < 11)
- indent (e, 11 - plen);
- fprintf (e, ",");
- }
- if (show_comment)
- {
- fprintf (e, "\t/* ");
- ascii_print (e, (const char *) &data[i], 2);
- fprintf (e, ". */");
- }
- fprintf (e, "\n");
- i += 2;
- first = 0;
- }
-
- if (i < length)
- {
- if (! first)
- indent (e, 2);
- fprintf (e, "\"");
- ascii_print (e, (const char *) &data[i], 1);
- fprintf (e, "\"");
- if (has_next)
- fprintf (e, ",");
- fprintf (e, "\n");
- first = 0;
- }
- }
- if (hasblock)
- fprintf (e, "END\n");
-}
-
-/* Write out an rcdata resource. This is also used for other types of
- resources that need to print arbitrary data. */
-
-static void
-write_rc_rcdata (FILE *e, const rc_rcdata_item *rcdata, int ind)
-{
- const rc_rcdata_item *ri;
-
- indent (e, ind);
- fprintf (e, "BEGIN\n");
-
- for (ri = rcdata; ri != NULL; ri = ri->next)
- {
- if (ri->type == RCDATA_BUFFER && ri->u.buffer.length == 0)
- continue;
-
- switch (ri->type)
- {
- default:
- abort ();
-
- case RCDATA_WORD:
- indent (e, ind + 2);
- fprintf (e, "%ld", (long) (ri->u.word & 0xffff));
- break;
-
- case RCDATA_DWORD:
- indent (e, ind + 2);
- fprintf (e, "%luL", (unsigned long) ri->u.dword);
- break;
-
- case RCDATA_STRING:
- indent (e, ind + 2);
- fprintf (e, "\"");
- ascii_print (e, ri->u.string.s, ri->u.string.length);
- fprintf (e, "\"");
- break;
-
- case RCDATA_WSTRING:
- indent (e, ind + 2);
- fprintf (e, "L\"");
- unicode_print (e, ri->u.wstring.w, ri->u.wstring.length);
- fprintf (e, "\"");
- break;
-
- case RCDATA_BUFFER:
- write_rc_datablock (e, (rc_uint_type) ri->u.buffer.length,
- (const bfd_byte *) ri->u.buffer.data,
- ri->next != NULL, 0, -1);
- break;
- }
-
- if (ri->type != RCDATA_BUFFER)
- {
- if (ri->next != NULL)
- fprintf (e, ",");
- fprintf (e, "\n");
- }
- }
-
- indent (e, ind);
- fprintf (e, "END\n");
-}
-
-/* Write out a stringtable resource. */
-
-static void
-write_rc_stringtable (FILE *e, const rc_res_id *name,
- const rc_stringtable *stringtable)
-{
- rc_uint_type offset;
- int i;
-
- if (name != NULL && ! name->named)
- offset = (name->u.id - 1) << 4;
- else
- {
- fprintf (e, "/* %s string table name. */\n",
- name == NULL ? "Missing" : "Invalid");
- offset = 0;
- }
-
- fprintf (e, "BEGIN\n");
-
- for (i = 0; i < 16; i++)
- {
- if (stringtable->strings[i].length != 0)
- {
- fprintf (e, " %lu, ", (unsigned long) offset + i);
- unicode_print_quoted (e, stringtable->strings[i].string,
- stringtable->strings[i].length);
- fprintf (e, "\n");
- }
- }
-
- fprintf (e, "END\n");
-}
-
-/* Write out a versioninfo resource. */
-
-static void
-write_rc_versioninfo (FILE *e, const rc_versioninfo *versioninfo)
-{
- const rc_fixed_versioninfo *f;
- const rc_ver_info *vi;
-
- f = versioninfo->fixed;
- if (f->file_version_ms != 0 || f->file_version_ls != 0)
- fprintf (e, " FILEVERSION %u, %u, %u, %u\n",
- (unsigned int) ((f->file_version_ms >> 16) & 0xffff),
- (unsigned int) (f->file_version_ms & 0xffff),
- (unsigned int) ((f->file_version_ls >> 16) & 0xffff),
- (unsigned int) (f->file_version_ls & 0xffff));
- if (f->product_version_ms != 0 || f->product_version_ls != 0)
- fprintf (e, " PRODUCTVERSION %u, %u, %u, %u\n",
- (unsigned int) ((f->product_version_ms >> 16) & 0xffff),
- (unsigned int) (f->product_version_ms & 0xffff),
- (unsigned int) ((f->product_version_ls >> 16) & 0xffff),
- (unsigned int) (f->product_version_ls & 0xffff));
- if (f->file_flags_mask != 0)
- fprintf (e, " FILEFLAGSMASK 0x%x\n", (unsigned int) f->file_flags_mask);
- if (f->file_flags != 0)
- fprintf (e, " FILEFLAGS 0x%x\n", (unsigned int) f->file_flags);
- if (f->file_os != 0)
- fprintf (e, " FILEOS 0x%x\n", (unsigned int) f->file_os);
- if (f->file_type != 0)
- fprintf (e, " FILETYPE 0x%x\n", (unsigned int) f->file_type);
- if (f->file_subtype != 0)
- fprintf (e, " FILESUBTYPE 0x%x\n", (unsigned int) f->file_subtype);
- if (f->file_date_ms != 0 || f->file_date_ls != 0)
- fprintf (e, "/* Date: %u, %u. */\n",
- (unsigned int) f->file_date_ms, (unsigned int) f->file_date_ls);
-
- fprintf (e, "BEGIN\n");
-
- for (vi = versioninfo->var; vi != NULL; vi = vi->next)
- {
- switch (vi->type)
- {
- case VERINFO_STRING:
- {
- const rc_ver_stringinfo *vs;
-
- fprintf (e, " BLOCK \"StringFileInfo\"\n");
- fprintf (e, " BEGIN\n");
- fprintf (e, " BLOCK ");
- unicode_print_quoted (e, vi->u.string.language, -1);
- fprintf (e, "\n");
- fprintf (e, " BEGIN\n");
-
- for (vs = vi->u.string.strings; vs != NULL; vs = vs->next)
- {
- fprintf (e, " VALUE ");
- unicode_print_quoted (e, vs->key, -1);
- fprintf (e, ", ");
- unicode_print_quoted (e, vs->value, -1);
- fprintf (e, "\n");
- }
-
- fprintf (e, " END\n");
- fprintf (e, " END\n");
- break;
- }
-
- case VERINFO_VAR:
- {
- const rc_ver_varinfo *vv;
-
- fprintf (e, " BLOCK \"VarFileInfo\"\n");
- fprintf (e, " BEGIN\n");
- fprintf (e, " VALUE ");
- unicode_print_quoted (e, vi->u.var.key, -1);
-
- for (vv = vi->u.var.var; vv != NULL; vv = vv->next)
- fprintf (e, ", 0x%x, %d", (unsigned int) vv->language,
- (int) vv->charset);
-
- fprintf (e, "\n END\n");
-
- break;
- }
- }
- }
-
- fprintf (e, "END\n");
-}
-
-static rc_uint_type
-rcdata_copy (const rc_rcdata_item *src, bfd_byte *dst)
-{
- if (! src)
- return 0;
- switch (src->type)
- {
- case RCDATA_WORD:
- if (dst)
- windres_put_16 (&wrtarget, dst, (rc_uint_type) src->u.word);
- return 2;
- case RCDATA_DWORD:
- if (dst)
- windres_put_32 (&wrtarget, dst, (rc_uint_type) src->u.dword);
- return 4;
- case RCDATA_STRING:
- if (dst && src->u.string.length)
- memcpy (dst, src->u.string.s, src->u.string.length);
- return (rc_uint_type) src->u.string.length;
- case RCDATA_WSTRING:
- if (dst && src->u.wstring.length)
- memcpy (dst, src->u.wstring.w, src->u.wstring.length * sizeof (unichar));
- return (rc_uint_type) (src->u.wstring.length * sizeof (unichar));
- case RCDATA_BUFFER:
- if (dst && src->u.buffer.length)
- memcpy (dst, src->u.buffer.data, src->u.buffer.length);
- return (rc_uint_type) src->u.buffer.length;
- default:
- abort ();
- }
- /* Never reached. */
- return 0;
-}
diff --git a/binutils/resres.c b/binutils/resres.c
deleted file mode 100644
index 2ad40b481a3..00000000000
--- a/binutils/resres.c
+++ /dev/null
@@ -1,737 +0,0 @@
-/* resres.c: read_res_file and write_res_file implementation for windres.
- Copyright 1998, 1999, 2001, 2002, 2007, 2008
- Free Software Foundation, Inc.
- Written by Anders Norlander <anorland@hem2.passagen.se>.
- Rewritten by Kai Tietz, Onevision.
-
- This file is part of GNU Binutils.
-
- 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. */
-
-/* FIXME: This file does not work correctly in a cross configuration.
- It assumes that it can use fread and fwrite to read and write
- integers. It does no swapping. */
-
-#include "sysdep.h"
-#include "bfd.h"
-#include "bucomm.h"
-#include "libiberty.h"
-#include "windres.h"
-
-#include <assert.h>
-#include <time.h>
-
-static rc_uint_type write_res_directory (windres_bfd *, rc_uint_type,
- const rc_res_directory *, const rc_res_id *,
- const rc_res_id *, rc_uint_type *, int);
-static rc_uint_type write_res_resource (windres_bfd *, rc_uint_type,const rc_res_id *,
- const rc_res_id *, const rc_res_resource *,
- rc_uint_type *);
-static rc_uint_type write_res_bin (windres_bfd *, rc_uint_type, const rc_res_resource *,
- const rc_res_id *, const rc_res_id *,
- const rc_res_res_info *);
-
-static rc_uint_type write_res_id (windres_bfd *, rc_uint_type, const rc_res_id *);
-static rc_uint_type write_res_info (windres_bfd *, rc_uint_type, const rc_res_res_info *);
-static rc_uint_type write_res_data_hdr (windres_bfd *, rc_uint_type, res_hdr *);
-
-static rc_uint_type write_res_header (windres_bfd *, rc_uint_type, rc_uint_type,
- const rc_res_id *, const rc_res_id *,
- const rc_res_res_info *);
-
-static int read_resource_entry (windres_bfd *, rc_uint_type *, rc_uint_type);
-static void read_res_data (windres_bfd *, rc_uint_type *, rc_uint_type, void *,
- rc_uint_type);
-static void read_res_data_hdr (windres_bfd *, rc_uint_type *, rc_uint_type, res_hdr *);
-static void read_res_id (windres_bfd *, rc_uint_type *, rc_uint_type, rc_res_id *);
-static unichar *read_unistring (windres_bfd *, rc_uint_type *, rc_uint_type, rc_uint_type *);
-static void skip_null_resource (windres_bfd *, rc_uint_type *, rc_uint_type);
-static int probe_binary (windres_bfd *wrbfd, rc_uint_type);
-
-static unsigned long get_id_size (const rc_res_id *);
-
-static void res_add_resource (rc_res_resource *, const rc_res_id *,
- const rc_res_id *, rc_uint_type, int);
-
-static void res_append_resource (rc_res_directory **, rc_res_resource *,
- int, const rc_res_id *, int);
-
-static rc_res_directory *resources = NULL;
-
-static const char *filename;
-
-extern char *program_name;
-
-/* Read resource file */
-rc_res_directory *
-read_res_file (const char *fn)
-{
- rc_uint_type off, flen;
- windres_bfd wrbfd;
- bfd *abfd;
- asection *sec;
- filename = fn;
-
- flen = (rc_uint_type) get_file_size (filename);
- if (! flen)
- fatal ("can't open '%s' for input.", filename);
- abfd = windres_open_as_binary (filename, 1);
- sec = bfd_get_section_by_name (abfd, ".data");
- if (sec == NULL)
- bfd_fatal ("bfd_get_section_by_name");
- set_windres_bfd (&wrbfd, abfd, sec,
- (target_is_bigendian ? WR_KIND_BFD_BIN_B
- : WR_KIND_BFD_BIN_L));
- off = 0;
-
- if (! probe_binary (&wrbfd, flen))
- set_windres_bfd_endianess (&wrbfd, ! target_is_bigendian);
-
- skip_null_resource (&wrbfd, &off, flen);
-
- while (read_resource_entry (&wrbfd, &off, flen))
- ;
-
- bfd_close (abfd);
-
- return resources;
-}
-
-/* Write resource file */
-void
-write_res_file (const char *fn,const rc_res_directory *resdir)
-{
- asection *sec;
- rc_uint_type language;
- bfd *abfd;
- windres_bfd wrbfd;
- unsigned long sec_length = 0,sec_length_wrote;
- static const bfd_byte sign[] =
- {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- filename = fn;
-
- abfd = windres_open_as_binary (filename, 0);
- sec = bfd_make_section_with_flags (abfd, ".data",
- (SEC_HAS_CONTENTS | SEC_ALLOC
- | SEC_LOAD | SEC_DATA));
- if (sec == NULL)
- bfd_fatal ("bfd_make_section");
- /* Requiring this is probably a bug in BFD. */
- sec->output_section = sec;
-
- set_windres_bfd (&wrbfd, abfd, sec,
- (target_is_bigendian ? WR_KIND_BFD_BIN_B
- : WR_KIND_BFD_BIN_L));
-
- language = -1;
- sec_length = write_res_directory ((windres_bfd *) NULL, 0x20UL, resdir,
- (const rc_res_id *) NULL,
- (const rc_res_id *) NULL, &language, 1);
- if (! bfd_set_section_size (abfd, sec, (sec_length + 3) & ~3))
- bfd_fatal ("bfd_set_section_size");
- if ((sec_length & 3) != 0)
- set_windres_bfd_content (&wrbfd, sign, sec_length, 4-(sec_length & 3));
- set_windres_bfd_content (&wrbfd, sign, 0, sizeof (sign));
- language = -1;
- sec_length_wrote = write_res_directory (&wrbfd, 0x20UL, resdir,
- (const rc_res_id *) NULL,
- (const rc_res_id *) NULL,
- &language, 1);
- if (sec_length != sec_length_wrote)
- fatal ("res write failed with different sizes (%lu/%lu).",
- (unsigned long) sec_length, (unsigned long) sec_length_wrote);
-
- bfd_close (abfd);
- return;
-}
-
-/* Read a resource entry, returns 0 when all resources are read */
-static int
-read_resource_entry (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax)
-{
- rc_res_id type;
- rc_res_id name;
- rc_res_res_info resinfo;
- res_hdr reshdr;
- void *buff;
-
- rc_res_resource *r;
- struct bin_res_info l;
-
- off[0] = (off[0] + 3) & ~3;
-
- /* Read header */
- if ((off[0] + 8) > omax)
- return 0;
- read_res_data_hdr (wrbfd, off, omax, &reshdr);
-
- /* read resource type */
- read_res_id (wrbfd, off, omax, &type);
- /* read resource id */
- read_res_id (wrbfd, off, omax, &name);
-
- off[0] = (off[0] + 3) & ~3;
-
- /* Read additional resource header */
- read_res_data (wrbfd, off, omax, &l, BIN_RES_INFO_SIZE);
- resinfo.version = windres_get_32 (wrbfd, l.version, 4);
- resinfo.memflags = windres_get_16 (wrbfd, l.memflags, 2);
- resinfo.language = windres_get_16 (wrbfd, l.language, 2);
- /* resinfo.version2 = windres_get_32 (wrbfd, l.version2, 4); */
- resinfo.characteristics = windres_get_32 (wrbfd, l.characteristics, 4);
-
- off[0] = (off[0] + 3) & ~3;
-
- /* Allocate buffer for data */
- buff = res_alloc (reshdr.data_size);
- /* Read data */
- read_res_data (wrbfd, off, omax, buff, reshdr.data_size);
- /* Convert binary data to resource */
- r = bin_to_res (wrbfd, type, buff, reshdr.data_size);
- r->res_info = resinfo;
- /* Add resource to resource directory */
- res_add_resource (r, &type, &name, resinfo.language, 0);
-
- return 1;
-}
-
-/* write resource directory to binary resource file */
-static rc_uint_type
-write_res_directory (windres_bfd *wrbfd, rc_uint_type off, const rc_res_directory *rd,
- const rc_res_id *type, const rc_res_id *name, rc_uint_type *language,
- int level)
-{
- const rc_res_entry *re;
-
- for (re = rd->entries; re != NULL; re = re->next)
- {
- switch (level)
- {
- case 1:
- /* If we're at level 1, the key of this resource is the
- type. This normally duplicates the information we have
- stored with the resource itself, but we need to remember
- the type if this is a user define resource type. */
- type = &re->id;
- break;
-
- case 2:
- /* If we're at level 2, the key of this resource is the name
- we are going to use in the rc printout. */
- name = &re->id;
- break;
-
- case 3:
- /* If we're at level 3, then this key represents a language.
- Use it to update the current language. */
- if (! re->id.named
- && re->id.u.id != (unsigned long) *language
- && (re->id.u.id & 0xffff) == re->id.u.id)
- {
- *language = re->id.u.id;
- }
- break;
-
- default:
- break;
- }
-
- if (re->subdir)
- off = write_res_directory (wrbfd, off, re->u.dir, type, name, language,
- level + 1);
- else
- {
- if (level == 3)
- {
- /* This is the normal case: the three levels are
- TYPE/NAME/LANGUAGE. NAME will have been set at level
- 2, and represents the name to use. We probably just
- set LANGUAGE, and it will probably match what the
- resource itself records if anything. */
- off = write_res_resource (wrbfd, off, type, name, re->u.res,
- language);
- }
- else
- {
- fprintf (stderr, "// Resource at unexpected level %d\n", level);
- off = write_res_resource (wrbfd, off, type, (rc_res_id *) NULL,
- re->u.res, language);
- }
- }
- }
-
- return off;
-}
-
-static rc_uint_type
-write_res_resource (windres_bfd *wrbfd, rc_uint_type off, const rc_res_id *type,
- const rc_res_id *name, const rc_res_resource *res,
- rc_uint_type *language ATTRIBUTE_UNUSED)
-{
- int rt;
-
- switch (res->type)
- {
- default:
- abort ();
-
- case RES_TYPE_ACCELERATOR:
- rt = RT_ACCELERATOR;
- break;
-
- case RES_TYPE_BITMAP:
- rt = RT_BITMAP;
- break;
-
- case RES_TYPE_CURSOR:
- rt = RT_CURSOR;
- break;
-
- case RES_TYPE_GROUP_CURSOR:
- rt = RT_GROUP_CURSOR;
- break;
-
- case RES_TYPE_DIALOG:
- rt = RT_DIALOG;
- break;
-
- case RES_TYPE_FONT:
- rt = RT_FONT;
- break;
-
- case RES_TYPE_FONTDIR:
- rt = RT_FONTDIR;
- break;
-
- case RES_TYPE_ICON:
- rt = RT_ICON;
- break;
-
- case RES_TYPE_GROUP_ICON:
- rt = RT_GROUP_ICON;
- break;
-
- case RES_TYPE_MENU:
- rt = RT_MENU;
- break;
-
- case RES_TYPE_MESSAGETABLE:
- rt = RT_MESSAGETABLE;
- break;
-
- case RES_TYPE_RCDATA:
- rt = RT_RCDATA;
- break;
-
- case RES_TYPE_STRINGTABLE:
- rt = RT_STRING;
- break;
-
- case RES_TYPE_USERDATA:
- rt = 0;
- break;
-
- case RES_TYPE_VERSIONINFO:
- rt = RT_VERSION;
- break;
-
- case RES_TYPE_TOOLBAR:
- rt = RT_TOOLBAR;
- break;
- }
-
- if (rt != 0
- && type != NULL
- && (type->named || type->u.id != (unsigned long) rt))
- {
- fprintf (stderr, "// Unexpected resource type mismatch: ");
- res_id_print (stderr, *type, 1);
- fprintf (stderr, " != %d", rt);
- abort ();
- }
-
- return write_res_bin (wrbfd, off, res, type, name, &res->res_info);
-}
-
-/* Write a resource in binary resource format */
-static rc_uint_type
-write_res_bin (windres_bfd *wrbfd, rc_uint_type off, const rc_res_resource *res,
- const rc_res_id *type, const rc_res_id *name,
- const rc_res_res_info *resinfo)
-{
- rc_uint_type noff;
- rc_uint_type datasize = 0;
-
- noff = res_to_bin ((windres_bfd *) NULL, off, res);
- datasize = noff - off;
-
- off = write_res_header (wrbfd, off, datasize, type, name, resinfo);
- return res_to_bin (wrbfd, off, res);
-}
-
-/* Get number of bytes needed to store an id in binary format */
-static unsigned long
-get_id_size (id)
- const rc_res_id *id;
-{
- if (id->named)
- return sizeof (unichar) * (id->u.n.length + 1);
- else
- return sizeof (unichar) * 2;
-}
-
-/* Write a resource header */
-static rc_uint_type
-write_res_header (windres_bfd *wrbfd, rc_uint_type off, rc_uint_type datasize,
- const rc_res_id *type, const rc_res_id *name,
- const rc_res_res_info *resinfo)
-{
- res_hdr reshdr;
- reshdr.data_size = datasize;
- reshdr.header_size = 24 + get_id_size (type) + get_id_size (name);
-
- reshdr.header_size = (reshdr.header_size + 3) & ~3;
-
- off = (off + 3) & ~3;
-
- off = write_res_data_hdr (wrbfd, off, &reshdr);
- off = write_res_id (wrbfd, off, type);
- off = write_res_id (wrbfd, off, name);
-
- off = (off + 3) & ~3;
-
- off = write_res_info (wrbfd, off, resinfo);
- off = (off + 3) & ~3;
- return off;
-}
-
-static rc_uint_type
-write_res_data_hdr (windres_bfd *wrbfd, rc_uint_type off, res_hdr *hdr)
-{
- if (wrbfd)
- {
- struct bin_res_hdr brh;
- windres_put_32 (wrbfd, brh.data_size, hdr->data_size);
- windres_put_32 (wrbfd, brh.header_size, hdr->header_size);
- set_windres_bfd_content (wrbfd, &brh, off, BIN_RES_HDR_SIZE);
- }
- return off + BIN_RES_HDR_SIZE;
-}
-
-static void
-read_res_data_hdr (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax,
- res_hdr *reshdr)
-{
- struct bin_res_hdr brh;
-
- if ((off[0] + BIN_RES_HDR_SIZE) > omax)
- fatal ("%s: unexpected end of file %ld/%ld", filename,(long) off[0], (long) omax);
-
- get_windres_bfd_content (wrbfd, &brh, off[0], BIN_RES_HDR_SIZE);
- reshdr->data_size = windres_get_32 (wrbfd, brh.data_size, 4);
- reshdr->header_size = windres_get_32 (wrbfd, brh.header_size, 4);
- off[0] += BIN_RES_HDR_SIZE;
-}
-
-/* Read data from file, abort on failure */
-static void
-read_res_data (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax, void *data,
- rc_uint_type size)
-{
- if ((off[0] + size) > omax)
- fatal ("%s: unexpected end of file %ld/%ld %ld", filename,(long) off[0],
- (long) omax, (long) size);
- get_windres_bfd_content (wrbfd, data, off[0], size);
- off[0] += size;
-}
-
-/* Write a resource id */
-static rc_uint_type
-write_res_id (windres_bfd *wrbfd, rc_uint_type off, const rc_res_id *id)
-{
- if (id->named)
- {
- rc_uint_type len = (((bfd_signed_vma) id->u.n.length < 0 ? 0 : id->u.n.length) + 1);
- if (wrbfd)
- {
- rc_uint_type i;
- bfd_byte *d = (bfd_byte *) xmalloc (len * sizeof (unichar));
- for (i = 0; i < (len - 1); i++)
- windres_put_16 (wrbfd, d + (i * sizeof (unichar)), id->u.n.name[i]);
- windres_put_16 (wrbfd, d + (i * sizeof (unichar)), 0);
- set_windres_bfd_content (wrbfd, d, off, (len * sizeof (unichar)));
- }
- off += (len * sizeof (unichar));
- }
- else
- {
- if (wrbfd)
- {
- struct bin_res_id bid;
- windres_put_16 (wrbfd, bid.sig, 0xffff);
- windres_put_16 (wrbfd, bid.id, id->u.id);
- set_windres_bfd_content (wrbfd, &bid, off, BIN_RES_ID);
- }
- off += BIN_RES_ID;
- }
- return off;
-}
-
-/* Write resource info */
-static rc_uint_type
-write_res_info (windres_bfd *wrbfd, rc_uint_type off, const rc_res_res_info *info)
-{
- if (wrbfd)
- {
- struct bin_res_info l;
-
- windres_put_32 (wrbfd, l.version, info->version);
- windres_put_16 (wrbfd, l.memflags, info->memflags);
- windres_put_16 (wrbfd, l.language, info->language);
- windres_put_32 (wrbfd, l.version2, info->version);
- windres_put_32 (wrbfd, l.characteristics, info->characteristics);
- set_windres_bfd_content (wrbfd, &l, off, BIN_RES_INFO_SIZE);
- }
- return off + BIN_RES_INFO_SIZE;
-}
-
-/* read a resource identifier */
-static void
-read_res_id (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax, rc_res_id *id)
-{
- struct bin_res_id bid;
- unsigned short ord;
- unichar *id_s = NULL;
- rc_uint_type len;
-
- read_res_data (wrbfd, off, omax, &bid, BIN_RES_ID - 2);
- ord = (unsigned short) windres_get_16 (wrbfd, bid.sig, 2);
- if (ord == 0xFFFF) /* an ordinal id */
- {
- read_res_data (wrbfd, off, omax, bid.id, BIN_RES_ID - 2);
- id->named = 0;
- id->u.id = windres_get_16 (wrbfd, bid.id, 2);
- }
- else
- /* named id */
- {
- off[0] -= 2;
- id_s = read_unistring (wrbfd, off, omax, &len);
- id->named = 1;
- id->u.n.length = len;
- id->u.n.name = id_s;
- }
-}
-
-/* Read a null terminated UNICODE string */
-static unichar *
-read_unistring (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax,
- rc_uint_type *len)
-{
- unichar *s;
- bfd_byte d[2];
- unichar c;
- unichar *p;
- rc_uint_type l;
- rc_uint_type soff = off[0];
-
- do
- {
- read_res_data (wrbfd, &soff, omax, d, sizeof (unichar));
- c = windres_get_16 (wrbfd, d, 2);
- }
- while (c != 0);
- l = ((soff - off[0]) / sizeof (unichar));
-
- /* there are hardly any names longer than 256 characters, but anyway. */
- p = s = (unichar *) xmalloc (sizeof (unichar) * l);
- do
- {
- read_res_data (wrbfd, off, omax, d, sizeof (unichar));
- c = windres_get_16 (wrbfd, d, 2);
- *p++ = c;
- }
- while (c != 0);
- *len = l - 1;
- return s;
-}
-
-static int
-probe_binary (windres_bfd *wrbfd, rc_uint_type omax)
-{
- rc_uint_type off;
- res_hdr reshdr;
-
- off = 0;
- read_res_data_hdr (wrbfd, &off, omax, &reshdr);
- if (reshdr.data_size != 0)
- return 1;
- if ((reshdr.header_size != 0x20 && ! target_is_bigendian)
- || (reshdr.header_size != 0x20000000 && target_is_bigendian))
- return 1;
-
- /* Subtract size of HeaderSize. DataSize has to be zero. */
- off += 0x20 - BIN_RES_HDR_SIZE;
- if ((off + BIN_RES_HDR_SIZE) >= omax)
- return 1;
- read_res_data_hdr (wrbfd, &off, omax, &reshdr);
- /* off is advanced by BIN_RES_HDR_SIZE in read_res_data_hdr()
- which is part of reshdr.header_size. We shouldn't take it
- into account twice. */
- if ((off - BIN_RES_HDR_SIZE + reshdr.data_size + reshdr.header_size) > omax)
- return 0;
- return 1;
-}
-
-/* Check if file is a win32 binary resource file, if so
- skip past the null resource. Returns 0 if successful, -1 on
- error.
- */
-static void
-skip_null_resource (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax)
-{
- res_hdr reshdr;
- read_res_data_hdr (wrbfd, off, omax, &reshdr);
- if (reshdr.data_size != 0)
- goto skip_err;
- if ((reshdr.header_size != 0x20 && ! target_is_bigendian)
- || (reshdr.header_size != 0x20000000 && target_is_bigendian))
- goto skip_err;
-
- /* Subtract size of HeaderSize. DataSize has to be zero. */
- off[0] += 0x20 - BIN_RES_HDR_SIZE;
- if (off[0] >= omax)
- goto skip_err;
-
- return;
-
-skip_err:
- fprintf (stderr, "%s: %s: Not a valid WIN32 resource file\n", program_name,
- filename);
- xexit (1);
-}
-
-/* Add a resource to resource directory */
-static void
-res_add_resource (rc_res_resource *r, const rc_res_id *type, const rc_res_id *id,
- rc_uint_type language, int dupok)
-{
- rc_res_id a[3];
-
- a[0] = *type;
- a[1] = *id;
- a[2].named = 0;
- a[2].u.id = language;
- res_append_resource (&resources, r, 3, a, dupok);
-}
-
-/* Append a resource to resource directory.
- This is just copied from define_resource
- and modified to add an existing resource.
- */
-static void
-res_append_resource (rc_res_directory **resources, rc_res_resource *resource,
- int cids, const rc_res_id *ids, int dupok)
-{
- rc_res_entry *re = NULL;
- int i;
-
- assert (cids > 0);
- for (i = 0; i < cids; i++)
- {
- rc_res_entry **pp;
-
- if (*resources == NULL)
- {
- static unsigned long timeval;
-
- /* Use the same timestamp for every resource created in a
- single run. */
- if (timeval == 0)
- timeval = time (NULL);
-
- *resources = ((rc_res_directory *)
- res_alloc (sizeof (rc_res_directory)));
- (*resources)->characteristics = 0;
- (*resources)->time = timeval;
- (*resources)->major = 0;
- (*resources)->minor = 0;
- (*resources)->entries = NULL;
- }
-
- for (pp = &(*resources)->entries; *pp != NULL; pp = &(*pp)->next)
- if (res_id_cmp ((*pp)->id, ids[i]) == 0)
- break;
-
- if (*pp != NULL)
- re = *pp;
- else
- {
- re = (rc_res_entry *) res_alloc (sizeof (rc_res_entry));
- re->next = NULL;
- re->id = ids[i];
- if ((i + 1) < cids)
- {
- re->subdir = 1;
- re->u.dir = NULL;
- }
- else
- {
- re->subdir = 0;
- re->u.res = NULL;
- }
-
- *pp = re;
- }
-
- if ((i + 1) < cids)
- {
- if (! re->subdir)
- {
- fprintf (stderr, "%s: ", program_name);
- res_ids_print (stderr, i, ids);
- fprintf (stderr, ": expected to be a directory\n");
- xexit (1);
- }
-
- resources = &re->u.dir;
- }
- }
-
- if (re->subdir)
- {
- fprintf (stderr, "%s: ", program_name);
- res_ids_print (stderr, cids, ids);
- fprintf (stderr, ": expected to be a leaf\n");
- xexit (1);
- }
-
- if (re->u.res != NULL)
- {
- if (dupok)
- return;
-
- fprintf (stderr, "%s: warning: ", program_name);
- res_ids_print (stderr, cids, ids);
- fprintf (stderr, ": duplicate value\n");
- }
-
- re->u.res = resource;
-}
diff --git a/binutils/size.c b/binutils/size.c
deleted file mode 100644
index 415fee1011f..00000000000
--- a/binutils/size.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/* size.c -- report size of various sections of an executable file.
- Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
- Free Software Foundation, Inc.
-
- This file is part of GNU Binutils.
-
- 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. */
-
-/* Extensions/incompatibilities:
- o - BSD output has filenames at the end.
- o - BSD output can appear in different radicies.
- o - SysV output has less redundant whitespace. Filename comes at end.
- o - SysV output doesn't show VMA which is always the same as the PMA.
- o - We also handle core files.
- o - We also handle archives.
- If you write shell scripts which manipulate this info then you may be
- out of luck; there's no --compatibility or --pedantic option. */
-
-#include "sysdep.h"
-#include "bfd.h"
-#include "libiberty.h"
-#include "getopt.h"
-#include "bucomm.h"
-
-#ifndef BSD_DEFAULT
-#define BSD_DEFAULT 1
-#endif
-
-/* Program options. */
-
-static enum
- {
- decimal, octal, hex
- }
-radix = decimal;
-
-/* 0 means use AT&T-style output. */
-static int berkeley_format = BSD_DEFAULT;
-
-static int show_version = 0;
-static int show_help = 0;
-static int show_totals = 0;
-static int show_common = 0;
-
-static bfd_size_type common_size;
-static bfd_size_type total_bsssize;
-static bfd_size_type total_datasize;
-static bfd_size_type total_textsize;
-
-/* Program exit status. */
-static int return_code = 0;
-
-static char *target = NULL;
-
-/* Forward declarations. */
-
-static void display_file (char *);
-static void rprint_number (int, bfd_size_type);
-static void print_sizes (bfd * file);
-
-static void
-usage (FILE *stream, int status)
-{
- fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
- fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
- fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
- fprintf (stream, _(" The options are:\n\
- -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\
- -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
- -t --totals Display the total sizes (Berkeley only)\n\
- --common Display total size for *COM* syms\n\
- --target=<bfdname> Set the binary file format\n\
- @<file> Read options from <file>\n\
- -h --help Display this information\n\
- -v --version Display the program's version\n\
-\n"),
-#if BSD_DEFAULT
- "berkeley"
-#else
- "sysv"
-#endif
-);
- list_supported_targets (program_name, stream);
- if (REPORT_BUGS_TO[0] && status == 0)
- fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
- exit (status);
-}
-
-#define OPTION_FORMAT (200)
-#define OPTION_RADIX (OPTION_FORMAT + 1)
-#define OPTION_TARGET (OPTION_RADIX + 1)
-
-static struct option long_options[] =
-{
- {"common", no_argument, &show_common, 1},
- {"format", required_argument, 0, OPTION_FORMAT},
- {"radix", required_argument, 0, OPTION_RADIX},
- {"target", required_argument, 0, OPTION_TARGET},
- {"totals", no_argument, &show_totals, 1},
- {"version", no_argument, &show_version, 1},
- {"help", no_argument, &show_help, 1},
- {0, no_argument, 0, 0}
-};
-
-int main (int, char **);
-
-int
-main (int argc, char **argv)
-{
- int temp;
- int c;
-
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
- setlocale (LC_MESSAGES, "");
-#endif
-#if defined (HAVE_SETLOCALE)
- setlocale (LC_CTYPE, "");
-#endif
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- program_name = *argv;
- xmalloc_set_program_name (program_name);
-
- expandargv (&argc, &argv);
-
- bfd_init ();
- set_default_bfd_target ();
-
- while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
- (int *) 0)) != EOF)
- switch (c)
- {
- case OPTION_FORMAT:
- switch (*optarg)
- {
- case 'B':
- case 'b':
- berkeley_format = 1;
- break;
- case 'S':
- case 's':
- berkeley_format = 0;
- break;
- default:
- non_fatal (_("invalid argument to --format: %s"), optarg);
- usage (stderr, 1);
- }
- break;
-
- case OPTION_TARGET:
- target = optarg;
- break;
-
- case OPTION_RADIX:
-#ifdef ANSI_LIBRARIES
- temp = strtol (optarg, NULL, 10);
-#else
- temp = atol (optarg);
-#endif
- switch (temp)
- {
- case 10:
- radix = decimal;
- break;
- case 8:
- radix = octal;
- break;
- case 16:
- radix = hex;
- break;
- default:
- non_fatal (_("Invalid radix: %s\n"), optarg);
- usage (stderr, 1);
- }
- break;
-
- case 'A':
- berkeley_format = 0;
- break;
- case 'B':
- berkeley_format = 1;
- break;
- case 'v':
- case 'V':
- show_version = 1;
- break;
- case 'd':
- radix = decimal;
- break;
- case 'x':
- radix = hex;
- break;
- case 'o':
- radix = octal;
- break;
- case 't':
- show_totals = 1;
- break;
- case 'f': /* FIXME : For sysv68, `-f' means `full format', i.e.
- `[fname:] M(.text) + N(.data) + O(.bss) + P(.comment) = Q'
- where `fname: ' appears only if there are >= 2 input files,
- and M, N, O, P, Q are expressed in decimal by default,
- hexa or octal if requested by `-x' or `-o'.
- Just to make things interesting, Solaris also accepts -f,
- which prints out the size of each allocatable section, the
- name of the section, and the total of the section sizes. */
- /* For the moment, accept `-f' silently, and ignore it. */
- break;
- case 0:
- break;
- case 'h':
- case 'H':
- case '?':
- usage (stderr, 1);
- }
-
- if (show_version)
- print_version ("size");
- if (show_help)
- usage (stdout, 0);
-
- if (optind == argc)
- display_file ("a.out");
- else
- for (; optind < argc;)
- display_file (argv[optind++]);
-
- if (show_totals && berkeley_format)
- {
- bfd_size_type total = total_textsize + total_datasize + total_bsssize;
-
- rprint_number (7, total_textsize);
- putchar('\t');
- rprint_number (7, total_datasize);
- putchar('\t');
- rprint_number (7, total_bsssize);
- printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"),
- (unsigned long) total, (unsigned long) total);
- fputs ("(TOTALS)\n", stdout);
- }
-
- return return_code;
-}
-
-/* Total size required for common symbols in ABFD. */
-
-static void
-calculate_common_size (bfd *abfd)
-{
- asymbol **syms = NULL;
- long storage, symcount;
-
- common_size = 0;
- if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC | HAS_SYMS)) != HAS_SYMS)
- return;
-
- storage = bfd_get_symtab_upper_bound (abfd);
- if (storage < 0)
- bfd_fatal (bfd_get_filename (abfd));
- if (storage)
- syms = xmalloc (storage);
-
- symcount = bfd_canonicalize_symtab (abfd, syms);
- if (symcount < 0)
- bfd_fatal (bfd_get_filename (abfd));
-
- while (--symcount >= 0)
- {
- asymbol *sym = syms[symcount];
-
- if (bfd_is_com_section (sym->section)
- && (sym->flags & BSF_SECTION_SYM) == 0)
- common_size += sym->value;
- }
- free (syms);
-}
-
-/* Display stats on file or archive member ABFD. */
-
-static void
-display_bfd (bfd *abfd)
-{
- char **matching;
-
- if (bfd_check_format (abfd, bfd_archive))
- /* An archive within an archive. */
- return;
-
- if (bfd_check_format_matches (abfd, bfd_object, &matching))
- {
- print_sizes (abfd);
- printf ("\n");
- return;
- }
-
- if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
- {
- bfd_nonfatal (bfd_get_filename (abfd));
- list_matching_formats (matching);
- free (matching);
- return_code = 3;
- return;
- }
-
- if (bfd_check_format_matches (abfd, bfd_core, &matching))
- {
- const char *core_cmd;
-
- print_sizes (abfd);
- fputs (" (core file", stdout);
-
- core_cmd = bfd_core_file_failing_command (abfd);
- if (core_cmd)
- printf (" invoked as %s", core_cmd);
-
- puts (")\n");
- return;
- }
-
- bfd_nonfatal (bfd_get_filename (abfd));
-
- if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
- {
- list_matching_formats (matching);
- free (matching);
- }
-
- return_code = 3;
-}
-
-static void
-display_archive (bfd *file)
-{
- bfd *arfile = (bfd *) NULL;
- bfd *last_arfile = (bfd *) NULL;
-
- for (;;)
- {
- bfd_set_error (bfd_error_no_error);
-
- arfile = bfd_openr_next_archived_file (file, arfile);
- if (arfile == NULL)
- {
- if (bfd_get_error () != bfd_error_no_more_archived_files)
- {
- bfd_nonfatal (bfd_get_filename (file));
- return_code = 2;
- }
- break;
- }
-
- display_bfd (arfile);
-
- if (last_arfile != NULL)
- bfd_close (last_arfile);
- last_arfile = arfile;
- }
-
- if (last_arfile != NULL)
- bfd_close (last_arfile);
-}
-
-static void
-display_file (char *filename)
-{
- bfd *file;
-
- if (get_file_size (filename) < 1)
- {
- return_code = 1;
- return;
- }
-
- file = bfd_openr (filename, target);
- if (file == NULL)
- {
- bfd_nonfatal (filename);
- return_code = 1;
- return;
- }
-
- if (bfd_check_format (file, bfd_archive))
- display_archive (file);
- else
- display_bfd (file);
-
- if (!bfd_close (file))
- {
- bfd_nonfatal (filename);
- return_code = 1;
- return;
- }
-}
-
-static int
-size_number (bfd_size_type num)
-{
- char buffer[40];
-
- sprintf (buffer,
- (radix == decimal ? "%" BFD_VMA_FMT "u" :
- ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
- num);
-
- return strlen (buffer);
-}
-
-static void
-rprint_number (int width, bfd_size_type num)
-{
- char buffer[40];
-
- sprintf (buffer,
- (radix == decimal ? "%" BFD_VMA_FMT "u" :
- ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
- num);
-
- printf ("%*s", width, buffer);
-}
-
-static bfd_size_type bsssize;
-static bfd_size_type datasize;
-static bfd_size_type textsize;
-
-static void
-berkeley_sum (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr sec,
- void *ignore ATTRIBUTE_UNUSED)
-{
- flagword flags;
- bfd_size_type size;
-
- flags = bfd_get_section_flags (abfd, sec);
- if ((flags & SEC_ALLOC) == 0)
- return;
-
- size = bfd_get_section_size (sec);
- if ((flags & SEC_CODE) != 0 || (flags & SEC_READONLY) != 0)
- textsize += size;
- else if ((flags & SEC_HAS_CONTENTS) != 0)
- datasize += size;
- else
- bsssize += size;
-}
-
-static void
-print_berkeley_format (bfd *abfd)
-{
- static int files_seen = 0;
- bfd_size_type total;
-
- bsssize = 0;
- datasize = 0;
- textsize = 0;
-
- bfd_map_over_sections (abfd, berkeley_sum, NULL);
-
- bsssize += common_size;
- if (files_seen++ == 0)
- puts ((radix == octal) ? " text\t data\t bss\t oct\t hex\tfilename" :
- " text\t data\t bss\t dec\t hex\tfilename");
-
- total = textsize + datasize + bsssize;
-
- if (show_totals)
- {
- total_textsize += textsize;
- total_datasize += datasize;
- total_bsssize += bsssize;
- }
-
- rprint_number (7, textsize);
- putchar ('\t');
- rprint_number (7, datasize);
- putchar ('\t');
- rprint_number (7, bsssize);
- printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"),
- (unsigned long) total, (unsigned long) total);
-
- fputs (bfd_get_filename (abfd), stdout);
-
- if (bfd_my_archive (abfd))
- printf (" (ex %s)", bfd_get_filename (bfd_my_archive (abfd)));
-}
-
-/* I REALLY miss lexical functions! */
-bfd_size_type svi_total = 0;
-bfd_vma svi_maxvma = 0;
-int svi_namelen = 0;
-int svi_vmalen = 0;
-int svi_sizelen = 0;
-
-static void
-sysv_internal_sizer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec,
- void *ignore ATTRIBUTE_UNUSED)
-{
- bfd_size_type size = bfd_section_size (file, sec);
-
- if ( ! bfd_is_abs_section (sec)
- && ! bfd_is_com_section (sec)
- && ! bfd_is_und_section (sec))
- {
- int namelen = strlen (bfd_section_name (file, sec));
-
- if (namelen > svi_namelen)
- svi_namelen = namelen;
-
- svi_total += size;
-
- if (bfd_section_vma (file, sec) > svi_maxvma)
- svi_maxvma = bfd_section_vma (file, sec);
- }
-}
-
-static void
-sysv_one_line (const char *name, bfd_size_type size, bfd_vma vma)
-{
- printf ("%-*s ", svi_namelen, name);
- rprint_number (svi_sizelen, size);
- printf (" ");
- rprint_number (svi_vmalen, vma);
- printf ("\n");
-}
-
-static void
-sysv_internal_printer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec,
- void *ignore ATTRIBUTE_UNUSED)
-{
- bfd_size_type size = bfd_section_size (file, sec);
-
- if ( ! bfd_is_abs_section (sec)
- && ! bfd_is_com_section (sec)
- && ! bfd_is_und_section (sec))
- {
- svi_total += size;
-
- sysv_one_line (bfd_section_name (file, sec),
- size,
- bfd_section_vma (file, sec));
- }
-}
-
-static void
-print_sysv_format (bfd *file)
-{
- /* Size all of the columns. */
- svi_total = 0;
- svi_maxvma = 0;
- svi_namelen = 0;
- bfd_map_over_sections (file, sysv_internal_sizer, NULL);
- if (show_common)
- {
- if (svi_namelen < (int) sizeof ("*COM*") - 1)
- svi_namelen = sizeof ("*COM*") - 1;
- svi_total += common_size;
- }
-
- svi_vmalen = size_number ((bfd_size_type)svi_maxvma);
-
- if ((size_t) svi_vmalen < sizeof ("addr") - 1)
- svi_vmalen = sizeof ("addr")-1;
-
- svi_sizelen = size_number (svi_total);
- if ((size_t) svi_sizelen < sizeof ("size") - 1)
- svi_sizelen = sizeof ("size")-1;
-
- svi_total = 0;
- printf ("%s ", bfd_get_filename (file));
-
- if (bfd_my_archive (file))
- printf (" (ex %s)", bfd_get_filename (bfd_my_archive (file)));
-
- printf (":\n%-*s %*s %*s\n", svi_namelen, "section",
- svi_sizelen, "size", svi_vmalen, "addr");
-
- bfd_map_over_sections (file, sysv_internal_printer, NULL);
- if (show_common)
- {
- svi_total += common_size;
- sysv_one_line ("*COM*", common_size, 0);
- }
-
- printf ("%-*s ", svi_namelen, "Total");
- rprint_number (svi_sizelen, svi_total);
- printf ("\n\n");
-}
-
-static void
-print_sizes (bfd *file)
-{
- if (show_common)
- calculate_common_size (file);
- if (berkeley_format)
- print_berkeley_format (file);
- else
- print_sysv_format (file);
-}
diff --git a/binutils/windmc.c b/binutils/windmc.c
deleted file mode 100644
index 283c2657506..00000000000
--- a/binutils/windmc.c
+++ /dev/null
@@ -1,1206 +0,0 @@
-/* windmc.c -- a program to compile Windows message files.
- Copyright 2007, 2008
- Free Software Foundation, Inc.
- Written by Kai Tietz, Onevision.
-
- This file is part of GNU Binutils.
-
- 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 program can read and comile Windows message format.
-
- It is based on information taken from the following sources:
-
- * Microsoft documentation.
-
- * The wmc program, written by Bertho A. Stultiens (BS). */
-
-#include "sysdep.h"
-#include <assert.h>
-#include <time.h>
-#include "bfd.h"
-#include "getopt.h"
-#include "bucomm.h"
-#include "libiberty.h"
-#include "safe-ctype.h"
-#include "obstack.h"
-
-#include "windmc.h"
-#include "windint.h"
-
-/* Defines a message compiler element item with length and offset
- information. */
-typedef struct mc_msg_item
-{
- rc_uint_type res_len;
- rc_uint_type res_off;
- struct bin_messagetable_item *res;
-} mc_msg_item;
-
-/* Defined in bfd/binary.c. Used to set architecture and machine of input
- binary files. */
-extern enum bfd_architecture bfd_external_binary_architecture;
-extern unsigned long bfd_external_machine;
-
-int target_is_bigendian = 0;
-const char *def_target_arch;
-
-/* Globals and static variable definitions. */
-
-/* bfd global helper struct variable. */
-static struct
-{
- bfd *abfd;
- asection *sec;
-} mc_bfd;
-
-/* Memory list. */
-mc_node *mc_nodes = NULL;
-static mc_node_lang **mc_nodes_lang = NULL;
-static int mc_nodes_lang_count = 0;
-static mc_keyword **mc_severity_codes = NULL;
-static int mc_severity_codes_count = 0;
-static mc_keyword **mc_facility_codes = NULL;
-static int mc_facility_codes_count = 0;
-
-/* When we are building a resource tree, we allocate everything onto
- an obstack, so that we can free it all at once if we want. */
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
-/* The resource building obstack. */
-static struct obstack res_obstack;
-
-/* Flag variables. */
-/* Set by -C. Set the default code page to be used for input text file. */
-static rc_uint_type mcset_codepage_in = 0;
-
-/* Set by -O. Set the default code page to be used for output text files. */
-static rc_uint_type mcset_codepage_out = 0;
-
-/* Set by -b. .BIN filename should have .mc filename_ included for uniqueness. */
-static int mcset_prefix_bin = 0;
-
-/* The base name of the .mc file. */
-static const char *mcset_mc_basename = "unknown";
-
-/* Set by -e <ext>. Specify the extension for the header file. */
-static const char *mcset_header_ext = ".h";
-
-/* Set by -h <path>. Gives the path of where to create the C include file. */
-static const char *mcset_header_dir = "./";
-
-/* Set by -r <path>. Gives the path of where to create the RC include file
- and the binary message resource files it includes. */
-static const char *mcset_rc_dir = "./";
-
-/* Modified by -a & -u. By -u input file is unicode, by -a is ASCII (default). */
-static int mcset_text_in_is_unicode = 0;
-
-/* Modified by -A & -U. By -U bin file is unicode (default), by -A is ASCII. */
-static int mcset_bin_out_is_unicode = 1;
-
-/* Set by -c. Sets the Customer bit in all the message ID's. */
-int mcset_custom_bit = 0;
-
-/* Set by -o. Generate OLE2 header file. Use HRESULT definition instead of
- status code definition. */
-static int mcset_use_hresult = 0;
-
-/* Set by -m <msglen>. Generate a warning if the size of any message exceeds
- maxmsglen characters. */
-rc_uint_type mcset_max_message_length = 0;
-
-/* Set by -d. Sets message values in header to decimal initially. */
-int mcset_out_values_are_decimal = 0;
-
-/* Set by -n. terminates all strings with null's in the message tables. */
-static int mcset_automatic_null_termination = 0;
-
-/* The type used for message id output in header. */
-unichar *mcset_msg_id_typedef = NULL;
-
-/* Set by -x path. Geberated debug C file for mapping ID's to text. */
-static const char *mcset_dbg_dir = NULL;
-
-/* getopt long name definitions. */
-static const struct option long_options[] =
-{
- {"binprefix", no_argument, 0, 'b'},
- {"target", required_argument, 0, 'F'},
- {"extension", required_argument, 0, 'e'},
- {"headerdir", required_argument, 0, 'h'},
- {"rcdir", required_argument, 0, 'r'},
- {"verbose", no_argument, 0, 'v'},
- {"codepage_in", required_argument, 0, 'C'},
- {"codepage_out", required_argument, 0, 'O'},
- {"maxlength", required_argument, 0, 'm'},
- {"ascii_in", no_argument, 0, 'a'},
- {"ascii_out", no_argument, 0, 'A'},
- {"unicode_in", no_argument, 0, 'u'},
- {"unicode_out", no_argument, 0, 'U'},
- {"customflag", no_argument, 0, 'c'},
- {"decimal_values", no_argument, 0, 'd'},
- {"hresult_use", no_argument, 0, 'o'},
- {"nullterminate", no_argument, 0, 'n'},
- {"xdbg", required_argument, 0, 'x'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, 'H'},
- {0, no_argument, 0, 0}
-};
-
-
-/* Initialize the resource building obstack. */
-static void
-res_init (void)
-{
- obstack_init (&res_obstack);
-}
-
-/* Allocate space on the resource building obstack. */
-void *
-res_alloc (rc_uint_type bytes)
-{
- return (void *) obstack_alloc (&res_obstack, (size_t) bytes);
-}
-
-static FILE *
-mc_create_path_text_file (const char *path, const char *ext)
-{
- FILE *ret;
- size_t len = 1;
- char *hsz;
-
- len += (path != NULL ? strlen (path) : 0);
- len += strlen (mcset_mc_basename);
- len += (ext != NULL ? strlen (ext) : 0);
- hsz = xmalloc (len);
- sprintf (hsz, "%s%s%s", (path != NULL ? path : ""), mcset_mc_basename,
- (ext != NULL ? ext : ""));
- if ((ret = fopen (hsz, "wb")) == NULL)
- fatal (_("can't create %s file ,%s' for output.\n"), (ext ? ext : "text"), hsz);
- free (hsz);
- return ret;
-}
-
-static void
-usage (FILE *stream, int status)
-{
- fprintf (stream, _("Usage: %s [option(s)] [input-file]\n"),
- program_name);
- fprintf (stream, _(" The options are:\n\
- -a --ascii_in Read input file as ASCII file\n\
- -A --ascii_out Write binary messages as ASCII\n\
- -b --binprefix .bin filename is prefixed by .mc filename_ for uniqueness.\n\
- -c --customflag Set custom flags for messages\n\
- -C --codepage_in=<val> Set codepage when reading mc text file\n\
- -d --decimal_values Print values to text files decimal\n\
- -e --extension=<extension> Set header extension used on export header file\n\
- -F --target <target> Specify output target for endianess.\n\
- -h --headerdir=<directory> Set the export directory for headers\n\
- -u --unicode_in Read input file as UTF16 file\n\
- -U --unicode_out Write binary messages as UFT16\n\
- -m --maxlength=<val> Set the maximal allowed message length\n\
- -n --nullterminate Automatic add a zero termination to strings\n\
- -o --hresult_use Use HRESULT definition instead of status code definition\n\
- -O --codepage_out=<val> Set codepage used for writing text file\n\
- -r --rcdir=<directory> Set the export directory for rc files\n\
- -x --xdbg=<directory> Where to create the .dbg C include file\n\
- that maps message ID's to their symbolic name.\n\
-"));
- fprintf (stream, _("\
- -H --help Print this help message\n\
- -v --verbose Verbose - tells you what it's doing\n\
- -V --version Print version information\n"));
-
- list_supported_targets (program_name, stream);
-
- if (REPORT_BUGS_TO[0] && status == 0)
- fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
-
- exit (status);
-}
-
-static void
-set_endianess (bfd *abfd, const char *target)
-{
- const bfd_target *target_vec;
-
- def_target_arch = NULL;
- target_vec = bfd_find_target (target, abfd);
- if (! target_vec)
- fatal ("Can't detect target endianess and architecture.");
- target_is_bigendian = ((target_vec->byteorder == BFD_ENDIAN_BIG) ? 1 : 0);
-
- {
- const char * tname = target_vec->name;
- const char ** arches = bfd_arch_list ();
-
- if (arches && tname)
- {
- const char ** arch = arches;
-
- if (strchr (tname, '-') != NULL)
- tname = strchr (tname, '-') + 1;
-
- while (*arch != NULL)
- {
- const char *in_a = strstr (*arch, tname);
- char end_ch = (in_a ? in_a[strlen (tname)] : 0);
-
- if (in_a && (in_a == *arch || in_a[-1] == ':')
- && end_ch == 0)
- {
- def_target_arch = *arch;
- break;
- }
- arch++;
- }
- }
-
- free (arches);
-
- if (! def_target_arch)
- fatal ("Can't detect architecture.");
- }
-}
-
-static int
-probe_codepage (rc_uint_type *cp, int *is_uni, const char *pswitch, int defmode)
-{
- if (*is_uni == -1)
- {
- if (*cp != CP_UTF16)
- *is_uni = defmode;
- else
- *is_uni = 1;
- }
- if (*is_uni)
- {
- if (*cp != 0 && *cp != CP_UTF16)
- {
- fprintf (stderr, _("%s: warning: "), program_name);
- fprintf (stderr, _("A codepage was specified switch ,%s' and UTF16.\n"), pswitch);
- fprintf (stderr, _("\tcodepage settings are ignored.\n"));
- }
- *cp = CP_UTF16;
- return 1;
- }
- if (*cp == CP_UTF16)
- {
- *is_uni = 1;
- return 1;
- }
- if (*cp == 0)
- *cp = 1252;
- if (! unicode_is_valid_codepage (*cp))
- fatal ("Code page 0x%x is unknown.", (unsigned int) *cp);
- *is_uni = 0;
- return 1;
-}
-
-mc_node *
-mc_add_node (void)
-{
- mc_node *ret;
-
- ret = res_alloc (sizeof (mc_node));
- memset (ret, 0, sizeof (mc_node));
- if (! mc_nodes)
- mc_nodes = ret;
- else
- {
- mc_node *h = mc_nodes;
-
- while (h->next != NULL)
- h = h->next;
- h->next = ret;
- }
- return ret;
-}
-
-mc_node_lang *
-mc_add_node_lang (mc_node *root, const mc_keyword *lang, rc_uint_type vid)
-{
- mc_node_lang *ret, *h, *p;
-
- if (! lang || ! root)
- fatal (_("try to add a ill language."));
- ret = res_alloc (sizeof (mc_node_lang));
- memset (ret, 0, sizeof (mc_node_lang));
- ret->lang = lang;
- ret->vid = vid;
- if ((h = root->sub) == NULL)
- root->sub = ret;
- else
- {
- p = NULL;
- while (h != NULL)
- {
- if (h->lang->nval > lang->nval)
- break;
- if (h->lang->nval == lang->nval)
- {
- if (h->vid > vid)
- break;
- if (h->vid == vid)
- fatal ("double defined message id %ld.\n", (long) vid);
- }
- h = (p = h)->next;
- }
- ret->next = h;
- if (! p)
- root->sub = ret;
- else
- p->next = ret;
- }
- return ret;
-}
-
-static char *
-convert_unicode_to_ACP (const unichar *usz)
-{
- char *s;
- rc_uint_type l;
-
- if (! usz)
- return NULL;
- codepage_from_unicode (&l, usz, &s, mcset_codepage_out);
- if (! s)
- fatal ("unicode string not mappable to ASCII codepage 0x%lx.\n",
- (unsigned long) mcset_codepage_out);
- return s;
-}
-
-static void
-write_dbg_define (FILE *fp, const unichar *sym_name, const unichar *typecast)
-{
- char *sym;
-
- if (!sym_name || sym_name[0] == 0)
- return;
- sym = convert_unicode_to_ACP (sym_name);
- fprintf (fp, " {(");
- if (typecast)
- unicode_print (fp, typecast, unichar_len (typecast));
- else
- fprintf (fp, "DWORD");
- fprintf (fp, ") %s, \"%s\" },\n", sym, sym);
-}
-
-static void
-write_header_define (FILE *fp, const unichar *sym_name, rc_uint_type vid, const unichar *typecast, mc_node_lang *nl)
-{
- char *sym;
- char *tdef = NULL;
-
- if (!sym_name || sym_name[0] == 0)
- {
- if (nl != NULL)
- {
- if (mcset_out_values_are_decimal)
- fprintf (fp, "//\n// MessageId: 0x%lu\n//\n", (unsigned long) vid);
- else
- fprintf (fp, "//\n// MessageId: 0x%lx\n//\n", (unsigned long) vid);
- }
- return;
- }
- sym = convert_unicode_to_ACP (sym_name);
- if (typecast && typecast[0] != 0)
- tdef = convert_unicode_to_ACP (typecast);
- fprintf (fp, "//\n// MessageId: %s\n//\n", sym);
- if (! mcset_out_values_are_decimal)
- fprintf (fp, "#define %s %s%s%s 0x%lx\n\n", sym,
- (tdef ? "(" : ""), (tdef ? tdef : ""), (tdef ? ")" : ""),
- (unsigned long) vid);
- else
- fprintf (fp, "#define %s %s%s%s 0x%lu\n\n", sym,
- (tdef ? "(" : ""), (tdef ? tdef : ""), (tdef ? ")" : ""),
- (unsigned long) vid);
-}
-
-static int
-sort_mc_node_lang (const void *l, const void *r)
-{
- const mc_node_lang *l1 = *((const mc_node_lang **)l);
- const mc_node_lang *r1 = *((const mc_node_lang **)r);
-
- if (l == r)
- return 0;
- if (l1->lang != r1->lang)
- {
- if (l1->lang->nval < r1->lang->nval)
- return -1;
- return 1;
- }
- if (l1->vid == r1->vid)
- return 0;
- if (l1->vid < r1->vid)
- return -1;
- return 1;
-}
-
-static int
-sort_keyword_by_nval (const void *l, const void *r)
-{
- const mc_keyword *l1 = *((const mc_keyword **)l);
- const mc_keyword *r1 = *((const mc_keyword **)r);
- rc_uint_type len1, len2;
- int e;
-
- if (l == r)
- return 0;
- if (l1->nval != r1->nval)
- {
- if (l1->nval < r1->nval)
- return -1;
- return 1;
- }
- len1 = unichar_len (l1->usz);
- len2 = unichar_len (r1->usz);
- if (len1 <= len2)
- e = memcmp (l1->usz, r1->usz, sizeof (unichar) * len1);
- else
- e = memcmp (l1->usz, r1->usz, sizeof (unichar) * len2);
- if (e)
- return e;
- if (len1 < len2)
- return -1;
- else if (len1 > len2)
- return 1;
- return 0;
-}
-
-static void
-do_sorts (void)
-{
- mc_node *h;
- mc_node_lang *n;
- const mc_keyword *k;
- int i;
-
- /* Sort message by their language and id ascending. */
- mc_nodes_lang_count = 0;
-
- h = mc_nodes;
- while (h != NULL)
- {
- n = h->sub;
- while (n != NULL)
- {
- mc_nodes_lang_count +=1;
- n = n->next;
- }
- h = h->next;
- }
-
- if (mc_nodes_lang_count != 0)
- {
- h = mc_nodes;
- i = 0;
- mc_nodes_lang = xmalloc (sizeof (mc_node_lang *) * mc_nodes_lang_count);
-
- while (h != NULL)
- {
- n = h->sub;
- while (n != NULL)
- {
- mc_nodes_lang[i++] = n;
- n = n->next;
- }
- h = h->next;
- }
- qsort (mc_nodes_lang, (size_t) mc_nodes_lang_count, sizeof (mc_node_lang *), sort_mc_node_lang);
- }
- /* Sort facility code definitions by there id ascending. */
- i = 0;
- while ((k = enum_facility (i)) != NULL)
- ++i;
- mc_facility_codes_count = i;
- if (i != 0)
- {
- mc_facility_codes = xmalloc (sizeof (mc_keyword *) * i);
- i = 0;
- while ((k = enum_facility (i)) != NULL)
- mc_facility_codes[i++] = (mc_keyword *) k;
- qsort (mc_facility_codes, (size_t) mc_facility_codes_count, sizeof (mc_keyword *), sort_keyword_by_nval);
- }
-
- /* Sort severity code definitions by there id ascending. */
- i = 0;
- while ((k = enum_severity (i)) != NULL)
- ++i;
- mc_severity_codes_count = i;
- if (i != 0)
- {
- mc_severity_codes = xmalloc (sizeof (mc_keyword *) * i);
- i = 0;
- while ((k = enum_severity (i)) != NULL)
- mc_severity_codes[i++] = (mc_keyword *) k;
- qsort (mc_severity_codes, (size_t) mc_severity_codes_count, sizeof (mc_keyword *), sort_keyword_by_nval);
- }
-}
-
-static int
-mc_get_block_count (mc_node_lang **nl, int elems)
-{
- rc_uint_type exid;
- int i, ret;
-
- if (! nl)
- return 0;
- i = 0;
- ret = 0;
- while (i < elems)
- {
- ret++;
- exid = nl[i++]->vid;
- while (i < elems && nl[i]->vid == exid + 1)
- exid = nl[i++]->vid;
- }
- return ret;
-}
-
-static bfd *
-windmc_open_as_binary (const char *filename)
-{
- bfd *abfd;
-
- abfd = bfd_openw (filename, "binary");
- if (! abfd)
- fatal ("can't open `%s' for output", filename);
-
- return abfd;
-}
-
-static void
-target_put_16 (void *p, rc_uint_type value)
-{
- assert (!! p);
-
- if (target_is_bigendian)
- bfd_putb16 (value, p);
- else
- bfd_putl16 (value, p);
-}
-
-static void
-target_put_32 (void *p, rc_uint_type value)
-{
- assert (!! p);
-
- if (target_is_bigendian)
- bfd_putb32 (value, p);
- else
- bfd_putl32 (value, p);
-}
-
-static struct bin_messagetable_item *
-mc_generate_bin_item (mc_node_lang *n, rc_uint_type *res_len)
-{
- struct bin_messagetable_item *ret = NULL;
- rc_uint_type len;
-
- *res_len = 0;
- if (mcset_bin_out_is_unicode == 1)
- {
- unichar *ht = n->message;
- rc_uint_type txt_len;
-
- txt_len = unichar_len (n->message);
- if (mcset_automatic_null_termination && txt_len != 0)
- {
- while (txt_len > 0 && ht[txt_len - 1] > 0 && ht[txt_len - 1] < 0x20)
- ht[--txt_len] = 0;
- }
- txt_len *= sizeof (unichar);
- len = BIN_MESSAGETABLE_ITEM_SIZE + txt_len + sizeof (unichar);
- ret = res_alloc ((len + 3) & ~3);
- memset (ret, 0, (len + 3) & ~3);
- target_put_16 (ret->length, (len + 3) & ~3);
- target_put_16 (ret->flags, MESSAGE_RESOURCE_UNICODE);
- txt_len = 0;
- while (*ht != 0)
- {
- target_put_16 (ret->data + txt_len, *ht++);
- txt_len += 2;
- }
- }
- else
- {
- rc_uint_type txt_len, l;
- char *cvt_txt;
-
- codepage_from_unicode( &l, n->message, &cvt_txt, n->lang->lang_info.wincp);
- if (! cvt_txt)
- fatal ("Failed to convert message to language codepage.\n");
- txt_len = strlen (cvt_txt);
- if (mcset_automatic_null_termination && txt_len > 0)
- {
- while (txt_len > 0 && cvt_txt[txt_len - 1] > 0 && cvt_txt[txt_len - 1] < 0x20)
- cvt_txt[--txt_len] = 0;
- }
- len = BIN_MESSAGETABLE_ITEM_SIZE + txt_len + 1;
- ret = res_alloc ((len + 3) & ~3);
- memset (ret, 0, (len + 3) & ~3);
- target_put_16 (ret->length, (len + 3) & ~3);
- target_put_16 (ret->flags, 0);
- strcpy ((char *) ret->data, cvt_txt);
- }
- *res_len = (len + 3) & ~3;
- return ret;
-}
-
-static void
-mc_write_blocks (struct bin_messagetable *mtbl, mc_node_lang **nl, mc_msg_item *ml, int elems)
-{
- int i, idx = 0;
- rc_uint_type exid;
-
- if (! nl)
- return;
- i = 0;
- while (i < elems)
- {
- target_put_32 (mtbl->items[idx].lowid, nl[i]->vid);
- target_put_32 (mtbl->items[idx].highid, nl[i]->vid);
- target_put_32 (mtbl->items[idx].offset, ml[i].res_off);
- exid = nl[i++]->vid;
- while (i < elems && nl[i]->vid == exid + 1)
- {
- target_put_32 (mtbl->items[idx].highid, nl[i]->vid);
- exid = nl[i++]->vid;
- }
- ++idx;
- }
-}
-
-static void
-set_windmc_bfd_content (const void *data, rc_uint_type off, rc_uint_type length)
-{
- if (! bfd_set_section_contents (mc_bfd.abfd, mc_bfd.sec, data, off, length))
- bfd_fatal ("bfd_set_section_contents");
-}
-
-static void
-windmc_write_bin (const char *filename, mc_node_lang **nl, int elems)
-{
- unsigned long sec_length = 1;
- int block_count, i;
- mc_msg_item *mi;
- struct bin_messagetable *mtbl;
- rc_uint_type dta_off, dta_start;
-
- if (elems <= 0)
- return;
- mc_bfd.abfd = windmc_open_as_binary (filename);
- mc_bfd.sec = bfd_make_section_with_flags (mc_bfd.abfd, ".data",
- (SEC_HAS_CONTENTS | SEC_ALLOC
- | SEC_LOAD | SEC_DATA));
- if (mc_bfd.sec == NULL)
- bfd_fatal ("bfd_make_section");
- /* Requiring this is probably a bug in BFD. */
- mc_bfd.sec->output_section = mc_bfd.sec;
-
- block_count = mc_get_block_count (nl, elems);
-
- dta_off = (rc_uint_type) ((BIN_MESSAGETABLE_BLOCK_SIZE * block_count) + BIN_MESSAGETABLE_SIZE - 4);
- dta_start = dta_off = (dta_off + 3) & ~3;
- mi = xmalloc (sizeof (mc_msg_item) * elems);
- mtbl = xmalloc (dta_start);
-
- /* Clear header region. */
- memset (mtbl, 0, dta_start);
- target_put_32 (mtbl->cblocks, block_count);
- /* Prepare items section for output. */
- for (i = 0; i < elems; i++)
- {
- mi[i].res_off = dta_off;
- mi[i].res = mc_generate_bin_item (nl[i], &mi[i].res_len);
- dta_off += mi[i].res_len;
- }
- sec_length = (dta_off + 3) & ~3;
- if (! bfd_set_section_size (mc_bfd.abfd, mc_bfd.sec, sec_length))
- bfd_fatal ("bfd_set_section_size");
- /* Make sure we write the complete block. */
- set_windmc_bfd_content ("\0", sec_length - 1, 1);
-
- /* Write block information. */
- mc_write_blocks (mtbl, nl, mi, elems);
-
- set_windmc_bfd_content (mtbl, 0, dta_start);
-
- /* Write items. */
- for (i = 0; i < elems; i++)
- set_windmc_bfd_content (mi[i].res, mi[i].res_off, mi[i].res_len);
-
- free (mtbl);
- free (mi);
- bfd_close (mc_bfd.abfd);
- mc_bfd.abfd = NULL;
- mc_bfd.sec = NULL;
-}
-
-static void
-write_bin (void)
-{
- mc_node_lang *n = NULL;
- int i, c;
-
- if (! mc_nodes_lang_count)
- return;
-
- i = 0;
- while (i < mc_nodes_lang_count)
- {
- char *nd;
- char *filename;
-
- if (n && n->lang == mc_nodes_lang[i]->lang)
- {
- i++;
- continue;
- }
- n = mc_nodes_lang[i];
- c = i + 1;
- while (c < mc_nodes_lang_count && n->lang == mc_nodes_lang[c]->lang)
- c++;
- nd = convert_unicode_to_ACP (n->lang->sval);
-
- /* Prepare filename for binary output. */
- filename = xmalloc (strlen (nd) + 4 + 1 + strlen (mcset_mc_basename) + 1 + strlen (mcset_rc_dir));
- strcpy (filename, mcset_rc_dir);
- if (mcset_prefix_bin)
- sprintf (filename + strlen (filename), "%s_", mcset_mc_basename);
- strcat (filename, nd);
- strcat (filename, ".bin");
-
- /* Write message file. */
- windmc_write_bin (filename, &mc_nodes_lang[i], (c - i));
-
- free (filename);
- i = c;
- }
-}
-
-static void
-write_rc (FILE *fp)
-{
- mc_node_lang *n;
- int i, l;
-
- fprintf (fp,
- "/* Do not edit this file manually.\n"
- " This file is autogenerated by windmc. */\n\n");
- if (! mc_nodes_lang_count)
- return;
- n = NULL;
- i = 0;
- for (l = 0; l < mc_nodes_lang_count; l++)
- {
- if (n && n->lang == mc_nodes_lang[l]->lang)
- continue;
- ++i;
- n = mc_nodes_lang[l];
- fprintf (fp, "\n// Country: %s\n// Language: %s\n#pragma code_page(%u)\n",
- n->lang->lang_info.country, n->lang->lang_info.name,
- (unsigned) n->lang->lang_info.wincp);
- fprintf (fp, "LANGUAGE 0x%lx, 0x%lx\n",
- (unsigned long) (n->lang->nval & 0x3ff),
- (unsigned long) ((n->lang->nval & 0xffff) >> 10));
- fprintf (fp, "1 MESSAGETABLE \"");
- if (mcset_prefix_bin)
- fprintf (fp, "%s_", mcset_mc_basename);
- unicode_print (fp, n->lang->sval, unichar_len (n->lang->sval));
- fprintf (fp, ".bin\"\n");
- }
-}
-
-static void
-write_dbg (FILE *fp)
-{
- mc_node *h;
-
- fprintf (fp,
- "/* Do not edit this file manually.\n"
- " This file is autogenerated by windmc.\n\n"
- " This file maps each message ID value in to a text string that contains\n"
- " the symbolic name used for it. */\n\n");
-
- fprintf (fp,
- "struct %sSymbolicName\n"
- "{\n ", mcset_mc_basename);
- if (mcset_msg_id_typedef)
- unicode_print (fp, mcset_msg_id_typedef, unichar_len (mcset_msg_id_typedef));
- else
- fprintf (fp, "DWORD");
- fprintf (fp,
- " MessageId;\n"
- " char *SymbolicName;\n"
- "} %sSymbolicNames[] =\n"
- "{\n", mcset_mc_basename);
- h = mc_nodes;
- while (h != NULL)
- {
- if (h->symbol)
- write_dbg_define (fp, h->symbol, mcset_msg_id_typedef);
- h = h->next;
- }
- fprintf (fp, " { (");
- if (mcset_msg_id_typedef)
- unicode_print (fp, mcset_msg_id_typedef, unichar_len (mcset_msg_id_typedef));
- else
- fprintf (fp, "DWORD");
- fprintf (fp,
- ") 0xffffffff, NULL }\n"
- "};\n");
-}
-
-static void
-write_header (FILE *fp)
-{
- char *s;
- int i;
- const mc_keyword *key;
- mc_node *h;
-
- fprintf (fp,
- "/* Do not edit this file manually.\n"
- " This file is autogenerated by windmc. */\n\n"
- "//\n// The values are 32 bit layed out as follows:\n//\n"
- "// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1\n"
- "// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0\n"
- "// +---+-+-+-----------------------+-------------------------------+\n"
- "// |Sev|C|R| Facility | Code |\n"
- "// +---+-+-+-----------------------+-------------------------------+\n//\n"
- "// where\n//\n"
- "// C - is the Customer code flag\n//\n"
- "// R - is a reserved bit\n//\n"
- "// Code - is the facility's status code\n//\n");
-
- h = mc_nodes;
-
- fprintf (fp, "// Sev - is the severity code\n//\n");
- if (mc_severity_codes_count != 0)
- {
- for (i = 0; i < mc_severity_codes_count; i++)
- {
- key = mc_severity_codes[i];
- fprintf (fp, "// %s - %02lx\n", convert_unicode_to_ACP (key->usz),
- (unsigned long) key->nval);
- if (key->sval && key->sval[0] != 0)
- {
- if (! mcset_out_values_are_decimal)
- fprintf (fp, "#define %s 0x%lx\n", convert_unicode_to_ACP (key->sval),
- (unsigned long) key->nval);
- else
- fprintf (fp, "#define %s 0x%lu\n", convert_unicode_to_ACP (key->sval),
- (unsigned long) key->nval);
- }
- }
- fprintf (fp, "//\n");
- }
- fprintf (fp, "// Facility - is the facility code\n//\n");
- if (mc_facility_codes_count != 0)
- {
- for (i = 0; i < mc_facility_codes_count; i++)
- {
- key = mc_facility_codes[i];
- fprintf (fp, "// %s - %04lx\n", convert_unicode_to_ACP (key->usz),
- (unsigned long) key->nval);
- if (key->sval && key->sval[0] != 0)
- {
- if (! mcset_out_values_are_decimal)
- fprintf (fp, "#define %s 0x%lx\n", convert_unicode_to_ACP (key->sval),
- (unsigned long) key->nval);
- else
- fprintf (fp, "#define %s 0x%lu\n", convert_unicode_to_ACP (key->sval),
- (unsigned long) key->nval);
- }
- }
- fprintf (fp, "//\n");
- }
- fprintf (fp, "\n");
- while (h != NULL)
- {
- if (h->user_text)
- {
- s = convert_unicode_to_ACP (h->user_text);
- if (s)
- fprintf (fp, "%s", s);
- }
- if (h->symbol)
- write_header_define (fp, h->symbol, h->vid, mcset_msg_id_typedef, h->sub);
- h = h->next;
- }
-}
-
-static const char *
-mc_unify_path (const char *path)
-{
- char *end;
- char *hsz;
-
- if (! path || *path == 0)
- return "./";
- hsz = xmalloc (strlen (path) + 2);
- strcpy (hsz, path);
- end = hsz + strlen (hsz);
- if (hsz[-1] != '/' && hsz[-1] != '\\')
- strcpy (end, "/");
- while ((end = strchr (hsz, '\\')) != NULL)
- *end = '/';
- return hsz;
-}
-
-int main (int, char **);
-
-int
-main (int argc, char **argv)
-{
- FILE *h_fp;
- int c;
- char *target, *input_filename;
- int verbose;
-
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
- setlocale (LC_MESSAGES, "");
-#endif
-#if defined (HAVE_SETLOCALE)
- setlocale (LC_CTYPE, "");
-#endif
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- program_name = argv[0];
- xmalloc_set_program_name (program_name);
-
- expandargv (&argc, &argv);
-
- bfd_init ();
- set_default_bfd_target ();
-
- target = NULL;
- verbose = 0;
- input_filename = NULL;
-
- res_init ();
-
- while ((c = getopt_long (argc, argv, "C:F:O:h:e:m:r:x:aAbcdHunoUvV", long_options,
- (int *) 0)) != EOF)
- {
- switch (c)
- {
- case 'b':
- mcset_prefix_bin = 1;
- break;
- case 'e':
- {
- mcset_header_ext = optarg;
- if (mcset_header_ext[0] != '.' && mcset_header_ext[0] != 0)
- {
- char *hsz = xmalloc (strlen (mcset_header_ext) + 2);
-
- sprintf (hsz, ".%s", mcset_header_ext);
- mcset_header_ext = hsz;
- }
- }
- break;
- case 'h':
- mcset_header_dir = mc_unify_path (optarg);
- break;
- case 'r':
- mcset_rc_dir = mc_unify_path (optarg);
- break;
- case 'a':
- mcset_text_in_is_unicode = 0;
- break;
- case 'x':
- if (*optarg != 0)
- mcset_dbg_dir = mc_unify_path (optarg);
- break;
- case 'A':
- mcset_bin_out_is_unicode = 0;
- break;
- case 'd':
- mcset_out_values_are_decimal = 1;
- break;
- case 'u':
- mcset_text_in_is_unicode = 1;
- break;
- case 'U':
- mcset_bin_out_is_unicode = 1;
- break;
- case 'c':
- mcset_custom_bit = 1;
- break;
- case 'n':
- mcset_automatic_null_termination = 1;
- break;
- case 'o':
- mcset_use_hresult = 1;
- fatal ("option -o is not implemented until yet.\n");
- break;
- case 'F':
- target = optarg;
- break;
- case 'v':
- verbose ++;
- break;
- case 'm':
- mcset_max_message_length = strtol (optarg, (char **) NULL, 10);
- break;
- case 'C':
- mcset_codepage_in = strtol (optarg, (char **) NULL, 10);
- break;
- case 'O':
- mcset_codepage_out = strtol (optarg, (char **) NULL, 10);
- break;
- case '?':
- case 'H':
- usage (stdout, 0);
- break;
- case 'V':
- print_version ("windmc");
- break;
-
- default:
- usage (stderr, 1);
- break;
- }
- }
- if (input_filename == NULL && optind < argc)
- {
- input_filename = argv[optind];
- ++optind;
- }
-
- set_endianess (NULL, target);
-
- if (input_filename == NULL)
- {
- fprintf (stderr, "Error: No input file was specified.\n");
- usage (stderr, 1);
- }
- mc_set_inputfile (input_filename);
-
- if (!probe_codepage (&mcset_codepage_in, &mcset_text_in_is_unicode, "codepage_in", 0))
- usage (stderr, 1);
- if (mcset_codepage_out == 0)
- mcset_codepage_out = 1252;
- if (! unicode_is_valid_codepage (mcset_codepage_out))
- fatal ("Code page 0x%x is unknown.", (unsigned int) mcset_codepage_out);
- if (mcset_codepage_out == CP_UTF16)
- fatal ("UTF16 is no valid text output code page.");
- if (verbose)
- {
- fprintf (stderr, "// Default target is %s and it is %s endian.\n",
- def_target_arch, (target_is_bigendian ? "big" : "little"));
- fprintf (stderr, "// Input codepage: 0x%x\n", (unsigned int) mcset_codepage_in);
- fprintf (stderr, "// Output codepage: 0x%x\n", (unsigned int) mcset_codepage_out);
- }
-
- if (argc != optind)
- usage (stderr, 1);
-
- /* Initialize mcset_mc_basename. */
- {
- const char *bn, *bn2;
- char *hsz;
-
- bn = strrchr (input_filename, '/');
- bn2 = strrchr (input_filename, '\\');
- if (! bn)
- bn = bn2;
- if (bn && bn2 && bn < bn2)
- bn = bn2;
- if (! bn)
- bn = input_filename;
- else
- bn++;
- mcset_mc_basename = hsz = xstrdup (bn);
-
- /* Cut of right-hand extension. */
- if ((hsz = strrchr (hsz, '.')) != NULL)
- *hsz = 0;
- }
-
- /* Load the input file and do code page transformations to UTF16. */
- {
- unichar *u;
- rc_uint_type ul;
- char *buff;
- long flen;
- FILE *fp = fopen (input_filename, "rb");
-
- if (!fp)
- fatal (_("unable to open file ,%s' for input.\n"), input_filename);
-
- fseek (fp, 0, SEEK_END);
- flen = ftell (fp);
- fseek (fp, 0, SEEK_SET);
- buff = malloc (flen + 3);
- memset (buff, 0, flen + 3);
- fread (buff, 1, flen, fp);
- fclose (fp);
- if (mcset_text_in_is_unicode != 1)
- {
- unicode_from_codepage (&ul, &u, buff, mcset_codepage_in);
- if (! u)
- fatal ("Failed to convert input to UFT16\n");
- mc_set_content (u);
- }
- else
- {
- if ((flen & 1) != 0)
- fatal (_("input file does not seems to be UFT16.\n"));
- mc_set_content ((unichar *) buff);
- }
- free (buff);
- }
-
- while (yyparse ())
- ;
-
- do_sorts ();
-
- h_fp = mc_create_path_text_file (mcset_header_dir, mcset_header_ext);
- write_header (h_fp);
- fclose (h_fp);
-
- h_fp = mc_create_path_text_file (mcset_rc_dir, ".rc");
- write_rc (h_fp);
- fclose (h_fp);
-
- if (mcset_dbg_dir != NULL)
- {
- h_fp = mc_create_path_text_file (mcset_dbg_dir, ".dbg");
- write_dbg (h_fp);
- fclose (h_fp);
- }
- write_bin ();
-
- if (mc_nodes_lang)
- free (mc_nodes_lang);
- if (mc_severity_codes)
- free (mc_severity_codes);
- if (mc_facility_codes)
- free (mc_facility_codes);
-
- xexit (0);
- return 0;
-}