Commit Graph

6788 Commits

Author SHA1 Message Date
H.J. Lu
c2e9a4a3ed elf/x86-64: Adjust R_AMD64_DIR64/R_AMD64_DIR32 for PE/x86-64 inputs
Subtract the value of the section contents for R_AMD64_DIR64 and
R_AMD64_DIR32 relocations when generating ELF output from PE/x86-64
inputs.

bfd/

	PR ld/27171
	* reloc.c (bfd_perform_relocation): Adjust R_AMD64_DIR64 and
	R_AMD64_DIR32 relocations for PE/x86-64 inputs.

ld/

	PR ld/27171
	* testsuite/ld-x86-64/pe-x86-64-5.obj.bz2: New file.
	* testsuite/ld-x86-64/pe-x86-64-5.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise.
	* testsuite/ld-x86-64/pe-x86-64.exp: Run PR ld/27171 test.
2021-01-12 05:19:24 -08:00
H.J. Lu
83b33c6cb9 Binutils: Check if AR works with --plugin and rc
Check if AR works with --plugin and rc before passing --plugin to AR and
RANLIB.

bfd/

	PR ld/27173

binutils/

	PR ld/27173
	* configure: Regenerated.

gas/

	PR ld/27173
	* configure: Regenerated.

gprof/

	PR ld/27173
	* configure: Regenerated.

ld/

	PR ld/27173
	* configure: Regenerated.

libctf/

	PR ld/27173
	* configure: Regenerated.

opcodes/

	PR ld/27173
	* configure: Regenerated.
2021-01-11 16:29:45 -08:00
Matt Jenkins
c0f6e439cc Add support for more MIPS variants to the linker command line.
PR ld/27167
	* ldmain.c (get_emulation): Add mipsmips32r3, mips32r5, mips64r3
	and mips64r5 to list of known mips targets.
2021-01-11 14:31:55 +00:00
Nick Clifton
a8aa72b913 Updated translations for multiple subdirectories 2021-01-11 12:55:33 +00:00
H.J. Lu
a4966cd965 Binutils: Pass --plugin to AR and RANLIB
Detect GCC LTO plugin.  Pass --plugin to AR and RANLIB to support LTO
build.

bfd/

	* configure: Regenerated.

binutils/

	* configure: Regenerated.

gas/

	* configure: Regenerated.

gprof/

	* configure: Regenerated.

ld/

	* configure: Regenerated.

libctf/

	* configure: Regenerated.

opcodes/

	* configure: Regenerated.
2021-01-09 06:51:51 -08:00
H.J. Lu
0a94990bf6 ld/x86-64: Properly Handle -z lam-u48/lam-u57
Properly merge GNU properties for LAM_U48 and LAM_U57.

bfd/

	PR ld/27166
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Handle
	-z lam-u48 and -z lam-u57.

ld/

	PR ld/27166
	* testsuite/ld-x86-64/lam-u48.rd: New file.
	* testsuite/ld-x86-64/lam-u57.rd: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Add PR ld/27166 tests.
2021-01-09 06:13:11 -08:00
Nick Clifton
573fe3fbc1 Change version number to 2.36.50 and regenerate files 2021-01-09 11:01:01 +00:00
Nick Clifton
055bc77a80 Add Changelog entries and NEWS entries for 2.36 branch 2021-01-09 10:40:28 +00:00
H.J. Lu
ba9e922fa0 ld/x86-64: Also set LAM_U57 when setting LAM_U48
Since LAM_U48 implies LAM_U57, also set LAM_U57 when setting LAM_U48.

bfd/

	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Also set
	LAM_U57 when setting LAM_U48.

ld/

	* ld-x86-64/property-x86-lam-u48-4.d: Updated.
	* ld-x86-64/property-x86-lam-u48-5.d: Likewise.
2021-01-08 21:51:48 -08:00
Alan Modra
6430704567 configure regen
commit f478212851 did the regen by hand, missed a change in
ld/configure and didn't update line numbers.  Fix that, and an old
regen of ld/Makefile.in with the wrong automake.

bfd/
	* configure: Regenerate.
binutils/
	* configure: Regenerate.
gas/
	* configure: Regenerate.
gprof/
	* configure: Regenerate.
ld/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
libctf/
	* configure: Regenerate.
opcodes/
	* configure: Regenerate.
zlib/
	* configure: Regenerate.
2021-01-09 15:12:44 +10:30
Samuel Thibault
f478212851 libtool.m4: update GNU/Hurd test from upstream. In upstream libtool, 47a889a4ca20 ("Improve GNU/Hurd support.") fixed detection of shlibpath_overrides_runpath, thus avoiding unnecessary relink. This backports it.
.	* libtool.m4: Match gnu* along other GNU systems.

*/ChangeLog:

	* configure: Re-generate.
2021-01-07 16:47:36 +00:00
H.J. Lu
d1bcae833b ELF: Don't generate unused section symbols
For ELF targets, section symbols are required only for relocations.
With -ffunction-sections -fdata-sections, there can be many unused
section symbols.  Sizes of libstdc++.a on Linux/x86-64 in GCC 11 are

With unused section symbols   : 39411698 bytes
Without unused section symbols: 39227002 bytes

The unused section symbols in libstdc++.a occupy more than 180 KB.

Add BSF_SECTION_SYM_USED to indicate if a section symbol should be
included in the symbol table.  The BSF_SECTION_SYM_USED should be set
if the section symbol is used for relocation or the section symbol is
always included in the symbol table.

Add keep_unused_section_symbols to bfd_target to indicate if unused
section symbols should be kept.  If TARGET_KEEP_UNUSED_SECTION_SYMBOLS
is defined as FALSE, unused ection symbols will be removed.

Tested on Linux/x86.  Other ELF backends need to:

1. Define TARGET_KEEP_UNUSED_SECTION_SYMBOLS to FALSE.
2. Mark used section symbols in assembler backend.
3. Remove unused section symbols from expected assembler and linker
outputs.

