Commit Graph

4917 Commits

Author SHA1 Message Date
Nick Clifton
91896b4d6a Stop the linker from complaining about RWX segments in sparc-solaris targets.
PR 29411
	* configure.tgt (ac_default_ld_warn_rwx_segments): Disable for
	sparc-solaris configurations.
2022-07-26 14:25:33 +01:00
Nick Clifton
0bd0932314 Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
Nick Clifton
ed1c7ad8e3 Disable execstack and rwx segments warnings for MIPS targets.
PR 29263
	* configure.ac: Move HPPA specific code from here...
	* configure.tgt: ... to here.  Add similar code for MIPS.
	Move code for CRIS, MIPS and HPPA to block at start of file.
	* configure: Regenerate.
2022-06-27 11:39:27 +01:00
Nick Clifton
acd65fa610 Default to disabling the linker warnings about execstack and RWX segments if the target is the HPPA architecture.
PR 29263
	* configure.ac (ac_default_ld_warn_execstack): Default to 'no' for
	HPPA targets.
	(ac_default_ld_warn_rwx_segments): Likewise.
	* configure: Regenerate.
	* testsuite/ld-elf/elf.exp: Add the --warn-execstack command line
	option to the command line when running execstack tests for the
	HPPA target.
2022-06-21 11:22:38 +01:00
Alan Modra
678dc756a5 Fix an illegal memory access when creating DLLs.
PR 29006
	* pe-dll.c (dll_name): Delete, replacing with..
	(dll_filename): ..this, moved earlier in file.
	(generate_edata): Delete parameters.  Don't set up dll_name here..
	(pe_process_import_defs): ..instead set up dll_filename and
	dll_symname here before returning.
	(dll_symname_len): Delete write-only variable.
	(pe_dll_generate_implib): Don't set up dll_symname here.
2022-05-12 12:55:20 +01:00
Nick Clifton
46465574a9 Fix potential arithmetic overflow in the linker's plugin handling code.
PR 29101
	* libdep_plugin.c (get_libdeps): Check for overflow when computing
	amount of memory to allocate.
2022-05-03 11:41:45 +01:00
Nick Clifton
639d467b08 Fix potential buffer overruns when creating DLLs.
PR 29006
	* pe-dll.c (make_head): Use asprintf to allocate and populate a
	buffer containing the temporary name.
	(make_tail, make_one, make_singleton_name_thunk): Likewise.
	(make_import_fixup_mark, make_import_fixup_entry): Likewise.
	(make_runtime_pseudo_reloc): Likewise.
	(pe_create_runtime_relocator_reference): Likewise.
2022-04-27 08:35:18 +01:00
Nick Clifton
0d38576a34 Emit a note warning the user that creating an executable stack because of a missing .note.GNU-stack section is deprecated.
PR 29072
bfd	* elflink.c (bfd_elf_size_dynamic_sections): Display a note to the
	user that the current ehaviour of creating an executable stack
	because of a missing .note.GNU-stack section is deprecated and
	will be changed in a future release.

binutils* testsuite/lib/binutils-common.exp (prune_warnings_extra): Filter
	out notes about the executable stacjk behaviour beign deprecated.

ld	* testsuite/ld-elf/pr29072.b.warn: Update to include the note
	about the linker's behaviour being depreccated.
