Commit Graph

4421 Commits

Author SHA1 Message Date
H.J. Lu 382aae0632 x86: Only allow S + A relocations against absolute symbol
Since value of non-preemptible absolute symbol (SHN_ABS) won't change,
only relocations, which can be resolved as absolute value + addend, and
GOTPCREL relocations, where absolute value + addend is stored in the GOT
slot, against non-preemptible absolute symbol are allowed in PIE and
shared library.

Also convert load relocation to R_386_32, R_X86_64_32S or R_X86_64_32 for
relocation against non-preemptible absolute symbol.  Don't convert to
R_X86_64_32S nor R_X86_64_32 for non-preemptible absolute symbol if they
overflow.

bfd/

	PR ld/25749
	PR ld/25754
	* elf32-i386.c (elf_i386_convert_load_reloc): Convert load
	relocation to R_386_32 for relocation against non-preemptible
	absolute symbol.
	(elf_i386_check_relocs): Call _bfd_elf_x86_valid_reloc_p.  Don't
	allocate dynamic relocation for non-preemptible absolute symbol.
	(elf_i386_relocate_section): Pass sec to
	GENERATE_DYNAMIC_RELOCATION_P.
	* elf64-x86-64.c (R_X86_64_converted_reloc_bit): Moved.
	(elf_x86_64_convert_load_reloc): Covert load relocation to
	R_X86_64_32S or R_X86_64_32 for relocation against non-preemptible
	absolute symbol.  Don't convert to R_X86_64_32S nor R_X86_64_32
	for non-preemptible absolute symbol if they overflow.
	(elf_x86_64_check_relocs): Call _bfd_elf_x86_valid_reloc_p.  Set
	tls_type for GOT slot to GOT_ABS for non-preemptible absolute
	symbol.  Don't allocate dynamic relocation for non-preemptible
	absolute symbol.
	(elf_x86_64_relocate_section): Don't generate relative relocation
	for GOTPCREL relocations aganst local absolute symbol.  Pass sec
	to GENERATE_DYNAMIC_RELOCATION_P.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): No dynamic relocation
	against non-preemptible absolute symbol.
	(_bfd_elf_x86_valid_reloc_p): New function.
	(_bfd_x86_elf_size_dynamic_sections): No dynamic relocation for
	GOT_ABS GOT slot.
	* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Add an SEC
	argument.  Don't generate dynamic relocation against
	non-preemptible absolute symbol.
	(ABS_SYMBOL_P): New.
	(GENERATE_RELATIVE_RELOC_P): Don't generate relative relocation
	against non-preemptible absolute symbol.
	(GOT_ABS): New.
	(R_X86_64_converted_reloc_bit): New.  Moved from elf64-x86-64.c.
	(_bfd_elf_x86_valid_reloc_p): New.

ld/

	PR ld/25749
	PR ld/25754
	* testsuite/ld-elf/linux-x86.exp: Run ld/25749 tests.
	* testsuite/ld-elf/pr25749-1.c: New file.
	* testsuite/ld-elf/pr25749-1a.c: Likewise.
	* testsuite/ld-elf/pr25749-1b.c: Likewise.
	* testsuite/ld-elf/pr25749-1b.err: Likewise.
	* testsuite/ld-elf/pr25749-1c.c: Likewise.
	* testsuite/ld-elf/pr25749-1d.c: Likewise.
	* testsuite/ld-elf/pr25749-2.c: Likewise.
	* testsuite/ld-elf/pr25749-2a.s: Likewise.
	* testsuite/ld-elf/pr25749-2b.s: Likewise.
	* testsuite/ld-elf/pr25749.rd: Likewise.
	* testsuite/ld-elf/pr25754-1a.c: Likewise.
	* testsuite/ld-elf/pr25754-1b.s: Likewise.
	* testsuite/ld-elf/pr25754-2a.c: Likewise.
	* testsuite/ld-elf/pr25754-2b.err: Likewise.
	* testsuite/ld-elf/pr25754-2b.s: Likewise.
	* testsuite/ld-elf/pr25754-3a.c: Likewise.
	* testsuite/ld-elf/pr25754-3b.s: Likewise.
	* testsuite/ld-elf/pr25754-4a.c: Likewise.
	* testsuite/ld-elf/pr25754-4b.s: Likewise.
	* testsuite/ld-elf/pr25754-4c.s: Likewise.
	* testsuite/ld-elf/pr25754-5a.c: Likewise.
	* testsuite/ld-elf/pr25754-5b.s: Likewise.
	* testsuite/ld-elf/pr25754-5c.s: Likewise.
	* testsuite/ld-elf/pr25754-6a.c: Likewise.
	* testsuite/ld-elf/pr25754-6b.s: Likewise.
	* testsuite/ld-x86-64/pr19609-6a.d: Don't expect linker error.
2020-04-01 14:31:47 -07:00
Tamar Christina 3ce23ca1de Arm: Skip Thumb2 PLT tests on NaCL.
NaCL does not support dynamic linking and so these tests should be
skipped under it.

ld/ChangeLog:

	PR ld/16017
	* testsuite/ld-arm/arm-elf.exp (thumb-plt, thumb-plt-got): Skip for NaCL.
2020-04-01 18:36:23 +01:00
Nick Clifton 77bf7b5317 Extend the linker's error message for missing libraries if there is an almost match.
PR ld/25747
	* ldfile.c (ldfile_open_file): If a search for a library fails,
	but there is a file that would match if it had a "lib" prefix to
	its name, then tell the user.
2020-04-01 17:25:28 +01:00
Tamar Christina a7618269b7 Arm: Fix LSB of GOT for Thumb2 only PLT.
When you have a Thumb only PLT then the address in the GOT for PLT0 needs to
have the Thumb bit set since the instruction used in PLTn to get there is
`ldr.w	pc` which is an inter-working instruction:

the PLT sequence in question is

00000120 <foo@plt>:
 120:	f240 0c98 	movw	ip, #152	; 0x98
 124:	f2c0 0c01 	movt	ip, #1
 128:	44fc      	add	ip, pc
 12a:	f8dc f000 	ldr.w	pc, [ip]
 12e:	e7fc      	b.n	12a <foo@plt+0xa>

Disassembly of section .text:

00000130 <bar>:
 130:	b580      	push	{r7, lr}
 132:	af00      	add	r7, sp, #0
 134:	f7ff fff4 	bl	120 <foo@plt>

and previously the linker would generate

Hex dump of section '.got':
 ...
  0x000101b8 40010100 00000000 00000000 10010000 @...............

Which would make it jump and transition out of thumb mode and crash since you
only have thumb mode on such cores.

Now it correctly generates

Hex dump of section '.got':
 ...
  0x000101b8 40010100 00000000 00000000 11010000 @...............

Thanks to Amol for testing patch and to rgujju for reporting it.

bfd/ChangeLog:

	PR ld/16017
	* elf32-arm.c (elf32_arm_populate_plt_entry): Set LSB of the PLT0
	address in the GOT if in thumb only mode.

ld/ChangeLog:

	PR ld/16017
	* testsuite/ld-arm/arm-elf.exp (thumb-plt-got): New.
	* testsuite/ld-arm/thumb-plt-got.d: New test.
2020-04-01 10:52:33 +01:00
Tamar Christina 15ccbdd717 Arm: Fix thumb2 PLT branch offsets.
When I previously changed these offsets I had incorrectly used an offset of -2
for this Thumb2 PLT.  Unfortunately because we had no tests for this PLT I had
missed that the result was incorrect.

This patch fixes the offset to PC .-4 so that it correctly addresses the
previous instruction and adds a test for this PLT stub.

bfd/ChangeLog:

	* elf32-arm.c (elf32_thumb2_plt_entry): Fix PC-rel offset.

ld/ChangeLog:

	* testsuite/ld-arm/arm-elf.exp (thumb-plt): New.
	* testsuite/ld-arm/thumb-plt.d: New test.
	* testsuite/ld-arm/thumb-plt.s: New test.
2020-04-01 10:52:32 +01:00
Hans-Peter Nilsson 41ff29bf5d ld/testsuite/ld-scripts/defined4.d: Don't xfail mmix-*-*.
A recent fix for the mmo input reader caused symbol-to-type mapping
(which is heuristic for the mmo format) to change (as in "corrected"),
and this test-case now passes.