bfd/

	PR 27109
	* aix386-core.c (core_aix386_vec): Initialize
	keep_unused_section_symbol to TARGET_KEEP_UNUSED_SECTION_SYMBOLS.
	* aout-target.h (MY (vec)): Likewise.
	* binary.c (binary_vec): Likewise.
	* cisco-core.c (core_cisco_be_vec): Likewise.
	(core_cisco_le_vec): Likewise.
	* coff-alpha.c (alpha_ecoff_le_vec): Likewise.
	* coff-i386.c (TARGET_SYM): Likewise.
	(TARGET_SYM_BIG): Likewise.
	* coff-ia64.c (TARGET_SYM): Likewise.
	* coff-mips.c (mips_ecoff_le_vec): Likewise.
	(mips_ecoff_be_vec): Likewise.
	(mips_ecoff_bele_vec): Likewise.
	* coff-rs6000.c (rs6000_xcoff_vec): Likewise.
	(powerpc_xcoff_vec): Likewise.
	* coff-sh.c (sh_coff_small_vec): Likewise.
	(sh_coff_small_le_vec): Likewise.
	* coff-tic30.c (tic30_coff_vec): Likewise.
	* coff-tic54x.c (tic54x_coff0_vec): Likewise.
	(tic54x_coff0_beh_vec): Likewise.
	(tic54x_coff1_vec): Likewise.
	(tic54x_coff1_beh_vec): Likewise.
	(tic54x_coff2_vec): Likewise.
	(tic54x_coff2_beh_vec): Likewise.
	* coff-x86_64.c (TARGET_SYM): Likewise.
	(TARGET_SYM_BIG): Likewise.
	* coff64-rs6000.c (rs6000_xcoff64_vec): Likewise.
	(rs6000_xcoff64_aix_vec): Likewise.
	* coffcode.h (CREATE_BIG_COFF_TARGET_VEC): Likewise.
	(CREATE_BIGHDR_COFF_TARGET_VEC): Likewise.
	(CREATE_LITTLE_COFF_TARGET_VEC): Likewise.
	* elfxx-target.h (TARGET_BIG_SYM): Likewise.
	(TARGET_LITTLE_SYM): Likewise.
	* hppabsd-core.c (core_hppabsd_vec): Likewise.
	* hpux-core.c (core_hpux_vec): Likewise.
	* i386msdos.c (i386_msdos_vec): Likewise.
	* ihex.c (ihex_vec): Likewise.
	* irix-core.c (core_irix_vec): Likewise.
	* mach-o-target.c (TARGET_NAME): Likewise.
	* mmo.c (mmix_mmo_vec): Likewise.
	* netbsd-core.c (core_netbsd_vec): Likewise.
	* osf-core.c (core_osf_vec): Likewise.
	* pdp11.c (MY (vec)): Likewise.
	* pef.c (pef_vec): Likewise.
	(pef_xlib_vec): Likewise.
	* plugin.c (plugin_vec): Likewise.
	* ppcboot.c (powerpc_boot_vec): Likewise.
	* ptrace-core.c (core_ptrace_vec): Likewise.
	* sco5-core.c (core_sco5_vec): Likewise.
	* som.c (hppa_som_vec): Likewise.
	* srec.c (srec_vec): Likewise.
	(symbolsrec_vec): Likewise.
	* tekhex.c (tekhex_vec): Likewise.
	* trad-core.c (core_trad_vec): Likewise.
	* verilog.c (verilog_vec): Likewise.
	* vms-alpha.c (alpha_vms_vec): Likewise.
	* vms-lib.c (alpha_vms_lib_txt_vec): Likewise.
	* wasm-module.c (wasm_vec): Likewise.
	* xsym.c (sym_vec): Likewise.
	* elf.c (ignore_section_sym): Return TRUE if BSF_SECTION_SYM_USED
	isn't set.
	(elf_map_symbols): Don't include ignored section symbols.
	* elfcode.h (elf_slurp_symbol_table): Also set
	BSF_SECTION_SYM_USED on STT_SECTION symbols.
	* elflink.c (bfd_elf_final_link): Generated section symbols only
	when emitting relocations or reqired.
	* elfxx-x86.h (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New.
	* syms.c (BSF_SECTION_SYM_USED): New.
	* targets.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New.
	(bfd_target): Add keep_unused_section_symbols.
	(bfd_keep_unused_section_symbols): New.
	* bfd-in2.h: Regenerated.

binutils/

	PR 27109
	* objcopy.c (copy_object): Handle section symbols for
	non-relocatable inputs.
	* testsuite/binutils-all/readelf.exp (readelf_test): Check
	is_elf_unused_section_symbols.
	* testsuite/binutils-all/readelf.s-64: Updated.
	* testsuite/binutils-all/readelf.ss: Likewise.
	* testsuite/binutils-all/readelf.ss-64: Likewise.
	* testsuite/binutils-all/readelf.s-64-unused: New file.
	* testsuite/binutils-all/readelf.ss-64-unused: Likewise.
	* testsuite/binutils-all/readelf.ss-unused: Likewise.
	* testsuite/lib/binutils-common.exp
	(is_elf_unused_section_symbols): New proc.

gas/ChangeLog:

	PR 27109
	* read.c (s_reloc): Call symbol_mark_used_in_reloc on the
	section symbol.
	* subsegs.c (subseg_set_rest): Set BSF_SECTION_SYM_USED if needed.
	* write.c (adjust_reloc_syms): Call symbol_mark_used_in_reloc
	on the section symbol.
	(set_symtab): Don't generate unused section symbols.
	(maybe_generate_build_notes): Call symbol_mark_used_in_reloc
	on the section symbol.
	* config/obj-elf.c (elf_adjust_symtab): Call
	symbol_mark_used_in_reloc on the group signature symbol.
	* testsuite/gas/cfi/cfi-label.d: Remove unused section symbols
	from expected output.
	* testsuite/gas/elf/elf.exp (run_elf_list_test): Check
	is_elf_unused_section_symbols.
	* testsuite/gas/elf/section2.e: Updated.
	* testsuite/gas/elf/section2.e-unused: New file.
	* testsuite/gas/elf/symver.d: Remove unused section symbols.
	* testsuite/gas/i386/ilp32/elf/symver.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-1.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-3.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-5.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-unwind.d: Likewise.
	* testsuite/gas/i386/size-1.d: Likewise.
	* testsuite/gas/i386/size-3.d: Likewise.
	* testsuite/gas/i386/svr4.d: Likewise.
	* testsuite/gas/i386/x86-64-size-1.d: Likewise.
	* testsuite/gas/i386/x86-64-size-3.d: Likewise.
	* testsuite/gas/i386/x86-64-size-5.d: Likewise.
	* testsuite/gas/i386/x86-64-unwind.d: Likewise.

ld/

	PR 27109
	* testsuite/ld-elf/export-class.sd: Adjust the expected output.
	* testsuite/ld-elf/loadaddr3b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-1l.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
	* testsuite/ld-x86-64/pr23854.d: Likewise.
	* testsuite/ld-x86-64/pr25416-3.d: Likewise.
	* testsuite/ld-x86-64/pr25416-4.d: Likewise.
	* testsuite/ld-i386/plt-pic.pd: Likewise.
	* testsuite/ld-i386/plt-pic2.dd: Likewise.
	* testsuite/ld-i386/plt.pd: Likewise.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/tlsbin.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
	* testsuite/ld-i386/tlsnopic.rd: Likewise.
	* testsuite/ld-i386/tlspic.rd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-x86-64/mpx3.dd: Likewise.
	* testsuite/ld-x86-64/mpx3n.dd: Likewise.
	* testsuite/ld-x86-64/mpx4.dd: Likewise.
	* testsuite/ld-x86-64/mpx4n.dd: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-1.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
	* testsuite/ld-x86-64/plt.pd: Likewise.
	* testsuite/ld-x86-64/plt2.dd: Likewise.
	* testsuite/ld-x86-64/tlsbin.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlspic.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.rd: Likewise.
	* testsuite/ld-elf/sec64k.exp: Check
	is_elf_unused_section_symbols.
2021-01-07 06:46:55 -08:00
Alan Modra
dc20061339 sh-pe ld XPASSes
* testsuite/ld-scripts/fill.d: Skip sh-*-pe rather than xfail.
	* testsuite/ld-scripts/fill16.d: Don't xfail sh-*-pe.
	* testsuite/ld-scripts/segment-start.d: Likewise.
2021-01-08 00:32:43 +10:30
Alan Modra
8e604ff077 xfail more cases of complaints about relocs in read-only sections
* testsuite/ld-elf/comm-data5.d: xfail targets that complain
	about dynamic relocations in read-only sections.
	* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
	* testsuite/ld-elf/ehdr_start.d: Likewise.
	* testsuite/ld-scripts/pr22267.d: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise for DT_TEXTREL tests and
	pr20995 text.
	* testsuite/ld-elf/sec64k.exp: Don't run 64ksec on lm32-linux.
2021-01-08 00:32:10 +10:30
Marcus Comstedt
4d4490b8d7 ld: xfail riscv64*-*-* for ld-scripts/empty-address-2 tests.
For now we have supported the riscv big endian targets, so
xfail riscv64*-*-* for ld-scripts/empty-address-2 tests, to
cover both little endian and big endian targets.

ld/
    * testsuite/ld-scripts/empty-address-2a.d: xfail riscv64*-*-*.
    * testsuite/ld-scripts/empty-address-2b.d: Likewise.
2021-01-07 15:08:04 +08:00
Alan Modra
f526791a6f Regen ld/po/BLD-POTFILES.in
* po/BLD-POTFILES.in: Regenerate.
2021-01-07 08:56:28 +10:30
Alan Modra
4018f4e0fc ld pr22471 test fails
* testsuite/ld-elf/shared.exp: xfail pr22471 for targets that
	complain about relocs in read-only sections.  Tidy ASFLAGS append.
2021-01-07 08:56:28 +10:30
Alan Modra
3677b72961 sparc-sun-solaris2 and sparc64-sun-solaris2 config
A bunch of ld tests fail on these targets due to the test specifying
-melf32_sparc or -melf64_sparc, which according to ld/configure.tgt
are valid.  However, config.bfd lacks the corresponding bfd target
resulting in an error.  Fix that by adding target_selvecs.

bfd/
	* config.bfd (sparc-*-solaris2*): Add sparc_elf32_vec.
	(sparc64-*-solaris2*): Add sparc_elf64_vec and
	sparc_elf32_vec.
ld/
	* testsuite/ld-sparc/sparc.exp (sparc64tests): Set text-segment
	base for some tests.
	* testsuite/ld-sparc/gotop32.dd: Match solaris output.
	* testsuite/ld-sparc/gotop32.sd: Likewise.
	* testsuite/ld-sparc/gotop32.td: Likewise.
	* testsuite/ld-sparc/gotop64.dd: Likewise.
	* testsuite/ld-sparc/gotop64.sd: Likewise.
	* testsuite/ld-sparc/gotop64.td: Likewise.
	* testsuite/ld-sparc/tlsg32.sd: Likewise.
	* testsuite/ld-sparc/tlsg64.sd: Likewise.
	* testsuite/ld-sparc/tlspie32.dd: Likewise.
	* testsuite/ld-sparc/tlspie64.dd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.dd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.sd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.td: Likewise.
	* testsuite/ld-sparc/tlssunbin64.dd: Likewise.
	* testsuite/ld-sparc/tlssunbin64.sd: Likewise.
	* testsuite/ld-sparc/tlssunbin64.td: Likewise.
	* testsuite/ld-sparc/tlssunnopic32.dd: Likewise.
	* testsuite/ld-sparc/tlssunnopic32.sd: Likewise.
	* testsuite/ld-sparc/tlssunnopic64.dd: Likewise.
	* testsuite/ld-sparc/tlssunnopic64.sd: Likewise.
	* testsuite/ld-sparc/tlssunpic32.dd: Likewise.
	* testsuite/ld-sparc/tlssunpic32.sd: Likewise.
	* testsuite/ld-sparc/tlssunpic32.td: Likewise.
	* testsuite/ld-sparc/tlssunpic64.dd: Likewise.
	* testsuite/ld-sparc/tlssunpic64.sd: Likewise.
	* testsuite/ld-sparc/tlssunpic64.td: Likewise.
	* testsuite/ld-sparc/wdispcall.dd: Likewise.
2021-01-06 21:03:55 +10:30
Alan Modra
73624512cf ld rgn-at10 and rgn-at11 test
These fail on v850 due to that target using different .tbss section flags.

	* testsuite/ld-scripts/rgn-at10.d: xfail v850.
	* testsuite/ld-scripts/rgn-at11.d: Likewise.
2021-01-06 21:03:55 +10:30
Marcus Comstedt
f36ce378b4 RISC-V: Fix riscv gas/ld testsuites failures for big endian.
Add riscv_choose_[ilp32|lp64]_emul, and use them to choose the correct
linker script rather than set elf[32|64]lriscv directly.

gas/
    * testsuite/gas/riscv/li32.d: Accept bigriscv in addition
    to littleriscv.
    * testsuite/gas/riscv/li64.d: Likewise.
    * testsuite/gas/riscv/lla32.d: Likewise.
    * testsuite/gas/riscv/lla64.d: Likewise.
    * testsuite/gas/riscv/march-ok-g2.d: Likewise.
    * testsuite/gas/riscv/march-ok-g2_p1.d: Likewise.
    * testsuite/gas/riscv/march-ok-g2p0.d: Likewise.
    * testsuite/gas/riscv/march-ok-i2p0.d: Likewise.
    * testsuite/gas/riscv/march-ok-i2p0m2_a2f2.d: Likewise.
    * testsuite/gas/riscv/march-ok-nse-with-version.d: Likewise.
    * testsuite/gas/riscv/march-ok-two-nse.d: Likewise.

ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Added
    riscv_choose_[ilp32|lp64]_emul to choose the correct linker script.
    * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Call
    riscv_choose_[ilp32|lp64]_emul instead of hardcoding elf[32|64]lriscv.
    * testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
    * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
    * testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Likewise.
    * testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Likewise.
    * testsuite/ld-riscv-elf/c-lui-2.d: Likewise.
    * testsuite/ld-riscv-elf/c-lui.d: Likewise.
    * testsuite/ld-riscv-elf/call-relax.d: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-2.d: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend.d: Likewise.
    * testsuite/ld-riscv-elf/weakref32.d: Accept bigriscv in addition
    to littleriscv.
    * testsuite/ld-riscv-elf/weakref64.d: Likewise.
2021-01-06 18:01:41 +08:00
Marcus Comstedt
fbc09e7af7 RISC-V: Implement support for big endian targets.
RISC-V instruction/code is always little endian, but data might be
big-endian.  Therefore, we can not use the original bfd_get/bfd_put
to get/put the code for big endian targets.  Add new riscv_get_insn
and riscv_put_insn to always get/put code as little endian can resolve
the problem.  Just remember to update them once we have supported
the 48-bit/128-bit instructions in the future patches.

bfd/
    * config.bfd: Added targets riscv64be*-*-*, riscv32be*-*-* and
    riscvbe*-*-*.  Also added riscv_elf[32|64]_be_vec.
    * configure.ac: Handle riscv_elf[32|64]_be_vec.
    * configure: Regenerate.
    * elfnn-riscv.c: Include <limits.h> and define CHAR_BIT for
    riscv_is_insn_reloc.
    (riscv_get_insn): RISC-V instructions are always little endian, but
    bfd_get may be used for big-endian, so add new riscv_get_insn to handle
    the insturctions.
    (riscv_put_insn): Likewsie.
    (riscv_is_insn_reloc): Check if we are relocaing an instruction.
    (perform_relocation): Call riscv_is_insn_reloc to decide if we should
    use riscv_[get|put]_insn or bfd_[get|put].
    (riscv_zero_pcrel_hi_reloc): Use riscv_[get|put]_insn, bfd_[get|put]l32
    or bfd_[get|put]l16 for code.
    (riscv_elf_relocate_section): Likewise.
    (riscv_elf_finish_dynamic_symbol): Likewise.
    (riscv_elf_finish_dynamic_sections): Likewise.
    (_bfd_riscv_relax_call): Likewise.
    (_bfd_riscv_relax_lui): Likewise.
    (_bfd_riscv_relax_align): Likewise.
    (_bfd_riscv_relax_pc): Likewise.
    (riscv_elf_object_p): Handled for big endian.
    (TARGET_BIG_SYM, TARGET_BIG_NAME): Defined.
    * targets.c: Add riscv_elf[32|64]_be_vec.
    (_bfd_target_vector): Likewise.

gas/
    * config/tc-riscv.c (riscv_target_format): Add elf64-bigriscv and
    elf32-bigriscv.
    (install_insn): Always write instructions as little endian.
    (riscv_make_nops): Likewise.
    (md_convert_frag_branch): Likewise.
    (md_number_to_chars): Write data in target endianness.
    (options, md_longopts): Add -mbig-endian and -mlittle-endian options.
    (md_parse_option): Handle the endian options.
    * config/tc-riscv.h: Only define TARGET_BYTES_BIG_ENDIAN if not
    already defined.
    * configure.tgt: Added riscv64be*, riscv32be*, riscvbe*.

ld/
    * configure.tgt: Added riscvbe-*-*, riscv32be*-*-*, riscv64be*-*-*,
    riscv32be*-*-linux*, and riscv64be*-*-linux*.
    * Makefile.am: Added eelf32briscv.c, eelf32briscv_ilp32f.c and
    eelf32briscv_ilp32.c.
    * Makefile.in: Regenerate.
    * emulparams/elf32briscv.sh: Added.
    * emulparams/elf32briscv_ilp32.sh: Likewise.
    * emulparams/elf32briscv_ilp32f.sh: Likewise.
    * emulparams/elf64briscv.sh: Likewise.
    * emulparams/elf64briscv_lp64.sh: Likewise.
    * emulparams/elf64briscv_lp64f.sh: Likewise.
2021-01-06 17:57:52 +08:00
Nick Alcock
b4b6ea4680 libctf, ld: fix formatting of forwards to unions and enums
The type printer was unconditionally printing these as if they were
forwards to structs, even if they were forwards to unions or enums.

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/enum-forward.c: New test.
	* testsuite/ld-ctf/enum-forward.c: New results.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_aname): Print forwards to unions and enums
	properly.
