Commit Graph

9147 Commits

Author SHA1 Message Date
Alan Modra
0f55320bc4 elf_hash_table_id access
* elf-m10300.c (elf32_mn10300_hash_table): Test is_elf_hash_table
	before accessing elf_hash_table_id.
	* elf32-arc.c (elf_arc_hash_table): Likewise.
	* elf32-arm.c (elf32_arm_hash_table): Likewise.
	* elf32-avr.c (avr_link_hash_table): Likewise.
	* elf32-bfin.c (bfinfdpic_hash_table): Likewise.
	* elf32-cris.c (elf_cris_hash_table): Likewise.
	* elf32-csky.c (csky_elf_hash_table): Likewise.
	* elf32-frv.c (frvfdpic_hash_table): Likewise.
	* elf32-hppa.c (hppa_link_hash_table): Likewise.
	* elf32-lm32.c (lm32_elf_hash_table): Likewise.
	* elf32-m32r.c (m32r_elf_hash_table): Likewise.
	* elf32-m68hc1x.h (m68hc11_elf_hash_table): Likewise.
	* elf32-m68k.c (elf_m68k_hash_table): Likewise.
	* elf32-metag.c (metag_link_hash_table): Likewise.
	* elf32-microblaze.c (elf32_mb_hash_table): Likewise.
	* elf32-nds32.h (nds32_elf_hash_table): Likewise.
	* elf32-or1k.c (or1k_elf_hash_table): Likewise.
	* elf32-s390.c (elf_s390_hash_table): Likewise.
	* elf32-sh.c (sh_elf_hash_table): Likewise.
	* elf32-spu.c (spu_hash_table): Likewise.
	* elf32-tilepro.c (tilepro_elf_hash_table): Likewise.
	* elf32-xtensa.c (elf_xtensa_hash_table): Likewise.
	* elf64-alpha.c (alpha_elf_hash_table): Likewise.
	* elf64-hppa.c (hppa_link_hash_table): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_hash_table): Likewise.
	* elf64-s390.c (elf_s390_hash_table): Likewise.
	* elfnn-ia64.c (elfNN_ia64_hash_table): Likewise.
	* elfnn-riscv.c (riscv_elf_hash_table): Likewise.
	* elfxx-mips.c (mips_elf_hash_table): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_hash_table): Likewise.
	* elfxx-tilegx.c (tilegx_elf_hash_table): Likewise.
2020-08-25 02:45:58 +09:30
Jon Turney
3cdad0846b
Fix erroroneous use of '%zu' in elfcore_grok_win32pstatus
As reported in [1], _bfd_error_handler() doesn't support '%zu'.

module_name_size is always 32-bits in the data structure we are
extracting it from, so use an unsigned int to store it instead.

[1] https://sourceware.org/pipermail/gdb-patches/2020-August/171391.html

bfd/ChangeLog:

2020-08-21  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Change name_size to unsigned
	int. Use '%u' format with  _bfd_error_handler to render it.
2020-08-24 18:04:55 +01:00
Alan Modra
918dc783de PR26489, ASAN: ppc64_elf_size_stubs elf64-ppc.c:13389
Stub sections are inserted after sec_info is sized, so have higher ids.
Test flags that will exclude stub sections before looking at the
sec_info array.

	PR 26489
	* elf64-ppc.c (ppc64_elf_size_stubs): Test code_sec->has_toc_reloc
	and code_sec->makes_toc_func_call before sec_info[code_sec->id].
2020-08-25 02:12:35 +09:30
Alan Modra
573eb292ee PR26492, ASAN: ppc64_elf_before_check_relocs elf64-ppc.c:4337
PR 26492
	* elf64-ppc.c (ppc_hash_table): Test is_elf_hash_table before
	accessing elf_hash_table_id.
2020-08-25 02:12:35 +09:30
Alan Modra
a8d549c006 PR26483, ASAN: ppc_elf_link_params elf32-ppc.c:2314
PR 26483
	* elf32-ppc.c (ppc_elf_hash_table): Test is_elf_hash_table before
	accessing elf_hash_table_id.
2020-08-25 02:11:13 +09:30
Mark Wielaard
19d80e5fec bfd: Handle DW_FORM_data16 for .debug_line tables containing MD5
* dwarf2.c (read_attribute_value): Handle DW_FORM_data16.
	(read_formatted_entries): Likewise. And skip zero entry.
2020-08-24 15:52:53 +01:00
Cooper Qu
531c73a37b CSKY: Add new arch CK860.
bfd/
        * bfd-in2.h (bfd_mach_ck860): New.
        * cpu-csky.c (arch_info_struct): Add item for CK860.

gas/
        * config/tc-csky.c (csky_archs): Add item for CK860,
        change ck810 and ck807's arch_flag.
        (csky_cpus): Add item for CK860.
        (md_begin): Enable DSP for CK810 and CK807 by default.
        (md_apply_fix): Fix CKCORE_TLS_IE32 relocation failure.
        * gas/testsuite/gas/csky/cskyv2_all.d: Change 'sync 0'
        to 'sync'.
        * gas/testsuite/gas/csky/cskyv2_all.s: Likewise.
        * gas/testsuite/gas/csky/cskyv2_ck860.d: New.
        * gas/testsuite/gas/csky/cskyv2_ck860.s: New.
        * gas/testsuite/gas/csky/enhance_dsp.d: Change plsli.u16
        to plsli.16.
        * gas/testsuite/gas/csky/enhance_dsp.s: Likewise.

include/
        * opcode/csky.h (CSKYV2_ISA_10E60): New.
        (CSKY_ARCH_860): New.

opcode/
        * csky-dis.c (csky_find_inst_info): Skip CK860's instructions
        in other CPUs to speed up disassembling.
        * csky-opc.h (csky_v2_opcodes): Add CK860's instructions,
        Change plsli.u16 to plsli.16, change sync's operand format.

Change-Id: I80ec1a9c0cc600d668082a9b91ae6d45b33ec0fc
2020-08-24 20:27:07 +08:00
Alan Modra
252dcdf432 PowerPC TPREL_HA/LO optimisation
ppc64 ld optimises sequences like the following
	addis 3,13,wot@tprel@ha
	lwz 3,wot@tprel@l(3)
to
	nop
	lwz 3,wot@tprel(13)