Before that change, the comment was actually wrong: the symbol type
was mistakenly set to as B for uninitialized data, not T for text
section.
2020-04-01 04:10:18 +02:00
Nick Clifton 00386881a3 Fix objcopy's --preserve-dates command line option so that it will work with PE format files.
PR binutils/pr25662
bfd	* libcoff-in.h (struct pe_tdata): Rename the insert_timestamp
	field to timestamp and make it an integer.
	* libcoff.h: Regenerate.
	* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Test the timestamp
	field in the pe_data structure rather than the insert_timestamp
	field.

binutils* objcopy.c (copy_object): When copying PE format files set the
	timestamp field in the pe_data structure if the preserve_dates
	flag is set.
	* testsuite/binutils-all/objcopy.exp (objcopy_test) Use
	--preserve-dates in place of the -p option, in order to make its
	effect more obvious.

ld	* emultempl/pe.em (after_open): Replace initialisation of the
	insert_timestamp field in the pe_data structure with an
	initialisation of the timestamp field.
	* emultemp/pep.em: Likewise.
	* pe-dll.c (fill_edata): Use the timestamp field in the pe_data
	structure instead of the insert_timestamp field.
2020-03-30 16:30:02 +01:00
H.J. Lu 767be9d907 ld: Set COMMONPAGESIZE for i386 Solaris
Since COMMONPAGESIZE is set for other Solaris targets, including x86-64
Solaris, also set COMMONPAGESIZE for i386 Solaris to fix

FAIL: Build pr20995-2.so
FAIL: pr20995-2

	PR 25732
	* emulparams/elf_i386_ldso.sh (COMMONPAGESIZE): New.
	* testsuite/ld-elf/shared.exp:Don't xfail pr20995-2 tests for
	Solaris.
2020-03-28 05:06:58 -07:00
H.J. Lu 258e884429 ld: Xfail pr20995-2 tests for Solaris
Xfail pr20995-2 tests for Solaris since Solaris doesn't support RELRO.

	PR 25732
	* testsuite/ld-elf/shared.exp: Xfail pr20995-2 tests for Solaris.
2020-03-27 07:35:22 -07:00
H.J. Lu cacb9d8713 ld: Skip some x86 IFUNC tests for Solaris
Since Solaris ld.so.1 doesn't support ifunc and never will, skip some
x86 IFUNC tests for Solaris.

	PR 25732
	* testsuite/ld-ifunc/ifunc-23a-x86.d: Add notarget for Solaris.
	* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
2020-03-27 07:01:54 -07:00
Alan Modra 86fd7e2e10 h8300-linux ld testsuite
This fixes lots of fails caused by h8300-linux not supporting -shared
and related options.  I've also fixed ld-h8300 tests to accept the
valid h8300-linux -m options .

pr22450.d is also fixed for avr, crx, ip2k, m68hc11 and xc16x, and the
new pr25708 test for hppa64.

	* testsuite/ld-elf/compress1c.d: xfail h8300.
	* testsuite/ld-elf/compressed1c.d: Likewise.
	* testsuite/ld-elf/compressed1e.d: Likewise.
	* testsuite/ld-elf/dynamic1.d: Likewise.
	* testsuite/ld-elf/dynsym1.d: Likewise.
	* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
	* testsuite/ld-elf/exclude3b.d: Likewise.
	* testsuite/ld-elf/export-class.exp: Don't run without -shared support.
	* testsuite/ld-elf/global1.d: xfail h8300.
	* testsuite/ld-elf/hash.d: Likewise.
	* testsuite/ld-elf/loadaddr1.d: Likewise.
	* testsuite/ld-elf/loadaddr2.d: Likewise.
	* testsuite/ld-elf/local1.d: Likewise.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
	* testsuite/ld-elf/now-1.d: Likewise.
	* testsuite/ld-elf/now-2.d: Likewise.
	* testsuite/ld-elf/now-3.d: Likewise.
	* testsuite/ld-elf/now-4.d: Likewise.
	* testsuite/ld-elf/pie.d: Likewise.
	* testsuite/ld-elf/pr12975.d: Likewise.
	* testsuite/ld-elf/pr13177.d: Likewise.
	* testsuite/ld-elf/pr13195.d: Likewise.
	* testsuite/ld-elf/pr16322.d: Likewise.
	* testsuite/ld-elf/pr16498a.d: Likewise.
	* testsuite/ld-elf/pr16498b.d: Likewise.
	* testsuite/ld-elf/pr17615.d: Likewise.
	* testsuite/ld-elf/pr19162.d: Likewise.
	* testsuite/ld-elf/pr19539.d: Likewise.
	* testsuite/ld-elf/pr19617a.d: Likewise.
	* testsuite/ld-elf/pr19698.d: Likewise.
	* testsuite/ld-elf/pr20513c.d: Likewise.
	* testsuite/ld-elf/pr20513d.d: Likewise.
	* testsuite/ld-elf/pr21389a.d: Likewise.
	* testsuite/ld-elf/pr21389b.d: Likewise.
	* testsuite/ld-elf/pr21389c.d: Likewise.
	* testsuite/ld-elf/pr21562a.d: Likewise.
	* testsuite/ld-elf/pr21562b.d: Likewise.
	* testsuite/ld-elf/pr21562c.d: Likewise.
	* testsuite/ld-elf/pr21562d.d: Likewise.
	* testsuite/ld-elf/pr21562e.d: Likewise.
	* testsuite/ld-elf/pr21562f.d: Likewise.
	* testsuite/ld-elf/pr21562g.d: Likewise.
	* testsuite/ld-elf/pr21562h.d: Likewise.
	* testsuite/ld-elf/pr21562i.d: Likewise.
	* testsuite/ld-elf/pr21562j.d: Likewise.
	* testsuite/ld-elf/pr21562k.d: Likewise.
	* testsuite/ld-elf/pr21562l.d: Likewise.
	* testsuite/ld-elf/pr21562m.d: Likewise.
	* testsuite/ld-elf/pr21562n.d: Likewise.
	* testsuite/ld-elf/pr21903a.d: Likewise.
	* testsuite/ld-elf/pr21903b.d: Likewise.
	* testsuite/ld-elf/pr21903d.d: Likewise.
	* testsuite/ld-elf/pr22269a.d: Likewise.
	* testsuite/ld-elf/pr22269b.d: Likewise.
	* testsuite/ld-elf/pr22393-1a.d: Likewise.
	* testsuite/ld-elf/pr22393-1b.d: Likewise.
	* testsuite/ld-elf/pr22393-1c.d: Likewise.
	* testsuite/ld-elf/pr22393-1d.d: Likewise.
	* testsuite/ld-elf/pr22393-1e.d: Likewise.
	* testsuite/ld-elf/pr22393-1f.d: Likewise.
	* testsuite/ld-elf/pr22423.d: Likewise.
	* testsuite/ld-elf/pr22450.d: xfail avr, crx, h8300, ip2k, m68hc11,
	and xc16x.
	* testsuite/ld-elf/pr23658-1c.d: xfail h8300.
	* testsuite/ld-elf/pr25708.d: xfail h8300 and hppa64.
	* testsuite/ld-elf/rpath-1.d: xfail h8300.
	* testsuite/ld-elf/rpath-2.d: Likewise.
	* testsuite/ld-elf/runpath-1.d: Likewise.
	* testsuite/ld-elf/runpath-2.d: Likewise.
	* testsuite/ld-elf/sizeofb.d: Likewise.
	* testsuite/ld-elf/startofb.d: Likewise.
	* testsuite/ld-elf/strtab.d: Likewise.
	* testsuite/ld-elf/textaddr1.d: Likewise.
	* testsuite/ld-elf/textaddr2.d: Likewise.
	* testsuite/ld-elf/textaddr4.d: Likewise.
	* testsuite/ld-elf/textaddr5.d: Likewise.
	* testsuite/ld-elf/textaddr6.d: Likewise.
	* testsuite/ld-elf/unknown2.d: Likewise.
	* testsuite/ld-undefined/entry-3.d: Likewise.
	* testsuite/ld-undefined/entry-4.d: Likewise.
	* testsuite/ld-h8300/h8300.exp: Pass appropriate ld -m option.
	* testsuite/ld-h8300/gcsection.d: Remove ld -m option and relax
	file format match.
	* testsuite/ld-h8300/relax-2.d: Likewise.
	* testsuite/ld-h8300/relax-3.d: Likewise.
	* testsuite/ld-h8300/relax-4.d: Likewise.
	* testsuite/ld-h8300/relax-5.d: Likewise.
	* testsuite/ld-h8300/relax-6.d: Likewise.
	* testsuite/ld-h8300/relax-7.d: Likewise.
	* testsuite/ld-h8300/relax.d: Relax file format match.
