Commit Graph

2056 Commits

Author SHA1 Message Date
H.J. Lu 72f4393d8c Remove leading/trailing white spaces in ChangeLog 2015-07-24 04:16:47 -07:00
Jiong Wang 77a69ff840 [AArch64][3/3] LD support BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 2015-07-16 15:46:21 +01:00
H.J. Lu 19a7fe52ae Make default compression gABI compliant
All programs in binutils+gdb git repo now support gABI compression
with the SHF_COMPRESSED bit.  This patch makes the zlib-gabi option
as compression default for gas, gold, ld and objcopy, instead of the
zlib-gnu option whose outputs are incompatible with gABI.

binutils/

	* objcopy.c (copy_file): Set BFD_COMPRESS_GABI if not
	zlib-gnu.
	* doc/binutils.texi: Change --compress-debug-sections and
	--compress-debug-sections=zlib to zlib-gabi.

binutils/testsuite/

	* binutils-all/compress.exp: Update.

gas/

	* as.c (parse_args): Make --compress-debug-sections and
	--compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* doc/as.texinfo: Change --compress-debug-sections and
	--compress-debug-sections=zlib to zlib-gabi.

gold/

	* compressed_output.cc (Output_compressed_section::set_final_data_size):
	Make --compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* testsuite/Makefile.am (flagstest_compress_debug_sections.check):
	Expect ".debug_.*" with the SHF_COMPRESSED bit, instead of
	".zdebug_".
	* testsuite/Makefile.in: Regenerated.

ld/

	* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Make
	--compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* ld.texinfo: Change --compress-debug-sections=zlib to zlib-gabi.

ld/testsuite/

	* ld-elf/zlibbegin.rS: Updated to .debug_.* with the
	SHF_COMPRESSED bit.
	* ld-elf/zlibnormal.rS: Likewise.
2015-07-14 10:26:23 -07:00
Catherine Moore 3350cc01de 2015-07-09 Catherine Moore <clm@codesourcery.com>
include/
        * elf/mips/mips.h (Val_GNU_MIPS_ABI_FP_NAN2008): New.

        gas/
        * config/tc-mips.c (check_fpabi):  Handle
        VAL_GNU_MIPS_ABI_FP_NAN2008.

        binutils/
        * readelf.c (print_mips_fp_abi_value): Handle
        Val_GNU_MIPS_ABI_FP_NAN2008.

        ld/testsuite/
        * ld-mips-elf/attr-gnu-4-08.d: Update expected output.
        * ld-mips-elf/attr-gnu-4-09.d: New.
        * ld-mips-elf/attr-gnu-4-19.d: New.
        * ld-mips-elf/attr-gnu-4-29.d: New.
        * ld-mips-elf/attr-gnu-4-39.d: New.
        * ld-mips-elf/attr-gnu-4-49.d: New.
        * ld-mips-elf/attr-gnu-4-59.d: New.
        * ld-mips-elf/attr-gnu-4-69.d: New.
        * ld-mips-elf/attr-gnu-4-79.d: New.
        * ld-mips-elf/attr-gnu-4-89.d: New.
        * ld-mips-elf/attr-gnu-4-9.s: New.
        * ld-mips-elf/mips-elf.exp: Run new tests.
2015-07-09 08:26:10 -07:00
Denis Chertykov 328e7bfdde Define DIFF_EXPR_OK for avr target to allow PC relative difference relocation.
When generating relocation (tc_gen_reloc) 32 bit relocation fixup
is changed to new 32 bit PC relative relocation if the fixup has pc-relative
flag set.

bfd/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * elf32-avr.c: Add 32 bit PC relative relocation for AVR target.

gas/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * config/tc-avr.c (tc_gen_reloc): Change 32 bit relocation to
    32 bit PC relative and update offset if the fixup is pc-relative.
    * config/tc-avr.h (DIFF_EXPR_OK): Define to enable PC relative diff
    relocs.

gas/testsuite/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * gas/avr/pc-relative-reloc.d: New test for 32 bit pc relative reloc.
    * gas/avr/per-function-debugline.s: New test source.

include/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * elf/avr.h: Add new 32 bit PC relative relocation.

ld/testsuite/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * ld-avr/gc-section-debugline.d: New test.
    * ld-avr/per-function-debugline.s: Source for new test.
2015-07-08 21:41:52 +03:00
Richard Sandiford 92a9c616e4 Fix an opd->append index in elf64-ppc.c
bfd/
	* elf64-ppc.c (toc_adjusting_stub_needed): Use the symbol value
	plus addend rather than the original st_value when looking up
	entries in opd->adjust.

ld/testsuite/
	* ld-powerpc/tocopt6-inc.s, ld-powerpc/tocopt6a.s,
	ld-powerpc/tocopt6b.s, ld-powerpc/tocopt6c.s,
	ld-powerpc/tocopt6.d: New test.
	* ld-powerpc/powerpc.exp (ppc64elftests): Add it.
2015-07-05 19:57:07 +01:00
Kai Tietz 0f088b2a94 Add experimental support for --gc-sections with COFF and PE based targets.
PR ld/11539
bfd	* coffcode.h (coff_bfd_gc_sections): Define default
	to bfd_coff_gc_sections function.
	* cofflink.c (init_reloc_cookie): Copy and adjust coff
	related code about gc-sections from elflink.c to here.
	(fini_reloc_cookie): Likewise.
	(init_reloc_cookie_rels): Likewise.
	(fini_reloc_cookie_rels): Likewise.
	(init_reloc_cookie_for_section): Likewise.
	(fini_reloc_cookie_for_section): Likewise.
	(_bfd_coff_gc_mark_hook): Likewise.
	(_bfd_coff_gc_mark_rsec): Likewise.
	(_bfd_coff_gc_mark_reloc): Likewise.
	(_bfd_coff_gc_mark): Likewise.
	(_bfd_coff_gc_mark_extra_sections): Likewise.
	(coff_gc_sweep_symbol_info): Likewise.
	(coff_gc_sweep_symbol): Likewise.
	(gc_sweep_hook_fn): Likewise.
	(coff_gc_sweep): Likewise.
	(bfd_coff_gc_sections): Likewise.
	(_bfd_coff_gc_keep): Likewise.
	* libcoff.h (coff_reloc_cookie): New struct.
	(bfd_coff_gc_sections): New prototype.
	(coff_gc_mark_hook_fn): New type.

ld	* scripttempl/pep.sc: Mark .idata*, .CRT*, .tls*,
	.rsrc*, .init, .ctor*, .dtor*, .fini, .jcr,
	.eh_frame, .pdata. .xdata, and .gcc_except_table sections
	as KEEP.
	* scripttempl/pe.sc: Likewise.
2015-07-03 15:50:29 +01:00
Sandra Loosemore 965b1d8083 Add Nios II arch flags and compatibility tests
2015-07-01  Sandra Loosemore  <sandra@codesourcery.com>
	    Cesar Philippidis  <cesar@codesourcery.com>

	bfd/
	* archures.c (bfd_mach_nios2r1, bfd_mach_nios2r2): New.
	* bfd-in2.h: Regenerated.
	* cpu-nios2.c (nios2_compatible): New.
	(N): Use nios2_compatible instead of bfd_default_compatible.
	(NIOS2R1_NEXT, NIOS2R2_NEXT): Define.
	(arch_info_struct): New.
	(bfd_nios2_arch): Chain to NIOS2R1_NEXT.
	* elf32-nios2.c (is_nios2_elf): New.
	(nios2_elf32_merge_private_bfd_data): New.
	(nios2_elf32_object_p): New.
	(bfd_elf32_bfd_merge_private_bfd_data): Define.
	(elf_backend_object_p): Define.

	gas/
	* config/tc-nios2.c: Adjust includes.
	(OPTION_MARCH): Define.
	(md_longopts): Add -march option.
	(nios2_architecture): New.
	(nios2_use_arch): New.
	(md_parse_option): Handle OPTION_MARCH.
	(md_show_usage): Document -march.
	(md_begin): Set arch in BFD.
	(nios2_elf_final_processing): New.
	* config/tc-nios2.h (elf_tc_final_processing): Define.
	(nios2_elf_final_processing): New.
	* doc/c-nios2.texi (-march): Add documentation.

	include/elf/
	* nios2.h (EF_NIOS2_ARCH_R1, EF_NIOS2_ARCH_R2): Define.

	ld/testsuite/
	* ld-nios2/mixed1a.d: New.
	* ld-nios2/mixed1a.s: New.
	* ld-nios2/mixed1b.d: New.
	* ld-nios2/mixed1b.s: New.
	* ld-nios2/nios2.exp: Build the new compatibility tests.
