Commit Graph

4511 Commits

Author SHA1 Message Date
Alan Modra 5fd104addf Emit a warning when -z relro is unsupported
ld silently accepts -z relro and -z norelro for targets that lack the
necessary GNU_RELRO support.  This patch makes those targets emit a
warning instead, and adds testsuite infrastructure to detect when
relro is unsupported.

binutils/
	* testsuite/config/default.exp (ld_elf_shared_opt): Don't set.
	* testsuite/lib/binutils-common.exp (check_relro_support): New proc.
	(run_dump_test): Use check_relro_support to decide whether to pass
	extra ld option "-z norelro".
ld/
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Omit
	-z relro and -z norelro when target support for GNU_RELRO is lacking.
	(gld${EMULATION_NAME}_before_parse): Ignore RELRO default too.
	* emultempl/aarch64elf.em (gld${EMULATION_NAME}_before_parse): Ignore
	RELRO default when target support for GNU_RELRO is lacking.
	* emultempl/armelf.em (gld${EMULATION_NAME}_before_parse): Likewise.
	* emultempl/linux.em (gld${EMULATION_NAME}_before_parse): Likewise.
	* emultempl/scoreelf.em (gld${EMULATION_NAME}_before_parse): Likewise.
	* testsuite/config/default.exp (ld_elf_shared_opt): Don't set.
	* testsuite/ld-elf/pr16322.d: xfail when no relro support.
	* testsuite/ld-elf/pr22393-1a.d: Likewise.
	* testsuite/ld-elf/pr22393-1b.d: Likewise.
	* testsuite/ld-elf/shared.exp (pr20995-2.so, pr20995-2): Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_tests): Use check_relro_support
	to decide whether to pass extra ld option "-z norelro".
2020-06-19 09:50:20 +09:30
H.J. Lu 00401e65be ld: Suppress warning for unsupported attribute from older GCC
Suppress warning for unsupported attribute from older GCC:

.../ld/testsuite/ld-elf/pr25754-1a.c:9: warning: 'noclone' attribute directive ignored
.../ld/testsuite/ld-elf/pr25754-1a.c:9: warning: 'noclone' attribute directive ignored
ERROR: .../ld/testsuite/ld-elf/pr25754-1a.c: compilation failed
UNRESOLVED: Build pr25754-1a ( )

	* testsuite/ld-elf/linux-x86.exp (check_pr25749a): Append "-w"
	to cflags.
2020-06-17 07:53:19 -07:00
H.J. Lu 22aa1d5119 ld: Require GCC 5 for Build pr25749-1b (-pie -fPIE)
Before GCC 5, Build pr25749-1b (-pie -fPIE) won't trigger the expected
linker error.

	* testsuite/ld-elf/linux-x86.exp: Require GCC 5 for Build
	pr25749-1b (-pie -fPIE).
2020-06-17 07:39:28 -07:00
Alan Modra 5f89899448 Re: Use __asm__ rather than asm in ld testsuite
* testsuite/ld-elf/pr19553c.c: Replace asm with __asm__.
	* testsuite/ld-elfvers/vers27b.c: Likewise.
2020-06-16 22:44:13 +09:30
Alan Modra 07e7fdfd42 Use __asm__ rather than asm in ld testsuite
* testsuite/ld-elf/pr23428.c: Define _DEFAULT_SOURCE.
	* testsuite/ld-elf/indirect1b.c: Replace asm with __asm__.
	* testsuite/ld-elf/indirect2.c: Likewise.
	* testsuite/ld-elf/indirect3b.c: Likewise.
	* testsuite/ld-elf/indirect4b.c: Likewise.
	* testsuite/ld-elf/pr14323-2.c: Likewise.
	* testsuite/ld-elf/pr18720b.c: Likewise.
	* testsuite/ld-elf/pr23428.c: Likewise.
	* testsuite/ld-elfvsb/common.c: Likewise.
	* testsuite/ld-elfvsb/main.c: Likewise.
	* testsuite/ld-elfvsb/sh1.c: Likewise.
	* testsuite/ld-elfvsb/test.c: Likewise.
	* testsuite/ld-pe/aligncomm-1.c: Likewise.
	* testsuite/ld-pe/aligncomm-2.c: Likewise.
	* testsuite/ld-pe/aligncomm-3.c: Likewise.
	* testsuite/ld-pe/aligncomm-4.c: Likewise.
	* testsuite/ld-plugin/pr23958.c: Likewise.
	* testsuite/ld-size/size-1b.c: Likewise.
	* testsuite/ld-size/size-2b.c: Likewise.
	* testsuite/ld-size/size-3a.c: Likewise.
	* testsuite/ld-size/size-3b.c: Likewise.
	* testsuite/ld-size/size-3c.c: Likewise.
	* testsuite/ld-size/size-4b.c: Likewise.
	* testsuite/ld-size/size-5b.c: Likewise.
	* testsuite/ld-size/size-6a.c: Likewise.
	* testsuite/ld-size/size-7a.c: Likewise.
	* testsuite/ld-size/size-8a.c: Likewise.
	* testsuite/ld-size/size-9b.c: Likewise.
	* testsuite/ld-size/size-10b.c: Likewise.
2020-06-16 22:13:20 +09:30
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 1298463902 Unnecessary load_lib in ld testsuite
ld-lib.exp is loaded in config/defaults.exp

	* testsuite/ld-scripts/include.exp: Don't load ld-lib.exp.
	* testsuite/ld-scripts/phdrs3.exp: Likewise.
	* testsuite/ld-scripts/rgn-at.exp: Likewise.
	* testsuite/ld-scripts/rgn-over.exp: Likewise.
	* testsuite/ld-scripts/sort.exp: Likewise.
	* testsuite/ld-discard/discard.exp: Likewise.  Use is_elf_format.
