Commit Graph

4016 Commits

Author SHA1 Message Date
Alan Modra
5250d2f0a5 display_debug_str_offsets
* dwarf.c (display_debug_str_offsets): Constrain reads to length
	given in header.
2021-05-15 15:16:35 +09:30
Alan Modra
6ca0735017 display_debug_aranges
* dwarf.c (display_debug_aranges): Delete initial_length_size.
	Use end_ranges to constrain data reads to header length.  Avoid
	pointer UB.
2021-05-15 15:15:35 +09:30
Alan Modra
7848009791 display_loc_list
* dwarf.c (display_loc_list): Avoid pointer UB.  Correct check
	before reading uleb length.  Warn on excess length.
2021-05-15 15:13:45 +09:30
Alan Modra
b0d461ec37 display_debug_macro
* dwarf.c (display_debug_macro): Print strings that might not
	be zero terminated with %*s.  Don't bump curr if unterminated.
2021-05-15 15:10:29 +09:30
Alan Modra
46d1214d88 get_line_filename_and_dirname
* dwarf.c (get_line_filename_and_dirname): Delete initial_length_size.
	Simplify length sanity check, and check for too small lengths.
	Constrain data reads to header length.  Avoid pointer UB.
2021-05-15 15:09:01 +09:30
Alan Modra
c03df92247 display_debug_macinfo
The existing code went to the bother of using strnlen for scanning but
went wild when printing, and possibly incremented curr past end.

	* dwarf.c (display_debug_macinfo): Print strings that might not
	be zero terminated with %*s.  Don't bump curr if unterminated.
2021-05-15 15:05:29 +09:30
Alan Modra
35b2c89ec8 display_debug_pubnames_worker
* dwarf.c (display_debug_pubnames_worker): Delete initial_length_size.
	Simplify length check.  Constrain reads to length given by header.
2021-05-15 15:01:39 +09:30
Alan Modra
56051e28a3 display_debug_lines_decoded
The directory_table strnlen used the negative of the proper size.  After
fixing that I realised we don't need strnlen here.

	* dwarf.c (display_debug_lines_decoded): Don't use strnlen when
	we have already checked for NUL termination.
2021-05-15 14:57:38 +09:30
Alan Modra
37195e23e7 read_debug_line_header
This patch also better constrains the data read, and removes pointer UB.

	* dwarf.c (read_debug_line_header): Delete initial_length_size.
	Avoid pointer UB.  Keep within length specified by header.
	Delete dead code.
2021-05-15 14:54:05 +09:30
Alan Modra
edba4e4aba process_debug_info
This patch constrains process_debug_info to stay within the data
specified by the CU length rather than allowing access up to the end
of the section.

	* dwarf.c (process_debug_info): Always do the first CU length
	scan for sanity checks.  Remove initial_length_size var and
	instead calculate end_cu.  Use end_cu to limit data reads.
	Delete now dead code checking length.
2021-05-15 14:48:33 +09:30
Alan Modra
ebb1786492 SAFE_BYTE_GET_INTERNAL
We won't want this assert triggering in the next release.

	* dwarf.c (SAFE_BYTE_GET_INTERNAL): Assert only when ENABLE_CHECKING.
2021-05-15 14:38:42 +09:30
Alan Modra
fc5e0925d4 _mul_overflow and get_encoded_value
A sufficiently mad compiler optimiser can take undefined behaviour
according to the C standard as an opportunity to remove code.  Since
"data + size" might be seen to be past the end of an array,
calculating such an expression is UB.

_mul_overflow is infrastructure for later patches.

	* bucomm.h (_mul_overflow): Define.
	* dwarf.c (get_encoded_value): Avoid pointer UB.
2021-05-15 14:36:54 +09:30
Nick Clifton
0522d0165a revert previous delta 2021-05-13 14:33:39 +01:00
Nick Clifton
c4375dd764 Fix an infinite loop in the DWARF decoder when parsing a corrupt string table.
PR 27861
	* dwarf.c (display_debug_str_offsets): Warn if the length field is
	larger than the amount of data remaining in the section.
2021-05-13 14:31:09 +01:00
Alan Modra
b96a1bcb81 PR27861, Infinite loop in dwarf.c:7507-7526
PR 27861
	* dwarf.c (display_debug_str_offsets): Sanity check dwarf5
	header length.
2021-05-13 22:49:17 +09:30
Alan Modra
d21f875d67 PR27860, Segmentation fault on readelf -w
Well it didn't take long for the SAFE_BYTE_GET assert to trigger.

	PR 27860
	* dwarf.c (display_debug_frames): Sanity check cie_off before
	attempting to read cie.
2021-05-13 22:49:17 +09:30
Alan Modra
a7077ce760 Ensure data pointer kept within bounds
* dwarf.c (process_extended_line_op): Don't bump data pointer past
	end when strnlen doesn't find string terminator.
	(decode_location_expression): Remove dead code.
	(skip_attr_bytes): Remove const from end param.  Ensure data
	pointer doesn't pass end.
	(get_type_signedness): Remove const from end param.
	(read_and_display_attr_value): Ensure data pointer doesn't pass end.
	(display_debug_lines_raw, display_debug_lines_decoded): Likewise.
	(display_debug_pubnames_worker): Likewise.
	(display_debug_pubnames_worker): Use SAFE_BYTE_GET_AND INC rather
	than blindly incrementing data pointer.
	(display_debug_addr, display_debug_str_offsets): Likewise.  Don't
	compare pointers, compare lengths.
2021-05-12 21:29:25 +09:30
Alan Modra
6d1ad6f783 SAFE_BYTE_GET
This rearranges SAFE_BYTE_GET* macros, eliminating some duplication,
and making sure that the _INC variants never increment their PTR arg
past END.  I've added an assertion that should show us places where we
use them improperly with user derived PTR args, which I'm sure the
fuzzers will find for us.

	* dwarf.c (SAFE_BYTE_GET_INTERNAL): Define.
	(SAFE_BYTE_GET, SAFE_BYTE_GET_AND_INC): Define using the above.
	(SAFE_SIGNED_BYTE_GET, SAFE_SIGNED_BYTE_GET_AND_INC): Likewise.
	(display_discr_list): Use SAFE_BYTE_GET_AND_INC rather than
	SAFE_BYTE_GET followed by increment.
	(process_debug_info): Likewise, and test bytes remaining before
	incrementing section_begin rather than using pointer comparison.
	(display_debug_names): Pass lvalue as SAFE_BYTE_GET PTR.
	(process_cu_tu_index): Likewise for SAFE_BYTE_GET_AND_INC.
2021-05-12 21:17:35 +09:30
Alan Modra
af2ddf69ab SAFE_BYTE_GET64
Functions dealing with lack of a 64-bit integer type can disappear now
that we require C99.  Printing using dwarf_vmatoa is better too.

binutils/
	* dwarf.c (dwarf_vmatoa64, SAFE_BYTE_GET64, add64): Delete.
	(skip_attr_bytes): Replace use of SAFE_BYTE_GET64 with
	SAFE_BYTE_GET_AND_INC.
	(read_and_display_attr_value): Likewise.  Print using dwarf_vmatoa.
	(process_debug_info, process_cu_tu_index): Likewise.
	* elfcomm.c (byte_put, byte_put_little_endian, byte_put_big_endian),
	(byte_get, byte_get_little_endian, byte_get_big_endian),
	(byte_get_signed): Make size param unsigned.  Remove code dealing
	with 4-byte elf_vma.
	(byte_get_64): Delete.
	* elfcomm.h  (byte_put, byte_put_little_endian, byte_put_big_endian),
	(byte_get, byte_get_little_endian, byte_get_big_endian),
	(byte_get_signed): Update prototypes.
	(byte_get_64): Delete.
gas/
	* testsuite/gas/elf/dwarf-5-file0.d: Update.
	* testsuite/gas/i386/dwarf5-line-1.d: Update.
2021-05-12 21:10:33 +09:30
Alan Modra
0d872fca02 PR27836, readelf -w pointer comparison UB
PR 27836
	* dwarf.c (display_debug_frames): Don't compare pointers derived
	from user input.  Test offset against bounds instead.