2015-07-01 15:55:28 -07:00
H.J. Lu a2a55a4007 Update xtensa linker tests
* ld-xtensa/tlsbin.rd: Updated.
	* ld-xtensa/tlspic.rd: Likewise.
2015-06-27 16:25:34 -07:00
Matthew Fortune a5499fa464 Add support for DT_MIPS_RLD_MAP_REL.
This tag makes it possible to access the debug map when debugging position
independent executables.

bfd/

	* elfxx-mips.c (_bfd_mips_elf_create_dynamic_sections): Use executable
	instead of !shared to indicate an application vs shared library.
	(_bfd_mips_elf_size_dynamic_sections): Likewise.
	(_bfd_mips_elf_finish_dynamic_sections): Handle DT_MIPS_RLD_MAP_REL.
	(_bfd_mips_elf_get_target_dtag): Likewise.

binutils/

	* readelf.c (get_mips_dynamic_type): Handle DT_MIPS_RLD_MAP_REL.

include/

	* elf/mips.h (DT_MIPS_RLD_MAP_REL): New macro.

ld/testsuite/

	* ld-mips-elf/pic-and-nonpic-3b.ad: Adjust for extra dynamic tag.
	* ld-mips-elf/pic-and-nonpic-4b.ad: Likewise.
	* ld-mips-elf/pic-and-nonpic-5b.ad: Likewise.
	* ld-mips-elf/pic-and-nonpic-6-n32.ad: Likewise.
	* ld-mips-elf/pic-and-nonpic-6-n64.ad: Likewise.
	* ld-mips-elf/pic-and-nonpic-6-o32.ad: Likewise.
	* ld-mips-elf/tlsdyn-o32-1.d: Likewise.
	* ld-mips-elf/tlsdyn-o32-1.got: Likewise.
	* ld-mips-elf/tlsdyn-o32-2.d: Likewise.
	* ld-mips-elf/tlsdyn-o32-2.got: Likewise.
	* ld-mips-elf/tlsdyn-o32-3.d: Likewise.
	* ld-mips-elf/tlsdyn-o32-3.got: Likewise.
	* ld-mips-elf/tlsdyn-o32.d: Likewise.
	* ld-mips-elf/tlsdyn-o32.got: Likewise.
	* ld-mips-elf/pie-n32.d: New file.
	* ld-mips-elf/pie-n64.d: Likewise.
	* ld-mips-elf/pie-o32.d: Likewise.
	* ld-mips-elf/pie.s: Likewise.
	* ld-mips-elf/mips-elf.exp: Add new tests.
2015-06-26 11:53:33 +01:00
H.J. Lu 06e78fc77d Run ld-elf/strtab only on linux/gnu targets
Since not all ELF targets support -shared, we limit ld-elf/strtab to
linux and gnu targets.

	* ld-elf/strtab.d: Only run on *-*-linux* and *-*-gnu* targets.
2015-06-25 10:14:13 -07:00
H.J. Lu 4a677ba724 Update .strtab section sizes in mmix tests
Since commit ef10c3ace0 may reduce .strtab
section size, we need to adjust expected .strtab section sizes in mmix
tests.

gas/testsuite/

	* gas/mmix/loc-3.d: Updated.
	* gas/mmix/loc-5.d: Likewise.

ld/testsuite/

	* ld-mmix/bspec1.d: Updated.
	* ld-mmix/bspec2.d: Likewise.
	* ld-mmix/undef-3.d: Likewise.
2015-06-25 10:07:53 -07:00
H.J. Lu ef10c3ace0 Use strtab with GC and suffix merging for .strtab
This patch uses ELF strtab with GC and suffix merging support to create
ELF .strtab section.  There is some small memory overhead to use ELF
strtab:

==14928== HEAP SUMMARY:
==14928==     in use at exit: 3,276,318 bytes in 679 blocks
==14928==   total heap usage: 1,544 allocs, 865 frees, 15,259,146 bytes allocated

vs.

==14936== HEAP SUMMARY:
==14936==     in use at exit: 3,276,318 bytes in 679 blocks
==14936==   total heap usage: 1,532 allocs, 853 frees, 15,026,402 bytes allocated

when running:

./ld-new -m elf_x86_64 -o tmpdir/ld-partial.o -r ldgram.o ldlex-wrapper.o lexsup.o ldlang.o mri.o ldctor.o ldmain.o plugin.o ldwrite.o ldexp.o ldemul.o ldver.o ldmisc.o ldfile.o ldcref.o eelf_x86_64.o eelf32_x86_64.o eelf_i386.o eelf_iamcu.o ei386linux.o eelf_l1om.o eelf_k1om.o ldbuildid.o

The results are

  [32] .strtab STRTAB 0+ 3beff8 00407a 00 0 0 1

vs

  [32] .strtab STRTAB 0+ 3beff8 0041d8 00 0 0 1

It reduces the .strtab size by 350 bytes, about 2%

Saving on libc.so from glibc is much more since libc.so has many alias
symbols with the same suffix.  For x32 glibc,

 [82] .strtab STRTAB 0+ 81b348 0159e7 00 0 0 1

vs

 [82] .strtab STRTAB 0+ 81b8bc 019e72 00 0 0 1

It reduces the .strtab size by 17547 bytes, about 16%.

bfd/

	PR gas/18451
	* elf-bfd.h (elf_sym_strtab): New.
	(elf_link_hash_table): Add strtabcount, strtabsize and
	strtab.
	(_bfd_elf_stringtab_init): Removed.
	* elf.c (_bfd_elf_stringtab_init): Removed.
	(_bfd_elf_compute_section_file_positions): Replace
	bfd_strtab_hash/_bfd_elf_stringtab_init/_bfd_stringtab_free/
	_bfd_stringtab_size with
	elf_strtab_hash/_bfd_elf_strtab_init/_bfd_elf_strtab_free/
	_bfd_elf_strtab_size.  Use _bfd_elf_strtab_add,
	_bfd_elf_strtab_finalize and _bfd_elf_strtab_offset to get
	st_name.
	(swap_out_syms): Likewise.
	* elflink.c (elf_final_link_info): Replace bfd_strtab_hash
	with elf_strtab_hash.  Remove symbuf, symbuf_count,
	symbuf_size and shndxbuf_size.
	(elf_link_flush_output_syms): Removed.
	(elf_link_output_sym): Renamed to ...
	(elf_link_output_symstrtab): This.  Replace _bfd_stringtab_add
	with _bfd_elf_strtab_add.  Don't flush symbols to the file nor
	swap out symbols.
	(elf_link_swap_symbols_out): New.
	(elf_link_output_extsym): Replace elf_link_output_sym with
	elf_link_output_symstrtab.
	(elf_link_input_bfd): Likewise.
	(elf_final_link_free): Replace _bfd_stringtab_free with
	_bfd_elf_strtab_free.  Remove symbuf.
	(bfd_elf_final_link): Replace _bfd_elf_stringtab_init with
	_bfd_elf_strtab_init.  Don't set symbuf, symbuf_count,
	symbuf_size nor shndxbuf_size.  Initialize strtabsize and
	strtab.  Initialize symshndxbuf to -1 when number of sections
	>= 64K.  Replace elf_link_output_sym/elf_link_output_sym with
	elf_link_output_symstrtab/elf_link_output_symstrtab. Don't
	call elf_link_flush_output_syms.  Call _bfd_elf_strtab_finalize
	and elf_link_swap_symbols_out.  Replace _bfd_stringtab_size
	and _bfd_stringtab_emit with _bfd_elf_strtab_size and
	_bfd_elf_strtab_emit.

gas/testsuite/

	PR gas/18451
	* gas/elf/elf.exp: Run strtab.
	* gas/elf/strtab.d: New file.
	* gas/elf/strtab.s: Likewise.