when "wot" is located near enough to the thread pointer.
However, the ABI doesn't require that R_PPC64_TPREL16_HA always be on
an addis rt,13,imm instruction, and while ld checked for that on the
high-part instruction it didn't disable the optimisation on the
low-part instruction.  This patch fixes that problem, disabling the
tprel optimisation globally if high-part instructions don't pass
sanity checks.  The optimisation is also enabled for ppc32, where
before ld.bfd had the code in the wrong place and ld.gold had it in a
block only enabled for ppc64.

bfd/
	* elf32-ppc.c (ppc_elf_check_relocs): Set has_tls_reloc for
	high part tprel16 relocs.
	(ppc_elf_tls_optimize): Sanity check high part tprel16 relocs.
	Clear do_tls_opt on odd instructions.
	(ppc_elf_relocate_section): Move TPREL16_HA/LO optimisation later.
	Don't sanity check them here.
	* elf64-ppc.c (ppc64_elf_check_relocs): Set has_tls_reloc for
	high part tprel16 relocs.
	(ppc64_elf_tls_optimize): Sanity check high part tprel16 relocs.
	Clear do_tls_opt on odd instructions.
	(ppc64_elf_relocate_section): Don't sanity check TPREL16_HA.
ld/
	* testsuite/ld-powerpc/tls32.d: Update for TPREL_HA/LO optimisation.
	* testsuite/ld-powerpc/tlsexe32.d: Likewise.
	* testsuite/ld-powerpc/tlsldopt32.d: Likewise.
	* testsuite/ld-powerpc/tlsmark32.d: Likewise.
	* testsuite/ld-powerpc/tlsopt4_32.d: Likewise.
	* testsuite/ld-powerpc/tprel.s,
	* testsuite/ld-powerpc/tprel.d,
	* testsuite/ld-powerpc/tprel32.d: New tests.
	* testsuite/ld-powerpc/tprelbad.s,
	* testsuite/ld-powerpc/tprelbad.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
gold/
	* powerpc.cc (Target_powerpc): Add tprel_opt_ and accessors.
	(Target_powerpc::Scan::local): Sanity check tprel high relocs.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Control tprel optimisation
	with tprel_opt_ and enable for 32-bit.
2020-08-24 21:15:06 +09:30
John David Anglin
c40e66502c Disable default ELF plugins on 32-bit hppa*-*-hpux*.
PR binutils/26357
	* configure.ac: Disable plugins by default on 32-bit hppa*-*-hpux*.
	* configure: Regenerate.
2020-08-23 16:44:22 +00:00
H.J. Lu
3f2e969923 elf: Keep only one '@' for undefined versioned symbols
The symbol string table in the .symtab section is optional and cosmetic.
Keep only one '@' for undefined versioned symbols, which are defined in
shared objects, in the symbol string table.  Update "nm -D" to display
only one '@' for undefined versioned symbols.

bfd/

	PR ld/26382
	* elflink.c (elf_link_output_symstrtab): Keep only one '@' for
	versioned symbols, which are defined in shared objects, in
	symbol string table.

binutils/

	PR ld/26382
	* nm.c (print_symname): Display only one '@' for undefined
	versioned symbols.
	* doc/binutils.texi: Update nm version information.

ld/

	PR ld/26382
	* testsuite/ld-elf/pr26302.nd: Updated.
	* testsuite/ld-elf/pr26302.rd: New file.
	* testsuite/ld-elf/shared.exp: Add a test for readelf -sW.
2020-08-22 08:32:02 -07:00
Nick Clifton
ccf61261eb Fix problems with the AArch64 linker exposed by testing it with sanitization enabled.
bfd	* elfnn-aarch64.c (_bfd_aarch64_erratum_835769_scan): Only sort
	the data map if there are entries in it.
	(_bfd_aarch64_erratum_843419_scan): Likewise.

opcodes	* aarch64-dis.c (get_sym_code_type): Return FALSE for non-ELF
	symbols.
2020-08-21 15:32:20 +01:00
Jan Beulich
610ed3e08f fix objcopy of PE images with .buildid section
Xen Project embeds a build ID in its hypervisor binary (including its
EFI variant), living in a standalone section. This usually gets placed
right after .rodata, and due to the rounding done on the (file) size of
.rodata the two sections appear to overlap (as far as e.g.
find_section_by_vma() is concerned). With the first byte "found" in
.rodata, nothing guarantees that the entire debug dir fits in that
section, leading to apparently random failure of objcopy on such an
image.

Possible alternatives to the solution chosen:
- make find_section_by_vma() honor virt_size,
- correct the recording of sizes elsewhere (ibfd has size == virt_size,
  while obfd doesn't),
- fix the linker to avoid producing apparently overlapping sections.

While touching the condition around and the contents of the disgnostic,
pull it up ahead of the bfd_malloc_and_get_section() call: There's no
point first obtaining the section contents, in order to then fail.
2020-08-21 10:28:35 +02:00
Nick Clifton
01147b2082 Ensure that compressed sections that have an ELF compression header structure at the start are correctly aligned.
PR 26428
bfd	* bfd.c (bfd_update_compression_header): Also set the sh_addralign
	field in the ELF header of the compressed sections.

ld	* testsuite/ld-elf/zlibbegin.rS: Update expected output.
	* testsuite/ld-elf/zlibnormal.rS: Likewise.
2020-08-20 15:03:21 +01:00
Nick Clifton
44466e45c5 Apply a workaround to mitigate a quadratic performance hit in the linker when writing out secondary reloc sections.
PR 26406
	* elf-bfd.h (struct bfd_elf_section_data): Add
	has_secondary_relocs field.
	* elf.c (_bfd_elf_copy_special_section_fields): Set the
	has_secondary_relocs field for sections which have associated
	secondary relocs.
	* elfcode.h (elf_write_relocs): Only call write_secondary_relocs
	on sections which have associated secondary relocs.
2020-08-20 10:19:47 +01:00
Alan Modra
10885e2436 Set SEC_SMALL_DATA on small common
Unlike the previous patch setting SEC_SMALL_DATA during
elf_backend_symbol_processing, this patch is mostly cosmetic.

	* elf32-frv.c (elf32_frv_add_symbol_hook): Set SEC_SMALL_DATA on
	small common section.
	* elf32-m32r.c (m32r_elf_add_symbol_hook): Likewise.
	* elf32-microblaze.c (microblaze_elf_add_symbol_hook): Likewise.
	* elf32-nds32.c (nds32_elf_add_symbol_hook): Likewise.
	* elf32-nios2.c (nios2_elf_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-score.c (s3_bfd_score_elf_add_symbol_hook): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_add_symbol_hook): Likewise.
	* elf32-tic6x.c (elf32_tic6x_add_symbol_hook): Likewise.
	* elf32-v850.c (v850_elf_check_relocs): Likewise.
	(v850_elf_add_symbol_hook): Likewise.
	* elf64-alpha.c (elf64_alpha_add_symbol_hook): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_add_symbol_hook): Likewise.
	* elfnn-ia64.c (elfNN_ia64_add_symbol_hook): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Likewise.