2021-05-12 21:10:33 +09:30
Alan Modra
55b26492bb PR27853, Infinite loop in dwarf.c
Not quite infinite but much longer than it need be.  The problem is
triggered by read_and_display_attr_value incrementing "data" past
"end".  read_and_display_attr_value shouldn't do that, but be
defensive.

	PR 27853
	* dwarf.c (display_formatted_table): Test for data >= end rather
	than data == end.
	(process_extended_line_op): Likewise.
	(display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.
2021-05-12 15:41:10 +09:30
Alan Modra
5ab3907543 PR27849, heap-buffer-overflow on readelf -w
PR 27849
	* dwarf.c (fetch_indexed_string): Correct length sanity checks.
	Sanity check section size for version and padding too.  Correct
	index sanity check.  Handle multiple tables in .debug_str_offsets.
2021-05-12 15:41:10 +09:30
Hans-Peter Nilsson
d30182b51e dwarf.c (process_abbrev_set): Properly parenthesize, fix fallout
Building as ILP32 shows:

 gcc -m32 -DHAVE_CONFIG_H -I. -I/checkout/binutils  -I. -I/checkout/binutils -I../bfd -I/checkout/binutils/../bfd -I/checkout/binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -I/checkout/binutils/../zlib -g -O2   -MT dwarf.o -MD -MP -MF $depbase.Tpo -c -o dwarf.o /checkout/binutils/dwarf.c &&\
 mv -f $depbase.Tpo $depbase.Po
 In file included from /checkout/binutils/sysdep.h:101:0,
                  from /checkout/binutils/dwarf.c:21:
 /checkout/binutils/dwarf.c: In function 'process_abbrev_set':
 /checkout/binutils/dwarf.c:1072:15: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'dwarf_vma {aka long long unsigned int}' [-Werror=format=]
        warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
                ^
 /checkout/binutils/dwarf.c:1072:13: note: in expansion of macro '_'
        warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
              ^
 cc1: all warnings being treated as errors
 Makefile:1101: recipe for target 'dwarf.o' failed

The recent commit, casting one of the terms, has an obvious
typo.  To wit, the (non-cast) term abbrev_size is a
dwarf_vma and causes the whole expression to (still) be 64
bits.

binutils:
	* dwarf.c (process_abbrev_set): Properly parenthesize before
	casting to unsigned long.
2021-05-11 16:26:30 +02:00
Alan Modra
f2f9554bf0 PR27845, readelf heap-buffer-overflow
PR 27845
	* dwarf.c (process_abbrev_set): Replace start and end parameters
	with section, abbrev_base, abbrev_size, abbrev_offset.  Update
	all callers.  Sanity check parameters correctly and emit warnings
	here rather than..
	(process_debug_info): ..here.
2021-05-11 19:07:02 +09:30
Thomas Wolff
749c700282 Restore old behaviour of windres so that options containing spaces are not enclosed in double quotes.
PR 4356
	PR 26865
	PR 27594
	* windres.c (quot): Revert previous delta.  Do not use double
	quotes when spaces are detected in options.
	* doc/binutils.texi (windres): Remove suggestion that the
	--preprocessor option can take arguments.
2021-05-10 11:28:15 +01:00
Alan Modra
2d4b49864e Avoid possible pointer wrap
PTR supplied to these macros can be read from user input, END is an
end of buffer pointer.  It's safer to do arithmetic on END than on PTR.

	* dwarf.c (SAFE_BYTE_GET): Check bounds by subtracting amount from
	END rather than adding amount to PTR.
	(SAFE_SIGNED_BYTE_GET, SAFE_BYTE_GET64): Likewise.
2021-05-10 10:03:00 +09:30
Alan Modra
b05a0fc79b Use htab_eq_string in binutils
A quick check says this is the only place in all of bfd, opcodes,
binutils, gas, ld, gprof that duplicates the new libiberty
htab_eq_string.

	* objcopy.c (eq_string): Delete.
	(create_symbol_htab): Use htab_eq_string.
2021-05-09 12:28:18 +09:30
Mike Frysinger
354c317ea4 binutils: update release docs process
Now that we generate multiple html & pdf forms, update the release
process to show how they get updated.
2021-05-08 12:06:41 -04:00
Mike Frysinger
cf758b3960 support generating multi-html pages in parallel
Use the pattern from other projects where we generate the html pages
in a dir named the same as the project.  So now we have:
gas/doc/gas.html - single html page
gas/doc/gas/ - multiple html pages

This works for projects that have a doc/ subdir already, but gprof &
ld require a little tweaking since they generate their docs in their
respective toplevels.
2021-05-08 12:06:07 -04:00
Mike Frysinger
2faf902da5 generate single html manual page by default
This better matches other GNU projects like autoconf/automake where
the html manual is the single page form.  We'll support the multi-page
form in a follow up change.
2021-05-08 11:58:19 -04:00
Nick Clifton
3ecc00ec9c Srop readelf's unwind decoder from complaining about x86 binaries.
* readelf.c (no_processor_specific_unwind): New function.
	(process_unwind): Use no_processor_specific_unwind for X86
	targets.
2021-05-07 15:24:14 +01:00
Michael Forney
4896932e62 dwarf: Don't omit second operand of '?' operator
This is a GNU C extension and is not valid in ISO C.

	* dwarf.c: Don't omit second operand of '?' operator.
2021-05-07 16:54:00 +09:30
Nick Clifton
bfbfa6e7f4 Fix attempt to free non-allocated pointer when parsing .debug_sup sections.
PR 27796
	* dwarf.c (load_debug_sup_file): Allocate memory for filename in
	.debug_sup section.
2021-04-30 12:28:39 +01:00
Nick Clifton
5edb8e3f5a Correct the text describing windres's --processor option.
PR 27594
 * doc/binutils.texi (windres): Correct the description of the
 default value of the --preprocessor argument.
2021-04-29 13:11:29 +01:00
Nick Clifton
3d64c987c7 Reject debuglink sections with no associated filename.
PR 27779
	* dwarf.c (parse_gnu_debuglink): Reject empty names.
	(parse_gnu_debugaltlink): Likewise.
2021-04-27 15:19:41 +01:00
Cl?ment Chigot
b11b2969a9 Harmonize and improve auxiliary entries support for XCOFF
bfd/ChangeLog:
	* coff-rs6000.c (_bfd_xcoff_swap_aux_in): Add errors for
	unsupported storage class or auxialiry entries.
	Improve and adapt to new aux structures.
	Add C_DWARF support.
	(_bfd_xcoff_swap_aux_out): Likewise.
	* coff64-rs6000.c (_bfd_xcoff64_swap_aux_in): Likewise.
	(_bfd_xcoff64_swap_aux_out): Likewise.

binutils/ChangeLog:
	* od-xcoff.c (dump_xcoff32_symbols): Adapt to new
	aux structures.

include/ChangeLog:
	* coff/internal.h (union internal_auxent):
	 Add x_sect structure.
	* coff/rs6000.h (union external_auxent): Rework to
	match official documentation.
	* coff/rs6k64.h (union external_auxent): Likewise.
	(_AUX_SECT): New define.
2021-04-22 12:28:50 +01:00
Nick Lott
047c3dbf55 Add ability to select numeric base when displaying symbol values in readelf.
PR 27672
	* readelf.c (sym_base): New variable.
	(enum print_mode): Add more modes.
	(print_vma): Add suport for new modes.
	(options): Add sym-base.
	(usage): Add sym-base.
	(parse_args): Add support for --sym-base.
	(print_dynamic_symbol_size): New function.
	(print_dynamic_symbol): Use new function.
	* doc/binutils.texi: Document the new feature.
	* NEWS: Mention the new feature.
2021-04-21 15:33:13 +01:00
Nick Clifton
2335639744 Adjust readelf's output so that section symbols without a name as shown with their section name.
binutils* readelf.c (print_dynamic_symbol): Print the section name for
	section symbols without a name of their own.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d:
	Adjust expected output to allow for named section symbols.
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d:
	Likewise.
	* testsuite/binutils-all/readelf.s-64: Likewise.
	* testsuite/binutils-all/readelf.ss-64-unused: Likewise.
	* testsuite/binutils-all/readelf.ss-tmips: Likewise.
	* testsuite/binutils-all/readelf.ss-unused: Likewise.

ld	* testsuite/ld-aarch64/variant_pcs-now.d: Adjust expected output
	to allow for named section symbols.
	* testsuite/ld-aarch64/variant_pcs-r.d: Likewise.
	* testsuite/ld-aarch64/variant_pcs-shared.d: Likewise.
	* testsuite/ld-alpha/tlsbin.rd: Likewise.
	* testsuite/ld-alpha/tlsbinr.rd: Likewise.
	* testsuite/ld-alpha/tlspic.rd: Likewise.
	* testsuite/ld-arm/rodata-merge-map.sym: Likewise.
	* testsuite/ld-arm/script-type.sym: Likewise.
	* testsuite/ld-cris/libdso-2.d: Likewise.
	* testsuite/ld-cris/pr16044.d: Likewise.
	* testsuite/ld-elf/sec64k.exp: Likewise.
	* testsuite/ld-ia64/tlsbin.rd: Likewise.
	* testsuite/ld-ia64/tlspic.rd: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: Likewise.
	* testsuite/ld-mmix/bspec1.d: Likewise.
	* testsuite/ld-mmix/bspec2.d: Likewise.
	* testsuite/ld-mmix/local1.d: Likewise.
	* testsuite/ld-mmix/local3.d: Likewise.
	* testsuite/ld-mmix/local5.d: Likewise.
	* testsuite/ld-mmix/local7.d: Likewise.
	* testsuite/ld-mmix/undef-3.d: Likewise.
	* testsuite/ld-powerpc/tlsso.r: Likewise.
	* testsuite/ld-powerpc/tlsso32.r: Likewise.
	* testsuite/ld-powerpc/tlstocso.r: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-s390/tlspic.rd: Likewise.
	* testsuite/ld-s390/tlspic_64.rd: Likewise.
	* testsuite/ld-sparc/gotop32.rd: Likewise.
	* testsuite/ld-sparc/gotop64.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
	* testsuite/ld-sparc/tlssunnopic32.rd: Likewise.
	* testsuite/ld-sparc/tlssunnopic64.rd: Likewise.
	* testsuite/ld-sparc/tlssunpic32.rd: Likewise.
	* testsuite/ld-sparc/tlssunpic64.rd: Likewise.
	* testsuite/ld-tic6x/common.d: Likewise.
	* testsuite/ld-tic6x/shlib-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.

gas	* testsuite/gas/aarch64/dwarf.d: Adjust expected output to allow
	for named section symbols.
	* testsuite/gas/arm/thumbver.d: Likewise.
	* testsuite/gas/bfin/loop_temps.d: Likewise.
	* testsuite/gas/elf/section2.e-arc: Likewise.
	* testsuite/gas/elf/section2.e-arm: Likewise.
	* testsuite/gas/elf/section2.e-csky: Likewise.
	* testsuite/gas/elf/section2.e-m32r: Likewise.
	* testsuite/gas/elf/section2.e-mips: Likewise.
	* testsuite/gas/elf/section2.e-msp430: Likewise.
	* testsuite/gas/elf/section2.e-riscv: Likewise.
	* testsuite/gas/elf/section2.e-rl78: Likewise.
	* testsuite/gas/elf/section2.e-rx: Likewise.
	* testsuite/gas/elf/section2.e-score: Likewise.
	* testsuite/gas/elf/section2.e-tic6x: Likewise.
	* testsuite/gas/elf/section2.e-unused: Likewise.
	* testsuite/gas/elf/section2.e-v850: Likewise.
	* testsuite/gas/elf/section2.e-xtensa: Likewise.
	* testsuite/gas/ia64/alias-ilp32.d: Likewise.
	* testsuite/gas/ia64/alias.d: Likewise.
	* testsuite/gas/ia64/global.d: Likewise.
	* testsuite/gas/microblaze/relax_size.elf: Likewise.
	* testsuite/gas/microblaze/relax_size2.elf: Likewise.
	* testsuite/gas/mips/global-local-symtab-sort-n64t.d: Likewise.
	* testsuite/gas/mips/global-local-symtab-sort-o32t.d: Likewise.
	* testsuite/gas/mmix/bspec-1.d: Likewise.
	* testsuite/gas/mmix/byte-1.d: Likewise.
	* testsuite/gas/mmix/comment-1.d: Likewise.
	* testsuite/gas/mmix/loc-1.d: Likewise.
	* testsuite/gas/mmix/loc-2.d: Likewise.
	* testsuite/gas/mmix/loc-3.d: Likewise.
	* testsuite/gas/mmix/loc-4.d: Likewise.
	* testsuite/gas/mmix/loc-5.d: Likewise.
	* testsuite/gas/tic6x/scomm-directive-4.d: Likewise.
2021-04-21 10:34:32 +01:00
Andreas Krebbel
aee4e85e27 MAINTAINERS: Remove Martin Schwidefsky as s390 maintainer
https://lwn.net/ml/linux-kernel/20190521162350.GA17107@osiris/

ChangeLog:

2021-04-20  Andreas Krebbel  <krebbel@linux.ibm.com>

	* MAINTAINERS: Remove Martin Schwidefsky as s390 maintainer and
	add him to Past Maintainers.
	Update my email address.
2021-04-20 09:19:16 +02:00
Nick Clifton
229597a129 Fix a problem running the archiver program in MRI mode on archives containing LTO compiled objects.
PR 21702
	* arsup.c (ar_addmod): Enable plugin support, if available.
2021-04-19 17:38:39 +01:00
Nick Clifton
4dee4f3ea1 Fix compile time warning about unused functions.
binutils * rename.c: (get_stat_atime_ns): Add prototype.
	(get_stat_mtime_ns): Add prototype.
2021-04-19 09:41:04 +01:00
Alan Modra
ad7c46164f undefined reference to get_stat_atime
PR 27725
	* rename.c (get_stat_atime, get_stat_mtime): Make static.
	(get_stat_atime_ns, get_stat_mtime_ns): Likewise.
2021-04-16 12:12:50 +09:30
Pekka Seppänen
4c79248a46 PR27734, get_stat_atime_ns/get_stat_mtime_ns might not use parameter
PR 27725
	* rename.c (get_stat_atime_ns): Add ATTRIBUTE_UNUSED.
	(get_stat_mtime_ns): Likewise.
2021-04-16 00:09:26 +09:30
Alan Modra
985e026451 PR27725, better objcopy -p times
Nanosecond rather than second resolution.

	PR 27725
	* configure.ac: Check for sys/time.h and utimensat.  Use standard
	checks for mkstemp and mkdtemp.  Whitespace.  Check for nanosecond
	members of struct stat.
	* rename.c: Prefer sys/time.h for utimes over utime.h for utime.
	(STAT_TIMESPEC, STAT_TIMESPEC_NS): Define
	(get_stat_atime_ns, get_stat_mtime_ns): New inline functions.
	(get_stat_atime, get_stat_mtime): Likewise.
	(set_times): Choose first available of utimensat, utimes, utime.
	Use above inline functions to set timespec and timeval values.
	* configure: Regenerate.
	* config.in: Regenerate.
	* testsuite/binutils-all/objcopy.exp (objcopy_test): Add test of
	file timestamp when --preserve-dates is used.
2021-04-15 17:51:17 +09:30
Alan Modra
d0ecdcddc3 Make objcopy -p work when an output file is specified
More fallout from the PR27456 fixes.

	PR 27456
	* rename.c (smart_rename): When TO and FROM are equal, just set
	file timestamp.
	* objcopy.c (strip_main, copy_main): Always call smart_rename.
2021-04-15 14:16:55 +09:30
H.J. Lu
9917b5596a elf: Set p_memsz to p_filesz for loadable PT_NOTE segment
Since p_memsz of the loadable PT_NOTE segment should be the same as
p_filesz, set p_memsz on the loadable PT_NOTE segment when updating
p_filesz.

bfd/

	PR binutils/27708
	* elf.c (assign_file_positions_for_non_load_sections): Set
	p_memsz to p_filesz for the loadable PT_NOTE segment.

binutils/

	PR binutils/27708
	* testsuite/binutils-all/x86-64/pr27708.dump: New file.
	* testsuite/binutils-all/x86-64/pr27708.exe.bz2: Likewise.
	* testsuite/binutils-all/x86-64/x86-64.exp: Run binutils/27708
	test.
2021-04-14 05:31:15 -07:00
Mark Harmstone
6be872a439 Ignore trailing bytes at the end of a Windows Resource Version structure.
PR 27686
	* resbin.c (bin_to_res_version): Ignore any trailing bytes at the
	end of the structure.
2021-04-14 11:55:16 +01:00
Frederic Cambus
5f47741bf6 Remove unneeded tests for definitions of NT_BSDNETCORE values.
binutils* readelf.c (get_netbsd_elfcore_note_type): Remove unneeded #ifdef
	checks for NT_NETBSDCORE_AUXV and NT_NETBSDCORE_LWPSTATUS.

bfd	* elf.c (elfcore_grok_netbsd_note): Remove unneeded #ifdef
	checks for NT_NETBSDCORE_AUXV and NT_NETBSDCORE_LWPSTATUS.
2021-04-14 11:15:01 +01:00
Alan Modra
13acb58d42 PR27716, build failure for msdosdjgpp: PATH_MAX undeclared
We shouldn't be using arbitrary limits like PATH_MAX in GNU programs.
This patch also fixes some memory leaks in readelf when processing
separate debug info.

	PR 27716
binutils/
	* objdump.c (show_line): Don't limit paths to PATH_MAX.
	* readelf.c (struct filedata): Change program_interpreter from
	a char array to a char pointer.
	(process_program_headers): Sanity check PT_INTERP p_filesz.
	Malloc program_interpreter using p_filesz and read directly from
	file.
	(process_dynamic_section): Check program_interpreter is non-NULL.
	(free_filedata): New function, split out from..
	(process_object): ..here.
	(close_debug_file): Call free_filedata.
	* sysdep.h: Don't include sys/param.h.
	(PATH_MAX): Don't define.
	* configure.ac: Don't check for sys/param.h.
	* configure: Regenerate.
gprof/
	* gprof.h (PATH_MAX): Don't define.
	* corefile.c (core_create_line_syms): Don't use PATH_MAX for initial
	file name size.
	* source.c (annotate_source): Malloc file name buffer.  Always
	trim off "-ann" when dos 8.3 annotate file matches original.
	* utils.c (print_name_only): Malloc file name buffer.
2021-04-14 15:06:11 +09:30
Frederic Cambus
0fa29e2dee Remove now unneeded #ifdef check for NT_NETBSD_PAX.
NT_NETBSD_PAX was defined in commit be3b926d8d.

binutils/ChangeLog:

	* readelf.c (process_netbsd_elf_note): Remove now unneeded #ifdef
	check for NT_NETBSD_PAX.
2021-04-13 16:11:39 +09:30
Alan Modra
43e05cd4f4 ENABLE_CHECKING in bfd, opcodes, binutils, ld
gas already has this.  Here it enables checking hash table type passed
to elf_link_hash_lookup and elf_link_hash_traverse.

bfd/
	* elf-bfd.h (ENABLE_CHECKING): Define.
	(elf_link_hash_lookup): Abort if wrong type of hash table.
	(elf_link_hash_traverse): Likewise.
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
binutils/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
ld/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
opcodes/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
2021-04-13 00:35:44 +09:30
Alan Modra
c3f72de4f5 PowerPC disassembly of pcrel references
This adds some annotation to Power10 pcrel instructions, displaying
the target address (ie. pc + D34 field) plus a symbol if there is one
at exactly that target address.  pld from the .got or .plt will also
look up the entry and display it, symbolically if there is a dynamic
relocation on the entry.

include/
	* dis-asm.h (struct disassemble_info): Add dynrelbuf and dynrelcount.
binutils/
	* objdump.c (struct objdump_disasm_info): Delete dynrelbuf and
	dynrelcount.
	(find_symbol_for_address): Adjust for dynrelbuf and dynrelcount move.
	(disassemble_section, disassemble_data): Likewise.
opcodes/
	* ppc-dis.c (struct dis_private): Add "special".
	(POWERPC_DIALECT): Delete.  Replace uses with..
	(private_data): ..this.  New inline function.
	(disassemble_init_powerpc): Init "special" names.
	(skip_optional_operands): Add is_pcrel arg, set when detecting R
	field of prefix instructions.
	(bsearch_reloc, print_got_plt): New functions.
	(print_insn_powerpc): For pcrel instructions, print target address
	and symbol if known, and decode plt and got loads too.
gas/
	* testsuite/gas/ppc/prefix-pcrel.d: Update expected output.
	* testsuite/gas/ppc/prefix-reloc.d: Likewise.
	* gas/testsuite/gas/ppc/vsx_32byte.d: Likewise.
ld/
	* testsuite/ld-powerpc/inlinepcrel-1.d: Update expected output.
	* testsuite/ld-powerpc/inlinepcrel-2.d: Likewise.
	* testsuite/ld-powerpc/notoc2.d: Likewise.
	* testsuite/ld-powerpc/notoc3.d: Likewise.
	* testsuite/ld-powerpc/pcrelopt.d: Likewise.
	* testsuite/ld-powerpc/startstop.d: Likewise.
	* testsuite/ld-powerpc/tlsget.d: Likewise.
	* testsuite/ld-powerpc/tlsget2.d: Likewise.
	* testsuite/ld-powerpc/tlsld.d: Likewise.
	* testsuite/ld-powerpc/weak1.d: Likewise.
	* testsuite/ld-powerpc/weak1so.d: Likewise.
2021-04-09 16:56:43 +09:30
Alan Modra
a2e6677373 Return symbol from symbol_at_address_func
include/
	* dis-asm.h (struct disassemble_info <symbol_at_address_func>):
	Return asymbol*.
binutils/
	* objdump.c (objdump_symbol_at_address): Return asymbol*.
opcodes/
	* dis-buf.c (generic_symbol_at_address): Return symbol* NULL.
	* s12z-dis.c (decode_possible_symbol): Use symbol returned from
	symbol_at_address_func.
2021-04-06 23:25:09 +09:30
Alan Modra
4db29512ce C99 NEWS and README
* NEWS: Mention C99 requirement.
	* README: Likewise.  Modernise examples and "Reporting bugs".
2021-04-06 23:25:09 +09:30
Alan Modra
87b9f2556d C99 binutils configury
* configure.ac: Assume long long is available.  Don't test for
	strings.h, stdlib.h, limits.h, locale.h, or wchar.h.  Check
	inttypes.h, stdint.h, sys/stat.h and sys/types.h. Don't check for
	strcoll, setlocale, setmode or location of time_t.  Don't check
	for fprintf, getenv, snprintf, strnlen, strstr or vsnprintf decls.
	(AC_ISC_POSIX, AXC_HEADER_STRING, AC_FUNC_ALLOCA): Don't invoke.
	* sysdep.h: Don't include alloca-conf.h, include config.h instead.
	Test HAVE_SYS_TYPES_H and reorder includes.  Include limits.h,
	locale.h, string.h and stdlib.h unconditionally.  Remove various
	fallback declarations.  Assume long long is available.
	* addr2line.c: Don't test HAVE_SETLOCALE.
	* ar.c: Likewise.
	* coffdump.c: Likewise.
	* dlltool.c: Likewise.
	* dllwrap.c: Likewise.
	* elfedit.c: Likewise.
	* nm.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* readelf.c: Likewise.
	* size.c: Likewise.
	* srconv.c: Likewise.
	* strings.c: Likewise.
	* sysdump.c: Likewise.
	* windmc.c: Likewise.
	* windres.c: Likewise.
	* bucomm.c: Don't test HAVE_TIME_T_IN_TIME_H or HAVE_TIME_T_IN_TYPES_H.
	* dwarf.c: Include limits.h unconditionally.  Assume long long
	is available.
	* nm.c: Don't test HAVE_STRCOLL.
	* readelf.c: Don't test HAVE_WCHAR_H.
	* strings.c: Assume long long is available.
	* syslex.l: Include string.h unconditionally.
	* aclocal.m4: Regenerate.
	* config.in: Regenerate.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
	* doc/Makefile.in: Regenerate.
2021-04-05 15:30:22 +09:30
Martin Liska
e9b095a538 Remove strneq macro and use startswith.
bfd/ChangeLog:

	* ecoff.c (strneq): Remove strneq and use startswith.
	(_bfd_ecoff_slurp_armap): Likewise.

binutils/ChangeLog:

	* elfcomm.h (strneq): Remove strneq and use startswith.
	* readelf.c (ia64_process_unwind): Likewise.
	(process_note): Likewise.

gas/ChangeLog:

	* config/obj-coff.c (strneq): Remove strneq and use startswith.
	(weak_is_altname): Likewise.
	(obj_coff_section): Likewise.
	* config/tc-cr16.c (process_label_constant): Likewise.
	* config/tc-crx.c (strneq): Likewise.

include/ChangeLog:

	* opcode/cr16.h (strneq): Remove strneq and use startswith.

ld/ChangeLog:

	* ldbuildid.c (strneq): Remove strneq and use startswith.
	(validate_build_id_style): Likewise.
	(compute_build_id_size): Likewise.

opcodes/ChangeLog:

	* arm-dis.c (strneq): Remove strneq and use startswith.
	* cr16-dis.c (print_insn_cr16): Likewise.
	* score-dis.c (streq): Likewise.
	(strneq): Likewise.
	* score7-dis.c (strneq): Likewise.
2021-04-01 15:00:56 +02:00
Martin Liska
3f3328b816 Use startswith more for strncmp function calls.
bfd/ChangeLog:

	* elf-bfd.h (bfd_section_is_ctf): Use startswith function.
	* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
	(elf_get_reloc_section): Likewise.
	* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_section_flags): Likewise.
	* elf32-microblaze.c (microblaze_elf_size_dynamic_sections): Likewise.
	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
	(nds32_elf_relocate_section): Likewise.
	(nds32_elf_action_discarded): Likewise.
	(nds32_elf_check_relocs): Likewise.
	(nds32_elf_section_flags): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_section_from_shdr): Likewise.
	* elf32-rx.c (rx_table_find): Likewise.
	(rx_table_map): Likewise.
	* elf32-spu.c (spu_elf_backend_symbol_processing): Likewise.
	(spu_elf_find_overlays): Likewise.
	(needs_ovl_stub): Likewise.
	(allocate_spuear_stubs): Likewise.
	(build_spuear_stubs): Likewise.
	(mark_overlay_section): Likewise.
	(spu_elf_auto_overlay): Likewise.
	(spu_elf_output_symbol_hook): Likewise.
	* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (xtensa_property_section_name): Likewise.
	* elf64-ppc.c (ppc64_elf_section_flags): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	* elflink.c (resolve_section): Likewise.
	(UNARY_OP): Likewise.
	(BINARY_OP_HEAD): Likewise.
	(elf_link_input_bfd): Likewise.
	* elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
	* elfxx-riscv.c (riscv_parse_subset): Likewise.
	* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
	* opncls.c (get_build_id): Likewise.