2021-01-05 14:53:40 +00:00
Nick Alcock
37002871ac libctf, ld: dump enums: generally improve dump formatting
This commit adds dumping of enumerands in this general form:

    0x3: (kind 8) enum eleven_els (size 0x4) (aligned at 0x4)
         ELEVEN_ONE: 10
         ELEVEN_TWO: 11
         ELEVEN_THREE: -256
         ELEVEN_FOUR: -255
         ELEVEN_FIVE: -254
         ...
         ELEVEN_SEVEN: -252
         ELEVEN_EIGHT: -251
         ELEVEN_NINE: -250
         ELEVEN_TEN: -249
         ELEVEN_ELEVEN: -248

The first and last enumerands in the enumerated type are printed so that
you can tell if they've been cut off at one end or the other.  (For now,
there is no way to control how many enumerands are printed.)

The dump output in general is improved, from this sort of thing a few
days ago:

     4c: char [0x0:0x8] (size 0x1)
        [0x0] (ID 0x4c) (kind 1) char:8 (aligned at 0x1, format 0x3, offset:bits 0x0:0x8)
     4d: char * (size 0x8) -> 4c: char [0x0:0x8] (size 0x1)
        [0x0] (ID 0x4d) (kind 3) char * (aligned at 0x8)
[...]
     5a: struct _IO_FILE (size 0xd8)
        [0x0] (ID 0x5a) (kind 6) struct _IO_FILE (aligned at 0x4)
            [0x0] (ID 0x3) (kind 1) int _flags:32 (aligned at 0x4, format 0x1, offset:bits 0x0:0x20)
            [0x40] (ID 0x4d) (kind 3) char * _IO_read_ptr (aligned at 0x8)
            [0x80] (ID 0x4d) (kind 3) char * _IO_read_end (aligned at 0x8)
            [0xc0] (ID 0x4d) (kind 3) char * _IO_read_base (aligned at 0x8)
     5b: __FILE (size 0xd8) -> 5a: struct _IO_FILE (size 0xd8)
        [0x0] (ID 0x5b) (kind 10) __FILE (aligned at 0x4)
            [0x0] (ID 0x3) (kind 1) int _flags:32 (aligned at 0x4, format 0x1, offset:bits 0x0:0x20)
            [0x40] (ID 0x4d) (kind 3) char * _IO_read_ptr (aligned at 0x8)
            [0x80] (ID 0x4d) (kind 3) char * _IO_read_end (aligned at 0x8)
            [0xc0] (ID 0x4d) (kind 3) char * _IO_read_base (aligned at 0x8)