2020-03-25 14:51:41 +10:30
H.J. Lu 7e6e972f74 bfd: Display symbol version for nm -D
Extend _bfd_elf_get_symbol_version_string for nm -D to display symbol
version.  _bfd_elf_get_symbol_version_name is added to avoid updating
all XXX_get_symbol_version_string functions.

bfd/

	PR binutils/25708
	* elf-bfd.h (_bfd_elf_get_symbol_version_name): New.
	* elf.c (_bfd_elf_get_symbol_version_name): New function.  Based
	on the previous _bfd_elf_get_symbol_version_string.
	(_bfd_elf_get_symbol_version_string): Use it.

binutils/

	PR binutils/25708
	* nm.c (SYM_NAME): Removed.
	(print_symname): Add a pointer to struct extended_symbol_info
	argument.  Call _bfd_elf_get_symbol_version_name to get symbol
	version.
	(print_symdef_entry): Pass NULL to print_symname.
	(print_symbol_info_bsd): Update call to print_symname.
	(print_symbol_info_sysv): Likewise.
	(print_symbol_info_posix): Likewise.

ld/

	PR binutils/25708
	* testsuite/ld-elf/pr25708.d: New file.
2020-03-24 04:23:11 -07:00
Alan Modra 5e737279c6 i386msdos uninitialised read
Also reinstate ld i386aout for i386-msdos target, which doesn't build
otherwise.

bfd/
	* i386msdos.c (msdos_object_p): Don't access e_lfanew when that
	field hasn't been read.  Remove unnecessary casts.
ld/
	* Makefile.am (ALL_EMULATION_SOURCES): Reinstate ei386aout.c.
	Include ei386aout dep file.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
2020-03-23 23:26:12 +10:30
H.J. Lu 3d98c46092 plugin: Don't invoke LTO-wrapper
Don't invoke LTO-wrapper since the LTO wrapper approach is not only
slow but also unreliable.  For GCC 10 or newer, LDPT_ADD_SYMBOLS_V2
will be used.

bfd/

	* configure.ac (HAVE_EXECUTABLE_SUFFIX): Removed.
	(EXECUTABLE_SUFFIX): Likewise.
	* config.in: Regenerated.
	* configure: Likewise.
	* plugin.c (bfd_plugin_close_and_cleanup): Defined as
	_bfd_generic_close_and_cleanup.
	(plugin_list_entry): Remove resolution_file, resolution_option,
	real_bfd, real_nsyms, real_syms, lto_nsyms, lto_syms, gcc,
	lto_wrapper, gcc_env and initialized,
	(need_lto_wrapper_p): Removed.
	(get_lto_wrapper): Likewise.
	(setup_lto_wrapper_env): Likewise.
	(register_all_symbols_read): Likewise.
	(egister_cleanup): Likewise.
	(get_symbols): Likewise.
	(add_input_file): Likewise.
	(bfd_plugin_set_program_name): Remove need_lto_wrapper.
	(add_symbols): Updated.
	(try_claim): Likewise.
	(try_load_plugin): Likewise.
	(bfd_plugin_canonicalize_symtab): Likewise.
	* plugin.h (bfd_plugin_set_program_name): Remove int argument.
	(plugin_data_struct): Remove real_bfd, real_nsyms and real_syms.

binutils/

	* ar.c (main): Update bfd_plugin_set_program_name call.
	* nm.c (main): Likewise.

ld/

	* testsuite/ld-plugin/lto.exp (lto_link_tests): Run PR ld/25355
	test only for GCC 10 or newer.
2020-03-20 03:55:30 -07:00
Alan Modra c02d66610b Silence warnings due to plugin API change
* testplug.c (parse_symdefstr): Use %hhi to read sym->def, and
	clear new fields.
	* testplug2.c (parse_symdefstr): Likewise.
	* testplug3.c (parse_symdefstr): Likewise.
	* testplug4.c (parse_symdefstr): Likewise.
2020-03-20 12:59:54 +10:30
Christophe Lyon aef397a154 Non-contiguous memory regions support: Fix testcases after previous commit
2020-03-18  Christophe Lyon  <christophe.lyon@linaro.org>

	* testsuite/ld-arm/non-contiguous-arm4.d: Fix expected output.
	* testsuite/ld-powerpc/non-contiguous-powerpc.d: Likewise.

Change-Id: I8870800177e1ff79cdd05af13613ec53ef95681f
2020-03-18 12:38:30 +00:00
Christophe Lyon 53215f214c Non-contiguous memory regions support: Avoid calls to abort
Use '%F' format when printing error messages to exit cleanly rather
than by calling abort().

2020-03-18  Christophe Lyon  <christophe.lyon@linaro.org>

	bfd/
	* elf32-arm.c (arm_build_one_stub): Emit a fatal error message
	instead of calling abort.
	* elf32-csky.c (csky_build_one_stub): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
	* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
	* elf32-metag.c (metag_build_one_stub): Likewise.
	* elf32-nios2.c (nios2_build_one_stub): Likewise.
	* elf64-ppc.c (ppc_build_one_stub): Likewise.
	(ppc_size_one_stub): Likewise.
	* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.

	ld/
	* emultempl/xtensaelf.em: Emit a fatal error message
	instead of calling abort.
	* ldlang.c: Likewise.

Change-Id: I60deaeeee59d4e7cab06b8a40a3e51837c43a8ab
2020-03-18 10:09:43 +00:00
Alan Modra 02a8180e6f non-contiguous elf test
This test XPASSes on the generic ELF targets, so adjusting.  I also
made xtensa an xfail instead of a skip, since skip is hiding some
nastiness.

	* testsuite/ld-elf/non-contiguous.d: Don't xfail generic ELF
	targets.  Don't skip xtensa, xfail instead.
2020-03-14 17:24:19 +10:30
Christophe Lyon abf874aafe Add support for non-contiguous memory regions
2020-01-06  Christophe Lyon  <christophe.lyon@linaro.org>

	bfd/
	* bfd-in2.h: Regenerate.
	* section.c (asection): Add already_assigned field.
	(BFD_FAKE_SECTION): Add default initializer for it.
	* ecoff.c (bfd_debug_section): Initialize already_assigned field.
	* elf32-arm.c (arm_build_one_stub): Add support for
	non_contiguous_regions.
	* elf32-csky.c (csky_build_one_stub): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
	* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
	* elf32-metag.c (metag_build_one_stub): Likewise.
	* elf32-nios2.c (nios2_build_one_stub): Likewise.
	* elf64-ppc.c (ppc_build_one_stub): Likewise.
	(ppc_size_one_stub): Likewise.
	* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.
	* elflink.c (elf_link_input_bfd): Likewise.

	include/
	* bfdlink.h (bfd_link_info): Add non_contiguous_regions and
	non_contiguous_regions_warnings fields.

	ld/
	* ldlang.c (lang_add_section): Add support for
	non_contiguous_regions.
	(size_input_section): Likewise.
	(lang_size_sections_1): Likewise.
	(process_insert_statements): Likewise.
	* ldlex.h (option_values): Add OPTION_NON_CONTIGUOUS_REGIONS and
	OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS.
	* lexsup.c (ld_options): Add entries for
	--enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings.
	(parse_args): Handle it.
	* NEWS: Add --enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings.
	* ld.texi: Add --enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings documentation.
	* emultempl/armelf.em (elf32_arm_add_stub_section): Add
	SEC_LINKER_CREATED flag.
	* emultempl/xtensaelf.em (ld_build_required_section_dependence):
	Emit an error when --enable-non-contiguous-regions is used.
	* testsuite/ld-elf/non-contiguous.d: New.
	* testsuite/ld-elf/non-contiguous.ld: New.
	* testsuite/ld-elf/non-contiguous.s: New.
	* testsuite/ld-arm/arm-elf.exp: Run the new tests.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.s: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm2.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm4.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm4.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm5.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm5.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm6.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm6.ld: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/non-contiguous-powerpc.d: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.ld: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.sd: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc64.d: New.
2020-03-13 14:44:45 +00:00
H.J. Lu 74e10d1742 x86: Check static link of dynamic objects
On Linux/x86, when -static is passed to gcc, gcc passes it to linker
before all input files suitable for creating static executable.  X86
linker will report error for dynamic input objects if -static is passed
at command-line before all input files without --dynamic-linker unless
--no-dynamic-linker is used.