2020-06-15 15:07:13 +09:30
Alan Modra ea4b3731ec PR26103 testcase
PR 26103
	* testsuite/ld-linkonce/ref1.s,
	* testsuite/ld-linkonce/ref2.s,
	* testsuite/ld-linkonce/sym1.s,
	* testsuite/ld-linkonce/sym2.s,
	* testsuite/ld-linkonce/sym3.s: New test files.
	* testsuite/ld-linkonce/linkonce.exp: Run tests for PE too.
	Add pr26103 test.  Remove unnecessary load_lib.
2020-06-15 12:11:27 +09:30
Alan Modra cda58d5f97 ld-linkonce test
* testsuite/ld-linkonce/zeroeh_x.s: Rename from x.s.
	* testsuite/ld-linkonce/zeroeh_y.s: Rename from y.s.
	* testsuite/ld-linkonce/zeroehl32.d: Adjust for renaming.  Support
	big-endian output.  Run for powerpc.
2020-06-15 12:08:33 +09:30
Alan Modra 382264181d Run certain ld-plugun lto tests only for ELF
lto-6.c refers to _etext, pr12760b.c has a .gnu.warning section,
the pr23818 test uses readelf, and pr23958.c has a .symver directive.

	* testsuite/ld-plugin/lto.exp (lto_link_tests): Move lto-6,
	pr12760, pr23818 and pr23958 tests to..
	(lto_link_elf_tests): ..here.
2020-06-11 18:22:42 +09:30
Nick Clifton 928055a369 Fix a compile time warning in the linker testsuite when compiling using clang.
* testsuite/ld-elf/pr26094-1b.c (main): Change return type to
	int.
2020-06-11 09:27:41 +01:00
Alan Modra 84df1f9dcb Fix x86 ld testsuite fails with glibc < 2.28
* testsuite/ld-elf/linux-x86.exp: Build tests when non-native.
	(check_pr25749b): Add optional args.  Set expected pass file
	from args.  Run -1b and -2a tests with passall.out.
	* testsuite/ld-elf/passall.out: New file.
	* testsuite/ld-elf/pr25749-1.c: Adjust to pass with older glibc.
	* testsuite/ld-elf/pr25749-2.c: Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use
	regexp_diff to compare expected output from running binary.
2020-06-10 22:19:07 +09:30
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 a61e306070 PR26065, ld/testsuite/ld-elf symbolic tests dl4e and dl4f fail
PR 26065
	* testsuite/ld-elf/shared.exp: Compile dl4main.c -fPIC.
	(dl4e, dl4f): Expect dl4a.out.
	* testsuite/ld-elf/dl4e.out: Delete.
2020-06-09 17:34:52 +09:30
H.J. Lu 597344c9a4 ld: Pass $LFLAGS to PR ld/21703 shared test
$LFLAGS is needed for -shared test.  This fixes

FAIL: PR ld/21703 shared

for tic6x-*-elf.

	* testsuite/ld-elf/shared.exp: Pass $LFLAGS to PR ld/21703
	shared test.
2020-06-07 14:50:01 -07:00
H.J. Lu 656e4a22f3 ld: Xfail pr20995 and pr20995-2 for tic6x-*-*
Xfail pr20995 and pr20995-2 for tic6x-*-* since GNU_RELRO is not
supported.

	* testsuite/ld-elf/shared.exp: Xfail pr20995/pr20995-2 for
	tic6x-*-*.
2020-06-07 11:52:18 -07:00
H.J. Lu 0fd91d25e2 pr11304.d: Skip tic6x-*-elf
Since address 0x800000 overlaps with .heap section on tic6x-*-elf, skip
pr11304.d on tic6x-*-elf.

	* testsuite/ld-elf/pr11304.d: Skip tic6x-*-elf.
2020-06-07 08:47:02 -07:00
Alan Modra 1fc47f8089 Re: PR13802, referred common symbol not UNDefined
It looks like this one was previously just swept under the rug.  Prior
to git commit c4b126b87a, the arm backend emitted an absolute
dynamic symbol "foo" with value zero for what was originally a common
symbol.  That was just wrong.

The patch also removes an xfail for bfin-linux-uclibc.

	PR 13802
	* testsuite/ld-elf/comm-data.exp: Don't xfail arm or bfin-linux.
2020-06-06 14:44:32 +09:30
Alan Modra 070558eb0d ld -plugin options when plugins are disabled
This patch makes ld accept and ignore -plugin options when configured
with --disable-plugins.  The idea is to allow using a linker built
without plugin support with a gcc built with plugin support.  Quite
obviously such a combination won't work if using LTO, but gcc has a
habit of passing a bunch of -plugin and -plugin-opt arguments to ld
even when not generating or linking LTO objects.

Why do I want to do this?  Well, it lets me and other binutils
developers answer the question as to whether plugin support breaks
binutils in some areas.  Which it does for some targets.

	* lexsup.c (ld_options): Accept -plugin and -plugin-opt when
	!ENABLE_PLUGINS.
	* testsuite/lib/ld-lib.exp (check_plugin_api_available): Adjust.