[...]
     406: struct coff_link_hash_entry (size 0x60)
        [0x0] (ID 0x406) (kind 6) struct coff_link_hash_entry (aligned at 0x8)
            [0x0] (ID 0x2b3) (kind 6) struct bfd_link_hash_entry root (aligned at 0x8)
                [0x0] (ID 0x1d6) (kind 6) struct bfd_hash_entry root (aligned at 0x8)
                    [0x0] (ID 0x1d7) (kind 3) struct bfd_hash_entry * next (aligned at 0x8)
                    [0x40] (ID 0x61) (kind 3) const char * string (aligned at 0x8)
                    [0x80] (ID 0x1) (kind 1) long unsigned int hash:64 (aligned at 0x8, format 0x0, offset:bits 0x0:0x40)
                [0xc0] (ID 0x397) (kind 8) enum bfd_link_hash_type  type:8 (aligned at 0x1, format 0x0, offset:bits 0x0:0x8)
                [0xc8] (ID 0x1c7) (kind 1) unsigned int  non_ir_ref_regular:1 (aligned at 0x1, format 0x0, offset:bits 0x8:0x1)
                [0xc9] (ID 0x1c8) (kind 1) unsigned int  non_ir_ref_dynamic:1 (aligned at 0x1, format 0x0, offset:bits 0x9:0x1)
                [0xca] (ID 0x1c9) (kind 1) unsigned int  linker_def:1 (aligned at 0x1, format 0x0, offset:bits 0xa:0x1)
                [0xcb] (ID 0x1ca) (kind 1) unsigned int  ldscript_def:1 (aligned at 0x1, format 0x0, offset:bits 0xb:0x1)
                [0xcc] (ID 0x1cb) (kind 1) unsigned int  rel_from_abs:1 (aligned at 0x1, format 0x0, offset:bits 0xc:0x1)

... to this:

    0x4c: (kind 1) char (format 0x3) (size 0x1) (aligned at 0x1)
    0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) -> 0x4c: (kind 1) char (format 0x3) (size 0x1) (aligned at 0x1)
    0x5a: (kind 6) struct _IO_FILE (size 0xd8) (aligned at 0x4)
          [0x0] _flags: ID 0x3: (kind 1) int (format 0x1) (size 0x4) (aligned at 0x4)
          [0x40] _IO_read_ptr: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8)
          [0x80] _IO_read_end: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8)
          [0xc0] _IO_read_base: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8)
          [0x100] _IO_write_base: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8)
    0x5b: (kind 10) __FILE (size 0xd8) (aligned at 0x4) -> 0x5a: (kind 6) struct _IO_FILE (size 0xd8) (aligned at 0x4)