bfd/

	PR ld/24920
	* elf-linker-x86.h (elf_linker_x86_params): Add
	static_before_all_inputs and has_dynamic_linker.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Report
	dynamic input objects if -static is passed at command-line
	before all input files without --dynamic-linker unless
	--no-dynamic-linker is used.

ld/

	PR ld/24920
	* emulparams/elf32_x86_64.sh: Use static.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/static.sh: New file.
	* emultempl/elf-x86.em: Include "ldlex.h".
	* testsuite/ld-elf/pr24920.err: New file.
	* testsuite/ld-elf/linux-x86.exp: Run ld/24920 tests.
2020-03-13 07:39:06 -07:00
Christian Eggers 502794d432 Fix several mix up between octets and bytes in ELF program headers
When converting between addresses in ELF headers [octets] and bfd
LMA/VMA [bytes], the number of octets per byte needs to be
incorporated.

In ld, the SIZEOF_HEADERS linker script statement must be resolved to
bytes instead of octets.

include/
	* elf/internal.h (struct elf_internal_phdr): Add unit (octets)
	to several member field comments.
	(Elf_Internal_Shdr): likewise.
bfd/
	* elf.c (_bfd_elf_make_section_from_shdr): Introduce new temp
	opb.  Divide Elf_Internal_Shdr::sh_addr by opb when setting
	section LMA/VMA.
	(_bfd_elf_make_section_from_phdr): Similarly.
	(elf_fake_sections): Fix calculation of
	Elf_Internal_shdr::sh_addr from section VMA.
	(_bfd_elf_map_sections_to_segments): Fix mixup between octets
	and bytes.
	(assign_file_positions_for_load_sections): Fix calculations of
	Elf_Internal_shdr::p_vaddr and p_paddr from section LMA/VMA.  Fix
	comparison between program header address and section LMA.
	(assign_file_positions_for_non_load_sections): Likewise.
	(rewrite_elf_program_header): Likewise.  Introduce new temp opb.
	(IS_CONTAINED_BY_VMA): Add parameter opb.
	(IS_CONTAINED_BY_LMA,IS_SECTION_IN_INPUT_SEGMENT,
	INCLUDE_SECTION_IN_SEGMENT): Likewise.
	(copy_elf_program_header): Update call to ELF_SECTION_IN_SEGMENT.
	Fix calculations of p_addr_valid and p_vaddr_offset.
	* elflink.c (elf_link_add_object_symbols): Multiply section VMA
	with octets per byte when comparing against p_vaddr.
ld/
	* ldexp.c (fold_name): Return SIZEOF_HEADERS in bytes.
2020-03-13 15:37:11 +10:30
Alan Modra 1db6f99030 Don't merge sections with differing MASKPROC or MASKOS flags
Not just SHF_EXCLUDE but any of these flags ought to prevent merging
of sections for ld -r.

	* ldelf.c (elf_orphan_compatible): Return false when two sections
	have differing SHF_MASKPROC or SHF_MASKOS flags.
2020-03-11 15:00:44 +10:30
Alan Modra 92d4b13bf3 Reduce --warn-section-align output
PR 25570
	* ldlang.c (lang_size_sections_1): Don't report changes on
	second and subsequent iterations that make no change in
	alignment from that already reported.
2020-03-05 21:52:04 +10:30
Alan Modra baf09cba8f PR25570, ld duplicate "warning: changing start of section"
Note that because we should report a signed delta from the previous
VMA it isn't possible to use ngettext.  ngettext only supports
unsigned long values.  So byte/bytes goes from the message.

	PR 25570
	* ldlang.c (lang_sizing_iteration): New static var.
	(lang_size_sections_1): Warn about no memory region only on first
	iteration.  Warn about changing start address on first iteration
	then any delta from that on subsequent iterations.  Report a signed
	delta.
	(one_lang_size_sections_pass): Increment lang_sizing_iteration.
2020-03-05 09:48:04 +10:30
Alan Modra 45830fd60e Revert "PR25570, ld duplicate "warning: changing start of section""
This reverts commit 91114f7583.
2020-03-04 16:38:59 +10:30
Alan Modra 91114f7583 PR25570, ld duplicate "warning: changing start of section"
PR 25570
	* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
	errors/warnings until final pass.
	* ldexp.c (fold_name): Likewise.
2020-03-04 15:35:59 +10:30
Nick Clifton d8e4137b5e Note that the --rpath-link command line option will search the contents of the SEARCH_DIR linker script directive, if one is provided.
PR 25588
	* ld.texi (Options): Update the description of the --rpath-link
	option.
2020-03-03 12:53:00 +00:00
Alan Modra cb001c0d28 bfd_cleanup for object_p
The object_p (and archive_p, core_file_p) functions are not supposed
to have any target specific malloc'd memory attached to the bfd on
their return.  This should be obvious on a failure return, but it's
also true for a successful return.  The reason is that even though the
object_p recognises the file, that particular target may not be used
and thus the bfd won't be closed calling close_and_cleanup for the
target that allocated the memory.

It turns out that the object_p bfd_target* return value isn't needed.
In all cases except ld/plugin.c the target is abfd->xvec and with
ld/plugin.c the target isn't used.  So this patch returns a cleanup
function from object_p instead, called in bfd_check_format_matches to
tidy the bfd before trying a different target match.  The only cleanup
that does anything at this stage is the alpha-vms one.

bfd/
	* targets.c (bfd_cleanup): New typedef.
	(struct bfd <_bfd_check_format>): Return a bfd_cleanup.
	* libbfd-in.h (_bfd_no_cleanup): Define.
	* format.c (bfd_reinit): Add cleanup parameter, call it.
	(bfd_check_format_matches): Set cleanup from _bfd_check_format
	call and pass to bfd_reinit.  Delete temp, use abfd->xvec instead.
	* aout-target.h (callback, object_p): Return bfd_cleanup.
	* aout-tic30.c (tic30_aout_callback, tic30_aout_object_p): Likewise.
	* archive.c (bfd_generic_archive_p): Likewise.
	* binary.c (binary_object_p): Likewise.
	* coff-alpha.c (alpha_ecoff_object_p): Likewise.
	* coff-ia64.c (ia64coff_object_p): Likewise.
	* coff-rs6000.c (_bfd_xcoff_archive_p, rs6000coff_core_p): Likewise.
	* coff-sh.c (coff_small_object_p): Likewise.
	* coff-stgo32.c (go32_check_format): Likewise.
	* coff64-rs6000.c (xcoff64_archive_p, rs6000coff_core_p),
	(xcoff64_core_p): Likewise.
	* coffgen.c (coff_real_object_p, coff_object_p): Likewise.
	* elf-bfd.h (bfd_elf32_object_p, bfd_elf32_core_file_p),
	(bfd_elf64_object_p, bfd_elf64_core_file_p): Likewise.
	* elfcode.h (elf_object_p): Likewise.
	* elfcore.h (elf_core_file_p): Likewise.
	* i386msdos.c (msdos_object_p): Likewise.
	* ihex.c (ihex_object_p): Likewise.
	* libaout.h (some_aout_object_p): Likewise.
	* libbfd-in.h (bfd_generic_archive_p, _bfd_dummy_target),
	(_bfd_vms_lib_alpha_archive_p, _bfd_vms_lib_ia64_archive_p): Likewise.
	* libbfd.c (_bfd_dummy_target): Likewise.
	* libcoff-in.h (coff_object_p): Likewise.
	* mach-o-aarch64.c (bfd_mach_o_arm64_object_p),
	(bfd_mach_o_arm64_core_p): Likewise.
	* mach-o-arm.c (bfd_mach_o_arm_object_p),
	(bfd_mach_o_arm_core_p): Likewise.
	* mach-o-i386.c (bfd_mach_o_i386_object_p),
	(bfd_mach_o_i386_core_p): Likewise.
	* mach-o-x86-64.c (bfd_mach_o_x86_64_object_p),
	(bfd_mach_o_x86_64_core_p): Likewise.
	* mach-o.c (bfd_mach_o_header_p, bfd_mach_o_gen_object_p),
	(bfd_mach_o_gen_core_p, bfd_mach_o_fat_archive_p): Likewise.
	* mach-o.h (bfd_mach_o_object_p, bfd_mach_o_core_p),
	(bfd_mach_o_fat_archive_p, bfd_mach_o_header_p): Likewise.
	* mmo.c (mmo_object_p): Likewise.
	* pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise.
	* peicode.h (coff_real_object_p, pe_ILF_object_p),
	(pe_bfd_object_p): Likewise.
	* plugin.c (ld_plugin_object_p, bfd_plugin_object_p): Likewise.
	* ppcboot.c (ppcboot_object_p): Likewise.
	* rs6000-core.c (rs6000coff_core_p): Likewise.
	* som.c (som_object_setup, som_object_p): Likewise.
	* srec.c (srec_object_p, symbolsrec_object_p): Likewise.
	* tekhex.c (tekhex_object_p): Likewise.
	* vms-alpha.c (alpha_vms_object_p): Likewise.
	* vms-lib.c (_bfd_vms_lib_archive_p, _bfd_vms_lib_alpha_archive_p),
	(_bfd_vms_lib_ia64_archive_p, _bfd_vms_lib_txt_archive_p): Likewise.
	* wasm-module.c (wasm_object_p): Likewise.
	* xsym.c (bfd_sym_object_p): Likewise.
	* xsym.h (bfd_sym_object_p): Likewise.
	* aoutx.h (some_aout_object_p): Likewise, and callback parameter
	return type.
	* pdp11.c (some_aout_object_p): Likewise.
	* plugin.c (register_ld_plugin_object_p): Update object_p
	parameter type.
	* plugin.h (register_ld_plugin_object_p): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.
