Commit Graph

15579 Commits

Author SHA1 Message Date
GDB Administrator 8e71a6e725 Automatic date update in version.in 2019-11-06 00:00:41 +00:00
Tim R?hsen 3a70f7e8e3 Fix memory allocation and release problems in the bfd documentation processor.
* doc/chew.c (add_to_definition): Use correct type when
	calculating size of array reallocation.
	(nextword): Always initialise the word return parameter.
	(compile): Check return value of nextword().
2019-11-05 16:03:07 +00:00
GDB Administrator 73ddaae155 Automatic date update in version.in 2019-11-05 00:00:18 +00:00
GDB Administrator 5e874de30b Automatic date update in version.in 2019-11-04 00:00:16 +00:00
GDB Administrator 10d2e6b9c9 Automatic date update in version.in 2019-11-03 00:01:13 +00:00
GDB Administrator a1dc3a23d0 Automatic date update in version.in 2019-11-02 00:00:15 +00:00
GDB Administrator d0d6922c68 Automatic date update in version.in 2019-11-01 00:00:27 +00:00
GDB Administrator c7e49b689b Automatic date update in version.in 2019-10-31 00:00:22 +00:00
Keith Seitz 864619bb2e Add the ability to the BFD library to read build-ids from core flies.
* elf-bfd.h (elf_backend_data) <elf_backend_core_find_build_id>:
	New field.
	(_bfd_elf32_core_find_build_id, _bfd_elf64_core_find_build_id):
	New functions.
	(elf_read_notes): Add declaration.
	* elf.c (elf_read_notes): Move elf-bfd.h.
	(_bfd_elf_core_find_build_id): New function.
	(bfd_section_from_phdr): Scan core file PT_LOAD segments for
	build-id if none is known.
	(elf_parse_notes): For core files, scan for notes.
	* elfcore.h (elf_core_file_matches_executable_p): If both
	BFDs have identical build-ids, then they match.
	(_bfd_elf_core_find_build_id): New function.
	* elfxx-target.h (elf_backend_core_find_build_id): Define.
	(elfNN_bed): Add elf_backend_core_find_build_id.
2019-10-30 12:23:16 +00:00
GDB Administrator 74fb338f46 Automatic date update in version.in 2019-10-30 00:01:25 +00:00
Andrew Eikum 70cf683455 When copying pe format files, copy the dos_message array, rather than re-initiialising it.
* libcoff-in.h (struct pe_tdata): Add dos_message field.
	* libcoff.h: Regenerate.
	* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Copy the
	dos_message field rather than initialising it.
	(_bfd_XX_bfd_copy_private_bfd_data_common): Copy the dos_message
	field.
	* peicode.h (pe_mkobject): Initialise the dos_message field.
	(pe_mkobject_hook): Copy the dos_message field.
	(pe_bfd_object_p): Copy the dos_message field.
2019-10-29 17:07:03 +00:00
GDB Administrator d7b510baa8 Automatic date update in version.in 2019-10-29 00:00:34 +00:00
GDB Administrator 12c3e9173e Automatic date update in version.in 2019-10-28 00:00:43 +00:00
GDB Administrator e9c999a28f Automatic date update in version.in 2019-10-27 00:02:01 +00:00
GDB Administrator 25294a18fd Automatic date update in version.in 2019-10-26 00:00:44 +00:00
Alan Modra 30fe183248 PR4499, assign file positions assumes segment offsets increasing
This rewrites much of assign_file_positions_for_non_load_sections to
allow objcopy and strip to handle cases like that in PR4499 where
program headers were not in their usual position immediately after the
ELF file header, and PT_LOAD headers were not sorted by paddr.

	PR 4499
include/
	* elf/internal.h (struct elf_segment_map): Delete header_size.
	Add no_sort_lma and idx.
