Commit Graph

9082 Commits

Author SHA1 Message Date
H.J. Lu a57f74bb7c tic6x: Call _bfd_elf_add_dynamic_tags
Update tic6x linker tests to expect C6000_DSBT_BASE, C6000_DSBT_SIZE and
C6000_DSBT_INDEX dynamic tags immediately before NULL dynamic tag.

bfd/

	* elf32-tic6x.c (elf32_tic6x_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.

ld/

	* testsuite/ld-tic6x/shlib-1.rd: Move C6000_DSBT_BASE,
	C6000_DSBT_SIZE and C6000_DSBT_INDEX dynamic tags to the last.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
2020-06-29 05:53:01 -07:00
Alan Modra 07d22f648e asan: _bfd_pei_slurp_codeview_record use of uninit value
Fixes some seriously careless code.  bfd_bread return value is
(bfd_size_type)-1 on error.  "if (bfd_bread (...) < 4)" does not check
for an error since bfd_size_type is unsigned.  In any case, I think we
should be reading and checking the requested length.

	* peXXigen.c (_bfd_XXi_slurp_codeview_record): Properly check
	return value of bfd_bread.  Don't read more than requested length.
	Sanity check length.  Properly terminate file name.
2020-06-29 10:09:14 +09:30
Alan Modra 279edac53d C++ comments
binutils isn't c99 (yet).  This replaces or removes some C++ style
comments.

bfd/
	* arc-got.h: Use C style comments.
	* coff-z80.c: Likewise.
	* elf32-csky.c: Likewise.
	* peXXigen.c: Likewise.
	* elf32-m32c.c (m32c_elf_relax_delete_bytes): Remove commented out
	code.
binutils/
	* dwarf.c: Use C style comments.
	* resrc.c: Likewise.
gas/
	* config/tc-s12z.c: Use C style comments.
	* config/tc-z80.c: Likewise.
	* config/tc-xtensa.c (emit_ld_r_n): Remove commented out code.
include/
	* coff/internal.h: Use C style comments.
	* coff/pe.h: Likewise.
	* elf/ppc64.h: Likewise.
opcodes/
	* arm-dis.c: Use C style comments.
	* cr16-opc.c: Likewise.
	* ft32-dis.c: Likewise.
	* moxie-opc.c: Likewise.
	* tic54x-dis.c: Likewise.
	* s12z-opc.c: Remove useless comment.
	* xgate-dis.c: Likewise.
2020-06-29 10:07:56 +09:30
Pat Bernardi 85f7484a3a m68k: tag floating-point ABI used
This patch adds GNU attribute support to m68k and utilises it to tag the
floating-point calling convention used (hard-float or soft-float). It enables
the linker to ensure linked objects use a consistent floating-point ABI and
allows tools like GDB to infer the ABI used from the ELF file. It is based on
similar work done for PowerPC.

bfd/
	* elf32-m68k.c (m68k_elf_merge_obj_attributes): New function.
	(elf32_m68k_merge_private_bfd_data): Merge GNU attributes.
binutils/
	* readelf.c (display_m68k_gnu_attribute): New function.
	(process_arch_specific): Call display_m68k_gnu_attribute for EM_68K.
gas/
	* config/tc-m68k.c (m68k_elf_gnu_attribute): New function.
	(md_pseudo_table): Handle "gnu_attribute".
	* doc/as.texi: Document GNU attribute for M68K.
include/
	* elf/m68k.h: Add enum for GNU object attribute with floating point
	tag name and values.
ld/
	* testsuite/ld-m68k/attr-gnu-4-0.s: New file.
	* testsuite/ld-m68k/attr-gnu-4-1.s: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-2.s: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-00.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-01.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-02.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-10.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-11.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-12.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-20.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-21.d: Likewise.
	* testsuite/ld-m68k/attr-gnu-4-22.d: Likewise.
	* testsuite/ld-m68k/m68k.exp: Run the new tests.
2020-06-26 14:42:19 +09:30
Alan Modra ba9b3ef5ee RISCV changes broke 32-bit --enable-targets=all
By the look of it, git commit 39ff0b8123 broke 32-bit host
--enable-targets=all binutils builds.

/usr/local/bin/ld: ../opcodes/.libs/libopcodes.a(riscv-dis.o): in function `parse_riscv_dis_option':
/home/alan/src/binutils-gdb/opcodes/riscv-dis.c:102: undefined reference to `riscv_get_priv_spec_class'
collect2: error: ld returned 1 exit status
Makefile:925: recipe for target 'objdump' failed

The problem is that elfxx-riscv.c is not built for a 32-bit host
without --enable-64-bit-bfd or unless RISCV is given specifically as a
target.  No such trimming of 64-bit only targets is done in opcodes.

One solution is to move these support functions to cpu-riscv.c, which
runs into "error: implicit declaration of function ‘xmalloc’".  Now,
xmalloc is not supposed to be used in libbfd or libopcodes - it's rude
to crash out of an application that calls libbfd or libopcodes
functions without giving it a chance to deal with out-of-memory
itself.  So I removed the xmalloc and instead used a fixed size
buffer.  If you are worried about adding 36 bytes for the buffer to
the riscv_get_priv_spec_class_from_numbers stack frame size, then you
have no idea of the likely xmalloc + malloc stack frame size!  Trying
to reduce memory usage is commendable, but in this instance
riscv_estimate_digit and malloc for a temp buffer uses a lot more
memory than a fixed max-size buffer.

	* elfxx-riscv.c (struct priv_spec_t, priv_specs),
	(riscv_get_priv_spec_class, riscv_get_priv_spec_class_from_numbers),
	(riscv_get_priv_spec_name): Move to..
	* cpu-riscv.c: ..here.
	(riscv_get_priv_spec_class_from_numbers): Don't xmalloc temp buffer.
	Use %u to print unsigned numbers.
2020-06-26 10:58:03 +09:30
Andrew Burgess 069057bf0f bfd/riscv: tighten matching rules in riscv_scan
The following GDB behaviour was observed:

  (gdb) x/1i 0x0001014a
     0x1014a <main+8>:	jal	0x10132 <foo>
  (gdb) show architecture
  The target architecture is set automatically (currently riscv:rv32)
  (gdb) set architecture riscv:rv32
  The target architecture is assumed to be riscv:rv32
  (gdb) x/1i 0x0001014a
     0x1014a <main+8>:	0x37e5
  (gdb)

Notice that initially we can disassemble the instruction (it's a
compressed jal instruction), but after setting the architecture we can
no longer disassemble the instruction.

This is particularly puzzling as GDB initially thought the
architecture was 'riscv:rv32', but when we force the architecture to
be that, the disassembly stops working.

This issue was introduced with this commit:

  commit c35d018b1a
  Date:   Mon Jan 27 15:19:30 2020 -0800

      RISC-V: Fix gdbserver problem with handling arch strings.

In this commit we try to make riscv_scan handle cases where we see
architecture strings like 'riscv:rv32imc' (for example).  Normally
this wouldn't match as bfd_default_scan requires an exact match, so we
extended riscv_scan to ignore trailing characters.

Unfortunately the default riscv arch is called 'riscv', is 64-bit,
and has its mach type set to 0, which I think is intended to pair with
code is riscv-dis.c:riscv_disassemble_insn that tries to guess if we
are 32 or 64 bit.

What happens then is that 'riscv:rv32' is first tested against 'riscv'
using bfd_default_scan, this doesn't match, we then compare this to
'riscv', but allowing trailing characters to be ignored, this matches,
and our 'riscv:rv32' matches against the default (64-bit)
architecture.

The solution I propose is to prevent the default architecture from
taking part in this "ignore trailing characters" extra match case,
only the more specific 'riscv:rv32' and 'riscv:rv64' get this extra
matching.

bfd/ChangeLog:

	* cpu-riscv.c (riscv_scan): Don't allow shorter matches using the
	default architecture.
2020-06-24 19:15:07 +01:00
H.J. Lu 2c8e370829 csky: Don't generate unnecessary dynamic tags
Dynamic tags, DT_JMPREL, PLTREL and PLTRELSZ, are needed only if there
are relocation entries for PLT.  Don't generate them if there are no
relocation entries for PLT.

bfd/

	PR ld/26083
	* elf32-csky.c (csky_elf_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.

ld/

	PR ld/26083
	* testsuite/ld-csky/tls-ie-v1.d: Updated.
	* testsuite/ld-csky/tls-ie.d: Likewise.
2020-06-24 06:14:28 -07:00
H.J. Lu c679ec98a1 cris: Don't generate unnecessary dynamic tags
Dynamic tags, DT_JMPREL, PLTREL and PLTRELSZ, are needed only if there
are relocation entries for PLT.  Don't generate them if there are no
relocation entries for PLT.

bfd/

	PR ld/26083
	* elf32-cris.c (elf_cris_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.

ld/

	PR ld/26083
	* testsuite/ld-cris/libdso-15b.d: Updated.
	* testsuite/ld-cris/libdso-1c.d: Likewise.
	* testsuite/ld-cris/libdso-1d.d: Likewise.
	* testsuite/ld-cris/libdso-15c.d: New file.
2020-06-24 04:00:31 -07:00
Alan Modra f8b1e5f6fc ubsan: alpha-vms: shift exponent 536874240 is too large
C_OPR_ASH is supposed to be an arithmetic shift.  By the look of it,
this operator implemented logical shifts since the original binutils
support was added.  This patch corrects that and avoids some nonsense
ubsan complaints.  I chose to implement infinite precision shifts
rather than masking shift counts to the word size as the spec I had is
silent on what is supposed to happen with overlarge shift counts.

	* vms-alpha.c (_bfd_vms_slurp_etir <ETIR__C_OPR_ASH>): Implement
	shifts without undefined behaviour.
2020-06-24 10:48:15 +09:30
H.J. Lu 3084d7a27b ELF: Add _bfd_elf_add_dynamic_tags
All ELF backends with shared library support need to add dynamic tags.
Add dt_pltgot_required and dt_jmprel_required to elf_link_hash_table to
indicate that DT_PLTGOT and DT_JMPREL are required dynamic tags.

1. Add _bfd_elf_add_dynamic_tags to add common dynamic tags.
2. Add _bfd_elf_maybe_vxworks_add_dynamic_tags to add common VxWorks
dynamic tags.

	* elf-bfd.h (elf_link_hash_table): Add dt_pltgot_required and
	dt_jmprel_required.
	(_bfd_elf_add_dynamic_tags): New.
	* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.
	* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
	* elf32-bfin.c (elf32_bfinfdpic_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-frv.c (elf32_frvfdpic_size_dynamic_sections): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-microblaze.c (microblaze_elf_size_dynamic_sections):
	Likewise.
	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections):
	Likewise.
	* elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
	* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
	* elf32-arm.c (elf32_arm_size_dynamic_sections): Call
	_bfd_elf_maybe_vxworks_add_dynamic_tags.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections):
	Likewise.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.
	* elfxx-x86.h (elf_x86_link_hash_table): Remove dt_reloc,
	dt_reloc_sz and dt_reloc_ent.
	* elf-vxworks.c (_bfd_elf_maybe_vxworks_add_dynamic_tags): New.
	* elf-vxworks.h (_bfd_elf_maybe_vxworks_add_dynamic_tags):
	Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_create): Set
	etab.dt_pltgot_required.
	(elf32_hppa_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.
	* elf32-metag.c (elf_metag_link_hash_table_create): Set
	etab.dt_pltgot_required.
	(elf_metag_size_dynamic_sections): Call _bfd_elf_add_dynamic_tags.
	* elf32-sh.c (sh_elf_link_hash_table_create): Set
	root.dt_pltgot_required for FDPIC output.
	(sh_elf_size_dynamic_sections): Call
	_bfd_elf_maybe_vxworks_add_dynamic_tags.
	* elf32-xtensa.c (elf_xtensa_link_hash_table_create): Set
	elf.dt_pltgot_required.
	(elf_xtensa_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.
	* elf64-hppa.c (elf64_hppa_hash_table_create): Set
	root.dt_pltgot_required.
	(elf64_hppa_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.
	* elfnn-ia64.c (elfNN_ia64_hash_table_create): Set
	root.dt_pltgot_required.
	(elfNN_ia64_size_dynamic_sections): Set root.dt_jmprel_required
	for rel_pltoff_sec.  Call _bfd_elf_add_dynamic_tags.
	* elflink.c (_bfd_elf_add_dynamic_tags): New.
2020-06-23 05:07:45 -07:00
Saagar Jha d768f160a9 Recognize some new Mach-O load commands
bfd
	* mach-o.c: Support the new load commands by reading a linkedit data
	command for them.
binutils
	* od-macho.c: Dump linkedit data for new load commands.
include
	* mach-o/loader.h: Add declarations of two new Mach-O load
	commands.
2020-06-22 14:29:20 +01:00
Nelson Chu 39ff0b8123 RISC-V: Report warning when linking the objects with different priv specs.
We do know some conflicts among different privileged specs.  For linker,
the safest approach is that don't allow the object linked with others which
may cause conflicts.  But this may cause inconvenience since not all objects
with conflicting priv specs are linked will cause problems.  But it is hard
to know the detailed conflict cases for linker, so we probably need a option
to tell linker that we do know there are no conflicts, or we are willing to
take risks to link the objects with conflicted priv specs.  But the option
is still under discussion.

Therefore, we can report warnings rather than errors when linking the objects
with conflicted priv specs.  This not only makes the linker more flexible,
but also warns people that the conflicts may happen.  We also need to update
the output priv spec version once the input priv spec is newer.

	bfd/
	* elfxx-riscv.c (struct priv_spec_t priv_specs[]): Move them from
	opcodes/riscv-opc.c to bfd/elfxx-riscv.c, since we need it in linker.
	(riscv_get_priv_spec_class): Likewise.
	(riscv_get_priv_spec_name): Likewise.
	(riscv_get_priv_spec_class_from_numbers): New function, convert
	the version numbers into string, then call riscv_get_priv_spec_class
	to get the priv spec class.
	* elfxx-riscv.h (riscv_get_priv_spec_class): Move forward declaration
	from include/opcode/riscv.h to bfd/elfxx-riscv.h.
	(riscv_get_priv_spec_name): Likewise.
	(riscv_get_priv_spec_class_from_numbers): New forward declaration.
	(opcode/riscv.h): Include it in the header rather than elfxx-riscv.c.
	* elfnn-riscv.c (riscv_merge_attributes):  Get the priv spec classes
	of input and output objects form their priv spec attributes by
	riscv_get_priv_spec_class_from_numbers.  Report warning rather than
	errors when linking objects with differnet priv spec versions.  We do
	know v1.9.1 may have conflicts to other versions, so report the
	warning, too.  After that, update the output priv spec version to the
	newest one so far.

	gas/
	* config/tc-riscv.c (buf_size, buf): Remove the unused variables.
	(riscv_set_default_priv_spec): Get the priv spec version from the
	priv spec attributes by riscv_get_priv_spec_class_from_numbers.

	include/
	* opcode/riscv.h (riscv_get_priv_spec_class): Move the function
	forward declarations to bfd/elfxx-riscv.h.
	(riscv_get_priv_spec_name): Likewise.

	opcodes/
	* riscv-opc.c: Move the structures and functions to bfd/elfxx-riscv.c.
	* riscv-dis.c: Include elfxx-riscv.h.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Updated.
2020-06-22 10:01:14 +08:00
Nelson Chu cbd7581f34 RISC-V: Don't assume the priv attributes are in order when handling them.
There is no guarantee that the priv attributes should be defined in order.
Therefore, we shouldn't have the order assumption when handling them in the
riscv_merge_attributes.  Set priv_attrs_merged to TRUE if we have handled
all of the priv attributes.

	bfd/
	* elfnn-riscv.c (riscv_merge_attributes): Once we meet one of the
	priv attributes, we will check the conflicts for all of them (major,
	minor and revision), and then set the priv_attrs_merged to TRUE to
	indicate that we have handled all of the priv attributes.  Remove
	the unused boolean priv_may_conflict, in_priv_zero and out_priv_zero.
2020-06-22 09:54:02 +08:00
Alan Modra 1e92785005 PR26132, ar creates invalid libraries for some targets with plugins enabled
PR 26132
	* configure.ac: Disable plugins by default for some targets.
	* plugin.c: Comment typo fix.
	* configure: Regenerate.
2020-06-21 22:16:59 +09:30
Nick Clifton 13aa5ceb01 Silence warnings about incompatible plugins.
I have been looking at a Fedora bug report[1] from a user who was
receiving warning messages from the BFD library about incompatible
plugins.  It turns out that they had both 32-bit and 64-bit versions
of the same plugin installed, and the BFD library was attempting to
load all of them.

After thinking about it for a while, it seemed to me that the simplest
solution was to not warn about incompatible plugins whilst attempting
to create a list of viable plugins.

[1]: https://bugzilla.redhat.com/show_bug.cgi?id=1836618

	* plugin.c (try_load_plugin): Suppress the error message about
	being unable to open a plugin if creating a list of viable
	plugins.
2020-06-19 10:25:43 +01:00
Alan Modra a435742a7f Really remove tic30-aout support
bfd/
	* aout-tic30.c: Delete file.
	* Makefile.am (BFD32_BACKENDS): Remove aout-tic30.lo.
	(BFD32_BACKENDS_CFILES): Remove aout-tic30.c.
	* config.bfd (c30-*-*aout*, tic30-*-*aout*): Remove entry.
	(xc16x-*-elf): Sort properly.
	* configure.ac: Remove tic30_aout_vec.
	* targets.c: Likewise.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
gas/
	* config/tc-tic30.h: Remove OBJ_AOUT support.
	* configure.tgt: Delete tic30-*-*aout* entry.
ld/
	* emulparams/tic30aout.sh: Delete file.
	* scripttempl/tic30aout.sc: Delete file.
	* Makefile.am: Remove etic30aout.c from ALL_EMULATION_SOURCES and
	delete dependency.
	* configure.tgt: Delete tic30-*-*aout* entry.
	* testsuite/ld-scripts/sane1.d: Delete tic30-*-aout mention.
	* testsuite/ld-scripts/segment-start.d: Likewise.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
2020-06-16 15:57:59 +09:30
Max Filippov 7a77f1ac2c xtensa: allow runtime ABI selection
2020-06-15  Max Filippov  <jcmvbkbc@gmail.com>
bfd/
	* elf32-xtensa.c (XSHAL_ABI, XTHAL_ABI_UNDEFINED)
	(XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): New macros.
	(elf32xtensa_abi): New global variable.
	(xtensa_abi_choice): New function.
	(elf_xtensa_create_plt_entry): Use xtensa_abi_choice instead of
	XSHAL_ABI to select PLT code.

gas/
	* config/tc-xtensa.c (XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): New
	macros.
	(elf32xtensa_abi): New declaration.
	(option_abi_windowed, option_abi_call0): New enum constants.
	(md_longopts): Add entries for --abi-windowed and --abi-call0.
	(md_parse_option): Add handlers for --abi-windowed and
	--abi-call0.
	(xtensa_add_config_info): Use xtensa_abi_choice instead of
	XSHAL_ABI to format ABI tag.
	* doc/as.texi (Target Xtensa options): Add --abi-windowed and
	--abi-call0 to the list of options.
	* doc/c-xtensa.texi: Add description for options --abi-windowed
	and --abi-call0.
	* testsuite/gas/xtensa/abi-call0.d: New test definition.
	* testsuite/gas/xtensa/abi-windowed.d: New test definition.
	* testsuite/gas/xtensa/abi.s: New test source.

include/
	* elf/xtensa.h (xtensa_abi_choice): New declaration.

ld/
	* emultempl/xtensaelf.em (XSHAL_ABI): Remove macro definition.
	(XTHAL_ABI_UNDEFINED, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): New
	macros.
	(elf32xtensa_abi): New declaration.
	(xt_config_info_unpack_and_check): Set elf32xtensa_abi if it is
	undefined.  Use xtensa_abi_choice instead of XSHAL_ABI to test
	ABI tag consistency.
	(xtensa_add_config_info): Use xtensa_abi_choice instead of
	XSHAL_ABI to format ABI tag.
	(PARSE_AND_LIST_PROLOGUE): Define OPTION_ABI_WINDOWED,
	OPTION_ABI_CALL0 and declare elf32xtensa_abi.
	(PARSE_AND_LIST_LONGOPTS): Add entries for --abi-windowed and
	--abi-call0.
	(PARSE_AND_LIST_OPTIONS): Add help text for --abi-windowed and
	--abi-call0.
	(PARSE_AND_LIST_ARGS_CASES): Add handlers for --abi-windowed and
	--abi-call0.
	* ld.texi: Add description for options --abi-windowed and
	--abi-call0.
2020-06-15 13:01:30 -07:00
Roland McGrath cae64165f4 gold, ld: Implement -z start-stop-visibility=... option.
gold/
	Implement -z start-stop-visibility=... option.
	* options.h (class General_options): Handle -z start-stop-visibility=.
	(General_options::start_stop_visibility_enum): New public method.
	(General_options::set_start_stop_visibility_enum): New private method.
	(General_options::start_stop_visibility_enum_): New private member.
	* options.cc (General_options::General_options): Add initializer.
	(General_options::finalize): Set this->start_stop_visibility_enum_
	from string value.
	* layout.cc (Layout::define_section_symbols): Use option setting.

bfd/
	* elflink.c (bfd_elf_define_start_stop): Use start_stop_visibility
	field of bfd_link_info.

include/
	* bfdlink.h (struct bfd_link_info): New field start_stop_visibility.

ld/
	* NEWS: Mention -z start-stop-visibility=... option for ELF.
	* ld.texi (Options): Document -z start-stop-visibility=... option.
	* ldmain.c (main): Initialize link_info.start_stop_visibility.
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
	Parse -z start-stop-visibility=... option.
2020-06-15 11:45:02 -07:00
Alan Modra 40be168cc4 Obsolete PowerPC PE, winnt and cygwin targets
The PowerPC PE support is so old and bitrotted that it ought to be
removed.  Test results for a cross from x86_64 with no C cross
compiler currently shows 109 fails.  I don't think anyone cares about
the target.

This FIXME in bfd/peXXigen.c has been around since 1999, git commit
277d1b5e453:

/* FIXME: This file has various tests of POWERPC_LE_PE.  Those tests
   worked when the code was in peicode.h, but no longer work now that
   the code is in peigen.c.  PowerPC NT is said to be dead.  If
   anybody wants to revive the code, you will have to figure out how
   to handle those issues.  */

and this one in gas/config/tc-ppc.c since 1995, git commit
cd557d83d61:

 * FIXME: I just noticed this. This doesn't work at all really. It it
 *        setting bits that bfd probably neither understands or uses. The
 *        correct approach (?) will have to incorporate extra fields attached
 *        to the section to hold the system specific stuff. (krk)

	* config.bfd: Obsolete powerpcle-*-pe targets.
2020-06-15 15:09:38 +09:30
Alan Modra 75cfe082c0 PR26103, Assertion failure with symbols defined in link-once sections
PR 26103
	* elflink.c (elf_link_add_archive_symbols): Exclude undefined
	symbols that were defined in discarded sections.
	* cofflink.c (coff_link_check_archive_element): Likewise.
	(coff_link_add_symbols): Set indx to -3 for symbols defined in
	discarded sections.
	(_bfd_coff_write_global_sym): Don't emit such symbols.
	libcoff-in.h (struct coff_link_hash_entry): Update indx comment.
	libcoff.h: Regenerate.
2020-06-15 12:10:06 +09:30
Alan Modra f0aa30258a PR26107, Compilation failure in pdp11.c
PR 26107
	* pdp11.c (is_stab): Replace legacy "index" function with "strchr".
2020-06-11 15:50:33 +09:30
H.J. Lu 447f6d8627 ia64: Set DF_TEXTREL instead of reltext
Update ia64 ELF backend to set DF_TEXTREL for dynamic relocs against
readonly sections like other backends.

	* elfnn-ia64.c (elfNN_ia64_link_hash_table): Remove reltext.
	(allocate_dynrel_entries): Set DF_TEXTREL instead of reltext.
	(elfNN_ia64_size_dynamic_sections): Check DF_TEXTREL instead
	of reltext.
2020-06-10 18:20:36 -07:00
H.J. Lu e1b5d517d1 ELF: Properly handle section symbols
When defining the section symbol, __start_FOO, for the section FOO:

1. Treat the common symbol, __start_FOO, in input object file as
definition.
2. Clear verinfo.verdef.

bfd/

	PR ld/26094
	* elflink.c (bfd_elf_define_start_stop): Handle common symbols.
	Clear verinfo.verdef.

ld/

	PR ld/26094
	* testsuite/ld-elf/pr26094-1.ver: New fike.
	* testsuite/ld-elf/pr26094-1a.c: Likewise.
	* testsuite/ld-elf/pr26094-1a.rd: Likewise.
	* testsuite/ld-elf/pr26094-1b.c: Likewise.
	* testsuite/ld-elf/pr26094-1b.rd: Likewise.
	* testsuite/ld-elf/pr26094-1c.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run ld/26094 tests.
2020-06-10 05:31:31 -07:00
H.J. Lu cebd6b8ac1 IFUNC: Update IFUNC resolver check with DT_TEXTREL
Add ifunc_resolvers to elf_link_hash_table and use it for both x86 and
ppc64.  Before glibc commit b5c45e837, DT_TEXTREL is incompatible with
IFUNC resolvers.  Set ifunc_resolvers if there are IFUNC resolvers and
issue a warning for IFUNC resolvers with DT_TEXTREL.

bfd/

	PR ld/18801
	* elf-bfd.h (elf_link_hash_table): Add ifunc_resolvers.
	(_bfd_elf_allocate_ifunc_dyn_relocs): Remove the
	bfd_boolean * argument.  Set ifunc_resolvers if there are IFUNC
	resolvers.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Updated.
	Set ifunc_resolvers if there are FUNC resolvers.
	* elf64-ppc.c (ppc_link_hash_table): Remove local_ifunc_resolver.
	(build_global_entry_stubs_and_plt): Replace local_ifunc_resolver
	with elf.ifunc_resolvers.
	(write_plt_relocs_for_local_syms): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	(ppc64_elf_finish_dynamic_sections): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Updated.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
	(_bfd_x86_elf_size_dynamic_sections): Check elf.ifunc_resolvers
	instead of readonly_dynrelocs_against_ifunc.
	* elfxx-x86.h (elf_x86_link_hash_table): Remove
	readonly_dynrelocs_against_ifunc.

ld/

	PR ld/18801
	* testsuite/ld-i386/i386.exp: Run ifunc-textrel-1a,
	ifunc-textrel-1b, ifunc-textrel-2a and ifunc-textrel-2b.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/ifunc-textrel-1a.d: Likewise.
	* testsuite/ld-i386/ifunc-textrel-1b.d: Likewise.
	* testsuite/ld-i386/ifunc-textrel-2a.d: Likewise.
	* testsuite/ld-i386/ifunc-textrel-2b.d: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-1.s: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-1a.d: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-1b.d: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-2.s: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-2a.d: Likewise.
	* testsuite/ld-x86-64/ifunc-textrel-2b.d: Likewise.
	* testsuite/ld-i386/pr18801a.d: Expect warning for IFUNC
	resolvers.
	* testsuite/ld-i386/pr18801b.d: Likewise.
	* estsuite/ld-x86-64/pr18801a.d: Likewise.
	* estsuite/ld-x86-64/pr18801b.d: Likewise.
2020-06-09 06:57:25 -07:00
Alan Modra efb2a7b412 PowerPC64: Downgrade ifunc with textrel error to a warning
For ppc64 I set flags when recording the dynamic relocation rather
than when allocating space.  That allows you to distinguish three
cases:
1) The dynamic ifunc relocation is in an executable and will always be
   to an ifunc resolver in the executable.
2) The dynamic ifunc relocation is in a shared library which provides
   an ifunc resolver, but that may be overridden at runtime to use a
   resolver in another binary.
3) The dynamic ifunc relocation is not to a locally defined ifunc
   resolver.

Case (3) won't cause a segfault trying to run resolver code that is
non-exec on older glibc.

I made case (1) an error for ppc64, but since newer glibc ld.so does
allow running ifunc resolvers when segments are writable I suppose I
should downgrade that to a warning like case (2).

	* elf64-ppc.c (struct ppc_link_hash_table): Delete
	maybe_local_ifunc_resolver field.
	(build_global_entry_stubs_and_plt): Set local_ifunc_resolver in
	cases where maybe_local_ifunc_resolver was set.
	(ppc64_elf_relocate_section): Likewise.
	(ppc64_elf_finish_dynamic_sections): Downgrade ifunc with textrel
	error to a warning.
2020-06-09 09:37:23 +09:30
H.J. Lu 9bcc30e417 ELF: Move tlsdesc_plt/tlsdesc_got to elf_link_hash_table
All ELF backends with TLS descriptor support have

  /* The offset into splt of the PLT entry for the TLS descriptor
     resolver.  Special values are 0, if not necessary (or not found
     to be necessary yet), and -1 if needed but not determined
     yet.  */
  bfd_vma tlsdesc_plt;

  /* The GOT offset for the lazy trampoline.  Communicated to the
     loader via DT_TLSDESC_GOT.  The magic value (bfd_vma) -1
     indicates an offset is not allocated.  */
  bfd_vma tlsdesc_got;

in symbol hash entry.  Move tlsdesc_plt/tlsdesc_got to elf_link_hash_entry
to reduce code duplication.

	* elf-bfd.h (elf_link_hash_entry): Add tlsdesc_plt and
	tlsdesc_got.
	* elf32-arm.c (elf32_arm_link_hash_table): Remove tlsdesc_plt
	and dt_tlsdesc_got.
	(elf32_arm_size_dynamic_sections): Updated.  Clear
	root.tlsdesc_plt for DF_BIND_NOW.
	(elf32_arm_finish_dynamic_sections): Updated.
	(elf32_arm_output_arch_local_syms): Likewise.
	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Updated.
	Clear root.tlsdesc_plt for DF_BIND_NOW.
	(nds32_elf_finish_dynamic_sections): Updated.
	* elf32-nds32.h (elf_nds32_link_hash_table): Remove
	dt_tlsdesc_plt and dt_tlsdesc_got.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Updated.
	* elfnn-aarch64.c (elf_aarch64_link_hash_table): Remove
	tlsdesc_plt and dt_tlsdesc_got.
	(elfNN_aarch64_allocate_dynrelocs): Updated.
	(elfNN_aarch64_finish_dynamic_sections): Likewise.
	(elfNN_aarch64_size_dynamic_sections): Updated.  Clear
	root.tlsdesc_plt for DF_BIND_NOW.  Don't check DF_BIND_NOW
	twice.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Updated.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.
	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
	* elfxx-x86.h (elf_x86_link_hash_table): Remove tlsdesc_plt and
	tlsdesc_got.
2020-06-08 04:30:56 -07:00
H.J. Lu 845b83d7eb elf32-tic6x.c: Define the default elf32_bed to elf32_tic6x_bed
Get

00000000000007c0 d elf32_tic6x_bed
0000000000000000 d elf32_tic6x_elf_bed
00000000000003e0 d elf32_tic6x_linux_bed

instead of

00000000000007c0 d elf32_bed
0000000000000000 d elf32_tic6x_elf_bed
00000000000003e0 d elf32_tic6x_linux_bed

	* elf32-tic6x.c (elf32_bed): Defined the default to
	elf32_tic6x_bed.
2020-06-07 14:53:58 -07:00
H.J. Lu 9b8a8575b4 elf64-hppa: Replace plt_sec/plt_rel_sec with root.splt/root.srelplt
elf64-hppa should use root.splt and root.srelplt instead of plt_sec and
plt_rel_sec so that elflink.c can see splt and srelplt.  This fixed:

FAIL: ld-elf/pr19539

	* elf64-hppa.c (elf64_hppa_link_hash_table): Remove plt_sec and
	plt_rel_sec.
	(elf64_hppa_check_relocs): Replace plt_sec/plt_rel_sec with
	root.splt/root.srelplt.
	(elf64_hppa_create_dynamic_sections): Likewise.
	(elf64_hppa_size_dynamic_sections): Likewise.
	(elf64_hppa_finish_dynamic_symbol): Likewise.
	(elf_hppa_final_link): Likewise.
	(elf_hppa_final_link_relocate): Likewise.
2020-06-07 08:06:22 -07:00
H.J. Lu bcab203d31 Remove is_vxworks from _bfd_sparc_elf_link_hash_table
Replace is_vxworks with elf.target_os == is_vxworks.

	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Updated.
	* elfxx-sparc.h (_bfd_sparc_elf_link_hash_table): Remove
	is_vxworks.
2020-06-06 17:42:31 -07:00
H.J. Lu 90c14f0c3a ELF: Add target_os to elf_link_hash_table/elf_backend_data
Add target_os to elf_backend_data to identify target OS.  Add target_os,
to elf_link_hash_table to identify target OS for linker output.

	* elf-bfd.h (elf_target_os): New.
	(elf_link_hash_table): Add target_os.
	(elf_backend_data): Add target_os.
	* elf32-arm.c (elf32_arm_link_hash_table): Remove vxworks_p,
	symbian_p and nacl_p.
	(create_got_section): Updated.
	(elf32_arm_create_dynamic_sections): Likewise.
	(arm_type_of_stub): Likewise.
	(elf32_arm_create_or_find_stub_sec): Likewise.
	(elf32_arm_allocate_plt_entry): Likewise.
	(elf32_arm_populate_plt_entry): Likewise.
	(elf32_arm_final_link_relocate): Likewise.
	(elf32_arm_check_relocs): Likewise.
	(allocate_dynrelocs_for_symbol): Likewise.
	(elf32_arm_finish_dynamic_symbol): Likewise.
	(elf32_arm_finish_dynamic_sections): Likewise.
	(elf32_arm_output_plt_map_1): Likewise.
	(elf32_arm_output_arch_local_syms): Likewise.
	(elf32_arm_add_symbol_hook): Likewise.
	(elf32_arm_nacl_link_hash_table_create): Likewise.
	(elf32_arm_vxworks_link_hash_table_create): Likewise.
	(elf32_arm_symbian_link_hash_table_create): Likewise.
	(ELF_TARGET_OS): New.
	* elf32-i386.c (elf_i386_arch_bed): Removed.
	(elf_backend_arch_data): Likewise.
	(elf_i386_solaris_arch_bed): Likewise.
	(elf_i386_nacl_arch_bed): Likewise.
	(elf_i386_vxworks_arch_bed): Likewise.
	(elf_i386_relocate_section): Updated.
	(elf_i386_finish_dynamic_sections): Likewise.
	(elf_i386_get_synthetic_symtab): Likewise.
	(elf_i386_link_setup_gnu_properties): Likewise.
	(ELF_TARGET_OS): New.
	* elf32-mips.c (ELF_TARGET_OS): New.
	* elf32-ppc.c (ppc_elf_link_hash_table): Remove is_vxworks.
	(ppc_elf_create_got): Updated.
	(ppc_elf_create_dynamic_sections): Likewise.
	(ppc_elf_check_relocs): Likewise.
	(ppc_elf_adjust_dynamic_symbol): Likewise.
	(ppc_elf_size_dynamic_sections): Likewise.
	(ppc_elf_relocate_section): Likewise.
	(ppc_elf_finish_dynamic_sections): Likewise.
	(ppc_elf_vxworks_link_hash_table_create): Likewise.
	(ELF_TARGET_OS): New.
	* elf32-sh.c (elf_sh_link_hash_table): Remove vxworks_p.
	(sh_elf_link_hash_table_create): Updated.
	(sh_elf_create_dynamic_sections): Likewise.
	(allocate_dynrelocs): Likewise.
	(sh_elf_size_dynamic_sections): Likewise.
	(sh_elf_relocate_section): Likewise.
	(sh_elf_finish_dynamic_symbol): Likewise.
	(sh_elf_finish_dynamic_sections): Likewise.
	(ELF_TARGET_OS): New.
	* elf32-sparc.c (elf32_sparc_vxworks_link_hash_table_create):
	Removed.
	(bfd_elf32_bfd_link_hash_table_create): Likewise.
	(ELF_TARGET_OS): New.
	* elf64-x86-64.c (elf_x86_64_arch_bed): Removed.
	(elf_x86_64_solaris_arch_bed): Likewise.
	(elf_x86_64_nacl_arch_bed): Likewise.
	(elf_x86_64_finish_dynamic_sections): Updated.
	(elf_x86_64_get_synthetic_symtab): Likewise.
	(elf_x86_64_link_setup_gnu_properties): Likewise.
	(ELF_TARGET_OS): New.
	* elflink.c (_bfd_elf_link_hash_table_init): Initialize
	target_o.
	* elfxx-mips.c (mips_elf_link_hash_table): Remove is_vxworks.
	(MIPS_ELF_REL_DYN_NAME): Updated.
	(ELF_MIPS_GP_OFFSET): Likewise.
	(mips_elf_create_local_got_entry): Likewise.
	(mips_elf_allocate_dynamic_relocations): Likewise.
	(mips_elf_count_got_symbols): Likewise.
	(is_gott_symbol): Likewise.
	(mips_elf_calculate_relocation): Likewise.
	(mips_elf_create_dynamic_relocation): Likewise.
	(_bfd_mips_elf_check_relocs): Likewise.
	(allocate_dynrelocs): Likewise.
	(_bfd_mips_elf_adjust_dynamic_symbol): Likewise.
	(mips_elf_lay_out_got): Likewise.
	(mips_elf_set_plt_sym_value): Likewise.
	(_bfd_mips_elf_size_dynamic_sections): Likewise.
	(_bfd_mips_elf_finish_dynamic_symbol): Likewise.
	(_bfd_mips_elf_finish_dynamic_sections): Likewise.
	(_bfd_mips_elf_final_link): Likewise.
	(_bfd_mips_init_file_header): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_create_dynamic_sections):
	Likewise.
	(allocate_dynrelocs): Likewise.
	(_bfd_sparc_elf_size_dynamic_sections): Likewise.
	(_bfd_sparc_elf_relocate_section): Likewise.
	(_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
	(sparc_finish_dyn): Likewise.
	(_bfd_sparc_elf_finish_dynamic_sections): Likewise.
	* elfxx-target.h (ELF_TARGET_OS): New.
	(elfNN_bed): Add ELF_TARGET_OS.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Updated.
	(_bfd_x86_elf_link_hash_table_create): Likewise.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.
	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
	(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.
	(_bfd_x86_elf_link_setup_gnu_properties): Likewise.
	* elfxx-x86.h (elf_x86_target_os): Removed.
	(elf_x86_backend_data): Likewise.
	(get_elf_x86_backend_data): Likewise.
	(elf_x86_link_hash_table): Remove target_os.
2020-06-06 06:45:38 -07:00
Alan Modra 87c69f9732 Rename PowerPC64 pcrel GOT TLS relocations
These relocations should have had REL in their names, to reflect the
fact that they are pc-relative.  Fix that now by adding _PCREL.
I've added some back-compatibility code to support anyone using
.reloc with the old relocations.

include/
	* elf/ppc64.h (elf_ppc64_reloc_type): Rename
	R_PPC64_GOT_TLSGD34 to R_PPC64_GOT_TLSGD_PCREL34,
	R_PPC64_GOT_TLSLD34 to R_PPC64_GOT_TLSLD_PCREL34,
	R_PPC64_GOT_TPREL34 to R_PPC64_GOT_TPREL_PCREL34, and
	R_PPC64_GOT_DTPREL34 to R_PPC64_GOT_DTPREL_PCREL34.
bfd/
	* reloc.c: Rename
	BFD_RELOC_PPC64_GOT_TLSGD34 to BFD_RELOC_PPC64_GOT_TLSGD_PCREL34,
	BFD_RELOC_PPC64_GOT_TLSLD34 to BFD_RELOC_PPC64_GOT_TLSLD_PCREL34,
	BFD_RELOC_PPC64_GOT_TPREL34 to BFD_RELOC_PPC64_GOT_TPREL_PCREL34,
	BFD_RELOC_PPC64_GOT_DTPREL34 to BFD_RELOC_PPC64_GOT_DTPREL_PCREL34.
	* elf64-ppc.c: Update throughout for reloc renaming.
	(ppc64_elf_reloc_name_lookup): Handle old reloc names.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c: Update throughout for reloc renaming.
elfcpp/
	* powerpc.h: Rename
	R_PPC64_GOT_TLSGD34 to R_PPC64_GOT_TLSGD_PCREL34,
	R_PPC64_GOT_TLSLD34 to R_PPC64_GOT_TLSLD_PCREL34,
	R_PPC64_GOT_TPREL34 to R_PPC64_GOT_TPREL_PCREL34, and
	R_PPC64_GOT_DTPREL34 to R_PPC64_GOT_DTPREL_PCREL34.
gold/
	* powerpc.cc: Update throughout for reloc renaming.
2020-06-06 14:44:32 +09:30
H.J. Lu 8a4ba3a142 bfin: Initialize picrel to silence GCC warning 2020-06-05 06:22:56 -07:00
H.J. Lu 981f151804 bfin: Skip non SEC_ALLOC section
* elf32-bfin.c (bfinfdpic_relocate_section): Skip non SEC_ALLOC
	section.
2020-06-05 05:30:25 -07:00
Nick Clifton 9c65eeacd8 Fix a use before initialization bug in the pdp11.c source file.
* pdp11.c (aout_link_add_symbols): Fix use before initialisation
	bug.
2020-06-05 10:08:26 +01:00
Nelson Chu 412857647f RISC-V: The object without priv spec attributes can be linked with any object.
bfd/
	* elfnn-riscv.c (riscv_merge_attributes): Add new boolean
	priv_may_conflict, in_priv_zero and out_priv_zero to decide whether
	the object can be linked according to it's priv attributes.  The object
	without any priv spec attributes can be linked with others.  If the first
	input object doesn't contain any priv attributes, then we need to copy
	the setting from the next input one.  Also report more detailed error
	messages to user.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Rename to
	attr-merge-priv-spec-01.d.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s: Set priv spec
	to 1.11.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s: Empty priv spec
	setting.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: New testcase.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-06-05 12:20:53 +08:00
Stephen Casner a975c88e65 Extend pdp11-aout symbol table format and code for .stab symbols.
* bfd/pdp11.c (pdp11_external_nlist): Repurposed e_unused to e_desc.
(N_STAB, is_stab): Needed new function is_stab to disambiguate
normal vs. .stab symbol table type values, replacing N_STAB mask.
(translate_from_native_sym_flags): Determine correct section for
different .stab types.
(translate_to_native_sym_flags): Leave .stab types intact.
(translate_symbol_table): Error if symbol indicates overlay;
store desc field from .stab symbols.
(write_syms): Output desc field with symbol.
(aout_link_check_ar_symbols): Skip .stab symbols.
(aout_link_add_symbols): Correctly distinguish .stab symbols.
(aout_link_write_other_symbol): Write 0 for desk and ovly fields.
(aout_link_write_symbols): Write 0 for desk and ovly fields;
correctly distinguish .stab symbols and select calculate their
section and value; and copy desc and ovly fields from input symbol
to output symbol.
2020-06-04 18:12:32 -07:00
Stephen Casner 3b9313c420 Correct a comment.
* bfd/aoutx.h (translate_symbol_table): Comment had external and
internal swapped.
* bfd/pdp11.c (translate_symbol_table): Likewise.
2020-06-04 12:34:17 -07:00
H.J. Lu add5f777de x86: Remove target_id from elf_x86_link_hash_table
Since target_id in elf_x86_link_hash_table is the same as hash_table_id
in elf_link_hash_table, we can use elf.hash_table_id instead of target_id.

	* elfxx-x86.h (elf_x86_link_hash_table): Remove target_id.
	(is_x86_elf): Check elf.hash_table_id instead of target_id.
	* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Updated.
2020-06-04 09:56:25 -07:00
H.J. Lu c4b126b87a ELF: Don't check relocations in non-loaded, non-alloced sections
Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

Since check_relocs is no longer called on non-loaded, non-alloced
sections, remove SEC_ALLOC check.  Resolve relocation in debug section
against symbol defined in shared library to 0.

bfd/

	PR ld/26080
	* elf-m10300.c (mn10300_elf_relocate_section): Resolve relocation
	in debug section against symbol defined in shared library to 0.
	* elf32-i386.c (elf_i386_check_relocs): Remove SEC_ALLOC check.
	* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-nds32.c (nds32_elf_check_relocs): Likewise.
	* elf32-nios2.c (nios2_elf32_check_relocs): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Set non_got_ref for non-GOT
	reference.
	(elf_vax_adjust_dynamic_symbol): Generate a copy reloc only if
	there is non-GOT reference.
	* elflink.c (_bfd_elf_link_check_relocs): Skip non-loaded,
	non-alloced sections.

ld/

	PR ld/26080
	* testsuite/ld-elf/comm-data.exp: Remove copy_reloc.
	* testsuite/ld-elf/comm-data2r.rd: Removed.
	* testsuite/ld-elf/comm-data2r.sd: Likewise.
	* testsuite/ld-elf/comm-data2r.xd: Likewise.
2020-06-04 05:58:47 -07:00
Alan Modra 7eea15c514 Correct PR number in changelog 2020-06-04 10:20:48 +09:30
Stephen Casner 31af1e68af Copy several years of fixes from bfd/aoutx.h to bfd/pdp11.c.
* pdp11.c (some_aout_object_p): 4c1534c7a2 - Don't set EXEC_P for
files with relocs.
(aout_get_external_symbols): 6b8f0fd579 - Return if count is zero.
0301ce1486 PR 22306 - Handle stringsize of zero, and error for any
other size that doesn't qcover the header word.
bf82069dce PR 23056 - Allocate an extra byte at the end of the
string table, and zero it.
(translate_symbol_table): 0d329c0a83 PR 22887 - Print an error
message and set bfd_error on finding an invalid name string offset.
(add_to_stringtab): INLINE -> inline
(pdp11_aout_swap_reloc_in): 116acb2c26 PR 22887 - Correct r_index
bound check.
(squirt_out_relocs): e2996cc315 PR 20921 - Check for and report
any relocs that could not be recognised.
92744f0580 PR 20929 - Check for relocs	without an associated symbol.
(find_nearest_line):  808346fcfc PR 23055 - Check that the symbol
name exists and is long enough, before attempting to see if it is
for a .o file.
c386442122 - Correct case for N_SO being the last symbol.
50455f1ab2 PR 20891 - Handle the case where the main file name
and the directory name are both empty.
e82ab856bb PR 20892 - Handle the case where function name is empty.
(aout_link_add_symbols): e517df3dbf PR 19629 - Check for out of
range string table offsets.
531336e3a0 PR 20909 - Fix off-by-one error in check for an
illegal string offset.
(aout_link_includes_newfunc): Add comment.
(pdp11_aout_link_input_section): ad756e3f9e - Return with an error
on unexpected relocation type rather than ASSERT.
2020-06-03 17:43:45 -07:00
H.J. Lu d4d8aee345 nios2: Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL
Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL by scanning dynamic
relocations in read-only section.

	PR ld/26066
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Call
	_bfd_elf_maybe_set_textrel to set DF_TEXTREL.
2020-06-03 09:25:51 -07:00
H.J. Lu 58ee44efbc nios2: Don't check relocations in non-loaded, non-alloced sections
Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

	PR ld/26066
	* elf32-nios2.c (nios2_elf32_check_relocs): Skip non-loaded,
	non-alloced sections.
2020-06-03 09:21:14 -07:00
H.J. Lu 9a6896021d frv: Don't generate dynamic relocation for non SEC_ALLOC sections
Don't generate dynamic relocations for non SEC_ALLOC sections because
run-time loader won't process them.

	* elf32-frv.c (elf32_frv_relocate_section): Don't generate
	dynamic relocations for non SEC_ALLOC sections.
2020-06-03 09:12:53 -07:00
H.J. Lu 50d036364f arc: Don't generate dynamic relocation for non SEC_ALLOC sections
Don't generate dynamic relocations for non SEC_ALLOC sections because
run-time loader won't process them.

	* elf32-arc.c (elf_arc_relocate_section): Don't generate dynamic
	relocations for non SEC_ALLOC sections.
2020-06-03 09:10:03 -07:00
Gunther Nikl 0bff75284e This patch set for the generic BFD a.out backend removes a dead #define and makes aoutx.h self-contained: [PATCH 1/2]: bfd: remove unused NO_WRITE_HEADER_KLUDGE #define [PATCH 2/2]: bfd: make aoutx.h self-contained
* aout64.c (BMAGIC, QMAGIC): Do not define.
	* aoutx.h (N_IS_BMAGIC, N_SET_QMAGIC): New defines.
	(NAME (aout, some_aout_object_p)): Use N_IS_QMAGIC and N_IS_BMAGIC
	to check the file format.
	(adjust_z_magic): Use N_SET_QMAGIC to set file format.
	* i386aout.c (NO_WRITE_HEADER_KLUDGE): Delete define.
	* libaout.h (NO_WRITE_HEADER_KLUDGE): Do not define.
2020-06-03 15:24:58 +01:00
H.J. Lu d49e5065ed ELF: Consolidate maybe_set_textrel
All maybe_set_textrel implementations are the same.  Consolidate them
to a single _bfd_elf_maybe_set_textrel.

	* elf-bfd.h (_bfd_elf_maybe_set_textrel): New
	* elf32-arm.c (maybe_set_textrel): Removed.
	(elf32_arm_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-csky.c (maybe_set_textrel): Removed.
	(csky_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-hppa.c (maybe_set_textrel): Removed.
	(elf32_hppa_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-lm32.c (maybe_set_textrel): Removed.
	(lm32_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-m32r.c (maybe_set_textrel): Removed.
	(m32r_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-metag.c (maybe_set_textrel): Removed.
	(elf_metag_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-nds32.c (maybe_set_textrel): Removed.
	(nds32_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-or1k.c (maybe_set_textrel): Removed.
	(or1k_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-ppc.c (maybe_set_textrel): Removed.
	(ppc_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-s390.c (maybe_set_textrel): Removed.
	(elf_s390_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-sh.c (maybe_set_textrel): Removed.
	(sh_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-tic6x.c (maybe_set_textrel): Removed.
	(elf32_tic6x_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf32-tilepro.c (maybe_set_textrel): Removed.
	(tilepro_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf64-ppc.c (maybe_set_textrel): Removed.
	(ppc64_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elf64-s390.c (maybe_set_textrel): Removed.
	(elf_s390_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elfnn-aarch64.c (maybe_set_textrel): Removed.
	(elfNN_aarch64_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elfnn-riscv.c (maybe_set_textrel): Removed.
	(riscv_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elfxx-sparc.c (maybe_set_textrel): Removed.
	(_bfd_sparc_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elfxx-tilegx.c (maybe_set_textrel): Removed.
	(tilegx_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elfxx-x86.c (maybe_set_textrel): Removed.
	(_bfd_x86_elf_size_dynamic_sections): Replace maybe_set_textrel
	with _bfd_elf_maybe_set_textrel.
	* elflink.c (_bfd_elf_maybe_set_textrel): New.
2020-06-03 07:07:24 -07:00
H.J. Lu ad172eaa4f ELF: Copy dyn_relocs in _bfd_elf_link_hash_copy_indirect
Copy dyn_relocs in _bfd_elf_link_hash_copy_indirect instead of in each
target backend.

	PR ld/26067
	* elf32-arm.c (elf32_arm_copy_indirect_symbol): Don't copy
	dyn_relocs.
	* elf32-csky.c (csky_elf_copy_indirect_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Likewise.
	* elf32-metag.c (elf_metag_copy_indirect_symbol): Likewise.
	* elf32-microblaze.c (microblaze_elf_copy_indirect_symbol):
	Likewise.
	* elf32-nds32.c (nds32_elf_copy_indirect_symbol): Likewise.
	* elf32-nios2.c (nios2_elf32_copy_indirect_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_copy_indirect_symbol): Likewise.
	* elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
	* elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_copy_indirect_symbol): Likewise.
	* elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_copy_indirect_symbol): Likewise.
	* elfnn-riscv.c (riscv_elf_copy_indirect_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_copy_indirect_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_copy_indirect_symbol): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_copy_indirect_symbol): Likewise.
	* elf32-lm32.c (lm32_elf_copy_indirect_symbol): Removed.
	(elf_backend_copy_indirect_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_copy_indirect_symbol): Removed.
	(elf_backend_copy_indirect_symbol): Likewise.
	* elflink.c (_bfd_elf_link_hash_copy_indirect): Copy dyn_relocs.
2020-06-03 07:03:59 -07:00
H.J. Lu 5dbc8b372f ELF: Consolidate readonly_dynrelocs
All readonly_dynrelocs implementations are the same.  Consolidate them
to a single _bfd_elf_readonly_dynrelocs.

	PR ld/26067
	* elf-bfd.h (_bfd_elf_readonly_dynrelocs): New.
	* elf32-arm.c (readonly_dynrelocs): Removed.
	(maybe_set_textrel): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	* elf32-csky.c (readonly_dynrelocs): Removed.
	(maybe_set_textrel): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	*  elf32-hppa.c(readonly_dynrelocs): Removed.
	(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-lm32.c (readonly_dynrelocs): Removed.
	(lm32_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-m32r.c (readonly_dynrelocs): Removed.
	(m32r_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-metag.c (readonly_dynrelocs): Removed.
	(elf_metag_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-microblaze.c (readonly_dynrelocs): Removed.
	(microblaze_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	* elf32-nds32.c (readonly_dynrelocs): Removed.
	(nds32_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-or1k.c (readonly_dynrelocs): Removed.
	(or1k_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	* elf32-ppc.c (readonly_dynrelocs): Removed.
	(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	(ppc_elf_adjust_dynamic_symbol): Likewise.
	(maybe_set_textrel): Likewise.
	* elf32-s390.c (readonly_dynrelocs): Removed.
	(elf_s390_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-sh.c (readonly_dynrelocs): Removed.
	(sh_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf32-tic6x.c (readonly_dynrelocs): Removed.
	(maybe_set_textrel): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	* elf32-tilepro.c (readonly_dynrelocs): Removed.
	(tilepro_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elf64-ppc.c (readonly_dynrelocs): Removed.
	(alias_readonly_dynrelocs): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	(ppc64_elf_adjust_dynamic_symbol): Likewise.
	(maybe_set_textrel): Likewise.
	* elf64-s390.c (readonly_dynrelocs): Removed.
	(elf_s390_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elflink.c (_bfd_elf_readonly_dynrelocs): New.
	* elfnn-aarch64.c (readonly_dynrelocs): Removed.
	(maybe_set_textrel): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	* elfnn-riscv.c (readonly_dynrelocs): Removed.
	(riscv_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elfxx-sparc.c (readonly_dynrelocs): Removed.
	(_bfd_sparc_elf_adjust_dynamic_symbol): Replace
	readonly_dynrelocs with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elfxx-tilegx.c (readonly_dynrelocs): Removed.
	(tilegx_elf_adjust_dynamic_symbol): Replace readonly_dynrelocs
	with _bfd_elf_readonly_dynrelocs.
	(maybe_set_textrel): Likewise.
	* elfxx-x86.c (readonly_dynrelocs): Removed.
	(maybe_set_textrel): Replace readonly_dynrelocs with
	_bfd_elf_readonly_dynrelocs.
	(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.
2020-06-03 07:01:13 -07:00
H.J. Lu 433953ffa1 x86: Silence -fsanitize=undefined
Replace "&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)" to
silence -fsanitize=undefined.

	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Replace
	"&(EH)->elf" with "(struct elf_link_hash_entry *) (EH)".
2020-06-03 06:32:24 -07:00