ld/
	* plugin.c (plugin_object_p): Return a bfd_cleanup.
	(plugin_cleanup): New function.
2020-03-02 19:30:48 +10:30
H.J. Lu 2aa90762b7 plugin: Copy the no_export field to the IR dummy object
Copy the no_export field to the IR dummy object when claiming an IR
object.

	PR ld/25618
	* plugin.c (plugin_object_p): Copy the no_export field to the IR
	dummy object.
	* testsuite/ld-plugin/lto.exp (lto_link_elf_tests): Add
	PR ld/25618 tests.
	* testsuite/ld-plugin/pr25618.d: New file.
	* testsuite/ld-plugin/pr25618a.cc: Likewise.
	* testsuite/ld-plugin/pr25618a.h: Likewise.
	* testsuite/ld-plugin/pr25618b.cc: Likewise.
	* testsuite/ld-plugin/pr25618b.h: Likewise.
2020-03-01 17:10:49 -08:00
Alan Modra 5f60280291 mmix-mmo set SEC_DATA for .data section
With the bfd_decode_symclass change, ld SIZEOF test fails due to
data_end being reported as type '?'.

bfd/
	PR 24511
	* mmo.c (mmo_scan): Set SEC_DATA for .data.
ld/
	PR 24511
	* testsuite/ld-mmix/b-fixo2.d: Adjust for .data change.
	* testsuite/ld-mmix/sec-2.d: Likewise.
	* testsuite/ld-mmix/sec-3.d: Likewise.
	* testsuite/ld-mmix/sec-4.d: Likewise.
	* testsuite/ld-mmix/spec802.d: Likewise.
	* testsuite/ld-mmix/spec803.d: Likewise.
	* testsuite/ld-mmix/spec804.d: Likewise.
	* testsuite/ld-mmix/spec805.d: Likewise.
	* testsuite/ld-mmix/spec806.d: Likewise.
	* testsuite/ld-mmix/spec807.d: Likewise.
	* testsuite/ld-mmix/spec808.d: Likewise.
2020-02-28 08:19:42 +10:30
H.J. Lu 3312f67c09 ld: Add PR ld/25593 tests
PR ld/25593
	* testsuite/ld-plugin/lto.exp: Run PR ld/25593 tests.
	* testsuite/ld-plugin/pr25593.d: New file.
	* testsuite/ld-plugin/pr25593a-1.c: Likewise.
	* testsuite/ld-plugin/pr25593a-2.c: Likewise.
	* testsuite/ld-plugin/pr25593b.c: Likewise.
	* testsuite/ld-plugin/pr25593c.c: Likewise.
	* testsuite/ld-plugin/pr25593d.c: Likewise.
	* testsuite/ld-plugin/pr25593e.c: Likewise.
2020-02-26 03:58:47 -08:00
Alan Modra dc1e8a474f Indent labels
Labels don't go in the first column according to standard emacs C
indent rules, and I got annoyed enough at seeing diff -p show a label
rather than the function name to fix this.

bfd/
	* aoutx.h: Indent labels correctly.  Format error strings.
	* archive.c: Likewise.
	* archive64.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-stgo32.c: Likewise.
	* cpu-arm.c: Likewise.
	* dwarf2.c: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-properties.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf-strtab.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-csky.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-pru.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfcode.h: Likewise.
	* elfcore.h: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfnn-riscv.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-x86.c: Likewise.
	* i386lynx.c: Likewise.
	* merge.c: Likewise.
	* pdp11.c: Likewise.
	* plugin.c: Likewise.
	* reloc.c: Likewise.
binutils/
	* elfedit.c: Indent labels correctly.
	* readelf.c: Likewise.
	* resres.c: Likewise.
gas/
	* config/obj-elf.c: Indent labels correctly.
	* config/obj-macho.c: Likewise.
	* config/tc-aarch64.c: Likewise.
	* config/tc-alpha.c: Likewise.
	* config/tc-arm.c: Likewise.
	* config/tc-cr16.c: Likewise.
	* config/tc-crx.c: Likewise.
	* config/tc-frv.c: Likewise.
	* config/tc-i386-intel.c: Likewise.
	* config/tc-i386.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-mn10200.c: Likewise.
	* config/tc-mn10300.c: Likewise.
	* config/tc-nds32.c: Likewise.
	* config/tc-riscv.c: Likewise.
	* config/tc-s12z.c: Likewise.
	* config/tc-xtensa.c: Likewise.
	* config/tc-z80.c: Likewise.
	* read.c: Likewise.
	* symbols.c: Likewise.
	* write.c: Likewise.
ld/
	* emultempl/cskyelf.em: Indent labels correctly.
	* ldfile.c: Likewise.
	* ldlang.c: Likewise.
	* plugin.c: Likewise.
opcodes/
	* aarch64-asm.c: Indent labels correctly.
	* aarch64-dis.c: Likewise.
	* aarch64-gen.c: Likewise.
	* aarch64-opc.c: Likewise.
	* alpha-dis.c: Likewise.
	* i386-dis.c: Likewise.
	* nds32-asm.c: Likewise.
	* nfp-dis.c: Likewise.
	* visium-dis.c: Likewise.
2020-02-26 10:37:25 +10:30
Alan Modra e310298cf3 PR25593, --as-needed breaks DT_NEEDED order with linker plugin
This patch delays setting up DT_NEEDED dynamic tags until all object
files and libraries have been opened and their symbols processed,
rather than adding the tags while processing symbols.  Tags are
ordered according to the position of the associated library on the
command line and linker scripts.  It is still possible with
--as-needed libs that are mentioned more than once for tags to be
ordered according to which mention was needed.  For example with
"--as-needed a.so b.so c.so b.so" when b.so is not needed by a.so or
any other prior object file but is needed by c.so, the order of tags
will be "A C B".

bfd/
	PR 25593
	* elf-bfd.h (struct elf_link_hash_table): Rename "loaded" to
	"dyn_loaded".
	(bfd_elf_add_dt_needed_tag): Declare.
	* elf-strtab.c (_bfd_elf_strtab_restore): Handle NULL buf.
	* elflink.c (bfd_elf_add_dt_needed_tag): Make global and rename
	from elf_add_dt_needed_tag.  Remove soname and doit param.
	(elf_link_add_object_symbols): Don't use elf_add_dt_needed_tag
	to see whether as-needed lib is already loaded, use dyn_loaded
	list instead.  When saving and restoring around as-needed lib
	handle possibility that dynstr has not been initialised.  Don't
	add DT_NEEDED tags here.  Limit dyn_loaded list to dynamic libs.
	Mark libs loaded via DT_NEEDED entries of other libs with
	DYN_NO_NEEDED if they should not be mentioned in DT_NEEDED of
	the output.
	(elf_link_check_versioned_symbol): Remove now unneccesary
	DYNAMIC check when traversing dyn_loaded list.
ld/
	PR 25593
	* ldelf.c (ldelf_try_needed): Add DT_NEEDED lib to input_bfds.
	(ldelf_after_open): Save state of input_bfds list before loading
	DT_NEEDED libs.  Traverse input_bfds list adding DT_NEEDED tags.
	Restore input_bfds list.
	* testsuite/ld-cris/gotplt1.d: Adjust for changed .dynstr order.