binutils/ChangeLog:

	* dllwrap.c: Use startswith function.
	* objcopy.c (is_dwo_section): Likewise.
	(handle_remove_section_option): Likewise.
	(copy_main): Likewise.
	* objdump.c (is_significant_symbol_name): Likewise.
2021-04-01 14:59:04 +02:00
Martin Liska
24d127aa9f Replace const_strneq with startswith.
binutils/ChangeLog:

	* dwarf.c (display_debug_lines_raw): Replace const_strneq with
	startswith.
	(display_debug_lines_decoded): Likewise.
	(display_debug_links): Likewise.
	* elfcomm.c (setup_archive): Likewise.
	* elfcomm.h (const_strneq): Likewise.
	* readelf.c (process_section_headers): Likewise.
	(slurp_ia64_unwind_table): Likewise.
	(slurp_hppa_unwind_table): Likewise.
	(decode_arm_unwind): Likewise.
	(display_debug_section): Likewise.
	(process_note): Likewise.
2021-04-01 14:58:36 +02:00
Alan Modra
015dc7e1f8 Use bool in binutils
* sysdep.h (POISON_BFD_BOOLEAN): Define.
	* addr2line.c, * ar.c, * arsup.c, * bfdtest2.c, * binemul.c,
	* binemul.h, * bucomm.c, * bucomm.h, * budbg.h, * coffgrok.c,
	* debug.c, * debug.h, * dlltool.c, * dwarf.c, * dwarf.h,
	* elfedit.c, * emul_aix.c, * mclex.c, * nm.c, * objcopy.c,
	* objdump.c, * od-macho.c, * prdbg.c, * rdcoff.c, * rddbg.c,
	* readelf.c, * rename.c, * stabs.c, * strings.c, * windint.h,
	* windmc.c, * windmc.h, * windres.c, * winduni.c,
	* wrstabs.c: Replace bfd_boolean with bool, FALSE with false,
	and TRUE with true throughout.