ld/testsuite/

	PR gas/18451
	* ld-elf/strtab.d: New file.
	* ld-elf/strtab.s: Likewise.
2015-06-25 08:16:14 -07:00
H.J. Lu 7c1e8d3ed5 Keep .plt section and DT_PLTGOT for prelink
Since the .plt section and DT_PLTGOT are used by prelink to undo
prelinking for dynamic relocations, we must keep them even if there is
no PLT relocation.  This patch reverted commit a3747075a.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Always allocate
	space for the first .plt entry.
	(elf_i386_size_dynamic_sections): Always add DT_PLTGOT for .plt
	section.  Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
	there are PLT relocations.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Always
	allocate space for the first .plt entry.
	(elf_x86_64_size_dynamic_sections): Always add DT_PLTGOT for
	.plt section.  Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
	there are PLT relocations.

ld/testsuite/

	* ld-i386/i386.exp: Run pltgot-2 for Linux targets.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pltgot-1.d: Updated.
	* ld-x86-64/pltgot-1.d: Likewise.
	* ld-i386/pltgot-2.d: New file.
	* ld-x86-64/pltgot-2.d: Likewise.
2015-06-24 13:47:37 -07:00
Jiong Wang c217058957 [AArch64] Generate DT_TEXTREL for relocation against read-only section
2015-06-23  Jiong Wang  <jiong.wang@arm.com>

  bfd/
    * elfnn-aarch64.c (aarch64_readonly_dynrelocs): New function.
    (elfNN_aarch64_size_dynamic_sections): Traverse hash table to check
    relocations against read-only sections.

  ld/testsuite/
    * ld-aarch64/dt_textrel.s: New testcase.
    * ld-aarch64/dt_textrel.d: New expectation file.
    * ld-aarch64/aarch64-elf.exp: Run new testcase.
2015-06-23 12:12:06 +01:00
Jiong Wang 696ddf4b52 [AArch64] Select correct linker emulation for ILP32 according to endianes
2015-06-17  Jiong Wang  <jiong.wang@arm.com>

ld/testsuite/
  * ld-aarch64/aarch64-elf.exp (aarch64_choose_ilp32_emul): New function.
  * ld-aarch64/emit-relocs-28.d: Use aarch64_choose_ilp32_emul to choose
  emulation mode.
2015-06-17 16:36:04 +01:00
Alan Modra 1d5c94cb3e ppc476 linker workaround shared lib fixes again
Huh, I can't even write a binary search properly.

bfd/
	* elf32-ppc.c (ppc_elf_relocate_section): Correct binary search of
	dynamic relocs.
ld/testsuite/
	* ld-powerpc/ppc476-shared.s: Repeat dynamic reloc generating insns.
	* ld-powerpc/ppc476-shared.d: Update.
	* ld-powerpc/ppc476-shared2.d: Update.
2015-06-16 17:42:29 +09:30
Tristan Gingold 3604cb1f8c Add new ld option: --print-memory-usage
ld/
	* NEWS: Mention new option.
	* lexsup.c (parse_args): Handle --print-memory-usage.
	(ld_options): Add --print-memory-usage.
	* ldmain.c (main): Call lang_print_memory_usage.
	* ldlex.h (enum option_values): Add OPTION_PRINT_MEMORY_USAGE.
	* ldlang.h: Add prototype of lang_print_memory_usage.
	* ldlang.c (lang_print_memory_size, lang_print_memory_usage): New
	functions.
	* ld.texinfo (Options): Document --print-memory-usage.
	* ld.h (args_type): Add print_memory_usage field.

ld/testsuite/
	* ld-scripts/print-memory-usage-1.t,
	* ld-scripts/print-memory-usage-1.s,
	* ld-scripts/print-memory-usage-1.l,
	* ld-scripts/print-memory-usage-2.t,
	* ld-scripts/print-memory-usage-2.l,
	* ld-scripts/print-memory-usage-3.s,
	* ld-scripts/print-memory-usage-3.t,
	* ld-scripts/print-memory-usage-3.l,
	* ld-scripts/print-memory-usage.t: New tests.
	* ld-scripts/print-memory-usage.exp: Run them.
2015-06-12 11:24:36 +02:00
Nick Clifton e00a2fbc24 Fixes a typo in the list of targets that should not run the compressed1d test.
* ld-elf/compressed1d.d: Fix typo: iq200 -> iq2000.
2015-06-05 16:48:01 +01:00
Alan Modra f8b447819b ppc476 linker workaround shared lib fixes
When building a shared lib from non-PIC objects, we'll get dynamic
text relocations.  These need to move with any insns we move.
Otherwise the dynamic reloc will modify the branch, resulting in
crashes and other unpleasant behaviour.

Also, ld -r --ppc476-workaround used with sufficiently aligned PIC
objects needs a fix for emitted REL16 relocs.

bfd/
	* elf64-ppc.c (ppc_elf_relocate_section): Move dynamic text
	relocs with insns moved by --ppc476-workaround.  Correct
	output of REL16 relocs.
ld/testsuite/
	* ld-powerpc/ppc476-shared.s,
	* ld-powerpc/ppc476-shared.lnk,
	* ld-powerpc/ppc476-shared.d,
	* ld-powerpc/ppc476-shared2.d: New tests.
	* ld-powerpc/powerpc.exp: Run them.
2015-06-05 20:12:11 +09:30
Jiong Wang afa403d8d4 [AArch64] Fix typo in testcase
ld/testsuite/
  * ld-aarch64/emit-relocs-313.s: Use gotpage_lo15.
2015-06-02 14:01:29 +01:00
Jiong Wang 7018c0308a [AArch64] BFD support BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
This patch add BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14 relocation
supoprt in bfd linker.

2015-06-01  Jiong Wang  <jiong.wang@arm.com>

bfd/
  * elfnn-aarch64.c (aarch64_reloc_got_type): Support
  BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14.
  (elfNN_aarch64_final_link_relocate): Ditto.
  (elfNN_aarch64_gc_swap_hook): Ditto.
  (elfNN_aarch64_check_relocs): Ditto.
  * elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Ditto.

ld/testsuite/
  * ld-aarch64/emit-relocs-28.s: New test file.
  * ld-aarch64/emit-relocs-28.d: Ditto.
  * ld-aarch64/aarch64-elf.exp: Run new test.
2015-06-01 15:45:25 +01:00
Jiong Wang 36e6c1400b [AArch64] BFD_RELOC_AARCH64_TLSLE_ADD_LO12 should enable overflow check
BFD_RELOC_AARCH64_TLSLE_ADD_LO12 is used to generate simplest
one-instruction addressing for TLS LE model when tls size is smaller
4K. Linker need to make sure there is no TLS offset overflow.

2015-06-01  Jiong Wang  <jiong.wang@arm.com>

bfd/
  * elfnn-aarch64.c (elfNN_aarch64_howto_table): Set overflow type to
  complain_overflow_unsigned for BFD_RELOC_AARCH64_TLSLE_ADD_LO12.
  * elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation): Don't use
  PGOFF for BFD_RELOC_AARCH64_TLSLE_ADD_LO12, that will mask off all
  potential high overflowed bits.

ld/testsuite/
  * ld-aarch64/tprel_add_lo12_overflow.s: New testcase.
  * ld-aarch64/tprel_add_lo12_overflow.d: Nex expectation file.
  * ld-aarch64/aarch64-elf.exp: Run new testcase.
2015-06-01 10:31:38 +01:00
Jiong Wang 99ad26cb0d [AArch64] BFD Support BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
2015-06-01  Jiong Wang  <jiong.wang@arm.com>
bfd/
	* elfnn-aarch64.c (aarch64_reloc_got_type): Support
	BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15.
	(elfNN_aarch64_final_link_relocate): Ditto.
	(elfNN_aarch64_gc_swap_hook): Ditto.
	(elfNN_aarch64_check_relocs): Ditto.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Ditto.

ld/testsuite/
	* ld-aarch64/emit-relocs-313.s: New test file.
	* ld-aarch64/emit-relocs-313.d: Ditto.
	* ld-aarch64/aarch64-elf.exp: Run new test.