2020-02-26 10:37:25 +10:30
Nick Clifton 45c63c0fe8 Updated translations for some of the binutils sub-directories. 2020-02-24 14:52:34 +00:00
Alan Modra 7b3c27152b PR25585, PHDR segment not covered by LOAD segment
I closed this bug as invalid, but I think it is worth mentioning in NEWS
that older linkers didn't check PT_PHDR very well.  The patch also allows
people to force an output file with --noinhibit-exec after the error.

bfd/
	PR 25585
	* elf.c (assign_file_positions_for_load_sections): Continue linking
	on "PHDR segment not covered by LOAD segment" errors.
ld/
	PR 25585
	* NEWS: Mention better "PHDR segment not covered by LOAD segment"
	checking.
2020-02-22 12:53:52 +10:30
Sergey Belyashov fcaaac0a0d Various fixes for the Z80 support.
PR 25537
ld	* emultempl/z80.em: Remove machine compatability checking.

	PR 25517
	* testsuite/ld-z80/arch_ez80_adl.d: Update command line.
	* testsuite/ld-z80/arch_ez80_z80.d: Likewise.
	* testsuite/ld-z80/arch_r800.d: Likewise.
	* testsuite/ld-z80/arch_z180.d: Likewise.
	* testsuite/ld-z80/arch_z80n.d: Likewise.
	* testsuite/ld-z80/comb_arch_ez80_z80.d: Likewise.
	* testsuite/ld-z80/comb_arch_z180_z80.d: Likewise.
	* testsuite/ld-z80/comb_arch_z80_ez80.d: Likewise.
	* testsuite/ld-z80/comb_arch_z80_z180.d: Likewise.
	* testsuite/ld-z80/comb_arch_z80_z80n.d: Likewise.
	* testsuite/ld-z80/relocs_b_ez80.d: Likewise.
	* testsuite/ld-z80/relocs_b_z80.d: Likewise.
	* testsuite/ld-z80/relocs_f_ez80.d: Likewise.
	* testsuite/ld-z80/relocs_f_z80.d: Likewise.
	* testsuite/ld-z80/relocs_f_z80n.d: Likewise.

bfd
	* cpu-z80.c: Add machine type compatibility checking.

gas
	* config/tc-z80.c (md_parse_option): Do not use an underscore
	prefix for local labels in SDCC compatability mode.
	(z80_start_line_hook): Remove SDCC dollar label support.
	* testsuite/gas/z80/sdcc.d: Update expected disassembly.
	* testsuite/gas/z80/sdcc.s: Likewise.

	* config/tc-z80.c: Add -march option.
	* doc/as.texi: Update Z80 documentation.
	* doc/c-z80.texi: Likewise.
	* testsuite/gas/z80/ez80_adl_all.d: Update command line.
	* testsuite/gas/z80/ez80_adl_suf.d: Likewise.
	* testsuite/gas/z80/ez80_pref_dis.d: Likewise.
	* testsuite/gas/z80/ez80_z80_all.d: Likewise.
	* testsuite/gas/z80/ez80_z80_suf.d: Likewise.
	* testsuite/gas/z80/gbz80_all.d: Likewise.
	* testsuite/gas/z80/r800_extra.d: Likewise.
	* testsuite/gas/z80/r800_ii8.d: Likewise.
	* testsuite/gas/z80/r800_z80_doc.d: Likewise.
	* testsuite/gas/z80/sdcc.d: Likewise.
	* testsuite/gas/z80/z180.d: Likewise.
	* testsuite/gas/z80/z180_z80_doc.d: Likewise.
	* testsuite/gas/z80/z80_doc.d: Likewise.
	* testsuite/gas/z80/z80_ii8.d: Likewise.
	* testsuite/gas/z80/z80_in_f_c.d: Likewise.
	* testsuite/gas/z80/z80_op_ii_ld.d: Likewise.
	* testsuite/gas/z80/z80_out_c_0.d: Likewise.
	* testsuite/gas/z80/z80_sli.d: Likewise.
	* testsuite/gas/z80/z80n_all.d: Likewise.
	* testsuite/gas/z80/z80n_reloc.d: Likewise.
2020-02-19 17:46:10 +00:00
Alan Modra 2e3cd5d013 Adjust PR25355 testcase
* testsuite/ld-plugin/pr25355.d: Allow alpha-linux nm result.
2020-02-19 13:10:47 +10:30
H.J. Lu 0aa99dcd70 Use GCC LTO wrapper to get real symbols from LTO IR objects
GCC LTO wrapper is needed to extract real symbols from LTO IR objects.
This patch does the following:

1. Set up GCC LTO wrapper for each LTO IR object.
2. Run GCC LTO wrapper to get the real object.
3. Extract symbol info from the real object.
4. Cleanup afterwards.

bfd/

	PR binutils/25355
	* configure.ac (HAVE_EXECUTABLE_SUFFIX): New AC_DEFINE.
	(EXECUTABLE_SUFFIX): Likewise.
	* config.in: Regenerated.
	* configure: Likewise.
	* plugin.c (bfd_plugin_close_and_cleanup): Removed.
	(plugin_list_entry): Add all_symbols_read, cleanup_handler,
	gcc, lto_wrapper, resolution_file, resolution_option, gcc_env,
	real_bfd, real_nsyms, real_syms, lto_nsyms and lto_syms.
	(get_lto_wrapper): New.
	(setup_lto_wrapper_env): Likewise.
	(current_plugin): Likewise.
	(register_all_symbols_read): Likewise.
	(register_cleanup): Likewise.
	(get_symbols): Likewise.
	(add_input_file): Likewise.
	(bfd_plugin_close_and_cleanup): Likewise.
	(claim_file): Removed.
	(register_claim_file): Set current_plugin->claim_file.
	(add_symbols): Make a copy of LTO symbols.  Set lto_nsyms and
	lto_syms in current_plugin.
	(try_claim): Use current_plugin->claim_file.  Call LTO plugin
	all_symbols_read handler.  Copy real symbols to plugin_data.
	Call LTO plugin cleanup handler.  Clean up for LTO wrapper.
	(try_load_plugin): Don't reuse the previous plugin for LTO
	wrapper.  Set up GCC LTO wrapper if possible.  Don't set
	plugin_list_iter->claim_file.
	(bfd_plugin_canonicalize_symtab): Use real LTO symbols if
	possible.
	* plugin.h (plugin_data_struct): Add real_bfd, real_nsyms and
	real_syms.

ld/

	PR binutils/25355
	* testsuite/ld-plugin/lto.exp: Run PR binutils/25355 test.
	* testsuite/ld-plugin/pr25355.c: New file.
	* testsuite/ld-plugin/pr25355.d: Likewise.
	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Support compile
	only dump.
2020-02-10 19:01:53 -08:00
H.J. Lu 6e56965616 unique.exp: Update contains_unique_symbol
Since commit 9fc0b501af changed symbols from a/b to a_val/b_val,
contains_unique_symbol needs adjustment.

	* testsuite/ld-unique/unique.exp (contains_unique_symbol): Updated.
2020-02-07 12:03:40 -08:00
Sergey Belyashov 9fc0b501af Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add DWARF debug info support to the Z80 assembler.
PR 25469
bfd	* archures.c: Add GBZ80 and Z80N machine values.
	* reloc.c: Add BFD_RELOC_Z80_16_BE.
	* coff-z80.c: Add support for new reloc.
	* coffcode.h: Add support for new machine values.
	* cpu-z80.c: Add support for new machine names.
	* elf32-z80.c: Add support for new reloc.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

binutils* readelf.c (get_machine_flags): Add support for Z80N machine
	number.

gas	* config/tc-z80.c: Add -gbz80 command line option to generate code
	for the GameBoy Z80.  Add support for generating DWARF.
	* config/tc-z80.h: Add support for DWARF debug information
	generation.
	* doc/c-z80.texi: Document new command line option.
	* testsuite/gas/z80/gbz80_all.d: New file.
	* testsuite/gas/z80/gbz80_all.s: New file.
	* testsuite/gas/z80/z80.exp: Run the new tests.
	* testsuite/gas/z80/z80n_all.d: New file.
	* testsuite/gas/z80/z80n_all.s: New file.
	* testsuite/gas/z80/z80n_reloc.d: New file.

include	* coff/internal.h (R_IMM16BE): Define.
	* elf/z80.h (EF_Z80_MACH_Z80N): Define.
	(R_Z80_16_BE): New reloc.