bfd/
	* elf-nacl.c (nacl_modify_segment_map): Set no_sort_lma for all
	PT_LOAD segments.
	* elf32-spu.c (spu_elf_modify_segment_map): Likewise on overlay
	PT_LOAD segments.
	* elf.c (elf_sort_segments): New function.
	(assign_file_positions_except_relocs): Use shortcuts to elfheader
	and elf_tdata.  Seek to e_phoff not sizeof_ehdr to write program
	headers.  Move PT_PHDR check..
	(assign_file_positions_for_non_load_sections): ..and code setting
	PT_PHDR p_vaddr and p_paddr, and code setting __ehdr_start value..
	(assign_file_positions_for_load_sections): ..to here.  Sort
	PT_LOAD headers.  Delete header_pad code.  Use actual number of
	headers rather than allocated in calculating size for program
	headers.  Don't assume program headers follow ELF file header.
	Simplify pt_load_count code.  Only set "off" for PT_LOAD or
	PT_NOTE in cores.
	(rewrite_elf_program_header): Set p_vaddr_offset for segments
	that include file and program headers.
	(copy_elf_program_header): Likewise, replacing header_size code.
2019-10-25 13:30:05 +10:30
GDB Administrator e2ffdcea6c Automatic date update in version.in 2019-10-25 00:01:28 +00:00
GDB Administrator 867c09822c Automatic date update in version.in 2019-10-24 00:00:24 +00:00
GDB Administrator 6a093f341b Automatic date update in version.in 2019-10-23 00:00:20 +00:00
GDB Administrator 5ae8188eaa Automatic date update in version.in 2019-10-22 00:00:22 +00:00
Alan Modra 95cc7c169c ar P support
This patch extends "ar P" to allow creation of normal (as distinct
from thin) archives with full path names.

	PR 452
	PR 25104
bfd/
	* archive.c (normalize): Return file unchanged when
	BFD_ARCHIVE_FULL_PATH.
	(_bfd_construct_extended_name_table): Pass abfd, the output
	bfd, to normalize.
	(_bfd_archive_bsd44_construct_extended_name_table): Likewise.
	* bfd.c (struct bfd): Make flags a full flagword.
	(BFD_ARCHIVE_FULL_PATH): Define.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Set BFD_ARCHIVE_FULL_PATH.
	* doc/binutils.texi (extract from archive): Mention
	restrictions when extracting from archives with full paths.
	(ar P): Update to current P support.
	(ar -X32_64): Fix spelling.
2019-10-21 16:13:39 +10:30
GDB Administrator fd65fe1a18 Automatic date update in version.in 2019-10-21 00:00:52 +00:00
John David Anglin 2c9e9550ca [bfd] Provide 8-byte minimum alignment for .plt section
This change increases the default alignment for the .plt section
	from 4 bytes to 8 bytes.  When function descriptors are 8-byte
	aligned, they can be updated atomically on 32-bit hppa.  This
	helps with ordering issues on SMP machines.  It also ensures
	that descriptors reside on the same cache line.  This reduces
	the probability of a double TLB miss in a call.

	2019-10-20  John David Anglin  <danglin@gcc.gnu.org>

		* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Provide 8-byte
		minimum alignment for .plt section.
2019-10-20 12:01:58 -04:00
GDB Administrator 80051c7439 Automatic date update in version.in 2019-10-20 00:01:57 +00:00
John David Anglin 18338fcee6 [bfd] Revise import stubs on hppa.
This commit updates the import stubs to leave the pointer to the
	function descriptor in register %r22.  This provides a backup
	mechanism for _dl_runtime_resolve to fixup descriptors during
	lazy binding.

	bfd/ChangeLog
	2019-10-19  John David Anglin  <danglin@gcc.gnu.org>

		* elf32-hppa.c: Revise import stub sequences.
		(LONG_BRANCH_STUB_SIZE): Define.
		(LONG_BRANCH_SHARED_STUB_SIZE): Define.
		(IMPORT_STUB_SIZE): Define.
		(IMPORT_SHARED_STUB_SIZE): Define.
		(EXPORT_STUB_SIZE): Define.
		(plt_stub): Revise to not use register %r22.
		(LDO_R1_R22): Define.
		(LDW_R22_R21): Define.
		(LDW_R22_R19): Define.
		(hppa_build_one_stub): Update stub generation and use new defines.
		(hppa_size_one_stub): Likewise.
2019-10-19 13:52:23 -04:00
GDB Administrator 5a023697e1 Automatic date update in version.in 2019-10-19 00:00:34 +00:00
GDB Administrator 39849b0503 Automatic date update in version.in 2019-10-18 00:00:20 +00:00
Jim Wilson 330a6637a5 RISC-V: Report unresolved relocation error via linker's callback function.
Two patches from Nelson Chu.