2015-06-01 10:26:00 +01:00
Stephen Kitt 32c17175af Fix building PE test executables in environments where $CFLAGS is needed.
* ld-pe/pe-run2.exp (test_direct2_link_dll): Add $CFLAGS to the
	compiler command line.
2015-05-29 11:51:41 +01:00
Catherine Moore 2f0c68f23b Compact EH Support
The specification for the Compact EH format is available at:
https://github.com/MentorEmbedded/cxx-abi/blob/master/MIPSCompactEH.pdf

2015-05-28  Catherine Moore  <clm@codesourcery.com>
	    Bernd Schmidt <bernds@codesourcery.com>
	    Paul Brook <paul@codesourcery.com>

	bfd/
	* bfd-in2.h: Regenerated.
	* elf-bfd.h (DWARF2_EH_HDR, COMPACT_EH_HDR): Define.
	(COMPACT_EH_CANT_UNWIND_OPCODE): Define.
	(dwarf_eh_frame_hdr_info): Move dwarf-specific fields from
	eh_frame_hdr_info.
	(compact_eh_frame_hdr_info): Declare.
	(eh_frame_hdr_info):  Redeclare with union for dwarf-specific
	fields and compact-eh fields.
	(elf_backend_data): Add cant_unwind_opcode and compact_eh_encoding.
	(bfd_elf_section_data): Add eh_frame_entry_field.
	(elf_section_eh_frame_entry): Define.
	(bfd_elf_parse_eh_frame_entries): Declare.
	(_bfd_elf_parse_eh_frame_entry): Declare.
	(_bfd_elf_end_eh_frame_parsing): Declare.
	(_bfd_elf_write_section_eh_frame_entry): Declare.
	(_bfd_elf_eh_frame_entry_present): Declare.
	(_bfd_elf_section_for_symbol): Declare.
	* elf-eh-frame.c (bfd_elf_discard_eh_frame_entry): New function.
	(bfd_elf_record_eh_frame_entry): New function.
	(_bfd_elf_parse_eh_frame_entry): New function.
	(_bfd_elf_parse_eh_frame): Update hdr_info field references.
	(cmp_eh_frame_hdr): New function.
	(add_eh_frame_hdr_terminator): New function.
	(_bfd_elf_end_eh_frame_parsing): New function.
	(find_merged_cie): Update hdr_info field references.
	(_bfd_elf_discard_section_eh_frame): Likewise.
	(_bfd_elf_discard_section_eh_frame_hdr): Add Compact EH support.
	(_bfd_elf_eh_frame_entry_present): New function.
	(_bfd_elf_maybe_strip_eh_frame_hdr): Add Compact EH support.
	(_bfd_elf_write_section_eh_frame_entry): New function.
	(_bfd_elf_write_section_eh_frame): Update hdr_info field references.
	(_bfd_elf_fixup_eh_frame_hdr): New function.
	(write_compact_eh_frame_hdr): New function.
	(write_dwarf_eh_frame_hdr): New function.
	(_bfd_elf_write_section_eh_frame_hdr): Add Compact EH support.
	* elflink.c (_bfd_elf_section_for_symbol): New function.
	(elf_section_ignore_discarded_relocs): Add Compact EH support.
	(elf_link_input_bfd): Likewise.
	(bfd_elf_final_link): Likewise.
	(_bfd_elf_gc_mark): Likewise.
	(bfd_elf_parse_eh_frame_entries): New function.
	(bfd_elf_gc_sections): Add Compact EH support.
	(bfd_elf_discard_info): Likewise.
	* elfxx-mips.c: Include dwarf2.h.
	(_bfd_mips_elf_compact_eh_encoding): New function.
	(_bfd_mips_elf_cant_unwind_opcode): New function.
	* elfxx-mips.h (_bfd_mips_elf_compact_eh_encoding): Declare.
	(_bfd_mips_elf_cant_unwind_opcode): Declare.
	(elf_backend_compact_eh_encoding): Define.
	(elf_backend_cant_unwind_opcode): Define.
	* elfxx-target.h (elf_backend_compact_eh_encoding): Provide default.
	(elf_backend_cant_unwind_opcode): Provide default.
	(elf_backend_data elfNN_bed): Add elf_backend_compact_eh_encoding and
	elf_backend_cant_unwind_opcode.
	* section.c (SEC_INFO_TYPE_EH_FRAME_ENTRY): Add definition.

	gas/
	* config/tc-alpha.c (all_cfi_sections): Declare.
	(s_alpha_ent): Initialize all_cfi_sections.
	(alpha_elf_md_end): Invoke cfi_set_sections.
	* config/tc-mips.c (md_apply_fix):  Handle BFD_RELOC_NONE.
	(s_ehword): Use BFD_RELOC_32_PCREL.
	(mips_fix_adjustable): Handle BFD_RELOC_32_PCREL.
	(mips_cfi_reloc_for_encoding): New function.
	* tc-mips.h (DWARF2_FDE_RELOC_SIZE): Redefine.
	(DWARF2_FDE_RELOC_ENCODING): Define.
	(tc_cfi_reloc_for_encoding): Define.
	(mips_cfi_reloc_for_encoding): Define.
	(tc_compact_eh_opcode_stop): Define.
	(tc_compact_eh_opcode_pad): Define.
	* doc/as.texinfo: Document Compact EH extensions.
	* doc/internals.texi: Likewise.
	* dw2gencfi.c (EH_FRAME_LINKONCE): Redefine.
	(tc_cfi_reloc_for_encoding): Provide default.
	(compact_eh): Declare.
	(emit_expr_encoded): New function.
	(get_debugseg_name): Add Compact EH support.
	(alloc_debugseg_item): Likewise.
	(cfi_set_sections): New function.
	(dot_cfi_fde_data): New function.
	(dot_cfi_personality_id): New function.
	(dot_cfi_inline_lsda): New function.
	(cfi_pseudo_table): Add cfi_fde_data, cfi_personality_id,
	and cfi_inline_lsda.
	(dot_cfi_personality): Add Compact EH support.
	(dot_cfi_lsda): Likewise.
	(dot_cfi_sections): Likewise.
	(dot_cfi_startproc): Likewise.
	(get_cfi_seg): Likewise.
	(output_compact_unwind_data): New function.
	(output_cfi_insn): Add Compact EH support.
	(output_cie): Likewise.
	(output_fde): Likewise.
	(cfi_finish): Likewise.
	(cfi_emit_eh_header): New function.
	(output_eh_header): New function.
	* dw2gencfi.h (cfi_set_sections): Declare.
	(SUPPORT_COMPACT_EH): Define.
	(MULTIPLE_FRAME_SECTIONS): Define.
	New enumeration to describe the Compact EH header format.
	(fde_entry): Add new fields personality_id, eh_header_type, eh_data_size,
	eh_data, eh_loc and sections.
	(CFI_EMIT_eh_frame, CFI_EMIT_debug_frame, CFI_EMIT_target,
	CFI_EMIT_eh_frame_compact): Define.

2015-05-22  Catherine Moore  <clm@codesourcery.com>
	    Bernd Schmidt <bernds@codesourcery.com>

	gas/testsuite/
	* gas/mips/mips.exp: Run new tests.

	* gas/mips/compact-eh-1.s: New file.
	* gas/mips/compact-eh-2.s: New file.
	* gas/mips/compact-eh-3.s: New file.
	* gas/mips/compact-eh-4.s: New file.
	* gas/mips/compact-eh-5.s: New file.
	* gas/mips/compact-eh-6.s: New file.
	* gas/mips/compact-eh-7.s: New file.
	* gas/mips/compact-eh-eb-1.d: New file.
	* gas/mips/compact-eh-eb-2.d: New file.
	* gas/mips/compact-eh-eb-3.d: New file.
	* gas/mips/compact-eh-eb-4.d: New file.
	* gas/mips/compact-eh-eb-5.d: New file.
	* gas/mips/compact-eh-eb-6.d: New file.
	* gas/mips/compact-eh-eb-7.d: New file.
	* gas/mips/compact-eh-el-1.d: New file.
	* gas/mips/compact-eh-el-2.d: New file.
	* gas/mips/compact-eh-el-3.d: New file.
	* gas/mips/compact-eh-el-4.d: New file.
	* gas/mips/compact-eh-el-5.d: New file.
	* gas/mips/compact-eh-el-6.d: New file.
	* gas/mips/compact-eh-el-7.d: New file.
	* gas/mips/compact-eh-err1.l: New file.
	* gas/mips/compact-eh-err1.s: New file.
	* gas/mips/compact-eh-err2.l: New file.
	* gas/mips/compact-eh-err2.s: New file.