2021-03-31 10:49:23 +10:30
Alan Modra
3dfb1b6d34 Remove bfd_stdint.h
If we require C99 for binutils then stdint.h is available.

bfd/
	* .gitignore: Delete bfd_stdint.h entry.
	* Makefile.am (bfdinclude_HEADERS): Delete bfd_stdint.h.
	(BUILD_HFILES, LOCAL_H_DEPS): Likewise.
	* bfd-in.h: Include stdint.h in place of bfd_stdint.h.
	* configure.ac: Don't invoke GCC_HEADER_STDINT.
	* configure.com: Don't create bfd_stdint.h.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* bfd-in2.h: Regenerate.
	* config.in: Regenerate.
	* configure: Regenerate.
	* doc/Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
binutils/
	* coffdump.c: Include stdint.h in place of bfd_stdint.h.
	* dwarf.c: Likewise.
gas/
	* config/tc-aarch64.c: Include stdint.h in place of bfd_stdint.h.
	* config/tc-crx.c: Likewise.
	* config/tc-nds32.h: Likewise.
include/
	* cgen/basic-modes.h: Include stdint.h in place of bfd_stdint.h.
	* elf/nfp.h: Likewise.
	* opcode/aarch64.h: Likewise.
	* opcode/cgen.h: Likewise.
	* opcode/nfp.h: Likewise.
	* opcode/ppc.h: Likewise.
ld/
	* elf-hints-local.h: Include stdint.h in place of bfd_stdint.h.
	* emultempl/nds32elf.em: Likewise.
	* testsuite/ld-elf/mbind2b.c: Likewise.
	* testsuite/ld-elf/pr18718.c: Likewise.
	* testsuite/ld-elf/pr18720a.c: Likewise.
	* testsuite/ld-elf/pr25749-1.c: Likewise.
	* testsuite/ld-elf/pr25749-1a.c: Likewise.
	* testsuite/ld-elf/pr25749-1b.c: Likewise.
	* testsuite/ld-elf/pr25749-1c.c: Likewise.
	* testsuite/ld-elf/pr25749-1d.c: Likewise.
	* testsuite/ld-elf/pr25749-2.c: Likewise.
	* testsuite/ld-elf/pr25754-1a.c: Likewise.
	* testsuite/ld-elf/pr25754-2a.c: Likewise.
	* testsuite/ld-elf/pr25754-3a.c: Likewise.
	* testsuite/ld-elf/pr25754-4a.c: Likewise.
	* testsuite/ld-elf/pr25754-5a.c: Likewise.
	* testsuite/ld-elf/pr25754-6a.c: Likewise.