2020-08-15 15:14:42 +09:30
Alan Modra
4d1823674e PR26389, nm prints "c" for a common symbol with -flto and -fcommon
git commit 49d9fd42ac chose to make nm print 'C' for the normal
common section, and 'c' for other commons.  This was an attempt to
make common symbols in .scommon and other small common sections show
a 'c' type without a section name comparison, but it failed for
nm --plugin on lto objects where normal common symbols are stashed in
a "plug" section.  It's also wrong for large common symbols.  So
instead set SEC_SMALL_DATA on sections created for small commons, and
key off that flag to show 'c' type.  If your ELF target doesn't have
an elf_backend_symbol_processing function, then you won't see 'c' for
symbols in .scommon.

Note that due to bfd_decode_symclass decoding common symbols without
a chance for coff_section_type to treat .scommon specially, then
having .scommon in the array of special sections handled by
coff_section_type prior to 49d9fd42ac was entirely ineffective.
That fact escaped me when writing 49d9fd42ac.  Unless .scommon
didn't have SEC_IS_COMMON set, which would be a little weird.

	PR 26389
	* syms.c (bfd_decode_symclass): Choose 'c' for commons only when
	SEC_SMALL_DATA.
	* elf32-m32r.c (_bfd_m32r_elf_symbol_processing): Set SEC_SMALL_DATA
	on small common section.
	* elf32-score.c (s3_bfd_score_elf_symbol_processing): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_symbol_processing): Likewise.
	* elf32-tic6x.c (elf32_tic6x_symbol_processing): Likewise.
	* elf32-v850.c (v850_elf_symbol_processing): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_symbol_processing): Likewise.
	* ecoff.c (ecoff_set_symbol_info, ecoff_link_add_externals): Likewise.
2020-08-15 14:16:02 +09:30
Alan Modra
19bddbe95c Allow larger bfd_default_hash_table_size
* hash.c (bfd_hash_set_default_size): Use higher_prime_number
	rather than another copy of primes.  Increase maximum default
	size allowed.
2020-08-14 21:37:24 +09:30
Alan Modra
73d0dc162e Obsolete ia64
* config.bfd: Obsolete ia64*-*-*.
2020-08-13 14:13:43 +09:30
Alan Modra
2b6ba032ad Obsolete arm-symbianelf
* config.bfd: Obsolete arm*-*-symbianelf*.
2020-08-13 09:58:13 +09:30
Alan Modra
6738c8a7c9 PowerPC64 --no-pcrel-optimize
This new option effectively ignores R_PPC64_PCREL_OPT, disabling the
optimization of instructions marked by that relocation.  The patch
also disables GOT indirect to GOT/TOC pointer relative code editing
when --no-toc-optimize.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add no_pcrel_opt.
	* elf64-ppc.c (ppc64_elf_relocate_section): Disable GOT reloc
	optimizations when --no-toc-optimize.  Disable R_PPC64_PCREL_OPT
	optimization when --no-pcrel-optimize.
ld/
	* emultempl/ppc64elf.em (params): Init new field.
	(enum ppc64_opt): Add OPTION_NO_PCREL_OPT.
	(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS),
	(PARSE_AND_LIST_ARGS_CASES): Support --no-pcrel-optimize.
2020-08-13 08:10:18 +09:30
Alan Modra
75e100a30d PR26348, Malloc error in write_zeros
This adds a few more sanity checks on ELF objects, and a BFD flag to
disable objcopy and strip when fuzzed input files belong in the "too
hard" basket.

bfd/
	PR 26348
	* bfd.c (struct bfd): Add read_only.
	* elfcode.h (elf_swap_shdr_in): Test both sh_offset and sh_size.
	Set read_only on warning.
	(elf_object_p): Sanity check program header alignment.  Set
	read_only on warning.
	* bfd-in2.h: Regenerate.
binutils/
	PR 26348
	* objcopy.c (copy_object): Report file name with endian error.
	Error and return on abfd->read_only.
2020-08-13 08:09:08 +09:30
Jon Turney
2fef937354
Fix signedness comparison warning in elfcore_grok_win32pstatus()
bfd/ChangeLog:

2020-08-12  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Use unsigned int for
	win32pstatus note type to avoid signedness comparison warning.
2020-08-12 16:39:25 +01:00
Jon Turney
404ec93359
Only warn about malformed win32pstatus notes
bfd/ChangeLog:

2020-07-21  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Warn on malformed
	win32pstatus notes, and return TRUE so we continue rather than
	stopping as if it was an error.
2020-08-12 15:08:30 +01:00
Jon Turney
d61f3d0383
Add handling for 64-bit module addresses in Cygwin core dumps
bfd/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Handle NOTE_INFO_MODULE64.
2020-08-12 15:08:28 +01:00
Jon Turney
04ec0fa297
Refine size constraints applied to win32pstatus ELF notes
Don't reject any win32pstatus notes smaller than minimum size for a
NOTE_INFO_THREAD.

This only happens to work because the Cygwin dumper tool currently
writes all these notes as the largest size of the union, (which wastes
lots of space in the core dump).

Instead, apply the appropriate size constraint for each win32pstatus
note type.

bfd/ChangeLog:

2020-07-11  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Don't apply size constraint
	for NOTE_INFO_THREAD to all win32pstatus ELF notes, instead apply
	appropriate size constraint for each win32pstatus note type.
2020-08-12 15:08:27 +01:00
Jon Turney
03c29a6faf
Don't hardcode CONTEXT size for a NOTE_INFO_THREAD win32pstatus note
Don't hardcode the size of the Win32 API thread CONTEXT type read from a
NOTE_INFO_THREAD win32pstatus note (since it's different on different
architectures).

bfd/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Don't hardcode the size of
	the Win32 API thread CONTEXT type read from a NOTE_INFO_THREAD
	win32pstatus note.