2015-05-22  Catherine Moore  <clm@codesourcery.com>

	include/
	* bfdlink.h: Rename eh_frame_hdr to eh_frame_hdr_type.

2015-05-22  Catherine Moore  <clm@codesourcery.com>
	    Paul Brook <paul@codesourcery.com>

	ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_after_open):
	Add Compact EH support.
	* scripttempl/elf.sc: Handle .eh_frame_entry and .gnu_extab
	sections.

2015-05-22  Catherine Moore  <clm@codesourcery.com>

	ld/testsuite/
	* ld-mips-elf/compact-eh.ld: New linker script.
	* ld-mips-elf/compact-eh1.d: New.
	* ld-mips-elf/compact-eh1.s: New.
	* ld-mips-elf/compact-eh1a.s: New.
	* ld-mips-elf/compact-eh1b.s: New.
	* ld-mips-elf/compact-eh2.d: New.
	* ld-mips-elf/compact-eh2.s: New.
	* ld-mips-elf/compact-eh3.d: New.
	* ld-mips-elf/compact-eh3.s: New.
	* ld-mips-elf/compact-eh3a.s: New.
	* ld-mips-elf/compact-eh4.d: New.
	* ld-mips-elf/compact-eh5.d: New.
	* ld-mips-elf/compact-eh6.d: New.
	* ld-mips-elf/mips-elf.exp: Run new tests.
2015-05-28 15:21:17 -07:00
H.J. Lu 8ded2ddc8b Convert PLT reloc only if pointer equality isn't needed
When pointer equality needed, we can't replace PLT relocations with
GOT relocations for -z now.  This patch checks if pointer equality is
needed before converting PLT relocations to GOT relocations.

bfd/

	PR binutils/18458
	* elf32-i386.c (elf_i386_check_relocs): Create .plt.got section
	for now binding only if pointer equality isn't needed.
	(elf_i386_allocate_dynrelocs): Use .plt.got section for now
	binding only if pointer equality isn't needed.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Create .plt.got
	section for now binding only if pointer equality isn't needed.
	(elf_x86_64_allocate_dynrelocs): Use .plt.got section for now
	binding only if pointer equality isn't needed.

ld/testsuite/

	PR binutils/18458
	* ld-elf/shared.exp (build_tests): Build libpr18458a.so and
	libpr18458b.so.
	(run_tests): Run pr18458 test.
	* ld-elf/pr18458a.c: New file.
	* ld-elf/pr18458b.c: Likewise.
	* ld-elf/pr18458c.c: Likewise.
2015-05-27 14:32:24 -07:00
H.J. Lu 25070364b0 Don't generate PLT relocations for now binding
There is no need for PLT relocations with -z now. We can use GOT
relocations, which take less space, instead and replace 16-byte .plt
entres with 8-byte .plt.got entries.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Create .plt.got section
	for now binding.
	(elf_i386_allocate_dynrelocs): Use .plt.got section for now
	binding.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Create .plt.got
	section for now binding.
	(elf_x86_64_allocate_dynrelocs): Use .plt.got section for now
	binding.

ld/testsuite/

	* ld-i386/i386.exp: Run PR ld/17689 tests with -z now.
	* ld-x86-64/x86-64.exp: Likewise
	* ld-i386/pr17689now.rd: New file.
	* ld-x86-64/pr17689now.rd: Likewise
2015-05-16 07:00:55 -07:00
H.J. Lu 5db04b0965 Support AMD64/Intel ISAs in assembler/disassembler
AMD64 spec and Intel64 spec differ in direct unconditional branches in
64-bit mode.  AMD64 supports direct unconditional branches with 16-bit
offset via the data size prefix, which truncates RIP to 16 bits, while
the data size prefix is ignored by Intel64.

This patch adds -mamd64/-mintel64 option to x86-64 assembler and
-Mamd64/-Mintel64 option to x86-64 disassembler.  The most permissive
ISA, which is AMD64, is the default.

GDB can add an option, similar to

(gdb) help set disassembly-flavor
Set the disassembly flavor.
The valid values are "att" and "intel", and the default value is "att".

to select which ISA to disassemble.

binutils/

	PR binutis/18386
	* doc/binutils.texi: Document -Mamd64 and -Mintel64.

gas/

	PR binutis/18386
	* config/tc-i386.c (OPTION_MAMD64): New.
	(OPTION_MINTEL64): Likewise.
	(md_longopts): Add -mamd64 and -mintel64.
	(md_parse_option): Handle OPTION_MAMD64 and OPTION_MINTEL64.
	(md_show_usage): Add -mamd64 and -mintel64.
	* doc/c-i386.texi: Document -mamd64 and -mintel64.

gas/testsuite/

	PR binutis/18386
	* gas/i386/i386.exp: Run x86-64-branch-2 and x86-64-branch-3.
	* gas/i386/x86-64-branch.d: Also pass -Mintel64 to objdump.
	* gas/i386/ilp32/x86-64-branch.d: Likewise.
	* gas/i386/x86-64-branch-2.d: New file.
	* gas/i386/x86-64-branch-2.s: Likewise.
	* gas/i386/x86-64-branch-3.l: Likewise.
	* gas/i386/x86-64-branch-3.s: Likewise.

ld/testsuite/

	PR binutis/18386
	* ld-x86-64/tlsgdesc.dd: Also pass -Mintel64 to objdump.
	* ld-x86-64/tlspic.dd: Likewise.
	* ld-x86-64/x86-64.exp (x86_64tests): Also pass -Mintel64 to
	objdump for tlspic.dd and tlsgdesc.dd.

opcodes/

	PR binutis/18386
	* i386-dis.c: Add comments for '@'.
	(x86_64_table): Use '@' on call/jmp for X86_64_E8/X86_64_E9.
	(enum x86_64_isa): New.
	(isa64): Likewise.
	(print_i386_disassembler_options): Add amd64 and intel64.
	(print_insn): Handle amd64 and intel64.
	(putop): Handle '@'.
	(OP_J): Don't ignore the operand size prefix for AMD64 in 64-bit.
	* i386-gen.c (cpu_flags): Add CpuAMD64 and CpuIntel64.
	* i386-opc.h (AMD64): New.
	(CpuIntel64): Likewise.
	(i386_cpu_flags): Add cpuamd64 and cpuintel64.
	* i386-opc.tbl: Add direct call/jmp with Disp16|Disp32 for AMD64.
	Mark direct call/jmp without Disp16|Disp32 as Intel64.
	* i386-init.h: Regenerated.
	* i386-tbl.h: Likewise.
2015-05-15 09:48:10 -07:00
H.J. Lu 31955f993d Add missing ChangeLog entries for PR binutis/18386 2015-05-13 04:33:45 -07:00
H.J. Lu a3747075ae Allocate the first .plt entry space only if needed
Commit dd7e64d45b may optimize out
i386/x86-64 JUMP_SLOT relocation.  If there is no JUMP_SLOT relocation
left, we don't need to the first .plt entry.  This patch allocates
space for the first .plt entry only if we also reserve space for a PLT
slot for JUMP_SLOT relocation.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Allocate space
	for the first .plt entry only if needed.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.

ld/testsuite/

	* ld-i386/i386.exp: Run pltgot-1 for Linux targets.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pltgot-1.d: New file.
	* ld-i386/pltgot-1.s: Likewise.
	* ld-x86-64/pltgot-1.d: Likewise.
	* ld-x86-64/pltgot-1.s: Likewise.
2015-05-12 13:11:48 -07:00
H.J. Lu 5197d47436 Default e_machine to EM_IAMCU for i?86-*-elfiamcu
This patch sets the default ELF output format of assembler and linker to
EM_IAMCU when binutils is configured to i?86-*-elfiamcu target.