opcodes/
	* aarch64-dis.c: Include stdint.h in place of bfd_stdint.h.
	* aarch64-dis.h: Likewise.
	* aarch64-opc.c: Likewise.
	* avr-dis.c: Likewise.
	* csky-dis.c: Likewise.
	* nds32-asm.c: Likewise.
	* nds32-dis.c: Likewise.
	* nfp-dis.c: Likewise.
	* riscv-dis.c: Likewise.
	* s12z-dis.c: Likewise.
	* wasm32-dis.c: Likewise.
2021-03-31 10:49:23 +10:30
Alan Modra
57ae980e32 Include string.h in bfd.h and delete LITMEMCPY, LITSTRCPY
This fixes the issue that startswith depends on strncpy being
declared, and not all projects using bfd.h include string.h before
bfd.h.  I've also deleted some macros that don't find much use
anywhere.

bfd/
	* bfd-in.h: Include string.h.
	(LITMEMCPY, LITSTRCPY): Delete.
	* bfd-in2.h: Regenerate.
binutils/
	* prdbg.c (pr_function_type): Replace LITSTTCPY with strcpy.
2021-03-31 10:47:59 +10:30
Alan Modra
63b4cc53dc TRUE/FALSE simplification
There is really no need to write code like "foo != 0 ? TRUE : FALSE"
unless we had stupidly defined FALSE as something other than 0 or TRUE
as something other than 1.  The simpler "foo != 0" does just as well.
Similarly "(condition == TRUE)" or "(condition == FALSE) can be
simplified to "(condition)" and "(!condition)" respectively.

I'll note that there is reason to use "integer_expression != 0" when
assigning a bfd_boolean rather than the simpler "integer_expression",
if you expect the variable to have 0 or 1 value.  It's probably even a
good idea to not rely on implicit conversion if bfd_boolean were _Bool.

bfd/
	* aoutx.h (aout_link_write_symbols): Don't cast boolean expression
	to bfd_boolean.
	* elf32-or1k.c (or1k_set_got_and_rela_sizes): Dont compare booleans
	against FALSE.
	* elf32-arc.c (name_for_global_symbol): Don't compare boolean to TRUE.
	(is_reloc_PC_relative): Don't use "boolean_condition ? TRUE : FALSE".
	(is_reloc_SDA_relative, is_reloc_for_GOT): Likewise.
	(is_reloc_for_PLT, is_reloc_for_TLS): Likewise.
	* elf32-arm.c (stm32l4xx_need_create_replacing_stub): Likewise.
	* elf32-nds32.c (insert_nds32_elf_blank): Likewise.
	* elf32-rx.c (rx_set_section_contents): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_ignore_undef_symbol): Likewise.
	* mach-o.c (bfd_mach_o_read_command): Likewise.
	* targets.c (bfd_get_target_info): Likewise.
binutils/
	* dlltool.c (main): Don't use "boolean_condition ? TRUE : FALSE".
	* dwarf.c (read_and_display_attr_value): Likewise.
	(display_debug_str_offsets): Likewise.
	* objdump.c (dump_bfd): Likewise.
	* readelf.c (dump_section_as_strings): Likewise.
	(dump_section_as_bytes): Likewise.
gas/
	* atof-generic.c (FALSE, TRUE): Don't define.
	* config/obj-elf.h (FALSE, TRUE): Don't define.
	* config/obj-som.h (FALSE, TRUE): Don't define.
	* config/tc-hppa.h (FALSE, TRUE): Don't define.
	* config/tc-pdp11.c (FALSE, TRUE): Don't define.
	* config/tc-iq2000.h (obj_fix_adjustable): Delete.
	* config/tc-m32r.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-mt.h (obj_fix_adjustable): Delete.
	* config/tc-nds32.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-arc.c (parse_opcode_flags): Simplify boolean expression.
	(relaxable_flag, relaxable_operand, assemble_insn): Likewise.
	(tokenize_extregister): Likewise.
	* config/tc-csky.c (parse_opcode, get_operand_value): Likewise.
	(parse_operands_op, parse_operands, md_assemble): Likewise.
	* config/tc-d10v.c (build_insn): Likewise.
	* config/tc-score.c (s3_gen_insn_frag): Likewise.
	* config/tc-score7.c (s7_gen_insn_frag, s7_relax_frag): Likewise.
	* config/tc-tic6x.c (tic6x_update_features, md_assemble): Likewise.
	* config/tc-z80.c (emit_byte): Likewise.
include/
	* opcode/aarch64.h (alias_opcode_p): Simplify boolean expression.
	(opcode_has_alias, pseudo_opcode_p, optional_operand_p): Likewise.
	(opcode_has_special_coder): Likewise.
ld/
	* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Simplify
	boolean expression.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (pe_dll_id_target): Likewise.
opcodes/
	* aarch64-opc.c (vector_qualifier_p): Simplify boolean expression.
	(fp_qualifier_p, get_data_pattern): Likewise.
	(aarch64_get_operand_modifier_from_value): Likewise.
	(aarch64_extend_operator_p, aarch64_shift_operator_p): Likewise.
	(operand_variant_qualifier_p): Likewise.
	(qualifier_value_in_range_constraint_p): Likewise.
	(aarch64_get_qualifier_esize): Likewise.
	(aarch64_get_qualifier_nelem): Likewise.
	(aarch64_get_qualifier_standard_value): Likewise.
	(get_lower_bound, get_upper_bound): Likewise.
	(aarch64_find_best_match, match_operands_qualifier): Likewise.
	(aarch64_print_operand): Likewise.
	* aarch64-opc.h (operand_has_inserter, operand_has_extractor): Likewise.
	(operand_need_sign_extension, operand_need_shift_by_two): Likewise.
	(operand_need_shift_by_four, operand_maybe_stack_pointer): Likewise.
	* arm-dis.c (print_insn_mve, print_insn_thumb32): Likewise.
	* tic6x-dis.c (tic6x_check_fetch_packet_header): Likewise.
	(print_insn_tic6x): Likewise.
2021-03-29 11:22:22 +10:30
Alan Modra
1be305ffcd binutils int vs bfd_boolean fixes
* objdump.c (process_links): Use type int.
	* readelf.c (request_dump): Don't increment do_dump, set it.
	* windint.h (target_is_bigendian): Use type bfd_boolean.
	* windmc.c (target_is_bigendian): Likewise.
	* windres.c (target_is_bigendian): Likewise.