2020-06-06 11:28:08 +09:30
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
Nelson Chu 3fc6c3dc2a RISC-V: Don't generate the ELF privilege attributes when no CSR are used.
gas/
	* config/tc-riscv.c (explicit_csr): New static boolean.
	Used to indicate CSR are explictly used.
	(riscv_ip): Set explicit_csr to TRUE if any CSR is used.
	(riscv_write_out_attrs): If we already have set elf priv
	attributes, then generate them.  Otherwise, don't generate
	them when no CSR are used.

	* testsuite/gas/riscv/attribute-01.d: Remove the priv attributes.
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-06.d: Likewise.
	* testsuite/gas/riscv/attribute-07.d: Likewise.
	* testsuite/gas/riscv/attribute-08.d: Likewise.
	* testsuite/gas/riscv/attribute-09.d: Likewise.
	* testsuite/gas/riscv/attribute-10.d: Likewise.
	* testsuite/gas/riscv/attribute-unknown.d: Likewise.
	* testsuite/gas/riscv/attribute-11.s: New testcase.
	* testsuite/gas/riscv/attribute-11.d: New testcase.  The CSR is
	used, so we should output the ELF priv attributes.
	* testsuite/gas/riscv/attribute-12.d: New testcase.  The CSR is
	used, so output the priv attributes according to the -mpriv-spec.
	* testsuite/gas/riscv/attribute-13.d: New testcase.  The CSR isn't
	used, so ignore the -mpriv-spec setting.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Likewise.
	* 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-stack-align.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise.
	* testsuite/ld-riscv-elf/call-relax.d: Add -mno-arch-attr.
2020-06-05 12:14:44 +08: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 e2c8dab6ae tcl global directive outside proc body does nothing (ld)
* testsuite/config/default.exp: Remove global directive outside
	proc body.
	* testsuite/ld-bootstrap/bootstrap.exp: Likewise.
	* testsuite/ld-elf/compress.exp: Likewise.
	* testsuite/ld-elf/elf.exp: Likewise.
	* testsuite/ld-elf/exclude.exp: Likewise.
	* testsuite/ld-elf/frame.exp: Likewise.
	* testsuite/ld-elf/indirect.exp: Likewise.
	* testsuite/ld-elf/linux-x86.exp: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elf/tls.exp: Likewise.
	* testsuite/ld-elf/tls_common.exp: Likewise.
	* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-frv/fdpic.exp: Likewise.
	* testsuite/ld-frv/tls.exp: Likewise.
	* testsuite/ld-gc/gc.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-i386/no-plt.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-mips-elf/mips-elf-flags.exp: Likewise.
	* testsuite/ld-nios2/nios2.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-plugin/plugin.exp: Likewise.
	* testsuite/ld-powerpc/export-class.exp: Likewise.
	* testsuite/ld-scripts/align.exp: Likewise.
	* testsuite/ld-scripts/crossref.exp: Likewise.
	* testsuite/ld-scripts/defined.exp: Likewise.
	* testsuite/ld-scripts/overlay-size.exp: Likewise.
	* testsuite/ld-scripts/provide.exp: Likewise.
	* testsuite/ld-scripts/weak.exp: Likewise.
	* testsuite/ld-selective/selective.exp: Likewise.
	* testsuite/ld-sh/rd-sh.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-x86-64/mpx.exp: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2020-06-04 16:11:19 +09:30
Alan Modra a0c0ad5670 ld-dynamic test fixes
* testsuite/ld-dynamic/export-dynamic-symbol-2.d: Match output for
	mips-sgi-irix6.
	* testsuite/ld-dynamic/export-dynamic-symbol-glob.d: Likewise.
	* testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: Likewise.
	* testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: Likewise.
	* testsuite/ld-dynamic/export-dynamic-symbol.exp: Exclude targets
	with poor PIE support.
2020-06-04 14:13:04 +09:30
Alan Modra 60f207b4a9 ld testsuite fails with default-PIE compiler
* testsuite/ld-plugin/lto.exp (pr12758.exe): Add NOPIE_LDFLAGS.
	* testsuite/ld-unique/unique.exp: Add NOPIE_LDFLAGS to unique
	executable and dynamic executable tests.
2020-06-04 10:20:48 +09:30
H.J. Lu 1949ad044a ld: Pass -fno-sanitize=all to tests with linker
When binutils is compiled with -fsanitize=undefined, many tests with
linker, instead of $CC, fail with undefined symbol references to sanitize
library.  Define NOSANTIZE_CFLAGS to -fno-sanitize=all if target compiler
supports it and compile such tests with $NOSANTIZE_CFLAGS.

	* testsuite/config/default.exp (NOSANTIZE_CFLAGS): New.
	* testsuite/ld-elf/linux-x86.exp: Add $NOSANTIZE_CFLAGS to
	tests with run_ld_link_exec_tests.
	* testsuite/ld-elf/shared.exp: Add $NOSANTIZE_CFLAGS to tests
	with run_ld_link_tests.
	* testsuite/ld-elf/tls.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Add $NOSANTIZE_CFLAGS to
	tests with ld_link.
	* testsuite/ld-gc/gc.exp: Add $NOSANTIZE_CFLAGS to cflags.
	* testsuite/ld-plugin/lto.exp: Add $NOSANTIZE_CFLAGS to tests
	with run_ld_link_tests.a
	* testsuite/ld-plugin/plugin.exp: Append $NOSANTIZE_CFLAGS to
	CFLAGS.
	* testsuite/ld-selective/selective.exp: Add $NOSANTIZE_CFLAGS
	to cflags and cxxflags.
	* testsuite/ld-srec/srec.exp: Append $NOSANTIZE_CFLAGS to CC
	and CXX.
	* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Updated for
	-fsanitize=undefined.
	* testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Add $NOSANTIZE_CFLAGS to
	tests with run_cc_link_tests and run_ld_link_tests.