[...]
    0x406: (kind 6) struct coff_link_hash_entry (size 0x60) (aligned at 0x8)
           [0x0] root: ID 0x2b3: (kind 6) struct bfd_link_hash_entry (size 0x38) (aligned at 0x8)
               [0x0] root: ID 0x1d6: (kind 6) struct bfd_hash_entry (size 0x18) (aligned at 0x8)
                   [0x0] next: ID 0x1d7: (kind 3) struct bfd_hash_entry * (size 0x8) (aligned at 0x8)
                   [0x40] string: ID 0x61: (kind 3) const char * (size 0x8) (aligned at 0x8)
                   [0x80] hash: ID 0x1: (kind 1) long unsigned int (format 0x0) (size 0x8) (aligned at 0x8)
               [0xc0] type: ID 0x397: (kind 8) enum bfd_link_hash_type (format 0x7f2e) (size 0x1) (aligned at 0x1)
               [0xc8] non_ir_ref_regular: ID 0x1c7: (kind 1) unsigned int:1 [slice 0x8:0x1] (format 0x0) (size 0x1) (aligned at 0x1)
               [0xc9] non_ir_ref_dynamic: ID 0x1c8: (kind 1) unsigned int:1 [slice 0x9:0x1] (format 0x0) (size 0x1) (aligned at 0x1)
               [0xca] linker_def: ID 0x1c9: (kind 1) unsigned int:1 [slice 0xa:0x1] (format 0x0) (size 0x1) (aligned at 0x1)
               [0xcb] ldscript_def: ID 0x1ca: (kind 1) unsigned int:1 [slice 0xb:0x1] (format 0x0) (size 0x1) (aligned at 0x1)
               [0xcc] rel_from_abs: ID 0x1cb: (kind 1) unsigned int:1 [slice 0xc:0x1] (format 0x0) (size 0x1) (aligned at 0x1)
[...]

In particular, indented subsections are only present for actual structs
and unions, not forwards to them, and the structure itself doesn't add a
spurious level of indentation; structure field names are easier to spot
(at the cost of not making them look so much like C field declarations
any more, but they weren't always shown in valid decl syntax even before
this change) the size, type kind, and alignment are shown for all types
for which they are meaningful; bitfield info is only shown for actual
bitfields within structures and not ordinary integral fields; and type
IDs are never omitted.  Type printing is in general much more consistent
and there is much less duplicated code in the type dumper.

There is one user-visible effect outside the dumper: ctf_type_(a)name
was erroneously emitting a trailing space on the name of slice types,
even though a slice of an int and an int with the corresponding encoding
represent the same type and should have the same print form.  This
trailing space is now gone.

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for dumper changes.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-enums.d: Likewise.
	* testsuite/ld-ctf/conflicting-typedefs.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-into-cycle.d: Likewise.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
	* testsuite/ld-ctf/cycle-1.d: Likewise.
	* testsuite/ld-ctf/cycle-2.A.d: Likewise.
	* testsuite/ld-ctf/cycle-2.B.d: Likewise.
	* testsuite/ld-ctf/cycle-2.C.d: Likewise.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d: Likewise.
	* testsuite/ld-ctf/forward.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d: Likewise.
	* testsuite/ld-ctf/enums.c: New test.
	* testsuite/ld-ctf/enums.d: New test.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-decl.c (ctf_decl_push): Exclude slices from the decl stack.
	* ctf-types.c (ctf_type_aname): No longer deal with slices here.
	* ctf-dump.c (ctf_dump_membstate_t) <cdm_toplevel_indent>: Constify.
	(CTF_FT_REFS): New.
	(CTF_FT_BITFIELD): Likewise.
	(CTF_FT_ID): Likewise.
	(ctf_dump_member): Do not do indentation here. Migrate the
	type-printing parts of this into...
	(ctf_dump_format_type): ... here, to be shared by all type printers.
	Get the errno value for non-representable types right.  Do not print
	bitfield info for non-bitfields.  Improve the format and indentation
	of other type output.  Shuffle spacing around to make all indentation
	either 'width of column' or 4 chars.
	(ctf_dump_label): Pass CTF_FT_REFS to ctf_dump_format_type.
	(ctf_dump_objts): Likewise.  Spacing shuffle.
	(ctf_dump_var): Likewise.
	(type_hex_digits): Migrate down in the file, to above its new user.
	(ctf_dump_type): Indent here instead.  Pass CTF_FT_REFS to
	ctf_dump_format_type. Don't trim off excess linefeeds now we no
	longer generate them.  Dump enumerated types.
2021-01-05 14:53:39 +00:00
Nick Alcock
ffeece6ac2 libctf, ld: prohibit getting the size or alignment of forwards
C allows you to do only a very few things with entities of incomplete
type (as opposed to pointers to them): make pointers to them and give
them cv-quals, roughly. In particular you can't sizeof them and you
can't get their alignment.

We cannot impose all the requirements the standard imposes on CTF users,
because the deduplicator can transform any structure type into a forward
for the purposes of breaking cycles: so CTF type graphs can easily
contain things like arrays of forward type (if you want to figure out
their size or alignment, you need to chase down the types this forward
might be a forward to in child TU dicts: we will soon add API functions
to make doing this much easier).

Nonetheless, it is still meaningless to ask for the size or alignment of
forwards: but libctf didn't prohibit this and returned nonsense from
internal implementation details when you asked (it returned the kind of
the pointed-to type as both the size and alignment, because forwards
reuse ctt_type as a type kind, and ctt_type and ctt_size overlap).  So
introduce a new error, ECTF_INCOMPLETE, which is returned when you try
to get the size or alignment of forwards: we also return it when you try
to do things that require libctf itself to get the size or alignment of
a forward, notably using a forward as an array index type (which C
should never do in any case) or adding forwards to structures without
specifying their offset explicitly.

The dumper will not emit size or alignment info for forwards any more.

(This should not be an API break since ctf_type_size and ctf_type_align
could both return errors before now: any code that isn't expecting error
returns is already potentially broken.)

include/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ECTF_INCOMPLETE): New.
	(ECTF_NERR): Adjust.

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Adjust for dumper
	changes.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
	* testsuite/ld-ctf/forward.c: New test...
	* testsuite/ld-ctf/forward.d: ... and results.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_resolve): Improve comment.
	(ctf_type_size): Yield ECTF_INCOMPLETE when applied to forwards.
	Emit errors into the right dict.
	(ctf_type_align): Likewise.
	* ctf-create.c (ctf_add_member_offset): Yield ECTF_INCOMPLETE
	when adding a member without explicit offset when this member, or
	the previous member, is incomplete.
	* ctf-dump.c (ctf_dump_format_type): Do not try to print the size of
	forwards.
	(ctf_dump_member): Do not try to print their alignment.
2021-01-05 14:53:39 +00:00
Nick Alcock
91e7ce2fd7 libctf, ld: more dumper improvements
Dump more details about the types found in data object and function info
sections (the type ID and recursive info on the type itself, but not on
its members).  Before now, this was being dumped for entries in the
variable section, but not for the closely-related function info and data
object sections, which is inconsistent and makes finding the
corresponding types in the type section unnecessarily hard.  (This also
gets rid of code in which bugs have already been found in favour of the
same code everything else in the dumper uses to dump types.)

While we're doing that, change the recursive type dumper in question to
recursively dump info on arrays' element type, just as we do for all
types that reference other types. (Arrays are not a kind of reference
type in libctf, but perhaps we should change that in future and make
ctf_type_reference return the element type.)

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for dumper changes.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dump.c (ctf_dump_objts): Dump by calling ctf_dump_format_type.
	(ctf_dump_format_type): Don't emit the size for function objects.
	Dump the element type of arrays like we dump the pointed-to type of
	pointers, etc.