It is better to use the linker's callback functions to handle the link time
error when relocating.  The unresolved relocation error can be regarded as
an unsupported relocation.  To make user easier to understand different errors,
we need to extend the current error message format of the callback function
since the format is fixed.

	bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Use asprintf to extend
	the error message if needed, and then store the result into the
	`msg_buf`.  Finally, remember to free the unused `msg_buf`.  All error
	message for the dangerous relocation should be set before we call the
	callback function.  If we miss the error message since linker runs out
	of memory, we should set the default error message for the error.

	ld/
	* testsuite/ld-riscv-elf/lib-nopic-01a.s: Create the shared library
	lib-nopic-01a.so, it will be linked with lib-nopic-01b.s.
	* testsuite/ld-riscv-elf/lib-nopic-01b.s: Add new test for the
	unresolved relocation.  Link the non-pic code into a shared library
	may cause the error.
	* testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run the new test only when
	the shared library is supported.

R_RISCV_CALL, R_RISCV_JAL and R_RISCV_RVC_JUMP are pc-relative relocation.
For now, we do not allow the object with these relocation links into a shared
library since the referenced symbols may be loaded to the places that too far
from the pc.  We can improve the error message for these unsupported relocation
to notice user that they should recompile their code with `fPIC`.

	bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Report the error message
	that user should recompile their code with `fPIC` when linking non-pic
	code into shared library.

	ld/
	* testsuite/ld-riscv-elf/lib-nopic-01b.d: Update the error message.

Change-Id: Ib3347a0a6fa1c2b20a9647c314d5bec2c322ff04
2019-10-17 15:38:27 -07:00
GDB Administrator 611fa2f46c Automatic date update in version.in 2019-10-17 00:00:23 +00:00
Alan Modra 22216541c1 PR13616, linker should pad executable sections with nops, not zeros
This implements padding of orphan executable sections for PowerPC.
Of course, the simple implementation of bfd_arch_ppc_nop_fill and
removing the NOP definition didn't work, with powerpc64 hitting a
testsuite failure linking to S-records.  That's because the srec
target is BFD_ENDIAN_UNKNOWN so the test of bfd_big_endian (abfd) in
default_data_link_order therefore returned false, resulting in a
little-endian nop pattern.  The rest of the patch fixes that problem
by adding a new field to bfd_link_info that can be used to determine
actual endianness on targets like srec.

	PR 13616
include/
	* bfdlink.h (struct bfd_link_info <big_endian>): New field.
bfd/
	* cpu-powerpc.c (bfd_arch_ppc_nop_fill): New function, use it
	for all ppc arch info.
	* linker.c (default_data_link_order): Pass info->big_endian to
	arch_info->fill function.
ld/
	* emulparams/elf64lppc.sh (NOP): Don't define.
	* emulparams/elf64ppc.sh (NOP): Don't define.
	* ldwrite.c (build_link_order): Use link_info.big_endian.  Move
	code determining endian to use for data_statement to..
	* ldemul.c (after_open_default): ..here.  Set link_info.big_endian.
2019-10-16 23:07:27 +10:30
GDB Administrator d9f06fca19 Automatic date update in version.in 2019-10-16 00:00:20 +00:00
Alan Modra 9b142ddb4a m68hc1x: better arg checking for reloc_warning
* elf32-m68hc1x.c (reloc_warning): Add printf attribute.
	(elf32_m68hc11_relocate_section): Don't use a variable for format
	strings.  Delete some unnecessary xgettext:c-format comments.
2019-10-15 23:25:11 +10:30
Alan Modra 9a73315161 remove more xmalloc in bfd
Also fixes m68hc1x printf arguments which would have bombed when
compiling on a 32-bit host with --enable-64-bit-bfd.

bfd/
	PR 24955
	* elf32-arm.c (set_cmse_veneer_addr_from_implib): Use bfd_malloc
	rather than xmalloc.
	* elf32-m68hc1x.c (reloc_warning): New function.
	(elf32_m68hc11_relocate_section): Use it here.  Cast bfd_vma values
	corresponding to %lx in format strings.
	* elf32-nds32.c (nds32_insertion_sort): Use a stack temporary.