2020-06-03 06:57:19 -07:00
Fangrui Song 37a141bfed ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list
--export-dynamic-symbol-list is like a dynamic list, but without
the symbolic property for unspecified symbols.

When creating an executable, --export-dynamic-symbol-list is treated
like --dynamic-list.

When creating a shared library, it is treated like --dynamic-list if
-Bsymbolic or --dynamic-list are used,  otherwise, it is ignored, so
that references to matched symbols will not be bound to the definitions
within the shared library.

	PR ld/25910
	* NEWS: Mention --export-dynamic-symbol[-list].
	* ld.texi: Document --export-dynamic-symbol[-list].
	* ldgram.y: Pass current_dynamic_list_p to
	lang_append_dynamic_list.
	* ldlang.c (current_dynamic_list_p): New.
	(ang_append_dynamic_list): Updated to take a pointer to
	struct bfd_elf_dynamic_list * argument instead of using
	link_info.dynamic_list.
	(lang_append_dynamic_list_cpp_typeinfo): Pass
	&link_info.dynamic_list to ang_append_dynamic_list.
	(lang_append_dynamic_list_cpp_new): Likewise.
	* ldlang.h (current_dynamic_list_p): New.
	(lang_append_dynamic_list): Add a pointer to
	struct bfd_elf_dynamic_list * argument.
	* ldlex.h (option_values): Add OPTION_EXPORT_DYNAMIC_SYMBOL and
	OPTION_EXPORT_DYNAMIC_SYMBOL_LIST.
	* lexsup.c (ld_options): Add entries for
	OPTION_EXPORT_DYNAMIC_SYMBOL and
	OPTION_EXPORT_DYNAMIC_SYMBOL_LIST.
	(parse_args): Handle --export-dynamic-symbol and
	--export-dynamic-symbol-list.
	* testsuite/ld-dynamic/export-dynamic-symbol-1.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol-2.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol-glob.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol-list-1.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: New.
	* testsuite/ld-dynamic/export-dynamic-symbol.exp: New.
	* testsuite/ld-dynamic/export-dynamic-symbol.s: New.
	* testsuite/ld-dynamic/foo-bar.list: New.
	* testsuite/ld-dynamic/foo.list: New.
	* testsuite/ld-dynamic/foo.s: New.
	* testsuite/ld-dynamic/fstar.list: New.
	* testsuite/ld-elf/dlempty.list: New.
	* testsuite/ld-elf/shared.exp: Add tests for
	--export-dynamic-symbol and --export-dynamic-symbol-list.
2020-06-03 06:37:39 -07:00
Jan Beulich bbd2d6bf2d ld: fix ld-elf/linux-x86.exp for r/o source tree
Since the copying ofthe individual files gets done more than once, make
sure the destinations can be copied to on subsequent copying attempts.
2020-06-03 11:54:11 +02:00
Nick Clifton a87e1817a4 Have the linker fail if any attempt to link in an executable is made.
PR 26047
	* ldelf.c (ldelf_after_open): Fail if attempting to link one
	executable into another.  Ensure that the test is made for all
	forms of linking.
2020-05-28 17:43:21 +01:00
Nick Clifton a3fc941881 Stop the linker from accepting executable ELF files as inputs to other links.
PR 26047
	* ldelf.c (ldelf_after_open): Fail if attempting to link one
	executable into another.
2020-05-28 16:43:01 +01:00
H.J. Lu 6f028f3c07 ld: Mention --enable-textrel-check=yes is default for Linux/x86 targets
* NEWS: Mention --enable-textrel-check=yes is default for
	Linux/x86 targets.
2020-05-28 04:38:05 -07:00
H.J. Lu fa6ecf9405 ld: Enable --warn-textrel by default for Linux/x86 targets
* configure.tgt (ac_default_ld_textrel_check): Set to if unset
	for Linux/x86 targets.