2021-01-05 14:53:39 +00:00
Nick Alcock
57f97d0e6d libctf, ld: CTF dumper changes for consistency
In most places in CTF dumper output, we emit 0x... for hex strings, but
in three places (top-level type IDs, string table offsets, and the file
magic number) we don't emit the 0x.

This is very confusing if by chance there are no hex digits in the
output.  Add 0x consistently to everything, and adjust tests
accordingly.  While we're at it, improve the indentation of the output
so that subsequent lines in aggregate output are indented by at least as
many columns as the colon in the type output.  (Subsequent indentation
is still 4 spaces at a time.)

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for dumper changes.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-enums.d: Likewise.
	* testsuite/ld-ctf/conflicting-typedefs.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-into-cycle.d: Likewise.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
	* testsuite/ld-ctf/cycle-1.d: Likewise.
	* testsuite/ld-ctf/cycle-2.A.d: Likewise.
	* testsuite/ld-ctf/cycle-2.B.d: Likewise.
	* testsuite/ld-ctf/cycle-2.C.d: Likewise.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d: Likewise.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dump.c (ctf_dump_format_type): Add 0x to hex type IDs.
	(ctf_dump_header): Add 0x to the hex magic number.
	(ctf_dump_str): Add 0x to the hex string offsets.
	(ctf_dump_membstate_t) <cdm_toplevel_indent>: New.
	(ctf_dump_type): Adjust.  Free it when we're done.
	(type_hex_digits): New.
	(ctf_dump_member): Align output depending on the width of the type
	ID being generated.  Use printf padding, not a loop, to generate
	indentation.
2021-01-05 14:53:39 +00:00
Alan Modra
b281a04ff0 ld sysroot-prefix test fails
* testsuite/ld-scripts/sysroot-prefix.exp: Exclude some targets.
2021-01-05 23:09:05 +10:30
Alan Modra
40b119304e Re: elf: Allow mixed ordered/unordered inputs for non-relocatable link
PR ld/26256
	* testsuite/ld-elf/pr26256-1b.d: xfail s12z.
	* testsuite/ld-scripts/crossref.exp (cross1): Don't xfail ia64.
2021-01-05 15:47:06 +10:30
H.J. Lu
cd6d537c48 elf: Allow mixed ordered/unordered inputs for non-relocatable link
For non-relocatable link with SHF_LINK_ORDER inputs, allow mixed indirect
and data inputs with ordered and unordered inputs:

1. Add pattern to bfd_section for the matching section name pattern in
linker script and update BFD_FAKE_SECTION.
2. Sort the consecutive bfd_indirect_link_order sections with the same
pattern to allow linker script to overdide input section order.
3. Place unordered sections before ordered sections.
4. Change the offsets of the indirect input sections only.

bfd/

	PR ld/26256
	* elflink.c (compare_link_order): Place unordered sections before
	ordered sections.
	(elf_fixup_link_order): Add a link info argument.  Allow mixed
	ordered and unordered input sections for non-relocatable link.
	Sort the consecutive bfd_indirect_link_order sections with the
	same pattern.  Change the offsets of the bfd_indirect_link_order
	sections only.
	(bfd_elf_final_link): Pass info to elf_fixup_link_order.
	* section.c (bfd_section): Add pattern.
	(BFD_FAKE_SECTION): Initialize pattern to NULL.
	* bfd-in2.h: Regenerated.

gas/

	PR ld/26256
	* config/obj-elf.c (obj_elf_change_section): Also filter out
	SHF_LINK_ORDER.

ld/

	PR ld/26256
	* ldlang.c (gc_section_callback): Set pattern.
	* testsuite/ld-elf/pr26256-1.s: New file.
	* testsuite/ld-elf/pr26256-1.t: Likewise.
	* testsuite/ld-elf/pr26256-1a.d: Likewise.
	* testsuite/ld-elf/pr26256-1b.d: Likewise.
	* testsuite/ld-elf/pr26256-2.s: Likewise.
	* testsuite/ld-elf/pr26256-2.t: Likewise.
	* testsuite/ld-elf/pr26256-2a.d: Likewise.
	* testsuite/ld-elf/pr26256-2b-alt.d: Likewise.
	* testsuite/ld-elf/pr26256-2b.d: Likewise.
	* testsuite/ld-elf/pr26256-3.s: Likewise.
	* testsuite/ld-elf/pr26256-3a.d: Likewise.
	* testsuite/ld-elf/pr26256-3a.t: Likewise.
	* testsuite/ld-elf/pr26256-3b.d: Likewise.
	* testsuite/ld-elf/pr26256-3b.t: Likewise.
2021-01-04 12:38:05 -08:00
Alan Modra
5b4293ba3c PR26822, How to prevent a STT_FILE with absolute path in the linked image
bfd/
	PR 26822
	* elflink.c (elf_link_input_bfd): Use the file base name in
	linker generated STT_FILE symbols.
ld/
	PR 26822
	* testsuite/ld-arm/non-contiguous-arm2.d: Adjust STT_FILE symbol match.
	* testsuite/ld-arm/non-contiguous-arm3.d: Likewise.
	* testsuite/ld-arm/non-contiguous-arm5.d: Likewise.
	* testsuite/ld-arm/non-contiguous-arm6.d: Likewise.
	* testsuite/ld-i386/tlsbin.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsnopic.rd: Likewise.
	* testsuite/ld-i386/tlspic.rd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: Likewise.
	* testsuite/ld-plugin/pr17973.d: Likewise.
	* testsuite/ld-tic6x/shlib-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlspic.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.rd: Likewise.
	* testsuite/ld-xtensa/tlsbin.rd: Likewise.
	* testsuite/ld-xtensa/tlspic.rd: Likewise.
2021-01-04 18:58:15 +10:30
Alan Modra
f9a6a8f09d PR27116, Spelling errors found by Debian style checker
PR 27116
bfd/
	* xcofflink.c: Correct spelling in comments.
binutils/
	* coffgrok.c (do_type): Correct spelling of auxiliary in errors.
	* doc/binutils.texi: Correct grammar.
	* readelf.c (process_version_sections): Correct spelling of auxiliary
	in warning.
	* testsuite/binutils-all/vax/objdump.exp: Comment grammar fix.
config/
	* override.m4: Correct comment grammar.
gas/
	* config/tc-i386.c: Correct comment spelling.
	* config/tc-riscv.c: Likewise.
	* config/tc-s390.c: Correct comment grammar.
	* doc/c-i386.texi: Correct spelling.
	* doc/c-s390.texi: Correct grammar.
gold/
	* tilegx.cc: Correct comment spelling.
gprof/
	* README: Correct grammar.
	* gprof.texi: Likewise.
include/
	* coff/internal.h: Correct comment spelling.
	* coff/sym.h: Likewise.
	* opcode/aarch64.h: Likewise.
ld/
	* configure.tgt: Correct comment grammar.
	* emultempl/m68hc1xelf.em: Likewise.
	* ld.texi: Correct grammar.
2021-01-01 14:36:35 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Alan Modra
c2795844e6 ChangeLog rotation 2021-01-01 10:31:02 +10:30
Alan Modra
cab3f4da68 PR27128, nm -P portable output format regression
binutils/
	PR 27128
	* nm.c (print_symname): Append version string to symbol name
	before printing the lot under control of "form".  Append version
	to demangled names too.
ld/
	PR 27128
	* testsuite/ld-elf/pr27128.s: New file.
	* testsuite/ld-elf/pr27128.t: Likewise.
	* testsuite/ld-elf/pr27128a.d: Likewise.
	* testsuite/ld-elf/pr27128b.d: Likewise.
	* testsuite/ld-elf/pr27128c.d: Likewise.
	* testsuite/ld-elf/pr27128d.d: Likewise.
	* testsuite/ld-elf/pr27128e.d: Likewise.