gas/
	* config/tc-nds32.c (nds32_set_section_relocs): Use relocs and n
	parameters rather than equivalent sec->orelocation and
	sec->reloc_count.  Don't sort for n <= 1.  Tidy.
2019-10-15 16:50:32 +10:30
Alan Modra 779f2ae733 PR25100, Compile fails in elf64-ppc.c because of single equal sign instead of double equal for comparison
PR 25100
	* elf64-ppc.c (sfpr_define): Delete dead code that triggered a warning.
2019-10-15 16:01:05 +10:30
Alan Modra ed481f9799 Simplify power of two test
* bfd.c (bfd_check_compression_header): Check for powers of two
	with x == (x & -x).
2019-10-15 16:00:54 +10:30
GDB Administrator 22cc288441 Automatic date update in version.in 2019-10-15 00:00:20 +00:00
Alan Modra 47f6ff2f9e qsort: syms.c stab sorting
* syms.c (struct indexentry): Add idx field.
	(cmpindexentry): Final sort on idx.
	(_bfd_stab_section_find_nearest_line): Set idx.
2019-10-14 16:47:13 +10:30
Alan Modra 8025b0554c qsort: dwarf2.c
This patch ensures qsort stability in line and function sorting done
in dwarf2.c.  For the line sequences we make use of an existing field
that isn't used until later, as a monotonic counter for the qsort.

	* dwarf2.c (struct lookup_funcinfo): Add idx field.
	(compare_lookup_funcinfos): Perform final sort on idx.
	(build_lookup_funcinfo_table): Set idx.
	(compare_sequences): Perform final sort on num_lines.
	(build_line_info_table): Set num_lines and line_info_lookup earlier.
	(sort_line_sequences): Set num_lines for sort.
2019-10-14 16:47:13 +10:30
Alan Modra 3a3f4bf76a qsort: elf_link_add_object_symbols weak aliases
This particular sort almost certainly does not need to be stable for
the ELF linker to work correctly.  However it is conceivable that an
unstable sort could affect linker output, and thus different output be
seen with differing qsort implementations.  The argument goes like
this:  Given more than one strong alias symbol of equal section, value,
and size, the aliases will compare equal by elf_sort_symbol and thus
which one is chosen as the "real" symbol to be made dynamic depends on
qsort.  Why would anyone define two symbols at the same address?
Well, sometimes the fact that there are more than one strong alias
symbol is due to linker script symbols like __bss_start being made
dynamic.  This will match the first symbol defined in .bss if it
doesn't have correct size, and forgetting to properly set size and
type of symbols isn't as rare as it should be.

This patch adds some more heuristics to elf_sort_symbol.

	* elflink.c (elf_sort_symbol): Sort on type and name as well.
	(elf_link_add_object_symbols): Style fix.
2019-10-14 16:47:13 +10:30
Alan Modra 48db329734 qsort: elf_sort_sections use of target_index
elf_sort_sections tried to ensure a stable qsort by using target_index
as the final comparison, but target_index hasn't been set by anything
at the time elf_sort_sections was run.  This patch arrange to have
target_index set.

	* elf.c (_bfd_elf_map_sections_to_segments): Init target_index
	for sections about to be sorted.
	(assign_file_positions_for_load_sections): Likewise.
	(elf_sort_sections): Don't bother optimising both TOEND case.
	* elflink.c (bfd_elf_final_link): Reset target_index.
2019-10-14 16:47:13 +10:30
Alan Modra 8c1c5e5de4 qsort: SHF_LINK_ORDER section sort
The linker SHF_LINK_ORDER section sorting had a number of defects.
1) The ordering was by VMA, which won't work with overlays.  LMA is
   better.
2) Zero size sections can result in two sections at the same LMA/VMA.
   When only one of the two sections at the same LMA is zero size,
   that one must be first.
3) Warnings given by elf_get_linked_section_vma won't ever be emitted
   since elf_object_p warns and excludes objects with zero sh_link on
   a SHF_LINK_ORDER section.
4) Section offset was adjusted down rather than up by section
   alignment, possibly creating overlapping sections.
5) Finding the linked section did so the hard way, rather than simply
   using elf_linked_to_section.

	* elflink.c (elf_get_linked_section_vma): Delete.
	(compare_link_order): Use elf_linked_to_section and sort by lma,
	size, and id.
	(elf_fixup_link_order): Use size_t variables where appropriate.
	Make use of elf_linked_to_section.  Formatting.  Properly align
	sections.