2020-08-12 15:08:25 +01:00
Jon Turney
8fbac78b14
Define constants for win32pstatus ELF notes
Define constants for win32pstatus ELF notes, as they were prior to
4a6636fb, and say what specifies them.

bfd/ChangeLog:

2020-07-11  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (NOTE_INFO{_PROCESS,_THREAD,_MODULE}): Define.
	(elfcore_grok_win32pstatus): Use.
2020-08-12 15:08:23 +01:00
Jon Turney
ff2084b9ef
Read tid from correct offset in win32pstatus NOTE_INFO_THREAD
Fix the offset used to read the tid from a win32pstatus ELF note.

This probably meant that registers were only being correctly recovered
from the core dump for the current thread.

It looks like this has beeen incorrect since 4a6636fb.

Also fix offsets used in NOTE_INFO_PROCESS (which is not actually
generated by the Cygwin dumper tool).

Also improve comment.

bfd/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Fix the offset used to read
	the tid from a win32pstatus NOTE_INFO_THREAD ELF note.  Fix
	offsets used to read NOTE_INFO_PROCESS.
2020-08-12 15:08:21 +01:00
Nick Clifton
79ddc88496 Updated Serbian and Russian translations for various sub-directories 2020-08-12 11:25:38 +01:00
David Faust
d844f10ac2 bpf: fix false overflow in eBPF ELF backend linker
When performing DISP{16,32} relocations, the eBPF ELF backend linker
needs to convert the relocation from an address into a signed number
of 64-bit words (minus one) to jump.

Because of this unsigned-to-signed conversion, special care needs to
be taken when dividing to ensure the sign bits remain correct.
Otherwise, a false relocation overflow error can be triggered.

bfd/ChangeLog

2020-08-07  David Faust  <david.faust@oracle.com>

	* elf64-bpf.c (bpf_elf_relocate_section): Ensure signed division for
	DISP16 and DISP32 relocations.

ld/ChangeLog

2020-08-07  David Faust  <david.faust@oracle.com>

	* testsuite/ld-bpf/call-3.s: New file.
	* testsuite/ld-bpf/call-3.d: Likewise.
2020-08-07 20:36:47 +02:00
David Faust
3ee9565c95 bpf: relocation fixes for eBPF ELF backend
The eBPF ELF backend was not properly recording relocation addends
during installation, nor reading and applying them when performing
the final relocation. This lead to various issues with incorrect
relocations.

These issues are fixed with a new howto special function to install
the relocations, and updates to bpf_elf_relocate_section to read and
use the addends as recorded in the input_bfd.

bfd/ChangeLog

2020-08-05  David Faust  <david.faust@oracle.com>

	* elf64-bpf.c (bpf_elf_generic_reloc): New function.
	(bpf_elf_howto_table): Use it here.
	(bpf_elf_relocate_section): Use addends recorded in input_bfd for
	instruction and data relocations.

ld/ChangeLog

2020-08-05  David Faust  <david.faust@oracle.com>

	* testsuite/ld-bpf/call-2.s: New file.
	* testsuite/ld-bpf/call-2.d: Likewise.
	* testsuite/ld-bpf/reloc-data-be.d: Likewise.
	* testsuite/ld-bpf/reloc-data-le.d: Likewise.
	* testsuite/ld-bpf/reloc-data.s: Likewise.
	* testsuite/ld-bpf/reloc-insn-external-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn-external-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn-external.s: Likewise.
	* testsuite/ld-bpf/reloc-insn32-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn32-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn32.s: Likewise.
	* testsuite/ld-bpf/reloc-insn64-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn64-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn64.s: Likewise.
2020-08-06 15:14:54 +02:00
Alan Modra
e44a1d7b9a asan: alpha-vms: buffer overflow in vms_traverse_index
* vms-lib.c (vms_traverse_index): Sanity check size remaining
	before accessing vms_idx or vms_elfidx.
2020-08-03 23:18:34 +09:30
Alan Modra
b5f386d520 PR26330, Malloc size error in objdump
PR 26330
	* elf.c (_bfd_elf_get_symtab_upper_bound): Sanity check symbol table
	size against file size.  Correct LONG_MAX limit check.
	(_bfd_elf_get_dynamic_symtab_upper_bound): Likewise.
	(_bfd_elf_get_reloc_upper_bound): Don't check file size if writing.
	(_bfd_elf_get_dynamic_reloc_upper_bound): Likewise.
	* elf64-x86-64-.c (elf_x86_64_get_synthetic_symtab): Use
	bfd_malloc_and_get_section.
2020-08-03 14:07:31 +09:30
Alan Modra
a896df97b9 PR26314, Linking LTO objects with symbols from static and shared libraries
gcc -O2 -g -o ar -Wl,--as-needed arparse.o arlex.o ar.o not-ranlib.o arsup.o rename.o binemul.o emul_vanilla.o bucomm.o version.o filemode.o libbfd-2.35-3.fc33.so libiberty.a -Wl,-R,.

All of the above .o files are lto, leading to libbfd-2.35-3.fc33.so
not being found needed when loading the IR objects.  That's problem
number one:  We exclude IR references when deciding a shared library
is needed.  See PR15146.  Thus none of the libbfd.so symbols are
loaded before libiberty.a is scanned, and libbfd.so contains copies of
libiberty.a functions.  We ought to be using the libbfd.so copies
rather than extracting them from the archive (an object is extracted
even to satisfy IR symbols).  After lto recompilation, libbfd.so is of
course found to be needed and loaded.  But that causes more problems.
The lto recompilation didn't see symbol references from libbfd.so and
variables like _xexit_cleanup are made local in the recompiled
objects.  Oops, two copies of them.  Finally, those silly undefined
symbols in the lto output debug files, combined with definitions in
both libbfd.so and IR objects result in IR symbols being made
dynamic.

The main fix here is to revert the PR15146 change to
elf_link_add_object_symbols.

	PR 26314
	* elflink.c (bfd_elf_link_record_dynamic_symbol): Don't allow
	IR symbols to become dynamic.
	(elf_link_add_object_symbols): Don't exclude IR symbols when
	deciding whether an as-needed shared library is needed.
2020-07-31 20:31:20 +09:30
Szabolcs Nagy
4d3bb35620 aarch64: set sh_entsize of .plt to 0
On aarch64 the first PLT entry is 32 bytes, subsequent entries
are 16 bytes by default but can be 24 bytes with BTI or with
PAC-PLT.