2022-04-25 12:53:08 +01:00
Cl?ment Chigot
2d23f9656c xcoff: implement linker relaxation
bfd/ChangeLog:

	* coff-rs6000.c (xcoff_reloc_type_noop): Add info argument.
	(xcoff_reloc_type_fail): Likewise.
	(xcoff_reloc_type_pos): Likewise.
	(xcoff_reloc_type_neg): Likewise.
	(xcoff_reloc_type_rel): Likewise.
	(xcoff_reloc_type_toc): Likewise.
	(xcoff_reloc_type_ba): Likewise.
	(xcoff_reloc_type_crel): Likewise.
	(xcoff_reloc_type_tls): Likewise.
	(xcoff_reloc_type_br): Add stub handler.
	(xcoff_ppc_relocate_section): Add info to
	xcoff_calculate_relocation.
	(xcoff_stub_indirect_call_code): New constant.
	(xcoff_stub_shared_call_code): Likewise.
	(bfd_xcoff_backend_data): Add stub code fields.
	(bfd_pmac_xcoff_backend_data): Likewise.
	* coff64-rs6000.c (xcoff64_reloc_type_br): Add stub handler.
	(xcoff64_ppc_relocate_section): Add info to
	xcoff64_calculate_relocation.
	(xcoff64_stub_indirect_call_code): New constant.
	(xcoff64_stub_shared_call_code): Likewise.
	(bfd_xcoff_backend_data): Add stub code fields.
	(bfd_xcoff_aix5_backend_data): Likewise.
	* libxcoff.h (struct xcoff_backend_data_rec): Add stub fields.
	(bfd_xcoff_stub_indirect_call_code): New define.
	(bfd_xcoff_stub_indirect_call_size): New define.
	(bfd_xcoff_stub_shared_call_code): New define.
	(bfd_xcoff_stub_shared_call_size): New define.
	(xcoff_reloc_function): Add info argument.
	(enum xcoff_stub_type): New enum.
	(struct xcoff_stub_hash_entry): New structure.
	* xcofflink.c (struct xcoff_link_hash_table): Add stub hash
	table and params fields.
	(xcoff_stub_hash_entry): New define.
	(xcoff_stub_hash_lookup): New define.
	(stub_hash_newfunc): New function.
	(_bfd_xcoff_bfd_link_hash_table_free): Free the new stub hash
	table.
	(_bfd_xcoff_bfd_link_hash_table_create): Create the new stub
	hash table.
	(xcoff_link_add_symbols): Save rawsize for XTY_SD.
	(bfd_xcoff_link_init): New function.
	(xcoff_stub_csect_name): New function.
	(xcoff_stub_get_csect_in_range): New function.
	(xcoff_stub_name): New function.
	(bfd_xcoff_get_stub_entry): New function.
	(bfd_xcoff_type_of_stub): New function.
	(xcoff_add_stub): New function.
	(xcoff_build_one_stub): New function.
	(bfd_xcoff_size_stubs): New function.
	(bfd_xcoff_build_stubs): New function.
	(xcoff_stub_create_relocations): New function.
	(xcoff_link_input_bfd): Adapt relocations to stub.
	(xcoff_write_global_symbol): Adapt to new TOC entries generated
	for stubs.
	(_bfd_xcoff_bfd_final_link): Handle stub file.
	* xcofflink.h (struct bfd_xcoff_link_params): New structure.

ld/ChangeLog:

	* emultempl/aix.em (params): New variable.
	(stub_file): New variable.
	(xcoff_add_stub_section): New function.
	(xcoff_layout_sections_again): New function
	(hook_in_stub): New function.
	(_after_allocation): Add stub creation.
	(_create_output_section_statements): Allocate stub file and
	pass params to backend.
2022-04-20 15:11:47 +01:00
Cl?ment Chigot
1876a54217 Stubs (added in a later patch) will generate new .loader symbols, once the allocations have been done. Thus, the .loader section cannot be layout before that.
bfd/ChangeLog:

	* coff-rs6000.c (_bfd_xcoff_put_ldsymbol_name): Write len in
	  ldinfo->strings instead of directly in the output_bfd.
	* coff64-rs6000.c (_bfd_xcoff64_put_ldsymbol_name): Likewise.
	* xcofflink.c (struct xcoff_link_hash_table): Remove ldrel_count
	  field. Add ldinfo field.
	(xcoff_mark_symbol): Adjust to new ldinfo field.
	(xcoff_mark): Likewise.
	(bfd_xcoff_link_count_reloc): Likewise.
	(xcoff_build_loader_section): Split into two functions: one that
	build the loader section (this function) and one that only size
	it...
	(xcoff_size_loader_section): ... (this function).
	(bfd_xcoff_size_dynamic_sections): Adapt to new ldinfo field.
	Move the part where the dynamic sections are build to ...
	(bfd_xcoff_build_dynamic_sections): ... this function.
	* xcofflink.h: Add bfd_xcoff_build_dynamic_sections prototype.

include/ChangeLog:

	* coff/xcoff.h (struct xcoff_loader_info): Add ldrel_count and
	libpath fields.

ld/ChangeLog:

	* emultempl/aix.em (_after_allocation): New function.
