aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
AgeCommit message (Collapse)AuthorFilesLines
2020-03-14Implement NT_NETBSDCORE_LWPSTATUS (NetBSD-Core)Kamil Rytarowski1-1/+6
bfd/ChangeLog: * elf.c (elfcore_grok_netbsd_note): Add support for NT_NETBSDCORE_LWPSTATUS notes. binutils/ChangeLog: * readelf.c (get_netbsd_elfcore_note_type): Add support for NT_NETBSDCORE_LWPSTATUS notes. include/ChangeLog: * elf/common.h (NT_NETBSDCORE_LWPSTATUS): New define.
2020-03-13asan: more readelf leaksAlan Modra1-58/+94
* elfcomm.c (get_archive_member_name): Always return malloc'd string or NULL. * elfedit.c (process_archive): Tidy memory on all return paths. * readelf.c (process_archive): Likewise. (process_symbol_table): Likewise. (ba_cache): New, replacing .. (get_symbol_for_build_attribute): ..static vars here. Free strtab and symtab before loading new ones. Reject symtab without valid strtab in loop, breaking out of loop on valid symtab. (process_file): Free ba_cache symtab and strtab here, resetting ba_cache.
2020-03-12asan: readelf leaksAlan Modra1-1/+23
* readelf.c (process_section_headers): Don't just set filedata->section_headers NULL, free it first. Similarly for dynamic_symbols, dynamic_strings, dynamic_syminfo and symtab_shndx_list. Zero associated counts too. (process_object): Free symtab_shndx_list. (process_file): Free various allocated filedata tables.
2020-03-09PR25645, readelf segfault reading fuzzed alpha-vms binaryAlan Modra1-12/+12
PR 25645 * readelf.c (dump_ia64_vms_dynamic_fixups): Pass size and nmemb to get_data rather than multiplying. (dump_ia64_vms_dynamic_relocs): Likewise. (process_version_sections): Correct order of size and nmemb args in get_data call. (process_mips_specific): Likewise.
2020-03-08readelf.c: Fix a typo in commentsH.J. Lu1-1/+1
* readelf.c (get_dynamic_data): Replace "memory chekers" with "memory checkers" in comments.
2020-03-02Restore readelf's string dump to previous behaviour where newlines were ↵Nick Clifton1-7/+73
caused line breaks. PR 25543 * readelf.c (dump_section_as_strings): Display new-line characters as \n and then insert a line break. * testsuite/binutils-all/pr25543.s: New test. * testsuite/binutils-all/pr25543.d: Test driver. * testsuite/binutils-all/readelf.exp: Run the new test.
2020-02-27Fix an illegal memory access by readelf when displaying the contents of a ↵Nick Clifton1-0/+3
corrupt IA64 binary. PR 25526 * readelf.c (process_ia64_vms_dynamic_relocs): Check to see if get_data is unable to load the string table.
2020-02-26Indent labelsAlan Modra1-1/+1
Labels don't go in the first column according to standard emacs C indent rules, and I got annoyed enough at seeing diff -p show a label rather than the function name to fix this. bfd/ * aoutx.h: Indent labels correctly. Format error strings. * archive.c: Likewise. * archive64.c: Likewise. * coff-arm.c: Likewise. * coff-rs6000.c: Likewise. * coff-stgo32.c: Likewise. * cpu-arm.c: Likewise. * dwarf2.c: Likewise. * elf-ifunc.c: Likewise. * elf-properties.c: Likewise. * elf-s390-common.c: Likewise. * elf-strtab.c: Likewise. * elf.c: Likewise. * elf32-arm.c: Likewise. * elf32-bfin.c: Likewise. * elf32-cr16.c: Likewise. * elf32-csky.c: Likewise. * elf32-i386.c: Likewise. * elf32-m68k.c: Likewise. * elf32-msp430.c: Likewise. * elf32-nds32.c: Likewise. * elf32-nios2.c: Likewise. * elf32-pru.c: Likewise. * elf32-xtensa.c: Likewise. * elf64-ia64-vms.c: Likewise. * elf64-x86-64.c: Likewise. * elfcode.h: Likewise. * elfcore.h: Likewise. * elflink.c: Likewise. * elfnn-aarch64.c: Likewise. * elfnn-ia64.c: Likewise. * elfnn-riscv.c: Likewise. * elfxx-mips.c: Likewise. * elfxx-sparc.c: Likewise. * elfxx-x86.c: Likewise. * i386lynx.c: Likewise. * merge.c: Likewise. * pdp11.c: Likewise. * plugin.c: Likewise. * reloc.c: Likewise. binutils/ * elfedit.c: Indent labels correctly. * readelf.c: Likewise. * resres.c: Likewise. gas/ * config/obj-elf.c: Indent labels correctly. * config/obj-macho.c: Likewise. * config/tc-aarch64.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-crx.c: Likewise. * config/tc-frv.c: Likewise. * config/tc-i386-intel.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-mn10200.c: Likewise. * config/tc-mn10300.c: Likewise. * config/tc-nds32.c: Likewise. * config/tc-riscv.c: Likewise. * config/tc-s12z.c: Likewise. * config/tc-xtensa.c: Likewise. * config/tc-z80.c: Likewise. * read.c: Likewise. * symbols.c: Likewise. * write.c: Likewise. ld/ * emultempl/cskyelf.em: Indent labels correctly. * ldfile.c: Likewise. * ldlang.c: Likewise. * plugin.c: Likewise. opcodes/ * aarch64-asm.c: Indent labels correctly. * aarch64-dis.c: Likewise. * aarch64-gen.c: Likewise. * aarch64-opc.c: Likewise. * alpha-dis.c: Likewise. * i386-dis.c: Likewise. * nds32-asm.c: Likewise. * nfp-dis.c: Likewise. * visium-dis.c: Likewise.
2020-02-07Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add ↵Sergey Belyashov1-0/+1
DWARF debug info support to the Z80 assembler. PR 25469 bfd * archures.c: Add GBZ80 and Z80N machine values. * reloc.c: Add BFD_RELOC_Z80_16_BE. * coff-z80.c: Add support for new reloc. * coffcode.h: Add support for new machine values. * cpu-z80.c: Add support for new machine names. * elf32-z80.c: Add support for new reloc. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. binutils* readelf.c (get_machine_flags): Add support for Z80N machine number. gas * config/tc-z80.c: Add -gbz80 command line option to generate code for the GameBoy Z80. Add support for generating DWARF. * config/tc-z80.h: Add support for DWARF debug information generation. * doc/c-z80.texi: Document new command line option. * testsuite/gas/z80/gbz80_all.d: New file. * testsuite/gas/z80/gbz80_all.s: New file. * testsuite/gas/z80/z80.exp: Run the new tests. * testsuite/gas/z80/z80n_all.d: New file. * testsuite/gas/z80/z80n_all.s: New file. * testsuite/gas/z80/z80n_reloc.d: New file. include * coff/internal.h (R_IMM16BE): Define. * elf/z80.h (EF_Z80_MACH_Z80N): Define. (R_Z80_16_BE): New reloc. ld * emulparams/elf32z80.sh: Use z80 emulation. * emultempl/z80.em: Make generic to both COFF and ELF Z80 emulations. * emultempl/z80elf.em: Delete. * testsuite/ld-elf/pr22450.d: Expect to fail for the Z80. * testsuite/ld-elf/sec64k.exp: Fix Z80 assembly. * testsuite/ld-unique/pr21529.s: Avoid register name conflict. * testsuite/ld-unique/unique.s: Likewise. * testsuite/ld-unique/unique_empty.s: Likewise. * testsuite/ld-unique/unique_shared.s: Likewise. * testsuite/ld-unique/unique.d: Updated expected output. * testsuite/ld-z80/arch_z80n.d: New file. * testsuite/ld-z80/comb_arch_z80_z80n.d: New file. * testsuite/ld-z80/labels.s: Add more labels. * testsuite/ld-z80/relocs.s: Add more reloc tests. * testsuite/ld-z80/relocs_f_z80n.d: New file opcodes * z80-dis.c: Add support for GBZ80 opcodes.
2020-02-03readelf: add missing newlines to error messagesAndreas Schwab1-6/+9
* readelf.c (dump_relocations, dump_relocations) (decode_arm_unwind_bytecode, process_dynamic_section) (get_symbol_visibility, get_alpha_symbol_other): Add newline to error message.
2020-01-28Improve warning message from debuginfod support in readelf.Nick Clifton1-21/+16
* readelf.c (get_build_id): Simplify warning message about corrupt notes encountered whilst scanning for the build-id.
2020-01-24Fix issue with warning messages about corrupt debuginfod notes.Nick Clifton1-2/+2
* readelf.c (get_build_id): Fix warning messages about corrupt notes.
2020-01-22PR25417, Fix minor typosYuri Chornoivan1-1/+1
PR 25417 binutils/ * readelf.c (get_alpha_symbol_other): Fix error message typo. ld/ * ldlang.c (ldlang_open_ctf): Fix error message typo. * emultempl/z80elf.em (z80_elf_after_open): Likewise.
2020-01-13PR23560, PR23561, readelf memory leaksAlan Modra1-11/+20
PR 23560 PR 23561 * dwarf.c (display_debug_frames): Move fde_fc earlier. Free fde_fc col_type and col_offset. * readelf.c (apply_relocations): Move symsec check earlier. (free_debug_section): Free reloc_info. (process_notes_at): Free pnotes on error path. (process_object): Free dump_sects here.. (process_archive): ..not here.
2020-01-09Add support for debuginfod to the binutils (disable by default, enabled via ↵Aaron Merey1-0/+132
a configure time option). debuginfod is a lightweight web service that indexes ELF/DWARF debugging resources by build-id and serves them over HTTP. This patch enables objdump and readelf to query debuginfod servers when they are otherwise not able to find separate debug files. Binutils can be built with debuginfod using the --with-debuginfod configure option. This requires that libdebuginfod be installed and found at configure time. debuginfod is packaged with elfutils, starting with version 0.178. For more information see https://sourceware.org/elfutils/. toplevel* config/debuginfod.m4: New file. Add macro AC_DEBUGINFOD. Adds new configure option --with-debuginfod. * configure: Regenerate. * configure.ac: Call AC_DEBUGINFOD. binutils* Makefile.am (readelf_LDADD, objdump_LDADD): Add libdebuginfod. * Makefile.in: Regenerate. * NEWS: Update. * config.in: Regenerate. * configure: Regenerate. * configure.ac: Call AC_DEBUGINFOD. * doc/Makefile.in: Regenerate. * doc/binutils.texi: Add section on using binutils with debuginfod. * dwarf.c (debuginfod_fetch_separate_debug_info): New function. Query debuginfod servers for the target debug file. (load_separate_debug_info): Call debuginfod_fetch_separate_debug_info if configured with debuginfod. (load_separate_debug_files): Add file argument to load_separate_debug_info calls. * dwarf.h (get_build_id): Add declaration. * objdump.c (get_build_id): New function. Get build-id of file. * readelf.c (get_build_id): Likewise. * testsuite/binutils-all/debuginfod.exp: New tests. * testsuite/binutils-all/linkdebug.s: Add .note.gnu.build-id section.
2020-01-02Add support for the GBZ80, Z180, and eZ80 variants of the Z80 architecure. ↵Sergey Belyashov1-0/+29
Add an ELF based target for these as well. PR 25224 bfd * Makefile.am: Add z80-elf target support. * configure.ac: Likewise. * targets.c: Likewise. * config.bfd: Add z80-elf target support and new arches: ez80 and z180. * elf32-z80.c: New file. * archures.c: Add new z80 architectures: eZ80 and Z180. * coffcode.h: Likewise. * cpu-z80.c: Likewise. * bfd-in2.h: Likewise plus additional Z80 relocations. * coff-z80.c: Add new relocations for Z80 target and local label check. gas * config/tc-z80.c: Add new architectures: Z180 and eZ80. Add support for assembler code generated by SDCC. Add new relocation types. Add z80-elf target support. * config/tc-z80.h: Add z80-elf target support. Enable dollar local labels. Local labels starts from ".L". * testsuite/gas/all/fwdexp.d: Fix failure due to symbol conflict. * testsuite/gas/all/fwdexp.s: Likewise. * testsuite/gas/z80/suffix.d: Fix failure on ELF target. * testsuite/gas/z80/z80.exp: Add new tests * testsuite/gas/z80/dollar.d: New file. * testsuite/gas/z80/dollar.s: New file. * testsuite/gas/z80/ez80_adl_all.d: New file. * testsuite/gas/z80/ez80_adl_all.s: New file. * testsuite/gas/z80/ez80_adl_suf.d: New file. * testsuite/gas/z80/ez80_isuf.s: New file. * testsuite/gas/z80/ez80_z80_all.d: New file. * testsuite/gas/z80/ez80_z80_all.s: New file. * testsuite/gas/z80/ez80_z80_suf.d: New file. * testsuite/gas/z80/r800_extra.d: New file. * testsuite/gas/z80/r800_extra.s: New file. * testsuite/gas/z80/r800_ii8.d: New file. * testsuite/gas/z80/r800_z80_doc.d: New file. * testsuite/gas/z80/z180.d: New file. * testsuite/gas/z80/z180.s: New file. * testsuite/gas/z80/z180_z80_doc.d: New file. * testsuite/gas/z80/z80_doc.d: New file. * testsuite/gas/z80/z80_doc.s: New file. * testsuite/gas/z80/z80_ii8.d: New file. * testsuite/gas/z80/z80_ii8.s: New file. * testsuite/gas/z80/z80_in_f_c.d: New file. * testsuite/gas/z80/z80_in_f_c.s: New file. * testsuite/gas/z80/z80_op_ii_ld.d: New file. * testsuite/gas/z80/z80_op_ii_ld.s: New file. * testsuite/gas/z80/z80_out_c_0.d: New file. * testsuite/gas/z80/z80_out_c_0.s: New file. * testsuite/gas/z80/z80_reloc.d: New file. * testsuite/gas/z80/z80_reloc.s: New file. * testsuite/gas/z80/z80_sli.d: New file. * testsuite/gas/z80/z80_sli.s: New file. ld * Makefile.am: Add new target z80-elf * configure.tgt: Likewise. * emultempl/z80.em: Add support for eZ80 and Z180 architectures. * emulparams/elf32z80.sh: New file. * emultempl/z80elf.em: Likewise. * testsuite/ld-z80/arch_ez80_adl.d: Likewise. * testsuite/ld-z80/arch_ez80_z80.d: Likewise. * testsuite/ld-z80/arch_r800.d: Likewise. * testsuite/ld-z80/arch_z180.d: Likewise. * testsuite/ld-z80/arch_z80.d: Likewise. * testsuite/ld-z80/comb_arch_ez80_z80.d: Likewise. * testsuite/ld-z80/comb_arch_z180.d: Likewise. * testsuite/ld-z80/labels.s: Likewise. * testsuite/ld-z80/relocs.s: Likewise. * testsuite/ld-z80/relocs_b_ez80.d: Likewise. * testsuite/ld-z80/relocs_b_z80.d: Likewise. * testsuite/ld-z80/relocs_f_z80.d: Likewise. * testsuite/ld-z80/z80.exp: Likewise. opcodes * z80-dis.c: Add support for eZ80 and Z80 instructions.
2020-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2019-12-23Revise sleb128 and uleb128 readerAlan Modra1-154/+71
This patch catches and reports errors when reading leb128 values, addressing a FIXME in read_leb128. * dwarf.h (read_leb128): Update prototype. (report_leb_status): New inline function. (SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Define. * dwarf.c: Use above macros throughout file. Formatting. (read_leb128): Reorder params. Add status return param. Don't stop reading until finding terminator or end of data. Detect loss of significant bits. Sign extend only on terminating byte. (read_sleb128, read_uleb128): Delete functions. (SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Delete macros. (read_and_print_leb128): Rewrite. (process_extended_line_op): Return a size_t. Use size_t vars. Adjust to suit new macros. Add proper name size to "data" when processing DW_LNE_define_file. (process_abbrev_section): Adjust to suit new macros. (decode_location_expression, skip_attr_bytes): Likewise. (get_type_signedness): Likewise. (read_and_display_attr_value): Likewise. Consolidate block code. (process_debug_info): Adjust to suit new macros. (display_formatted_table, display_debug_lines_raw): Likewise. (display_debug_lines_decoded): Likewise. Properly check for end of DW_LNS_extended_op. (display_debug_macinfo): Adjust to suit new macros. (get_line_filename_and_dirname, display_debug_macro): Likewise. (display_view_pair_list): Likewise. Don't back off when hitting end of data. (display_loc_list): Adjust to suit new macros. (display_loclists_list, display_loc_list_dwo): Likewise. (display_debug_rnglists_list, read_cie): Likewise. (display_debug_frames): Likewise. * readelf.c: Use new ULEB macros throughout file. (read_uleb128): Delete. (decode_arm_unwind_bytecode): Use read_leb128. (decode_tic6x_unwind_bytecode): Likewise. (display_tag_value): Adjust to suit new macros. (display_arc_attribute, display_arm_attribute): Likewise. (display_gnu_attribute, display_power_gnu_attribute): Likewise. (display_s390_gnu_attribute, display_sparc_gnu_attribute): Likewise. (display_mips_gnu_attribute, display_tic6x_attribute): Likewise. (display_msp430x_attribute, display_msp430_gnu_attribute): Likewise. (display_riscv_attribute, process_attributes): Likewise.
2019-11-28binutils: Rename init_dwarf_regnamesAndrew Burgess1-1/+1
As part of a process to change how dwarf.c figures out the correct name for a register I wanted to clean up how we initialise the register name tracking state. As part of this I rename init_dwarf_regnames to init_dwarf_regnames_by_elf_machine_code, later commits will add a different entry point to initialise the register name state. There should be no user visible changes after this commit. binutils/ChangeLog: * dwarf.c (init_dwarf_regnames): Renamed to... (init_dwarf_regnames_by_elf_machine_code): ...this. * dwarf.h (init_dwarf_regnames): Renamed to... (init_dwarf_regnames_by_elf_machine_code): ...this. * readelf.c (process_file_header): Update call to use new name. Change-Id: Ic8d2ef5fb62a8590ecd8cbb7e6258e11c6263594
2019-11-06Fix an off-by-one error in the IN_RANGE macro used by readelf. Add another ↵Christian Eggers1-3/+7
use of the macro. * readelf.c (IN_RANGE): Rename parameter OFF to NELEM. Add comment. Catch potential integer overflow and fix off by one error whilst checking reloc location against section size. (apply_relocations): Use IN_RANGE macro.
2019-10-25readelf PT_PHDR checkAlan Modra1-5/+11
When PT_PHDR isn't covered by a PT_LOAD header, p_vaddr in PT_PHDR isn't valid but the value might just pass a vaddr test. So test p_offset as well. * readelf.c (process_program_headers): Check PT_PHDR p_offset as well as p_vaddr. Use p_filesz, not p_memsz, in vaddr test.
2019-10-07Add support for new functionality in the msp430 backend of GCC.Jozef Lawrynowicz1-1/+31
This functionality will generate a new GNU object attribute for the "data region" has been added. This object attribute is used mark whether the compiler has generated code assuming that data could be in the upper or lower memory regions. Code which assumes data is always in the lower memory region is incompatible with code which uses the full memory range for data. The patch also adds a new assembler directive ".mspabi_attribute" to handle the existing MSPABI object attributes. GCC will now emit both .gnu_attribute and .mspabi_attribute directives to indicate what options the source file was compiled with. The assembler will now check the values set in these directives against the options that the it has been invoked with. If there is a discrepancy, the assembler will exit with an error. bfd * elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Rename to.. (elf32_msp430_merge_msp430_attributes): Add support for merging the GNU object attribute for data region. binutils* readelf.c (display_msp430_gnu_attribute): New. (process_arch_specific): Use msp430 specific handler for GNU attributes. gas * config/tc-msp430.c (md_parse_option): Set lower_data_region_only to FALSE if the data region is set to "upper", "either" or "none". (msp430_object_attribute): New. (md_pseudo_table): Handle .mspabi_attribute and .gnu_attribute. (msp430_md_end): Replace hard-coded attribute values with enums. Handle data region object attribute. * doc/as.texi: Document MSP430 Data Region object attribute. * doc/c-msp430.texi: Document the .mspabi_attribute directive. * testsuite/gas/msp430/attr-430-small-bad.d: New test. * testsuite/gas/msp430/attr-430-small-bad.l: New test. * testsuite/gas/msp430/attr-430-small-good.d: New test. * testsuite/gas/msp430/attr-430-small.s: New test. * testsuite/gas/msp430/attr-430x-large-any-bad.d: New test. * testsuite/gas/msp430/attr-430x-large-any-bad.l: New test. * testsuite/gas/msp430/attr-430x-large-any-good.d: New test. * testsuite/gas/msp430/attr-430x-large-any.s: New test. * testsuite/gas/msp430/attr-430x-large-lower-bad.d: New test. * testsuite/gas/msp430/attr-430x-large-lower-bad.l: New test. * testsuite/gas/msp430/attr-430x-large-lower-good.d: New test. * testsuite/gas/msp430/attr-430x-large-lower.s: New test. * testsuite/gas/msp430/msp430.exp: Run new tests. include * elf/msp430.h: Add enums for MSPABI and GNU object attribute tag names and values. ld * testsuite/ld-msp430-elf/attr-gnu-main.s: New test. * testsuite/ld-msp430-elf/attr-gnu-obj.s: New test. * testsuite/ld-msp430-elf/attr-gnu-region-lower-upper.d: New test. * testsuite/ld-msp430-elf/attr-gnu-region-lower.d: New test. * testsuite/ld-msp430-elf/attr-gnu-region-upper.d: New test. * testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
2019-10-03binutils: spaces -> tabs in CTF parts of objdump and readelfNick Alcock1-11/+11
For readelf particularly, this is more or less whistling in the dark: there are hundreds of lines where spaces are used where tabs were used on adjacent lines. New in v5. binutils/ * objdump.c (main): Fix tabdamage. * readelf.c (CTF_DUMP): Likewise. (options): Likewise. (dump_section_as_ctf): Likewise.
2019-10-03binutils: readelf: when dumping CTF, load strtab and symtab automaticallyNick Alcock1-2/+8
We were only loading them when explicitly requested, which leads to strings that point off into empty space (into the non-loaded "external" ELF string table). Avoid this unfortunate consequence by loading the strtab and symtab by default, unless a blank name is given. binutils/ * readelf.c (dump_ctf_symtab_name): Give default value. (dump_ctf_strtab_name): Likewise. (dump_section_as_ctf): Allow for the null string.
2019-10-03libctf, binutils: dump the CTF headerNick Alcock1-3/+4
The CTF header has before now been thrown away too soon to be dumped using the ctf_dump() machinery used by objdump and readelf: instead, a kludge involving debugging-priority dumps of the header offsets on every open was used. Replace this with proper first-class dumping machinery just like everything else in the CTF file, and have objdump and readelf use it. (The dumper already had an enum value in ctf_sect_names_t for this purpose, waiting to be used.) v5: fix tabdamage. libctf/ * ctf-impl.h (ctf_file_t): New field ctf_openflags. * ctf-open.c (ctf_bufopen): Set it. No longer dump header offsets. * ctf-dump.c (dump_header): New function, dump the CTF header. (ctf_dump): Call it. (ctf_dump_header_strfield): New function. (ctf_dump_header_sectfield): Likewise. binutils/ * objdump.c (dump_ctf_archive_member): Dump the CTF header. * readelf.c (dump_section_as_ctf): Likewise.
2019-09-30PR25046, readelf "Reading xxx bytes extends past end of file for dynamic ↵Alan Modra1-3/+3
section" PR 25046 * readelf.c (process_program_headers): Clear dynamic_addr and dynamic_size earlier.
2019-08-16PR24909, Uninitialized use on stack in readelfAlan Modra1-6/+3
PR 24909 PR 23499 * readelf.c (get_symbol_version_string): Set sym_info earlier.
2019-08-09Add support for a MIPS specific .MIPS.xhash section.Mihailo Stojanovic1-4/+48
This patch is a reimplementation of [1] which was submitted in 2015 by Neil Schellenberger. Copyright issue was sorted out [2] last year. It proposed a new section (.gnu.xhash) and related dynamic tag (DT_GNU_XHASH). The new section would be virtually identical to the existing .gnu.hash except for the translation table (xlat) which would contain correct MIPS .dynsym indexes corresponding to the hashvals in chains. This is because MIPS ABI imposes a different ordering on the dynsyms than the one expected by the .gnu.hash section. Another addition would be a leading word (ngnusyms) which would contain the number of entries in the translation table. In this patch, the new section name and dynamic tag are changed to reflect the fact that the section should be treated as MIPS-specific (.MIPS.xhash and DT_MIPS_XHASH). This patch addresses the alignment issue as reported in [3], which is caused by the leading word added to the .MIPS.xhash section. Leading word is removed in this patch, and the number of entries in the translation table is now calculated using DT_MIPS_SYMTABNO dynamic tag (this is addressed by the corresponding glibc patch). Suggestions on coding style in [4] were taken into account. Existing GNU hash testcase was covered, and another one was added in the MIPS part of the testsuite. The other major change is reserving MIPS ABI version 5 for .MIPS.xhash, marking the need of support for .MIPS.xhash in the dynamic linker (again, addressed in the corresponding glibc patch). This is something which I am not sure of, especially after reading [5]. I am confused on whether this ABI version is reserved for IFUNC, or it can be used for this purpose. Already mentioned glibc patch is submitted at: https://sourceware.org/ml/libc-alpha/2019-06/msg00456.html [1] https://sourceware.org/ml/binutils/2015-10/msg00057.html [2] https://sourceware.org/ml/binutils/2018-03/msg00025.html [3] https://sourceware.org/ml/binutils/2016-01/msg00006.html [4] https://sourceware.org/ml/binutils/2016-02/msg00097.html [5] https://sourceware.org/ml/libc-alpha/2016-12/msg00853.html ld * emulparams/elf32bmip.sh: Add .MIPS.xhash section. * emulparams/elf32bmipn32-defs.sh: Add .MIPS.xhash section. * emulparams/elf64bmip-defs.sh: Add .MIPS.xhash section. * emultempl/mipself.em: Remove mips_after_parse function. * testsuite/ld-elf/hash.d: Update comment. * testsuite/ld-mips-elf/hash1.d: New test. * testsuite/ld-mips-elf/hash1.s: Ditto. * testsuite/ld-mips-elf/hash1a.d: Remove. * testsuite/ld-mips-elf/hash1b.d: Ditto. * testsuite/ld-mips-elf/hash1c.d: Ditto * testsuite/ld-mips-elf/hash2.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: New tests. * testsuite/ld-mips-elf/start.s: New test. bfd * elf-bfd.h (struct elf_backend_data): New members. * elflink.c (_bfd_elf_link_create_dynamic_sections): Create .gnu.hash section if necessary. (struct collect_gnu_hash_codes): New member. (elf_gnu_hash_process_symidx): New function name. (elf_renumber_gnu_hash_syms): Ignore local and undefined symbols. Record xlat location for every symbol which should have a .MIPS.xhash entry. (bfd_elf_size_dynamic_sections): Add DT_GNU_HASH dynamic tag to dynamic section if necessary. (GNU_HASH_SECTION_NAME): New define. (bfd_elf_size_dynsym_hash_dynstr): Get .MIPS.xhash section. Update the section size info. * elfxx-mips.c (struct mips_elf_hash_sort_data): New members. (struct mips_elf_link_hash_entry): New member. (mips_elf_link_hash_newfunc): Initialize .MIPS.xhash translation table location. (mips_elf_sort_hash_table): Initialize the pointer to the .MIPS.xhash section. (mips_elf_sort_hash_table_f): Populate the .MIPS.xhash translation table entry with the symbol dynindx. (_bfd_mips_elf_section_from_shdr): Add SHT_MIPS_XHASH. (_bfd_mips_elf_fake_sections): Initialize .MIPS.xhash section info. (_bfd_mips_elf_create_dynamic_sections): Create .MIPS.xhash section. (_bfd_mips_elf_size_dynamic_sections): Add DT_MIPS_XHASH tag to dynamic section. (_bfd_mips_elf_finish_synamic_sections): Add DT_MIPS_XHASH. (_bfd_mips_elf_final_write_processing): Set .MIPS.xhash section sh_link info. (_bfd_mips_elf_get_target_dtag): Get DT_MIPS_XHASH tag. (MIPS_LIBC_ABI_XHASH): New ABI version enum value. (_bfd_mips_post_process_headers): Mark the ABI version as MIPS_LIBC_ABI_XHASH if there exists a .MIPS.xhash section, but not a .hash section. (_bfd_mips_elf_record_xhash_symbol): New function. Record a position in the translation table, associated with the hash entry. * elfxx-mips.h (literal_reloc_p): Define elf_backend_record_xhash_symbol backend hook. * elfxx-target.h: Initialize elf_backend_record_xhash_symbol backend hook. include * elf/mips.h (SHT_GNU_XHASH): New define. (DT_GNU_XHASH): New define. binutils * readelf.c (get_mips_dynamic_type): Return MIPS_XHASH dynamic type. (get_mips_section_type_name): Return MI{S_XHASH name string. (dynamic_section_mips_val): Initialize the .MIPS.xhash dynamic info. (process_symbol_table): Initialize the .MIPS.xhash section pointer. Adjust the readelf output to support the new section. (process_object): Set the .MIPS.xhash dynamic info to zero.
2019-08-08Change the output of readelf's note display so that the "Data size" column ↵Nick Clifton1-1/+1
header is left justified. PR 24887 binutils* readelf.c (process_notes_at): Left justify the "Data size" column heading. * testsuite/binutils-all/i386/empty.d: Adjust for new output format. * testsuite/binutils-all/i386/ibt.d: Likewise. * testsuite/binutils-all/i386/pr21231a.d: Likewise. * testsuite/binutils-all/i386/pr21231b.d: Likewise. * testsuite/binutils-all/i386/shstk.d: Likewise. * testsuite/binutils-all/note-2-32.d: Likewise. * testsuite/binutils-all/note-2-64.d: Likewise. * testsuite/binutils-all/x86-64/empty-x32.d: Likewise. * testsuite/binutils-all/x86-64/empty.d: Likewise. * testsuite/binutils-all/x86-64/ibt-x32.d: Likewise. * testsuite/binutils-all/x86-64/ibt.d: Likewise. * testsuite/binutils-all/x86-64/pr21231a.d: Likewise. * testsuite/binutils-all/x86-64/pr21231b.d: Likewise. * testsuite/binutils-all/x86-64/pr23494a-x32.d: Likewise. * testsuite/binutils-all/x86-64/pr23494a.d: Likewise. * testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise. * testsuite/binutils-all/x86-64/pr23494c.d: Likewise. * testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise. * testsuite/binutils-all/x86-64/pr23494d.d: Likewise. * testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise. * testsuite/binutils-all/x86-64/pr23494e.d: Likewise. * testsuite/binutils-all/x86-64/shstk-x32.d: Likewise. * testsuite/binutils-all/x86-64/shstk.d: Likewise. ld * testsuite/ld-aarch64/bti-plt-2.d: Adjust for new output format from readelf. * testsuite/ld-aarch64/bti-plt-4.d: Likewise. * testsuite/ld-aarch64/bti-plt-6.d: Likewise. * testsuite/ld-aarch64/bti-plt-7.d: Likewise. * testsuite/ld-aarch64/bti-warn.d: Likewise. * testsuite/ld-aarch64/property-bti-pac1.d: Likewise. * testsuite/ld-aarch64/property-bti-pac2.d: Likewise. * testsuite/ld-aarch64/property-bti-pac3.d: Likewise. * testsuite/ld-elf/x86-feature-1a.rd: Likewise. * testsuite/ld-elf/x86-feature-1b.rd: Likewise. * testsuite/ld-elf/x86-feature-1c.rd: Likewise. * testsuite/ld-elf/x86-feature-1d.rd: Likewise. * testsuite/ld-elf/x86-feature-1e.rd: Likewise. * testsuite/ld-i386/ibt-plt-2d.d: Likewise. * testsuite/ld-i386/ibt-plt-3d.d: Likewise. * testsuite/ld-i386/pr23372a.d: Likewise. * testsuite/ld-i386/pr23372c.d: Likewise. * testsuite/ld-i386/pr23486a.d: Likewise. * testsuite/ld-i386/pr23486b.d: Likewise. * testsuite/ld-i386/pr23486c.d: Likewise. * testsuite/ld-i386/pr23486d.d: Likewise. * testsuite/ld-i386/pr24322a.d: Likewise. * testsuite/ld-i386/pr24322b.d: Likewise. * testsuite/ld-i386/property-x86-3.d: Likewise. * testsuite/ld-i386/property-x86-4a.d: Likewise. * testsuite/ld-i386/property-x86-5.d: Likewise. * testsuite/ld-i386/property-x86-cet1.d: Likewise. * testsuite/ld-i386/property-x86-cet2a.d: Likewise. * testsuite/ld-i386/property-x86-cet5a.d: Likewise. * testsuite/ld-i386/property-x86-cet5b.d: Likewise. * testsuite/ld-i386/property-x86-ibt1a.d: Likewise. * testsuite/ld-i386/property-x86-ibt1b.d: Likewise. * testsuite/ld-i386/property-x86-ibt2.d: Likewise. * testsuite/ld-i386/property-x86-ibt3a.d: Likewise. * testsuite/ld-i386/property-x86-ibt3b.d: Likewise. * testsuite/ld-i386/property-x86-ibt4.d: Likewise. * testsuite/ld-i386/property-x86-ibt5.d: Likewise. * testsuite/ld-i386/property-x86-shstk1a.d: Likewise. * testsuite/ld-i386/property-x86-shstk1b.d: Likewise. * testsuite/ld-i386/property-x86-shstk2.d: Likewise. * testsuite/ld-i386/property-x86-shstk3a.d: Likewise. * testsuite/ld-i386/property-x86-shstk3b.d: Likewise. * testsuite/ld-i386/property-x86-shstk4.d: Likewise. * testsuite/ld-i386/property-x86-shstk5.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d.d: Likewise. * testsuite/ld-x86-64/pr23372a-x32.d: Likewise. * testsuite/ld-x86-64/pr23372a.d: Likewise. * testsuite/ld-x86-64/pr23372c-x32.d: Likewise. * testsuite/ld-x86-64/pr23372c.d: Likewise. * testsuite/ld-x86-64/pr23486a-x32.d: Likewise. * testsuite/ld-x86-64/pr23486a.d: Likewise. * testsuite/ld-x86-64/pr23486b-x32.d: Likewise. * testsuite/ld-x86-64/pr23486b.d: Likewise. * testsuite/ld-x86-64/pr23486c-x32.d: Likewise. * testsuite/ld-x86-64/pr23486c.d: Likewise. * testsuite/ld-x86-64/pr23486d-x32.d: Likewise. * testsuite/ld-x86-64/pr23486d.d: Likewise. * testsuite/ld-x86-64/pr24322a-x32.d: Likewise. * testsuite/ld-x86-64/pr24322a.d: Likewise. * testsuite/ld-x86-64/pr24322b-x32.d: Likewise. * testsuite/ld-x86-64/pr24322b.d: Likewise. * testsuite/ld-x86-64/pr24458a-x32.d: Likewise. * testsuite/ld-x86-64/pr24458a.d: Likewise. * testsuite/ld-x86-64/pr24458b-x32.d: Likewise. * testsuite/ld-x86-64/pr24458b.d: Likewise. * testsuite/ld-x86-64/pr24458c-x32.d: Likewise. * testsuite/ld-x86-64/pr24458c.d: Likewise. * testsuite/ld-x86-64/property-1.r: Likewise. * testsuite/ld-x86-64/property-1a.r: Likewise. * testsuite/ld-x86-64/property-2.r: Likewise. * testsuite/ld-x86-64/property-2a.r: Likewise. * testsuite/ld-x86-64/property-3.r: Likewise. * testsuite/ld-x86-64/property-3a.r: Likewise. * testsuite/ld-x86-64/property-4.r: Likewise. * testsuite/ld-x86-64/property-4a.r: Likewise. * testsuite/ld-x86-64/property-5.r: Likewise. * testsuite/ld-x86-64/property-5a.r: Likewise. * testsuite/ld-x86-64/property-6.r: Likewise. * testsuite/ld-x86-64/property-7.r: Likewise. * testsuite/ld-x86-64/property-7a.r: Likewise. * testsuite/ld-x86-64/property-x86-3-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-3.d: Likewise. * testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-4a.d: Likewise. * testsuite/ld-x86-64/property-x86-5-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-5.d: Likewise. * testsuite/ld-x86-64/property-x86-cet1-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-cet1.d: Likewise. * testsuite/ld-x86-64/property-x86-cet2a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-cet2a.d: Likewise. * testsuite/ld-x86-64/property-x86-cet5a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-cet5a.d: Likewise. * testsuite/ld-x86-64/property-x86-cet5b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-cet5b.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt2.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt4.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-ibt5.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk2.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk4.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk5.d: Likewise. gas * testsuite/gas/i386/property-1.d: Adjust for new output format from readelf. * testsuite/gas/i386/property-2.d: Likewise. * testsuite/gas/i386/x86-64-property-1.d: Likewise. * testsuite/gas/i386/x86-64-property-2.d: Likewise.
2019-08-08readelf: mask unknown description data bytes.Jordan Rupprecht via binutils1-1/+1
When printing unknown note types, readelf prints the raw description section byte-by-byte. However, it does not mask appropriately, e.g. it prints the byte 'ba' as 'ffffffba'. * readelf.c (process_note): Mask unknown description data bytes.
2019-08-08Integer overflows in readelf get_dataAlan Modra1-8/+6
I noticed the test for overflow of amt = size * nmemb in get_data wasn't effective. An obvious example of nmemb = 3 and size = half max value overflows but doesn't result in amt < nmemb. This patch fixes this problem and reports a size truncation or overflow rather than out of memory in more cases. * readelf.c (get_data): Improve overflow checks.
2019-08-07PR24876, readelf: heap-buffer-overflow in dump_ia64_unwindAlan Modra1-1/+2
PR 24876 * readelf.c (dump_ia64_unwind): Check that buffer is large enough for "stamp" before reading.
2019-08-05Catch potential integer overflow in readelf when processing corrupt binaries.Nick Clifton1-1/+1
PR 24829 * readelf.c (apply_relocations): Catch potential integer overflow whilst checking reloc location against section size.
2019-08-02PR24871, readelf segv in dump_ia64_unwindAlan Modra1-7/+15
PR 24871 * readelf.c (ABSADDR): Delete. (dump_ia64_unwind): Expand ABSADDR. Check validity of info.section.
2019-07-25Stop an illegal memory access by readelf when parsing a corrupt MIPS binary ↵Nick Clifton1-4/+35
file. PR 24837 * readelf.c (process_mips_specific): Check for buffer overflow before reading reginfo information.
2019-07-23SHF_GNU_MBIND requires ELFOSABI_GNUAlan Modra1-43/+56
When SHF_GNU_MBIND was added in the SHF_LOOS to SHF_HIOS range, it should have required ELFOSABI_GNU since these flags are already in use by other OSes. HPUX SHF_HP_TLS in fact has the same value. That means no place in binutils should test SHF_GNU_MBIND without first checking OSABI, and SHF_GNU_MBIND should not be set without also setting OSABI. At least, that's the ideal, but the patch accepts SHF_GNU_MBIND on ELFOSABI_NONE object files since gas didn't always set OSABI. However, to reinforce the fact that SHF_GNU_MBIND isn't proper without a non-zero OSABI, readelf will display the flag as LOOS+0 if OSABI isn't set. The clash with SHF_HP_TLS means that hppa64-linux either has that flag on .tbss sections or supports GNU_MBIND, not both. (hppa64-linux users, if there are any, may have noticed that GNU ld since 2017 mysteriously aligned their .tbss sections to a 4k boundary. That was one consequence of SHF_HP_TLS being blindly interpreted as SHF_GNU_MBIND.) Since it seems that binutils, gdb, gcc, glibc, and the linux kernel don't care about SHF_HP_TLS I took that flag out of .tbss for hppa64-linux. bfd/ * elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_mbind. * elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_mbind. (get_program_header_size): Formatting. Only test SH_GNU_MBIND when elf_gnu_osabi_mbind is set. (_bfd_elf_map_sections_to_segments): Likewise. (_bfd_elf_init_private_section_data): Likewise. (_bfd_elf_final_write_processing): Update comment. * elf64-hppa.c (elf64_hppa_special_sections): Move .tbss entry. (elf_backend_special_sections): Define without .tbss for linux. binutils/ * readelf.c (get_parisc_segment_type): Split off hpux entries.. (get_ia64_segment_type): ..and these.. (get_hpux_segment_type): ..to here. (get_segment_type): Condition GNU_MBIND on osabi. Use get_hpux_segment_type. (get_symbol_binding): Do not print UNIQUE for ELFOSABI_NONE. (get_symbol_type): Do not print IFUNC for ELFOSABI_NONE. gas/ * config/obj-elf.c (obj_elf_change_section): Don't emit a fatal error for non-SHF_ALLOC SHF_GNU_MBIND here. (obj_elf_parse_section_letters): Return SHF_GNU_MBIND in new gnu_attr param. (obj_elf_section): Adjust obj_elf_parse_section_letters call. Formatting. Set SHF_GNU_MBIND and elf_osabi from gnu_attr. Emit normal error for non-SHF_ALLOC SHF_GNU_MBIND and wrong osabi. (obj_elf_type): Set elf_osabi for ifunc. * testsuite/gas/elf/section12a.d: xfail msp430 and hpux. * testsuite/gas/elf/section12b.d: Likewise. * testsuite/gas/elf/section13.d: Likewise. * testsuite/gas/elf/section13.l: Adjust expected error. ld/ * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Condition SHF_GNU_MBIND on osabi. Set output elf_gnu_osabi_mbind.
2019-06-25readelf: avoid shadowing a libiberty symbolJan Beulich1-2/+2
With my (oldish) gcc I'm seeing .../binutils/readelf.c: In function ‘dump_ctf_indent_lines’: .../binutils/readelf.c:13851: error: declaration of ‘spaces’ shadows a global declaration .../binutils/../include/libiberty.h:253: error: shadowed declaration is here
2019-06-12Add support for NetBSD PaX notes to readelf.Christos Zoulas1-15/+32
PR 24663 * readelf.c (process_netbsd_elf_note): Add support for NT_NETBSD_PAX. (process_note): Add support for PaX notes.
2019-06-12Add support for NetBSD/sh3 core reg sections to readelf.Christos Zoulas1-0/+17
PR 24665 * readelf.c (get_netbsd_elfcore_note_type): Add support for SH core notes.
2019-06-12Add support to readelf to display NetBSD auxv notes in core files.Christos Zoulas1-10/+21
PR 24664 * readelf.c (get_netbsd_elfcore_note_type): Add support for NetBSD auxv notes.
2019-06-11Add support for reporting Alpha and Vax symbol visibility in readelf.Christos Zoulas1-0/+18
PR 24662 * readelf.c (get_alpha_symbol_other): New function. (get_symbol_other): Use for Alpha symbols. (is_32bit_pcrel_reloc): Add R_VAX_PCREL32.
2019-06-11Fix an unitinitalised local variable in decode_arm_unwind().Christos Zoulas1-0/+5
PR 24661 * readelf.c (decode_arm_unwind): Ensure that the local variable 'addr' is always initialised.
2019-06-03Revert patch that disables building libctf for non-ELF based targets.Nick Clifton1-22/+0
Revert: binutls 2019-05-29 Nick Clifton <nickc@redhat.com> * configure.ac (LIBCTF): Export. Set to empty for non-ELF based targets. (HAVE_LIBCTF): Define if libctf support is available. * Makefile.am (LIBCTF): Set value to @LIBCTF@. * objdump.c: Make CTF code conditional upon HAVE_LIBCTF being defined. * readelf.c: Likewise. * configure: Regenerate. * Makefile.in: Regenerate. * config.in: Regenerate. top 2019-05-29 Nick Clifton <nickc@redhat.com> * configure.ac (noconfigdirs): Add libctf if the target does not use the ELF file format. * configure: Regenerate.
2019-05-31libctf: fix a number of build problems found on Solaris and NetBSDJose E. Marchesi1-3/+0
- Use of nonportable <endian.h> - Use of qsort_r - Use of zlib without appropriate magic to pull in the binutils zlib - Use of off64_t without checking (fixed by dropping the unused fields that need off64_t entirely) - signedness problems due to long being too short a type on 32-bit platforms: ctf_id_t is now 'unsigned long', and CTF_ERR must be used only for functions that return ctf_id_t - One lingering use of bzero() and of <sys/errno.h> All fixed, using code from gnulib where possible. Relatedly, set cts_size in a couple of places it was missed (string table and symbol table loading upon ctf_bfdopen()). binutils/ * objdump.c (make_ctfsect): Drop cts_type, cts_flags, and cts_offset. * readelf.c (shdr_to_ctf_sect): Likewise. include/ * ctf-api.h (ctf_sect_t): Drop cts_type, cts_flags, and cts_offset. (ctf_id_t): This is now an unsigned type. (CTF_ERR): Cast it to ctf_id_t. Note that it should only be used for ctf_id_t-returning functions. libctf/ * Makefile.am (ZLIB): New. (ZLIBINC): Likewise. (AM_CFLAGS): Use them. (libctf_a_LIBADD): New, for LIBOBJS. * configure.ac: Check for zlib, endian.h, and qsort_r. * ctf-endian.h: New, providing htole64 and le64toh. * swap.h: Code style fixes. (bswap_identity_64): New. * qsort_r.c: New, from gnulib (with one added #include). * ctf-decls.h: New, providing a conditional qsort_r declaration, and unconditional definitions of MIN and MAX. * ctf-impl.h: Use it. Do not use <sys/errno.h>. (ctf_set_errno): Now returns unsigned long. * ctf-util.c (ctf_set_errno): Adjust here too. * ctf-archive.c: Use ctf-endian.h. (ctf_arc_open_by_offset): Use memset, not bzero. Drop cts_type, cts_flags and cts_offset. (ctf_arc_write): Drop debugging dependent on the size of off_t. * ctf-create.c: Provide a definition of roundup if not defined. (ctf_create): Drop cts_type, cts_flags and cts_offset. (ctf_add_reftype): Do not check if type IDs are below zero. (ctf_add_slice): Likewise. (ctf_add_typedef): Likewise. (ctf_add_member_offset): Cast error-returning ssize_t's to size_t when known error-free. Drop CTF_ERR usage for functions returning int. (ctf_add_member_encoded): Drop CTF_ERR usage for functions returning int. (ctf_add_variable): Likewise. (enumcmp): Likewise. (enumadd): Likewise. (membcmp): Likewise. (ctf_add_type): Likewise. Cast error-returning ssize_t's to size_t when known error-free. * ctf-dump.c (ctf_is_slice): Drop CTF_ERR usage for functions returning int: use CTF_ERR for functions returning ctf_type_id. (ctf_dump_label): Likewise. (ctf_dump_objts): Likewise. * ctf-labels.c (ctf_label_topmost): Likewise. (ctf_label_iter): Likewise. (ctf_label_info): Likewise. * ctf-lookup.c (ctf_func_args): Likewise. * ctf-open.c (upgrade_types): Cast to size_t where appropriate. (ctf_bufopen): Likewise. Use zlib types as needed. * ctf-types.c (ctf_member_iter): Drop CTF_ERR usage for functions returning int. (ctf_enum_iter): Likewise. (ctf_type_size): Likewise. (ctf_type_align): Likewise. Cast to size_t where appropriate. (ctf_type_kind_unsliced): Likewise. (ctf_type_kind): Likewise. (ctf_type_encoding): Likewise. (ctf_member_info): Likewise. (ctf_array_info): Likewise. (ctf_enum_value): Likewise. (ctf_type_rvisit): Likewise. * ctf-open-bfd.c (ctf_bfdopen): Drop cts_type, cts_flags and cts_offset. (ctf_simple_open): Likewise. (ctf_bfdopen_ctfsect): Likewise. Set cts_size properly. * Makefile.in: Regenerate. * aclocal.m4: Likewise. * config.h: Likewise. * configure: Likewise.
2019-05-30Harmonize readelf's output for version sections.Nick Clifton1-2/+2
PR 24627 binutils * readelf.c (process_version_sections): Add 0x prefix to address display. Correct indentation. ld * testsuite/ld-elf/ver_def.vd: Update expected output.
2019-05-29Do not build libctf for targets that do not use the ELF file format.Nick Clifton1-1/+23
top * configure.ac (noconfigdirs): Add libctf if the target does not use the ELF file format. * configure: Regenerate. binutils* configure.ac (LIBCTF): Export. Set to empty for non-ELF based targets. (HAVE_LIBCTF): Define if libctf support is available. * Makefile.am (LIBCTF): Set value to @LIBCTF@. * objdump.c: Make CTF code conditional upon HAVE_LIBCTF being defined. * readelf.c: Likewise. * configure: Regenerate. * Makefile.in: Regenerate. * config.in: Regenerate.
2019-05-28binutils: CTF support for objdump and readelfNick Alcock1-0/+206
This introduces CTF support for objdump and readelf. objdump has the following new arguments: --ctf=SECTION: display CTF in the given SECTION --ctf-parent=SECTION: name of CTF section that is the parent of this section readelf has the above, and these two as well: --ctf-symbols=SECTION: name of symbol table section (optional) --ctf-strings=SECTION: name of string table section (optional) (objdump can always use BFD machinery to determine the applicable string and symbol tables automatically, so these arguments are unnecessary.) Nearly all the work is done by the ctf_dump machinery in libctf: most of the remaining work is option-processing and section-reading, and thus is different for objdump and readelf: the minimal amount of similar code remaining is, in my view, too small to share, particularly given that objdump uses ctf_bfdopen() and readelf uses ctf_simple_open() since it doesn't have a bfd. I am not particularly satisfied with the way resources are freed in either of these (I was forced to do it at the top level, for lack of anywhere else to free resources allocated during option processing), but I can't see any better way to do it without introducing new infrastructure for no other purpose. There are essentially arbitrary ordering changes to the Makefile.in's order of libtool-related stuff that I can't get rid of, but they have no semantic effect. (It is possible that some hunks of these changes could be dropped, but that seems a bit risky to me.) binutils/ * objdump.c (ctf-api.h): New include. (dump_ctf_section_info): New variable. (dump_ctf_section_name): Likewise. (usage): Describe new options. (enum option_values): Add OPTION_CTF and OPTION_CTF_PARENT. (main): Use them to add --ctf and --ctf-parent. (read_section_stabs): Add new parameter, entsize_ptr. (find_stabs_section): Adjust accordingly. (make_ctfsect): New. (dump_ctf_indent_lines): New. (dump_ctf_archive_member): New. (dump_ctf): New. (dump_bfd): Call it. Free resources afterwards. * readelf.c (ctf-api.h): New include. (CTF_DUMP): New. (static bfd_boolean do_ctf): Likewise. (dump_ctf_parent_name): Likewise. (dump_ctf_symtab_name): Likewise. (dump_ctf_strtab_name): Likewise. (OPTION_CTF_DUMP): Likewise. (OPTION_CTF_PARENT): Likewise. (OPTION_CTF_SYMBOLS): Likewise. (OPTION_CTF_STRINGS): Likewise. (options): Add them. (usage): Likewise. (parse_args): Handle the new options, requesting CTF_DUMP. (process_section_contents): Handle CTF_DUMP. (shdr_to_ctf_sect): New. (dump_ctf_indent_lines): New. (dump_section_as_ctf): New. (main): Free resources. * Makefile.am (LIBCTF): New variable. (objdump_DEPENDENCIES): Use it. (readelf_DEPENDENCIES): Likewise. (objdump_LDADD): Likewise. (readelf_LDADD): Likewise. * aclocal.m4: Regenerated. * Makefile.in: Likewise. * doc/binutils.texi (objdump): Document the new options. (readelf): Likewise. * doc/ctf.options.texi: New. * doc/Makefile.in: Regenerated. * NEWS: Mention the new feature.
2019-05-27readelf group errors/warningsAlan Modra1-1/+1
I noticed that one of the readelf errors stopped processing of further group sections. This patch makes readelf continue on to other groups, like it does with the other errors. * readelf.c (process_section_groups): Continue processing groups when sh_entsize exceeds group size.
2019-05-24aarch64: add STO_AARCH64_VARIANT_PCS and DT_AARCH64_VARIANT_PCSSzabolcs Nagy1-0/+20
The bottom 2 bits of st_other are used for visibility, the top 6 bits are de facto reserved for processor specific use. This patch defines a bits to mark function symbols that follow a variant procedure call standard with different register usage convention. A dynamic tag is also defined that marks modules with R_<CLS>_JUMP_SLOT relocations referencing symbols marked with STO_AARCH64_VARIANT_PCS. This can be used by dynamic linkers that support lazy binding to decide what registers need to be preserved during symbol resolution. binutils/ChangeLog: * readelf.c (get_aarch64_dynamic_type): Handle DT_AARCH64_VARIANT_PCS. (get_aarch64_symbol_other): New, handles STO_AARCH64_VARIANT_PCS. (get_symbol_other): Call get_aarch64_symbol_other. include/ChangeLog: * elf/aarch64.h (DT_AARCH64_VARIANT_PCS): Define. (STO_AARCH64_VARIANT_PCS): Define.
2019-05-23binutils: add support for eBPFJose E. Marchesi1-0/+8
This patch adds support for ELF64 eBPF to readelf, and fixes a `nm' test to run properly in bpf-*-* targets. binutils/ChangeLog: 2019-05-23 Jose E. Marchesi <jose.marchesi@oracle.com> * readelf.c: Include elf/bpf.h. (guess_is_rela): Hanle EM_BPF. (dump_relocations): Likewise. (is_32bit_abs_reloc): Likewise. * testsuite/binutils-all/nm.exp: Add bpf-*-* to the list of ELF targets.