2019-10-14 16:47:13 +10:30
Alan Modra dcea6a95d7 qsort issues
qsort isn't guaranteed to be a stable sort, that is, elements
comparing equal according to the comparison function may be reordered
relative to their original ordering.  Of course sometimes you may not
care, but even in those cases it is good to force some ordering
(ie. not have the comparison function return 0) so that linker output
is reproducible over different libc qsort implementations.

One way to make qsort stable (which the glibc manual incorrectly says
is the only way) is to augment the elements being sorted with a
monotonic counter of some kind, and use that counter as the final
arbiter of ordering in the comparison function.

Another way is to set up an array of pointers into the array of
elements, first pointer to first element, second pointer to second
element and so so, and sort the pointer array rather than the element
array.  Final arbiter in the comparison function then is the pointer
difference.  This works well with, for example, the symbol pointers
returned by _bfd_elf_canonicalize_symtab which point into a symbol
array.

This patch fixes a few places where sorting by symbol pointers is
appropriate, and adds comments where qsort stability is a non-issue.

	* elf-strtab.c (strrevcmp): Comment.
	* merge.c (strrevcmp): Likewise.
	* elf64-ppc.c (compare_symbols): Correct final pointer comparison.
	Comment on why comparing pointers ensures a stable sort.
	* elflink.c (struct elf_symbol): Add void* to union.
	(elf_sort_elf_symbol): Ensure a stable sort with pointer comparison.
	(elf_sym_name_compare): Likewise.
	(bfd_elf_match_symbols_in_sections): Style fix.
	(elf_link_sort_cmp1): Comment.
2019-10-14 16:47:12 +10:30
Alan Modra ec9bd0a22d PR24955, libbfd terminating program on out of memory (part2)
PR 24955
	* elflink.c (elf_output_implib): Don't use xmalloc.  Don't ignore
	return value of bfd_alloc2.
	* peXXigen.c (_bfd_XXi_write_codeview_record): Don't use xmalloc.
	* pef.c (bfd_pef_print_symbol): Likewise.  Don't ignore return
	value of bfd_get_section_contents.
	* som.c (som_write_space_strings): Don't use xmalloc.
	(som_write_symbol_strings): Likewise.
2019-10-14 16:47:12 +10:30
GDB Administrator 03f04b53b2 Automatic date update in version.in 2019-10-14 00:00:24 +00:00
GDB Administrator d5082b3251 Automatic date update in version.in 2019-10-13 00:01:15 +00:00
GDB Administrator bbcfc6249a Automatic date update in version.in 2019-10-12 00:00:24 +00:00
Max Filippov e168da45a2 bfd/dwarf2.c: fix assertion failure in comp_unit_hash_info
stash_maybe_enable_info_hash_tables sets
stash->info_hash_status = STASH_INFO_HASH_ON;
regardless of the result of stash_maybe_update_info_hash_tables call. In
case it fails this results in repeated invocation of comp_unit_hash_info
for the same comp unit and assertion failure in this function.

Only set stash->info_hash_status = STASH_INFO_HASH_ON; when
stash_maybe_update_info_hash_tables is successful.

bfd/
2019-10-11  Max Filippov  <jcmvbkbc@gmail.com>

	* dwarf2.c (stash_maybe_enable_info_hash_tables): Only set
	stash->info_hash_status = STASH_INFO_HASH_ON when
	stash_maybe_update_info_hash_tables succeeds.
2019-10-11 09:02:37 -07:00
GDB Administrator 863a974ed2 Automatic date update in version.in 2019-10-11 00:00:39 +00:00
GDB Administrator 61f0556832 Automatic date update in version.in 2019-10-10 00:00:24 +00:00
Alan Modra 336bfbeb18 PR25070, SEGV in function _bfd_dwarf2_find_nearest_line
Evil testcase with two debug info sections, with sizes of 2aaaabac4ec1
and ffffd5555453b140 result in a total size of 1.  Reading the first
section of course overflows the buffer and tramples on other memory.

	PR 25070
	* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Catch overflow of
	total_size calculation.
2019-10-09 13:28:20 +10:30