sh_entsize of .plt was set to the PLT entry size, so in some
cases sh_size % sh_entsize != 0, which breaks some tools.

Note that PLT0 (and the TLSDESC stub code which is also in the
PLT) were historically not padded up to meet the sh_size
requirement, but to ensure that PLT stub code is aligned on
cache lines. Similar layout is present on other targets too
which just happens to make sh_size a multiple of sh_entsize and
it is not expected that sh_entsize of .plt is used for anything.

This patch sets sh_entsize of .plt to 0: the section does not
hold a table of fixed-size entries so other values are not
conforming in principle to the ELF spec.

bfd/ChangeLog:

	PR ld/26312
	* elfnn-aarch64.c (elfNN_aarch64_init_small_plt0_entry): Set sh_entsize
	to 0.
	(elfNN_aarch64_finish_dynamic_sections): Remove sh_entsize setting.
2020-07-30 17:00:53 +01:00
Rainer Orth
c8693053f8 Unify Solaris procfs and largefile handling
GDB currently doesn't build on 32-bit Solaris:

* On Solaris 11.4/x86:

In file included from /usr/include/sys/procfs.h:26,
                 from /vol/src/gnu/gdb/hg/master/dist/gdb/i386-sol2-nat.c:24:
/usr/include/sys/old_procfs.h:31:2: error: #error "Cannot use procfs in the large file compilation environment"
 #error "Cannot use procfs in the large file compilation environment"
  ^~~~~

* On Solaris 11.3/x86 there are several more instances of this.

The interaction between procfs and large-file support historically has
been a royal mess on Solaris:

* There are two versions of the procfs interface:

** The old ioctl-based /proc, deprecated and not used any longer in
   either gdb or binutils.

