Commit Graph

5762 Commits

Author SHA1 Message Date
Andrew Burgess 8be965c5f0 ld: Find and run some tests using a wildcard pattern
Find the ld-script/provide-*.d tests using a wildcard, then run them in
a loop.  This will make it easier to add more tests in the future.  Some
associated clean up is required.

ld/ChangeLog:

	* testsuite/ld-scripts/provide-3.d: Add xfail directive.
	* testsuite/ld-scripts/provide-4.d: Use new map file name.
	* testsuite/ld-scripts/provide-5.d: Use new map file name.
	* testsuite/ld-scripts/provide-4-map.d: Renamed to...
	* testsuite/ld-scripts/provide-4.map: ...this.
	* testsuite/ld-scripts/provide-5-map.d: Renamed to...
	* testsuite/ld-scripts/provide-5.map: ...this.
	* testsuite/ld-scripts/provide.exp: Move xfail into provide-3.d
	file, and run tests in a loop.
2018-01-11 17:35:34 +00:00
Andrew Burgess b3b9f8d3e9 ld: In map file use '=' in PROVIDE statements
Currently when recording a PROVIDE statement in a linker map file we
display something like:

    PROVIDE (SYMBOL, VALUE)

However, in a linker script we write these statements like this:

    PROVIDE (SYMBOL = VALUE);

This commit changes the output in the map file to be closer to linker
script format, the map file now contains:

    PROVIDE (SYMBOL = VALUE)

The ';' is still missing from the end, but map files are not intended
to be valid linker script input, so adding the ';' just seems like
clutter.

ld/ChangeLog:

	* ldexp.c (exp_print_tree): Use '=' instead of ',' when printing
	PROVIDE statements.
	* testsuite/ld-scripts/provide-4.map: Update expected output.
	* testsuite/ld-scripts/provide-5.map: Likewise.
2018-01-11 17:33:20 +00:00
H.J. Lu 6bd0a312a4 Fix the order of SHLIB_RODATA_ADDR in elf.sc
elf.sc has

  if test -n "${RODATA_ADDR}"; then
    RODATA_ADDR="\
SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR}) + SIZEOF_HEADERS"
  else
    RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
    ^^^^^^^^^^ Set RODATA_ADDR
    RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR})"
    ^^^^^^^^^^ Set RODATA_ADDR with ${RODATA_ADDR}
  fi
  if test -n "${SHLIB_RODATA_ADDR}"; then
    SHLIB_RODATA_ADDR="\
SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS"
  else
    SHLIB_RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR})"
    ^^^^^^^^^^ Set SHLIB_RODATA_ADDR
    SHLIB_RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
    ^^^^^^^^^^ Override SHLIB_RODATA_ADDR
  fi

The order should be:

  if test -n "${SHLIB_RODATA_ADDR}"; then
    SHLIB_RODATA_ADDR="\
SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS"
  else
    SHLIB_RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
    SHLIB_RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR})"
  fi

	PR ld/22696
	* scripttempl/elf.sc: Fix the order of SHLIB_RODATA_ADDR.
