Commit Graph

5478 Commits

Author SHA1 Message Date
H.J. Lu de9a3c4285 x86: Create dynamic sections in create_dynamic_sections
This patch creates dynamic sections in i386/x86-64 create_dynamic_sections
instead of creating them on demend.  Linker will strip them if they are
empty.  It changes order in x86-64 .eh_frame section.  The extra DW_CFA_nop
paddings is due to

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

bfd/

	* elf32-i386.c (elf_i386_create_dynamic_sections): Create the
	.plt.got section here.
	(elf_i386_check_relocs): Don't create the .plt.got section.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Create
	the .plt.got and .plt.bnd sections here.
	(elf_x86_64_check_relocs): Don't create the .plt.got nor
	.plt.bnd sections.

ld/

	* testsuite/ld-x86-64/pr21038a.d: Update DW_CFA_nop paddings
	in .eh_frame section.
	* testsuite/ld-x86-64/pr21038c.d: Update .eh_frame order.
2017-04-27 13:55:48 -07:00
H.J. Lu 97d343d400 x86: Add DT_PLTRELSZ/DT_PLTREL/DT_JMPREL for PLT relocation
x86, PLT relocation may contain R_386_TLS_DESC or R_X86_64_TLSDESC
even though there is no real PLT.  We need to add DT_PLTRELSZ, DT_PLTREL
and DT_JMPREL if there is a .rel.plt/.rela.plt section.

bfd/

	* elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add
	DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys
	add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section.

ld/

	* testsuite/ld-i386/tlsdesc2.d: New test.
	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