** The `new' (introduced in Solaris 2.6, 1997) structured /proc.

* There are two headers one can possibly include:

** <procfs.h> which only provides the structured /proc, definining
   _STRUCTURED_PROC=1 and then including ...

** <sys/procfs.h> which defaults to _STRUCTURED_PROC=0, the ioctl-based
   /proc, but provides structured /proc if _STRUCTURED_PROC == 1.

* procfs and the large-file environment didn't go well together:

** Until Solaris 11.3, <sys/procfs.h> would always #error in 32-bit
   compilations when the large-file environment was active
   (_FILE_OFFSET_BITS == 64).

** In both Solaris 11.4 and Illumos, this restriction was lifted for
   structured /proc.

So one has to be careful always to define _STRUCTURED_PROC=1 when
testing for or using <sys/procfs.h> on Solaris.  As the errors above
show, this isn't always the case in binutils-gdb right now.

Also one may need to disable large-file support for 32-bit compilations
on Solaris.  config/largefile.m4 meant to do this by wrapping the
AC_SYS_LARGEFILE autoconf macro with appropriate checks, yielding
ACX_LARGEFILE.  Unfortunately the macro doesn't always succeed because
it neglects the _STRUCTURED_PROC part.

To make things even worse, since GCC 9 g++ predefines
_FILE_OFFSET_BITS=64 on Solaris.  So even if largefile.m4 deciced not to
enable large-file support, this has no effect, breaking the gdb build.

This patch addresses all this as follows:

* All tests for the <sys/procfs.h> header are made with
  _STRUCTURED_PROC=1, the definition going into the various config.h
  files instead of having to make them (and sometimes failing) in the
  affected sources.

* To cope with the g++ predefine of _FILE_OFFSET_BITS=64,
  -U_FILE_OFFSET_BITS is added to various *_CPPFLAGS variables.  It had
  been far easier to have just

  #undef _FILE_OFFSET_BITS

  in config.h, but unfortunately such a construct in config.in is
  commented by config.status irrespective of indentation and whitespace
  if large-file support is disabled.  I found no way around this and
  putting the #undef in several global headers for bfd, binutils, ld,
  and gdb seemed way more invasive.

* Last, the applicability check in largefile.m4 was modified only to
  disable largefile support if really needed.  To do so, it checks if
  <sys/procfs.h> compiles with _FILE_OFFSET_BITS=64 defined.  If it
  doesn't, the disabling only happens if gdb exists in-tree and isn't
  disabled, otherwise (building binutils from a tarball), there's no
  conflict.

  What initially confused me was the check for $plugins here, which
  originally caused the disabling not to take place.  Since AC_PLUGINGS
  does enable plugin support if <dlfcn.h> exists (which it does on
  Solaris), the disabling never happened.

  I could find no explanation why the linker plugin needs large-file
  support but thought it would be enough if gld and GCC's lto-plugin
  agreed on the _FILE_OFFSET_BITS value.  Unfortunately, that's not
  enough: lto-plugin uses the simple-object interface from libiberty,
  which includes off_t arguments.  So to fully disable large-file
  support would mean also disabling it in libiberty and its users: gcc
  and libstdc++-v3.  This seems highly undesirable, so I decided to
  disable the linker plugin instead if large-file support won't work.

The patch allows binutils+gdb to build on i386-pc-solaris2.11 (both
Solaris 11.3 and 11.4, using GCC 9.3.0 which is the worst case due to
predefined _FILE_OFFSET_BITS=64).  Also regtested on
amd64-pc-solaris2.11 (again on Solaris 11.3 and 11.4),
x86_64-pc-linux-gnu and i686-pc-linux-gnu.

	config:
	* largefile.m4 (ACX_LARGEFILE) <sparc-*-solaris*|i?86-*-solaris*>:
	Check for <sys/procfs.h> incompatilibity with large-file support
	on Solaris.
	Only disable large-file support and perhaps plugins if needed.
	Set, substitute LARGEFILE_CPPFLAGS if so.

	bfd:
	* bfd.m4 (BFD_SYS_PROCFS_H): New macro.
	(BFD_HAVE_SYS_PROCFS_TYPE): Require BFD_SYS_PROCFS_H.
	Don't define _STRUCTURED_PROC.
	(BFD_HAVE_SYS_PROCFS_TYPE_MEMBER): Likewise.
	* elf.c [HAVE_SYS_PROCFS_H] (_STRUCTURED_PROC): Don't define.
	* configure.ac: Use BFD_SYS_PROCFS_H to check for <sys/procfs.h>.
	* configure, config.in: Regenerate.
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.

	binutils:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.
	* configure: Regenerate.

	gas:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.
	* configure: Regenerate.

	gdb:
	* proc-api.c (_STRUCTURED_PROC): Don't define.
	* proc-events.c: Likewise.
	* proc-flags.c: Likewise.
	* proc-why.c: Likewise.
	* procfs.c: Likewise.

	* Makefile.in (INTERNAL_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* configure, config.in: Regenerate.

	gdbserver:
	* configure, config.in: Regenerate.

	gdbsupport:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* common.m4 (GDB_AC_COMMON): Use BFD_SYS_PROCFS_H to check for
	<sys/procfs.h>.
	* Makefile.in: Regenerate.
	* configure, config.in: Regenerate.

	gnulib:
	* configure.ac: Run ACX_LARGEFILE before gl_EARLY.
	* configure: Regenerate.

	gprof:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in: Regenerate.
	* configure: Regenerate.

	ld:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
2020-07-30 15:41:50 +02:00
H.J. Lu
f1dfbfdbc6 elf: Add sym_cache to elf_link_hash_table
Since many ELF backends have sym_cache to their link hash tables, add
sym_cache to elf_link_hash_table.  Also use sdynbss and srelbss in
elf_link_hash_table.

	* elf-bfd.h (sym_cache): Moved before elf_link_hash_table.
	(elf_link_hash_table): Add sym_cache.
	* elf32-arm.c (elf32_arm_link_hash_table): Remove sym_cache.
	(elf32_arm_check_relocs): Updated.
	(elf32_arm_size_dynamic_sections): Likewise.
	* elf32-bfin.c (bfin_link_hash_table): Removed.
	(bfin_link_hash_newfunc): Updated.
	(bfin_hash_table): Removed.
	* elf32-csky.c (csky_elf_link_hash_table): Remove sym_cache.
	(csky_elf_check_relocs): Updated.
	* elf32-hppa.c (elf32_hppa_link_hash_table): Remove sym_cache.
	(elf32_hppa_check_relocs): Updated.
	* elf32-i386.c (elf_i386_tls_transition): Updated.
	(elf_i386_convert_load_reloc): Likewise.
	(elf_i386_check_relocs): Likewise.
	* elf32-m32r.c (elf_m32r_link_hash_table): Removed.
	(m32r_elf_hash_table): Updated.
	(m32r_elf_link_hash_table_create): Likewise.
	(m32r_elf_create_dynamic_sections): Likewise.
	(m32r_elf_adjust_dynamic_symbol): Likewise.
	(allocate_dynrelocs): Likewise.
	(m32r_elf_size_dynamic_sections): Likewise.
	(m32r_elf_relocate_section): Likewise.
	(m32r_elf_finish_dynamic_symbol): Likewise.
	(m32r_elf_check_relocs): Likewise.
	* elf32-m68hc1x.h (m68hc11_elf_link_hash_table): Remove
	sym_cache.
	* elf32-m68k.c (elf_m68k_link_hash_table): Likewise.
	(elf_m68k_check_relocs): Updated.
	* elf32-metag.c (elf_metag_link_hash_table): Remove sym_cache.
	(elf_metag_check_relocs): Updated.
	* elf32-microblaze.c (elf32_mb_link_hash_table): Remove sym_sec.
	(microblaze_elf_check_relocs): Updated.
	* elf32-nds32.c (nds32_elf_link_hash_table_create): Likewise.
	(nds32_elf_create_dynamic_sections): Likewise.
	(nds32_elf_adjust_dynamic_symbol): Likewise.
	(nds32_elf_check_relocs): Likewise.
	* elf32-nds32.h (elf_nds32_link_hash_table): Remove sdynbss,
	srelbss and aym_cache.
	* elf32-nios2.c (elf32_nios2_link_hash_table): Remove sym_cache.
	(nios2_elf32_check_relocs): Updated.
	* elf32-or1k.c (elf_or1k_link_hash_table): Remove sym_sec.
	(or1k_elf_check_relocs): Updated.
	* elf32-ppc.c (ppc_elf_check_relocs): Remove sym_cache.
	(ppc_elf_check_relocs): Updated.
	* elf32-s390.c (elf_s390_link_hash_table): Remove sym_cache.
	(elf_s390_check_relocs): Updated.
	(elf_s390_finish_dynamic_sections): Likewise.
	* elf32-sh.c (elf_sh_link_hash_table): Remove sdynbss, srelbss
	and aym_cache.
	(sh_elf_create_dynamic_sections): Updated.
	(sh_elf_adjust_dynamic_symbol): Likewise.
	(sh_elf_size_dynamic_sections): Likewise.
	(sh_elf_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table): Remove sym_cache.
	(elf32_tic6x_check_relocs): Updated.
	* elf32-tilepro.c (tilepro_elf_link_hash_table): Removed.
	(tilepro_elf_hash_table): Updated.
	(tilepro_elf_link_hash_table_create): Likewise.
	(tilepro_elf_check_relocs): Likewise.
	(tilepro_elf_adjust_dynamic_symbol): Likewise.
	(allocate_dynrelocs): Likewise.
	(tilepro_elf_size_dynamic_sections): Likewise.
	(tilepro_elf_relocate_section): Likewise.
	(tilepro_elf_finish_dynamic_symbol): Likewise.
	(tilepro_finish_dyn): Likewise.
	(tilepro_elf_finish_dynamic_sections): Likewise.
	* elf64-ppc.c (ppc_link_hash_table): Remove sym_cache.
	(ppc64_elf_before_check_relocs): Updated.
	(ppc64_elf_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_link_hash_table): Remove sym_cache.
	(elf_s390_check_relocs): Updated.
	(elf_s390_relocate_section): Likewise.
	(elf_s390_finish_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_check_relocs): Likewise.
	* elfnn-aarch64.c (elf_aarch64_link_hash_table): Remove
	sym_cache.
	(elfNN_aarch64_check_relocs): Updated.
	* elfnn-riscv.c (riscv_elf_link_hash_table): Remove sym_cache.
	(riscv_elf_check_relocs): Updated.
	* elfxx-mips.c (mips_elf_link_hash_table): Remove sym_cache.
	(mips_elf_resolve_got_page_ref): Updated.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-sparc.h (_bfd_sparc_elf_link_hash_table): Remove
	sym_cache.
	* elfxx-tilegx.c (tilegx_elf_link_hash_table): Likewise.
	(tilegx_elf_check_relocs): Updated.
	* elfxx-x86.h (elf_x86_link_hash_table): Remove sym_cache.
2020-07-30 03:41:44 -07:00
Maciej W. Rozycki
c77cb2a09c MIPS: Make the IRIX naming of local section symbols consistent
Make the MIPS/IRIX naming of local section symbols consistent between
files produced by generic ELF code and ELF linker code, complementing
commit 174fd7f955 ("New bfd elf hook: force naming of local section
symbols"), <https://sourceware.org/ml/binutils/2004-02/msg00072.html>.

Local section symbols have no names in the standard ELF gABI, however
the lack of a name causes problems with IRIX's MIPSpro linker.  To work
around the issue we give them names, however we do that in generic ELF
code only, based on what the `elf_backend_name_local_section_symbols'
hook returns if present.  That makes objects created by GAS or `objdump'
work correctly, however not ones created by `ld -r'.  That would not
normally cause issues with IRIX systems using GAS and `objdump' only
with the MIPSpro linker, however if GNU LD was used for whatever reason
in producing objects later fed to IRIX's MIPSpro linker, then things
would break.

Modify ELF linker code accordingly then, using the same hook.  Adjust
the `ld-elf/64ksec-r' test accordingly so that it also accepts a section
symbol with a name.