2020-05-28 04:27:30 -07:00
H.J. Lu b32632c499 ld: Add --enable-textrel-check=[no|yes|warning|error]
Add a configure option, --enable-textrel-check=[no|yes|warning|error],
to decide what ELF linker should do by default with DT_TEXTREL in an
executable or shared library.

	PR ld/20824
	* NEWS: Mention --enable-textrel-check=[no|yes|warning|error].
	* configure.ac: Add --enable-textrel-check=[no|yes|warning|error].
	(DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.
	(DEFAULT_LD_TEXTREL_CHECK_WARNING): Likewise.
	* ldmain.c (main): Initialize link_info.textrel_check to
	DEFAULT_LD_TEXTREL_CHECK.
	* lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.
	* config.in: Regenerated.
	* configure: Likewise.
2020-05-28 04:21:16 -07:00
Nick Clifton 72a3b182e1 Linker: Remove support for -Map= with an empty argument.
* lexsup.c (parse_args): Generate an error if a name is not
	provided to the -Map option.
	(ld_options): Mention that the -Map option supports a directory
	name as an argument.
	* NEWS: Remove mention of support for an empty string as an
	argument to -Map.
	* ld.texi: Likewise.
2020-05-28 10:51:29 +01:00
Hans-Peter Nilsson 2a37823bfe PR ld/22909 amendment; don't xfail ld-elf/pr19539.d for cris*-*-*.
Noticed by my autotester covering cris-axis-linux-gnu:
...
Running <x>/src/ld/testsuite/ld-elf/elf.exp ...
XPASS: ld-elf/pr19539
...

This was apparently as intended, so I'm just adjusting the xfail.

	PR ld/22909
	* testsuite/ld-elf/pr19539.d: Don't xfail for cris*-*-*.
2020-05-27 23:25:53 +02:00
Nick Clifton 198204a7f0 [PATCH] allow empty string as argument to -Map
* lexsup.c (parse_args): If the map filename is defined but empty
	create a name based upon the output file name.  If the name is
	defined but refers to a directory create a file inside the
	directory based on the output file name.
	* ld.texi: Document the new feature.
	* testsuite/ld-script/map-address.exp: Add test of new feature.
	* NEWS: Mention the new feature.
2020-05-27 17:49:17 +01:00
H.J. Lu a6dbf402de ld: Add --warn-textrel and obsolete --warn-shared-textrel
--warn-shared-textrel and -z text apply to both shared object and PIE.
Add --warn-textrel and obsolete --warn-shared-textrel.  Consolidate
--warn-textrel and -z text/notext/textoff implementation.

bfd/

	PR ld/22909
	* elflink.c (bfd_elf_final_link): Use bfd_link_textrel_check.
	Check bfd_link_dll when issue a DT_TEXTREL warning.
	* elfxx-x86.c (maybe_set_textrel): Likewise.
	(_bfd_x86_elf_size_dynamic_sections): Likewise.

include/

	PR ld/22909
	* bfdlink.h (textrel_check_method): New enum.
	(bfd_link_textrel_check): New.
	(bfd_link_info): Replace warn_shared_textrel and error_textrel
	with textrel_check.

ld/

	PR ld/22909
	* NEWS: Mention --warn-textrel.
	* ld.texi: Update -z text/notext/textoff.  Add --warn-textrel.
	Remove --warn-shared-textrel.
	* ldlex.h (option_values): Rename OPTION_WARN_SHARED_TEXTREL to
	OPTION_WARN_TEXTREL.
	* lexsup.c (ld_options): Add --warn-textrel.  Obsolete
	--warn-shared-textrel.
	(parse_args): Updated.
	(elf_shlib_list_options): Check link_info.textrel_check.
	* emultempl/elf.em: Updated.
	* testsuite/ld-elf/pr19539.d: Replace -z notext with
	--warn-textrel.  Expect a warning.
	* testsuite/ld-i386/warn1.d: Update expected warning.
2020-05-27 04:54:10 -07:00
H.J. Lu 368584aa8c ld: Skip some x86 ifunc tests for lynxos and nto
On lynxos and nto:

regexp_diff match failure
regexp "^Relocation section '.rel(a|).plt' at offset 0x[0-9a-f]+ contains 1 entry:$"
line   "Relocation section '.rel.dyn' at offset 0x74 contains 1 entry:"
FAIL: ld-ifunc/ifunc-23a-x86

	* testsuite/ld-ifunc/ifunc-23a-x86.d: Skip *-*-lynxos *-*-nto*.
	* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
2020-05-26 14:25:19 -07:00
H.J. Lu 07e0bb0fb2 ld-x86-64: Pass -z notext to linker for tests with DT_TEXTREL
* testsuite/ld-x86-64/x86-64.exp: Pass -z notext to linker.
2020-05-25 06:45:13 -07:00
H.J. Lu af2c48d854 ld: Pass -z notext to linker for tests with DT_TEXTREL
Some linker tests need DT_TEXTREL.  Pass -z notext to linker for these
tests so that they will pass with DT_TEXTREL check defaulting to warning
or error.

	* testsuite/ld-elf/eh6.d: Pass -z notext to linker.
	* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
	* testsuite/ld-elf/pr19539.d: Likewise.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-i386/nogot1.d: Likewise.
	* testsuite/ld-i386/pr19539.d: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-i386/undefweaka.d: Likewise.
	* testsuite/ld-i386/undefweakb.d: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-unique/unique.exp: Likewise.
	* testsuite/ld-x86-64/pie1.d: Likewise.
	* testsuite/ld-x86-64/pr19539a.d: Likewise.
	* testsuite/ld-x86-64/pr19539b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2020-05-25 04:54:50 -07:00
Fangrui Song bb68f22c8e ld: Handle --dynamic-list* before -Bsymbolic -Bsymbolic-functions
--dynamic-list* should work both before and after -Bsymbolic and
-Bsymbolic-functions.

	PR ld/26018
	* lexsup.c (parse_args): Simplify.
	* testsuite/ld-elf/dl4e.out: New.
	* testsuite/ld-elf/shared.exp: Updated for PR ld/26018 tests.
2020-05-24 04:47:46 -07:00
H.J. Lu 309cae1f7b ld: Add -Bsymbolic-functions tests
PR ld/26018
	* testsuite/ld-i386/i386.exp: Add a -Bsymbolic-functions test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr26018.d: New file.
	* testsuite/ld-x86-64/pr26018.d: Likewise.
	* testsuite/ld-x86-64/pr26018.s: Likewise.
2020-05-23 20:56:31 -07:00
Alan Modra 5e2ab61254 Replace "if (x) free (x)" with "free (x)", ld
* deffilep.y: Replace "if (x) free (x)" with "free (x)" thoughout.
	* emultempl/elf.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldelf.c: Likewise.
	* ldfile.c: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* lexsup.c: Likewise.
	* pe-dll.c: Likewise.
2020-05-21 10:45:33 +09:30
Nelson Chu 8f595e9b4f [PATCH v2 0/9] RISC-V: Support version controling for ISA standard extensions and CSR
1. Remove the -mriscv-isa-version and --with-riscv-isa-version options.
We can still use -march to choose the version for each extensions, so there is
no need to add these.

2. Change the arguments of options from [1p9|1p9p1|...] to [1.9|1.9.1|...].
Unlike the architecture string has specified by spec, ther is no need to do
the same thing for options.

3. Spilt the patches to reduce the burdens of review.

[PATCH 3/7] RISC-V: Support new GAS options and configure options to set ISA versions
to
[PATCH v2 3/9] RISC-V: Support GAS option -misa-spec to set ISA versions
[PATCH v2 4/9] RISC-V: Support configure options to set ISA versions by default.

[PATCH 4/7] RISC-V: Support version checking for CSR according to privilege version.
to
[PATCH v2 5/9] RISC-V: Support version checking for CSR according to privilege spec version.
[PATCH v2 6/9] RISC-V: Support configure option to choose the privilege spec version.

4. Use enum class rather than string to compare the choosen ISA spec in opcodes/riscv-opc.c.
The behavior is same as comparing the choosen privilege spec.

include	* opcode/riscv.h: Include "bfd.h" to support bfd_boolean.
	(enum riscv_isa_spec_class): New enum class.  All supported ISA spec
	belong to one of the class
	(struct riscv_ext_version): New structure holds version information
	for the specific ISA.
	* opcode/riscv-opc.h (DECLARE_CSR): There are two version information,
	define_version and abort_version.  The define_version means which
	privilege spec is started to define the CSR, and the abort_version
	means which privilege spec is started to abort the CSR.  If the CSR is
	valid for the newest spec, then the abort_version should be
	PRIV_SPEC_CLASS_DRAFT.
	(DECLARE_CSR_ALIAS): Same as DECLARE_CSR, but only for the obselete CSR.
	* opcode/riscv.h (enum riscv_priv_spec_class): New enum class.  Define
	the current supported privilege spec versions.
	(struct riscv_csr_extra): Add new fields to store more information
	about the CSR.  We use these information to find the suitable CSR
	address when user choosing a specific privilege spec.

binutils * dwarf.c: Updated since DECLARE_CSR is changed.

opcodes	* riscv-opc.c (riscv_ext_version_table): The table used to store
	all information about the supported spec and the corresponding ISA
	versions.  Currently, only Zicsr is supported to verify the
	correctness of Z sub extension settings.  Others will be supported
	in the future patches.
	(struct isa_spec_t, isa_specs): List for all supported ISA spec
	classes and the corresponding strings.
	(riscv_get_isa_spec_class): New function.  Get the corresponding ISA
	spec class by giving a ISA spec string.
	* riscv-opc.c (struct priv_spec_t): New structure.
	(struct priv_spec_t priv_specs): List for all supported privilege spec
	classes and the corresponding strings.
	(riscv_get_priv_spec_class): New function.  Get the corresponding
	privilege spec class by giving a spec string.
	(riscv_get_priv_spec_name): New function.  Get the corresponding
	privilege spec string by giving a CSR version class.
	* riscv-dis.c: Updated since DECLARE_CSR is changed.
	* riscv-dis.c: Add new disassembler option -Mpriv-spec to dump the CSR
	according to the chosen version.  Build a hash table riscv_csr_hash to
	store the valid CSR for the chosen pirv verison.  Dump the direct
	CSR address rather than it's name if it is invalid.
	(parse_riscv_dis_option_without_args): New function.  Parse the options
	without arguments.
	(parse_riscv_dis_option): Call parse_riscv_dis_option_without_args to
	parse the options without arguments first, and then handle the options
	with arguments.  Add the new option -Mpriv-spec, which has argument.
	* riscv-dis.c (print_riscv_disassembler_options): Add description
	about the new OBJDUMP option.

ld	* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated
        priv attributes according to the -mpriv-spec option.
	* 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-priv-spec-a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-stack-align.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise.

bfd 	* elfxx-riscv.h (riscv_parse_subset_t): Add new callback function
	get_default_version.  It is used to find the default version for
	the specific extension.
	* elfxx-riscv.c (riscv_parsing_subset_version): Remove the parameters
	default_major_version and default_minor_version.  Add new bfd_boolean
	parameter *use_default_version.  Set it to TRUE if we need to call
	the callback rps->get_default_version to find the default version.
	(riscv_parse_std_ext): Call rps->get_default_version if we fail to find
	the default version in riscv_parsing_subset_version, and then call
	riscv_add_subset to add the subset into subset list.
	(riscv_parse_prefixed_ext): Likewise.
	(riscv_std_z_ext_strtab): Support Zicsr extensions.
	* elfnn-riscv.c (riscv_merge_std_ext): Use strcasecmp to compare the
	strings rather than characters.
	riscv_merge_arch_attr_info): The callback function get_default_version
	is only needed for assembler, so set it to NULL int the linker.
	* elfxx-riscv.c (riscv_estimate_digit): Remove the static.
	* elfxx-riscv.h: Updated.