2017-04-26 15:34:00 -07:00
Maciej W. Rozycki 23ec1e32b1 PR ld/21334: Always call `_bfd_elf_link_renumber_dynsyms' if required
Complement commit e17b0c351f ("MIPS/BFD: Respect the ELF gABI dynamic
symbol table sort requirement") and correct an inconsistency in dynamic
symbol accounting data causing an assertion failure in the MIPS backend:

ld: BFD (GNU Binutils) 2.28.51.20170330 assertion fail
../../binutils-gdb/bfd/elfxx-mips.c:3860

in the course of making a GOT entry in a static binary to satisfy a GOT
relocation present in input, due to the local dynamic symbol count not
having been established.

To do so let backends request `_bfd_elf_link_renumber_dynsyms' to be
always called, rather than where a dynamic binary is linked only, and
then make this request in the MIPS backend.

	bfd/
	PR ld/21334
	* elf-bfd.h (elf_backend_data): Add `always_renumber_dynsyms'
	member.
	* elfxx-target.h [!elf_backend_always_renumber_dynsyms]
	(elf_backend_always_renumber_dynsyms): Define.
	(elfNN_bed): Initialize `always_renumber_dynsyms' member.
	* elfxx-mips.h (elf_backend_always_renumber_dynsyms): Define.
	* elflink.c (bfd_elf_size_dynamic_sections): Also call
	`_bfd_elf_link_renumber_dynsyms' if the backend has requested
	it.
	(bfd_elf_size_dynsym_hash_dynstr): Likewise.

	ld/
	PR ld/21334
	* testsuite/ld-mips-elf/pr21334.dd: New test.
	* testsuite/ld-mips-elf/pr21334.gd: New test.
	* testsuite/ld-mips-elf/pr21334.ld: New test linker script.
	* testsuite/ld-mips-elf/pr21334.s: New test source.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2017-04-26 13:17:07 +01:00
H.J. Lu 9e9821ddd8 x86-64: Force symbol dynamic if it isn't undefined weak
Force symbol dynamic if it isn't undefined weak.  Generate relative
relocation for GOT reference against non-dynamic symbol in PIC to
avoid unnecessary dynamic symbols.

bfd/

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
	no_finish_dynamic_symbol.
	(elf_x86_64_link_hash_newfunc): Set no_finish_dynamic_symbol to
	0.
	(elf_x86_64_allocate_dynrelocs): If a symbol isn't undefined
	weak symbol, don't make it dynamic.
	(elf_x86_64_relocate_section): If a symbol isn't dynamic in PIC,
	set no_finish_dynamic_symbol and generate R_X86_64_RELATIVE
	relocation for GOT reference.
	(elf_x86_64_finish_dynamic_symbol): Abort if
	no_finish_dynamic_symbol isn't 0.

ld/

	* testsuite/ld-x86-64/no-plt.exp: Also check no-plt-1e.nd.
	* testsuite/ld-x86-64/no-plt-1e.nd: New file.
2017-04-24 14:37:12 -07:00
H.J. Lu e662f84f5d i386: Skip pr12570 tests for nacl targets
commit f129e49f4d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jan 10 11:30:25 2017 -0800

    Don't use elf_i386_eh_frame_plt directly

fixed i386 PLT eh_frame generation.  Skip pr12570 tests since they are
for non-nacl targets.

	* testsuite/ld-i386/pr12570a.d: Skip for nacl targets.
	* testsuite/ld-i386/pr12570b.d: Likewise.
2017-04-24 09:46:04 -07:00
H.J. Lu 1587442d37 i386: Set ELF_MAXPAGESIZE to 0x1000 for VxWorks
commit a27e437177
Author: Roland McGrath <roland@gnu.org>
Date:   Thu Jul 28 22:35:15 2011 +0000

    BFD vector for elf32-i386-nacl:

changed ELF_MAXPAGESIZE to 0x10000 for VxWorks.  This patch fixes it
and updated testsuite/ld-i386/vxworks2.sd to add space for program
headers.

bfd/

	PR ld/21425
	* elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks.

ld/

	PR ld/20815
	* testsuite/ld-i386/vxworks2.sd: Add space for program headers.
2017-04-24 09:37:10 -07:00
Jose E. Marchesi 8b353c47b7 ld: fix regressions with rett instructions in sparc tests.
A few tests in the ld testsuite were expecting the disassembler to
emit `rett' instructions in V9.  This patch updates the tests to
expect `return' instead.

ld/ChangeLog:

2017-04-24  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* testsuite/ld-sparc/tlssunbin64.dd: Expect `return' instructions
	instead of `rett' in V9.
	* testsuite/ld-sparc/tlssunnopic64.dd: Likewise.
	* testsuite/ld-sparc/tlssunpic64.dd: Likewise.
2017-04-24 05:31:31 -07:00
H.J. Lu e133d00576 i386: Avoid dynamic symbol with GOT reference in PIE
GOT reference to global symbol in PIE will lead to dynamic symbol.  It
becomes a problem when "time" or "times" is defined as a variable in
an executable, clashing with functions of the same name in libc.  If
a symbol isn't undefined weak symbol, don't make it dynamic in PIE and
generate R_386_RELATIVE relocation.

bfd/

	PR ld/21402
	* elf32-i386.c (elf_i386_link_hash_entry): Add
	no_finish_dynamic_symbol.
	(elf_i386_link_hash_newfunc): Set no_finish_dynamic_symbol to 0.
	(elf_i386_allocate_dynrelocs): If a symbol isn't undefined weak
	symbol, don't make it dynamic in PIE.
	(elf_i386_relocate_section): If a symbol isn't dynamic in PIE,
	set no_finish_dynamic_symbol and generate R_386_RELATIVE
	relocation for R_386_GOT32
	(elf_i386_finish_dynamic_symbol): Abort if no_finish_dynamic_symbol
	isn't 0.

ld/

	PR ld/21402
	* testsuite/ld-elf/indirect.exp: Don't skip PIE indirect5 and
	indirect6 tests on i386.
2017-04-21 12:03:26 -07:00
H.J. Lu 3c5fce9bc2 Require --no-dynamic-linker with -static -E/--dynamic-list
When -static -E/--dynamic-list are passed to linker, linker may create
executable with dynamic sections which aren't supported by run-time.
We require --no-dynamic-linker together with -static -E/--dynamic-list
before adding dynamic symbol table to static executable.

bfd/

	PR ld/19617
	PR ld/21086
	* elflink.c (elf_link_add_object_symbols): Require
	--no-dynamic-linker with -E/--dynamic-list when creating
	dynamic sections.

ld/

	PR ld/19617
	PR ld/21086
	* testsuite/ld-elf/pr19617a.d: Pass --no-dynamic-linker to ld.
	* testsuite/ld-elf/pr19617b.d: Likewise.
	* testsuite/ld-elf/pr19617c.d: Likewise.
	*testsuite/ld-i386/pr19636-4d.d: Likewise.
	* testsuite/ld-elf/readelf.exp: Pass --no-dynamic-linker to ld
	with --export-dynamic.
	* testsuite/ld-elf/shared.exp: Pass --no-dynamic-linker to ld
	with -E.
2017-04-21 12:01:05 -07:00
H.J. Lu afe9edbf48 Skip PIE indirect5 and indirect6 tests on i386
On i386, since GOT reference is needed to access global symbols in PIE,
those symbols are made dynamic.  Crash happens when there is a reference
to the same global symbol with a different symbol type in a shared
object.  Since mixing different types of the same symbol doesn't work in
general, this patch skips those tests on i386 as well as compiles non-PIE
indirect5 and indirect6 tests with $NOPIE_LDFLAGS and $NOPIE_CFLAGS.

	PR ld/21402
	* testsuite/ld-elf/indirect.exp: Pass $NOPIE_LDFLAGS and
	$NOPIE_CFLAGS to non-PIE indirect5 and indirect6 tests.  Skip
	PIE indirect5 and indirect6 tests on i386.
2017-04-20 12:40:42 -07:00
Maciej W. Rozycki 31321c8031 MIPS/LD/testsuite: Join `__ehdr_start' tests
Complement commit 3807734dbe ("PR ld/15428: MIPS/LD/testsuite:
Un-KFAIL `__ehdr_start' test 2") and join tests that do not need to be
split anymore.

	ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Join `__ehdr_start' tests.
2017-04-20 16:23:08 +01:00
H.J. Lu 59fa66c538 Handle symbol defined in IR and referenced in DSO
We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

	PR ld/21382
	* elflink.c (elf_link_add_object_symbols): Preserve
	dynamic_ref_after_ir_def when restoring the symbol table for
	unneeded dynamic object.

include/

	PR ld/21382
	* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

	PR ld/21382
	* plugin.c (is_visible_from_outside): Symbol may be visible
	from outside if dynamic_ref_after_ir_def is set.
	(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
	defined in an IR object and referenced in a dynamic object.
	* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
	* testsuite/ld-plugin/pr21382a.c: New file.
	* testsuite/ld-plugin/pr21382b.c: Likewise.
2017-04-20 07:48:35 -07:00
H.J. Lu e492d2f8ac x86-64: Handle undefined IFUNC symbol with -z now
Since undefined IFUNC symbol is treated as normal FUNC symbol, don't
abort on undefined IFUNC symbol in the second PLT.

bfd/

	PR ld/21401
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Don't abort
	on on undefined IFUNC symbol in the second PLT.

ld/

	PR ld/21401
	* testsuite/ld-ifunc/ifunc.exp: Add a libtest-2-now.so test with
	-z now.
2017-04-19 09:59:30 -07:00
Alan Modra 954b63d4c8 Implement -z dynamic-undefined-weak
-z nodynamic-undefined-weak is only implemented for x86.  (The sparc
backend has some support code but doesn't enable the option by
including ld/emulparams/dynamic_undefined_weak.sh, and since the
support looks like it may be broken I haven't enabled it.)  This patch
adds the complementary -z dynamic-undefined-weak, extends both options
to affect building of shared libraries as well as executables, and
adds support for the option on powerpc.

include/
	* bfdlink.h (struct bfd_link_info <dynamic_undefined_weak>):
	Revise comment.
bfd/
	* elflink.c (_bfd_elf_adjust_dynamic_symbol): Hide undefweak
	or make dynamic for info->dynamic_undefined_weak 0 and 1.
	* elf32-ppc.c:Formatting.
	(ensure_undefweak_dynamic): Don't make dynamic when
	info->dynamic_undefined_weak is zero.
	(allocate_dynrelocs): Discard undefweak dyn_relocs for
	info->dynamic_undefined_weak.  Discard undef dyn_relocs when
	not default visibility.  Discard undef and undefweak
	dyn_relocs earlier.
	(ppc_elf_relocate_section): Adjust to suit.
	* elf64-ppc.c: Formatting.
	(ensure_undefweak_dynamic): Don't make dynamic when
	info->dynamic_undefined_weak is zero.
	(allocate_dynrelocs): Discard undefweak dyn_relocs for
	info->dynamic_undefined_weak.  Discard them earlier.
ld/
	* ld.texinfo (dynamic-undefined-weak): Document.
	(nodynamic-undefined-weak): Document that this option now can
	be used with shared libs.
	* emulparams/dynamic_undefined_weak.sh: Support -z
	dynamic-undefined-weak.
	* emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh.
	* testsuite/ld-undefined/weak-undef.exp (undef_weak_so),
	(undef_weak_exe): New.  Use them.  Add -z dynamic-undefined-weak
	and -z nodynamic-undefined-weak tests.
	* Makefile.am: Update powerpc dependencies.
	* Makefile.in: Regenerate.
2017-04-19 20:39:52 +09:30
H.J. Lu e6699019c4 Put soname in the version definition section
commit 902e9fc76a
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Tue Feb 21 01:46:42 2017 +0000

    PR ld/20828: Move symbol version processing ahead of GC symbol sweep

breaks version definition with --version-script --soname.  This patch
fixes it by getting soname index before generating the version definition
section.

bfd/

	PR ld/21389
	* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
	before generating the version definition section.

ld/

	PR ld/21389
	* testsuite/ld-elf/pr21389.map: New file.
	* testsuite/ld-elf/pr21389.s: Likewise.
	* testsuite/ld-elf/pr21389a.d: Likewise.
	* testsuite/ld-elf/pr21389b.d: Likewise.
	* testsuite/ld-elf/pr21389c.d: Likewise.
2017-04-17 07:47:32 -07:00
Alan Modra c5d37467b1 Undo dynamic symbol state after regular object sym type mismatch
We already handle the case of an object file first defining a symbol
that a later shared library also defines where the symbol types are
incompatible.  This patch handles the reverse, when a later object
file defines an incompatible symbol defined by an earlier shared
library.

bfd/
	* elflink.c (_bfd_elf_merge_symbol): Undo dynamic linking
	state when a regular object file defines a symbol with
	incompatible type to that defined by an earlier shared lib.
ld/
	* testsuite/ld-elf/indirect5a.c,
	* testsuite/ld-elf/indirect5b.c,
	* testsuite/ld-elf/indirect5.map,
	* testsuite/ld-elf/indirect5.out: New test.
	* testsuite/ld-elf/indirect6a.c: Likewise.
	* testsuite/ld-elf/indirect.exp (check_dynamic_syms): New proc.
	Run new tests and check dynsyms.
2017-04-17 23:14:37 +09:30
Alan Modra fbea15088d PR 21274, ld segfaults linking PE DLL
Don't use fixed size buffers for symbol names.

	PR 21274
	PR 18466
	* emultempl/pe.em (pe_find_data_imports): Don't use fixed size
	symbol buffer.  Instead, xmalloc max size needed with space for
	prefix.  Wrap overlong lines.  Formatting.  Pass symbol buffer
	copy of name to pe_walk_relocs_of_symbol.
	(make_inport_fixup): Add "name" param, pass to pe_create_import_fixup.
	* emultempl/pe.em (pep_find_data_imports): As for pe_find_data_imports.
	(make_import_fixup): Add "name" param, pass to pep_create_import_fixup.
	Use bfd_get_signed_* and remove unnecessary casts.  Formatting.
	* pe-dll.c (pe_walk_relocs_of_symbol): Add "name" param.  Pass to
	callback.
	(make_import_fixup_mark): Add "name" param.  Make use of prefix
	space rather than xmalloc here.
	(pe_create_import_fixup): Likewise.
	* pe-dll.h (pe_walk_relocs_of_symbol): Update prototype.
	(pe_create_import_fixup): Likewise.
	* pep-dll.h (pep_walk_relocs_of_symbol): Likewise.
	(pep_create_import_fixup): Likewise.
2017-04-11 19:49:13 +09:30
Nick Clifton a70f34c01c Document undocumented linker command line options.
ld 	* ld.texinfo (--strip-discarded): Document.
	(--embedded-relocs): Document.
	(--spare-dynamic-tags): Document.
	(--task-link): Document.
2017-04-10 15:59:59 +01:00
Alan Modra 6f9dbcd42f PR21287, Inconsistent section type for .init_array and .init_array.42
PR21287 notes that .init_array is correctly given a type of
SHT_INIT_ARRAY while .init_array.nnn gets SHT_PROGBITS.  This patch
fixes that problem, and properly drops warnings from the compiler that
would cause the testsuite to fail.  My a44d0bd78 change to check
ld_compile status, necessary to pick up compile errors, also meant
warnings were not ignored.

bfd/
	PR 21287
	* elf.c (special_sections_f): Match .fini_array and .fini_array.*.
	(special_sections_i): Likewise for .init_array.
	(special_sections_p): Likewise for .preinit_array.
ld/
	PR 21287
	* testsuite/ld-elf/init-fini-arrays.d: Match INIT_ARRAY and FINI_ARRAY.
	* testsuite/ld-elf/init-fini-arrays.s: Use %init_array and %fini_array
	section types.
	* testsuite/lib/ld-lib.exp (default_ld_compile): Trim assembler
	warnings about "ignoring incorrect section type".
	(run_ld_link_exec_tests, run_cc_link_tests): Delete old comment.
2017-04-10 15:11:35 +09:30
Alan Modra 37095d07b4 Clean elfvsb files left over from previous runs
My mips-linux and mips64-linux testsuite runs have been failing a
bunch of visibility tests, seemingly randomly.  It turns out the
problem occurs when object files are left over in ld/tmpdir from a
previous run.

	* testsuite/ld-elfvsb/elfvsb.exp (visibility_run): Delete
	sh1p.o, sh2p.o, sh1np.o and sh2np.o before compiling.  Use
	remote_file host exists rather than file exists.
2017-04-10 15:10:58 +09:30
H.J. Lu a7eaf017f9 Use NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE
Since not all compilers support -no-pie, NOPIE_CFLAGS and NOPIE_LDFLAGS
should be used to disable PIE.

	PR ld/21090
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Use
	NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE for the non-pie
	version of the test.
2017-04-07 08:53:43 -07:00
H.J. Lu 8170f7693b ELF: Check ELF_COMMON_DEF_P for common symbols
Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.

bfd/

	PR ld/19579
	PR ld/21306
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elflink.c (_bfd_elf_merge_symbol): Revert commits
	202ac193bb and
	07492f668d.

ld/

	PR ld/19579
	PR ld/21306
	* testsuite/ld-elf/pr19579a.c (main): Updated.
2017-04-07 07:40:14 -07:00
Nick Clifton ae3f8c2813 Fix failure in x86_64 linker tests when compiling with a PIE enabled compiler.
PR 21090
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Explicitly
	disable PIE for the non-pie version of the test.
2017-04-07 11:48:08 +01:00
Alan Modra 5c1f54ce0b Tweak MBIND ld test for ARM.
* testsuite/ld-elf/mbind2a.s: Don't use @, the ARM comment char.
2017-04-07 18:24:38 +09:30
Tristan Gingold 1fd6d11190 pe/coff: handle weak defined symbol for gc-sections.
bfd/
	* coffgen.c (_bfd_coff_gc_mark_hook): Handle PE weak
	external symbols with a definition.
	(_bfd_coff_gc_mark_extra_sections): Fix typo.

ld/
	* testsuite/ld-pe/pe.exp: New test.
	* testsuite/ld-pe/weakdef-1.s: New test source.
	* testsuite/ld-pe/weakdef-1.d: New test.
2017-04-07 10:03:17 +02:00
Alan Modra 3944e22b46 mbind tests: don't check PT_LOAD headers
On powerpc-linux, the second PT_LOAD header is RWE.  On hppa64-linux,
only one PT_LOAD header is present.  Since the tests are really about
the new GNU_MBIND headers, ignore PT_LOAD and its section mapping.

	* testsuite/ld-elf/mbind1a.d: Remove matches for PT_LOAD segments.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
2017-04-07 00:18:33 +09:30
Hans-Peter Nilsson 6ca30fa561 PR ld/21233: change xfails to kfails, fix the indentation issue 2017-04-05 23:12:16 +02:00
Hans-Peter Nilsson 4d5efb852b PR ld/21233: xfail failing test-parts for cris*-*-* 2017-04-05 03:00:40 +02:00
Maciej W. Rozycki 80070c0d34 PR ld/21233: Avoid sweeping forced-undefined symbols in section GC
Complement commit 902e9fc76a ("PR ld/20828: Move symbol version
processing ahead of GC symbol sweep"), commit b531344c34 ("PR
ld/20828: Reorder the symbol sweep stage of section GC") and commit
81ff47b3a5 ("PR ld/20828: Fix linker script symbols wrongly forced
local with section GC"), and prevent symbols forcibly entered in the
output file with the use of the `--undefined=' or `--require-defined='
linker command line options or the EXTERN linker script command from
being swept in section garbage collection and consequently recorded in
the dynamic symbol table as local entries.  This happens in certain
circumstances, where a symbol reference also exists in one of the static
input files, however only in a section which is garbage-collected and
does not make it to the output file, and the symbol is defined in a
dynamic object present in the link.

For example with the `i386-linux' target and the `pr21233.s' and
`pr21233-l.s' sources, and the `pr21233.ld' linker script included with
this change we get:

$ as -o pr21233-l.o pr21233-l.s
$ ld -shared -T pr21233.ld -o libpr21233.so pr21233-l.o
$ as -o pr21233.o pr21233.s
$ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so
$ readelf --dyn-syms pr21233

Symbol table '.dynsym' contains 2 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 OBJECT  LOCAL  DEFAULT  UND bar
$

which makes the run-time `bar' dependency of the `pr21233' executable
different from its corresponding link-time dependency, i.e. the presence
of `libpr21233.so' and its `bar' symbol is required at the link time,
however at the run time a copy of `libpr21233.so' without `bar' will do.
Similarly with `--undefined=' and EXTERN which do not actually require
the reference to the symbol requested to be satisfied with a definition
at the link time, however once the definition has been pulled at the
link time, so it should at the dynamic load time.

Additionally with the `mips-linux' target we get:

$ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so
ld: BFD (GNU Binutils) 2.28.51.20170324 assertion fail .../bfd/elfxx-mips.c:3861
$

as the target is not prepared to handle such a local dynamic symbol.

With this change in effect we get:

$ readelf --dyn-syms pr21233

Symbol table '.dynsym' contains 2 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 OBJECT  GLOBAL DEFAULT  UND bar
$

instead, for both targets.

	ld/
	PR ld/21233
	* ldlang.c (insert_undefined): Set `mark' for ELF symbols.
	* testsuite/ld-elf/pr21233.sd: New test.
	* testsuite/ld-elf/pr21233-l.sd: New test.
	* testsuite/ld-elf/pr21233.ld: New test linker script.
	* testsuite/ld-elf/pr21233-e.ld: New test linker script.
	* testsuite/ld-elf/pr21233.s: New test source.
	* testsuite/ld-elf/pr21233-l.s: New test source.
	* testsuite/ld-elf/shared.exp: Run the new tests.
2017-04-04 23:21:44 +01:00
H.J. Lu a91e1603af Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
Mark an ALLOC section, which should be placed in special memory area,
with SHF_GNU_MBIND.  Its sh_info field indicates the special memory
type.  GNU_MBIND section names start with ".mbind" so that they are
placed as orphan sections by linker.  All input GNU_MBIND sections
with the same sh_type, sh_flags and sh_info are placed in one output
GNU_MBIND section.  In executable and shared object, create a
GNU_MBIND segment for each GNU_MBIND section and its segment type is
PT_GNU_MBIND_LO plus the sh_info value.  Each GNU_MBIND segment is
aligned at page boundary.

The assembler syntax:

    .section .mbind.foo,"adx",%progbits
                          ^             0: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.foo,"adx",%progbits,0x1
                          ^             1: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

    .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2
                          ^                               2: Special memory type.
                          |
                         'd' for SHF_GNU_MBIND.

bfd/

	* elf.c (get_program_header_size): Add a GNU_MBIND segment for
	each GNU_MBIND section and align GNU_MBIND section to page size.
	(_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
	segment for each GNU_MBIND section.
	(_bfd_elf_init_private_section_data): Copy sh_info from input
	for GNU_MBIND section.

binutils/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
	(get_elf_section_flags): Handle SHF_GNU_MBIND.
	(process_section_headers): Likewise.
	* testsuite/binutils-all/mbind1.s: New file.
	* testsuite/binutils-all/objcopy.exp: Run readelf test on
	mbind1.s.

gas/

	* NEWS: Mention support for ELF SHF_GNU_MBIND.
	* config/obj-elf.c (section_match): New.
	(get_section): Match both sh_info and group name.
	(obj_elf_change_section): Add argument for sh_info.  Pass both
	sh_info and group name to get_section. Issue an error for
	SHF_GNU_MBIND section without SHF_ALLOC.  Set sh_info.
	(obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
	(obj_elf_section): Support SHF_GNU_MBIND section info.
	* config/obj-elf.h (obj_elf_change_section): Add argument for
	sh_info.
	* config/tc-arm.c (start_unwind_section): Pass 0 as sh_info 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.texinfo: Document 'd' for SHF_GNU_MBIND.
	* testsuite/gas/elf/elf.exp: Run section12a, section12b and
	section13.
	* testsuite/gas/elf/section10.d: Updated.
	* testsuite/gas/elf/section10.s: Likewise.
	* testsuite/gas/elf/section12.s: New file.
	* testsuite/gas/elf/section12a.d: Likewise.
	* testsuite/gas/elf/section12b.d: Likewise.
	* testsuite/gas/elf/section13.l: Likewise.
	* testsuite/gas/elf/section13.d: Likewise.
	* testsuite/gas/elf/section13.s: Likewise.

include/

	* elf/common.h (PT_GNU_MBIND_NUM): New.
	(PT_GNU_MBIND_LO): Likewise.
	(PT_GNU_MBIND_HI): Likewise.
	(SHF_GNU_MBIND): Likewise.

ld/

	* NEWS: Mention support for ELF SHF_GNU_MBIND and
	PT_GNU_MBIND_XXX.
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
	input GNU_MBIND sections with the same type, attributes and
	sh_info field into a single output GNU_MBIND section.
	* testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
	* testsuite/ld-elf/mbind1.s: New file.
	* testsuite/ld-elf/mbind1a.d: Likewise.
	* testsuite/ld-elf/mbind1b.d: Likewise.
	* testsuite/ld-elf/mbind1c.d: Likewise.
	* testsuite/ld-elf/mbind2a.s: Likewise.
	* testsuite/ld-elf/mbind2b.c: Likewise.
2017-04-04 09:06:04 -07:00
Andrew Jenner 2f5f29cada IA16 support
* config.sub: Handle ia16 in $basic_machine.

       bfd/
       * config.bfd: Handle ia16.

       gas/
       * configure.tgt: Handle ia16.

       ld/
       * configure.tgt: Handle ia16.
2017-04-03 09:13:19 -07:00
H.J. Lu 2514e33e01 Correct the ChangeLog entry 2017-04-03 08:25:36 -07:00
H.J. Lu 46bed6796d ld: Support ELF GNU program properties
From .note.gnu.property section in each ELF input, we build a list of
GNU properties if .note.gnu.property section isn't corrupt.  The unknown
properties are ignored.  All property lists in relocatable inputs are
merged into an output property list.  When -z stack-size=N is used and
N isn't 0, the GNU_PROPERTY_STACK_SIZE property will be merged with or
added to the output property list.  .note.gnu.property section is
generated in output from the output property list.

bfd/

	* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
	(BFD32_BACKENDS_CFILES): Add elf-properties.c.
	* configure.ac (elf): Add elf-properties.lo.
	* Makefile.in: Regenerated.
	* configure: Likewise.
	* elf-bfd.h (elf_property_kind): New.
	(elf_property): Likewise.
	(elf_property_list): Likewise.
	(elf_properties): Likewise.
	(_bfd_elf_parse_gnu_properties): Likewise.
	(_bfd_elf_get_property): Likewise.
	(_bfd_elf_link_setup_gnu_properties): Likewise.
	(elf_backend_data): Add parse_gnu_properties, merge_gnu_properties
	and setup_gnu_properties.
	(elf_obj_tdata): Add properties.
	* elf-properties.c: New file.
	* elf32-i386.c (elf_i386_parse_gnu_properties): New.
	(elf_i386_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
	(elf_x86_64_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_merge_gnu_properties): Likewise.
	* elfxx-target.h (elf_backend_merge_gnu_properties): Likewise.
	(elf_backend_parse_gnu_properties): Likewise.
	(elf_backend_setup_gnu_properties): Likewise.
	(elfNN_bed): Add elf_backend_parse_gnu_properties,
	elf_backend_merge_gnu_properties and
	elf_backend_setup_gnu_properties.

ld/

	* ld/NEWS: Mention support for ELF GNU program properties.
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Call
	ELF setup_gnu_properties.
	* testsuite/ld-i386/i386.exp: Run property tests for Linux/i386.
	* testsuite/ld-i386/pass.c: New file.
	* testsuite/ld-i386/property-1.r: Likewise.
	* testsuite/ld-i386/property-2.r: Likewise.
	* testsuite/ld-i386/property-3.r: Likewise.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-6.r: Likewise.
	* testsuite/ld-i386/property-6a.c: Likewise.
	* testsuite/ld-i386/property-6b.c: Likewise.
	* testsuite/ld-i386/property-6c.S: Likewise.
	* testsuite/ld-i386/property-7.r: Likewise.
	* testsuite/ld-i386/property-no-copy.S: Likewise.
	* testsuite/ld-i386/property-stack.S: Likewise.
	* testsuite/ld-i386/property-unsorted-1.S: Likewise.
	* testsuite/ld-i386/property-unsorted-2.S: Likewise.
	* testsuite/ld-i386/property-x86-1.S: Likewise.
	* testsuite/ld-i386/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/pass.c: Likewise.
	* testsuite/ld-x86-64/property-1.r: Likewise.
	* testsuite/ld-x86-64/property-2.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-6.r: Likewise.
	* testsuite/ld-x86-64/property-6a.c: Likewise.
	* testsuite/ld-x86-64/property-6b.c: Likewise.
	* testsuite/ld-x86-64/property-6c.S: Likewise.
	* testsuite/ld-x86-64/property-7.r: Likewise.
	* testsuite/ld-x86-64/property-no-copy.S: Likewise.
	* testsuite/ld-x86-64/property-stack.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-1.S: Likewise.
	* testsuite/ld-x86-64/property-unsorted-2.S: Likewise.
	* testsuite/ld-x86-64/property-x86-1.S: Likewise.
	* testsuite/ld-x86-64/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run property tests for
	Linux/x86-64.
2017-04-03 08:08:27 -07:00
Hans-Peter Nilsson 086554e8e6 Fix for PR ld/16044: elf32-cris.c h->plt.refcount inconsistency 2017-03-28 23:43:09 +02:00
Maciej W. Rozycki c72cea5aec readelf: Fix incorrect "Version definition past end of section" message (ChangeLog)
Correct ChangeLog entry for commit c9f02c3e29 ("readelf: Fix incorrect
"Version definition past end of section" message").
2017-03-24 12:25:49 +00:00
Sandra Loosemore 4c8798c992 Disable shared library tests for nios2-*-elf.
The Nios II processor documentation defines relocations for PIC and
shared libraries as part of the GNU/Linux ABI only; GCC rejects -fpic
on bare-metal.

2017-03-21  Sandra Loosemore  <sandra@codesourcery.com>

	ld/
	* testsuite/lib/ld-lib.exp (check_shared_lib_support): Return
	false for nios2-*-elf.
2017-03-21 13:25:09 -07:00
Tristan Gingold 2170171889 ld: check overflow only for allocated sections.
* ldlang.c (lang_check_section_addresses): Check only for
	allocated sections.
2017-03-21 12:00:30 +01:00
Alan Modra 1d3fa25f58 ld sec64k test fix
* testsuite/ld-elf/sec64k.exp: Don't run on h8300 and ip2k.
2017-03-17 19:08:55 +10:30
Tristan Gingold 9494d96366 ld-checks: tweak overflow checks.
* testsuite/ld-checks/checks.exp (overflow_check): Disable for
	non-elf targets.
2017-03-15 10:23:19 +01:00
H.J. Lu 9216a6f335 Use addr_mask to check VMA and LMA
Since BFD64 may be used on 32-bit address, we need to apply addr_mask
to check VMA and LMA.

	* ldlang.c (lang_check_section_addresses): Use addr_mask to
	check VMA and LMA.
2017-03-14 09:09:54 -07:00
Nick Clifton f955cccff3 Rename R_AARCH64_TLSDESC_LD64_LO12_NC to R_AARCH64_TLSDESC_LD64_LO12 and R_AARCH64_TLSDESC_ADD_LO12_NC to R_AARCH64_TLSDESC_ADD_LO12.
PR binutils/21202
include	* elf/aarch64.h (R_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	R_AARCH64_TLSDESC_LD64_LO12.
	(R_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	R_AARCH64_TLSDESC_ADD_LO12_NC.

bfd	* reloc.c (BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.
	(BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC): Rename to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* elfnn-aarch64.c (IS_AARCH64_TLS_RELAX_RELOC): Update reloc
	names.
	(IS_AARCH64_TLSDESC_RELOC): Likewise.
	(elfNN_aarch64_howto_table): Likewise.
	(aarch64_tls_transition_without_check): Likewise.
	(aarch64_reloc_got_type): Likewise.
	(elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_tls_relax): Likewise.
	(elfNN_aarch64_relocate_section): Likewise.
	(elfNN_aarch64_gc_sweep_hook): Likewise.
	(elfNN_aarch64_check_relocs): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.
	(_bfd_aarch64_elf_resolve_relocation): Likewise.

gas	* config/tc-aarch64.c (reloc_table): Rename
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_LD64_LO12.  Rname
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC to
	BFD_RELOC_AARCH64_TLSDESC_ADD_LO12.
	(md_apply_fix): Likewise.
	(aarch64_force_relocation): Likewise.
	* testsuite/gas/aarch64/tls.d: Update regexp.

ld	* testsuite/ld-aarch64/ifunc-5r-local.d: Update regexp.
2017-03-13 09:58:04 +00:00
Tristan Gingold d40e34db39 ld: add an error in case of address space overflow.
ld/
	* ldlang.c (lang_check_section_addresses): Check for address space
	overflow.
	* testsuite/ld-checks/checks.exp (overflow_check): New procedure
	* testsuite/ld-checks/over.s: New test source.
	* testsuite/ld-checks/over.d: New test.
	* testsuite/ld-checks/over2.s: New test source.
	* testsuite/ld-checks/over2.d: New test.
2017-03-13 10:41:22 +01:00
Alexey Neyman 4b5900d8b8 PowerPC: incorrect library search order
First, need to match against just the CPU name, not the whole triplet.
Otherwise, the test picks up "*le-*" pattern from x86_64-apple-darwin
triplet.

Second, it should be testing for $target, not $host. Host may be
little endian by default, and the sysroot directory layout shouldn't
depend on whether it is built on LE or BE machine.

	* emulparams/elf32ppccommon.sh (LIBPATH_SUFFIX): Set from target
	cpu, not host.
2017-03-13 17:51:38 +10:30
Alan Modra 118aa6cf39 Add sysroot for ld -rpath search
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Add
	sysroot for -rpath search.
2017-03-11 23:40:21 +10:30
Alan Modra 316a1245fe Rewrite add_sysroot
Relative paths shouldn't have the sysroot prefix added.  The patch
also makes some attempt at supporting DOS paths, and tidies code using
the new add_sysroot.

	* emultempl/elf32.em (gld${EMULATION_NAME}_add_sysroot): Rewrite.
	Only prefix absolute paths with sysroot.  Handle DOS paths.
	(gld${EMULATION_NAME}_check_ld_elf_hints): Constify variable.
	(gld${EMULATION_NAME}_check_ld_so_conf): Likewise.
	(gld${EMULATION_NAME}_after_open): Short-circuit NULL path
	searches.  Rename variable.  Simplify get_runpath search.
2017-03-11 23:40:20 +10:30
Alan Modra bb4287c562 Don't use -rdynamic in ld test
This gcc option isn't well supported, so use the actual linker option
we want to test.

	* testsuite/ld-elf/shared.exp: Use -Wl,-export-dynamic rather
	than -rdynamic.
2017-03-11 11:04:02 +10:30
Alan Modra e299b3551e Don't run new orphan tests on i860 and i960
These targets use the generic ELF support, so don't handle orphans
well.  The patch also updates the orphan doco to reflect this fact,
and deletes some ELF details that don't really add anything.

	* ld.texinfo (Orphan Sections): Mention that not all targets
	handle orphans well.  Delete ELF details.
	* testsuite/ld-elf/orphan-9.d: Don't run for i860 and i960.
	* testsuite/ld-elf/orphan-10.d: Likewise.
2017-03-11 10:51:56 +10:30
Andrew Burgess 14ea2c1b23 ld: Track changes to default region LMA even for empty sections
Given a linker script fragment like this:

   SECTIONS {
     . = 0x1000;
     .text   : AT(0x100) { *(.text)   }
     .data   : AT(0x200) { *(.data)   }
     .rodata : AT(0x300) { *(.rodata) }
   }

and an input file containing sections, '.text', '.data.1', and
'.rodata', then we'd expect the linker to place '.text' and '.rodata' in
the obvious way, and the '.data.1' orphan section would be located after
the '.data' section (assuming similar section properties).

Further, I believe that the expectation would be that the LMA for the
orphan '.data.1' section would start from 0x200 (as there is no '.data'
content).

However, right now, the LMA for '.data.1' would be 0x101, following on
from the '.text' section, this is because the change in LMA for the
'.data' section is not noticed by the linker, if there's no content in
the '.data' section.

What can be even more confusing to a user (though the cause is obvious
once you understand what's going on) is that adding some content to
'.data' will cause the orphan '.data.1' to switch to an LMA based off of
0x200.

This commit changes the behaviour so that an empty section that is in
the default lma region, and sets its lma, will adjust the lma of the
default region, this change will then be reflected in following sections
within the default lma memory region.

There's a new test to cover this issue that passes on a range of
targets, however, some targets generate additional sections, or have
stricter memory region size requirements that make it harder to come
up with a generic pass pattern, that still tests the required
features.  For now I've set the test to ignore these targets.

ld/ChangeLog:

	* ldlang.c (lang_size_sections_1): Shortcut loop only after
	tracking changes to the default regions LMA.
	* testsuite/ld-elf/orphan-9.ld: Extend header comment.
	* testsuite/ld-elf/orphan-10.d: New file.
	* testsuite/ld-elf/orphan-10.s: New file.
	* NEWS: Mention change in behaviour.
2017-03-09 21:11:06 +00:00
Andrew Burgess 77f5e65ecf ld: better handling of lma region for orphan sections
When picking an lma_region for an orphan section we currently create a
new lang_output_section_statement_type and then populate this with the
orphan section.

The problem is that the lang_output_section_statement_type has a prev
pointer that links back to the previous output section.  For non-orphan
output sections, that are created in linker script order, the prev
pointer will point to the output section that appears previous in linker
script order, as you'd probably expect.

The problem is that orphan sections are placed after processing the
linker script, and so, in the case of an output section created for an
orphan input section, the prev pointer actually points to the last
output section created.

This causes some unexpected behaviour when the orphan section is not
placed after the last non-orphan section that was created.

For example, consider this linker script:

  MEMORY {
    TEXT   : ORIGIN = 0x200,  LENGTH = 0x10
    RODATA : ORIGIN = 0x400,  LENGTH = 0x10
  }

  SECTIONS {
    .text   :           {*(.text)    } AT>TEXT
    .data   : AT(0x300) { *(.data)   }
    .rodata :           { *(.rodata) } AT>RODATA
  }

If we are processing an orphan section '.data.1' and decide to place
this after '.data', then the output section created will have a prev
pointer that references the '.rodata' output section.  The result of
this is that '.data.1' will actually be assigned to the RODATA lma
region, which is probably not the expected behaviour.

The reason why '.data.1' is placed into the lma region of the '.rodata'
section is that lma region propagation is done at the time we create the
output section, based on the previous output section pointer, which is
really just a last-output-section-created pointer at that point in time,
though the prev point is fixed up later to reflect the true order of the
output sections.

The solution I propose in this commit is to move the propagation of lma
regions into a separate pass of the linker, rather than performing this
as part of the enter/exit of output sections during linker script
parsing.

During this later phase we have all of the output sections to hand, and
the prev/next points have been fixed up by this point to reflect the
actual placement ordering.

There's a new test to cover this issue that passes on a range of
targets, however, some targets generate additional sections, or have
stricter memory region size requirements that make it harder to come
up with a generic pass pattern, that still tests the required
features.  For now I've set the test to ignore these targets.

ld/ChangeLog:

	* ldlang.c (lang_leave_output_section_statement): Move lma_region
	logic to...
	(lang_propagate_lma_regions): ...this new function.
	(lang_process): Call new function.
	* testsuite/ld-elf/orphan-9.d: New file.
	* testsuite/ld-elf/orphan-9.ld: New file.
	* testsuite/ld-elf/orphan-9.s: New file.
	* NEWS: Mention change in behaviour.
2017-03-09 21:11:05 +00:00
Andrew Burgess a87ded7b88 ld: Orphan section documentation
Make more explicit mention of the fact that orphan sections can cause a
new output section to be created.  Though this information is clearly
implied in the manual it might not be clear enough.

A user _might_ (incorrectly) think that orphan sections can only be
inserted into an existing output section.

ld/ChangeLog:

	* ld.texinfo (Orphan Sections): Add more detail.
2017-03-09 21:10:58 +00:00