2020-12-31 19:07:02 +10:30
Alan Modra
99d8bab0c1 SHF_GNU_RETAIN 7a and 7b tests
* testsuite/ld-elf/retain7a.d: Don't run on hppa-linux.
	* testsuite/ld-elf/retain7b.d: Correct name.  Don't run on tic6x.
	Allow OSABI FreeBSD.
2020-12-24 22:58:14 +10:30
Alan Modra
de34d42812 PR27100, final link failed: bad value
The failure on this PR is due to using the same bfd section for
multiple output sections.  Commit 21401fc7bf managed to create
duplicate linker script output section statements, but not the actual
bfd sections.

	PR 27100
	* ldlang.h (lang_output_section_statement_type): Add dup_output.
	* ldlang.c (lang_output_section_statement_lookup): Set dup_output.
	(init_os): Test dup_output rather than constraint.
	* testsuite/ld-scripts/pr27100.d,
	* testsuite/ld-scripts/pr27100.s,
	* testsuite/ld-scripts/pr27100.t: New test.
	* testsuite/ld-scripts/data.exp: Run it.  Don't exclude aout here.
	* testsuite/ld-scripts/data.d: Do so here instead.
	* testsuite/ld-scripts/fill.d: Likewise.
	* testsuite/ld-scripts/fill16.d: Likewise.
2020-12-24 22:58:03 +10:30
H.J. Lu
279d901e5a x86-64: Add Intel LAM property support
Add Intel Linear Address Masking (LAM) property support.  LAM modifies
the checking that is applied to 64-bit linear addresses, allowing
software to use of the untranslated address bits for metadata.

bfd/

	* elf-linker-x86.h (elf_x86_cet_report): Renamed to ...
	(elf_x86_prop_report): This.
	(elf_linker_x86_params): Add lam_u48, lam_u57, lam_u48_report
	and lam_u57_report.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
	GNU_PROPERTY_X86_FEATURE_1_LAM_U57.
	(_bfd_x86_elf_link_fixup_gnu_properties): Keep LAM features only
	for 64-bit output.

binutils/

	* NEWS: Mention LAM_U48 and LAM_U57 support.
	* elfedit.c (elf_x86_feature): Support lam_u48 and lam_u57.
	(usage): Add lam_u48 and lam_u57.
	* readelf.c (decode_x86_feature_1): Support LAM_U48 and LAM_U57.
	* doc/binutils.texi: Update elfedit with lam_u48 and lam_u57
	support.
	* testsuite/binutils-all/x86-64/lam-u48.d: New file.
	* testsuite/binutils-all/x86-64/lam-u48.s: Likewise.
	* testsuite/binutils-all/x86-64/lam-u57.d: Likewise.
	* testsuite/binutils-all/x86-64/lam-u57.s: Likewise.

include/

	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_LAM_U48): New.
	(GNU_PROPERTY_X86_FEATURE_1_LAM_U57): Likewise.

ld/

	* NEWS: Mention LAM_U48 and LAM_U57 support.
	* ld.texi: Document LAM_U48 and LAM_U57 support.
	* emulparams/cet.sh: Updated.
	* emulparams/elf_x86_64.sh: Source x86-64-lam.sh.
	* emulparams/x86-64-lam.sh: New file.
	* testsuite/ld-x86-64/property-x86-lam-u48-1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48.s: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run LAM tests.
2020-12-23 13:00:55 -08:00
H.J. Lu
eba7b68cb0 ld: Build and install only unversioned libdep
Build only unversioned libdep and remove the installed libdep.la since
only a single libdep.so is needed.

	PR ld/27082
	* Makefile.am
	(libdep_la_LDFLAGS): Add -module -avoid-version.
	(libdep_la_LINK): New.
	(install-data-local): Depend on $(install-bfdpluginLTLIBRARIES)
	and remove libdep.la.
2020-12-18 04:30:59 -08:00
H.J. Lu
04f8967487 elf: Copy elf_gnu_osabi_retain only for relocatable link
Copy elf_gnu_osabi_retain from input only for relocatable link since
SHF_GNU_RETAIN has no impact on non-relocatable outputs.

bfd/

	PR ld/27091
	* elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain
	from input only for relocatable link.

ld/

	PR ld/27091
	* testsuite/ld-elf/retain7.s: New file.
	* testsuite/ld-elf/retain7a.d: Likewise.
	* testsuite/ld-elf/retain7b.d: Likewise.
2020-12-18 04:24:36 -08:00
H.J. Lu
bcac599f73 ld: Skip libdep plugin if not all plugin hooks are available
Skip plugin if not all required plugin hooks are available.

2020-12-16  Howard Chu <hyc@symas.com>
	    H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/27081
	* libdep_plugin.c (onload): Skip if not all required plugin hooks
	are available.
	* testsuite/config/default.exp (dep_plug_opt): New.
	* testsuite/ld-elf/elf.exp: Pass $dep_plug_opt to nm.
	* testsuite/ld-elf/pr26391.fd: New file.
2020-12-16 13:40:51 -08:00
Alan Modra
c410035d37 constify elfNN_bed
elfNN_bed was made writable as an expedient means of communicating
ld -z max-page-size and ld -z common-page-size values to BFD linker
code, and even for objcopy to communicate segment alignment between
copy_private_bfd_data, rewrite_elf_program_header and
assign_file_positions_for_load_sections.  Some time later elfNN_bed
elf_osabi was written by gas.  It turns out none of these
modifications to elfNN_bed was necessary, so make it const again.

include/
	* bfdlink.h (struct bfd_link_info): Add maxpagesize and
	commonpagesize.