ld	* emulparams/elf32z80.sh: Use z80 emulation.
	* emultempl/z80.em: Make generic to both COFF and ELF Z80 emulations.
	* emultempl/z80elf.em: Delete.
	* testsuite/ld-elf/pr22450.d: Expect to fail for the Z80.
	* testsuite/ld-elf/sec64k.exp: Fix Z80 assembly.
	* testsuite/ld-unique/pr21529.s: Avoid register name conflict.
	* testsuite/ld-unique/unique.s: Likewise.
	* testsuite/ld-unique/unique_empty.s: Likewise.
	* testsuite/ld-unique/unique_shared.s: Likewise.
	* testsuite/ld-unique/unique.d: Updated expected output.
	* testsuite/ld-z80/arch_z80n.d: New file.
	* testsuite/ld-z80/comb_arch_z80_z80n.d: New file.
	* testsuite/ld-z80/labels.s: Add more labels.
	* testsuite/ld-z80/relocs.s: Add more reloc tests.
	* testsuite/ld-z80/relocs_f_z80n.d: New file

opcodes	* z80-dis.c: Add support for GBZ80 opcodes.
2020-02-07 14:53:46 +00:00
H.J. Lu adb8754e48 pr25022.d: Xfail more targets without ldelf_before_place_orphans
PR ld/25022
	* testsuite/ld-elf/pr25022.d: Xfail more targets which don't use
	ldelf_before_place_orphans.
2020-02-07 05:10:05 -08:00
H.J. Lu 9b538ba71f ELF: Discard a section if any of its linked-to sections has been discarded
Add ldelf_before_place_orphans to call before lang_place_orphans to
discard a section if any of its linked-to sections has been discarded.

	PR ld/25022
	* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
	before_place_orphans_default.
	* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/vanilla.em (ld_${EMULATION_NAME}_emulation): Likewise.
	* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Use
	ldelf_before_place_orphans.
	* ldelf.c (ldelf_before_place_orphans): New.
	* ldelf.h (ldelf_before_place_orphans): Likewise.
	* ldemul.c (ldemul_before_place_orphans): Likewise.
	(before_place_orphans_default): Likewise.
	* ldemul.h (ldemul_before_place_orphans): Likewise.
	(before_place_orphans_default): Likewise.
	(ld_emulation_xfer_struct): Add before_place_orphans.
	* ldlang.c (lang_process): Call ldemul_before_place_orphans
	before lang_place_orphans.
	* testsuite/ld-elf/pr25022.d: New file.
	* testsuite/ld-elf/pr25022.s: Likewise.
	* testsuite/ld-elf/pr25022.t: Likewise.
2020-02-06 19:43:03 -08:00
H.J. Lu 5242a0a000 ld: Issue an error for GC on __patchable_function_entries section
__patchable_function_entries section is generated by a compiler with
-fpatchable-function-entry=XX.  The assembly code looks like this:

---
	.text
	.globl	_start
	.type	_start, %function
_start:
	.section __patchable_function_entries,"aw",%progbits
	.dc.a	.LPFE1
	.text
.LPFE1:
	.byte 0
---

But --gc-sections will silently remove __patchable_function_entries
section and generate corrupt result.  This patch disallows garbage
collection on __patchable_function_entries section without linked-to
section.

bfd/

	PR ld/25490
	* elflink.c (_bfd_elf_gc_mark_extra_sections): Issue an error
	for garbage collection on __patchable_function_entries section
	without linked-to section.

ld/

	PR ld/25490
	* testsuite/ld-elf/pr25490-1.d: New file.
	* testsuite/ld-elf/pr25490-1.s: Likewise.
2020-02-06 19:40:38 -08:00
H.J. Lu b7d0721677 ELF: Support the section flag 'o' in .section directive
As shown in

https://sourceware.org/bugzilla/show_bug.cgi?id=25490

--gc-sections will silently remove __patchable_function_entries section
and generate corrupt result.  This patch adds the section flag 'o' to
.section directive:

.section __patchable_function_entries,"awo",@progbits,foo
.section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat
.section __patchable_function_entries,"awo",@progbits,bar,unique,4
.section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat,unique,1

which specifies the symbol name which the section references.  Assmebler
will set its elf_linked_to_section to a local section where the symbol
is defined.

Linker is updated to call mark_hook if gc_mark of any of its linked-to
sections is set after all sections, except for backend specific ones,
have been garbage collected.

bfd/

	PR gas/25381
	* bfd-in2.h: Regenerated.
	* elflink.c (_bfd_elf_gc_mark_extra_sections): Call mark_hook
	on section if gc_mark of any of its linked-to sections is set
	and don't set gc_mark again.
	* section.c (asection): Add linked_to_symbol_name to map_head
	union.

gas/

	PR gas/25381
	* config/obj-elf.c (get_section): Also check
	linked_to_symbol_name.
	(obj_elf_change_section): Also set map_head.linked_to_symbol_name.
	(obj_elf_parse_section_letters): Handle the 'o' flag.
	(build_group_lists): Renamed to ...
	(build_additional_section_info): This.  Set elf_linked_to_section
	from map_head.linked_to_symbol_name.
	(elf_adjust_symtab): Updated.
	* config/obj-elf.h (elf_section_match): Add linked_to_symbol_name.
	* doc/as.texi: Document the 'o' flag.
	* testsuite/gas/elf/elf.exp: Run PR gas/25381 tests.
	* testsuite/gas/elf/section18.d: New file.
	* testsuite/gas/elf/section18.s: Likewise.
	* testsuite/gas/elf/section19.d: Likewise.
	* testsuite/gas/elf/section19.s: Likewise.
	* testsuite/gas/elf/section20.d: Likewise.
	* testsuite/gas/elf/section20.s: Likewise.
	* testsuite/gas/elf/section21.d: Likewise.
	* testsuite/gas/elf/section21.l: Likewise.
	* testsuite/gas/elf/section21.s: Likewise.

ld/

	PR ld/24526
	PR ld/25021
	PR ld/25490
	* testsuite/ld-elf/elf.exp: Run PR ld/25490 tests.
	* testsuite/ld-elf/pr24526.d: New file.
	* testsuite/ld-elf/pr24526.s: Likewise.
	* testsuite/ld-elf/pr25021.d: Likewise.
	* testsuite/ld-elf/pr25021.s: Likewise.
	* testsuite/ld-elf/pr25490-2-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-2-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-2-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-2.s: Likewise.
	* testsuite/ld-elf/pr25490-3-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-3-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-3-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-3.s: Likewise.
	* testsuite/ld-elf/pr25490-4-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-4-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-4-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-4.s: Likewise.
	* testsuite/ld-elf/pr25490-5-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-5-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-5-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-5.s: Likewise.
	* testsuite/ld-elf/pr25490-6-16.rd: Likewise.
	* testsuite/ld-elf/pr25490-6-32.rd: Likewise.
	* testsuite/ld-elf/pr25490-6-64.rd: Likewise.
	* testsuite/ld-elf/pr25490-6.s: Likewise.
2020-02-06 18:05:10 -08:00
H.J. Lu 9e4d08bbf4 check_gc_sections_available: Mark z80 as not supported
[hjl@gnu-cfl-2 tmpdir]$ ../ld-new -V --gc-sections pr22319.o
GNU ld (GNU Binutils) 2.34.50.20200206
  Supported emulations:
   elf32z80
../ld-new: warning: gc-sections option ignored
../ld-new: warning: cannot find entry symbol _start; defaulting to 0000000000000100
[hjl@gnu-cfl-2 tmpdir]$

	* testsuite/lib/ld-lib.exp (check_gc_sections_available): Mark
	z80 as not supported.