Also modify the hook itself so that only actual ET_REL objects have
names assigned to local section symbols.  Other kinds of ELF files are
not ever supposed to be relocated with the MIPSpro linker, so we can
afford producing more standard output.

Add suitable GAS, LD and `objcopy' test cases to the relevant testsuites
to keep these tools consistently verified.  This change also fixes:

FAIL: objcopy executable (pr25662)

across MIPS targets using the IRIX compatibility mode.

	bfd/
	* elflink.c (bfd_elf_final_link): Give local symbols a name if
	so requested.
	* elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): Only
	return TRUE if making ET_REL output.

	binutils/
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n64.d:
	New test.
	* testsuite/binutils-all/mips/mips.exp: Run the new tests.

	gas/
	* testsuite/gas/mips/global-local-symtab-sort-o32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-o32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64t.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-elf/sec64k.exp: Also accept a section symbol with
	a name.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n64.d: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2020-07-29 20:56:41 +01:00
Maciej W. Rozycki
3f1b17bbf0 MIPS/LD: Set symtab's `sh_info' correctly for IRIX emulations
Correct ELF linker code so as to set the `sh_info' value of the static
symbol table section according to the section symbols vs other symbols
split where required by the selection of the IRIX compatibility mode for
MIPS target.  Add a `elf_backend_elfsym_local_is_section' hook for that
purpose, returning TRUE if it is only STB_LOCAL/STT_SECTION symbols that
are to be considered local for the purpose of this split rather than all
STB_LOCAL symbols.

We do it already in generic ELF code, and have done it since 1993, with
the `elf_backend_sym_is_global' hook, affecting GAS and `objcopy', so
these tools produce correct ELF output in the IRIX compatibility mode,
however if such output is fed as input to `ld -r', then the linker's
output is no longer valid for that mode.  The relevant changes to
generic ELF code are:

commit 062189c6ea
Author: Ian Lance Taylor <ian@airs.com>
Date:   Thu Nov 18 17:12:47 1993 +0000

and:

commit 6e07e54f1b
Author: Ian Lance Taylor <ian@airs.com>
Date:   Thu Jan 6 20:01:42 1994 +0000

(split across two GIT commits likely due to repository conversion
peculiarities).

The `elf_backend_sym_is_global' hook however operates on BFD rather than
ELF symbols, making it unsuitable for the ELF linker as the linker does
not convert any symbol tables processed into the BFD format.  Converting
the hook to operate on ELF symbols would in principle be possible, but
it would still require a considerable rewrite of `bfd_elf_final_link' to
adapt to the interface.

Therefore, especially given that no new use for the IRIX compatibility
mode is expected, minimize changes made to the ELF linker code and just
add an entirely new hook, and wire it in the o32 and n32 MIPS backends
accordingly; the n64 backend never uses the IRIX compatibility mode.

Since we have no coverage here at all add suitable GAS, LD and `objcopy'
test cases to the relevant testsuites to keep these tools consistently
verified.

	bfd/
	* elf-bfd.h (elf_backend_data): Add
	`elf_backend_elfsym_local_is_section' member.
	* elfxx-target.h (elf_backend_elfsym_local_is_section): New
	macro.
	(elfNN_bed): Add `elf_backend_elfsym_local_is_section' member.
	* elflink.c (bfd_elf_final_link): Use it to determine whether
	set the `.symtab' section's `sh_info' value to the index of the
	first non-local or non-section symbol.
	* elf32-mips.c (mips_elf32_elfsym_local_is_section): New
	function.
	(elf_backend_elfsym_local_is_section): New macro.
	* elfn32-mips.c (mips_elf_n32_elfsym_local_is_section): New
	function.
	(elf_backend_elfsym_local_is_section): New macro.

	binutils/
	* testsuite/binutils-all/mips/global-local-symtab-o32.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-o32t.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n32.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n32t.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n64.d: New
	test.
	* testsuite/binutils-all/mips/mips.exp: Run the new tests.

	gas/
	* testsuite/gas/mips/global-local-symtab-o32.d: New test.
	* testsuite/gas/mips/global-local-symtab-o32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-n32.d: New test.
	* testsuite/gas/mips/global-local-symtab-n32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-n64.d: New test.
	* testsuite/gas/mips/global-local-symtab.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/global-local-symtab-o32.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-o32t.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n32.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n32t.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n64.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab.ld: New test linker
	script.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2020-07-29 20:56:41 +01:00
Alan Modra
4d68fd750f Don't segfault on discarded section dynsyms
We get lots of errors before we get to this code, but let's not
segfault.

	* elflink.c (bfd_elf_final_link): Don't segfault on local dynsyms
	defined in excluded sections.
2020-07-29 17:39:54 +09:30
Alan Modra
67411cbf63 PR25022 testcase segfault for generic ELF linker targets
Even a testcase that is expected to fail shouldn't segfault.

	* elf.c (assign_section_numbers): Comment.  Don't segfault on
	discarded sections when setting linked-to section for generic
	ELF linker.
	* elflink.c (bfd_elf_match_symbols_in_sections): Allow NULL info.