gas	* testsuite/gas/riscv/priv-reg-fail-read-only-01.s: Updated.
	* config/tc-riscv.c (default_arch_with_ext, default_isa_spec):
	Static variables which are used to set the ISA extensions. You can
	use -march (or ELF build attributes) and -misa-spec to set them,
	respectively.
	(ext_version_hash): The hash table used to handle the extensions
	with versions.
	(init_ext_version_hash): Initialize the ext_version_hash according
	to riscv_ext_version_table.
	(riscv_get_default_ext_version): The callback function of
	riscv_parse_subset_t.  According to the choosed ISA spec,
	get the default version for the specific extension.
	(riscv_set_arch): Set the callback function.
	(enum options, struct option md_longopts): Add new option -misa-spec.
	(md_parse_option): Do not call riscv_set_arch for -march.  We will
	call it later in riscv_after_parse_args.  Call riscv_get_isa_spec_class
	to set default_isa_spec class.
	(riscv_after_parse_args): Call init_ext_version_hash to initialize the
	ext_version_hash, and then call riscv_set_arch to set the architecture
	with versions according to default_arch_with_ext.
	* testsuite/gas/riscv/attribute-02.d: Set 0p0 as default version for
	x extensions.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-09.d: New testcase.  For i-ext, we
	already set it's version to 2p1 by march, so no need to use the default
	2p2 version.  For m-ext, we do not set the version by -march and ELF arch
	attribute, so set the default 2p0 to it.  For zicsr, it is not defined in
	ISA spec 2p2, so set 0p0 to it.
	* testsuite/gas/riscv/attribute-10.d: New testcase.  The version of
	zicsr is 2p0 according to ISA spec 20191213.
	* config/tc-riscv.c (DEFAULT_RISCV_ARCH_WITH_EXT)
	(DEFAULT_RISCV_ISA_SPEC): Default configure option settings.
	You can set them by configure options --with-arch and
	--with-isa-spec, respectively.
	(riscv_set_default_isa_spec): New function used to set the
	default ISA spec.
	(md_parse_option): Call riscv_set_default_isa_spec rather than
	call riscv_get_isa_spec_class directly.
	(riscv_after_parse_args): If the -isa-spec is not set, then we
	set the default ISA spec according to DEFAULT_RISCV_ISA_SPEC by
	calling riscv_set_default_isa_spec.
	* testsuite/gas/riscv/attribute-01.d: Add -misa-spec=2.2, since
	the --with-isa-spec may be set to different ISA spec.
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-06.d: Likewise.
	* testsuite/gas/riscv/attribute-07.d: Likewise.
	* configure.ac: Add configure options, --with-arch and
	--with-isa-spec.
	* configure: Regenerated.
	* config.in: Regenerated.
	* config/tc-riscv.c (default_priv_spec): Static variable which is
	used to check if the CSR is valid for the chosen privilege spec. You
	can use -mpriv-spec to set it.
	(enum reg_class): We now get the CSR address from csr_extra_hash rather
	than reg_names_hash.  Therefore, move RCLASS_CSR behind RCLASS_MAX.
	(riscv_init_csr_hashes): Only need to initialize one hash table
	csr_extra_hash.
	(riscv_csr_class_check): Change the return type to void.  Don't check
	the ISA dependency if -mcsr-check isn't set.
	(riscv_csr_version_check): New function.  Check and find the CSR address
	from csr_extra_hash, according to default_priv_spec.  Report warning
	for the invalid CSR if -mcsr-check is set.
	(reg_csr_lookup_internal): Updated.
	(reg_lookup_internal): Likewise.
	(md_begin): Updated since DECLARE_CSR and DECLARE_CSR_ALIAS are changed.
	(enum options, struct option md_longopts): Add new GAS option -mpriv-spec.
	(md_parse_option): Call riscv_set_default_priv_version to set
	default_priv_spec.
	(riscv_after_parse_args): If -mpriv-spec isn't set, then set the default
	privilege spec to the newest one.
	(enum riscv_csr_class, struct riscv_csr_extra): Move them to
	include/opcode/riscv.h.
	* testsuite/gas/riscv/priv-reg-fail-fext.d: This test case just want
	to check the ISA dependency for CSR, so fix the spec version by adding
	-mpriv-spec=1.11.
	* testsuite/gas/riscv/priv-reg-fail-fext.l: Likewise.  There are some
	version warnings for the test case.
	* gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.d: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.l: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.d: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.d: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.l: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.d: New test case.
	Check whether the CSR is valid when privilege version 1.9 is choosed.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.l: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: New test case.
	Check whether the CSR is valid when privilege version 1.9.1 is choosed.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.l: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.d: New test case.
	Check whether the CSR is valid when privilege version 1.10 is choosed.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.l: Likewise.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.d: New test case.
	Check whether the CSR is valid when privilege version 1.11 is choosed.
	* gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.l: Likewise.
	* config/tc-riscv.c (DEFAULT_RISCV_ISA_SPEC): Default configure option
	setting.  You can set it by configure option --with-priv-spec.
	(riscv_set_default_priv_spec): New function used to set the default
	privilege spec.
	(md_parse_option): Call riscv_set_default_priv_spec rather than
	call riscv_get_priv_spec_class directly.
	(riscv_after_parse_args): If -mpriv-spec isn't set, then we set the
	default privilege spec according to DEFAULT_RISCV_PRIV_SPEC by
	calling riscv_set_default_priv_spec.
	* testsuite/gas/riscv/csr-dw-regnums.d: Add -mpriv-spec=1.11, since
	the --with-priv-spec may be set to different privilege spec.
	* testsuite/gas/riscv/priv-reg.d: Likewise.
	* configure.ac: Add configure option --with-priv-spec.
	* configure: Regenerated.
	* config.in: Regenerated.
	* config/tc-riscv.c (explicit_attr): Rename explicit_arch_attr to
	explicit_attr.  Set it to TRUE if any ELF attribute is found.
	(riscv_set_default_priv_spec): Try to set the default_priv_spec if
	the priv attributes are set.
	(md_assemble): Set the default_priv_spec according to the priv
	attributes when we start to assemble instruction.
	(riscv_write_out_attrs): Rename riscv_write_out_arch_attr to
	riscv_write_out_attrs.  Update the arch and priv attributes.  If we
	don't set the corresponding ELF attributes, then try to output the
	default ones.
	(riscv_set_public_attributes): If any ELF attribute or -march-attr
	options is set (explicit_attr is TRUE), then call riscv_write_out_attrs
	to update the arch and priv attributes.
	(s_riscv_attribute): Make sure all arch and priv attributes are set
	before any instruction.
	* testsuite/gas/riscv/attribute-01.d: Update the priv attributes if any
	ELF attribute or -march-attr is set.  If the priv attributes are not
	set, then try to update them by the default setting (-mpriv-spec or
	--with-priv-spec).
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-06.d: Likewise.
	* testsuite/gas/riscv/attribute-07.d: Likewise.
	* testsuite/gas/riscv/attribute-08.d: Likewise.
	* testsuite/gas/riscv/attribute-09.d: Likewise.
	* testsuite/gas/riscv/attribute-10.d: Likewise.
	* testsuite/gas/riscv/attribute-unknown.d: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.  Also, the priv spec
	set by priv attributes must be supported.
	* testsuite/gas/riscv/attribute-05.s: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-version-1p9.d: Likewise.  Updated
	priv attributes according to the -mpriv-spec option.
	* testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-version-1p10.d: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-version-1p11.d: Likewise.
	* testsuite/gas/riscv/priv-reg.d: Removed.
	* testsuite/gas/riscv/priv-reg-version-1p9.d: New test case.  Dump the
	CSR according to the priv spec 1.9.
	* testsuite/gas/riscv/priv-reg-version-1p9p1.d: New test case.  Dump the
	CSR according to the priv spec 1.9.1.
	* testsuite/gas/riscv/priv-reg-version-1p10.d: New test case.  Dump the
	CSR according to the priv spec 1.10.
	* testsuite/gas/riscv/priv-reg-version-1p11.d: New test case.  Dump the
	CSR according to the priv spec 1.11.
	* config/tc-riscv.c (md_show_usage): Add descriptions about
	the new GAS options.
	* doc/c-riscv.texi: Likewise.