gas/

	* configure.tgt (arch): Set to iamcu for i386-*-elfiamcu target.
	* config/tc-i386.c (i386_mach): Support iamcu.
	(i386_target_format): Likewise.

ld/

	* configure.tgt: Support i[3-7]86-*-elfiamcu target.

ld/testsuite/

	* ld-i386/i386.exp (iamcu_tests): Run iamcu-4.
	* ld-i386/iamcu-4.d: New file.
2015-05-11 12:06:33 -07:00
H.J. Lu 7e0a81123d Add Intel MCU support to ld
-m elf_iamcu must be passed to i386 linker to generate Intel MCU binary.

ld/

	* Makefile.am (ALL_EMULATION_SOURCES): Add eelf_iamcu.c.
	(eelf_iamcu.c): New.
	* configure.tgt (targ_extra_emuls): Add elf_iamcu if elf_i386 is
	enabled in BFD.
	* Makefile.in: Regenerated.
	* emulparams/elf_iamcu.sh: New file.

ld/testsuite/

	* ld-i386/abs-iamcu.d: New file.
	* ld-i386/dummy.s: Likewise.
	* ld-i386/foo.s: Likewise.
	* ld-i386/iamcu-1.d: Likewise.
	* ld-i386/iamcu-2.d: Likewise.
	* ld-i386/iamcu-3.d: Likewise.
	* ld-i386/start.s: Likewise.
	* ld-i386/i386.exp (iamcu_tests): New.
	Run iamcu_tests.
2015-05-11 11:29:03 -07:00
H.J. Lu 43c1d34c31 Link the last *normal against libfoozlib.so
Link the last zlibnormal gnunormal and gabinormal against libfoozlib.so
so that their only differences are DWARF debug sections.

	PR ld/18354
	* ld-elf/compress.exp (run_tests): Link the last zlibnormal,
	gnunormal and gabinormal against libfoozlib.so.
2015-04-29 08:43:22 -07:00
Jiong Wang 9081b64dc1 [ARM] Update ld testcases
2015-04-29  Renlin Li  <renlin.li@arm.com>
ld/testsuite/
  * ld-arm/ifunc-10.dd: Adjust expected output.
  * ld-arm/ifunc-2.dd: Likewise.
2015-04-29 11:04:17 +01:00
Andreas Krebbel 963a4320b4 S/390: Fix gotreloc_31-1 testcase.
Since we changed the default arch for objdump to zarch the following
testcase needs to check for the real instruction mnemonics instead of
just bytes.

This fixes the following testsuite fail on s390x:

FAIL: GOT: symbol address load from got to larl
2015-04-27 10:24:24 +02:00
Alan Modra 44bd1acd55 Non-alloc sections don't belong in PT_LOAD segments
Taking them out showed a bug in the powerpc64 backend with .branch_lt
being removed from output_bfd but not from previously set up segment
section maps.  Removing the bfd sections meant their sh_flags (and
practically everything else) remaining zero, ie. not SHF_ALLOC,
triggering complaints about "`.branch_lt' can't be allocated in
segment".

include/elf/
	* internal.h (ELF_SECTION_IN_SEGMENT_1): Ensure PT_LOAD and
	similar segments only contain alloc sections.
ld/
	* emultempl/ppc64elf.em (gld${EMULATION_NAME}_after_allocation):
	Call gld${EMULATION_NAME}_map_segments regardless of need_laying_out.
ld/testsuite/
	* ld-powerpc/tocnovar.d: Revert last change.
2015-04-25 09:15:49 +09:30
Richard Earnshaw 7a5c933c7c [ARM]: Don't tail-pad over-aligned functions to the alignment boundary.
2015-04/24  Richard Earnshaw  <rearnsha@arm.com>

	gas/
	* config/tc-arm.h (arm_min): New function.
	(SUB_SEGMENT_ALIGN): Define.

	gas/testsuite/
	* gas/arm/align64.d: Delete trailing padding NOPs.

	ld/testsuite/
	* ld-arm/armthumb-lib.d: Regenerate expected output.
	* ld-arm/armthumb-lib.d: Likewise.
	* ld-arm/armthumb-lib.sym: Likewise.
	* ld-arm/cortex-a8-fix-b-rel-arm.d: Likewise.
	* ld-arm/cortex-a8-fix-b-rel-thumb.d: Likewise.
	* ld-arm/cortex-a8-fix-b.d: Likewise.
	* ld-arm/cortex-a8-fix-bcc-rel-thumb.d: Likewise.
	* ld-arm/cortex-a8-fix-bcc.d: Likewise.
	* ld-arm/cortex-a8-fix-bl-rel-arm.d: Likewise.
	* ld-arm/cortex-a8-fix-bl-rel-plt.d: Likewise.
	* ld-arm/cortex-a8-fix-bl-rel-thumb.d: Likewise.
	* ld-arm/cortex-a8-fix-bl.d: Likewise.
	* ld-arm/cortex-a8-fix-blx-bcond.d: Likewise.
	* ld-arm/cortex-a8-fix-blx-rel-arm.d: Likewise.
	* ld-arm/cortex-a8-fix-blx-rel-thumb.d: Likewise.
	* ld-arm/cortex-a8-fix-blx.d: Likewise.
	* ld-arm/cortex-a8-fix-hdr.d: Likewise.
	* ld-arm/farcall-mixed-app-v5.d: Likewise.
	* ld-arm/farcall-mixed-app.d: Likewise.
	* ld-arm/farcall-mixed-lib-v4t.d: Likewise.
	* ld-arm/farcall-mixed-lib.d: Likewise.
	* ld-arm/mixed-app-v5.d: Likewise.
	* ld-arm/mixed-app.d: Likewise.
	* ld-arm/mixed-lib.d: Likewise.
2015-04-24 15:54:39 +01:00
Nick Clifton 30d72bc335 Skip the compressed1d test for targets which do not use the elf32.em linker emulation file.
* ld-elf/compressed1d.d: Add notarget for ELF based targets that
	do not use elf.em.
2015-04-24 10:15:41 +01:00
Hans-Peter Nilsson 04651c084e Correct ld-elf/compressed1e.d to use notarget and for cris-elf, not cris-*.
Don't XPASS cris-linux which *does* support -shared.
And xfail is for bugs, notarget is for not-applicable.
2015-04-24 06:10:19 +02:00
H.J. Lu 005db9f99b Xfail cris and frv for ld-elf/compressed1e.d
cris and frv don't support -shared.

	* ld-elf/compressed1e.d: Only run for Linux/gnu.  Xfail cris and
	frv.
2015-04-23 18:58:46 -07:00
H.J. Lu 3e19fb8f99 Delay setting up compressed debug section names
When we set up st_name for output section name in elf_fake_sections, we
don't know if the compressed DWARF debug section will be smaller. We may
end up with compressed DWARF debug sections which are bigger than the
uncompressed ones.  This patch delays setting up st_name for output DWARF
debug section to _bfd_elf_assign_file_positions_for_non_load which will
compress the output debug section.  We also postpone placement of shstrtab
section after DWARF debug sections have been compressed.  The net effect
is .shstrtab section is now placed after .symtab and .strtab sections.

bfd/

	PR ld/18277
	* compress.c (bfd_compress_section_contents): Remove the
	write_compress argument.
	(bfd_init_section_compress_status): Updated.
	(bfd_compress_section): Likewise.
	* elf.c (_bfd_elf_set_reloc_sh_name): New.
	(_bfd_elf_init_reloc_shdr): Add delay_st_name_p.  Set sh_name
	to (unsigned int) -1 if delay_st_name_p is TRUE.  Use
	_bfd_elf_set_reloc_sh_name.
	(elf_fake_sections): Don't rename DWARF debug section for
	linker output if it will be compressed.  Instead, set
	delay_st_name_p to TRUE and pass it to _bfd_elf_init_reloc_shdr.
	(assign_section_numbers): Call _bfd_elf_strtab_addref only if
	sh_name != (unsigned int) -1.  Don't finalize nor assign
	shstrtab section here.  Delay setting output section names to
	_bfd_elf_write_object_contents.
	(_bfd_elf_compute_section_file_positions): Update comments on
	sh_offset for shstrtab section.
	(assign_file_positions_for_non_load_sections): Set sh_offset to
	-1 for shstrtab section.
	(assign_file_positions_except_relocs): Likewise.
	(_bfd_elf_assign_file_positions_for_non_load): Set up sh_name
	when compressing DWARF debug sections.  Place shstrtab section
	after DWARF debug sections have been compressed.
	(_bfd_elf_write_object_contents): Setting sh_name for output
	sections.