2020-07-28 16:56:14 +09:30
Alan Modra
93fd13c704 Accept --just-symbols symbols as absolute for xcoff
This patch is aimed at curing
    just-symbols-1.o: loader reloc in unrecognized section `*ABS*'
for xcoff by treating symbols defined by --just-symbols objects as
absolute.

	* xcofflink.c (xcoff_need_ldrel_p): Accept --just-symbols symbols and
	similar as absolute.
	(bfd_xcoff_import_symbol): Don't fuss over absolute symbol
	redefinitions here.
2020-07-27 22:31:37 +09:30
Nick Clifton
04f096fb9e Move the xc16x target to the obsolete list 2020-07-24 12:01:48 +01:00
Kevin Buettner
5efb677960 Update binary_get_section_contents to seek using section's file position
I have a patch for GDB which opens and reads from BFDs using the
"binary" target.  However, for it to work, we need to be able to get a
section's contents based from the file position of that section.

At the moment, reading a section's contents will always read from the
start of the file regardless of where that section is located.  While
this was fine for the original use of the "binary" target, it won't
work for my use case.  This change shouldn't impact any existing
callers due to the fact that the single .data section is initialized
with a filepos of 0.

bfd/ChangeLog:

	* binary.c (binary_get_section_contents): Seek using offset
	from section's file position.
2020-07-22 12:42:31 -07:00
Kevin Buettner
ea57e509a2 Remove hack for GDB which sets the section size to 0
This commit removes a hack for GDB which was introduced in 2007.
See:

    https://sourceware.org/ml/binutils/2007-08/msg00044.html

That hack mostly allowed GDB's handling of core files to continue to
work without any changes to GDB.

The problem with setting the section size to zero is that GDB won't
know how big that section is/was.  Often, this doesn't matter because
the data in question are found in the exec file.  But it can happen
that the section describes memory that had been allocated, but never
written to.  In this instance, the contents of that memory region are
not written to the core file.  Also, since the region in question was
dynamically allocated, it won't appear in the exec file.  We don't
want these regions to appear as inaccessible to GDB (since they *were*
accessible when the process was live), so it's important that GDB know
the size of the region.

I've made changes to GDB which correctly handles this case.  When
attempting to access memory, GDB will first consider core file data
for which both SEC_ALLOC and SEC_HAS_CONTENTS is set.  Next, if that
fails, GDB will attempt to find the data in the exec file.  Finally,
if that also fails, GDB will attempt to access memory in the sections
which are flagged as SEC_ALLOC, but not SEC_HAS_CONTENTS.

bfd/ChangeLog:

	* elf.c (_bfd_elf_make_section_from_phdr): Remove hack for GDB.
2020-07-22 12:32:24 -07:00
Max Filippov
1ad2776d3d bfd: xtensa: pr26246: fix removed_literal_compare
2020-07-22  Max Filippov  <jcmvbkbc@gmail.com>
bfd/
	PR 26246
	* elf32-xtensa.c (removed_literal_compare): Use correct pointer
	type for the first function argument. Rename pointers to reflect
	that they have distinct types.
2020-07-22 02:58:34 -07:00
Alan Modra
2f5541f384 PR26265, Spurious 'gc-sections requires ... when --init or --fini
bfd/
	* elflink.c (_bfd_elf_gc_keep): Use bfd_is_const_section.
ld/
	PR 26265
	* ldlang.c (undef_from_cmdline): Delete.
	(ldlang_add_undef): Mark "cmdline" param unused.
	(lang_end): Traverse gc_sym_list to determine whether a symbol root
	has been specified.  Update error message.
	* testsuite/ld-gc/noent.d: Adjust for changed error message.
2020-07-20 22:21:11 +09:30
Alan Modra
e10a07b32d Power10 stub selection
This patch better supports mixing of power10 and non-power10 code,
as might be seen in a cpu-optimized library using ifuncs to select
functions optimized for a given cpu.  Using -Wl,--no-power10-stubs
isn't that good in this situation since non-power10 notoc stubs are
slower and larger than the power10 variants, which you'd like to use
on power10 code paths.

With this change, power10 pc-relative code that makes calls marked
@notoc uses power10 stubs if stubs are necessary, and other calls use
non-power10 instructions in stubs.  This will mean that if gcc is
generating code for -mcpu=power10 but with pc-rel disabled then you'll
get the older stubs even on power10 (unless you force with
-Wl,--power10-stubs).  That shouldn't be too big a problem: stubs that
use r2 are reasonable.  It's just the ones that set up addressing
using "mflr 12; bcl 20,31,.+4; mflr 11; mtlr 12" that should be
avoided if possible.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add has_power10_relocs.
	(select_alt_stub): New function.
	(ppc_get_stub_entry): Use it here.
	(ppc64_elf_check_relocs): Set had_power10_relocs rather than
	power10_stubs.
	(ppc64_elf_size_stubs): Clear power10_stubs here instead.  Don't
	merge notoc stubs with other varieties when power10_stubs is "auto".
	Instead dup the stub hash table entry.
	(plt_stub_size, ppc_build_one_stub, ppc_size_one_stub): Adjust
	tests of power10_stubs.
ld/
	* emultempl/ppc64elf.em (power10-stubs): Accept optional "auto" arg.
	* ld.texi (power10-stubs): Update.
	* testsuite/ld-powerpc/callstub-1.d: Force --power10-stubs.
	* testsuite/ld-powerpc/callstub-2.d: Relax branch offset comparison.
	* testsuite/ld-powerpc/callstub-4.d: New test.
	* testsuite/ld-powerpc/notoc.d: Force --no-power10-stubs.
	* testsuite/ld-powerpc/notoc3.d,
	* testsuite/ld-powerpc/notoc3.s,
	* testsuite/ld-powerpc/notoc3.wf: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.  Pass
	--no-power10-stubs for notoc link.
2020-07-19 12:27:47 +09:30
Alan Modra
28b80303a2 PR26239, memory leak in _bfd_dwarf2_slurp_debug_info
PR 26239
	* coffgen.c (_bfd_coff_close_and_cleanup): Free dwarf2 info.
2020-07-15 19:47:57 +09:30
Nick Clifton
4fd8d58564 Fix an illegal memory access in the BFD library which can be triggered by attempting to parse a corrupt PE format file.
PR26240
	* coffgen.c (coff_get_normalized_symtab): Fix off-by-one error in
	check for aux entries that overflow the buufer.
2020-07-15 11:09:59 +01:00