2021-03-29 11:22:21 +10:30
Martin Liska
08dedd6631 Add startswith function and use it instead of CONST_STRNEQ.
bfd/ChangeLog:

	* bfd-in.h (startswith): Add startswith function.
	(CONST_STRNEQ): Remove.
	* bfd-in2.h (startswith): Regenerate with make headers.
	* archive.c (bfd_slurp_armap): Replace usage of CONST_STRNEQ with startswith.
	(_bfd_slurp_extended_name_table): Likewise.
	* archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise.
	* bfd.c (bfd_get_sign_extend_vma): Likewise.
	(bfd_convert_section_size): Likewise.
	(bfd_convert_section_contents): Likewise.
	* coff-stgo32.c (go32exe_create_stub): Likewise.
	(go32exe_check_format): Likewise.
	* coffcode.h (styp_to_sec_flags): Likewise.
	(GNU_DEBUGALTLINK): Likewise.
	* coffgen.c (_bfd_coff_section_already_linked): Likewise.
	(coff_gc_sweep): Likewise.
	(bfd_coff_gc_sections): Likewise.
	* cofflink.c (coff_link_add_symbols): Likewise.
	(process_embedded_commands): Likewise.
	* compress.c (bfd_is_section_compressed_with_header): Likewise.
	(bfd_init_section_decompress_status): Likewise.
	* dwarf2.c (find_debug_info): Likewise.
	(place_sections): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_armap): Likewise.
	* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
	(assign_section_numbers): Likewise.
	(elfcore_grok_win32pstatus): Likewise.
	* elf32-arm.c (cmse_scan): Likewise.
	(elf32_arm_gc_mark_extra_sections): Likewise.
	(elf32_arm_size_dynamic_sections): Likewise.
	(is_arm_elf_unwind_section_name): Likewise.
	* elf32-bfin.c (bfin_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_size_dynamic_sections): Likewise.
	* elf32-csky.c (csky_elf_size_dynamic_sections): Likewise.
	* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_size_dynamic_sections): Likewise.
	* elf32-msp430.c (msp430_elf_relax_delete_bytes): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections): Likewise.
	* elf32-tic6x.c (is_tic6x_elf_unwind_section_name): Likewise.
	(elf32_tic6x_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise.
	(xtensa_is_insntable_section): Likewise.
	(xtensa_is_littable_section): Likewise.
	(xtensa_is_proptable_section): Likewise.
	(xtensa_property_section_name): Likewise.
	(xtensa_callback_required_dependence): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.
	* elf64-ia64-vms.c (is_unwind_section_name): Likewise.
	(get_reloc_section): Likewise.
	(elf64_ia64_size_dynamic_sections): Likewise.
	(elf64_ia64_object_p): Likewise.
	* elf64-mmix.c (mmix_elf_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	(_bfd_elf_gc_mark_extra_sections): Likewise.
	(bfd_elf_parse_eh_frame_entries): Likewise.
	(_bfd_elf_section_already_linked): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise.
	* elfnn-ia64.c (is_unwind_section_name): Likewise.
	(elfNN_ia64_size_dynamic_sections): Likewise.
	(elfNN_ia64_object_p): Likewise.
	* elfxx-mips.c (FN_STUB_P): Likewise.
	(CALL_STUB_P): Likewise.
	(CALL_FP_STUB_P): Likewise.
	(_bfd_mips_elf_section_from_shdr): Likewise.
	(_bfd_mips_elf_fake_sections): Likewise.
	(_bfd_mips_elf_size_dynamic_sections): Likewise.
	(_bfd_mips_final_write_processing): Likewise.
	(_bfd_mips_elf_final_link): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise.
	* elfxx-x86.c (elf_i386_is_reloc_section): Likewise.
	(elf_x86_64_is_reloc_section): Likewise.
	* hpux-core.c (thread_section_p): Likewise.
	* libcoff.h (bfd_pei_p): Likewise.
	* linker.c (REAL): Likewise.
	(unwrap_hash_lookup): Likewise.
	(_bfd_generic_link_add_one_symbol): Likewise.
	* mmo.c (mmo_internal_write_section): Likewise.
	* osf-core.c (osf_core_core_file_p): Likewise.
	* pef.c (bfd_pef_print_symbol): Likewise.
	* pei-x86_64.c (pex64_print_all_pdata_sections): Likewise.
	* som.c (som_slurp_symbol_table): Likewise.
	(som_slurp_armap): Likewise.
	* wasm-module.c (wasm_compute_custom_section_file_position): Likewise.

binutils/ChangeLog:

	* dlltool.c (scan_drectve_symbols): Replace usage of CONST_STRNEQ with startswith.
	* emul_aix.c (ar_emul_aix_parse_arg): Likewise.
	* objcopy.c (is_mergeable_note_section): Likewise.
	* objdump.c (dump_dwarf_section): Likewise.
	* prdbg.c (pr_method_type): Likewise.
	(pr_class_baseclass): Likewise.
	(tg_class_baseclass): Likewise.
	* readelf.c (process_lto_symbol_tables): Likewise.
	* stabs.c (ULLHIGH): Likewise.
	(parse_stab_argtypes): Likewise.
	(stab_demangle_function_name): Likewise.

gas/ChangeLog:

	* config/tc-i386.c (md_parse_option): Replace usage of CONST_STRNEQ with startswith.
	(x86_64_section_word): Likewise.
	* config/tc-sparc.c (md_parse_option): Likewise.

gdb/ChangeLog:

	* arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith.
	(_initialize_arm_tdep): Likewise.

ld/ChangeLog:

	* emultempl/aix.em: Replace usage of CONST_STRNEQ with startswith.
	* emultempl/beos.em: Likewise.
	* emultempl/elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldctor.c (ctor_prio): Likewise.
	* ldelf.c (ldelf_try_needed): Likewise.
	(ldelf_parse_ld_so_conf): Likewise.
	(ldelf_after_open): Likewise.
	(output_rel_find): Likewise.
	(ldelf_place_orphan): Likewise.
	* ldfile.c (ldfile_add_library_path): Likewise.
	* ldlang.c (lang_add_input_file): Likewise.
	* ldmain.c (get_sysroot): Likewise.
	(get_emulation): Likewise.
	(add_archive_element): Likewise.
	* ldwrite.c (unsplittable_name): Likewise.
	(clone_section): Likewise.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (is_import): Likewise.
	(pe_implied_import_dll): Likewise.

opcodes/ChangeLog:

	* aarch64-dis.c (parse_aarch64_dis_option): Replace usage of CONST_STRNEQ with startswith.
	* arc-dis.c (parse_option): Likewise.
	* arm-dis.c (parse_arm_disassembler_options): Likewise.
	* cris-dis.c (print_with_operands): Likewise.
	* h8300-dis.c (bfd_h8_disassemble): Likewise.
	* i386-dis.c (print_insn): Likewise.
	* ia64-gen.c (fetch_insn_class): Likewise.
	(parse_resource_users): Likewise.
	(in_iclass): Likewise.
	(lookup_specifier): Likewise.
	(insert_opcode_dependencies): Likewise.
	* mips-dis.c (parse_mips_ase_option): Likewise.
	(parse_mips_dis_option): Likewise.
	* s390-dis.c (disassemble_init_s390): Likewise.
	* wasm32-dis.c (parse_wasm32_disassembler_options): Likewise.
2021-03-22 11:01:43 +01:00
H.J. Lu
7b9f985957 elf: Rename EM_INTEL205 to EM_INTELGT
Rename EM_INTEL205 to EM_INTELGT for Intel Graphics Technology.

binutils/

	* readelf.c (get_machine_name): Add EM_INTELGT.

include/

	* elf/common.h (EM_INTEL205): Renamed to ...
	(EM_INTELGT): This.
2021-03-19 05:58:46 -07:00
Nick Clifton
835f2fae11 Fix section dumping so that warnings are not issued for missed sections in separate debuginfo files.
PR 27478
	* readelf.c (dump_section_as_strings): Mention separate filename.
	(dump_section_as_bytes): Likewise.
	(dump_section_as_ctf): Likewise.
	(initialise_dumkps_byname): Only issue a warning for missing
	sections if processing the main file.
	(process_section_contents): Only issue a warning for unsumped
	section numbers in the main file.
	(initialise_dump_sects): New function.  Contains code extracted
	from ...
	(process_object): ... here.  Also call initialise_dump_sects for
	separate files.
2021-03-18 14:01:25 +00:00
Nick Clifton
44266f362b Retain .debug_addr sections loaded in the main file.
PR 27534
	* readelf.c (display_debug_section): Also retain .debug_addr
	sections.
2021-03-16 18:01:58 +00:00
Nick Clifton
d6bfbc3981 Re-enable the dislay of debug sections in separate debuginfo files without the need for -P.
PR 27533
	* readelf.c (process_section_contents): Only dump debug
	information for separate files unless process_links is enabled.
	(process_object): Always call process_section_contents for
	separate info files.
2021-03-16 16:39:46 +00:00
Nick Clifton
1996d0f12c Add a symbols-only mode to nm.
PR 27487
	* nm.c (FORMAT_JUST_SYMBOLS): Define.
	(struct optput_fns): Add entry for FORMAT_JUST_SYMBOLS.
	(long_options): Add just-symbols.
	(set_output_format): Add support for just-symbols.
	(get_print_format): Likewise.
	(do_not_print_object_filename): New function.
	(do_not_print_archive_filename): New function.
	(do_not_print_archive_member): New function.
	(do_not_print_symbol_filename): New function.
	(just_print_symbol_name): New function.
	(main): Handle --just-symbols.
	* NEWS: Mention the new feature.
	* doc/binutils.texi: Document the new feature.
2021-03-15 10:55:49 +00:00
Clément Chigot
2c1bef53de aix: correct HOWTO table and add missing relocations
Since the last time AIX HOWTO table was modified, IBM has now
released an official documentation about XCOFF relocations.
This commit corrects the wrong ones and add some missing.
For now, the "custom" relocations made for xcoff_rtype2howto have
been kept.
The new relocations are still set as EMPTY_HOWTO because they will
be implemented in later commits.

In xcoff[64]_ppc_relocate_section, instead of recreating howto
from scratch, it's better to use the existing howto from the
table and fixing it according to r_size field.

bfd/
	* coff-rs6000.c (xcoff_calculate_relocation): Correct and
	add new relocations.
	(xcoff_howto_table): Likewise.
	(xcoff_rtype2howto): Increase r_type maximum value.
	(xcoff_ppc_relocate_section): Reuse predefined HOWTOs instead
	of create a new one from scratch.  Enable only some relocations
	to have a changing r_size.
	* coff64-rs6000.c (xcoff64_calculate_relocation): Likewise.
	(xcoff64_howto_table): Likewise.
	(xcoff64_rtype2howto): Likewise.
	(xcoff64_ppc_relocate_section): Likewise.
	* libxcoff.h (XCOFF_MAX_CALCULATE_RELOCATION): Fix value.
binutils/
	* od-xcoff.c: Replace RTB by TRL entry.
include/
	* coff/xcoff.h (R_RTB): Remove.
	(R_TRL): Fix value.
2021-03-12 22:08:20 +10:30
Andrew Burgess
db6092f3ae bfd/binutils: add support for RISC-V CSRs in core files
Adds support for including RISC-V control and status registers into
core files.

The value for the define NT_RISCV_CSR is set to 0x900, this
corresponds to a patch I have proposed for the Linux kernel here:

  http://lists.infradead.org/pipermail/linux-riscv/2020-December/003910.html

As I have not yet heard if the above patch will be accepted into the
kernel or not I have set the note name string to "GDB", and the note
type to NT_RISCV_CSR.

This means that if the above patch is rejected from the kernel, and
the note type number 0x900 is assigned to some other note type, we
will still be able to distinguish between the GDB produced
NT_RISCV_CSR, and the kernel produced notes, where the name would be
set to "CORE".

bfd/ChangeLog:

	* elf-bfd.h (elfcore_write_riscv_csr): Declare.
	* elf.c (elfcore_grok_riscv_csr): New function.
	(elfcore_grok_note): Handle NT_RISCV_CSR.
	(elfcore_write_riscv_csr): New function.
	(elfcore_write_register_note): Handle '.reg-riscv-csr'.

binutils/ChangeLog:

	* readelf.c (get_note_type): Handle NT_RISCV_CSR.

include/ChangeLog:

	* elf/common.h (NT_RISCV_CSR): Define.
2021-03-05 17:21:41 +00:00
Andrew Burgess
b63a5e38ef bfd/binutils: support for gdb target descriptions in the core file
This commit lays the ground work for allowing GDB to write its target
description into a generated core file.

The goal of this work is to allow a user to connect to a remote
target, capture a core file from within GDB, then pass the executable
and core file to another user and have the user be able to examine the
state of the machine without needing to connect to a running target.

Different remote targets can have different register sets and this
information is communicated from the target to GDB in the target
description.

It is possible for a user to extract the target description from GDB
and pass this along with the core file so that when the core file is
used the target description can be fed back into GDB, however this is
not a great user experience.

It would be nicer, I think, if GDB could write the target description
directly into the core file, and then make use of this description
when loading a core file.

This commit performs the binutils/bfd side of this task, adding the
boiler plate functions to access the target description from within a
core file note, and reserving a new number for a note containing the
target description.  Later commits will extend GDB to make use of
this.

The new note is given the name 'GDB' and a type NT_GDB_TDESC.  This
should hopefully protect us if there's ever a reuse of the number
assigned to NT_GDB_TDESC by some other core file producer.  It should
also, hopefully, make it clearer to users that this note carries GDB
specific information.

bfd/ChangeLog:

	* elf-bfd.h (elfcore_write_gdb_tdesc): Declare new function.
	* elf.c (elfcore_grok_gdb_tdesc): New function.
	(elfcore_grok_note): Handle NT_GDB_TDESC.
	(elfcore_write_gdb_tdesc): New function.
	(elfcore_write_register_note): Handle NT_GDB_TDESC.

binutils/ChangeLog:

	* readelf.c (get_note_type): Handle NT_GDB_TDESC.

include/ChangeLog:

	* elf/common.h (NT_GDB_TDESC): Define.
2021-03-05 17:21:40 +00:00
Nick Clifton
d296b73620 Fix the dislay of .debug_macro.dwo sections.
PR 27387
	* dwarf.c (display_debug_macro): Handle the displaying of
	DW_MACRO_define_strp and DW_MACRO_undef_strp in v4
	.debug_macro.dwo sections.
2021-03-05 12:56:24 +00:00
Nick Clifton
ca0e11aa4b Gate the displaying of non-debug sections in separate debuginfo files.
PR 27478
	* objdump.c (process_links): New variable.
	(usage): Add --process-links.
	(long_options): Likewise.
	(dump_bfd): Stop processing once the bfd has been loaded unless
	this is the main file or process_links has been enabled.
	(main): Handle the process-links option.
	* readelf.c (process_links): New variable.
	(struct filedata): Add is_separate field.
	(options): Add --process-links.
	(usage): Likewise.
	(parse_args): Likewise.
	(process_file_header): Include the filename when dumping
	information for separate debuginfo files.
	(process_program_headers): Likewise.
	(process_section_headers): Likewise.
	(process_section_groups): Likewise.
	(process_relocs): Likewise.
	(process_dynamic_section): Likewise.
	(process_version_sections): Likewise.
	(display_lto_symtab): Likewise.
	(process_symbol_table): Likewise.
	(process_syminfo): Likewise.
	(initialise_dumps_by_name): Likewise.
	(process_section_contents): Likewise.
	(process_notes_at): Likewise.
	(process_notes): Likewise.
	(open_file): Add is_separate parameter.  Use to initialise the
	is_separate field in the filedata structure.
	(open_deug): Update call to open_file.
	(process_object): Add processing of the contents of separate
	debuginfo files, gated by the process_links variable.
	(process_archive): Update call to open_file.
	(process_file): Initialise the is_separate field in the filedata
	structure.
	* dwarf.c (load_separate_debug_info_file): Only report the
	loading of a separate file if debug links are being dumped.
	* objcopy.c (keep_section_symbols): New variable.
	(enum command_line_switch): Add OPTION_KEEP_SYMBOLS.
	(strip_options): Add keep-section-symbols.
	(copy_options): Likewise.
	(copy_usage): Likewise.
	(strip_usage): Likewise.
	(copy_object): Keep section symbols if requested by command line
	option.
	(strip_main): Handle --keep-section-symbols.
	(copy_main): Likewise.
	* doc/binutils.texi: Document the new options.
	* NEWS: Mention the new features.
	* testsuite/binutils-all/compress.exp (test_gnu_debuglink):
	Update options passed to objdump.  Use diff rather than cmp to
	compare the dumped data.
	* testsuite/binutils-all/objdump.WK2: Update regexp.
	* testsuite/binutils-all/objdump.WK3: Update regexp.
	* testsuite/binutils-all/objdump.exp: Use --process-links
	instead of --dwarf=follow-links.
	* testsuite/binutils-all/readelf.exp (readelf_test): Include
	readelf's output in the log when the test fails.
	Add the -P option to the -wKis test.
	* testsuite/binutils-all/readelf.wKis: Update expected output.
2021-03-04 10:41:22 +00:00
Alan Modra
fd5c076a06 PR27493, objcopy --weaken-symbol does not weaken undefined symbols
PR 27493
	* objcopy.c (filter_symbols): Apply --weaken to undefined symbols.
	* NEWS: Mention feature.
2021-03-03 17:46:52 +10:30
H.J. Lu
ecd65684f5 Warn for missing separate debug files only if needed
We shouldn't warn missing separate debug files when debug info isn't
needed.

	PR binutils/27486
	* dwarf.c (load_separate_debug_info): Issue warning only if
	do_debug_links is set.
	* testsuite/binutils-all/compress.exp: Run objdump and readelf
	with missing debug file.
2021-03-01 05:34:47 -08:00
Alan Modra
6a1224ec76 PR27128, nm -P portable output format regression
Add nm --without-symbol-versions.

binutils/
	PR 27128
	* doc/binutils.texi: Add nm --with-symbol-versions and
	--without-symbol-versions documentation.
	* nm.c (with_symbol_versions): New variable.
	(enum long_option_values): Delete OPTION_WITH_SYMBOL_VERSIONS.
	(long_options): Make --with-symbol-versions entry twiddle the flag.
	Add --without-symbol-versions.
	(print_symname): Strip version when !with_symbol_versions.  Add
	dynamic version info under control of with_symbol_versions.
	(main): Remove OPTION_WITH_SYMBOL_VERSIONS case.
ld/
	* testsuite/ld-elf/pr25708.d: Add --with-symbol-versions to nm.
	* testsuite/ld-elf/pr27128a.d: Likewise.
	* testsuite/ld-elf/pr27128b.d: Likewise.
	* testsuite/ld-elf/pr27128c.d: Likewise.
	* testsuite/ld-elf/pr27128d.d: Likewise.
	* testsuite/ld-elf/pr27128e.d: Likewise.
2021-03-01 14:26:39 +10:30
Fangrui Song
7fe1b1388f nm: Add --quiet to suppress "no symbols" diagnostic
PR binutils/27408
	* readelf.c (quiet): New option flag.
	(enum long_option_values): New enum to hold long option value.
	(long_options): Add --quiet.
	(usage): Mention --quiet.
	(display_rel_file): If quiet is enabled, suppress "no symbols".
	(main): Handle the new option.
	* NEWS: Mention --quiet.
	* docs/binutils.texi: Document --quiet.
2021-02-26 09:26:41 -08:00
Tom de Vries
0e12f6c802 Add support for decoding DWARF v5 DW_AT_addr_base tags.
* dwarf.c (display_debug_addr): Handle dwarf-5 .debug_addr bits.
2021-02-26 15:52:39 +00:00
Tom de Vries
32e4f96cec Add support for the split DWARF forms.
PR 27390
	* dwarf.c: (skip_attr_bytes): Add support for DW_FORM_str* and
	DW_FORM_addrx*.
	(read_and_display_attr_value): Likewise.
2021-02-26 13:30:10 +00:00
Nick Clifton
e38332c286 Add initial support for .debug_sup sections.
* dwarf.c (get_type_abbrev_from_form): Accept but ignore sup
	forms.
	(read_and_display_attr_value): Handle sup forms.
	(display_debug_sup): New function.  Displays the contents of a
	.debug_sup section.
	(load_debug_sup_file): New function.  Loads the contents of a file
	referenced by a .debug_sup section.
	(check_for_and_load_links): Call load_debug_sup_file.
	(debug_displays): Add entry for .debug_sup.
	* dwarf.h (enum dwarf_section_display_enum): Add debug_sup.
	* readelf.c (process_section_headers): Add support for debug_sup.
	* doc/debug.options.texi: Note that the =links option will display
	the contents of .debug_sup sections.
	* NEWS: Mention the new support.
2021-02-25 17:50:44 +00:00
Alan Modra
40b02646ec Re: Use make_tempname file descriptor in smart_rename
PR 27456
	* rename.c (simple_copy): Mark target_stat ATTRIBUTE_UNUSED.
2021-02-25 09:48:17 +10:30
Nick Clifton
9d3fcfe068 Fix a potential integer overflow when adding together section sizes for the AVR port of objdump.
PR 27285
	* od-elf32_avr.c (elf32_avr_get_memory_usage): Check for overflows
	when adding together the section sizes.
2021-02-24 14:14:45 +00:00
Nick Clifton
c74147bbe0 Remove support for old v1 & v2 style GNU build notes.
* objcopy.c (merge_gnu_build_notes): Remove support for v1/v2 GNU
	build notes.
	* readelf.c (print_gnu_build_attribute_description): Likewise.
2021-02-24 10:08:56 +00:00
Alan Modra
c42c71a152 Use make_tempname file descriptor in smart_rename
This patch makes use of the temp file descriptor in smart_rename
rather than reopening the file.  I don't believe there is a security
issue in reopening the file, but this way is one less directory
operation.  The patch also attempts to preserve S_ISUID and S_ISGID.

	PR 27456
	* bucomm.h (smart_rename): Update prototype.
	* rename.c (smart_rename): Add fromfd and preserve_dates params.
	Pass fromfd and target_stat to simple_copy.  Call set_times
	when preserve_dates.
	(simple_copy): Accept fromfd rather than from filename.  Add
	target_stat param.  Rewind fromfd rather than opening.  Open
	"to" file without O_CREAT.  Try to preserve S_ISUID and S_ISGID.
	* ar.c (write_archive): Rename ofd to tmpfd.  Dup tmpfd before
	closing output temp file, and pass tmpfd to smart_rename.
	* arsup.c (temp_fd): Rename from real_fd.
	(ar_save): Dup temp_fd and pass to smart_rename.
	* objcopy.c (strip_main, copy_main): Likewise, and pass
	preserve_dates.
2021-02-24 09:34:42 +10:30
Alan Modra
cca8873dd5 PR27456, lstat in rename.c on MinGW
PR 27456
	* rename.c: Tidy throughout.
	(smart_rename): Always copy.  Remove windows specific code.
2021-02-24 09:33:01 +10:30
H.J. Lu
8c3853d9e8 readelf: Replace procesor with processor
binutils/

	PR binutils/27445
	* readelf.c (print_gnu_property_note): Replace procesor with
	processor.

ld/

	PR binutils/27445
	* testsuite/ld-i386/property-x86-isa1.d: Replace procesor with
	processor.
	* testsuite/ld-x86-64/property-x86-isa1-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1.d: Likewise.
2021-02-20 05:55:42 -08:00
Alan Modra
4d496013a2 Fail run_dump_test when an error is expected but not seen
* testsuite/lib/binutils-common.exp: Whitespace fixes throughout.
	(run_dump_test): Fail if expecting errors from a file like we do
	for error strings, if no error is seen.
2021-02-20 18:26:10 +10:30
Alan Modra
0be51eb4c3 pr26548 test
I forgot that .sleb128 handles bignums, so this test should run fine
for 32-bit targets on 32-bit hosts.

	* testsuite/binutils-all/readelf.exp (pr26548): Run for 32-bit too.
2021-02-19 13:49:15 +10:30
Siddhesh Poyarekar
3685de750e binutils: Avoid renaming over existing files
Renaming over existing files needs additional care to restore
permissions and ownership, which may not always succeed.
Additionally, other properties of the file such as extended attributes
may be lost, making the operation flaky.

For predictable results, resort to rename() only if the file does not
exist, otherwise copy the file contents into the existing file.  This
ensures that no additional tricks are needed to retain file
properties.

This also allows dropping of the redundant set_times on the tmpfile in
objcopy/strip since now we no longer rename over existing files.

binutils/

	* ar.c (write_archive): Remove TARGET_STAT.  Adjust call to
	SMART_RENAME.
	* arsup.c (ar_save): Likewise.
	* objcopy (strip_main): Don't copy TMPFD.  Don't set times on
	temporary file and adjust call to SMART_RENAME.
	(copy_main): Likewise.
	* rename.c [!S_ISLNK]: Remove definitions.
	(try_preserve_permissions): Remove function.
	(smart_rename): Remove FD, PRESERVE_DATES arguments.  Use
	rename system call only if TO does not exist.
	* bucomm.h (smart_rename): Adjust declaration.
2021-02-19 08:05:33 +05:30
Nick Clifton
8568422270 Fix a problem merging empty annobin notes on ppc64le targets.
* objcopy.c (merge_gnu_build_notes): Handle notes with a start
	address that is higher than the end address.
2021-02-18 11:43:26 +00:00
Alan Modra
b9b204b311 read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote.  It's to do with sleb128
values that have unnecessary excess bytes.  For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on.  None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes.  This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts.  (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value.  A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts.  Mind you, it is very unlikely
to be compiling binutils with such a compiler.)

bfd/
	* wasm-module.c: Guard include of limits.h.
	(CHAR_BIT): Provide backup define.
	(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
	Correct signed overflow checking.
opcodes/
	* wasm32-dis.c: Include limits.h.
	(CHAR_BIT): Provide backup define.
	(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
	Correct signed overflow checking.
binutils/
	* dwarf.c: Include limits.h.
	(CHAR_BIT): Provide backup define.
	(read_leb128): Use CHAR_BIT to size "result" in bits.  Correct
	signed overflow checking.
	* testsuite/binutils-all/pr26548.s,
	* testsuite/binutils-all/pr26548.d,
	* testsuite/binutils-all/pr26548e.d: New tests.
	* testsuite/binutils-all/readelf.exp: Run them.
	(readelf_test): Drop unused "xfails" parameter.  Update all uses.
2021-02-17 16:57:59 +10:30
Jan Beulich
e6ca18783f Dwarf: fix build with old gcc
4.3-ish warns about a possibly uninitialized variable, which results in
a build failure due to -Werror.
2021-02-16 11:26:00 +01:00
Alan Modra
208599d928 objdump: don't cache section contents in load_specific_debug_section
* objdump.c (load_specific_debug_section): Don't call
	bfd_cache_section_contents.  Rearrange so that
	bfd_get_full_section_contents is not called on path where
	bfd_simple_get_relocated_section_contents is called.
	Don't set section->user_data.
	(free_debug_section): Always free section->start.  Don't twiddle
	section flags.
	* readelf.c (load_specific_debug_section): Don't set user_data.
	* dwarf.h (struct dwarf_section): Remove use_data field.
	* dwarf.c (NO_ABBREVS, ABBREV): Adjust to suit.
2021-02-15 13:34:08 +10:30
Alan Modra
1781a9d0f3 nds32_elf_get_relocated_section_contents
nds32_elf_get_relocated_section_contents uses nds32_get_section_contents
to read sections contents, but nds32_get_section_contents has the wrong
behaviour as it calls bfd_malloc_and_get_section.  That function always
mallocs its output buffer, whereas get_relocated_section_contents must
support an already allocated buffer.

bfd/
	* elf32-nds32.c (nds32_get_section_contents): Replace
	bfd_malloc_and_get_section with bfd_get_full_section_contents.
	(nds32_elf_relax_delete_blanks): Init contents.
	(nds32_elf_relax_section, nds32_relax_fp_as_gp): Likewise.
binutils/
	* testsuite/binutils-all/compress.exp: Remove nds32 xfails.
	* testsuite/binutils-all/objdump.exp: Likewise.
2021-02-15 13:34:08 +10:30
Alan Modra
1944212b42 objdump: don't add an extra entry to syms array
Space for a NULL is there in every backend bfd_get_symtab_upper_bound
or bfd_get_dynamic_symtab_upper_bound when the symbol count is non-zero,
and placed as a terminator by bfd_canonicalize_symtab.  Many backends
even return a single NULL entry array for zero symbol count, and while
there are a few that return a NULL array for no symbols, that case is
handled fine in objdump.  So don't have objdump add yet another NULL
entry.

	* objdump.c (slurp_symtab): Don't add an extra entry for NULL
	to the symbol array.
	(slurp_dynamic_symtab): Likewise.
	(dump_bfd): Formatting.  Copy terminating NULL from extra_syms.
2021-02-14 22:54:12 +10:30
Alan Modra
0d0a0d86c8 Regen for binutils/aclocal.m4 change
* Makefile.in: Regenerate.
	* doc/Makefile.in: Regenerate.
2021-02-14 22:35:32 +10:30
Mike Frysinger
adeab0c5b3 config/debuginfod: do not include pkg.m4 directly
Any code using AC_DEBUGINFOD from this dir is using -I../config when
running aclocal, so an explicit include on pkg.m4 is unnecessary:
aclocal will find the pkg.m4 in this dir just as easily.  This is
seen in the only two dirs that use AC_DEBUGINFOD (binutils & gdb)
as their aclocal.m4 already has m4_include on config m4 files.

The include as written only works if aclocal is run on a dir that is
at the same level of config/.  Any other depth will fail.
./
|-- config/
|-- binutils/    # works
|-- gdb/         # works
`-- sim/         # works
    `-- <port>/  # fails

It fails even if AC_DEBUGINFOD itself isn't used:
sim/bfin/ $ aclocal -I../../config
aclocal-1.15: error: ../../config/debuginfod.m4:8: file '../config/pkg.m4' does not exist
2021-02-13 00:15:11 -05:00
Nick Clifton
c46b706620 Change the readelf and objdump programs so that they will automatically follow links to separate debug info files.
* configure.ac (follow-debug-links): Add option to enable or
	disable the following of debug links by default.  Set the
	default for the option to be 'follow'.
	* dwarf.c (do_follow_links): Initialise with DEFAULT_FOR_FOLLOW_LINKS.
	(dwarf_select_sections_by_names): Add no-follow-links option.
	(dwarf_select_sections_by_letter): Add 'N' option.
	* objdump.c (usage): Add conditional text describing the
	follow links option.
	(slurp_symtab): Ensure that there is a NULL entry at the end
	of the symbol table.
	(slurp_dynamic_symtab): Likewise.
	(dump_bfd): When extending the symbol table, ensure that there
	is still a NULL entry at the end.
	* readelf.c (usage): Add conditional text describing the
	follow links option.
	* doc/binutils.texi: Update documentation for objcopy and
	readelf.
	* doc/debug.options.texi: Update documentation of the
	follow-links option.
	* config.in: Regenerate.
	* configure: Regenerate.
	* testsuite/binutils-all/compress.exp: Add the -WN option to
	objdump command lines that are not expecting to follow links.
	* testsuite/binutils-all/readelf.exp: Add the
	--debug-dump=no-follow-links option to tests that are not
	expecting to follow debug links.

gas	* testsuite/gas/mach-o/sections-1.d: Stop automatic debug link
        following.
	* testsuite/gas/xgate/insns-dwarf2.d: Likewise.

ld	* testsuite/ld-elf/sec64k.exp: Stop readelf from automatically
	following debug links.
2021-02-12 14:52:22 +00:00
Alan Modra
17e04eff81 binutils testsuite: replace unresolved with unsupported
You'd think "unresolved" would be correct for an objcopy test when the
assembler refuses to assemble one of our source files.  After all, the
test of objcopy hasn't been run.  However, "unresolved" results in
runtest returning with an error status.  If instead we report
"unsupported", runtest returns success.  Which is a little less
confusing to a user who doesn't see any errors reported unless they
look in log files.

	* testsuite/binutils-all/objcopy.exp: Report "unsupported" when
	gas or ld fails to build a testcase rather than "unresolved".
	Report "fail" when readelf returns an error status rather than
	"unresolved".
	* testsuite/binutils-all/ar.exp: Likewise.
	* testsuite/binutils-all/compress.exp: Likewise.
	* testsuite/binutils-all/readelf.exp: Likewise.
2021-02-12 18:56:05 +10:30