ld/testsuite/

	PR ld/18277
	* ld-elf/compressed1d.d: New.
	* ld-elf/compressed1e.d: Likewise.
2015-04-23 16:37:56 -07:00
Alan Modra 2ab52ca58f Accept odd result in ld-powerpc/tocnovar testcase
I didn't commit this with the relro and powerpc .TOC. changes,
thinking that something should be done about the odd result of
.shstrtab appearing in PT_GNU_RELRO.  On looking at it further,
I think that changing readelf would be wrong, so let's just
accept the results.  Real binaries will always have other sections
past .got, so PT_GNU_RELRO won't finish past the end of loaded
sections.

	* ld-powerpc/tocnovar.d: Adjust.
2015-04-23 13:28:53 +09:30
Alan Modra a27e685fa0 Align .TOC. for PowerPC64
This change, with prerequisite 0e5fabeb, provides a toc base aligned
to 256 bytes rather than 8 bytes.  This is necessary for a minor gcc
optimisation, allowing use of d-form instructions to correctly access
toc-relative items larger than 8 bytes.

bfd/
	* elf64-ppc.c (TOC_BASE_ALIGN): Define.
	(ppc64_elf_next_toc_section): Align multi-got toc base.
	(ppc64_elf_set_toc): Likewise initial toc base and .TOC. symbol.
ld/
	* emulparams/elf64ppc.sh (GOT): Align.
ld/testsuite/
	* ld-powerpc/ambiguousv1b.d: Update for aligned .got.
	* ld-powerpc/defsym.d: Likewise.
	* ld-powerpc/elfv2-2exe.d: Likewise.
	* ld-powerpc/elfv2exe.d: Likewise.
	* ld-powerpc/elfv2so.d: Likewise.
	* ld-powerpc/relbrlt.d: Likewise.
	* ld-powerpc/tls.g: Likewise.
	* ld-powerpc/tlsexe.d: Likewise.
	* ld-powerpc/tlsexe.g: Likewise.
	* ld-powerpc/tlsexe.r: Likewise.
	* ld-powerpc/tlsexetoc.d: Likewise.
	* ld-powerpc/tlsexetoc.g: Likewise.
	* ld-powerpc/tlsexetoc.r: Likewise.
	* ld-powerpc/tlsso.d: Likewise.
	* ld-powerpc/tlsso.g: Likewise.
	* ld-powerpc/tlsso.r: Likewise.
	* ld-powerpc/tlstoc.g: Likewise.
	* ld-powerpc/tlstocso.d: Likewise.
	* ld-powerpc/tlstocso.g: Likewise.
	* ld-powerpc/tlstocso.r: Likewise.
	* ld-powerpc/tocopt.d: Likewise.
	* ld-powerpc/tocopt2.d: Likewise.
	* ld-powerpc/tocopt3.d: Likewise.
	* ld-powerpc/tocopt4.d: Likewise.
	* ld-powerpc/tocopt5.d: Likewise.
2015-04-23 09:49:19 +09:30
Alan Modra 0e5fabeb2c Rewrite relro adjusting code
The linker tries to put the end of the last section in the relro
segment exactly on a page boundary, because the relro segment itself
must end on a page boundary.  If for any reason this can't be done,
padding is inserted.  Since the end of the relro segment is typically
between .got and .got.plt, padding effectively increases the size of
the GOT.  This isn't nice for targets and code models with limited GOT
addressing.

The problem with the current code is that it doesn't cope very well
with aligned sections in the relro segment.  When making .got aligned
to a 256 byte boundary for PowerPC64, I found that often the initial
alignment attempt failed and the fallback attempt to be less than
adequate.  This is a particular problem for PowerPC64 since the
distance between .got and .plt affects the size of plt call stubs,
leading to "stubs don't match calculated size" errors.

So this rewrite takes a direct approach to calculating a new relro
base.  Starting from the last section in the segment, we calculate
where it must start to position its end on the boundary, or as near as
possible considering alignment requirements.  The new start then
becomes the goal for the previous section to end, and so on for all
sections.  This of course ignores the possibility that user scripts
will place . = ALIGN(xxx); in the relro segment, or provide section
address expressions.  In those cases we might fail, but the old code
probably did too, and a fallback is provided.

ld/
	* ldexp.h (struct ldexp_control): Delete dataseg.min_base.  Add
	data_seg.relro_offset.
	* ldexp.c (fold_binary <DATA_SEGMENT_ALIGN>): Don't set min_base.
	(fold_binary <DATA_SEGMENT_RELRO_END>): Do set relro_offset.
	* ldlang.c (lang_size_sections): Rewrite code adjusting relro
	segment base to line up last section on page boundary.
ld/testsuite/
	* ld-x86-64/pr18176.d: Update.
2015-04-22 23:19:59 +09:30
H.J. Lu d5597ebccc i386: Allow copy relocs for building PIE
This patch allows copy relocs for R_386_GOTOFF relocations in PIE.  For

extern int glob_a;
int foo ()
{
  return glob_a;
}

compiler now can optimize it from

	call	__x86.get_pc_thunk.ax
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
	movl	glob_a@GOT(%eax), %eax
	movl	(%eax), %eax
	ret

to

	call	__x86.get_pc_thunk.ax
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
	movl	glob_a@GOTOFF(%eax), %eax
	ret

bfd/

	PR ld/18289
	* elf32-i386.c (elf_i386_link_hash_entry): Add gotoff_ref.
	(elf_i386_link_hash_newfunc): Initialize gotoff_ref to 0.
	(elf_i386_create_dynamic_sections): Always allow copy relocs for
	building executables.
	(elf_i386_copy_indirect_symbol): Also copy gotoff_ref.
	(elf_i386_check_relocs): Set gotoff_ref for R_386_GOTOFF.
	(elf_i386_adjust_dynamic_symbol): Also allocate copy relocs for
	PIE and R_386_GOTOFF.
	(elf_i386_relocate_section): Allow R_386_GOTOFF in executable.

ld/testsuite/

	PR ld/18289
	* ld-i386/copyreloc-lib.c: New file.
	* ld-i386/copyreloc-main.S: Likewise.
	* ld-i386/copyreloc-main.out: Likewise.
	* ld-i386/copyreloc-main1.rd: Likewise.
	* ld-i386/copyreloc-main2.rd: Likewise.
	* ld-i386/dummy.c: Likewise.
	* ld-i386/pr17689.out: Likewise.
	* ld-i386/pr17689.rd: Likewise.
	* ld-i386/pr17689a.c: Likewise.
	* ld-i386/pr17689b.S: Likewise.
	* ld-i386/pr17827.rd: Likewise.
	* ld-i386/pr17827ver.rd: Likewise.
	* ld-i386/i386.exp: Run copyreloc tests.
2015-04-22 05:30:01 -07:00
H.J. Lu be59ad3d96 Don't hardcode offset of .shstrtab section
There is no requirement on placement of section name section, .shstrtab.
This patch removes hardcoded offsets of .shstrtab sections.

binutils/testsuite/

	* binutils-all/i386/compressed-1b.d: Don't hardcode offset of
	.shstrtab section.
	* binutils-all/i386/compressed-1c.d: Likewise.
	* binutils-all/readelf.s-64: Likewise.
	* binutils-all/x86-64/compressed-1b.d: Likewise.
	* binutils-all/x86-64/compressed-1c.d: Likewise.