2020-02-06 06:42:11 -08:00
Alan Modra bb4e012ca0 Enable ld-ifunc tests for more targets
Also fix some ix86 fails.

	* testsuite/ld-ifunc/ifunc.exp: Enable for more targets, specifying
	targets that don't support ifunc rather than ones that do.
	(contains_irelative_reloc): Match R_PARISC_IPLT.
	* testsuite/ld-ifunc/lib.c: Don't use .set in asm.
	* testsuite/ld-ifunc/ifunc-23-x86.s,
	* testsuite/ld-ifunc/ifunc-24-x86.s,
	* testsuite/ld-ifunc/ifunc-25-x86.s,
	* testsuite/ld-ifunc/ifunc-4-local-x86.s,
	* testsuite/ld-ifunc/ifunc-4-x86.s: Define _main.
	* testsuite/ld-ifunc/ifunc-10-i386.d,
	* testsuite/ld-ifunc/ifunc-11-i386.d,
	* testsuite/ld-ifunc/ifunc-12-i386.d,
	* testsuite/ld-ifunc/ifunc-13-i386.d,
	* testsuite/ld-ifunc/ifunc-14a-i386.d,
	* testsuite/ld-ifunc/ifunc-14b-i386.d,
	* testsuite/ld-ifunc/ifunc-14c-i386.d,
	* testsuite/ld-ifunc/ifunc-14d-i386.d,
	* testsuite/ld-ifunc/ifunc-14e-i386.d,
	* testsuite/ld-ifunc/ifunc-14f-i386.d,
	* testsuite/ld-ifunc/ifunc-15-i386.d,
	* testsuite/ld-ifunc/ifunc-16-i386-now.d,
	* testsuite/ld-ifunc/ifunc-16-i386.d,
	* testsuite/ld-ifunc/ifunc-17a-i386.d,
	* testsuite/ld-ifunc/ifunc-17b-i386.d,
	* testsuite/ld-ifunc/ifunc-18a-i386.d,
	* testsuite/ld-ifunc/ifunc-18b-i386.d,
	* testsuite/ld-ifunc/ifunc-19a-i386.d,
	* testsuite/ld-ifunc/ifunc-19b-i386.d,
	* testsuite/ld-ifunc/ifunc-2-i386-now.d,
	* testsuite/ld-ifunc/ifunc-2-i386.d,
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d,
	* testsuite/ld-ifunc/ifunc-2-local-i386.d,
	* testsuite/ld-ifunc/ifunc-20-i386.d,
	* testsuite/ld-ifunc/ifunc-21-i386.d,
	* testsuite/ld-ifunc/ifunc-22-i386.d,
	* testsuite/ld-ifunc/ifunc-26.d,
	* testsuite/ld-ifunc/ifunc-5a-i386.d,
	* testsuite/ld-ifunc/ifunc-5a-local-i386.d,
	* testsuite/ld-ifunc/ifunc-5b-i386.d,
	* testsuite/ld-ifunc/ifunc-5b-local-i386.d,
	* testsuite/ld-ifunc/ifunc-5r-local-i386.d,
	* testsuite/ld-ifunc/ifunc-6a-i386.d,
	* testsuite/ld-ifunc/ifunc-6b-i386.d,
	* testsuite/ld-ifunc/ifunc-7a-i386.d,
	* testsuite/ld-ifunc/ifunc-7b-i386.d,
	* testsuite/ld-ifunc/ifunc-8-i386.d,
	* testsuite/ld-ifunc/ifunc-9-i386.d,
	* testsuite/ld-ifunc/pr17154-i386-now.d,
	* testsuite/ld-ifunc/pr17154-i386.d: xfail lynxos, nto, and solaris.
2020-02-06 13:59:40 +10:30
Alan Modra 02e0be6901 mbind gas tests and supports_gnu_osabi testsuite infrastructure
With the addition of section16 tests we have multiple tests
advertising themselves as "mbind sections" and "mbind section
contents".  This patch fixes that, and fails on quite a few targets
that force an OSABI value.  It's a pain specifying all the relevant
arm targets on an xfail line, so I wrote supports_gnu_osabi.

binutils/
	* testsuite/lib/binutils-common.exp (match_target): Accept '!' before
	TCL procedure.
	(supports_gnu_osabi): New procedure.
	(is_generic): New, from ld-lib.exp.
	(supports_gnu_unique): Use the above.
gas/
	* testsuite/gas/elf/section12a.d: Use supports_gnu_osabi in
	xfail, and rename test.
	* testsuite/gas/elf/section12b.d: Likewise.
	* testsuite/gas/elf/section16a.d: Likewise.
	* testsuite/gas/elf/section16b.d: Likewise.
ld/
	* testsuite/lib/ld-lib.exp (is_generic): Delete.
	* testsuite/ld-unique/unique.exp: Exclude tic6x.
2020-02-06 13:57:37 +10:30
Alan Modra b88237bc21 i386-moss and i386-openbsd ld config
i386-moss is an ELF target needing ldelf.c.  x86 openbsd wouldn't even
build, so I added entries to do the same as netbsd.  Quite likely this
isn't ideal but if the openbsd folk don't contribute their changes
this is what they get.

	* configure.tgt (i[3-7]86-*-moss*): Don't clear targ_extra_ofiles.
	(i[3-7]86-*-openbsd*, x86_64-*-openbsd*): Add.
2020-02-06 13:56:29 +10:30
H.J. Lu a8c4d40b57 ELF: Add support for unique section ID to assembler
Clang's integrated assembler supports multiple section with the same
name:

	.section .text,"ax",@progbits,unique,1
	nop
	.section .text,"ax",@progbits,unique,2
	nop

"unique,N" assigns the number, N, as the section ID, to a section.  The
valid values of the section ID are between 0 and 4294967295.  It can be
used to distinguish different sections with the same section name.

This is useful with -fno-unique-section-names -ffunction-sections.
-ffunction-sections by default generates .text.foo, .text.bar, etc.
Using the same string can save lots of space in .strtab.

This patch adds section_id to bfd_section and reuses the linker
internal bit in BFD section flags, SEC_LINKER_CREATED, for assmebler
internal use to mark valid section_id.  It also updates objdump to
compare section pointers if 2 sections comes from the same file since
2 different sections can have the same section name.

bfd/

	PR gas/25380
	* bfd-in2.h: Regenerated.
	* ecoff.c (bfd_debug_section): Add section_id.
	* section.c (bfd_section): Add section_id.
	(SEC_ASSEMBLER_SECTION_ID): New.
	(BFD_FAKE_SECTION): Add section_id.

binutils/

	PR gas/25380
	* objdump.c (sym_ok): Return FALSE if 2 sections are in the
	same file with different section pointers.

gas/

	PR gas/25380
	* config/obj-elf.c (section_match): Removed.
	(get_section): Also match SEC_ASSEMBLER_SECTION_ID and
	section_id.
	(obj_elf_change_section): Replace info and group_name arguments
	with match_p.  Also update the section ID and flags from match_p.
	(obj_elf_section): Handle "unique,N".  Update call to
	obj_elf_change_section.
	* config/obj-elf.h (elf_section_match): New.
	(obj_elf_change_section): Updated.
	* config/tc-arm.c (start_unwind_section): Update call to
	obj_elf_change_section.
	* config/tc-ia64.c (obj_elf_vms_common): Likewise.
	* config/tc-microblaze.c (microblaze_s_data): Likewise.
	(microblaze_s_sdata): Likewise.
	(microblaze_s_rdata): Likewise.
	(microblaze_s_bss): Likewise.
	* config/tc-mips.c (s_change_section): Likewise.
	* config/tc-msp430.c (msp430_profiler): Likewise.
	* config/tc-rx.c (parse_rx_section): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* doc/as.texi: Document "unique,N" in .section directive.
	* testsuite/gas/elf/elf.exp: Run "unique,N" tests.
	* testsuite/gas/elf/section15.d: New file.
	* testsuite/gas/elf/section15.s: Likewise.
	* testsuite/gas/elf/section16.s: Likewise.
	* testsuite/gas/elf/section16a.d: Likewise.
	* testsuite/gas/elf/section16b.d: Likewise.
	* testsuite/gas/elf/section17.d: Likewise.
	* testsuite/gas/elf/section17.l: Likewise.
	* testsuite/gas/elf/section17.s: Likewise.
	* testsuite/gas/i386/unique.d: Likewise.
	* testsuite/gas/i386/unique.s: Likewise.
	* testsuite/gas/i386/x86-64-unique.d: Likewise.
	* testsuite/gas/i386/i386.exp: Run unique and x86-64-unique.

ld/

	PR gas/25380
	* testsuite/ld-i386/pr22001-1c.S: Use "unique,N" in .section
	directives.
	* testsuite/ld-i386/tls-gd1.S: Likewise.
	* testsuite/ld-x86-64/pr21481b.S: Likewise.
2020-02-02 17:08:01 -08:00
Jan Beulich 5cebc931d7 ld/doc: drop blank between @option and brace
Commit 9e7028aa1e ("PowerPC64 __tls_get_addr_desc") introduced a use
of @option which apparently newer makeinfo tolerates, but older ones
reject. Drop the unnecessary (a per all other uses of @option) blank.
2020-01-30 17:02:33 +01:00