2018-01-11 05:05:25 -08:00
Jim Wilson 74ccf6db11 Add explicit shared check to eh-frame-hdr test.
ld/
	* testsuite/ld-elf/eh-frame-hdr.d (#xfail): Delete
	(#alltargets): Renamed from #target.  Add shared.
	* testsuite/lib/ld-lib.exp (run_dump_test): Document shared target.
	Document alltargets option.  Add support for alltargets option.
	(istarget): Add support for shared target.
2018-01-09 10:08:47 -08:00
Jim Wilson 7615ca1dc9 RISC-V: Fix accidental embedded -shared regressions.
ld/
	* testsuite/ld-riscv-elf/c-lui.d: Don't use -shared.  Check for _start
	instead of .text.
	* testsuite/ld-riscv-elf/c-lui.s: Add _start label.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Before __global_pointer$
	tests, add call to check_shared_lib_support.
2018-01-08 17:55:29 -08:00
Jim Wilson 35eeb78fa9 RISC-V: Print symbol address for jalr w/ zero offset.
ld/
	* testsuite/ld-riscv-elf/disas-jalr.d: New.
	* testsuite/ld-riscv-elf/disas-jalr.s: New.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run new testcase.

	opcodes/
	* riscv-dis.c (print_insn_args) <'s'>: Call maybe_print_address for a
	jalr.
2018-01-05 17:51:23 -08:00
Jim Wilson be1dce2625 RISC-V: Disable shared library support for embedded elf.
ld/
	* emulparams/elf32lriscv-defs.sh (GENERATE_SHLIB_SCRIPT): Move inside
	case on $target, and don't set for riscv*-elf targets.
	(GENERATE_PIE_SCRIPT): Likewise.
2018-01-05 14:29:49 -08:00
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Alan Modra 1e56386871 ChangeLog rotation 2018-01-03 17:49:42 +10:30
Nick Clifton 863f7a5f48 Update the address of the FSF in the copyright notice of files which were using the old address.
top	* COPYING.LIBGLOSS: Update address of FSF in copyright notice.

bfd	* cpu-mt.c: Update address of FSF in copyright notice.
	* elf32-m32c.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-rx.h: Likewise.
	* elf32-spu.h: Likewise.
	* hosts/x86-64linux.h: Likewise.

etc	* add-log.el: Update address of FSF in copyright notice.

gas	* config/tc-m32c.c: Update address of FSF in copyright notice.
	* config/tc-m32c.h: Likewise.
	* config/tc-mt.c: Likewise.
	* config/tc-mt.h: Likewise.
	* config/tc-visium.c: Likewise.
	* config/tc-visium.h: Likewise.
	* testsuite/gas/rx/explode: Likewise.

ld	* testsuite/ld-mn10300/mn10300.exp: Update address of FSF in
	copyright notice.
2017-12-14 12:48:55 +00:00
Renlin Li 79e7419204 [BFD][AARCH64]Disallow R_AARCH64_ABS32(LP64) & R_AARCH64_ABS16 in const section of shared object.
R_AARCH64_ABS64, R_AARCH64_ABS32 and R_AARCH64_ABS16 are data relocations
supported in AArch64 elf ABI.

R_AARCH64_ABS64 under LP64 is allowed in shared object and a dynamic relocation entry
will be generated. This allows the dynamic linker to do further symbol resolution.
R_AARCH64_ABS32 likewise is allowed in shared object, however under ILP32 abi.

The original behavior for R_AARCH64_ABS32 under LP64 is that, it's allowed
in shared object and silently resolved at static linking time.
No dynamic relocation entry is generate for it.

R_AARCH64_ABS16 is allowed in shared object under both L64 and ILP32.
It's resolved at static linking time as well.

Under LP64, the address should be 64-bit. R_AARCH64_ABS32 relocation indicates
an address that is only sized 32 bits which is meaningless in LP64 shared object.
It's useful to error out.

I have checked glibc dynamic linker code, R_AARCH64_ABS16 is not supported at all. So
R_AARCH64_ABS16 should be reject in shared object completely.

In this patch, R_AARCH64_ABS32 is rejected under LP64 in constant section of shared object.
R_AARCH64_ABS16 is rejected in constant section of shared object in both ABI.

This will sometimes provide useful information for buggy code.
2017-12-13 15:15:50 +00:00
Alan Modra 7d6de425da Objcopy interleave test
PR 22465
	* testsuite/ld-elf/interleave.s: Use .data sections and provide
	section attrs.
	* testsuite/ld-elf/interleave.ld: Discard other sections.  Adjust
	for changed section names.
2017-12-07 23:04:15 +10:30
Alan Modra 931c97c81a mcore-elf lacks shared lib support
elf32-mcore.c has no backend create_dynamic_sections function so can't
support shared libs.

	* emulparams/elf32mcore.sh (GENERATE_SHLIB_SCRIPT): Don't define.
2017-12-07 21:07:19 +10:30
Alan Modra 05a5feafdd Rewrite check_shared_lib_support
* testsuite/lib/ld-lib.exp (check_shared_lib_support): Ask ld
	under test whether -shared is supported.
2017-12-07 17:52:49 +10:30
Jim Wilson 1c9c7ce078 Objcopy interleave fails if section address not multiple of interleave.
PR 22465
	binutils/
	* objcopy.c (copy_section): New local extra.  If isection->lma not
	exactly divisible by interleave, then bias from.  Also adjust
	osection->lma if necessary.

	ld/
	* testsuite/ld-elf/interleave-0.d, testsuite/ld-elf/interleave-4.d,
	* testsuite/ld-elf/interleave.ld, testsuite/ld-elf/interleave.s: New.
2017-12-06 10:34:36 -08:00
Nick Clifton 846fefbdb2 Tell the linker testsuite that lm32-rtems toolchains do not support the generation of shared libraries.
* testsuite/lib/ld-lib.exp (check_shared_lib_support): Return
	false for lm32-rtems targets.
2017-12-06 10:04:51 +00:00
Alan Modra a3cc9aad2e Enable shared lib tests for frv, lm32, m32r, microblaze, nds32 and or1k
These claim to support shared libs when configuring for <target>-linux
(in contrast to <target>-elf which doesn't support shared libs).

	* testsuite/lib/ld-lib.exp (check_shared_lib_support): Return true
	for frv, lm32, m32r, microblaze, nds32 and or1k linux targets.
2017-12-06 14:21:45 +10:30
Jim Wilson 0527614a9b Really fix riscv shared library __global_pointer$ problem.
ld/
	* emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Remove HIDDEN.
	Don't define __global_pointer$ when CREATE_SHLIB.
	* testsuite/ld-riscv-elf/gp-hidden-64.rd,
	* testsuite/ld-riscv-elf/gp-hidden-lib.rd,
	* testsuite/ld-riscv-elf/gp-hidden-lib.s,
	* testsuite/ld-riscv-elf/gp-hidden-ver-64.rd,
	* testsuite/ld-riscv-elf/gp-hidden-ver.rd,
	* testsuite/ld-riscv-elf/gp-hidden-ver.s,
	* testsuite/ld-riscv-elf/gp-hidden-ver.ver,
	* testsuite/ld-riscv-elf/gp-hidden.rd,
	* testsuite/ld-riscv-elf/gp-hidden.s,
	* testsuite/ld-riscv-elf/gp-hidden.sd: Delete.
	* testsuite/ld-riscv-elf/gp-test-lib.sd,
	* testsuite/ld-riscv-elf/gp-test.s,
	* testsuite/ld-riscv-elf/gp-test.sd: New.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Rewrite gp tests.
2017-12-05 14:42:12 -08:00
Jim Wilson da02107a39 Riscv shared libraries should not export __global_pointer$.
ld/
	* emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Mark
	__global_pointer$ as HIDDEN.
	* testsuite/ld-riscv-elf/gp-hidden-64.rd: New.
	* testsuite/ld-riscv-elf/gp-hidden-lib.rd: New.
	* testsuite/ld-riscv-elf/gp-hidden-lib.s: New.
	* testsuite/ld-riscv-elf/gp-hidden-ver-64.rd: New.
	* testsuite/ld-riscv-elf/gp-hidden-ver.rd: New.
	* testsuite/ld-riscv-elf/gp-hidden-ver.s: New.
	* testsuite/ld-riscv-elf/gp-hidder-ver.ver: New.
	* testsuite/ld-riscv-elf/gp-hidden.rd: New.
	* testsuite/ld-riscv-elf/gp-hidden.s: New.
	* testsuite/ld-riscv-elf/gp-hidden.sd: New.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Change riscv to riscv*.
	Run the new tests with run_ld_link_tests.
2017-12-04 17:37:55 -08:00
Alan Modra 826c3f1edc x86 map file textrel
bfd/
	* elfxx-x86.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function.  Always prints via minfo and
	correct "readonly" to "read-only" in warning message., replacing..
	(_bfd_x86_elf_readonly_dynrelocs): ..this.
	(_bfd_x86_elf_size_dynamic_sections): Correct "readonly" to
	"read-only" in warning message.  Formatting.
	(_bfd_x86_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
	* linker.c (bfd_link_hash_traverse): Comment typo fix.
ld/
	* testsuite/ld-i386/pr17935-1.d: Adjust expected error.
	* testsuite/ld-i386/pr17935-2.d: Likewise.
	* testsuite/ld-x86-64/pr17935-1.d: Likewise.
	* testsuite/ld-x86-64/pr17935-2.d: Likewise.
2017-12-04 23:05:01 +10:30
Alan Modra 97d4213f68 Modify ppceabi ld tests to run on all powerpc ELF targets
* testsuite/ld-powerpc/powerpc.exp (ppceabitests): Add -a32 -mbig
	to assembler options, and -melf32ppc to linker options.  Always
	run these tests.
2017-12-04 10:23:57 +10:30
Tobias Ulmer 7b2d209485 Check return value of bfd_new_link_order
* ldwrite.c (build_link_order): Check return value of all
	bfd_new_link_order calls.
2017-12-01 19:26:45 +10:30
Alan Modra 40363a913b weak alias test
This adds the test I was using when testing 60d67dc8.

	* testsuite/ld-elfweak/alias.c,
	* testsuite/ld-elfweak/alias.dat,
	* testsuite/ld-elfweak/aliasmain.c,
	* testsuite/ld-elfweak/weakref1.c,
	* testsuite/ld-elfweak/weakref2.c: New test.
	* testsuite/ld-elfweak/elfweak.exp: Run it.  Don't return on fails,
	attempt other tests.
2017-12-01 17:23:56 +10:30
Alan Modra 63c1f59d66 readonly_dynrelocs
In early October, HJ Lu added support for a number of targets to "Dump
dynamic relocation in read-only section with minfo".  This extends
that support to more targets, displays the symbol involved, and splits
the existing function that sets TEXTREL into a "readonly_dynrelocs"
and "maybe_set_textrel" function.  I'll need "readonly_dynrelocs" if I
ever get around to fixing "pr22374 function pointer initialization"
fails.

am33_2.0, arc, bfin, hppa64, mn10300, and nios2 fail to mark a binary
needing text relocations with DT_TEXTREL.  That's not good.  xtensa also
fails to do so but complains about "dangerous relocation: dynamic
relocation in read-only section" so I reckon that is fine and have
marked the test as an xfail.  The other targets need maintainer
attention.

Curiously, the map file dump wasn't added for x86, so the map test
currently fail on x86.  It also fails on alpha, am33_2.0, arc, bfin,
hppa64, ia64, m68k, mips, mn10300, nios2, score and vax.  cris
complains with "tmpdir/textrel.o, section .rodata: relocation
R_CRIS_32 should not be used in a shared object; recompile with -fPIC"
so I've marked it as an xfail.

bfd/
	* elf32-hppa.c (maybe_set_textrel): Print symbol for map file output.
	* elf32-ppc.c (maybe_set_textrel): Likewise.
	* elf64-ppc.c (maybe_set_textrel): Likewise.
	* elf32-arm.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(elf32_arm_readonly_dynrelocs): ..this.
	* elf32-lm32.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-m32r.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-metag.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-nds32.c: Delete unnecessary forward declarations.
	(readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-or1k.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-s390.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-sh.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf32-tic6x.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(elf32_tic6x_readonly_dynrelocs): ..this.
	* elf32-tilepro.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elf64-s390.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfnn-aarch64.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing..
	(aarch64_readonly_readonly_dynrelocs): ..this.
	* elfnn-riscv.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfxx-sparc.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
	* elfxx-tilegx.c (readonly_dynrelocs): New function.
	(maybe_set_textrel): New function, replacing old version of..
	(readonly_dynrelocs): ..this.
ld/
	* testsuite/ld-elf/shared.exp: Run new textrel tests.
	* testsuite/ld-elf/textrel.map: New file.
	* testsuite/ld-elf/textrel.rd: New file.
	* testsuite/ld-elf/textrel.s: New file.
	* testsuite/ld-elf/textrel.warn: New file.
2017-12-01 17:23:56 +10:30
Alan Modra 668247656d Fix testcase for PR ld/22471
ASFLAGS should be restored after any modification.  Fixes
metag-linux  +FAIL: Long branch stub
metag-linux  +FAIL: Long branch stub (PIC, app)
mn10300-elf  +FAIL: difference of two same-section symbols where the difference is held in another section
mn10300-elf  +FAIL: relaxation and alignment directives

	PR 22471
	* testsuite/ld-elf/shared.exp: Save and restore ASFLAGS.
2017-11-30 13:16:35 +10:30
H.J. Lu 08f650e6b6 ld: Add a testcase for PR ld/22471
PR ld/22471
	* testsuite/ld-elf/pr22471.t: New file.
	* testsuite/ld-elf/pr22471a.s: Likewise.
	* testsuite/ld-elf/pr22471b.s: Likewise.
	* testsuite/ld-elf/shared.exp (ASFLAGS): Define UNDERSCORE for
	underscore targets.
	Run PR ld/22471 tests.
2017-11-29 04:21:01 -08:00
Stefan Stroe ca39c2f4dd Support --localedir, --datarootdir and --datadir
bfd/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
binutils/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gas/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gold/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gprof/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
ld/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
opcodes/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
2017-11-29 20:10:52 +10:30
Alan Modra 165f707ac8 PR22471, undefined reference to linker-defined symbols
This patch processes linker script assignment statements before ld
opens DT_NEEDED libraries, in order to define symbols like __bss_start
that might also be defined by a library, falsely triggering an error
about "DSO missing from command line".

The initial value won't be correct when assigning a symbol from dot,
and I make no attempt to handle all expressions.  For example, an
assignment like "_start_foo = ADDR (.foo)" isn't valid until sections
are laid out, so won't define _start_foo early.  What's here should be
enough for most common scripts, and hopefully won't perturb fragile
scripts.

bfd/
	PR 22471
	* elflink.c (_bfd_elf_merge_symbol): Allow weak symbols to override
	early passes over linker script symbols.
	* linker.c (_bfd_generic_link_add_one_symbol): Allow symbols to
	override early passes over linker script symbols.  Clear ldscript_def
	on symbol definitions.
ld/
	PR 22471
	* ldexp.c (struct definedness_hash_entry): Delete "by_script".  Make
	"iteration" an 8-bit field, and update mask in all uses.
	(definedness_newfunc): Don't init "by_script".
	(update_definedness): Test ldscript_def rather than by_script.
	(is_sym_value): Likewise.
	(fold_name <DEFINED>): Return a result for first phase.  Test
	ldscript_def.
	(fold_name <NAME>): Return a result for first phase.
	* ldlang.c (open_input_bfds): Process all assignments, not just
	defsym.
	(lang_process): Increment lang_statement_iteration before
	open_input_bfds.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.d: Adjust for larger .dynsym.
	* testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
	* testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
2017-11-28 22:57:00 +10:30
Alan Modra cd5b2babea Copying symbol type in ld script assignments
There is a call to update_definedness between code that evaluates an
assignment expression value and code that transfers symbol
attributes.  When script assignment expressions contain DEFINED, that
can mean the wrong symbol type is copied.  This patch tracks symbols
read during expression evaluation, rather than examining the
expression and re-evaluating conditionals.  Not only does this
simplify the code, it also means ld can now copy symbol types in more
complex expressions.

An unfortunate side effect of copying symbol type for more complex
expressions affects mmix, which uses
 PROVIDE (Main = DEFINED (Main) ? Main : (DEFINED (_start) ? _start : _start.));
in a default script.  So now _start or _start. symbol type may be
copied, losing the function type specially set up for Main.  This can
be avoided by making bfd_copy_link_hash_symbol_type do nothing for
mmix.

bfd/
	* elf64-mmix.c (bfd_elf64_bfd_copy_link_hash_symbol_type): Define.
ld/
	* ldexp.h (struct ldexp_control): Add "assign_src".
	* ldexp.c (fold_trinary): Save and restore assign_src around
	condition evaluation.
	(fold_name <NAME>): Set expld.assign_src.
	(try_copy_symbol_type): Delete.
	(exp_fold_tree_1): Set symbol type using expld.assign_src.
2017-11-28 22:56:59 +10:30
H.J. Lu a83ef4d139 ld: Set non_ir_ref_regular on symbols referenced in regular objects
If linker plugin is enabled, set non_ir_ref_regular on symbols referenced
in regular objects so that linker plugin will get the correct symbol
resolution.

bfd/

	PR ld/22502
	* elflink.c (_bfd_elf_merge_symbol): Also skip definition from
	an IR object.
	(elf_link_add_object_symbols): If linker plugin is enabled, set
	non_ir_ref_regular on symbols referenced in regular objects so
	that linker plugin will get the correct symbol resolution.

ld/

	PR ld/22502
	* testsuite/ld-plugin/lto.exp: Run PR ld/22502 test.
	* testsuite/ld-plugin/pr22502a.c: New file.
	* testsuite/ld-plugin/pr22502b.c: Likewise.
2017-11-28 03:48:44 -08:00
H.J. Lu 8b77421a20 Update PR ld/21562 tests for underscore targets
We also need to provide __start_scnfoo and __stop_scnfoo with the extra
leading underscore for underscore targets.

This patch fixed:

FAIL: ld-elf/pr21562k
FAIL: ld-elf/pr21562l
FAIL: ld-elf/pr21562m
FAIL: ld-elf/pr21562n

for metag-linux,

	* testsuite/ld-elf/pr21562c.t: Also provide ___start_scnfoo and
	___stop_scnfoo.
	* testsuite/ld-elf/pr21562d.t: Likewise.
2017-11-24 08:58:56 -08:00
Martin Storsjo 9d9c67b06c Add libmsvcrt, libmsvcrt-os and libucrtbase to the list of libraries for which the automatic generation of exported variables should be disabled.
In the latest git version of mingw-w64, one can set the default
libmsvcrt.a to actually be the import library of another CRT version,
to facilitate switching to ucrtbase.dll. In these versions, the
traditional libmsvcrt.a (for linking to msvcrt.dll) is also provided
with the name libmsvcrt-os.a.

The import libraries for the CRT also contain a number of compatibility
wrapper functions. The ones in libmsvcrt.a have so far been excluded
automatically since they in most cases come with a corresponding
__imp_foo function. None of these make sense to export automatically
from a DLL though, so add these libraries to the exclude list.

libucrtbase.a contains a number of compatibility wrapper functions
that don't have a corresponding __imp_foo symbol, which cause
these symbols to be exported from DLLs.

This can be worked around on the mingw-w64 side by adding extra
__imp_ symbols, but since they aren't strictly necessary for linking
to succeed, it's probably better long-term to add these libraries to
the exclusion list.

ld	* pe-dll.c (autofilter_liblist): Add libmsvcrt, libmsvcrt-os and
	libucrtbase.
2017-11-23 12:07:24 +00:00
Jan Beulich 43083a502b x86-64: always use unsigned 32-bit reloc for 32-bit addressing w/o base reg
Except for %eip-relative addressing, where we don't have a suitable
relocation type silently wrapping at the 4G boundary, consistently
force use of R_X86_64_32 (in ELF terms) instead of its sign-extending
counterpart. This wasn't right in case there was no base register in
the addressing expression.
2017-11-23 11:02:30 +01:00
Nick Clifton 2824e1bd4f Stop the v850 linker from converting to other output formats whilst linking.
PR 22419
	* emultempl/v850elf.em (v850_create_output_section_statements):
	New function.  Generate an error if attempting to convert the
	format of the output file.
	* testsuite/ld-unique/pr21529.d: Skip for the V850.
	* testsuite/ld-elf/pr21884.d: Skip for the V850.
2017-11-21 14:15:51 +00:00
claziss 50d2740d56 [ARC] Improve printing of pc-relative instructions.
opcodes/
2017-11-21  Claudiu Zissulescu <claziss@synopsys.com>

	* arc-dis.c (print_insn_arc): Pretty print pc-relative offsets.
	* arc-opc.c (SIMM21_A16_5): Make it pc-relative.

gas/
2017-11-21  Claudiu Zissulescu <claziss@synopsys.com>

	* testsuite/gas/arc/b.d : Update test.
	* testsuite/gas/arc/bl.d: Likewise.
	* testsuite/gas/arc/jli-1.d: Likewise.
	* testsuite/gas/arc/lp.d: Likewise.
	* testsuite/gas/arc/pcl-relocs.d: Likewise.
	* testsuite/gas/arc/pcrel-relocs.d: Likewise.
	* testsuite/gas/arc/pic-relocs.d: Likewise.
	* testsuite/gas/arc/plt-relocs.d: Likewise.
	* testsuite/gas/arc/pseudos.d: Likewise.
	* testsuite/gas/arc/relax-avoid2.d: Likewise.
	* testsuite/gas/arc/relax-avoid3.d: Likewise.
	* testsuite/gas/arc/relax-b.d: Likewise.
	* testsuite/gas/arc/tls-relocs.d: Likewise.
	* testsuite/gas/arc/relax-add01.d: Likewise.
	* testsuite/gas/arc/relax-add04.d: Likewise.
	* testsuite/gas/arc/relax-ld01.d: Likewise.
	* testsuite/gas/arc/relax-sub01.d: Likewise.
	* testsuite/gas/arc/relax-sub02.d: Likewise.
	* testsuite/gas/arc/relax-sub04.d: Likewise.
	* testsuite/gas/arc/pcl-print.s: New file.
	* testsuite/gas/arc/pcl-print.d: Likewise.
	* testsuite/gas/arc/nps400-12.d: Likewise.

ld/
2017-11-21  Claudiu Zissulescu <claziss@synopsys.com>

	* testsuite/ld-arc/jli-simple.d: Update test.
2017-11-21 14:56:16 +01:00
Nick Clifton b77db948f4 Fix handling of GNU Property notes that are not in a GNU NOTE PROPERTY section.
PR 22450
gas	* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Skip
	objects without a GNU_PROPERTY note section when looking for a bfd
	onto which notes can be accumulated.

ld	* testsuite/ld-elf/elf.exp: Add --defsym ALIGN=2|3 to assembler
	command line depending upon the size of the target address space.
	* testsuite/ld-elf/pr22450.s: New test file.
	* testsuite/ld-elf/pr22450.d: New test driver.
	* testsuite/config/default.exp: Add note that LD_CLASS refers to
	the size of the host linker not the size of the target linker.
2017-11-20 15:32:55 +00:00
Nick Clifton dda8d76d0d Add support to readelf and objdump for following links to separate debug information files.
Hi Guys,

  I am applying the rather large patch attached to this email to enhance
  the readelf and objdump programs so that they now have the ability to
  follow links to separate debug info files.  (As requested by PR
  15152).  So for example whereas before we had this output:

    $ readelf -wi main.exe

    Contents of the .debug_info section:
    [...]
    <15>   DW_AT_comp_dir    : (alt indirect string, offset: 0x30c)
    [...]

  With the new option enabled we get:

    $ readelf -wiK main.exe

    main.exe: Found separate debug info file: dwz.debug
    Contents of the .debug_info section (loaded from main.exe):
    [...]
    <15>   DW_AT_comp_dir    : (alt indirect string, offset: 0x30c) /home/nickc/Downloads/dwzm
    [...]

  The link following feature also means that we can get two lots of
  output if the same section exists in both the main file and the
  separate debug info file:

    $ readelf -wiK main.exe
    main.exe: Found separate debug info file: dwz.debug
    Contents of the .debug_info section (loaded from main.exe):
    [...]
    Contents of the .debug_info section (loaded from dwz.debug):
    [...]

  The patch also adds the ability to display the contents of debuglink
  sections:

    $ readelf -wk main.exe
    Contents of the .gnu_debugaltlink section:

      Separate debug info file: dwz.debug
      Build-ID (0x14 bytes):
     c4 a8 89 8d 64 cf 70 8a 35 68 21 f2 ed 24 45 3e 18 7a 7a 93

  Naturally there are long versions of these options (=follow-links and
  =links).  The documentation has been updated as well, and since both
  readelf and objdump use the same set of debug display options, I have
  moved the text into a separate file.  There are also a couple of new
  binutils tests to exercise the new behaviour.

  There are a couple of missing features in the current patch however,
  although I do intend to address them in follow up submissions:

  Firstly the code does not check the build-id inside separate debug
  info files when it is searching for a file specified by a
  .gnu_debugaltlink section.  It just assumes that if the file is there,
  then it contains the information being sought.

  Secondly I have not checked the DWARF-5 version of these link
  features, so there will probably be code to add there.

  Thirdly I have only implemented link following for the
  DW_FORM_GNU_strp_alt format.  Other alternate formats (eg
  DW_FORM_GNU_ref_alt) have yet to be implemented.

  Lastly, whilst implementing this feature I found it necessary to move
  some of the global variables used by readelf (eg section_headers) into
  a structure that can be passed around.  I have moved all of the global
  variables that were necessary to get the patch working, but I need to
  complete the operation and move the remaining, file-specific variables
  (eg dynamic_strings).

Cheers
  Nick

binutils	PR 15152
	* dwarf.h (enum dwarf_section_display_enum): Add gnu_debuglink,
	gnu_debugaltlink and separate_debug_str.
	(struct dwarf_section): Add filename field.
	Add prototypes for load_separate_debug_file, close_debug_file and
	open_debug_file.
	* dwarf.c (do_debug_links): New.
	(do_follow_links): New.
	(separate_debug_file, separate_debug_filename): New.
	(fetch_alt_indirect_string): New function.  Retrieves a string
	from the debug string table in the separate debug info file.
	(read_and_display_attr_value): Use it with DW_FORM_GNU_strp_alt.
	(load_debug_section_with_follow): New function.  Like
	load_debug_section, but if the first attempt fails, then tries
	again in the separate debug info file.
	(introduce): New function.
	(process_debug_info): Use load_debug_section_with_follow and
	introduce.
	(load_debug_info): Likewise.
	(display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.
	(display_debug_macinfo): Likewise.
	(display_debug_macro): Likewise.
	(display_debug_abbrev): Likewise.
	(display_debug_loc): Likewise.
	(display_debug_str): Likewise.
	(display_debug_aranges): Likewise.
	(display_debug_addr); Likewise.
	(display_debug_frames): Likewise.
	(display_gdb_index): Likewise.
	(process_cu_tu_index): Likewise.
	(load_cu_tu_indexes): Likewise.
	(display_debug_links): New function.  Displays the contents of a
	.gnu_debuglink or .gnu_debugaltlink section.
	(calc_gnu_debuglink_ctc32):New function.  Calculates a CRC32
	value.
	(check_gnu_debuglink): New function.  Checks the CRC of a
	potential separate debug info file.
	(parse_gnu_debuglink): New function.  Reads a CRC value out of a
	.gnu_debuglink section.
	(check_gnu_debugaltlink): New function.
	(parse_gnu_debugaltlink): New function.  Reads the build-id value
	out of a .gnu_debugaltlink section.
	(load_separate_debug_info): New function.  Finds and loads a
	separate debug info file.
	(load_separate_debug_file): New function. Attempts to find and
	follow a link to a separate debug info file.
	(free_debug_memory): Free the separate debug info file
	information.
	(opts_table): Add "follow-links" and "links".
	(dwarf_select_sections_by_letters): Add "k" and "K".
	(debug_displays): Reformat.  Add .gnu-debuglink and
	.gnu_debugaltlink.
	Add an extra entry for .debug_str in a separate debug info file.
	* doc/binutils.texi: Move description of debug dump features
	common to both readelf and objdump into...
	* objdump.c (usage): Add -Wk and -WK.
	(load_specific_debug_section): Initialise the filename field in
	the dwarf_section structure.
	(close_debug_file): New function.
	(open_debug_file): New function.
	(dump_dwarf): Load and dump the separate debug info sections.
	* readelf.c (struct filedata): New structure.  Contains various
	variables that used to be global:
	(current_file_size, string_table, string_table_length, elf_header)
	(section_headers, program_headers, dump_sects, num_dump_sects):
	Move into filedata structure.
	(cmdline): New global variable.  Contains list of sections to dump
	by number, as specified on the command line.
	Add filedata parameter to most functions.
	(load_debug_section): Load the string table if it has not already
	been retrieved.
	(close_file): New function.
	(close_debug_file): New function.
	(open_file): New function.
	(open_debug_file): New function.
	(process_object): Process sections in any separate debug info files.
	* doc/debug.options.texi: New file.  Add description of =links and
	=follow-links options.
	* NEWS: Mention the new feature.
	* elfcomm.c: Have the byte gte functions take a const pointer.
	* elfcomm.h: Update prototypes.
	* testsuite/binutils-all/dw5.W: Update expected output.
	* testsuite/binutils-all/objdump.WL: Update expected output.
	* testsuite/binutils-all/objdump.exp: Add test of -WK and -Wk.
	* testsuite/binutils-all/readelf.exp: Add test of -wK and -wk.
	* testsuite/binutils-all/readelf.k: New file.
	* testsuite/binutils-all/objdump.Wk: New file.
	* testsuite/binutils-all/objdump.WK2: New file.
	* testsuite/binutils-all/linkdebug.s: New file.
	* testsuite/binutils-all/debuglink.s: New file.

gas	* testsuite/gas/avr/large-debug-line-table.d: Update expected
	output.
	* testsuite/gas/elf/dwarf2-11.d: Likewise.
	* testsuite/gas/elf/dwarf2-12.d: Likewise.
	* testsuite/gas/elf/dwarf2-13.d: Likewise.
	* testsuite/gas/elf/dwarf2-14.d: Likewise.
	* testsuite/gas/elf/dwarf2-15.d: Likewise.
	* testsuite/gas/elf/dwarf2-16.d: Likewise.
	* testsuite/gas/elf/dwarf2-17.d: Likewise.
	* testsuite/gas/elf/dwarf2-18.d: Likewise.
	* testsuite/gas/elf/dwarf2-5.d: Likewise.
	* testsuite/gas/elf/dwarf2-6.d: Likewise.
	* testsuite/gas/elf/dwarf2-7.d: Likewise.

ld	* testsuite/ld-avr/gc-section-debugline.d: Update expected
	output.
2017-11-15 11:34:03 +00:00
Alan Modra 99847db8ea ld einfo positional arg support
To allow translators to reorder values in translated strings.  This
should mean that all binutils messages now have support for
reordering.

Note to translators:  Not all % letters take arguments, so for example
the following only has two arguments, the two %s strings.
"%P%F: output format %s cannot represent section called %s: %E\n"

You could reorder this if you liked to:
"%P%F: %E: section %2$s cannot be represented in output format %1$s\n"

einfo lacks support for flags, field width, precision and length
modifier (apart from %ld and %lu) so don't try to use them in
translations.  Both ld and bfd lack support to use a positional arg
twice.  These features could be added if needed..

	* ldmisc.c (vfinfo): Support up to 9 positional args.
2017-11-15 13:35:03 +10:30
Jim Wilson 4fbd5513b1 Add modified file I missed in last commit. 2017-11-14 17:07:32 -08:00
Jim Wilson 754842fba3 Fix riscv ld testsuite failure for compressed1d.
ld/
	* testsuite/ld-elf/compress1-alt.s: New.
	* testsuite/ld-elf/compressed1d-alt.d: New.
	* testsuite/ld-elf/compressed1d.d: Add riscv*-*-* to notarget list.
2017-11-14 17:02:43 -08:00
Alan Modra 06bcf5416f PR22431, powerpc64 ld segfault when .plt discarded
The fix for the PR is to not use input_section->output_section->owner
to get to the output bfd, but use the output bfd directly since it is
available nowadays in struct bfd_link_info.

I thought it worth warning when non-empty dynamic sections are
discarded too, which meant a tweak to one of the ld tests to avoid the
warning.

bfd/
	PR 22431
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Warn on discarding
	non-empty dynamic section.
	(ppc_build_one_stub): Take elf_gp from output bfd, not output
	section owner.
	(ppc_size_one_stub, ppc64_elf_next_toc_section): Likewise.
ld/
	* testsuite/ld-elf/note-3.t: Don't discard .got.
2017-11-14 20:43:55 +10:30
Alan Modra 640d0ed874 ld-ifunc non-PIC tests
* testsuite/ld-ifunc/ifunc.exp: Ensure non-PIC tests are really
	not PIE by default gcc options.
2017-11-14 19:53:35 +10:30
H.J. Lu 58e6cc77b7 ld: Replace exp_dataseg_none with exp_seg_none
* emultempl/ppc32elf.em (ppc_before_allocation): Replace
	exp_dataseg_none with exp_seg_none.
	* emultempl/ppc64elf.em (prelim_size_sections): Likewise.
	* emultempl/spuelf.em (spu_before_allocation): Likewise.
2017-11-13 08:19:10 -08:00
H.J. Lu ed1794ee7a ld: Add ldlang_check_relro_region/update lang_find_relro_sections_1
Extract GNU_RELRO region check into a new funtion and pass a pointer to
seg_align_type to lang_find_relro_sections_1 so that they can also be
used for text-only LOAD segment.

	* ldlang.c (lang_size_sections_1): Extract GNU_RELRO region check
	into ...
	(ldlang_check_relro_region): New function.
	(lang_find_relro_sections_1): Add an argument for pointer to
	seg_align_type and replace expld.dataseg with the pointer.
	(lang_find_relro_sections): Pass address of expld.dataseg to
	lang_find_relro_sections_1.
2017-11-12 17:26:11 -08:00
H.J. Lu f4d18a5466 cl 2017-11-12 17:26:10 -08:00
H.J. Lu cba6246d3a ld: Add lang_size_relro_segment
Break lang_size_sections down into separate functions so that they can
also be used for text-only LOAD segment.  lang_size_relro_segment will
call lang_size_relro_segment_1 and lang_size_segment for both GNU_RELRO
segment and text-only LOAD segment.

	* ldlang.c (lang_size_segment): New function.
	(lang_size_relro_segment_1): Likewise.
	(lang_size_relro_segment): Likewise.
	(lang_size_sections): Rewrite to call lang_size_relro_segment.
2017-11-12 17:22:24 -08:00
H.J. Lu d7475e036f ld: Add fold_segment_align/fold_segment_relro_end/fold_segment_end
Extract DATA_SEGMENT_END/DATA_SEGMENT_ALIGN/DATA_SEGMENT_RELRO_END cases
for GNU_RELRO segment into separate functions so that they can also be
used for text-only LOAD segment.

	* ldexp.c (fold_unary): Extract the DATA_SEGMENT_END case to ...
	(fold_segment_end): New function.
	(fold_binary): Extract the DATA_SEGMENT_ALIGN case to ...
	(fold_segment_align): New function.
	(fold_binary): Extract the DATA_SEGMENT_RELRO_END case to ...
	(fold_segment_relro_end): New function.
2017-11-12 17:20:18 -08:00
H.J. Lu 0f99513f2a ld: Update phase_enum/relro_enum and add seg_align_type
Update GNU_RELRO date type so that they can also be used for text-only
LOAD segment.

	* ldexp.h (phase_enum): Rename exp_dataseg_none,
	exp_dataseg_align_seen, exp_dataseg_relro_seen,
	exp_dataseg_end_seen, exp_dataseg_relro_adjust,
	exp_dataseg_adjust and exp_dataseg_done to exp_seg_none,
	exp_seg_align_seen, exp_seg_relro_seen, exp_seg_end_seen,
	exp_seg_relro_adjust, exp_seg_adjust and exp_seg_done.
	(relro_enum): Rename exp_dataseg_relro_none,
	exp_dataseg_relro_start and exp_dataseg_relro_end to
	exp_seg_relro_none, exp_seg_relro_start and exp_seg_relro_end.
	(seg_align_type): New struct type.
	(ldexp_control): Use seg_align_type.
	* ldexp.c (fold_unary): Updated.
	(fold_binary): Likewise.
	* ldlang.c (strip_excluded_output_sections): Likewise.
	(lang_size_sections_1): Likewise.
	(lang_size_sections): Likewise.
2017-11-12 17:17:58 -08:00
H.J. Lu f882209d9a ld: Remove PF_X from PT_PHDR segment
It was reasonable to mark PT_PHDR segment with PF_X for compatibility
with UnixWare and Solaris linkers 20 years ago.  But it is inappropriate
today when the primary OS of GNU ld is Linux.  This patch removes PF_X
from PT_PHDR segment as gold does.

Tested natively on Linux/x86 as well as crosss-binutils for alpha-linux,
ia64-linux, powerpc64-linux, powerpc-linux, s390-linux, s390x-linux,
sparc64-linux and sparc-linux.

bfd/

	PR ld/22423
	* elf.c (_bfd_elf_map_sections_to_segments): Remove PF_X from
	PT_PHDR segment.

ld/

	PR ld/22423
	* testsuite/ld-alpha/tlsbin.rd: Replace "R E " with "R +" for
	PT_PHDR segment.
	* testsuite/ld-alpha/tlsbinr.rd: Likewise.
	* testsuite/ld-ia64/tlsbin.rd: Likewise.
	* testsuite/ld-powerpc/tlsexe.r: Likewise.
	* testsuite/ld-powerpc/tlsexe32.r: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.r: Likewise.
	* testsuite/ld-s390/tlsbin.rd: Likewise.
	* testsuite/ld-s390/tlsbin_64.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin32.rd: Likewise.
	* testsuite/ld-sparc/tlssunbin64.rd: Likewise.
	* testsuite/ld-elf/pr22423.d: New test.
2017-11-12 17:04:03 -08:00
H.J. Lu ce3ad33357 ld: Add OTHER_PLT_SECTIONS
OTHER_PLT_SECTIONS contains sections which should be placed right after
.plt section.

	* emulparams/elf32_x86_64.sh (TINY_READONLY_SECTION): Renamed
	to ...
	(OTHER_PLT_SECTIONS): This.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* scripttempl/elf.sc: Place ${OTHER_PLT_SECTIONS} just after
	.plt.
2017-11-12 07:25:36 -08:00