gas/testsuite/

	* gas/i386/ilp32/x86-64-unwind.d: Don't hardcode offset of
	.shstrtab section.
	* gas/i386/x86-64-unwind.d: Likewise.
	* gas/ia64/alias-ilp32.d: Likewise.
	* gas/ia64/alias.d: Likewise.
	* gas/ia64/group-1.d: Likewise.
	* gas/ia64/group-2.d: Likewise.
	* gas/ia64/secname-ilp32.d: Likewise.
	* gas/ia64/secname.d: Likewise.
	* gas/ia64/unwind-ilp32.d: Likewise.
	* gas/ia64/unwind.d: Likewise.
	* gas/mmix/bspec-1.d: Likewise.
	* gas/mmix/byte-1.d: Likewise.
	* gas/mmix/loc-1.d: Likewise.
	* gas/mmix/loc-2.d: Likewise.
	* gas/mmix/loc-3.d: Likewise.
	* gas/mmix/loc-4.d: Likewise.
	* gas/mmix/loc-5.d: Likewise.
	* gas/tic6x/scomm-directive-4.d: Likewise.

ld/testsuite/

	* ld-mmix/bspec1.d: Don't hardcode offset of .shstrtab section.
	* ld-mmix/bspec2.d: Likewise.
	* ld-mmix/local1.d: Likewise.
	* ld-mmix/local3.d: Likewise.
	* ld-mmix/local5.d: Likewise.
	* ld-mmix/local7.d: Likewise.
	* ld-mmix/undef-3.d: Likewise.
	* ld-sh/sh64/crangerel1.rd: Likewise.
	* ld-sh/sh64/crangerel2.rd: Likewise.
	* ld-tic6x/common.d: Likewise.
	* ld-tic6x/shlib-1.rd: Likewise.
	* ld-tic6x/shlib-1b.rd: Likewise.
	* ld-tic6x/shlib-1r.rd: Likewise.
	* ld-tic6x/shlib-1rb.rd: Likewise.
	* ld-tic6x/shlib-app-1.rd: Likewise.
	* ld-tic6x/shlib-app-1b.rd: Likewise.
	* ld-tic6x/shlib-app-1r.rd: Likewise.
	* ld-tic6x/shlib-app-1rb.rd: Likewise.
	* ld-tic6x/shlib-noindex.rd: Likewise.
	* ld-tic6x/static-app-1.rd: Likewise.
	* ld-tic6x/static-app-1b.rd: Likewise.
	* ld-tic6x/static-app-1r.rd: Likewise.
	* ld-tic6x/static-app-1rb.rd: Likewise.
	* ld-x86-64/ilp32-4.d: Likewise.
	* ld-x86-64/split-by-file-nacl.rd: Likewise.
	* ld-x86-64/split-by-file.rd: Likewise.
2015-04-20 09:55:47 -07:00
H.J. Lu 0ce398f106 Add --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]
This patch adds --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]
to ld for ELF targets to support generating compressed DWARF debug
sections.  We always generate .zdebug_* section since section names have
been finalized and they can't be changed easily when compression is
being performed.

bfd/

	* bfd-in.h (compressed_debug_section_type): New.
	* compress.c (bfd_compress_section_contents): Add an argument
	for linker write compression and always generate .zdebug_*
	section when linking.
	(bfd_init_section_compress_status): Pass FALSE to
	bfd_compress_section_contents.
	(bfd_compress_section): New function.
	* elf.c (elf_fake_sections): For linking, set SEC_ELF_COMPRESS
	on DWARF debug sections if COMPRESS_DEBUG is set and rename
	section if COMPRESS_DEBUG_GABI_ZLIB isn't set.
	(assign_file_positions_for_non_load_sections): Set sh_offset
	to -1 if SEC_ELF_COMPRESS is set.
	(assign_file_positions_except_relocs): Likwise.
	(_bfd_elf_assign_file_positions_for_relocs): Renamed to ...
	(_bfd_elf_assign_file_positions_for_non_load): This.  Change
	return time to bfd_boolean.  Compress the section if
	SEC_ELF_COMPRESS is set.
	(_bfd_elf_write_object_contents): Updated.
	(_bfd_elf_set_section_contents): Write section contents to
	the buffer if SEC_ELF_COMPRESS is set.
	* merge.c: Include "elf-bfd.h".
	(sec_merge_emit): Add arguments for contents and offset.  Write
	to contents with offset if contents isn't NULL.
	(_bfd_write_merged_section): Write section contents to the
	buffer if SEC_ELF_COMPRESS is set.  Pass contents and
	output_offset to sec_merge_emit.
	* elflink.c (bfd_elf_final_link): Allocate the buffer for
	output section contents if SEC_ELF_COMPRESS is set.
	* section.c (SEC_ELF_COMPRESS): New.
	* bfd-in2.h: Regenerated.

gas/

	* as.h (compressed_debug_section_type): Removed.

include/

	* bfdlink.h (bfd_link_info): Add compress_debug.

ld/

	* ld.texinfo: Document --compress-debug-sections=.
	* ldmain.c (main): Set BFD_COMPRESS on output_bfd if
	COMPRESS_DEBUG is set.  Set BFD_COMPRESS_GABI on output_bfd
	for COMPRESS_DEBUG_GABI_ZLIB.
	* lexsup.c (elf_static_list_options): Add
	--compress-debug-sections=.
	* emultempl/elf32.em (OPTION_COMPRESS_DEBUG): New.
	(xtra_long): Add "compress-debug-sections".
	(gld${EMULATION_NAME}_handle_option): Handle
	OPTION_COMPRESS_DEBUG.

ld/testsuite/

	* ld-elf/compress.exp (build_tests): Add tests for
	--compress-debug-sections=.
	(run_tests): Likewise.
	Add additonal tests for --compress-debug-sections=.
	* ld-elf/gabiend.rt: New file.
	* ld-elf/gabinormal.rt: Likewise.
	* ld-elf/gnubegin.rS: Likewise.
	* ld-elf/gnunormal.rS: Likewise.
	* ld-elf/zlibbegin.rS: Likewise.
	* ld-elf/zlibnormal.rS: Likewise.
2015-04-14 22:01:38 -07:00
Alan Modra ecd272101d xfail pr18223 test for tic6x
Fails due to
warning: generating a shared library containing non-PIC/PID code

	* ld-gc/pr18223.d: xfail tic6x.
2015-04-15 12:01:33 +09:30
H.J. Lu 889c2a6796 Add -z noextern-protected-data to ld for ELF/x86
Address of protected data defined in the shared library may be external,
i.e., due to copy relocation.  By default, linker backend checks if
relocations against protected data symbols are valid for building shared
library and issues an error if relocation isn't allowed.  The new option
override linker backend default.  When -z noextern-protected-data is used,
updates on protected data symbols by another module won't be visibile
to the resulting shared library.  This option is specific to ELF/i386
and ELF/x86-64.

bfd/

	PR ld/pr17709
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Check
	info->extern_protected_data when warning copy relocs against
	protected symbols.
	(_bfd_elf_symbol_refs_local_p): Check info->extern_protected_data
	when checking protected non-function symbols.

include/

	PR ld/pr17709
	* bfdlink.h (bfd_link_info): Add extern_protected_data.

ld/

	PR ld/pr17709
	* ld.texinfo: Document "-z noextern-protected-data".
	* ldmain.c (main): Initialize link_info.extern_protected_data
	to -1.
	* lexsup.c (elf_shlib_list_options): Add
	"-z [no]extern-protected-data".
	* emulparams/elf32_x86_64.sh: Source extern_protected_data.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_i386_be.sh: Likewise.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_i386_vxworks.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Source extern_protected_data.sh.
	(PARSE_AND_LIST_OPTIONS): Renamed to ...
	(PARSE_AND_LIST_OPTIONS_BNDPLT): This.
	(PARSE_AND_LIST_ARGS_CASE_Z): Renamed to ...
	(PARSE_AND_LIST_ARGS_CASE_Z_BNDPLT): This.
	(PARSE_AND_LIST_OPTIONS): Append $PARSE_AND_LIST_OPTIONS_BNDPLT.
	(PARSE_AND_LIST_ARGS_CASE_Z): Append
	$PARSE_AND_LIST_ARGS_CASE_Z_BNDPLT.
	* emulparams/extern_protected_data.sh: New file.

ld/testsuite/

	PR ld/pr17709
	* ld-i386/i386.exp: Run protected6b.
	* ld-i386/protected6b.d: New file.
	* ld-x86-64/protected6b.d: Likewise.
	* ld-x86-64/x86-64.exp:  Run protected6b.
2015-04-14 04:13:11 -07:00