2020-05-20 17:22:48 +01:00
Alan Modra 7b958a48e1 PR25993, read of freed memory
ldmain.c:add_archive_element copies file name pointers from the bfd to
a lang_input_statement_type.
  input->filename = abfd->filename;
  input->local_sym_name = abfd->filename;
This results in stale pointers when twiddling the bfd filename in
places like the pe ld after_open.  So don't free the bfd filename,
and make copies using bfd_alloc memory that won't result in small
memory leaks that annoy memory checkers.

	PR 25993
bfd/
	* archive.c (_bfd_get_elt_at_filepos): Don't strdup filename,
	use bfd_set_filename.
	* elfcode.h (_bfd_elf_bfd_from_remote_memory): Likewise.
	* mach-o.c (bfd_mach_o_fat_member_init): Likewise.
	* opncls.c (bfd_fopen, bfd_openstreamr, bfd_openr_iovec, bfd_openw),
	(bfd_create): Likewise.
	(_bfd_delete_bfd): Don't free filename.
	(bfd_set_filename): Copy filename param to bfd_alloc'd memory,
	return pointer to the copy or NULL on alloc fail.
	* vms-lib.c (_bfd_vms_lib_get_module): Free newname and test
	result of bfd_set_filename.
	* bfd-in2.h: Regenerate.
