Commit Graph

13983 Commits

Author SHA1 Message Date
H.J. Lu f0f07ad182 sparc: Dump dynamic relocation info to the map file
Dump dynamic relocation info to the map file when generating dynamic
relocation in read-only section relocations if -Map is used.

	* elfxx-sparc.c (readonly_dynrelocs): Dump dynamic relocation
	in read-only section with minfo.
	(_bfd_sparc_elf_size_dynamic_sections): Likewise.
2017-10-07 17:30:54 -07:00
GDB Administrator b05c287c18 Automatic date update in version.in 2017-10-08 00:00:25 +00:00
GDB Administrator 0ee6e554c4 Automatic date update in version.in 2017-10-07 00:00:17 +00:00
H.J. Lu 99180bccaf x86: Update UNDEFINED_WEAK_RESOLVED_TO_ZERO comments
* elfxx-x86.h (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Update
	comments.
2017-10-06 16:45:37 -07:00
H.J. Lu 98b273dc13 x86: Use zero_undefweak in elf_x86_link_hash_entry
Replace has_got_reloc and has_non_got_reloc in elf_x86_link_hash_entry
with zero_undefweak:

Bit 0: Symbol has no GOT nor PLT relocations.
Bit 1: Symbol has non-GOT/non-PLT relocations in text sections.

zero_undefweak is initialized to 1 and undefined weak symbol should be
resolved to 0 if zero_undefweak > 0.

	* elf32-i386.c (elf_i386_check_relocs): Replace has_got_reloc
	and has_non_got_reloc with zero_undefweak.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_newfunc): Initialize
	zero_undefweak to 1.
	(_bfd_x86_elf_copy_indirect_symbol): Replace has_got_reloc and
	has_non_got_reloc with zero_undefweak.
	* elfxx-x86.h (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Replace
	has_got_reloc and has_non_got_reloc with zero_undefweak.
	(elf_x86_link_hash_entry): Likewise.
2017-10-06 15:29:32 -07:00
John Baldwin 544c67cda1 Account for padding in FreeBSD/mipsn32 NT_PRSTATUS notes.
Add a new ELF backend method to grok FreeBSD NT_PRSTATUS core dump
notes.  Define a method for MIPS N32 to override the default
elfcore_grok_freebsd_prstatus that accounts for additional padding
between pr_pid and pr_reg that is not present in other 32-bit FreeBSD
platforms.

	* elf-bfd.h (struct elf_backend_data): Add
	`elf_backend_grok_freebsd_prstatus'.
	* elf.c (elfcore_grok_freebsd_note): Call
	`elf_backend_grok_freebsd_prstatus' to handle NT_PRSTATUS if
	present.
	* elfn32-mips.c (elf_n32_mips_grok_freebsd_prstatus): New
	function.
	(elf_backend_grok_freebsd_prstatus): Define.
	* elfxx-target.h (elf_backend_grok_freebsd_prstatus): Define.
	(elfNN_bed): Initialize `elf_backend_grok_freebsd_prstatus'.
2017-10-06 11:43:07 -07:00
H.J. Lu e0d8f43169 Add "do/while(0);" to COPY_INPUT_RELOC_P/VERIFY_COPY_RELOC
Add "do/while(0);" to COPY_INPUT_RELOC_P/VERIFY_COPY_RELOC to avoid
potential dangling else problems.

	* elfxx-x86.h (COPY_INPUT_RELOC_P): Add "do/while(0);".
	(VERIFY_COPY_RELOC): Likewise.
2017-10-06 05:49:48 -07:00
H.J. Lu ff38b4cc55 x86: Add VERIFY_COPY_RELOC
Add VERIFY_COPY_RELOC to verify that symbol supports copy relocation.

	* elfxx-x86.h (VERIFY_COPY_RELOC): New.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use it.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2017-10-06 00:51:40 -07:00
H.J. Lu f3180fa9ee x86: Add VERIFY_PLT_ENTRY
Add VERIFY_PLT_ENTRY to verify that symbol has an entry in the procedure
linkage table.

	* elfxx-x86.h (VERIFY_PLT_ENTRY): New.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Use it.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
2017-10-06 00:48:26 -07:00
H.J. Lu e74399c47c x86: Add COPY_INPUT_RELOC_P
Add COPY_INPUT_RELOC_P which returns TRUE if input relocation should
be copied to output.

	* elfxx-x86.h (COPY_INPUT_RELOC_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:44:38 -07:00
H.J. Lu aebcc8ffd2 x86: Add GENERATE_DYNAMIC_RELOCATION_P
Add GENERATE_DYNAMIC_RELOCATION_P which returns TRUE if dynamic
relocation should be generated.

	* elf32-i386.c (X86_SIZE_TYPE_P): New.
	(elf_i386_relocate_section): Use GENERATE_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (X86_SIZE_TYPE_P): New.
	(elf_x86_64_relocate_section): Use GENERATE_DYNAMIC_RELOCATION_P.
	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): New.
2017-10-06 00:41:58 -07:00
H.J. Lu cf1070f1a1 x86: Add POINTER_LOCAL_IFUNC_P/PLT_LOCAL_IFUNC_P
Add POINTER_LOCAL_IFUNC_P which returns TRUE for pointer reference to
local IFUNC symbol.  Add PLT_LOCAL_IFUNC_P which returns TRUE for PLT
reference to local IFUNC symbol.

	* elfxx-x86.h (POINTER_LOCAL_IFUNC_P): New.
	(PLT_LOCAL_IFUNC_P): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Use them.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:37:43 -07:00
H.J. Lu f70656b260 x86: Add GENERATE_RELATIVE_RELOC_P
Add GENERATE_RELATIVE_RELOC_P which returns TRUE if dynamic relative
relocation should be generated.

	* elfxx-x86.h (GENERATE_RELATIVE_RELOC_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:32:43 -07:00
H.J. Lu 1f92404c50 x86: Add RESOLVED_LOCALLY_P
Add RESOLVED_LOCALLY_P which returns TRUE if symbol is resolved to
local definition at link-time.

	* elfxx-x86.h (RESOLVED_LOCALLY_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2017-10-06 00:26:17 -07:00
H.J. Lu 2eba97c207 Add RESOLVED_LOCALLY_P 2017-10-06 00:24:23 -07:00
H.J. Lu daf1c414a4 x86: Add NEED_DYNAMIC_RELOCATION_P
Add NEED_DYNAMIC_RELOCATION_P which returns TRUE if dynamic relocation
is needed.

	* elf32-i386.c (X86_PCREL_TYPE_P): New.
	(elf_i386_check_relocs): Use NEED_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (IS_X86_64_PCREL_TYPE): Renamed to ...
	(X86_PCREL_TYPE_P): This.
	(elf_x86_64_check_relocs): Use NEED_DYNAMIC_RELOCATION_P.
	Replace IS_X86_64_PCREL_TYPE with X86_PCREL_TYPE_P.
	(elf_x86_64_relocate_section): Replace IS_X86_64_PCREL_TYPE with
	X86_PCREL_TYPE_P.
	* elfxx-x86.h (NEED_DYNAMIC_RELOCATION_P): New.
2017-10-06 00:23:00 -07:00
H.J. Lu 51537393bd x86: Add TLS_TRANSITION_IE_TO_LE_P
Add TLS_TRANSITION_IE_TO_LE_P which returns TRUE if TLS IE->LE transition
is OK.

	* elfxx-x86.h (TLS_TRANSITION_IE_TO_LE_P): New.
	* elf32-i386.c (elf_i386_tls_transition): Use it.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
2017-10-06 00:13:52 -07:00
H.J. Lu 0caf6c82ab powerpc: Dump dynamic relocation info to the map file
Dump dynamic relocation info to the map file when generating dynamic
relocation in read-only section relocations if -Map is used.

	* elf32-ppc.c (readonly_dynrelocs): Add a link_info argument.
	Dump dynamic relocation in read-only section with minfo if
	needed.
	(ppc_elf_adjust_dynamic_symbol): Pass NULL to readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	(ppc_elf_size_dynamic_sections): Dump dynamic relocation in
	read-only section with minfo.
2017-10-05 18:09:19 -07:00
GDB Administrator 46e31de783 Automatic date update in version.in 2017-10-06 00:00:28 +00:00
John Baldwin 6d5be5d6b8 Handle the NT_ARM_VFP core dump note on FreeBSD.
bfd/ChangeLog:

	* elf.c (elfcore_grok_freebsd_note): Handle NT_ARM_VFP.
2017-10-05 09:50:01 -07:00
H.J. Lu 007873f54e tile: Dump dynamic relocation info to the map file
Dump dynamic relocation info to the map file when generating dynamic
relocation in read-only section relocations if -Map is used.

	* elf32-tilepro.c (readonly_dynrelocs): Dump dynamic relocation
	in read-only section with minfo.
	(tilepro_elf_size_dynamic_sections): Likewise.
	* elfxx-tilegx.c (readonly_dynrelocs): Likewise.
	(tilegx_elf_size_dynamic_sections): Likewise.
2017-10-05 06:01:30 -07:00
Pedro Alves 2ca7de3746 bfd_set_input_error
A downside to the 2017-10-04 PR22245 fix is that bfd_set_error can now
silently accept invalid errors if/when someone passes the a value of
the wrong enumeration type, which previously would be caught by the
-Wenum-conversion warning.

	PR 22245
	* bfd.c (bfd_set_error): Revert 2017-10-04 change.  Remove
	ellipsis parameter.  Split out bfd_error_on_input code to..
	(bfd_set_input_error): .. New function.
	* archive.c (_bfd_write_archive_contents): Use bfd_set_input_error.
	* vms-lib.c (_bfd_vms_lib_write_archive_contents): Likewise.
	* bfd-in2.h: Regenerate.
2017-10-05 12:03:47 +10:30
Alan Modra 8c6716e57e bfd_error_on_input is for archives
* elflink.c (elf_link_input_bfd): Correct ctor/dtor in init_array/
	fini_array error value.
2017-10-05 11:08:20 +10:30
GDB Administrator e6fef60069 Automatic date update in version.in 2017-10-05 00:00:13 +00:00
Alan Modra db4677b8bd PR21167, relocation sections not included in groups
This fixes a wart I've known about for years, but haven't done
anything about because BFD treats relocation sections as an adjunct to
the section they relocate.  SHF_GROUP on the section thus implicitly
applies to its relocation section(s), but it is an error that the
reloc sections aren't part of the group.

Like many patches to gas, this wasn't as straightforward as it could
be due to a number of backends, i386, cr16 and others, removing relocs
in tc_get_reloc rather than marking them as "done" earlier in
md_apply_reloc.  So it isn't possible for the group support to
reliably detect the presence of relocs by looking at fixups earlier
than write_relocs.  However the group support needs to create
signature symbols, and that must be done before the symbol table is
frozen, before write_relocs.  So split off the group sizing from
elf_adjust_symtab and put it in elf_frob_file_after_relocs.

bfd/
	PR 21167
	* elf.c (_bfd_elf_setup_sections): Don't trim reloc sections from
	groups.
	(_bfd_elf_init_reloc_shdr): Pass sec_hdr, use it to copy SHF_GROUP
	flag from section.
	(elf_fake_sections): Adjust calls.  Exit immediately on failure.
	(bfd_elf_set_group_contents): Add associated reloc section indices
	to group contents
gas/
	PR 21167
	* config/obj-elf.c (struct group_list): Delete elt_count.
	(groups): New static.
	(build_group_lists): Don't count elements.
	(elf_adjust_symtab): Use groups rather than auto list.  Set up
	pointer from group member to SHT_GROUP section.  Don't size
	SHT_GROUP section or clean up here..
	(elf_frob_file_after_relocs): ..do so here instead.
	* testsuite/gas/arc/jli-1.d,
	* testsuite/gas/elf/groupautob.d,
	* testsuite/gas/mips/compact-eh-eb-2.d,
	* testsuite/gas/mips/compact-eh-eb-5.d,
	* testsuite/gas/mips/compact-eh-el-2.d,
	* testsuite/gas/mips/compact-eh-el-5.d: Adjust.
ld/
	PR 21167
	* testsuite/ld-elf/group9b.d: Adjust for relocs included in group.
2017-10-05 08:38:11 +10:30
Alan Modra a5259595e7 PowerPC64 ELFv2 symbols not needed in get_synthetic_symtab
* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't sort or
	classify symbols for ELFv2.
2017-10-04 14:25:37 +10:30
Pavel I. Kryukov 9ba5f27cdd PR22245, Fix potential UB in bfd_set_error
Passing enum as a first argument to variadic argument function
may lead to undefined behavior. The explanation on CERT site:
https://www.securecoding.cert.org/confluence/display/cplusplus/
EXP58-CPP.+Pass+an+object+of+the+correct+type+to+va_start

The bug was found by Kirill Nedostoev (nedostoev.ka@phystech.edu)
when he tried to build GNU binutils with Clang 7.

	PR 22245
	* bfd.c (bfd_set_error): Avoid UB on passing arg to va_start that
	undergoes default promotion.
	* bfd-in2.h: Regenerate.
2017-10-04 14:24:21 +10:30
GDB Administrator ca2a727a5b Automatic date update in version.in 2017-10-04 00:00:20 +00:00
GDB Administrator 40c0777b17 Automatic date update in version.in 2017-10-03 00:00:16 +00:00
Alan Modra dcd2b8a014 Fix powerpc comment typo
* elf32-ppc.c (ppc_elf_relocate_section): Fix comment typo.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
2017-10-02 16:58:51 +10:30
GDB Administrator 7a0c60fea0 Automatic date update in version.in 2017-10-02 00:00:13 +00:00
Alan Modra 20230942fe PR21957, addr2line incorrectly handles non-increasing sequences in line table
PR 21957
	* dwarf2.c (new_line_sorts_after): Remove end_sequence comparison.
	(add_line_info): Always put end_sequence last.
2017-10-01 19:35:07 +10:30
Alan Modra 4b04bba2eb PR22047, Heap out of bounds read in parse_comp_unit
Like the PR22230 fix, we can allocate a buffer with an extra byte
rather than letting bfd_simple_get_relocated_section_contents malloc
and return a buffer.  Much better than allocating another buffer
afterwards.

	PR 22047
	* dwarf2.c (read_section): Allocate buffer with extra byte for
	bfd_simple_get_relocated_section_contents rather than copying
	afterwards.
2017-10-01 12:07:59 +10:30
GDB Administrator 3678b25d0c Automatic date update in version.in 2017-10-01 00:00:25 +00:00
GDB Administrator 1755697b1d Automatic date update in version.in 2017-09-30 00:00:28 +00:00
Alan Modra f6ac8c52c9 Fail when string merge can't alloc memory
I was looking at Debian bug #874674 again today, and think I might
have spotted the problem.  It appears that merge.c tries to cope with
memory allocation failures in some circumstances, but doesn't quite
manage to get everything right.  This patch will make ld report memory
allocation failures instead of silently not merging strings.

	* merge.c (merge_strings): Return FALSE on malloc failure.
	(_bfd_merge_sections): Return failures from record_section and
	merge_strings.
2017-09-29 14:42:36 +09:30
GDB Administrator 1b8f6c7f82 Automatic date update in version.in 2017-09-29 00:00:24 +00:00
Alan Modra 1a3b5c34fe PR22220, BFD linker wrongly marks symbols as PREVAILING_DEF_IRONLY
non_ir_ref_dynamic wasn't being set in the case where we have a
versioned dynamic symbol definition with a non-versioned matching IR
symbol.

bfd/
	PR 22220
	* elflink.c (_bfd_elf_merge_symbol): Set non_ir_ref_dynamic in
	a case where plugin_notice isn't called.
ld/
	* testsuite/ld-plugin/pr22220.h,
	* testsuite/ld-plugin/pr22220lib.cc,
	* testsuite/ld-plugin/pr22220lib.ver,
	* testsuite/ld-plugin/pr22220main.cc: New test.
	* testsuite/ld-plugin/lto.exp: Run it.
2017-09-28 17:36:36 +09:30
GDB Administrator 50300765aa Automatic date update in version.in 2017-09-28 00:00:30 +00:00
Kuan-Lin Chen cd28e7aaf3 nds32: Fix a tautological comparison. 2017-09-27 13:07:19 +08:00
GDB Administrator 25c7861f70 Automatic date update in version.in 2017-09-27 00:00:23 +00:00
H.J. Lu ac69a0d75b x86-64: Don't pass output_bfd to info->callbacks->minfo
Don't pass output_bfd to info->callbacks->minfo when dumping local IFUNC
functions in the map file.

	PR ld/22199
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Don't pass
	output_bfd to info->callbacks->minfo.
2017-09-26 14:41:22 -07:00
Nick Clifton 262c0a877f Fix an assertion failure when parsing a fuzzed x86_64 ELF binary.
PR 22172
	* elf64-x86-64.c (elf_x86_64_info_to_howto): Do not trigger an
	assertion failure if elf_x86_64_rtype_to_howto has already issued
	an error message.
2017-09-26 16:03:10 +01:00
Alan Modra 33e0a9a056 Tidy reading data in read_formatted_entries
Using read_attribute_value accomplishes two things: It checks for
unexpected formats, and ensures the buffer pointer always increments.

	PR 22210
	* dwarf2.c (read_formatted_entries): Use read_attribute_value to
	read data.
2017-09-26 23:23:44 +09:30
Nick Clifton 30d0157a2a Avoid needless resource usage when processing a corrupt DWARF directory or file name table.
PR 22210
	* dwarf2.c (read_formatted_entries): Fail early if we know that
	the loop parsing data entries will overflow the end of the
	section.
2017-09-26 14:37:47 +01:00
Alan Modra 1b86808a86 PR22209, invalid memory read in find_abstract_instance_name
This patch adds bounds checking for DW_FORM_ref_addr die refs, and
calculates them relative to the first .debug_info section.  See the
big comment for why calculating relative to the current .debug_info
section was wrong for relocatable object files.

	PR 22209
	* dwarf2.c (struct comp_unit): Delete sec_info_ptr field.
	(find_abstract_instance_name): Calculate DW_FORM_ref_addr relative
	to stash->info_ptr_memory, and check die_ref is within that memory.
	Set info_ptr_end correctly when another CU is refd.  Check die_ref
	for DW_FORM_ref4 etc. is within CU.
2017-09-26 22:12:40 +09:30
Alan Modra a54018b72d PR22205, .debug_line file table NULL filename
The PR22200 fuzzer testcase found one way to put NULLs into .debug_line
file tables.  PR22205 finds another.  This patch gives up on trying to
prevent NULL files in the file table and instead just copes with them.
Arguably, this is better than giving up and showing no info from
.debug_line.  I've also fixed a case where the fairly recent DWARF5
support in handling broken DWARG could result in uninitialized memory
reads, and made a small tidy.

	PR 22205
	* dwarf2.c (concat_filename): Return "<unknown>" on NULL filename.
	(read_formatted_entries): Init "fe".
	(decode_line_info <DW_LNE_define_file>): Use line_info_add_file_name.
2017-09-26 09:38:26 +09:30
Alan Modra e338894dc2 PR22204, Lack of DW_LNE_end_sequence causes "infinite" loop
PR 22204
	* dwarf2.c (decode_line_info): Ensure line_ptr stays within
	bounds in inner loop.
2017-09-26 09:36:50 +09:30
GDB Administrator 898f57a89f Automatic date update in version.in 2017-09-26 00:00:21 +00:00
Alan Modra 1da5c9a485 PR22202, buffer overflow in parse_die
There was a complete lack of sanity checking in dwarf1.c

	PR 22202
	* dwarf1.c (parse_die): Sanity check pointer against section limit
	before dereferencing.
	(parse_line_table): Likewise.
2017-09-25 22:01:47 +09:30
Alan Modra 11855d8a1f PR22201, DW_AT_name with out of bounds reference
DW_AT_name ought to always have a string value.

	PR 22201
	* dwarf2.c (scan_unit_for_symbols): Ignore DW_AT_name unless it
	has string form.
	(parse_comp_unit): Likewise.
2017-09-25 22:01:47 +09:30
Alan Modra c361faae8d PR22200, DWARF5 .debug_line sanity check
The format_count entry can't be zero unless the count is also zero.

	PR 22200
	* dwarf2.c (read_formatted_entries): Error on format_count zero.
2017-09-25 22:01:47 +09:30
GDB Administrator 5b3fd0aac2 Automatic date update in version.in 2017-09-25 00:00:24 +00:00
Alan Modra 52b36c51e5 PR22197, buffer overflow in bfd_get_debug_link_info_1
PR 22197
	* opncls.c (bfd_get_debug_link_info_1): Properly check that crc is
	within section bounds.
2017-09-24 21:40:58 +09:30
Alan Modra a26a013f22 PR22191, memory leak in dwarf2.c
table->sequences is a linked list before it is replaced by a bfd_alloc
array in sort_line_sequences.

	PR 22191
	* dwarf2.c (decode_line_info): Properly free line sequences on error.
2017-09-24 21:01:30 +09:30
Alan Modra 52a93b95ec PR22187, infinite loop in find_abstract_instance_name
This patch prevents the simple case of infinite recursion in
find_abstract_instance_name by ensuring that the attributes being
processed are not the same as the previous call.

The patch also does a little cleanup, and leaves in place some changes
to the nested_funcs array that I made when I wrongly thought looping
might occur in scan_unit_for_symbols.

	PR 22187
	* dwarf2.c (find_abstract_instance_name): Add orig_info_ptr and
	pname param.  Return status.  Make name const.  Don't abort,
	return an error.  Formatting.  Exit if current info_ptr matches
	orig_info_ptr.  Update callers.
	(scan_unit_for_symbols): Start at nesting_level of zero.  Make
	nested_funcs an array of structs for extensibility.  Formatting.
2017-09-24 16:17:19 +09:30
Alan Modra d8010d3e75 PR22186, divide-by-zero in decode_line_info
PR 22186
	* dwarf2.c (decode_line_info): Fail on lh.line_range of zero
	rather than dividing by zero.
2017-09-24 16:17:19 +09:30
Alan Modra 515f23e63c PR22169, heap-based buffer overflow in read_1_byte
The .debug_line header length field doesn't include the length field
itself, ie. it's the size of the rest of .debug_line.

	PR 22169
	* dwarf2.c (decode_line_info): Correct .debug_line unit_length check.
2017-09-24 16:15:14 +09:30
Alan Modra 0d76029f92 PR22167, NULL pointer dereference in scan_unit_for_symbols
PR 22167
	* dwarf2.c (scan_unit_for_symbols): Check u.blk->data is non-NULL.
2017-09-24 14:35:33 +09:30
Alan Modra bd61e13549 PR22166, SHT_GNU_verneed memory allocation
The sanity check covers the previous minimim size, plus that the size
is at least enough for sh_info verneed entries.

Also, since we write all verneed fields or exit with an error, there
isn't any need to zero the memory allocated for verneed entries.

	PR 22166
	* elf.c (_bfd_elf_slurp_version_tables): Test sh_info on
	SHT_GNU_verneed section for sanity.  Don't zalloc memory for
	verref.
2017-09-24 14:34:57 +09:30
GDB Administrator 8d296e2d4d Automatic date update in version.in 2017-09-24 00:00:26 +00:00
GDB Administrator 4102159923 Automatic date update in version.in 2017-09-23 00:00:27 +00:00
H.J. Lu 61e3bf5f83 x86: Guard against corrupted PLT
There should be only one entry in PLT for a given symbol.  Set howto to
NULL after processing a PLT entry to guard against corrupted PLT so that
the duplicated PLT entries are skipped.

	PR binutils/22170
	* elfxx-x86.c (_bfd_x86_elf_get_synthetic_symtab): Guard against
	corrupted PLT.
2017-09-22 14:18:20 -07:00
H.J. Lu 59ca4c1bbd Update ChangeLog entry for PR 22163 2017-09-22 14:10:59 -07:00
H.J. Lu b69e9267d1 x86: Return -1 if bfd_canonicalize_dynamic_reloc returns 0
Stop if bfd_canonicalize_dynamic_reloc returns 0.

	PR ld/22163
	* elfxx-x86.c (_bfd_x86_elf_get_synthetic_symtab): Also return
	-1 if bfd_canonicalize_dynamic_reloc returns 0.
2017-09-22 07:25:16 -07:00
Pedro Alves b877d21f34 bfd/version.h: Add rationale for BFD_VERSION_DATE
bfd/ChangeLog:
2017-09-22  Pedro Alves  <palves@redhat.com>
	    Alan Modra  <amodra@gmail.com>

	* version.h: Add comment.
2017-09-22 14:57:52 +01:00
GDB Administrator df52f331ed Automatic date update in version.in 2017-09-22 00:00:27 +00:00
Andreas Arnez 8fe09d7421 S/390: Fix Elf note swap s390_gs_bc vs. s390_gs_cb
Fix two typos that resulted in swapping the BFD names for the core note
register sections NT_S390_GS_CB and NT_S390_GS_BC.

bfd/ChangeLog:

	* elf.c (elfcore_grok_note): For the cases NT_S390_GS_CB and
	NT_S390_GS_BC, correct the previously swapped invocations of
	elfcore_grok_s390_gs_bc and elfcore_grok_s390_gs_cb.
2017-09-21 17:45:18 +02:00
GDB Administrator f5b358c8aa Automatic date update in version.in 2017-09-21 00:00:27 +00:00
GDB Administrator dba74cb2b7 Automatic date update in version.in 2017-09-20 00:00:30 +00:00
Alan Modra 25516cc573 PowerPC64 stubs don't match calculated size
After the PR 21411 fix, the linker generated .eh_frame for ppc64 glink
can be edited by the generic code.  The sequence of events goes
something like:
1) Some object file adds .eh_frame aligned to 8, making the output
   .eh_frame aligned to at least 8, so linker generated .eh_frame FDE
   is padded to an 8 byte boundary.
2) All .eh_frame past the glink .eh_frame is garbage collected.
3) Generic code detects that last FDE (the glink .eh_frame) doesn't
   need to be padded to an 8 byte boundary, reducing size from 88 to
   84.
4) elf64-ppc.c check fails.

	PR 21441
	* elf64-ppc.c (ppc64_elf_build_stubs): Don't check glink_eh_frame
	size.
2017-09-19 14:32:18 +09:30
Alan Modra 3d13f3e9bd PR22150, ld keeps a version reference for gc'd symbols
elf_gc_sweep_symbol should run after verdefs are calculated, since
the verdef code creates symbols for the versions.  However,
elf_gc_sweep_symbol needs to run before verrefs so as to not emit
useless verrefs for symbols that are gc'd.

I've also removed a _bfd_elf_link_renumber_dynsyms calls added by
Maciej after I fussed about it when reviewing.  On further examination
the call appears to be unnecessary.  Looking at renumber_dynsyms also
made me realize that the test to exclude .gnu.version has been wrong
since 2016-04-26 (git commit d5486c4372), so fix that too.

	PR 22150
	* elflink.c (bfd_elf_size_dynamic_sections): Garbage collect
	symbols before calculating verrefs.  Don't renumber dynsyms
	after gc.  Exclude .gnu.version when zero or one dynsym.
	Localize some vars and reindent.
2017-09-19 12:18:49 +09:30
GDB Administrator ced154d810 Automatic date update in version.in 2017-09-19 00:00:29 +00:00
H.J. Lu 94670f6cf1 Check error return from bfd_canonicalize_dynamic_reloc
Since bfd_canonicalize_dynamic_reloc returns -1 on error, check it in
_bfd_x86_elf_get_synthetic_symtab.

	PR ld/22148
	* elfxx-x86.c (_bfd_x86_elf_get_synthetic_symtab): Check error
	return from bfd_canonicalize_dynamic_reloc.
2017-09-18 13:05:25 -07:00
GDB Administrator 35d3b1d74f Automatic date update in version.in 2017-09-18 00:00:30 +00:00
GDB Administrator d9d0d1bc3f Automatic date update in version.in 2017-09-17 00:00:32 +00:00
GDB Administrator ebee3285b3 Automatic date update in version.in 2017-09-16 00:00:34 +00:00
Alan Modra 21d0a60620 Error when 32-bit ar tries to handle 4G or larger files
We used to silently truncate the size returned by stat() to 32 bits.
While it is possible to make binutils handle a 64-bit off_t on a
32-bit host, to me the effort needed doesn't seem worth the benefit.
Instead, error if we truncate the size.  I've written the test the way
I have to avoid a signed/unsigned warning.

	PR 22116
	* archive.c (bfd_ar_hdr_from_filesystem): Detect when status.st_size
	overflows bfd_size_type.
2017-09-15 10:36:40 +09:30
GDB Administrator cc3e190059 Automatic date update in version.in 2017-09-15 00:00:28 +00:00
H.J. Lu 5e5e02aeca x86: Cache section contents and relocations
bfd/

	PR ld/22135
	* elf32-i386.c (elf_i386_convert_load_reloc): Add an argument
	to indicate if conversion is performed.
	(elf_i386_check_relocs): Cache section contents and relocations
	if conversion is performed.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Cache section
	contents and relocations if conversion is performed.

ld/

	PR ld/22135
	* testsuite/ld-i386/i386.exp: Run pr22135.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22135.d: New file.
	* testsuite/ld-i386/pr22135.s: Likewise.
	* testsuite/ld-x86-64/pr22135.d: Likewise.
	* testsuite/ld-x86-64/pr22135.s: Likewise.
2017-09-14 12:29:29 -07:00
Nick Clifton 4d465c689a Fix address violation when parsing a corrupt PE binary.
PR binutils/22113
	* peXXigen.c (pe_print_idata): Extend check for HintName vector
	entries.
2017-09-14 11:15:55 +01:00
GDB Administrator 0952b7101e Automatic date update in version.in 2017-09-14 00:00:26 +00:00
H.J. Lu f47432d4b9 elfxx-x86.h: Fix a typo in comments
* elfxx-x86.h: Fix a typo in comments.
2017-09-13 04:25:14 -07:00
GDB Administrator 9f2815a079 Automatic date update in version.in 2017-09-13 00:00:31 +00:00
GDB Administrator 331f81b22c Automatic date update in version.in 2017-09-12 00:00:28 +00:00
Kuan-Lin Chen 4ec521f238 nds32: Rename __BIT() to N32_BIT(). 2017-09-11 13:46:27 +08:00
GDB Administrator 555cb16881 Automatic date update in version.in 2017-09-11 00:00:31 +00:00
GDB Administrator 502b834c1a Automatic date update in version.in 2017-09-10 00:00:33 +00:00
Alan Modra 2420fff633 PowerPC64 --plt-align
This changes the PowerPC64 --plt-align option to perform the usual
alignment of code as suggested by its name, as well as the previous
behaviour of padding so as to reduce boundary crossing.  The old
behaviour is had by using a negative parameter.

The default is also changed to align plt stub code by default to 32
byte boundaries, the point being to get better bctr branch prediction
on power8 and power9 hardware.

bfd/
	* elf64-ppp.c (plt_stub_pad): Handle positive and negative
	plt_stub_align.
ld/
	* ld.texinfo (--plt-align): Describe new behaviour of option.
	* emultempl/ppc64elf.em (params): Default plt_stub_align to 5.
	* testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for
	selected tests.
	* testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align.
	* testsuite/ld-powerpc/elfv2so.d: Adjust expected output.
2017-09-10 01:55:16 +09:30
H.J. Lu c5bce5c697 x86: Update UNDEFINED_WEAK_RESOLVED_TO_ZERO
Since the only information which SYMBOL_REFERENCES_LOCAL_P doesn't check
is relocations, UNDEFINED_WEAK_RESOLVED_TO_ZERO only needs to check for
relocations with SYMBOL_REFERENCES_LOCAL_P.

	* elf32-i386.c (elf_i386_relocate_section): Update usage of
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_i386_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
	(_bfd_x86_elf_fixup_symbol): Likewise.
2017-09-09 07:29:29 -07:00
H.J. Lu 8fbf0ba18c x86: Don't check has_non_got_reloc
_bfd_x86_elf_link_symbol_references_local should depend only on symbol
references, not relocations, to work in check_relocs.

	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
	check has_non_got_reloc.
2017-09-09 07:20:58 -07:00
H.J. Lu 0a27fed72d x86: Properly handle __ehdr_start
After _bfd_i386_elf_convert_load and _bfd_x86_64_elf_convert_load are
removed, elf_i386_convert_load_reloc and elf_x86_64_convert_load_reloc
see __ehdr_start as an undefined symbol when they are called from
check_relocs to convert GOT relocations against local symbols.  But
__ehdr_start will be defined as a hidden symbol by linker at the later
stage if it is referenced.  This patch marks __ehdr_start as a defined
local symbol at the start of check_relocs if it is referenced and not
defined.

bfd/

	PR ld/22115
	* elf32-i386.c (elf_i386_convert_load_reloc): Check linker_def.
	Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Check
	linker_def.  Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set local_ref
	and linker_def on __ehdr_start if it is referenced and not
	defined.
	(_bfd_x86_elf_link_symbol_references_local): Also set local_ref
	and return TRUE when building executable, if a symbol has
	non-GOT/non-PLT relocations in text section or there is no
	dynamic linker.
	* elfxx-x86.h (elf_x86_link_hash_entry): Add linker_def.

ld/

	PR ld/22115
	* ld-i386/i386.exp: Run PR ld/22115 tests,
	* ld/testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr22115-1.s: New file.
	* testsuite/ld-i386/pr22115-1a.d: Likewise.
	* testsuite/ld-i386/pr22115-1b.d: Likewise.
	* testsuite/ld-i386/pr22115-1c.d: Likewise.
	* testsuite/ld-i386/pr22115-1d.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1.s: Likewise.
	* testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1a.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1b.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1c.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr22115-1d.d: Likewise.
2017-09-09 05:05:29 -07:00
GDB Administrator 90d499086b Automatic date update in version.in 2017-09-09 00:00:19 +00:00
H.J. Lu c7df954fc4 x86: Update comments in elfxx-x86.h
* elfxx-x86.h: Update comments.
2017-09-08 09:15:37 -07:00
H.J. Lu 1de031c80b x86: Replace elf_x86_plt_layout_table with elf_x86_init_table
* elf32-i386.c (elf_i386_link_setup_gnu_properties): Replace
	elf_x86_plt_layout_table with elf_x86_init_table.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.h (elf_x86_plt_layout_table): Renamed to ...
	(elf_x86_init_table): This.
	(_bfd_x86_elf_link_setup_gnu_properties): Replace
	elf_x86_plt_layout_table with elf_x86_init_table.
2017-09-08 04:10:34 -07:00
H.J. Lu 7a382c1c50 x86; Don't add elf64-x86-64.lo nor elf64.lo together with elfxx-x86.lo
Don't set r_info and r_sym fields in _bfd_x86_elf_link_hash_table_create.
Instead, set them in _bfd_x86_elf_link_setup_gnu_properties.  We can
avoid adding elf64-x86-64.lo and elf64.lo together with elfxx-x86.lo to
bfd_backends.

	* configure.ac (bfd_backends): Don't add elf64-x86-64.lo nor
	elf64.lo together with elfxx-x86.lo for 64-bit BFD.
	* configure: Regenerated.
	* elf32-i386.c (elf_i386_link_setup_gnu_properties): Set r_info
	and r_sym fields of plt_layout.
	* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties):
	Likewise.
	* elfxx-x86.c (elf_x86_64_is_reloc_section): Remove BFD64 check.
	(_bfd_x86_elf_link_hash_table_create): Likewise.  Don't set
	r_info nor r_sym fields.
	(_bfd_x86_elf_link_setup_gnu_properties): Set r_info and r_sym
	fields of htab.
	* elfxx-x86.h (elf_x86_plt_layout_table): Add r_info and r_sym.
2017-09-07 17:21:07 -07:00
GDB Administrator bd757a5bf2 Automatic date update in version.in 2017-09-08 00:00:20 +00:00
Palmer Dabbelt 9eb7b0acb5 RISC-V: Print an error when unable to align a section
This used to just print "can't relax section: Success", which is a silly
error message.

bfd/ChangeLog

2017-09-07  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv.c (_bfd_riscv_relax_align): Call bfd_set_error and
        print an error message when unable to relax a .align directive.
2017-09-07 09:45:35 -07:00
Palmer Dabbelt b1308d2c37 RISC-V: Support PCREL_* relocations agaist weak undefined symbols
I recently modified our Linux port's base address such the absolute
address 0 is no longer addressable as a 32-bit PC-relative offset.
Since Linux links a weak undefined symbol in an intermediate binary, it
needs to be able to reference absolute address 0.

This patch changes R_RISCV_PCREL_* relocations to absolute relocations
while resolving them in order to allow these symbols to be referenced in
PC-relative programs linked at high addresses.  Note that this doesn't
apply to PIC, which also uses PC-relative relocations, just to
position-dependent objects, which we use to allow programs to be linked
at high addresses.

In case some of our embedded users are using R_RISCV_PCREL_* as a hacked
up method of getting position-independent binaries (which can work if
you have very simple programs), we only convert the relocations when the
PC-relative version would overflow.

bfd/ChangeLog:

2017-09-07  Palmer Dabbelt  <palmer@dabbelt.com>

        * elfnn-riscv.c (riscv_zero_pcrel_hi_reloc): New function.
        (riscv_record_pcrel_hi_reloc): Add absolute argument.
        (riscv_elf_relocate_section): Call riscv_zero_pcrel_hi_reloc for
        R_RISCV_PCREL_HI20 relocs, and pass the result to
        riscv_record_pcrel_hi_reloc.
2017-09-07 09:42:15 -07:00
H.J. Lu 6999821f8b x86: Remove _bfd_{i386,x86_64}_elf_convert_load
Instead of converting GOT relocations when sizing dynamic sections, we
convert GOT relocations during relocation check.  Add a field, local_ref,
to elf_x86_link_hash_entry to indicate if symbol references are always
local with a new function to check if symbol references are always local,
which works in check_relocs.

	* elf32-i386.c (elf_i386_convert_load_reloc): Add an argument,
	r_type_p.  Remove the converted argument.  Replace
	SYMBOL_REFERENCES_LOCAL with SYMBOL_REFERENCES_LOCAL_P.  Return
	the new relocation type via r_type_p.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(need_convert_load): Removed.
	(check_relocs_failed): Updated.
	(elf_i386_check_relocs): Call elf_i386_convert_load_reloc,
	instead of setting need_convert_load.
	(_bfd_i386_elf_convert_load): Removed.
	* elf64-x86-64.c (need_convert_load): Removed.
	(check_relocs_failed): Updated.
	(elf_x86_64_convert_load_reloc): Add an argument, r_type_p.
	Replace SYMBOL_REFERENCES_LOCAL with SYMBOL_REFERENCES_LOCAL_P.
	Return the new relocation type via r_type_p.
	(elf_x86_64_check_relocs): Call elf_x86_64_convert_load_reloc,
	instead of setting need_convert_load.
	(elf_x86_64_check_relocs): Don't check PIC if relocation has
	been converted.
	(_bfd_x86_64_elf_convert_load): Removed.
	(elf_x86_64_relocate_section): Replace SYMBOL_REFERENCES_LOCAL
	with SYMBOL_REFERENCES_LOCAL_P.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Don't
	set convert_load.
	(_bfd_x86_elf_size_dynamic_sections): Don't call convert_load.
	(_bfd_x86_elf_link_symbol_references_local): New function.
	* elfxx-x86.h (SYMBOL_REFERENCES_LOCAL_P): New.
	(UNDEFINED_WEAK_RESOLVED_TO_ZERO): Replace elf.forced_local with
	SYMBOL_REFERENCES_LOCAL_P.
	(elf_x86_link_hash_entry): Add local_ref.
	(elf_x86_link_hash_table): Remove convert_load.
	(_bfd_i386_elf_convert_load): Removed.
	(_bfd_x86_64_elf_convert_load): Likewise.
	(_bfd_x86_elf_link_symbol_references_local): New.
2017-09-07 04:03:30 -07:00