2022-04-20 15:07:50 +01:00
Mark Harmstone
145667f8d9 Add support for COFF secidx relocations
bfd	* coff-i386.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_i386_relocation_section): Add support for R_SECTION.
	(coff_i386_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* coff-x86_64.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_amd64_relocation_section): Add support for R_SECTION.
	(coff_amd64_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* reloc.c: Add BFD_RELOC_16_SECIDX.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

gas	* config/tc-i386.c (pe_directive_secidx): New function.
	(md_pseudo_table): Add support for secidx.
	(x86_cons_fix_new): Likewise.
	(tc_gen_reloc): Likewise.
	* expr.c (op_rank): Add O_secidx.
	* expr.h (operatorT): Likewise.
	* symbols.c (resolve_symbol_value): Add support for O_secidx.
	* testsuite/gas/i386/secidx.s: New test source file.
	* testsuite/gas/i386/secidx.d: New test driver file.
	* testsuite/gas/i386/i386.exp: Run new test.

include	* coff/i386.h: Define R_SECTION.
	* coff/x86_64.h: Likewise.

ld	* testsuite/ld-pe/secidx1.s: New test source file.
	* testsuite/ld-pe/secidx2.s: New test source file.
	* testsuite/ld-pe/secidx.d: New test driver file.
	* testsuite/ld-pe/secidx_64.d: New test driver file.
	* testsuite/ld-pe/pe.exp: Add new tests.
2022-04-07 14:47:17 +01:00
Nick Clifton
95e96e052a Fix linker tests to compile with gcc-12.
PR 21964
	* testsuite/ld-elf/pr21964-1a.c: Fix array comparisons.
	* testsuite/ld-elf/pr21964-1b.c: Likewise.
	* testsuite/ld-elf/pr21964-1c.c: Likewise.
	* testsuite/ld-elf/pr21964-2a.c: Likewise.
	* testsuite/ld-elf/pr21964-2b.c: Likewise.
	* testsuite/ld-elf/pr21964-3a.c: Likewise.
2022-03-01 10:10:20 +00:00
Roland McGrath
5c14cc552d Fix typo in ld.texi
ld/
	* ld.texi (Output Section Type): Fix typo in @code syntax.
2022-02-18 11:42:09 -08:00
Nick Clifton
36d285b9da Updated Serbian translations for the bfd, gold, ld and opcodes directories 2022-02-17 15:18:59 +00:00
Fangrui Song
c212f39d9a ld: Support customized output section type
bfd/
    PR ld/28841
    * bfd-in2.h (struct bfd_section): Add type.
    (discarded_section): Add field.
    * elf.c (elf_fake_sections): Handle bfd_section::type.
    * section.c (BFD_FAKE_SECTION): Add field.
    * mri.c (mri_draw_tree): Update function call.

ld/
    PR ld/28841
    * ld.texi: Document new output section type.
    * ldlex.l: Add new token TYPE.
    * ldgram.y: Handle TYPE=exp.
    * ldlang.h: Add type_section to list of section types.
    * ldlang.c (lang_add_section): Handle type_section.
    (map_input_to_output_sections): Handle type_section.
    * testsuite/ld-scripts/output-section-types.t: Add tests.
    * testsuite/ld-scripts/output-section-types.d: Update.
2022-02-16 17:41:23 +00:00
Nick Clifton
a698397481 Updated French translation for the ld/ and gold/ sub-directories 2022-02-02 15:05:05 +00:00
Nick Clifton
5fe73d4624 Update Bulgarian, French, Romaniam and Ukranian translation for some of the sub-directories 2022-01-24 14:22:49 +00:00
Alexander von Gluck IV
cc5e40736d Adjust default page sizes for haiku arm.
* configure.tgt (arm-haiku): Fix typo.
	* emulparams/armelf_haiku.su (MAXPAGESIZE): Use the default value.
	(COMMONPAGESIZE): Likewise.
2022-01-22 14:18:34 +00:00
Nick Clifton
f908e960c5 Change version number to 2.38.50 and regenerate files 2022-01-22 12:39:28 +00:00
Nick Clifton
a74e1cb344 Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
Nick Clifton
e901223d53 Updated Serbian translation for the ld sub-directory 2022-01-21 15:42:18 +00:00
Nick Clifton
6c037fdbf0 Update the config.guess and config.sub files from the master repository and regenerate files. 2022-01-17 16:21:22 +00:00
Martin Storsj
c4a8df19ba Fix multiple problems with DLL generation.
ld	* pe-dll.c (make_head): Prefix the symbol name with the dll name.
	(make_tail, make_one, make_singleton_name_thunk): Likewise.
	(make_import_fixup_entry, make_runtime_pseudo_reloc): Likewise.
	(pe_create_runtime_relocator_reference): Likewise.
	(pe_dll_generate_implib): Set dll_symname_len.
	(pe_process_import_defs): Likewise.

binutils
	* dlltool.c (main): If a prefix has not been provided, attempt to
	use a deterministic one based upon the dll name.
2022-01-11 15:43:59 +00:00
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
The result of running etc/update-copyright.py --this-year, fixing all
the files whose mode is changed by the script, plus a build with
--enable-maintainer-mode --enable-cgen-maint=yes, then checking
out */po/*.pot which we don't update frequently.

The copy of cgen was with commit d1dd5fcc38ead reverted as that commit
breaks building of bfp opcodes files.
2022-01-02 12:04:28 +10:30
Nick Clifton
f3be70df1b Fix AVR assembler so that it creates relocs that will work with linker relaxation.
PR 28686
gas	* config/tc-avr.h (tc_fix_adjustable): Define.
	* config/tc-avr.c (avr_fix_adjustable): New function.
	* testsuite/gas/all/gas.exp: Skip tests that need adjustable fixups.
	* testsuite/gas/elf/elf.exp: Likewise.
	* testsuite/gas/avr/diffreloc_withrelax.d: Adjust expected output.
	* testsuite/gas/avr/pc-relative-reloc.d: Adjust expected output.

ld	* testsuite/ld-avr/avr-prop-7.d: Adjust expected output.
	* testsuite/ld-avr/avr-prop-8.d: Likewise.
	* testsuite/ld-avr/pr13402.d: Likewise.
2021-12-16 16:40:57 +00:00
Nick Clifton
44b357eb9a ld: pru: Add pru_irq_map output section
* scripttempl/pru.sc (.pru_irq_map): Define output section.
	* testsuite/ld-pru/pru_irq_map-1.d: New test.
	* testsuite/ld-pru/pru_irq_map-2.d: New test.
	* testsuite/ld-pru/pru_irq_map.s: New test.
2021-11-30 13:11:57 +00:00
Jeremy Drake
ef6379e16d Set the default DLL chracteristics to 0 for Cygwin based targets.
* emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Set to 0 for
	Cygwin targets.
	* emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Likewise.
2021-11-17 16:24:53 +00:00
Nick Clifton
ee9e412f14 Fix the linker script parser so that it will recognise the PT_GNU_RELRO segment type, and the linker itself so that it will gracefully handle being unable to assign any sections to such a segment.
PR 28452
bfd	* elf.c (assign_file_positions_for_non_load_sections): Replace
	assertion with a warning message.

ld	* ldgram.y: Add support for PT_GNU_RELRO and PT_GNU_PROPERTY.
	* ldgram.c: Regenerate.
2021-11-17 15:59:16 +00:00
Roland McGrath
d029b54d9c ld: Fix testsuite failures under --enable-textrel-check=error
ld/
	* testsuite/ld-aarch64/dt_textrel.d: Pass explicit -z notext in
	case ld was configured with --enable-textrel-check=error.
	* testsuite/ld-aarch64/pr22764.d: Likewise.
	* testsuite/ld-aarch64/pr20402.d: Likewise.
2021-11-15 11:09:17 -08:00
Nick Alcock
eb5323fdf8 libctf, ld: handle nonrepresentable types better
ctf_type_visit (used, among other things, by the type dumping code) was
aborting when it saw a nonrepresentable type anywhere: even a single
structure member with a nonrepresentable type caused an abort with
ECTF_NONREPRESENTABLE.  This is not useful behaviour, given that the
abort comes from a type-resolution we are only doing in order to
determine whether the type is a structure or union.  We know
nonrepresentable types can't be either, so handle that case and
pass the nonrepresentable type down.

(The added test verifies that the dumper now handles this case and
prints nonrepresentable structure members as it already does
nonrepresentable top-level types, rather than skipping the whole
structure -- or, without the previous commit, skipping the whole types
section.)

ld/ChangeLog
2021-10-25  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/nonrepresentable-member.*: New test.

libctf/ChangeLog
2021-10-25  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_rvisit): Handle nonrepresentable types.
2021-10-25 11:17:05 +01:00
Nick Alcock
10909ea819 binutils, ld: make objdump --ctf's parameter optional
ld by default (and always, unless adjusted with a hand-rolled linker
script) emits deduplicated CTF into the .ctf section.  But viewing
it needs you to explicitly tell objdump this: it doesn't default
its argument, even though what you always end up typing is
--ctf=.ctf.

This is annoying, so make the argument optional.

binutils/ChangeLog
2021-10-25  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (usage): --ctf now has an optional argument.
	(main): Adjust accordingly.
	(dump_ctf): Default it.
	* doc/ctf.options.texi: Adjust.

ld/ChangeLog
2021-10-25  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Change --ctf=.ctf to --ctf.
	* 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/enum-forward.d: Likewise.
	* testsuite/ld-ctf/enums.d: Likewise.
	* testsuite/ld-ctf/forward.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/nonrepresentable.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d: Likewise.
2021-10-25 11:17:03 +01:00
Dimitar Dimitrov
5109a7bd9b ld: pru: Fix resource_table output section alignment
My commit 261980de18 added alignment for the resource table symbol.
But it is wrong.  The Linux remoteproc driver loads and interprets the
contents of the .resource_table ELF section, not of a table symbol.

Without this patch, if the linker happens to output padding for symbol
alignment, then the resource table contents as viewed by the kernel
loader would "shift" and look corrupted.

ld/ChangeLog:

	* scripttempl/pru.sc  (.resource_table): Align the output
	section, not the first symbol.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2021-09-30 22:15:50 +03:00
Nick Alcock
b9004024b9 configure: regenerate in all projects that use libtool.m4
(including sim/, which has no changelog.)

bfd/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

binutils/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

gas/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

gprof/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

ld/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

libctf/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.
	* Makefile.in: Regenerate.

opcodes/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.

zlib/ChangeLog
2021-09-27  Nick Alcock  <nick.alcock@oracle.com>

	* configure: Regenerate.
2021-09-27 20:31:24 +01:00
Nick Clifton
5226a6a892 Change the linker's heuristic for computing the entry point for binaries so that shared libraries default to an entry point of 0.
* ldlang.c (lang_end): When computing the entry point, only
	try the start address of the entry section when creating an
	executable.
	* ld.texi (Entry point): Update description of heuristic used to
	choose the entry point.
	testsuite/ld-alpha/tlspic.rd: Update expected entry point address.
	testsuite/ld-arm/tls-gdesc-got.d: Likewise.
	testsuite/ld-i386/tlsnopic.rd: Likewise.
	testsuite/ld-ia64/tlspic.rd: Likewise.
	testsuite/ld-sparc/gotop32.rd: Likewise.
	testsuite/ld-sparc/gotop64.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic32.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic64.rd: Likewise.
	testsuite/ld-sparc/tlssunpic32.rd: Likewise.
	testsuite/ld-sparc/tlssunpic64.rd: 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-noindex.rd: Likewise.
	testsuite/ld-x86-64/pr14207.d: Likewise.
	testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	testsuite/ld-x86-64/tlspic.rd: Likewise.
	testsuite/ld-x86-64/tlspic2.rd: Likewise.
2021-09-21 13:21:41 +01:00
Claudiu Zissulescu
720f6ee095 arc: Fix got-weak linker test
Use regular expressions to fix the got-weak linker test.

ld/
	* testsuite/got-weak.d: Update test.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2021-09-15 13:49:02 +03:00
Claudiu Zissulescu
09a7e91293 arc: Fix potential invalid pointer access when fixing got symbols.
When statically linking, it can arrive to an undefined weak symbol of
which its value cannot be determined. However, we are having pieces of
code which doesn't take this situation into account, leading to access
a structure which may not be initialized. Fix this situation and add a
test.

bfd/
xxxx-xx-xx  Cupertino Miranda  <cmiranda@synopsys.com>
            Claudiu Zissulescu  <claziss@synopsys.com>

	* arc-got.h (arc_static_sym_data): New structure.
	(get_static_sym_data): New function.
	(relocate_fix_got_relocs_for_got_info): Move the computation fo
	symbol value and section to above introduced function, and use
	this new function.

ld/testsuite/
xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>

	* ld-arc/got-weak.d: New file.
	* ld-arc/got-weak.s: Likewise.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>

fix
2021-09-14 12:10:54 +03:00
Roland McGrath
dfe3b80549 Fix ld test case that assumes --enable-textrel-check
ld/
	* testsuite/ld-x86-64/x86-64.exp (Build textrel-1): Use --warn-textrel.
2021-07-26 17:55:12 -07:00
Michael Matz
235f5ef4a6 elf/riscv: Fix relaxation with aliases [PR28021]
the fix for PR22756 only changed behaviour for hidden aliases,
but the same situation exists for non-hidden aliases: sym_hashes[]
can contain multiple entries pointing to the same symbol structure
leading to relaxation adjustment to be applied twice.

Fix this by testing for duplicates for everything that looks like it
has a version.

PR ld/28021

bfd/
	* elfnn-riscv.c (riscv_relax_delete_bytes): Check for any
	versioning.

ld/
	* testsuite/ld-riscv-elf/relax-twice.ver: New.
	* testsuite/ld-riscv-elf/relax-twice-1.s: New.
	* testsuite/ld-riscv-elf/relax-twice-2.s: New.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp
	(run_relax_twice_test): New, and call it.
2021-07-06 15:49:03 +02:00
Nick Clifton
346d80ef33 Update version number and regenerate files 2021-07-03 15:16:48 +01:00
Nick Clifton
514192487e Add markers for 2.37 branch 2021-07-03 14:50:57 +01:00
Nelson Chu
50331d64f1 RISC-V: Clarify the addends of pc-relative access.
The original discussion was here,
https://github.com/riscv/riscv-elf-psabi-doc/issues/184

After discussing with Kito Cheng, I think the addends of %pcrel_hi
and %pcrel_lo are both allowed in GNU toolchain.  However, both of
the them mean the offset of symbols, rather than the pc address.
But the addends of %got_pcrel_hi and it's %pcrel_lo do not look
reasonable.  I believe gcc won't generate the got patterns with
addends, so linker should report dangerous relocation errors,
in case the assembly code use them.

Another issue was here,
https://sourceware.org/pipermail/binutils/2021-June/116983.html

At the beginnig, I suppose %pcrel_hi and %pcrel_lo are valid only
when they are in the same input section.  But Jim Wilson points out
that gcc may generate %hi and %lo in the different input sections,
when -freorder-blocks-and-partition option is used.  So that a memory
references for a loop may have the %hi outside the loop, but the %lo
remain in the loop.  However, it is hard to create the testcases,
to see if %pcrel_hi and %pcrel_lo have the same behavior.

Unfortunately, I notice that the current pcrel resolver cannot
work for the above case.  For now we build a hash table for pcrel
at the start of riscv_elf_relocate_section, and then free the hash
at the end.  But riscv_elf_relocate_section only handles an input
section at a time, so that means we can only resolve the %pcrel_hi
and %pcrel_lo which are in the same input section.  Otherwise, like
the above case, we will report "%pcrel_lo missing matching %pcrel_hi"
for them.  I have no plan to improve this in the short-term, so maybe
we can wait until someone meets the problem before we deal with it.

bfd/
    * elfnn-riscv.c (riscv_pcrel_hi_reloc): Added field to store
    the original relocation type, in case the type is converted to
    R_RISCV_HI20.
    (riscv_pcrel_lo_reloc): Removed unused name field.
    (riscv_pcrel_relocs): Added comments.
    (riscv_zero_pcrel_hi_reloc): Removed unused input_bfd.
    (riscv_record_pcrel_hi_reloc): Updated.
    (riscv_record_pcrel_lo_reloc): Likewise.
    (riscv_resolve_pcrel_lo_relocs): Likewise.  Check the original
    type of auipc, to make sure the %pcrel_lo without any addends.
    Otherwise, report dangerous relocation error.
    (riscv_elf_relocate_section): Updated above functions are changed.
    For R_RISCV_GOT_HI20, report dangerous relocation error when addend
    isn't zero.
ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.d: New testcase.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.d: New testcase.
    Should report error since the %pcrel_lo with addend refers to
    %got_pcrel_hi.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.d: New testcase.
    Should report error since the %got_pcrel_hi with addend.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3.ld: Likewise.
2021-06-22 17:14:55 +08:00
H.J. Lu
406b4ada55 x86: Count PLT for GOTOFF relocation against IFUNC symbol
Since GOTOFF relocations against IFUNC symbols must go through PLT,
set PLT reference count to 1 for GOTOFF relocation.

bfd/

	PR ld/27998
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Count PLT for GOTOFF
	relocation against IFUNC symbols.
	(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.

ld/

	PR ld/27998
	* testsuite/ld-i386/i386.exp: Run PR ld/27998 tests.
	* testsuite/ld-i386/pr27998a.d: New file.
	* testsuite/ld-i386/pr27998a.s: Likewise.
	* testsuite/ld-i386/pr27998b.d: Likewise.
	* testsuite/ld-i386/pr27998b.s: Likewise.
2021-06-19 20:21:04 -07:00
H.J. Lu
83b1d8f4a6 elf: Correct DT_TEXTREL warning in PDE
Change

ld: warning: creating DT_TEXTREL in a PIE

to

ld: warning: creating DT_TEXTREL in a PDE

on PDE.

bfd/

	* elflink.c (bfd_elf_final_link): Correct DT_TEXTREL warning in
	PDE.

ld/

	* testsuite/ld-x86-64/textrel-1.err: New file.
	* testsuite/ld-x86-64/textrel-1a.s: Likewise.
	* testsuite/ld-x86-64/textrel-1b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run textrel-1 tests.
2021-06-19 16:33:35 -07:00
H.J. Lu
c30420d82a elf: Update GNU_PROPERTY_UINT32_[AND|OR]_XXX tests
1. Skip am33_2.0-*-* hppa*-*-hpux* mn10300-*-* since assembly source file
for the HPPA assembler is renamed and modifed by sed.  mn10300 has RELA
relocations in .note.gnu.property section which elf_parse_notes doesn't
support.
2. Pass --generate-missing-build-notes=no to assembler.
3. Allow other note sections for xtensa.

	* testsuite/ld-elf/property-and-1.d: Skip am33_2.0, hppa-hpux
	and mn10300.
	Pass --generate-missing-build-notes=no to assembler.  Allow
	other note sections for xtensa.
	* testsuite/ld-elf/property-and-2.d: Likewise.
	* testsuite/ld-elf/property-and-3.d: Likewise.
	* testsuite/ld-elf/property-and-4.d: Likewise.
	* testsuite/ld-elf/property-or-1.d: Likewise.
	* testsuite/ld-elf/property-or-2.d: Likewise.
	* testsuite/ld-elf/property-or-3.d: Likewise.
	* testsuite/ld-elf/property-or-4.d: Likewise.
2021-06-19 04:41:10 -07:00
H.J. Lu
2d95647bdd ld.texi: Move -z unique-symbol after -z undefs.
* ld.texi: Move -z unique-symbol after -z undefs.
2021-06-18 07:33:30 -07:00
H.J. Lu
5a767724d7 elf: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX
Implement GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX:

https://sourceware.org/pipermail/gnu-gabi/2021q1/000467.html

1. GNU_PROPERTY_UINT32_AND_LO..GNU_PROPERTY_UINT32_AND_HI

 #define GNU_PROPERTY_UINT32_AND_LO 0xb0000000
 #define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff

A bit in the output pr_data field is set only if it is set in all
relocatable input pr_data fields.  If all bits in the the output
pr_data field are zero, this property should be removed from output.

If the bit is 1, all input relocatables have the feature.  If the
bit is 0 or the property is missing, the info is unknown.

2. GNU_PROPERTY_UINT32_OR_LO..GNU_PROPERTY_UINT32_OR_HI

 #define GNU_PROPERTY_UINT32_OR_LO 0xb0008000
 #define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff

A bit in the output pr_data field is set if it is set in any
relocatable input pr_data fields. If all bits in the the output
pr_data field are zero, this property should be removed from output.

If the bit is 1, some input relocatables have the feature.  If the
bit is 0 or the property is missing, the info is unknown.

bfd/

	* elf-properties.c (_bfd_elf_parse_gnu_properties): Handle
	GNU_PROPERTY_UINT32_AND_LO, GNU_PROPERTY_UINT32_AND_HI,
	GNU_PROPERTY_UINT32_OR_LO and GNU_PROPERTY_UINT32_OR_HI.
	(elf_merge_gnu_properties): Likewise.

binutils/

	* readelf.c (print_gnu_property_note): Handle
	GNU_PROPERTY_UINT32_AND_LO, GNU_PROPERTY_UINT32_AND_HI,
	GNU_PROPERTY_UINT32_OR_LO and GNU_PROPERTY_UINT32_OR_HI.

include/

	* elf/common.h (GNU_PROPERTY_UINT32_AND_LO): New.
	(GNU_PROPERTY_UINT32_AND_HI): Likewise.
	(GNU_PROPERTY_UINT32_OR_LO): Likewise.
	(GNU_PROPERTY_UINT32_OR_HI): Likewise.

ld/

	* testsuite/ld-elf/property-and-1.d: New file.
	* testsuite/ld-elf/property-and-1.s: Likewise.
	* testsuite/ld-elf/property-and-2.d: Likewise.
	* testsuite/ld-elf/property-and-2.s: Likewise.
	* testsuite/ld-elf/property-and-3.d: Likewise.
	* testsuite/ld-elf/property-and-3.s: Likewise.
	* testsuite/ld-elf/property-and-4.d: Likewise.
	* testsuite/ld-elf/property-and-empty.s: Likewise.
	* testsuite/ld-elf/property-or-1.d: Likewise.
	* testsuite/ld-elf/property-or-1.s: Likewise.
	* testsuite/ld-elf/property-or-2.d: Likewise.
	* testsuite/ld-elf/property-or-2.s: Likewise.
	* testsuite/ld-elf/property-or-3.d: Likewise.
	* testsuite/ld-elf/property-or-3.s: Likewise.
	* testsuite/ld-elf/property-or-4.d: Likewise.
	* testsuite/ld-elf/property-or-empty.s: Likewise.
2021-06-18 07:19:01 -07:00
H.J. Lu
e013d20dc7 x86-64: Use $NOPIE_LDFLAGS/$NOPIE_CFLAGS on protected-func-1
PR ld/27973
	* testsuite/ld-x86-64/x86-64.exp: Pass $NOPIE_LDFLAGS and
	$NOPIE_CFLAGS to protected-func-1 without PIE.
2021-06-17 10:36:15 -07:00
H.J. Lu
b6b4298372 x86-64: Test protected function pointers
On x86-64, function pointers in executable for external funtions may be
resolved to their PLT entries in executable.  If it happens, function
pointers of protected funtions in shared libraries must be resolved to
the PLT entries in executable, not addresses of protected funtions in
shared libraries.

	PR ld/27973
	* testsuite/ld-x86-64/x86-64.exp: Run protected function tests.
	* testsuite/ld-x86-64/protected-func-1.h: New file.
	* testsuite/ld-x86-64/protected-func-1a.s: Likewise.
	* testsuite/ld-x86-64/protected-func-1b.c: Likewise.
2021-06-17 10:26:34 -07:00
Fangrui Song
d208bc7617 ld: Add ChangeLog entry for -no-pie 2021-06-17 10:18:28 -07:00
Alan Modra
93df3340fd readelf: report DF_1_PIE as "Position-Independent Executable"
I finally found time to teach readelf to identify PIEs in the file
header display and program header display.  So in place of
"DYN (Shared object file)" which isn't completely true, show
"DYN (Position-Independent Executable file)".

It requires a little bit of untangling code in readelf due to
process_program_headers setting up dynamic_addr and dynamic_size,
needed to scan .dynamic for the DT_FLAGS_1 entry, and
process_program_headers itself wanting to display the file type in
some cases.  At first I modified process_program_header using a
"probe" parameter similar to get_section_headers in order to inhibit
output, but decided it was cleaner to separate out
locate_dynamic_sections.

binutils/
	* readelf.c (locate_dynamic_section, is_pie): New functions.
	(get_file_type): Replace e_type parameter with filedata.  Call
	is_pie for ET_DYN.  Update all callers.
	(process_program_headers): Use local variables dynamic_addr and
	dynamic_size, updating filedata on exit from function.  Set
	dynamic_size of 1 to indicate no dynamic section or segment.
	Update tests of dynamic_size throughout.
	* testsuite/binutils-all/x86-64/pr27708.dump: Update expected output.
ld/
	* testsuite/ld-pie/vaddr-0.d: Update expected output.
gdb/
	* testsuite/lib/gdb.exp (exec_is_pie): Match new PIE readelf output.
2021-06-15 13:24:57 +09:30