gdb/
	* solib-darwin.c (darwin_bfd_open): Don't strdup pathname for
	bfd_set_filename.
	* solib-aix.c (solib_aix_bfd_open): Use std::string for name
	passed to bfd_set_filename.
	* symfile-mem.c (add_vsyscall_page): Likewise for string
	passed to symbol_file_add_from_memory.
	(symbol_file_add_from_memory): Make name param a const char* and
	don't strdup.
ld/
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Don't copy
	other_bfd_filename for bfd_set_filename, and test result of
	bfd_set_filename call.  Don't create a new is->filename, simply
	copy from bfd filename.  Free new_name after bfd_set_filename.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
2020-05-20 11:43:50 +09:30
Siddhesh Poyarekar 7e05773767 [PATCH v3] aarch64: Emit jump slot for conditional branch to undefined symbols
The linker silently writes out a conditional branch to 0 if the
target symbol in R_AARCH64_CONDBR19 or R_AARCH64_TSTBR14 relocations is
undefined.  Emit a PLT instead so that behaviour is the same for these
relocations as the llvm linker.

The special behaviour for undefined weak symbols, where conditional
branches to such symbols result in a branch unto themselves, has been
retained.  This is because the weak-undefined.s test explicitly checks
for that, leading me to conclude that it's expected behaviour.

bfd	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Club
	BFD_RELOC_AARCH64_BRANCH19 and BFD_RELOC_AARCH64_TSTBR14
	cases with BFD_RELOC_AARCH64_JUMP26.
	(elfNN_aarch64_check_relocs): Likewise.

ld	* testsuite/ld-aarch64/aarch64-elf.exp: New test
	emit-relocs-560.
	* testsuite/ld-aarch64/emit-relocs-560.d: New file.
	* testsuite/ld-aarch64/emit-relocs-560.s: New file.
2020-05-19 11:07:52 +01:00
Alan Modra 607b483327 Use bfd_get_filename throughout ld
* emultempl/beos.em (sort_by_file_name): Use bfd_get_filename
	rather than accessing bfd->filename directly.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/spuelf.em (embedded_spu_file): Likewise.
	* ldlang.c (input_statement_is_archive_path, wild_sort),
	(check_excluded_libs): Likewise.
	* ldmain.c (add_archive_element): Likewise.
	* ldmisc.c (vfinfo): Likewise.
	* pe-dll.c (auto_export, generate_edata, pe_create_import_fixup),
	(pe_dll_generate_implib, pe_process_import_defs): Likewise.
	* plugin.c (plugin_object_p): Likewise.
2020-05-19 12:57:15 +09:30