bfd/
	* elfxx-target.h (elfNN_bed): Constify.
	* bfd.c (bfd_elf_set_pagesize): Delete.
	(bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete.
	* elf.c (get_program_header_size): Get commonpagesize from
	link info.
	(_bfd_elf_map_sections_to_segments): Get maxpagesize from link info.
	(assign_file_positions_for_load_sections): Likewise.
	(assign_file_positions_for_non_load_sections): Likewise.
	(rewrite_elf_program_header): Add maxpagesize param.  Set map_p_align.
	(copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize.
	Instead pass maxpagesize to rewrite_elf_program_header.
	* elf32-nds32.c (relax_range_measurement): Add link_info param.
	Get maxpagesize from link_info.  Adjust caller.
	* bfd-in2.h: Regenerate.
gas/
	* config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
	(obj_elf_type): Likewise.
ld/
	* ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
	* emultempl/elf.em: Use link_info rather than config
	for maxpagesize and commonpagesize.
	* emultempl/ppc32elf.em: Likewise.
	* ldexp.c (fold_binary, fold_name): Likewise.
	* ldemul.c (after_parse_default): Likewise.
	(set_output_arch_default): Don't call bfd_emul_set_maxpagesize
	or bfd_emul_set_commonpagesize.
2020-12-16 15:17:53 +10:30
Vivek Das Mohapatra
c3805e4cef Document -z unique/-z nounique in the ld man page and help output
* ld.texi (Options): Document -z unique and -z nounique.
	* lexsup.c (elf_shlib_list_options): Likewise.
2020-12-15 18:45:03 +10:30
Vivek Das Mohapatra
6a0a0dd0cc Handle -z unique/-z nounique in ld
Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.

bfd/
	* elflink.c (bfd_elf_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section.
include/
	* bfdlink.h (struct bfd_link_info): New field gnu_flags_1.
ld/
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
	Parse -z unique / -z nounique options.
2020-12-15 18:44:56 +10:30
Howard Chu
bf6d803782 Add a plugin for processing static library dependencies.
* libdep_plugin.c: New file: Processes archives that contain a
	special library dependencies element.
	* Makefile.am: Add build rules for libdep_plugin.
	* Makefile.in: Regenerate.
	* NEWS: Mention the new plugin.
	* ld.texi: Document the new plugin.
2020-12-14 14:26:11 +00:00
Alan Modra
8da4f428d1 PR26836, memory leak in parse_args
PR 26836
	* lexsup.c (parse_args): Free really_longopts, longopts and
	shortopts.
2020-12-14 23:36:09 +10:30
Nick Clifton
3991c7acb2 Fix a use of an uninitialised variable in the bfd linker.
PR 27050
	* lexsup.c (parse_args): Ensure that the longind local variable is
	set.
2020-12-14 12:40:13 +00:00
Alan Modra
6abe7848fa Solaris 11.4 ld build failure
/usr/include/sys/mman.h:81:0: note: this is the location of the previous definition
 #define SHARED  0x10

	PR 27064
	* deffilep.y (SHARED_K): Rename from SHARED.  Update uses.
2020-12-14 14:05:05 +10:30
Maciej W. Rozycki
0fcf331bb1 VAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is made
Match the condition used in `elf_vax_instantiate_got_entries' for the
creation of GOT entries in the processing of R_VAX_GOT32 relocations in
`elf_vax_check_relocs', removing incorrect warnings about a GOT addend
mismatch like:

./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 1 to `bar_hidden' does not match previous GOT addend of 0
./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 2 to `bar_hidden' does not match previous GOT addend of 0

and corresponding failures with the test cases newly added here:

FAIL: GOT test (executable hidden reference with offset)
FAIL: GOT test (executable visible reference with offset)

for symbols that are considered local for reasons other than having been
forced local with a version script, which is usually the ELF visibility.
Correct code is produced regardless, but the warning breaks `-Werror'
compilation and may upset people regardless.

Interestingly this shows with executable links only, because in shared
library links code from `elf_link_add_object_symbols' triggers:

	    /* If the symbol already has a dynamic index, but
	       visibility says it should not be visible, turn it into
	       a local symbol.  */
	    switch (ELF_ST_VISIBILITY (h->other))
	      {
	      case STV_INTERNAL:
	      case STV_HIDDEN:
		(*bed->elf_backend_hide_symbol) (info, h, TRUE);
		dynsym = FALSE;
		break;
	      }

that sets `h->forced_local' like with a version script.

Add suitable test cases including disassembly to verify correct code has
been produced where no warnings have been issued, and that warnings do
get issued where necessary.  Do not verify (broken) code produced in the
latter case; we should probably make the warning an error, or preferably
actually start supporting GOT references with different addends as they
appear feasible with explicitly relocated GOT that we use.

	bfd/
	* elf32-vax.c (elf_vax_check_relocs) <R_VAX_GOT32>: Use
	SYMBOL_REFERENCES_LOCAL rather than `h->forced_local' to check
	whether the symbol referred is local or not.

	ld/
	* testsuite/ld-vax-elf/got-local-exe-off-hidden.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-exe-off-visible.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-lib-off-hidden.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-lib-off-visible.ed: New test
	dump.
	* testsuite/ld-vax-elf/got-local-off-external.ed: New test dump.
	* testsuite/ld-vax-elf/got-local-exe-off.xd: New test dump.
	* testsuite/ld-vax-elf/got-local-lib-off.xd: New test dump.
	* testsuite/ld-vax-elf/got-local.ld: New test linker script.
	* testsuite/ld-vax-elf/got-local-aux-off.s: New test source.
	* testsuite/ld-vax-elf/got-local-def-off.s: New test source.
	* testsuite/ld-vax-elf/got-local-ref-off-external.s: New test
	source.
	* testsuite/ld-vax-elf/got-local-ref-off-hidden.s: New test
	source.
	* testsuite/ld-vax-elf/got-local-ref-off-visible.s: New test
	source.
	* testsuite/ld-vax-elf/vax-elf.exp: Run the new tests.
2020-12-05 11:18:14 +00:00
H.J. Lu
7e45e7a9ab x86-64: Convert load to mov only for GOTPCRELX relocations
Since converting load to mov needs to rewrite the REX byte and we don't
know if there is a REX byte with GOTPCREL relocation, do it only for
GOTPCRELX relocations.

bfd/

	PR ld/27016
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Convert load
	to mov only for GOTPCRELX relocations.

ld/

	PR ld/27016
	* testsuite/ld-x86-64/x86-64.exp: Run pr27016a and pr27016b.
	* testsuite/ld-x86-64/pr27016a.d: New file.
	* testsuite/ld-x86-64/pr27016a.s: Likewise.
	* testsuite/ld-x86-64/pr27016b.d: Likewise.
	* testsuite/ld-x86-64/pr27016b.s: Likewise.
2020-12-04 18:54:47 -08:00
Alan Modra
726d7d1ecf PR26978, Inconsistency for strong foo@v1 and weak foo@@v1
Prior to this patch
  ld -shared --version-script=pr26979.ver pr26978a.o pr26978b.o
results in
  ld: pr26978b.o: in function `foo_v1':
  (.text+0x0): multiple definition of `foo@v1'
  ld: pr26978b.o:(*IND*+0x0): multiple definition of `foo'
while
  ld -shared --version-script=pr26979.ver pr26978b.o pr26978a.o
results in no error, but some odd dynamic symbols.
  ... 0 NOTYPE  GLOBAL DEFAULT    7 foo@v1
  ... 0 NOTYPE  WEAK   DEFAULT    7 foo@@v1

When linking an undecorated reference to foo against such a shared
library, ld complains about multiple definitions of foo@v1 while gold
creates a dynamic reference to foo@v1.  That results in foo@v1 being
used at runtime.

While we could error in both cases, it is reasonable to say foo@v1 and
foo@@v1 are in fact the same symbol.  (Same name, same version.  The
only real difference is that foo@@v1 satisfies a reference to plain
foo, while foo@v1 does not.)  Just as merging a weak undecorated sym
with a strong sym results in the strong sym prevailing, so should the
strong foo@v1 prevail.  And since there is a definition that satisfies
plain foo, the foo@@v1 variety of dynamic symbol should be emitted at
the foo@v1 value.  That makes the testcase that currently links
continue to produce a shared library, and that shared library can now
be used by both ld and gold with the same runtime behaviour as when
using gold with the odd dynamic symbol library.

bfd/
	PR 26978
	* elflink.c (_bfd_elf_add_default_symbol): Handle the case where
	a new weak sym@@ver should be overridden by an existing sym@ver.
	(elf_link_add_object_symbols): Don't _bfd_elf_add_default_symbol
	for a new weak sym@ver when sym@@ver already exists.
	* linker.c (link_action): Choose MIND for previous indirect,
	current def, rather than MDEF.
	(_bfd_generic_link_add_one_symbol <MIND>): Handle redefinition of
	weak indirect symbol.
ld/
	* testsuite/ld-elf/pr26978a.d,
	* testsuite/ld-elf/pr26978a.s,
	* testsuite/ld-elf/pr26978b.d,
	* testsuite/ld-elf/pr26978b.s: New tests.
2020-12-04 11:06:52 +10:30