Commit Graph

538 Commits

Author SHA1 Message Date
H.J. Lu dc2be3d2f6 x86: Generate PLT relocations for -z now
This patch partially reverses:

commit 25070364b0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat May 16 07:00:21 2015 -0700

    Don't generate PLT relocations for now binding

to support LD_AUDIT and LD_PROFILE with -z now.  If there is an existing
GOT relocation, it is still used to avoid PLT relocation against the same
function symbol.

bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Partially revert
	commit 25070364b0.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewse.

ld/

	* testsuite/ld-i386/plt-pic2.dd: Updated.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/plt2.rd: Likewise.
	* testsuite/ld-i386/pr17689now.rd: Likewise.
	* testsuite/ld-ifunc/ifunc-16-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/plt2.dd: Likewise.
	* testsuite/ld-x86-64/plt2.rd: Likewise.
	* testsuite/ld-x86-64/pr17689now.rd: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
2017-05-11 07:45:59 -07:00
H.J. Lu dd9e66ee95 Add missing initializer to silence GCC 4.2
Silence GCC 4.2:

elf64-x86-64.c: In function ‘elf_x86_64_get_synthetic_symtab’:
elf64-x86-64.c:6490: warning: missing initializer
elf64-x86-64.c:6490: warning: (near initialization for ‘plts[3].sec’)

	* elf32-i386.c (elf_i386_get_synthetic_symtab): Add missing
	initializer for GCC 4.2.
	* lf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
2017-05-08 13:39:43 -07:00
H.J. Lu f604c2a2a5 i386: Improve PLT generation and synthetic PLT symbols
On i386, the procedure linkage table (PLT) is used to

1. Call external function.
2. Call internal IFUNC function.  The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.

PLT looks like:

PLT0:  push  GOT[1]
       jmp   *GOT[2]
       nop
PLT1:  jmp   *GOT[name1_index]
       push  name1_reloc_index
       jmp   PLT0

GOT is an array of addresses.  Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.

1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.

This patch

1. Remove PLT layout configurations from i386 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to i386
link_hash_table.  Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in i386 setup_gnu_properties, based
on PIC and target selection.  PLT section alignment is also set to PLT
entry size for non-NaCl/VxWorks target.
3. Remove elf_i386_create_dynamic_sections.  create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations.  Instead,
create all i386 specific dynamic sections in i386 setup_gnu_properties,
which initializes elf.dynobj, so that i386 check_relocs can be simplified.
4. Rewrite elf_i386_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.

bfd/

	* elf32-i386.c (PLT_ENTRY_SIZE): Renamed to ...
	(LAZY_PLT_ENTRY_SIZE): This.
	(NON_LAZY_PLT_ENTRY_SIZE): New.
	(elf_i386_plt0_entry): Renamed to ...
	(elf_i386_lazy_plt0_entry): This.
	(elf_i386_plt_entry): Renamed to ...
	(elf_i386_lazy_plt_entry): This.
	(elf_i386_pic_plt0_entry): Renamed to ...
	(elf_i386_pic_lazy_plt0_entry): This.
	(elf_i386_pic_plt_entry): Renamed to ...
	(elf_i386_pic_lazy_plt_entry): This.
	(elf_i386_got_plt_entry): Renamed to ...
	(elf_i386_non_lazy_plt_entry): This.
	(elf_i386_pic_got_plt_entry): Renamed to ...
	(elf_i386_pic_non_lazy_plt_entry): This.
	(elf_i386_eh_frame_plt): Renamed to ...
	(elf_i386_eh_frame_lazy_plt): This.
	(elf_i386_eh_frame_plt_got): Renamed to ...
	(elf_i386_eh_frame_non_lazy_plt): This.
	(elf_i386_plt_layout): Renamed to ...
	(elf_i386_lazy_plt_layout): This.  Remove eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_i386_non_lazy_plt_layout): New.
	(elf_i386_plt_layout): Likewise.
	(elf_i386_non_lazy_plt): Likewise.
	(GET_PLT_ENTRY_SIZE): Removed.
	(elf_i386_plt): Renamed to ...
	(elf_i386_lazy_plt): This.
	(elf_i386_backend_data): Remove plt.  Rename is_vxworks to os.
	(elf_i386_arch_bed): Updated.
	(elf_i386_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
	(elf_i386_create_dynamic_sections): Removed.
	(elf_i386_check_relocs): Don't check elf.dynobj.  Don't call
	_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
	(elf_i386_adjust_dynamic_symbol): Updated.
	(elf_i386_allocate_dynrelocs): Updated.  Pass 0 as PLT header
	size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
	size for PLT0 if there is no PLT0.
	(elf_i386_size_dynamic_sections): Updated.  Check whether GOT
	output section is discarded only if GOT isn't empty.
	(elf_i386_relocate_section): Updated.  Properly get PLT index
	if there is no PLT0.
	(elf_i386_finish_dynamic_symbol): Updated.  Don't fill the
	second and third slots in the PLT entry if there is no PLT0.
	(elf_i386_finish_dynamic_sections): Updated.  Don't fill PLT0
	if there is no PLT0.  Set sh_entsize on the .plt.got section.
	(elf_i386_nacl_plt): Forward declaration.
	(elf_i386_get_plt_sym_val): Removed.
	(elf_i386_get_synthetic_symtab): Rewrite to check PLT sections
	against all dynamic relocations.
	(elf_i386_link_setup_gnu_properties): New function.
	(elf_backend_create_dynamic_sections): Updated.
	(elf_backend_setup_gnu_properties): New.
	(elf_i386_nacl_plt): Updated.
	(elf_i386_nacl_arch_bed): Likewise.
	(elf_i386_vxworks_arch_bed): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Add some -z now tests.
	* testsuite/ld-i386/plt-pic2.dd: New file.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/plt2.rd: Likewise.
	* testsuite/ld-i386/plt2.s: Likewise.
	* testsuite/ld-ifunc/ifunc-16-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-i386/pr20830.d: Update the .plt.got section
	with func@plt.
2017-05-08 10:11:32 -07:00
H.J. Lu 750eaa47f1 x86: Check plt_got before using .plt.got
Since the GOT procedure linkage table is supported only if plt_got
isn't NULL, we need to check plt_got before using it.

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Check plt_got
	before using .plt.got.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2017-04-28 07:26:45 -07:00
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 1f78f649e8 i386: Simplify VxWorks for non-PIC
Change

  if (PIC)
    {
      #1
    }
  else
    {
      #2
      if (VxWorks)
        {
          #3
        }
    }
  #4
  if (VxWorks && !PIC)
    {
      #5
    }

to

  #4
  if (PIC)
    {
      #1
    }
  else
    {
      #2
      if (VxWorks)
        {
          #3
          #5
        }
    }

	* elf32-i386.c (elf_i386_finish_dynamic_sections): Simplify
	VxWorks for non-PIC.
2017-04-27 08:55:36 -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
H.J. Lu 0dc9a308a1 i386: Force symbol dynamic if it isn't undefined weak
Force symbol dynamic if it isn't undefined weak.  Generate R_386_RELATIVE
relocation for R_386_GOT32 relocation against non-dynamic symbol in PIC.

	PR ld/21402
	* elf32-i386.c (elf_i386_allocate_dynrelocs): If a symbol isn't
	undefined weak symbol, don't make it dynamic.
	(elf_i386_relocate_section): If a symbol isn't dynamic in PIC,
	set no_finish_dynamic_symbol and generate R_386_RELATIVE
	relocation for R_386_GOT32.
2017-04-24 13:42:33 -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
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
Alan Modra 63a5468afa Wrap long lines
Not a comprehensive change, just some split out from fixes made for
the %A and %B changes.

	* coffcode.h: Wrap some overly long _bfd_error_handler args.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
2017-04-13 17:07:25 +09:30
Alan Modra c08bb8dd9b Rewrite bfd error handler
This steals _doprnt from libiberty, extended to handle %A and %B.
Which lets us do away with the current horrible %A and %B handling
that requires all %A and %B arguments to be passed first, rather than
in the natural order.

	* bfd.c (PRINT_TYPE): Define.
	(_doprnt): New function.
	(error_handler_internal): Use _doprnt.
	* coff-arm.c: Put %A and %B arguments to _bfd_error_handler
	calls in their natural order, throughout file.
	* coff-mcore.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-tic80.c: Likewise.
	* cofflink.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
2017-04-13 17:07:24 +09:30
H.J. Lu e4097f5ee5 Remove the extra `\n' in warning/error messages
* elf-properties.c (_bfd_elf_parse_gnu_properties): Remove the
	extra `\n' in warning/error messages.
	* elf32-i386.c (elf_i386_parse_gnu_properties): Likewise.
	* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.
2017-04-11 15:41:00 -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
Alan Modra afbf7e8e3a Don't make dynamic .data.rel.ro SEC_READONLY
I'd made this dynamic section read-only so a flag test distinguished
it from .dynbss, but like any other .data.rel.ro section it really
should be marked read-write.  (It is read-only after relocation, not
before.)  When using the standard linker scripts this usually doesn't
matter since the output section is among other read-write sections and
not page aligned.  However, it might matter in the extraordinary case
of the dynamic section being the only .data.rel.ro section with the
output section just happening to be page aligned and a multiple of a
page in size.  In that case the output section would be read-only, and
live it its own read-only PT_LOAD segment, which is incorrect.

	* elflink.c (_bfd_elf_create_dynamic_sections): Don't make
	dynamic .data.rel.ro read-only.
	* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Compare section
	rather than section flags when deciding where copy reloc goes.
	* elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Likewise.
	* elf32-metag.c (elf_metag_finish_dynamic_symbol): Likewise.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Likewise.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_finish_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_finish_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Likewise.
	* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.
2017-02-28 11:59:47 +10:30
H.J. Lu 2a5684011e i386: Allow "lea foo@GOT, %reg" in PIC
"lea foo@GOT, %reg" is OK in PIC since it only loads the GOT offset
into register, which can be used later with a GOT base register to
get the value in the GOT entry.

bfd/

	PR ld/21168
	* elf32-i386.c (elf_i386_relocate_section): Allow
	"lea foo@GOT, %reg" in PIC.

ld/

	PR ld/21168
	* testsuite/ld-i386/i386.exp: Run pr21168.
	* testsuite/ld-i386/pr21168a.c: New file.
	* testsuite/ld-i386/pr21168b.S: Likewise.
2017-02-15 11:39:48 -08:00
H.J. Lu a5def14f1c Add a test for R_386_GOT32/R_386_GOT32X IFUNC reloc error
bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): Properly get IFUNC
	symbol name when reporting R_386_GOT32/R_386_GOT32X relocation
	error against local IFUNC symbol without a base register for
	PIC.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-4a, pr20244-4b and
	pr20244-4c.
	* testsuite/ld-i386/pr20244-4.s: New file.
	* testsuite/ld-i386/pr20244-4a.d: Likewise.
	* testsuite/ld-i386/pr20244-4b.d: Likewise.
	* testsuite/ld-i386/pr20244-4c.d: Likewise.
2017-02-15 11:11:40 -08:00
H.J. Lu 52b232b366 i386/x32: Align .eh_frame section to 4 bytes
.eh_frame section covering PLT sections should be aligned to 4 bytes
for i386 and x32.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Align .eh_frame section
	to 4 bytes.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Align
	.eh_frame section to 4 bytes for x32.
	(elf_x86_64_check_relocs): Likewise.

ld/

	* testsuite/ld-x86-64/pr20830b.d: Updated.
2017-01-10 14:21:21 -08:00
H.J. Lu fff53daefb i386/x86-64: Add unwind info for .plt.got section
When there are both PLT and GOT references to the same function symbol,
linker combines GOTPLT and GOT slots into a single GOT slot and create
an entry in .plt.got section for PLT access via the GOT slot.  This
patch adds unwind info for .plt.got section.

bfd/

	PR ld/20830
	* elf32-i386.c (elf_i386_eh_frame_plt_got): New.
	(PLT_GOT_FDE_LENGTH): Likewise.
	(elf_i386_plt_layout): Add eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_i386_plt): Updated.
	(elf_i386_link_hash_table): Add plt_got_eh_frame.
	(elf_i386_check_relocs): Create .eh_frame section for .plt.got.
	(elf_i386_size_dynamic_sections): Allocate and initialize
	.eh_frame section for .plt.got.
	(elf_i386_finish_dynamic_sections): Adjust .eh_frame section for
	.plt.got.
	(elf_i386_nacl_plt): Add FIXME for eh_frame_plt_got and
	eh_frame_plt_got_size.
	* elf64-x86-64.c (elf_x86_64_eh_frame_plt_got): New.
	(PLT_GOT_FDE_LENGTH): Likewise.
	(elf_x86_64_backend_data): Add eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_x86_64_arch_bed): Updated.
	(elf_x86_64_bnd_arch_bed): Add FIXME for eh_frame_plt_got and
	eh_frame_plt_got_size.
	(elf_x86_64_nacl_arch_bed): Likewise.
	(elf_x86_64_link_hash_table): Add plt_got_eh_frame.
	(elf_x86_64_check_relocs): Create .eh_frame section for .plt.got.
	(elf_x86_64_size_dynamic_sections): Allocate and initialize
	.eh_frame section for .plt.got.
	(elf_x86_64_finish_dynamic_sections): Adjust .eh_frame section
	for .plt.got.

ld/

	PR ld/20830
	* testsuite/ld-i386/i386.exp: Run pr20830.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr20830.d: New file.
	* testsuite/ld-i386/pr20830.s: Likewise.
	* testsuite/ld-x86-64/pr20830.d: Likewise.
	* testsuite/ld-x86-64/pr20830.s: Likewise.
2017-01-10 13:31:59 -08:00
H.J. Lu f129e49f4d Don't use elf_i386_eh_frame_plt directly
Use eh_frame_plt_size and eh_frame_plt from elf_i386_plt_layout for
.eh_frame covering the .plt section.

	* elf32-i386.c (elf_i386_size_dynamic_sections): Set
	plt_eh_frame->size to eh_frame_plt_size and use eh_frame_plt.
2017-01-10 11:30:25 -08:00
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra e81830c5c6 link_hash_copy_indirect and symbol flags
A while ago HJ fixed PR ld/18720 with commit 6e33951ed, which, among
other things, modified _bfd_elf_link_hash_copy_indirect to not copy
ref_dynamic, ref_regular, ref_regular_nonweak, non_got_ref, needs_plt
and pointer_equality_needed when setting up an indirect non-versioned
symbol pointing to a non-default versioned symbol.  I didn't notice at
the time, but the pr18720 testcase fails on hppa-linux with
"internal error, aborting at binutils-gdb-2.28/bfd/elf32-hppa.c:3933
in elf32_hppa_relocate_section".

Now hppa-linux creates entries in the plt even for local functions, if
they are referenced using plabel (function pointer) relocations.   So
needs_plt is set for foo when processing pr18720a.o.  When the aliases
in pr28720b.o are processed, we get an indirection from foo to
foo@FOO, but don't copy needs_plt.  Since foo@FOO is the "real" symbol
that is used after that point, no plt entry is made for foo and we
bomb when relocating the plabel.

As shown by the hppa-linux scenario, needs_plt should be copied even
for non-default versioned symbols.  I believe all of the others ought
to be copied too, with the exception of ref_dynamic.  Not copying
ref_dynamic is right because if a shared lib references "foo" it
should not be satisfied by any non-default version "foo@FOO".

	* elflink.c (_bfd_elf_link_hash_copy_indirect): Only omit
	copying one flag, ref_dynamic, when versioned_hidden.
	* elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Use same
	logic for copying weakdef flags.  Copy plabel flag and merge
	tls_type.
	* elf32-i386.c (elf_i386_copy_indirect_symbol): Use same logic
	for copying weakdef flags.
	* elf32-ppc.c (ppc_elf_copy_indirect_symbol): Likewise.
	* elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
	* elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
	* elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
	* elfnn-ia64.c (elfNN_ia64_hash_copy_indirect): Likewise.
	* elf64-x86-64.c (elf_x86_64_copy_indirect_symbol): Likewise.
	Simplify.
2016-12-29 23:56:54 +10:30
Alan Modra 5474d94f03 dynrelro section for read-only dynamic symbols copied into executable
Variables defined in shared libraries are copied into an executable's
.bss section when code in the executable is non-PIC and thus would
require dynamic text relocations to access the variable directly in
the shared library.  Recent x86 toolchains also copy variables into
the executable to gain a small speed improvement.

The problem is that if the variable was originally read-only, the copy
in .bss is writable, potentially opening a security hole.  This patch
cures that problem by putting the copy in a section that becomes
read-only after ld.so relocation, provided -z relro is in force.

The patch also fixes a microblaze linker segfault on attempting to
use dynamic bss variables.

bfd/
	PR ld/20995
	* elf-bfd.h (struct elf_link_hash_table): Add sdynrelro and
	sreldynrelro.
	(struct elf_backend_data): Add want_dynrelro.
	* elfxx-target.h (elf_backend_want_dynrelro): Define.
	(elfNN_bed): Update initializer.
	* elflink.c (_bfd_elf_create_dynamic_sections): Create
	sdynrelro and sreldynrelro sections.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Place variables
	copied into the executable from read-only sections into sdynrelro.
	(elf32_arm_size_dynamic_sections): Handle sdynrelro.
	(elf32_arm_finish_dynamic_symbol): Select sreldynrelro for
	dynamic relocs in sdynrelro.
	(elf_backend_want_dynrelro): Define.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol)
	(elf32_hppa_size_dynamic_sections, elf32_hppa_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol)
	(elf_i386_size_dynamic_sections, elf_i386_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-metag.c (elf_metag_adjust_dynamic_symbol)
	(elf_metag_size_dynamic_sections, elf_metag_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol)
	(microblaze_elf_size_dynamic_sections)
	(microblaze_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol)
	(nios2_elf32_adjust_dynamic_symbol)
	(nios2_elf32_size_dynamic_sections)
	(elf_backend_want_dynrelro): As above.
	* elf32-or1k.c (or1k_elf_finish_dynamic_symbol)
	(or1k_elf_adjust_dynamic_symbol, or1k_elf_size_dynamic_sections)
	(elf_backend_want_dynrelro): As above.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol)
	(ppc_elf_size_dynamic_sections, ppc_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol)
	(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol)
	(elf32_tic6x_size_dynamic_sections)
	(elf32_tic6x_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol)
	(tilepro_elf_size_dynamic_sections)
	(tilepro_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol)
	(ppc64_elf_size_dynamic_sections, ppc64_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol)
	(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol)
	(elf_x86_64_size_dynamic_sections)
	(elf_x86_64_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol)
	(elfNN_aarch64_size_dynamic_sections)
	(elfNN_aarch64_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfnn-riscv.c (riscv_elf_adjust_dynamic_symbol)
	(riscv_elf_size_dynamic_sections, riscv_elf_finish_dynamic_symbol)
	(elf_backend_want_dynrelro): As above.
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol)
	(_bfd_mips_elf_size_dynamic_sections)
	(_bfd_mips_vxworks_finish_dynamic_symbol): As above.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol)
	(_bfd_sparc_elf_size_dynamic_sections)
	(_bfd_sparc_elf_finish_dynamic_symbol): As above.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol)
	(tilegx_elf_size_dynamic_sections)
	(tilegx_elf_finish_dynamic_symbol): As above.
	* elf32-mips.c (elf_backend_want_dynrelro): Define.
	* elf64-mips.c (elf_backend_want_dynrelro): Define.
	* elf32-sparc.c (elf_backend_want_dynrelro): Define.
	* elf64-sparc.c (elf_backend_want_dynrelro): Define.
	* elf32-tilegx.c (elf_backend_want_dynrelro): Define.
	* elf64-tilegx.c (elf_backend_want_dynrelro): Define.
	* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol): Tidy.
	(microblaze_elf_size_dynamic_sections): Handle sdynbss.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Make use
	of linker shortcuts to dynamic sections rather than comparing
	names.  Correctly set "got" flag.
ld/
	PR ld/20995
	* testsuite/ld-arm/farcall-mixed-app-v5.d: Update to suit changed
	stub hash table traversal caused by section id increment.  Accept
	the previous output too.
	* testsuite/ld-arm/farcall-mixed-app.d: Likewise.
	* testsuite/ld-arm/farcall-mixed-lib-v4t.d: Likewise.
	* testsuite/ld-arm/farcall-mixed-lib.d: Likewise.
	* testsuite/ld-elf/pr20995a.s, * testsuite/ld-elf/pr20995b.s,
	* testsuite/ld-elf/pr20995.r: New test.
	* testsuite/ld-elf/elf.exp: Run it.
2016-12-26 13:47:51 +10:30
Alan Modra 9d19e4fdb7 Put .dynbss and .rel.bss shortcuts in main elf hash table
Also, create .rel{,a}.bss for PIEs on all targets, not just x86.

	* elf-bfd.h (struct elf_link_hash_table): Add sdynbss and srelbss.
	* elflink.c (_bfd_elf_create_dynamic_sections): Set them.  Create
	.rel.bss/.rela.bss for executables, both PIE and non-PIE.
	* elf32-arc.c (struct elf_arc_link_hash_table): Delete srelbss.
	Use ELF hash table var throughout.
	* elf32-arm.c (struct elf32_arm_link_hash_table): Delete sdynbss
	and srelbss.  Use ELF hash table vars throughout.
	* elf32-hppa.c (struct elf32_hppa_link_hash_table): Likewise.
	* elf32-i386.c (struct elf_i386_link_hash_table): Likewise.
	* elf32-metag.c (struct elf_metag_link_hash_table): Likewise.
	* elf32-microblaze.c (struct elf32_mb_link_hash_table): Likewise.
	* elf32-nios2.c (struct elf32_nios2_link_hash_table): Likewise.
	* elf32-or1k.c (struct elf_or1k_link_hash_table): Likewise.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Likewise.
	* elf32-s390.c (struct elf_s390_link_hash_table): Likewise.
	* elf32-tic6x.c (struct elf32_tic6x_link_hash_table): Likewise.
	* elf32-tilepro.c (struct tilepro_elf_link_hash_table): Likewise.
	* elf64-ppc.c (struct ppc_link_hash_table): Likewise.
	* elf64-s390.c (struct elf_s390_link_hash_table): Likewise.
	* elf64-x86-64.c (struct elf_x86_64_link_hash_table): Likewise.
	* elfnn-aarch64.c (struct elf_aarch64_link_hash_table): Likewise.
	* elfnn-riscv.c (struct riscv_elf_link_hash_table): Likewise.
	* elfxx-mips.c (struct mips_elf_link_hash_table): Likewise.
	* elfxx-sparc.h (struct _bfd_sparc_elf_link_hash_table): Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c (struct tilegx_elf_link_hash_table): Likewise.

	* elf32-arc.c (arc_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-microblaze.c (microblaze_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-or1k.c (or1k_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf32-s390.c (elf_s390_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf64-ppc.c (ppc64_elf_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.
	* elf64-s390.c (elf_s390_create_dynamic_sections): Delete.
	(elf_backend_create_dynamic_sections): Use base ELF version.

	* elf32-tilepro.c (tilepro_elf_create_dynamic_sections): Remove
	extraneous tests.
	* elfnn-aarch64.c (elfNN_aarch64_create_dynamic_sections): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_create_dynamic_sections): Likewise.
	* elfxx-tilegx.c (tilegx_elf_create_dynamic_sections): Likewise.

	* elf32-i386.c (elf_i386_create_dynamic_sections): Don't create
	".rel.bss" for executables.
	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Don't create
	".rela.bss" for executables.
	* elf32-nios2.c (nios2_elf32_create_dynamic_sections): Don't
	ignore return status from _bfd_elf_create_dynamic_sections.
2016-12-26 13:42:20 +10:30
Alan Modra 64f52338e9 elf_backend_dtrel_excludes_plt
Now that all targets creating .rel.plt/.rela.plt use the ELF hash
table shortcut srelplt, the generic ELF code can set up DT_RELSZ/
DT_RELASZ and DT_REL/DT_RELA for targets that don't want PLT relocs
included in those tags.

	* elf-bfd.h (struct elf_backend_data): Add dtrel_excludes_plt.
	* elfxx-target.h (elf_backend_dtrel_excludes_plt): Define.
	(elfNN_bed): Init new field.
	* elflink.c (bfd_elf_final_link): Add and use htab variable.  Handle
	dtrel_excludes_plt.
	* elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-arc.c (elf_arc_finish_dynamic_sections): Delete DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-arm.c (elf32_arm_finish_dynamic_sections): Delete code
	subtracting off plt relocs from DT_RELSZ, DT_RELASZ.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-cris.c (elf_cris_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-i386.c (elf_i386_finish_dynamic_sections): Delete DT_RELSZ
	and DT_REL code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-lm32.c (lm32_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-m32r.c (m32r_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-m68k.c (elf_m68k_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-metag.c (elf_metag_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Delete
	DT_RELASZ and DT_RELA code.  Use ELF htab shortcuts for other
	dynamic sections.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-mips.c (elf_backend_dtrel_excludes_plt): Define.
	* elf32-nds32.c (nds32_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-or1k.c (or1k_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-ppc.c (ppc_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-sh.c (sh_elf_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-sparc.c (elf_backend_dtrel_excludes_plt): Define.
	* elf32-vax.c (elf_vax_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Delete DT_RELASZ
	and DT_RELA code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Delete
	DT_RELASZ code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfnn-ia64.c (elfNN_ia64_finish_dynamic_sections): Delete DT_RELASZ
	code.
	(elf_backend_dtrel_excludes_plt): Define.
	* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Delete
	DT_RELASZ code.
	* elfxx-sparc.c (sparc_finish_dyn): Delete DT_RELASZ code.
2016-11-23 15:43:25 +10:30
Nick Clifton 695344c018 Add c-format tags to translatable strings with more than one argument-using formatting token.
* aout-adobe.c: Add missing c-format tags for translatable strings.
	* aout-cris.c: Likewise.
	* aoutx.h: Likewise.
	* bfd.c: Likewise.
	* binary.c: Likewise.
	* cache.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-i860.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic4x.c: Likewise.
	* coff-tic54x.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* coffcode.h: Likewise.
	* coffgen.c: Likewise.
	* cofflink.c: Likewise.
	* coffswap.h: Likewise.
	* cpu-arm.c: Likewise.
	* dwarf2.c: Likewise.
	* ecoff.c: Likewise.
	* elf-attrs.c: Likewise.
	* elf-eh-frame.c: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-d30v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-gen.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i960.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc11.c: Likewise.
	* elf32-m68hc12.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mcore.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-pj.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh-symbian.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-xgate.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-gen.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfcode.h: Likewise.
	* elfcore.h: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* ieee.c: Likewise.
	* ihex.c: Likewise.
	* libbfd.c: Likewise.
	* linker.c: Likewise.
	* m68klinux.c: Likewise.
	* mach-o.c: Likewise.
	* merge.c: Likewise.
	* mmo.c: Likewise.
	* oasys.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* peXXigen.c: Likewise.
	* pei-x86_64.c: Likewise.
	* peicode.h: Likewise.
	* ppcboot.c: Likewise.
	* reloc.c: Likewise.
	* sparclinux.c: Likewise.
	* srec.c: Likewise.
	* stabs.c: Likewise.
	* vms-alpha.c: Likewise.
	* vms-lib.c: Likewise.
	* xcofflink.c: Likewise.
2016-10-19 14:37:21 +01:00
Alan Modra 1a0670f374 -Wimplicit-fallthrough warning fixes
Comment changes.

bfd/
	* coff-h8300.c: Spell fall through comments consistently.
	* coffgen.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elfxx-aarch64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* cpu-ns32k.c: Add missing fall through comments.
	* elf-m10300.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-rx.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* ieee.c: Likewise.
	* oasys.c: Likewise.
	* pdp11.c: Likewise.
	* srec.c: Likewise.
	* versados.c: Likewise.
opcodes/
	* aarch64-opc.c: Spell fall through comments consistently.
	* i386-dis.c: Likewise.
	* aarch64-dis.c: Add missing fall through comments.
	* aarch64-opc.c: Likewise.
	* arc-dis.c: Likewise.
	* arm-dis.c: Likewise.
	* i386-dis.c: Likewise.
	* m68k-dis.c: Likewise.
	* mep-asm.c: Likewise.
	* ns32k-dis.c: Likewise.
	* sh-dis.c: Likewise.
	* tic4x-dis.c: Likewise.
	* tic6x-dis.c: Likewise.
	* vax-dis.c: Likewise.
binutils/
	* dlltool.c: Spell fall through comments consistently.
	* objcopy.c: Likewise.
	* readelf.c: Likewise.
	* dwarf.c: Add missing fall through comments.
	* elfcomm.c: Likewise.
	* sysinfo.y: Likewise.
	* readelf.c: Likewise.  Also remove extraneous comments.
gas/
	* app.c: Add missing fall through comments.
	* dw2gencfi.c: Likewise.
	* expr.c: Likewise.
	* config/tc-alpha.c: Likewise.
	* config/tc-arc.c: Likewise.
	* config/tc-arm.c: Likewise.
	* config/tc-cr16.c: Likewise.
	* config/tc-crx.c: Likewise.
	* config/tc-dlx.c: Likewise.
	* config/tc-h8300.c: Likewise.
	* config/tc-hppa.c: Likewise.
	* config/tc-i370.c: Likewise.
	* config/tc-i386.c: Likewise.
	* config/tc-i960.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-m68hc11.c: Likewise.
	* config/tc-m68k.c: Likewise.
	* config/tc-mep.c: Likewise.
	* config/tc-metag.c: Likewise.
	* config/tc-microblaze.c: Likewise.
	* config/tc-mips.c: Likewise.
	* config/tc-ns32k.c: Likewise.
	* config/tc-rx.c: Likewise.
	* config/tc-score.c: Likewise.
	* config/tc-score7.c: Likewise.
	* config/tc-sh.c: Likewise.
	* config/tc-tic4x.c: Likewise.
	* config/tc-vax.c: Likewise.
	* config/tc-xstormy16.c: Likewise.
	* config/tc-z80.c: Likewise.
	* config/tc-z8k.c: Likewise.
	* config/obj-elf.c: Likewise.
	* config/tc-i386.c: Likewise.
	* depend.c: Spell fall through comments consistently.
	* config/tc-arm.c: Likewise.
	* config/tc-d10v.c: Likewise.
	* config/tc-i960.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-m68k.c: Likewise.
	* config/tc-mcore.c: Likewise.
	* config/tc-mep.c: Likewise.
	* config/tc-ns32k.c: Likewise.
	* config/tc-visium.c: Likewise.
	* config/tc-xstormy16.c: Likewise.
	* config/tc-z8k.c: Likewise.
gprof/
	* gprof.c: Add missing fall through comments.
ld/
	* lexsup.c: Spell fall through comments consistently and add
	missing fall through comments.
2016-10-06 10:13:15 +10:30
Alan Modra 4eca02287c Remove syntactic sugar
Now that _bfd_error_handler is not a function pointer.

	* aout-adobe.c: Replace (*_bfd_error_handler) (...) with
	_bfd_error_handler (...) throughout.
	* aout-cris.c, * aoutx.h, * archive.c, * bfd.c, * binary.c,
	* cache.c, * coff-alpha.c, * coff-arm.c, * coff-h8300.c,
	* coff-i860.c, * coff-mcore.c, * coff-ppc.c, * coff-rs6000.c,
	* coff-sh.c, * coff-tic4x.c, * coff-tic54x.c, * coff-tic80.c,
	* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* coffswap.h, * cpu-arm.c, * cpu-m68k.c, * cpu-sh.c, * dwarf2.c,
	* ecoff.c, * elf-eh-frame.c, * elf-m10300.c, * elf.c, * elf32-arc.c,
	* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cris.c, * elf32-crx.c, * elf32-dlx.c, * elf32-frv.c,
	* elf32-hppa.c, * elf32-i370.c, * elf32-i386.c, * elf32-lm32.c,
	* elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c,
	* elf32-mcore.c, * elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
	* elf32-mips.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-or1k.c,
	* elf32-pj.c, * elf32-ppc.c, * elf32-rl78.c, * elf32-s390.c,
	* elf32-score.c, * elf32-score7.c, * elf32-sh.c, * elf32-sh64.c,
	* elf32-sparc.c, * elf32-spu.c, * elf32-tic6x.c, * elf32-tilepro.c,
	* elf32-v850.c, * elf32-vax.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sh64.c, * elf64-sparc.c,
	* elf64-x86-64.c, * elfcode.h, * elfcore.h, * elflink.c,
	* elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-mips.c,
	* elfxx-sparc.c, * elfxx-tilegx.c, * hpux-core.c, * i386linux.c,
	* ieee.c, * ihex.c, * libbfd.c, * linker.c, * m68klinux.c,
	* mach-o.c, * merge.c, * mmo.c, * oasys.c, * osf-core.c, * pdp11.c,
	* pe-mips.c, * peXXigen.c, * pef.c, * plugin.c, * reloc.c,
	* rs6000-core.c, * sco5-core.c, * som.c, * sparclinux.c, * srec.c,
	* stabs.c, * syms.c, * vms-alpha.c, * vms-lib.c, * vms-misc.c,
	* xcofflink.c: Likewise.
2016-09-30 15:17:44 +09:30
H.J. Lu 74437ea28f i386: Issue an error on non-PIC call to IFUNC in PIC object
On i386, IFUNC function must be called via PLT.  Since PLT in PIC
object uses EBX register, R_386_PLT32 relocation must be used to
call IFUNC function even when IFUNC function is defined locally.
Linker should issue an error when R_386_PC32 relocation is used
to call IFUNC function.

Since PR ld/19784 tests doesn't use PLT relocation to local IFUNC
function, they are moved to the x86-64 test directory.

bfd/

	PR ld/14961
	PR ld/20515
	* elf32-i386.c (elf_i386_check_relocs): Issue an error when
	R_386_PC32 relocation is used to call IFUNC function in PIC
	object.

ld/

	PR ld/14961
	PR ld/20515
	* testsuite/ld-i386/i386.exp: Run pr20515.
	* testsuite/ld-i386/pr20515.d: New file.
	* testsuite/ld-i386/pr20515.s: Likewise.
	* testsuite/ld-ifunc/ifunc-14a.s: Use R_386_PLT32 to call IFUNC
	function.
	* testsuite/ld-ifunc/ifunc-14c.s: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386.s: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Move PR ld/19784 tests to ...
	* testsuite/ld-x86-64/x86-64.exp: Here.
	* testsuite/ld-ifunc/pr19784a.c: Moved to ...
	* testsuite/ld-x86-64/pr19784a.c: Here.
	* testsuite/ld-ifunc/pr19784b.c: Moved to ...
	* testsuite/ld-x86-64/pr19784b.c: Here.
	* testsuite/ld-ifunc/pr19784c.c: Moved to ...
	* testsuite/ld-x86-64/pr19784c.c: Here.
2016-08-29 08:14:45 -07:00
H.J. Lu 233cc9c13a Don't generate PLT for IFUNC GOT/pointer reference
If a backend supports it, PLT entry isn't needed when all references
to a STT_GNU_IFUNC symbols are done via GOT or static function pointers.
For GOT entries, We generate dynamic R_*_GLOB_DAT relocations for
preemptable symbols and R_*_IRELATIVE relocations for non-preemptable
symbols to update them with real function address.  For static pointer
pointers, we generate dynamic pointer relocations and store them in:

1. .rel[a].ifunc section in PIC object.
2. .rel[a].got section in dynamic executable.
3. .rel[a].iplt section in static executable.

We don't allocate GOT entry if it isn't used.

bfd/

	PR ld/20253
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add an
	bfd_boolean argument.
	* elf-ifunc.c (_bfd_elf_create_ifunc_sections): Replace
	"shared object" with "PIC object" in comments.
	(_bfd_elf_allocate_ifunc_dyn_relocs): Updated.  Replace
	"shared object" with "PIC object" in comments.  Avoid PLT if
	requested.  Generate dynamic relocations for non-GOT references.
	Make room for the special first entry in PLT and allocate PLT
	entry only for PLT and PC-relative references.  Store dynamic
	GOT relocations in .rel[a].iplt section for static executables.
	If PLT isn't used, always use GOT for symbol value.  Don't
	allocate GOT entry if it isn't used.
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_i386_adjust_dynamic_symbol): Increment PLT reference count
	only for PC-relative references.
	(elf_i386_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_i386_relocate_section): Allow R_386_GOT32/R_386_GOT32X
	relocations against STT_GNU_IFUNC symbols without PLT.  Generate
	dynamic pointer relocation against STT_GNU_IFUNC symbol in
	the non-code section and store it in the proper REL section.
	Don't allow non-pointer relocation against STT_GNU_IFUNC symbol
	without PLT.
	(elf_i386_finish_dynamic_symbol): Generate dynamic
	R_386_IRELATIVE and R_386_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_i386_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_i386_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elf32-x86-64.c (elf_i386_check_relocs): Increment PLT reference
	count only in the code section.  Allocate dynamic pointer
	relocation against STT_GNU_IFUNC symbol in the non-code section.
	(elf_x86_64_adjust_dynamic_symbol): Increment PLT reference
	count only for PC-relative references.
	(elf_x86_64_allocate_dynrelocs): Pass TRUE to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	(elf_x86_64_relocate_section): Allow R_X86_64_GOTPCREL,
	R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX and
	R_X86_64_GOTPCREL64 relocations against STT_GNU_IFUNC symbols
	without PLT.  Generate dynamic pointer relocation against
	STT_GNU_IFUNC symbol in the non-code section and store it in
	the proper RELA section.  Don't allow non-pointer relocation
	against STT_GNU_IFUNC symbol without PLT.
	(elf_x86_64_finish_dynamic_symbol): Generate dynamic
	R_X86_64_IRELATIVE and R_X86_64_GLOB_DAT GOT relocations against
	STT_GNU_IFUNC symbols without PLT.
	(elf_x86_64_finish_dynamic_sections): Don't handle local
	STT_GNU_IFUNC symbols here.
	(elf_x86_64_output_arch_local_syms): Handle local STT_GNU_IFUNC
	symbols here.
	(elf_backend_output_arch_local_syms): New.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Pass FALSE to _bfd_elf_allocate_ifunc_dyn_relocs.

ld/

	PR ld/20253
	* testsuite/ld-i386/i386.exp: Run PR ld/20253 tests.
	* testsuite/ld-i386/no-plt.exp: Likewise.
	* testsuite/ld-x86-64/no-plt.exp: Likewise.
	* testsuite/ld-i386/pr13302.d: Remove .rel.plt section.
	* testsuite/ld-ifunc/ifunc-13-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-13-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-15-x86-64.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-5b.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6a.d: Likewise.
	* testsuite/ld-x86-64/pr13082-6b.d: Likewise.
	* testsuite/ld-i386/pr20244-2a.d: Remove .plt section.
	* testsuite/ld-ifunc/ifunc-21-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-i386/pr20244-2b.d: Updated.
	* testsuite/ld-i386/pr20244-2c.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-i386/pr20253-1a.c: New file.
	* testsuite/ld-i386/pr20253-1b.S: Likewise.
	* testsuite/ld-i386/pr20253-1c.S: Likewise.
	* testsuite/ld-i386/pr20253-1d.S: Likewise.
	* testsuite/ld-i386/pr20253-2a.c: Likewise.
	* testsuite/ld-i386/pr20253-2b.S: Likewise.
	* testsuite/ld-i386/pr20253-2c.S: Likewise.
	* testsuite/ld-i386/pr20253-2d.S: Likewise.
	* testsuite/ld-i386/pr20253-3.d: Likewise.
	* testsuite/ld-i386/pr20253-3.s: Likewise.
	* testsuite/ld-i386/pr20253-4.s: Likewise.
	* testsuite/ld-i386/pr20253-4a.d: Likewise.
	* testsuite/ld-i386/pr20253-4b.d: Likewise.
	* testsuite/ld-i386/pr20253-4c.d: Likewise.
	* testsuite/ld-i386/pr20253-5.d: Likewise.
	* testsuite/ld-i386/pr20253-5.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-23a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-23c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-24c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25-x86.s: Likewise.
	* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25b-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-25c-x86.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1.s: Likewise.
	* testsuite/ld-x86-64/pr20253-1a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1g.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1i.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1k.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
	* testsuite/ld-x86-64/pr20253-2a.c: Likewise.
	* testsuite/ld-x86-64/pr20253-2b.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2c.S: Likewise.
	* testsuite/ld-x86-64/pr20253-2d.S: Likewise.
	* testsuite/ld-x86-64/pr20253-3.d: Likewise.
	* testsuite/ld-x86-64/pr20253-3.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4.s: Likewise.
	* testsuite/ld-x86-64/pr20253-4a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4b.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4c.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4e.d: Likewise.
	* testsuite/ld-x86-64/pr20253-4f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5.s: Likewise.
	* testsuite/ld-x86-64/pr20253-5a.d: Likewise.
	* testsuite/ld-x86-64/pr20253-5b.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a-i386.d: Remove extra IRELATIVE
	relocation.
	* testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-18a.s: Fix a typo.
	* testsuite/ld-x86-64/x86-64.exp: Run pr20253-1 tests.
2016-06-18 09:17:25 -07:00
H.J. Lu bf52d7c720 Don't check undefined symbol for IFUNC reloc
Since x86 elf_*_check_relocs is called after all symbols have been
resolved, there is no need to check undefined symbols for relocations
against IFUNC symbols.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Don't check undefined
	symbols for relocations against IFUNC symbols.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/

	* testsuite/ld-i386/i386.exp: Run pr19636-2e-nacl.
	* testsuite/ld-i386/pr19636-2e.d: Skip for NaCl targets.
	Remove .rel.plt section.
	* testsuite/ld-i386/pr19636-2e-nacl.d: New file.
2016-06-16 11:28:29 -07:00
H.J. Lu 081b1afe5a Skip relocations in non-loaded, non-alloced sections
Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

	* elf32-i386.c (elf_i386_check_relocs): Skip relocations in
	non-loaded, non-alloced sections.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2016-06-16 05:52:34 -07:00
H.J. Lu 4c23f2ffa8 Check SEC_ALLOC before allocating dynamic relocation
* elf32-i386.c (elf_i386_check_relocs): Check SEC_ALLOC before
	allocating dynamic relocation.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2016-06-15 18:42:56 -07:00
H.J. Lu c428ce9d90 Check R_*_IRELATIVE in x86 reloc_type_class
elf_{i386|x86_64}_reloc_type_class should return reloc_class_ifunc for
R_386_IRELATIVE/R_X86_64_IRELATIVE relocations.  There is no need to
check symbol type for STN_UNDEF symbol index.

	* elf32-i386.c (elf_i386_reloc_type_class): Check R_386_IRELATIVE.
	Don't check symbol type for STN_UNDEF symbol index.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Check
	R_X86_64_IRELATIVE.  Don't check symbol type for STN_UNDEF symbol
	index.
2016-06-14 10:18:26 -07:00
H.J. Lu 712ec27916 Add the GOT base for GOT32 relocs against IFUNC
Add the GOT base for R_386_GOT32/R_386_GOT32X relocations against IFUNC
symbols if there is no base register and disallow them for PIC.

bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): Add the .got.plt
	section address for R_386_GOT32/R_386_GOT32X relocations against
	IFUNC symbols if there is no base register and return error for
	PIC.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-2a, pr20244-2b,
	pr20244-2c and pr20244-2d.
	* testsuite/ld-i386/no-plt.exp: Run pr20244-3a and pr20244-3b.
	* testsuite/ld-i386/pr20244-2.s: New file.
	* testsuite/ld-i386/pr20244-2a.d: Likewise.
	* testsuite/ld-i386/pr20244-2b.d: Likewise.
	* testsuite/ld-i386/pr20244-2c.d: Likewise.
	* testsuite/ld-i386/pr20244-2d.d: Likewise.
	* testsuite/ld-i386/pr20244-3a.c: Likewise.
	* testsuite/ld-i386/pr20244-3b.S: Likewise.
	* testsuite/ld-i386/pr20244-3c.S: Likewise.
	* testsuite/ld-i386/pr20244-3d.S: Likewise.
2016-06-13 11:11:23 -07:00
H.J. Lu ca8c86efe7 Add 2 i386 tests to call IFUNC functions via GOT
bfd/

	* elf32-i386.c (elf_i386_relocate_section): Simplify IFUNC
	GOT32 adjustment for static executables.

ld/

2016-06-13  H.J. Lu  <hongjiu.lu@intel.com>

	* testsuite/ld-i386/i386.exp: Run ifunc-1a and ifunc-1b.
	* testsuite/ld-i386/ifunc-1a.c: New file.
	* testsuite/ld-i386/ifunc-1b.S: Likewise.
	* testsuite/ld-i386/ifunc-1c.S: Likewise.
	* testsuite/ld-i386/ifunc-1d.S: Likewise.
2016-06-13 09:27:12 -07:00
H.J. Lu 74d7f0aa5b Subtract GOT base only with a base register
When relocating R_386_GOT32 in "op $0, bar@GOT", we shouldn't subtract
GOT base without a base register and we should disallow it without a
base register for PIC.

bfd/

	PR ld/20244
	* elf32-i386.c (elf_i386_relocate_section): When relocating
	R_386_GOT32, return error without a base register for PIC and
	subtract the .got.plt section address only with a base register.

ld/

	PR ld/20244
	* testsuite/ld-i386/i386.exp: Run pr20244-1a and pr20244-1b.
	* testsuite/ld-i386/pr20244-1.s: New file.
	* testsuite/ld-i386/pr20244-1a.d: Likewise.
	* testsuite/ld-i386/pr20244-1b.d: Likewise.
	* testsuite/ld-i386/pr20244-1c.d: Likewise.
2016-06-11 21:24:01 -07:00
H.J. Lu 6eaa7fb59b Support i386 TLS code sequences without PLT
We can generate i386 TLS code sequences for general and local dynamic
models without PLT, which uses indirect call via GOT:

call *___tls_get_addr@GOT(%reg)

where EBX register isn't required as GOT base, instead of direct call:

call ___tls_get_addr[@PLT]

which requires EBX register as GOT base.

Since direct call is 4-byte long and indirect call, is 5-byte long, the
extra one byte must be handled properly.

For general dynamic model, 7-byte lea instruction before call instruction
is replaced by 6-byte one to make room for indirect call.  For local
dynamic model, we simply use 5-byte indirect call.

TLS linker optimization is updated to recognize new instruction patterns.
For local dynamic model to local exec model transition, we generate
a 6-byte lea instruction as nop, instead of a 1-byte nop plus a 4-byte
lea instruction.  Since linker may convert

call ___tls_get_addr[@PLT]

to

addr32 call ____tls_get_addr

when producing static executable, both patterns are recognized.

bfd/

	* elf64-i386.c (elf_i386_link_hash_entry): Add tls_get_addr.
	(elf_i386_link_hash_newfunc): Initialize tls_get_addr to 2.
	(elf_i386_check_tls_transition): Check indirect call and direct
	call with the addr32 prefix for general and local dynamic models.
	Set the tls_get_addr feild.
	(elf_i386_convert_load_reloc): Always use addr32 prefix for
	indirect ___tls_get_addr call via GOT.
	(elf_i386_relocate_section): Handle GD->LE, GD->IE and LD->LE
	transitions with indirect call and direct call with the addr32
	prefix.

ld/

	* testsuite/ld-i386/i386.exp: Run libtlspic2.so, tlsbin2,
	tlsgd3, tlsld2, tlsgd4, tlspie3a, tlspie3b and tlspie3c.
	* testsuite/ld-i386/pass.out: New file.
	* testsuite/ld-i386/tls-def1.c: Likewise.
	* testsuite/ld-i386/tls-gd1.S: Likewise.
	* testsuite/ld-i386/tls-ld1.S: Likewise.
	* testsuite/ld-i386/tls-main1.c: Likewise.
	* testsuite/ld-i386/tls.exp: Likewise.
	* testsuite/ld-i386/tlsbin2-nacl.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.dd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.sd: Likewise.
	* testsuite/ld-i386/tlsbin2.td: Likewise.
	* testsuite/ld-i386/tlsbinpic2.s: Likewise.
	* testsuite/ld-i386/tlsgd3.dd: Likewise.
	* testsuite/ld-i386/tlsgd3.s: Likewise.
	* testsuite/ld-i386/tlsgd4.d: Likewise.
	* testsuite/ld-i386/tlsgd4.s: Likewise.
	* testsuite/ld-i386/tlsld2.s: Likewise.
	* testsuite/ld-i386/tlspic2-nacl.rd: Likewise.
	* testsuite/ld-i386/tlspic2.dd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-i386/tlspic2.sd: Likewise.
	* testsuite/ld-i386/tlspic2.td: Likewise.
	* testsuite/ld-i386/tlspic3.s: Likewise.
	* testsuite/ld-i386/tlspie3.s: Likewise.
	* testsuite/ld-i386/tlspie3a.d: Likewise.
	* testsuite/ld-i386/tlspie3b.d: Likewise.
	* testsuite/ld-i386/tlspie3c.d: Likewise.
2016-06-08 12:01:50 -07:00
Alan Modra 1a72702bb3 Return void from linker callbacks
The ldmain.c implementation of these linker callback functions always
return true, so any code handling a false return is dead.  What's
more, some of the bfd backends abort if ever a false return is seen,
and there seems to be some confusion in gdb's compile-object-load.c.
The return value was never meant to be "oh yes, a multiple_definition
error occurred", but rather "out of memory or other catastrophic
failure".

This patch removes the status return on the callbacks that always
return true.  I kept the return status for "notice" because that one
does happen to need to return "out of memory".

include/
	* bfdlink.h (struct bfd_link_callbacks): Update comments.
	Return void from multiple_definition, multiple_common,
	add_to_set, constructor, warning, undefined_symbol,
	reloc_overflow, reloc_dangerous and unattached_reloc.
bfd/
	* aoutx.h: Adjust linker callback calls throughout file,
	removing dead code.
	* bout.c: Likewise.
	* coff-alpha.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-h8300.c: Likewise.
	* coff-h8500.c: Likewise.
	* coff-i960.c: Likewise.
	* coff-mcore.c: Likewise.
	* coff-mips.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-sh.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff-w65.c: Likewise.
	* coff-z80.c: Likewise.
	* coff-z8k.c: Likewise.
	* coff64-rs6000.c: Likewise.
	* cofflink.c: Likewise.
	* ecoff.c: Likewise.
	* elf-bfd.h: Likewise.
	* elf-m10200.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf32-arc.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-d10v.c: Likewise.
	* elf32-epiphany.c: Likewise.
	* elf32-fr30.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-ft32.c: Likewise.
	* elf32-h8300.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i370.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-i860.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-lm32.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m32r.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-mep.c: Likewise.
	* elf32-metag.c: Likewise.
	* elf32-microblaze.c: Likewise.
	* elf32-moxie.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-or1k.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-sh64.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-tilepro.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-vax.c: Likewise.
	* elf32-visium.c: Likewise.
	* elf32-xstormy16.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-mmix.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elf64-sh64.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* pe-mips.c: Likewise.
	* reloc.c: Likewise.
	* reloc16.c: Likewise.
	* simple.c: Likewise.
	* vms-alpha.c: Likewise.
	* xcofflink.c: Likewise.
	* elf32-rl78.c (get_symbol_value, get_romstart, get_ramstart): Delete
	status param.  Adjust calls to these and linker callbacks throughout.
	* elf32-rx.c: (get_symbol_value, get_gp, get_romstart,
	get_ramstart): Delete status param.  Adjust calls to these and
	linker callbacks throughout.
ld/
	* ldmain.c (multiple_definition, multiple_common, add_to_set,
	constructor_callback, warning_callback, undefined_symbol,
	reloc_overflow, reloc_dangerous, unattached_reloc): Return void.
	* emultempl/elf32.em: Adjust callback calls.
gdb/
	* compile/compile-object-load.c (link_callbacks_multiple_definition,
	link_callbacks_warning, link_callbacks_undefined_symbol,
	link_callbacks_undefined_symbol, link_callbacks_reloc_overflow,
	link_callbacks_reloc_dangerous,
	link_callbacks_unattached_reloc): Return void.
2016-05-28 11:17:20 +09:30
H.J. Lu 52bf37dd91 Don't check R_386_GOT32 when setting need_convert_load
Since we no longer convert R_386_GOT32, don't check R_386_GOT32 when
setting need_convert_load.

	* elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32
	when setting need_convert_load.
2016-05-20 09:36:48 -07:00
H.J. Lu 7d4d970973 Don't convert R_386_GOT32 relocation
Don't convert R_386_GOT32 since we can't tell if it is applied
to "mov $foo@GOT, %reg" which isn't a load via GOT.

bfd/

	PR ld/20117
	* elf32-i386.c (elf_i386_convert_load_reloc): Don't check
	R_386_GOT32X.
	(elf_i386_convert_load): Don't convert R_386_GOT32.

ld/

	PR ld/20117
	* testsuite/ld-i386/i386.exp: Run pr20117.
	* testsuite/ld-i386/pr19609-1i.d: Updated.
	* testsuite/ld-i386/pr20117.d: New file.
	* testsuite/ld-i386/pr20117.s: Likewise.
2016-05-19 12:57:11 -07:00
Maciej W. Rozycki a43942db49 LD/ELF: Unify STB_GNU_UNIQUE handling
Take STB_GNU_UNIQUE handling scattered across targets and gather it in
the generic ELF linker.  Update test suite infrastructure accordingly.

	bfd/
	* elf-s390-common.c (elf_s390_add_symbol_hook): Remove
	STB_GNU_UNIQUE handling.
	* elf32-arc.c (elf_arc_add_symbol_hook): Likewise.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Likewise.
	* elf32-i386.c (elf_i386_add_symbol_hook): Remove function.
	(elf_backend_add_symbol_hook): Remove macro.
	* elflink.c (elf_link_add_object_symbols): Set `has_gnu_symbols'
	for STB_GNU_UNIQUE symbols.

	binutils/
	* testsuite/lib/binutils-common.exp (supports_gnu_unique): New
	procedure.
	* testsuite/binutils-all/objcopy.exp: Use `supports_gnu_unique'
	with the `strip-10' test.

	ld/
	* testsuite/ld-unique/unique.exp: Use `is_elf_format' and
	`supports_gnu_unique' to qualify testing.
2016-05-17 12:21:40 +01:00
H.J. Lu 030e823caf Define elf_backend_add_symbol_hook for Intel MCU
elf_backend_add_symbol_hook is undefined for FreeBSD.  Define it for
Intel MCU to support STB_GNU_UNIQUE for Intel MCU and NaCl.

	* elf32-i386.c (elf_backend_add_symbol_hook): Defined for Intel
	MCU.
2016-05-06 08:28:27 -07:00
H.J. Lu c175a65796 Extract convert_load_reloc from x86 convert_load
* elf32-i386.c (elf_i386_convert_load): Extract the GOT load
	conversion to ...
	(elf_i386_convert_load_reloc): This.  New function.
	* elf64-x86-64.c (elf_x86_64_convert_load): Extract the GOT load
	conversion to ...
	(elf_x86_64_convert_load_reloc): This.  New function.
2016-05-05 04:14:00 -07:00
H.J. Lu bedfd056d4 Cache the section contents in x86 check_relocs
Cache the section contents in x86 check_relocs for sections without
TLS relocations.

	* elf32-i386.c (elf_i386_check_tls_transition): Remove abfd.
	Don't check if contents == NULL.
	(elf_i386_tls_transition): Add from_relocate_section.  Check
	from_relocate_section instead of contents != NULL.  Update
	elf_i386_check_tls_transition call.
	(elf_i386_check_relocs): Cache the section contents if
	keep_memory is FALSE.  Pass FALSE as from_relocate_section to
	elf_i386_tls_transition.
	(elf_i386_relocate_section): Pass TRUE as from_relocate_section
	to elf_i386_tls_transition.
	(elf_backend_caches_rawsize): New.
	* elf64-x86-64.c (elf_x86_64_check_tls_transition): Don't check
	if contents == NULL.
	(elf_x86_64_tls_transition): Add from_relocate_section.  Check
	from_relocate_section instead of contents != NULL.
	(elf_x86_64_check_relocs): Cache the section contents if
	keep_memory is FALSE.  Pass FALSE as from_relocate_section to
	elf_x86_64_tls_transition.
	(elf_x86_64_relocate_section): Pass TRUE as from_relocate_section
	to elf_x86_64_tls_transition.
	(elf_backend_caches_rawsize): New.
2016-05-05 04:12:16 -07:00
H.J. Lu 493f652c95 Set interpreter in x86 create_dynamic_sections
Set interpreter in x86 create_dynamic_sections to make this information
available to x86 check_relocs.

	* elf32-i386.c (elf_i386_size_dynamic_sections): Move interp
	setting to ...
	(elf_i386_create_dynamic_sections): Here.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Move
	interp setting to ...
	(elf_x86_64_create_dynamic_sections): Here.
2016-04-29 08:27:29 -07:00
H.J. Lu e62b9723fd Pass GOT_RELOC to UNDEFINED_WEAK_RESOLVED_TO_ZERO
When UNDEFINED_WEAK_RESOLVED_TO_ZERO is checked to convert load via
GOT, has_got_reloc is always TRUE.  This patch adds GOT_RELOC, which
is TRUE in x86 convert_load, to UNDEFINED_WEAK_RESOLVED_TO_ZERO.

	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Take GOT_RELOC
	and replace (EH)->has_got_reloc with GOT_RELOC.
	(elf_i386_fixup_symbol): Pass has_got_reloc to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_convert_load): Pass TRUE to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Take
	GOT_RELOC and replace (EH)->has_got_reloc with GOT_RELOC.
	(elf_x86_64_fixup_symbol): Pass has_got_reloc to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
	(elf_x86_64_allocate_dynrelocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.
	(elf_x86_64_finish_dynamic_symbol): Likewise.
	(elf_x86_64_convert_load): Pass TRUE to
	UNDEFINED_WEAK_RESOLVED_TO_ZERO.
2016-04-29 08:21:51 -07:00
H.J. Lu c337a1627c i386: Don't relocate section when check_relocs failed
No need to relocate section when check_relocs failed.

	* elf32-i386.c (check_relocs_failed): New.
	(elf_i386_check_relocs): Set check_relocs_failed on error.
	(elf_i386_relocate_section): Skip if check_relocs failed.
2016-04-29 04:31:54 -07:00
Nick Clifton 5522f910cb Enhance support for copying and stripping Solaris and ARM binaries.
PR 19938
bfd	* elf-bfd.h (struct elf_backend_data): Rename
	elf_backend_set_special_section_info_and_link to
	elf_backend_copy_special_section_fields.
	* elfxx-target.h: Likewise.
	* elf.c (section_match): Ignore the SHF_INFO_LINK flag when
	comparing section flags.
	(copy_special_section_fields): New function.
	(_bfd_elf_copy_private_bfd_data): Copy the EI_ABIVERSION field.
	Perform two scans over special sections.  The first one looks for
	a direct mapping between the output section and an input section.
	The second scan looks for a possible match based upon section
	characteristics.
	* elf32-arm.c (elf32_arm_copy_special_section_fields): New
	function.  Handle setting the sh_link field of SHT_ARM_EXIDX
	sections.
	* elf32-i386.c (elf32_i386_set_special_info_link): Rename to
	elf32_i386_copy_solaris_special_section_fields.
	* elf32-sparc.c (elf32_sparc_set_special_section_info_link):
	Rename to elf32_sparc_copy_solaris_special_section_fields.
	* elf64-x86-64.c (elf64_x86_64_set_special_info_link): Rename to
	elf64_x86_64_copy_solaris_special_section_fields.

binutils* readelf.c (get_solaris_segment_type): New function.
	(get_segment_type): Call it.
2016-04-29 09:24:42 +01:00
H.J. Lu e66cdd681f Remove x86 gc_sweep_hook
Since x86 backends never see the removed sections, there is no need
for gc_sweep_hook.

	* elf32-i386.c (elf_i386_gc_sweep_hook): Removed.
	(elf_backend_gc_sweep_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_gc_sweep_hook): Likewise.
	(elf_backend_gc_sweep_hook): Likewise.
2016-04-20 17:14:02 -07:00
H.J. Lu 466ee2af4a Call _bfd_elf_create_ifunc_sections only for ifunc
Since x86 check_relocs is called after opening all input files, we
need to call _bfd_elf_create_ifunc_sections only for STT_GNU_IFUNC
symbols.

	* elf32-i386.c (elf_i386_check_relocs): Call
	_bfd_elf_create_ifunc_sections only for STT_GNU_IFUNC symbol.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2016-04-20 05:34:15 -07:00
Nick Clifton 8486501545 Fix copying Solaris binaries with objcopy.
PR target/19938
bfd	* elf-bbfd.h (struct elf_backend_data): New field:
	elf_strtab_flags.
	New field: elf_backend_set_special_section_info_and_link
	* elfxx-target.h (elf_backend_strtab_flags): Define if not already
	defined.
	(elf_backend_set_special_section_info_and_link): Define if not
	already defined.
	(elfNN_bed): Use elf_backend_set_special_section_info_and_link and
	elf_backend_strtab_flags macros to initialise fields in structure.
	* elf.c (_bfd_elf_make_section_from_shdr): Check for SHF_STRINGS
	being set even if SHF_MERGE is not set.
	(elf_fake_sections): Likewise.
	(section_match): New function.  Matches two ELF sections based
	upon fixed characteristics.
	(find_link): New function.  Locates a section in a BFD that
	matches a section in a different BFD.
	(_bfd_elf_copy_private_bfd_data): Copy the sh_info and sh_link
	fields of reserved sections.
	(bfd_elf_compute_section_file_positions): Set the flags for the
	.shstrtab section based upon the elf_strtab_flags field in the
	elf_backend_data structure.
	(swap_out_syms): Likewise for the .strtab section.
	* elflink.c (bfd_elf_final_link): Set the flags for the
	.strtab section based upon the elf_strtab_flags field in the
	elf_backend_data structure.
	* elf32-i386.c (elf32_i386_set_special_info_link): New function.
	(elf_backend_strtab_flags): Set to SHF_STRINGS for Solaris
	targets.
	(elf_backend_set_special_section_info_and_link): Define for
	Solaris targets.
	* elf32-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.

binutils* testsuite/binutils-all/i386/compressed-1b.d: Allow for the
	string sections possibly having the SHF_STRINGS flag bit set.
	* testsuite/binutils-all/i386/compressed-1c.d: Likewise.
	* testsuite/binutils-all/readelf.s: Likewise.
	* testsuite/binutils-all/readelf.s-64: Likewise.
	* testsuite/binutils-all/x86-64/compressed-1b.d: Likewise.
	* testsuite/binutils-all/x86-64/compressed-1c.d: Likewise.

gas	* testsuite/gas/i386/ilp32/x86-64-unwind.d: Allow for the string
	sections possibly having the SHF_STRINGS flag bit set.
	* testsuite/gas/i386/x86-64-unwind.d: Likewise.
2016-04-14 12:04:09 +01:00
H.J. Lu 2df3368d85 Properly handle dynamic reloc against normal symbol
We shouldn't issue an error for read-only segment with dynamic IFUNC
relocations when dynamic relocations are against normal symbols.

bfd/

	PR ld/19939
	* elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add a pointer
	to bfd_boolean.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Updated.
	Set *readonly_dynrelocs_against_ifunc_p to TRUE if dynamic reloc
	applies to read-only section.
	* elf32-i386.c (elf_i386_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_i386_allocate_dynrelocs): Updated.
	(elf_i386_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elf64-x86-64.c (elf_x86_64_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(elf_x86_64_allocate_dynrelocs): Updated.
	(elf_x86_64_size_dynamic_sections): Issue an error for read-only
	segment with dynamic IFUNC relocations only if
	readonly_dynrelocs_against_ifunc is TRUE.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Updated.

ld/

	PR ld/19939
	* testsuite/ld-i386/i386.exp: Run PR ld/19939 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19939.s: New file.
	* testsuite/ld-i386/pr19939a.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/pr19939.s: Likewise.
	* testsuite/ld-x86-64/pr19939a.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
2016-04-11 19:41:52 -07:00
H.J. Lu 4e0c91e454 Bind defined symbol locally in PIE
Symbols defined in PIE should be bound locally, the same as -shared
-Bsymbolic.

bfd/

	PR ld/19827
	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
	locally in PIE.
	(elf_i386_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	(elf_x86_64_relocate_section): Likewise.

ld/

	PR ld/19827
	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr19827.rd: New file.
	* testsuite/ld-i386/pr19827a.S: Likewise.
	* testsuite/ld-i386/pr19827b.S: Likewise.
	* testsuite/ld-x86-64/pr19827.rd: Likewise.
	* testsuite/ld-x86-64/pr19827a.S: Likewise.
	* testsuite/ld-x86-64/pr19827b.S: Likewise.
2016-03-15 11:47:06 -07:00
H.J. Lu d1ed1c7d69 Handle local IFUNC symbols in shared object
Increment PLT reference count for locally defined local IFUNC symbols
in shared object since STT_GNU_IFUNC symbol must go through PLT even
if it is locally defined and undefined symbol may turn out to be a
STT_GNU_IFUNC symbol later.

bfd/

	PR ld/19784
	* elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
	count for locally defined local IFUNC symbols in shared object.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/

	PR ld/19784
	* testsuite/ld-i386/i386.exp: Remove pr19636-2e-nacl test.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Moved to ...
	* testsuite/ld-i386/pr19636-2e.d: Here.  Remove notarget.
	* testsuite/ld-ifunc/ifunc.exp: Run PR ld/19784 tests.
	* testsuite/ld-ifunc/pass.out: New file.
	* testsuite/ld-ifunc/pr19784a.c: Likewise.
	* testsuite/ld-ifunc/pr19784b.c: Likewise.
	* testsuite/ld-ifunc/pr19784c.c: Likewise.
2016-03-08 09:42:16 -08:00
H.J. Lu bae420ef26 Optimize x86 GOT32X/GOTPCRELX relocations
R_386_GOT32X, R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX relocations
retrieve the symbol address via its GOT slot.  If the symbol address is
known at the link-time, we can use it directly by changing instruction
encoding.  Indirect branch can only be converted to PC relative direct
branch.  MOV can be changed to LEA or encoded differently with signed
address.  The subset of binary operations can be encoded only with
signed address.

If undefined weak symbol is resolved to zero link-time, we can use it
as address.  Zero addresss can't used with PC relative direct branch
when PIC is true since the current PC is unknown.  In 64-bit, 32-bit
relocation for PC relatiave direct branch to zero may also overflow.

If this optimization causes relocation overflow, --no-relax can be used
to work around it.

bfd/

	PR ld/19609
	* elf32-i386.c (elf_i386_convert_load): Convert to R_386_32 for
	load with locally bound symbols if PIC is false or there is no
	base register.  Optimize branch to 0 if PIC is false.
	(elf_i386_relocate_section): Don't generate dynamic relocations
	against undefined weak symbols if PIC is false.
	* elf64-x86-64.c (elf_x86_64_convert_load): Disable optimization
	if we can't estimate relocation overflow with --no-relax.
	Convert to R_X86_64_32S/R_X86_64_32 for load with locally bound
	symbols if PIC is false.  Optimize branch to 0 if PIC is false.
	(elf_x86_64_relocate_section): Don't generate dynamic relocations
	against undefined weak symbols if PIC is false.

ld/

	PR ld/19609
	* testsuite/ld-i386/got1.dd: Updated.
	* testsuite/ld-i386/lea1c.d: Likewise.
	* testsuite/ld-i386/load1-nacl.d: Likewise.
	* testsuite/ld-i386/load1.d: Likewise.
	* testsuite/ld-i386/load4b.d: Likewise.
	* testsuite/ld-i386/load5b.d: Likewise.
	* testsuite/ld-i386/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1d.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-i386.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-x86-64/gotpcrel1.dd: Likewise.
	* testsuite/ld-x86-64/lea1a.d: Likewise.
	* testsuite/ld-x86-64/lea1b.d: Likewise.
	* testsuite/ld-x86-64/lea1c.d: Likewise.
	* testsuite/ld-x86-64/lea1d.d: Likewise.
	* testsuite/ld-x86-64/lea1e.d: Likewise.
	* testsuite/ld-x86-64/lea1f.d: Likewise.
	* testsuite/ld-x86-64/mov1b.d: Likewise.
	* testsuite/ld-x86-64/mov1d.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3b.d: Likewise.
	* testsuite/ld-x86-64/pr13082-4b.d: Likewise.
	* testsuite/ld-x86-64/lea1.s: Add tests for 32-bit registers.
	* testsuite/ld-i386/pr19609-1.s: New file.
	* testsuite/ld-i386/pr19609-1a.d: Likewise.
	* testsuite/ld-i386/pr19609-1b.d: Likewise.
	* testsuite/ld-i386/pr19609-1c.d: Likewise.
	* testsuite/ld-i386/pr19609-1d.d: Likewise.
	* testsuite/ld-i386/pr19609-1e.d: Likewise.
	* testsuite/ld-i386/pr19609-1f.d: Likewise.
	* testsuite/ld-i386/pr19609-1g.d: Likewise.
	* testsuite/ld-i386/pr19609-1h.d: Likewise.
	* testsuite/ld-i386/pr19609-1i.d: Likewise.
	* testsuite/ld-i386/pr19609-2.s: Likewise.
	* testsuite/ld-i386/pr19609-2a.d: Likewise.
	* testsuite/ld-i386/pr19609-2b.d: Likewise.
	* testsuite/ld-i386/pr19609-2c.d: Likewise.
	* testsuite/ld-i386/undefweak.s: Likewise.
	* testsuite/ld-i386/undefweaka.d: Likewise.
	* testsuite/ld-i386/undefweakb.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3c.d: Likewise.
	* testsuite/ld-x86-64/pr13082-3d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1.s: Likewise.
	* testsuite/ld-x86-64/pr19609-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1f.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1g.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1h.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1i.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1j.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1k.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1l.d: Likewise.
	* testsuite/ld-x86-64/pr19609-1m.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2.s: Likewise.
	* testsuite/ld-x86-64/pr19609-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-3.s: Likewise.
	* testsuite/ld-x86-64/pr19609-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-3b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4.s: Likewise.
	* testsuite/ld-x86-64/pr19609-4a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5.s: Likewise.
	* testsuite/ld-x86-64/pr19609-5a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-5e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6.s: Likewise.
	* testsuite/ld-x86-64/pr19609-6a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6d.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7.s: Likewise.
	* testsuite/ld-x86-64/pr19609-7a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7d.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run undefweak tests and tests for
	PR ld/19609.
	* testsuite/ld-x86-64/x86-64.exp: Run pr13082-3c, pr13082-3d
	and tests for PR ld/19609.
2016-02-26 09:39:24 -08:00
H.J. Lu aec6b87e0b [x86] Resolve non-PIC undefweak symbols in executable
For i386 and x86-64, non-PIC references to undefined weak symbols are
resolved without dynamic relocation when creating executable.  Resolved
undefined weak symbols are removed from the dynamic symbol table in
executable.  One exception is on i386, we need resolved undefined weak
symbols in the dynamic symbol table in PIE if input relocatable files
contain branchs without PLT so that we can branch to 0 with dynamic
relocation in text section.

This makes behaviors of dynamic executable and position independent
executable predictable with mixed PIC and non-PIC references to undefined
weak symbols.  If all references to undefined weak symbols are PIC,
dynamic relocations against undefined weak symbols will be generated
in executable unless -z nodynamic-undefined-weak is passed to linker.

bfd/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* elf32-i386.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_i386_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_i386_link_hash_table): Add interp.
	(elf_i386_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_i386_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_i386_check_relocs): Set has_got_reloc and has_non_got_reloc.
	(elf_i386_fixup_symbol): New function.
	(elf_i386_pie_finish_undefweak_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.  Keep dynamic non-GOT/non-PLT
	relocation against undefined weak symbols in PIE.
	(elf_i386_size_dynamic_sections): Set interp to .interp section.
	(elf_i386_relocate_section): Don't generate dynamic relocations
	against resolved undefined weak symbols in PIE, except for
	R_386_PC32.
	(elf_i386_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_i386_finish_dynamic_sections): Call
	elf_i386_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.
	* elf64-x86-64.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
	(elf_x86_64_link_hash_entry): Add has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_link_hash_table): Add interp.
	(elf_x86_64_link_hash_newfunc): Initialize has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_copy_indirect_symbol): Copy has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_check_relocs): Set has_got_reloc and
	has_non_got_reloc.
	(elf_x86_64_fixup_symbol): New function.
	(elf_x86_64_pie_finish_undefweak_symbol): Likewise.
	(elf_x86_64_allocate_dynrelocs): Don't allocate space for dynamic
	relocations and discard relocations against resolved undefined
	weak symbols in executable.  Don't make resolved undefined weak
	symbols in executable dynamic.
	(elf_x86_64_size_dynamic_sections): Set interp to .interp section.
	(elf_x86_64_relocate_section): Check relocation overflow for
	dynamic relocations against unresolved weak undefined symbols.
	Don't generate dynamic relocations against resolved weak
	undefined symbols in PIE.
	(elf_x86_64_finish_dynamic_symbol): Keep PLT/GOT entries without
	dynamic PLT/GOT relocations for resolved undefined weak symbols.
	Don't generate dynamic relocation against resolved undefined weak
	symbol in executable.
	(elf_x86_64_finish_dynamic_sections): Call
	elf_x86_64_pie_finish_undefweak_symbol on all symbols in PIE.
	(elf_backend_fixup_symbol): New.

include/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* bfdlink.h (bfd_link_info): Add dynamic_undefined_weak.

ld/

	PR ld/19636
	PR ld/19704
	PR ld/19719
	* Makefile.am (ELF_X86_DEPS): Add dynamic_undefined_weak.sh.
	* Makefile.in: Regenerated.
	* NEWS: Mention -z nodynamic-undefined-weak.
	* ld.texinfo: Document -z nodynamic-undefined-weak.
	* ldmain.c (main): Initialize dynamic_undefined_weak to -1.
	* emulparams/dynamic_undefined_weak.sh: New file.
	* emulparams/elf32_x86_64.sh: Source dynamic_undefined_weak.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_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/extern_protected_data.sh (PARSE_AND_LIST_OPTIONS):
	Append.
	(PARSE_AND_LIST_ARGS_CASE_Z): Likewise.
	* testsuite/ld-elf/pr19719a.c: New file.
	* testsuite/ld-elf/pr19719b.c: Likewise.
	* testsuite/ld-elf/pr19719c.c: Likewise.
	* testsuite/ld-elf/pr19719d.c: Likewise.
	* testsuite/ld-i386/pr19636-1.s: Likewise.
	* testsuite/ld-i386/pr19636-1a.d: Likewise.
	* testsuite/ld-i386/pr19636-1b.d: Likewise.
	* testsuite/ld-i386/pr19636-1c.d: Likewise.
	* testsuite/ld-i386/pr19636-1d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-1e.d: Likewise.
	* testsuite/ld-i386/pr19636-1f.d: Likewise.
	* testsuite/ld-i386/pr19636-1g.d: Likewise.
	* testsuite/ld-i386/pr19636-1h.d: Likewise.
	* testsuite/ld-i386/pr19636-1i.d: Likewise.
	* testsuite/ld-i386/pr19636-2.s: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e-nacl.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3.s: Likewise.
	* testsuite/ld-i386/pr19636-3a.d: Likewise.
	* testsuite/ld-i386/pr19636-3b.d: Likewise.
	* testsuite/ld-i386/pr19636-3c.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19636-3f.d: Likewise.
	* testsuite/ld-i386/pr19636-3g.d: Likewise.
	* testsuite/ld-i386/pr19636-4.s: Likewise.
	* testsuite/ld-i386/pr19636-4a.d: Likewise.
	* testsuite/ld-i386/pr19636-4b.d: Likewise.
	* testsuite/ld-i386/pr19636-4c.d: Likewise.
	* testsuite/ld-i386/pr19636-4d.d: Likewise.
	* testsuite/ld-i386/pr19704.out: Likewise.
	* testsuite/ld-i386/pr19704a.c: Likewise.
	* testsuite/ld-i386/pr19704b.c: Likewise.
	* testsuite/ld-x86-64/pr19636-1.s: Likewise.
	* testsuite/ld-x86-64/pr19636-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2.s: Likewise.
	* testsuite/ld-x86-64/pr19636-2a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2g.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2h.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2i.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3.s: Likewise.
	* testsuite/ld-x86-64/pr19636-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3c.d: Likewise.
	* testsuite/ld-x86-64/pr19636-3d.d: Likewise.
	* testsuite/ld-x86-64/pr19704.out: Likewise.
	* testsuite/ld-x86-64/pr19704a.c: Likewise.
	* testsuite/ld-x86-64/pr19704b.c: Likewise.
	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): New.
	Run mix_pic_and_non_pic.
	* testsuite/ld-i386/i386.exp (undefined_weak): New.
	Run undefined_weak and PR ld/19636 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-x86-64/pr13082-3b.d: Updated.
	* testsuite/ld-x86-64/pr13082-4b.d: Likewise.
2016-02-26 04:55:57 -08:00
H.J. Lu 13f422778f Set plt_got.offset to (bfd_vma) -1
Since plt_got.offset may be updated in x86 allocate_dynrelocs, set
plt_got.offset to (bfd_vma) -1 when setting needs_plt to 0.

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Set plt_got.offset
	to (bfd_vma) -1 when setting needs_plt to 0.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2016-02-24 05:49:48 -08:00
H.J. Lu 32875eb1f3 Mask off the least significant bit in GOT offset
The least significant bit in GOT offset is to record whether we have
initialized the GOT entry in R_386_GOT32 processing.  We need to mask
it off for R_386_GOT32X.

	PR ld/19601
	* elf32-i386.c (elf_i386_relocate_section): Mask off the least
	significant bit in GOT offset for R_386_GOT32X.
2016-02-10 19:33:52 -08:00
Alan Modra ec1f73bb0b x86 synthetic plt symbols
Changing "pushq $1" in the following to "pushq $too_big" results in an
abort.  BFD shouldn't abort on (deliberately) bad user input.

 400480:       ff 25 9a 0b 20 00       jmpq   *0x200b9a(%rip)
 400486:       68 01 00 00 00          pushq  $0x1
 40048b:       e9 d0 ff ff ff          jmpq   400460 <_init+0x20>

	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Don't abort on
	an out of range reloc_index.
	* elf32-i386.c (elf_i386_get_plt_sym_val): Likewise.
2016-02-01 21:27:02 +10:30
H.J. Lu d9e3b59069 Check reloc against IFUNC symbol only with dynamic symbols
There is no need to check relocation IFUNC symbol if there are no
dynamic symbols.

bfd/

	PR ld/19539
	* elf32-i386.c (elf_i386_reloc_type_class): Check relocation
	against STT_GNU_IFUNC symbol only with dynamic symbols.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.

ld/

	PR ld/19539
	* testsuite/ld-elf/pr19539.d: New file.
	* testsuite/ld-elf/pr19539.s: Likewise.
	* testsuite/ld-elf/pr19539.t: Likewise.
2016-01-30 16:08:20 -08:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
H.J. Lu 02e2aef89b Optimize R_386_GOT32/R_386_GOT32X only if addend is 0
Linker can't optimize R_386_GOT32 and R_386_GOT32X relocations if addend
isn't 0.  It isn't valid to convert

movl	foo@GOT+1(%ecx), %eax

to

leal	foo@GOTOFF+1(%ecx), %eax

nor to convert

movq	foo@GOTPCREL+1(%rip), %rax

to

leaq	foo(%rip), %rax

for x86-64.  We should check if addend is 0 before optimizing R_386_GOT32
and R_386_GOT32X relocations.  Testcases are added for i386 and x86-64.

bfd/

	* elf32-i386.c (elf_i386_convert_load): Skip if addend isn't 0.
	(elf_i386_relocate_section): Skip R_386_GOT32X optimization if
	addend isn't 0.

ld/testsuite/

	* ld-i386/i386.exp: Run mov2a, mov2b and mov3.
	* ld-i386/mov2.s: New file.
	* ld-i386/mov2a.d: Likewise.
	* ld-i386/mov2b.d: Likewise.
	* ld-i386/mov3.d: Likewise.
	* ld-i386/mov3.s: Likewise.
	* ld-x86-64/mov2.s: Likewise.
	* ld-x86-64/mov2a.d: Likewise.
	* ld-x86-64/mov2b.d: Likewise.
	* ld-x86-64/mov2c.d: Likewise.
	* ld-x86-64/mov2d.d: Likewise.
	* ld-x86-64/x86-64.exp: Run mov2a, mov2b, mov2c and mov2d.
2015-12-04 09:03:04 -08:00
H.J. Lu ead3d5427a Properly check symbol defined by assignment in linker script
Symbol defined by a linker assignment may have type bfd_link_hash_new
or bfd_link_hash_undefined.  And h->def_regular is always set.
elf_i386_convert_load and elf_x86_64_convert_load should check
h->def_regular as well as bfd_link_hash_undefined and bfd_link_hash_new
to see if a symbol is defined by a linker script.

bfd/

	PR ld/19319
	* elf32-i386.c (elf_i386_convert_load): Check h->def_regular
	instead of bfd_link_hash_new.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.  Skip
	relocation overflow for bfd_link_hash_undefined and
	bfd_link_hash_new if h->def_regular is set.

ld/testsuite/

	PR ld/19319
	* ld-i386/i386.exp: Run pr19319 test.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr19319.dd: New file.
	* ld-i386/pr19319a.S: Likewise.
	* ld-i386/pr19319b.S: Likewise.
	* ld-x86-64/pr19319.dd: Likewise.
	* ld-x86-64/pr19319a.S: Likewise.
	* ld-x86-64/pr19319b.S: Likewise.
2015-12-01 14:45:51 -08:00
H.J. Lu 18954b29a1 Handle x86 VTINHERIT/VTENTRY relocs when deleting relocations
* elf32-i386.c (elf_i386_relocate_section): Handle VTINHERIT
	and VTENTRY relocations when deleting relocations.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 04:27:51 -08:00
H.J. Lu 2d5da47320 Properly move kept relocations when deleting relocations
* elf32-i386.c (elf_i386_relocate_section): Properly move
	kept relocations when deleting relocations.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 00:17:59 -08:00
H.J. Lu 60f2e42e00 Fix performance regression on x86 with ld -r
Similar fix to "commit c316a17c40e44e8798b34ff84130904f2e7a53de".

	* elf32-i386.c (elf_i386_relocate_section): Use read and write
	pointers to reloc array, rather than memmove when deleting a
	reloc.  Don't use RELOC_AGAINST_DISCARDED_SECTION.  Adjust
	reloc counts at end of loop.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-11-10 00:00:04 -08:00
H.J. Lu a3718e9efd Fix a typo in comment in elf32-i386.c
* elf32-i386.c (elf_i386_relocate_section): Fix a typo in
	comment.
2015-10-28 09:15:40 -07:00
H.J. Lu 7b7e7f1da2 Check symbol defined by assignment in linker script
Symbol symbol defined by an assignment in a linker script has type
bfd_link_hash_new.  elf_i386_convert_load and elf_x86_64_convert_load
should check bfd_link_hash_new to see if a symbol is defined by a linker
script.

bfd/

	PR ld/19175
	* elf32-i386.c (elf_i386_convert_load): Check bfd_link_hash_new
	instead of calling bfd_link_get_defined_symbol.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.  Skip
	relocation overflow for bfd_link_hash_new.
	* linker.c (bfd_link_get_defined_symbol): Removed.
	* bfd-in2.h: Regenerated.

ld/testsuite/

	PR ld/19175
	* ld-i386/i386.exp: Run pr19175.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr19175.d: New file.
	* ld-i386/pr19175.s: Likewise.
	* ld-i386/pr19175.t: Likewise.
	* ld-x86-64/pr19175.d: Likewise.
	* ld-x86-64/pr19175.s: Likewise.
	* ld-x86-64/pr19175.t: Likewise.
2015-10-26 16:32:55 -07:00
H.J. Lu a6af384b19 Properly convert address load of __start_XXX/__stop_XXX
Since __start_XXX and __stop_XXX symbols aren't defined when address
load is being converted, we need to check if there is an XXX output
section to get their section and value.  This patch adds a new function,
bfd_link_get_defined_symbol, to search for the XXX output section to
check if __start_XXX and __stop_XXX symbols are defined.

bfd/

	PR ld/19171
	* elf32-i386.c (elf_i386_convert_load): Call
	bfd_link_get_defined_symbol to check if a symbol is defined.
	* elf64-x86-64.c (elf_x86_64_convert_load): Call
	bfd_link_get_defined_symbol to get defined symbol section and
	value.
	* linker.c (bfd_link_get_defined_symbol): New function.
	* bfd-in2.h: Regenerated.

ld/testsuite/

	PR ld/19171
	* ld-i386/lea1.s: Add tests for address load of __start_XXX
	and __stop_XXX.
	* ld-i386/mov1.s: Likewise.
	* ld-x86-64/lea1.s: Likewise.
	* ld-x86-64/mov1.s: Likewise.
	* ld-i386/lea1a.d: Updated.
	* ld-i386/lea1b.d: Likewise.
	* ld-i386/lea1c.d: Likewise.
	* ld-i386/mov1a.d: Likewise.
	* ld-i386/mov1b.d: Likewise.
	* ld-x86-64/lea1a.d: Likewise.
	* ld-x86-64/lea1b.d: Likewise.
	* ld-x86-64/lea1c.d: Likewise.
	* ld-x86-64/lea1d.d: Likewise.
	* ld-x86-64/lea1e.d: Likewise.
	* ld-x86-64/lea1f.d: Likewise.
	* ld-x86-64/mov1a.d: Likewise.
	* ld-x86-64/mov1b.d: Likewise.
	* ld-x86-64/mov1c.d: Likewise.
	* ld-x86-64/mov1d.d: Likewise.
2015-10-26 08:11:55 -07:00
H.J. Lu caa65211bb Add "-z call-nop=PADDING" option to ld
The ld linker can transform indirect call to a locally defined function,
foo, via its GOT slot, to either "NOP call foo" or "call foo NOP" where
NOP is a 1-byte NOP padding.  This patch adds a "-z call-nop=PADDING"
option to x86 ld to control 1-byte NOP padding for x86 call instruction.
PADDING is one of prefix-addr, prefix-nop, suffix-nop, prefix-NUMBER or
suffix-NUMBER.

bfd/

	* elf32-i386.c (elf_i386_convert_load): Use call_nop_byte and
	check call_nop_as_suffix for 1-byte NOP padding to pad call.
	* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.

include/

	* bfdlink.h (bfd_link_info): Add call_nop_as_suffix and
	call_nop_byte.

ld/

	* ld/ld.texinfo: Document "-z call-nop=PADDING" option.
	* emulparams/call_nop.sh: New file.
	* emulparams/elf_i386_be.sh: Source
	${srcdir}/emulparams/call_nop.sh.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_i386_vxworks.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
	link_info.call_nop_byte if $CALL_NOP_BYTE isn't empty.

ld/testsuite/

	* ld-i386/call3.s: New file.
	* ld-i386/call3a.d: Likewise.
	* ld-i386/call3b.d: Likewise.
	* ld-i386/call3c.d: Likewise.
	* ld-i386/call3d.d: Likewise.
	* ld-i386/call3e.d: Likewise.
	* ld-i386/call3f.d: Likewise.
	* ld-i386/call3g.d: Likewise.
	* ld-i386/call3h.d: Likewise.
	* ld-i386/load1-nacl.d: Likewise.
	* ld-x86-64/call1.s: Likewise.
	* ld-x86-64/call1a.d: Likewise.
	* ld-x86-64/call1b.d: Likewise.
	* ld-x86-64/call1c.d: Likewise.
	* ld-x86-64/call1d.d: Likewise.
	* ld-x86-64/call1e.d: Likewise.
	* ld-x86-64/call1f.d: Likewise.
	* ld-x86-64/call1g.d: Likewise.
	* ld-x86-64/call1h.d: Likewise.
	* ld-x86-64/call1i.d: Likewise.
	* ld-x86-64/load1a-nacl.d: Likewise.
	* ld-x86-64/load1b-nacl.d: Likewise.
	* ld-x86-64/load1c-nacl.d: Likewise.
	* ld-x86-64/load1d-nacl.d: Likewise.
2015-10-22 04:56:39 -07:00
H.J. Lu 02a866936d Add R_386_GOT32X support to gas and ld
This patch adds support for the R_386_GOT32X relocation proposed in

https://groups.google.com/forum/#!topic/ia32-abi/GbJJskkid4I

to gas and ld.  It updates gas to generate R_386_GOT32X relocation for
memory operand, foo@GOT[(%reg)].  We must encode "mov foo@GOT, %eax"
with the 0x8b opcode, instead of the 0xb8 opcode, so that it can be
transformed to "lea foo, %eax".  With the locally defined symbol, foo,
we convert

   mov foo@GOT[(%reg1)], %reg2
to
   lea foo[@GOTOFF(%reg1)], %reg2

and convert

   call/jmp *foo@GOT[(%reg)]
to

   nop call foo/jmp foo nop

When PIC is false, convert

   test %reg1, foo@GOT[(%reg2)]
to
   test $foo, %reg1

and convert

binop foo@GOT[(%reg1)], %reg2

to

binop $foo, %reg2

where binop is one of adc, add, and, cmp, or, sbb, sub, xor instructions.

bfd/

	* elf32-i386.c: Include opcode/i386.h.
	(elf_howto_table): Add R_386_GOT32X.
	(R_386_ext2): Replace R_386_IRELATIVE with R_386_GOT32X.
	(elf_i386_reloc_type_lookup): Handle BFD_RELOC_386_GOT32X.
	(need_convert_mov_to_lea): Renamed to ...
	(need_convert_load): This.
	(elf_i386_check_relocs): Handle R_386_GOT32X.  Replace
	need_convert_mov_to_lea with need_convert_load.
	(elf_i386_gc_sweep_hook): Handle R_386_GOT32X.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_convert_mov_to_lea): Renamed to ...
	(elf_i386_convert_load): This.  Replace need_convert_mov_to_lea
	with need_convert_load.  Support R_386_GOT32X transformations.
	* reloc.c (BFD_RELOC_386_GOT32X): New.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

gas/

	* config/tc-i386.c (tc_i386_fix_adjustable): Handle
	BFD_RELOC_386_GOT32X.
	(tc_gen_reloc): Likewise.
	(match_template): Force 0x8b encoding for "mov foo@GOT, %eax".
	(output_disp): Check for "call/jmp *mem", "mov mem, %reg",
	"test %reg, mem" and "binop mem, %reg" where binop is one of
	adc, add, and, cmp, or, sbb, sub, xor instructions.  Set
	fx_tcbit if the REX prefix is generated.  Set fx_tcbit2 if
	BFD_RELOC_386_GOT32X should be generated.
	(i386_validate_fix): Generate BFD_RELOC_386_GOT32X if fx_tcbit2
	is set.

gas/testsuite/

	* gas/i386/got.d: New file.
	* gas/i386/got.s: Likewise.
	* gas/i386/i386.exp: Run got.
	* gas/i386/localpic.d: Replace R_386_GOT32 with R_386_GOT32X.
	* gas/i386/mixed-mode-reloc32.d: Likewise.
	* gas/i386/reloc32.d: Likewise.

include/elf/

	* i386.h (R_386_GOT32X): New relocation.

ld/testsuite/

	* ld-i386/branch1.d: New file.
	* ld-i386/branch1.s: Likewise.
	* ld-i386/call1.d: Likewise.
	* ld-i386/call1.s: Likewise.
	* ld-i386/call2.d: Likewise.
	* ld-i386/call2.s: Likewise.
	* ld-i386/got1.dd: Likewise.
	* ld-i386/got1.out: Likewise.
	* ld-i386/got1a.S: Likewise.
	* ld-i386/got1b.c: Likewise.
	* ld-i386/got1c.c: Likewise.
	* ld-i386/got1d.S: Likewise.
	* ld-i386/jmp1.d: Likewise.
	* ld-i386/jmp1.s: Likewise.
	* ld-i386/jmp2.d: Likewise.
	* ld-i386/jmp2.s: Likewise.
	* ld-i386/load1.d: Likewise.
	* ld-i386/load1.s: Likewise.
	* ld-i386/load2.d: Likewise.
	* ld-i386/load2.s: Likewise.
	* ld-i386/load3.d: Likewise.
	* ld-i386/load3.s: Likewise.
	* ld-i386/load4.s: Likewise.
	* ld-i386/load4a.d: Likewise.
	* ld-i386/load4b.d: Likewise.
	* ld-i386/load5.s: Likewise.
	* ld-i386/load5a.d: Likewise.
	* ld-i386/load5b.d: Likewise.
	* ld-i386/load6.d: Likewise.
	* ld-i386/load6.s: Likewise.
	* ld-i386/i386.exp: Run branch1, call1, call2, jmp1, jmp2,
	load1, load2, load3, load4a, load4b, load5a, load5b and load6
	tests.  Run got1 test.
2015-10-22 04:47:07 -07:00
H.J. Lu 75a06c790f Check if symbol is defined when converting mov to lea
We need to check if symbol is defined when converting mov to lea since
SYMBOL_REFERENCES_LOCAL may return true on hidden undefined symbols.

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Check if symbol
	is defined.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2015-10-16 04:21:03 -07:00
H.J. Lu b31bcacc48 Convert mov to lea for loading address of local common symbol
There is no need to check def_regular when converting mov to lea for
loading address of local symbols since def_regular may be false for
common symbols and SYMBOL_REFERENCES_LOCAL is sufficient.

bfd/

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Don't check
	def_regular.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

	* ld-i386/lea1.s: Add a test for loading address of local common
	symbol.
	* ld-x86-64/lea1.s: Likewise.
	* ld-i386/lea1a.d: Updated.
	* ld-i386/lea1b.d: Likewise.
	* ld-i386/lea1c.d: Likewise.
	* ld-x86-64/lea1a.d: Likewise.
	* ld-x86-64/lea1b.d: Likewise.
	* ld-x86-64/lea1c.d: Likewise.
	* ld-x86-64/lea1d.d: Likewise.
	* ld-x86-64/lea1e.d: Likewise.
	* ld-x86-64/lea1f.d: Likewise.
2015-10-16 03:14:40 -07:00
H.J. Lu 4b627c1844 Create a PLT entry for R_386_PC32 in non-code sections
Since something like ".long foo - ." may be used as pointer, we make
sure that PLT is used if foo is a function defined in a shared library.

bfd/

	PR ld/19031
	* elf32-i386.c (elf_i386_check_relocs): Set
	pointer_equality_needed for R_386_PC32 reloc in non-code
	sections.

ld/testsuite/

	PR ld/19031
	* ld-i386/i386.exp: Run PR ld/19031 test.
	* ld/testsuite/ld-i386/pr19031.out: New file.
	* ld/testsuite/ld-i386/pr19031a.c: Likewise.
	* ld/testsuite/ld-i386/pr19031b.S: Likewise.
	* ld/testsuite/ld-i386/pr19031c.c: Likewise.
2015-09-30 08:45:13 -07:00
Rich Felker 9b8b325a1f Add --no-dynamic-linker option to ld, for static PIE use
Inhibits output of .interp section in ELF executables.

include/
	* bfdlink.h (struct bfd_link_info): Add "nointerp" field.
bfd/
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Don't create
	.interp when info->nointerp.
	(bfd_elf_size_dynamic_sections): Adjust assert.
	* elf32-arm.c (elf32_arm_size_dynamic_sections): Don't size .interp
	when info->nointerp.
	* elf32-bfin.c (elf32_bfinfdpic_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_size_dynamic_sections): Likewise.
	* elf32-frv.c (elf32_frvfdpic_size_dynamic_sections): Likewise.
	* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise.
	* elf32-i370.c (i370_elf_size_dynamic_sections): Likewise.
	* elf32-i386.c (elf_i386_size_dynamic_sections): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_size_dynamic_sections): Likewise.
	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections): Likewise.
	* elf32-tic6x.c (elf32_tic6x_size_dynamic_sections): Likewise.
	* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf64-sh64.c (sh64_elf64_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise.
	* elfnn-ia64.c (elfNN_ia64_size_dynamic_sections): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_size_dynamic_sections): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise.
	* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
ld/
	* ld.texinfo (--no-dynamic-linker): Document.
	* ldlex.h (enum option_values): Add OPTION_NO_DYNAMIC_LINKER.
	* lexsup.c (ld_options, parse_args): Handle --no-dynamic-linker.
2015-09-20 15:52:27 +09:30
H.J. Lu c74be520ba Rename R_386_irelative to R_386_ext2
* elf32-i386.c (R_386_irelative): Renamed to ...
	(R_386_ext2): This.
	(R_386_vt_offset): Updated.
	(elf_i386_rtype_to_howto): Likewise.
	(elf_i386_relocate_section): Likewise.
2015-09-02 05:13:08 -07:00
H.J. Lu 04ebc307f9 Skip PLT for function pointer initialization
We use its PLT entry to initialize function pointer at run-time.  If
there is no other usage for the PLT entry, we can generate run-time
function pointer relocations in read-write section, which can be
resolved by dynamic linker, to initialize function pointers.  It avoids
the extra indirect branch overhead in PLT.

bfd/

	PR ld/18900
	* elf32-i386.c (elf_i386_link_hash_entry): Add
	func_pointer_refcount.
	(elf_i386_link_hash_newfunc): Clear func_pointer_refcount.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_copy_indirect_symbol): Also copy
	func_pointer_refcount.
	(elf_i386_check_relocs): Increment func_pointer_refcount.
	(elf_i386_gc_sweep_hook): Decrement func_pointer_refcount.
	(elf_i386_allocate_dynrelocs): Don't create the PLT entry if
	there are only function pointer relocations which can be
	resolved at run-time.  Keep dynanamic relocations for run-time
	function pointer initialization.
	(elf_i386_relocate_section): Copy dynamic function pointer
	relocations.
	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
	func_pointer_refcount.
	(elf_x86_64_link_hash_newfunc): Clear func_pointer_refcount.
	(elf_x86_64_get_local_sym_hash): Likewise.
	(elf_x86_64_copy_indirect_symbol): Also copy
	func_pointer_refcount.
	(elf_x86_64_check_relocs): Increment func_pointer_refcount.
	(elf_x86_64_gc_sweep_hook): Decrement func_pointer_refcount.
	(elf_x86_64_allocate_dynrelocs): Don't create the PLT entry if
	there are only function pointer relocations which can be
	resolved at run-time.  Keep dynanamic relocations for run-time
	function pointer initialization.
	(elf_x86_64_relocate_section): Copy dynamic function pointer
	relocations.

ld/testsuite/

	PR ld/18900
	* ld-i386/i386.exp: Run tests for PR ld/18900.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18900.out: New file.
	* ld-i386/pr18900a.c: Likewise.
	* ld-i386/pr18900a.c: Likewise.
	* ld-i386/pr18900a.rd: Likewise.
	* ld-i386/pr18900b.c: Likewise.
	* ld-i386/pr18900b.rd: Likewise.
	* ld-i386/pr18900c.c: Likewise.
	* ld-x86-64/pr18900.out: Likewise.
	* ld-x86-64/pr18900a.c: Likewise.
	* ld-x86-64/pr18900a.rd: Likewise.
	* ld-x86-64/pr18900b.c: Likewise.
	* ld-x86-64/pr18900b.rd: Likewise.
	* ld-x86-64/pr18900c.c: Likewise.
	* ld-x86-64/mpx3.dd: Updated.
2015-09-01 05:06:33 -07:00
H.J. Lu cae1fbbb7e Return reloc_class_ifunc for reloc against IFUNC
elf_XXX_reloc_type_class should return reloc_class_ifunc for relocation
against STT_GNU_IFUNC symbol.

bfd/

	PR ld/18841
	* elf-bfd.h (elf_link_hash_table): Add dynsym.
	* elf32-i386.c (elf_i386_reloc_type_class): Return
	reloc_class_ifunc for relocation against STT_GNU_IFUNC symbol.
	* elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise.
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Set dynsym.
	(bfd_elf_size_dynsym_hash_dynstr): Use dynsym.
	(elf_final_link_info): Remove dynsym_sec.
	(elf_link_output_extsym): Replace dynsym_sec with dynsym.
	(bfd_elf_final_link): Remove reference to dynsym_sec.  Replace
	dynsym_sec with dynsym.

ld/testsuite/

	PR ld/18841
	* ld-ifunc/ifunc.exp: Add a test for PR ld/18841.
	* ld-ifunc/pr18841.out: New file.
	* ld-ifunc/pr18841a.c: Likewise.
	* ld-ifunc/pr18841b.c: Likewise.
2015-08-18 09:50:08 -07:00
H.J. Lu 0e1862bb40 Add output_type to bfd_link_info
The "shared" field in bfd_link_info is set for both DSO and and PIE.
There are separate fields for executable and relocatable outputs.  This
patch adds an "output_type" field:

enum output_type
{
  type_unknown = 0,
  type_executable,
  type_dll,
  type_relocatable
};

and a "pic" field to bfd_link_info to replace shared, executable and
relocatable fields so that we can use the "output_type" field to check
for output type and the "pic" field check if output is PIC.  Macros,
bfd_link_executable, bfd_link_dll, bfd_link_relocatable, bfd_link_pic
and bfd_link_pie, are provided to check for output features.

bfd/

	* bfd/aoutx.h: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* bfd/bout.c: Likewise.
	* bfd/coff-alpha.c: Likewise.
	* bfd/coff-arm.c: Likewise.
	* bfd/coff-i386.c: Likewise.
	* bfd/coff-i960.c: Likewise.
	* bfd/coff-m68k.c: Likewise.
	* bfd/coff-mcore.c: Likewise.
	* bfd/coff-mips.c: Likewise.
	* bfd/coff-ppc.c: Likewise.
	* bfd/coff-rs6000.c: Likewise.
	* bfd/coff-sh.c: Likewise.
	* bfd/coff-tic80.c: Likewise.
	* bfd/coff-x86_64.c: Likewise.
	* bfd/coff64-rs6000.c: Likewise.
	* bfd/coffgen.c: Likewise.
	* bfd/cofflink.c: Likewise.
	* bfd/ecoff.c: Likewise.
	* bfd/ecofflink.c: Likewise.
	* bfd/elf-bfd.h: Likewise.
	* bfd/elf-eh-frame.c: Likewise.
	* bfd/elf-ifunc.c: Likewise.
	* bfd/elf-m10200.c: Likewise.
	* bfd/elf-m10300.c: Likewise.
	* bfd/elf-s390-common.c: Likewise.
	* bfd/elf-vxworks.c: Likewise.
	* bfd/elf.c: Likewise.
	* bfd/elf32-arm.c: Likewise.
	* bfd/elf32-avr.c: Likewise.
	* bfd/elf32-bfin.c: Likewise.
	* bfd/elf32-cr16.c: Likewise.
	* bfd/elf32-cr16c.c: Likewise.
	* bfd/elf32-cris.c: Likewise.
	* bfd/elf32-crx.c: Likewise.
	* bfd/elf32-d10v.c: Likewise.
	* bfd/elf32-dlx.c: Likewise.
	* bfd/elf32-epiphany.c: Likewise.
	* bfd/elf32-fr30.c: Likewise.
	* bfd/elf32-frv.c: Likewise.
	* bfd/elf32-ft32.c: Likewise.
	* bfd/elf32-h8300.c: Likewise.
	* bfd/elf32-hppa.c: Likewise.
	* bfd/elf32-i370.c: Likewise.
	* bfd/elf32-i386.c: Likewise.
	* bfd/elf32-i860.c: Likewise.
	* bfd/elf32-ip2k.c: Likewise.
	* bfd/elf32-iq2000.c: Likewise.
	* bfd/elf32-lm32.c: Likewise.
	* bfd/elf32-m32c.c: Likewise.
	* bfd/elf32-m32r.c: Likewise.
	* bfd/elf32-m68hc11.c: Likewise.
	* bfd/elf32-m68hc1x.c: Likewise.
	* bfd/elf32-m68k.c: Likewise.
	* bfd/elf32-mcore.c: Likewise.
	* bfd/elf32-mep.c: Likewise.
	* bfd/elf32-metag.c: Likewise.
	* bfd/elf32-microblaze.c: Likewise.
	* bfd/elf32-moxie.c: Likewise.
	* bfd/elf32-msp430.c: Likewise.
	* bfd/elf32-mt.c: Likewise.
	* bfd/elf32-nds32.c: Likewise.
	* bfd/elf32-nios2.c: Likewise.
	* bfd/elf32-or1k.c: Likewise.
	* bfd/elf32-ppc.c: Likewise.
	* bfd/elf32-rl78.c: Likewise.
	* bfd/elf32-rx.c: Likewise.
	* bfd/elf32-s390.c: Likewise.
	* bfd/elf32-score.c: Likewise.
	* bfd/elf32-score7.c: Likewise.
	* bfd/elf32-sh-symbian.c: Likewise.
	* bfd/elf32-sh.c: Likewise.
	* bfd/elf32-sh64.c: Likewise.
	* bfd/elf32-spu.c: Likewise.
	* bfd/elf32-tic6x.c: Likewise.
	* bfd/elf32-tilepro.c: Likewise.
	* bfd/elf32-v850.c: Likewise.
	* bfd/elf32-vax.c: Likewise.
	* bfd/elf32-visium.c: Likewise.
	* bfd/elf32-xc16x.c: Likewise.
	* bfd/elf32-xstormy16.c: Likewise.
	* bfd/elf32-xtensa.c: Likewise.
	* bfd/elf64-alpha.c: Likewise.
	* bfd/elf64-hppa.c: Likewise.
	* bfd/elf64-ia64-vms.c: Likewise.
	* bfd/elf64-mmix.c: Likewise.
	* bfd/elf64-ppc.c: Likewise.
	* bfd/elf64-s390.c: Likewise.
	* bfd/elf64-sh64.c: Likewise.
	* bfd/elf64-x86-64.c: Likewise.
	* bfd/elflink.c: Likewise.
	* bfd/elfnn-aarch64.c: Likewise.
	* bfd/elfnn-ia64.c: Likewise.
	* bfd/elfxx-mips.c: Likewise.
	* bfd/elfxx-sparc.c: Likewise.
	* bfd/elfxx-tilegx.c: Likewise.
	* bfd/i386linux.c: Likewise.
	* bfd/linker.c: Likewise.
	* bfd/m68klinux.c: Likewise.
	* bfd/pdp11.c: Likewise.
	* bfd/pe-mips.c: Likewise.
	* bfd/peXXigen.c: Likewise.
	* bfd/reloc.c: Likewise.
	* bfd/reloc16.c: Likewise.
	* bfd/sparclinux.c: Likewise.
	* bfd/sunos.c: Likewise.
	* bfd/vms-alpha.c: Likewise.
	* bfd/xcofflink.c: Likewise.

include/

	* include/bfdlink.h (output_type): New enum.
	(bfd_link_executable): New macro.
	(bfd_link_dll): Likewise.
	(bfd_link_relocatable): Likewise.
	(bfd_link_pic): Likewise.
	(bfd_link_pie): Likewise.
	(bfd_link_info): Remove shared, executable, pie and relocatable.
	Add output_type and pic.

ld/

	* ld/ldctor.c: Replace shared, executable, relocatable and pie
	fields with bfd_link_executable, bfd_link_dll,
	bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
	* ld/ldemul.c: Likewise.
	* ld/ldfile.c: Likewise.
	* ld/ldlang.c: Likewise.
	* ld/ldmain.c: Likewise.
	* ld/ldwrite.c: Likewise.
	* ld/lexsup.c: Likewise.
	* ld/pe-dll.c: Likewise.
	* ld/plugin.c: Likewise.
	* ld/emultempl/aarch64elf.em: Likewise.
	* ld/emultempl/aix.em: Likewise.
	* ld/emultempl/alphaelf.em: Likewise.
	* ld/emultempl/armcoff.em: Likewise.
	* ld/emultempl/armelf.em: Likewise.
	* ld/emultempl/avrelf.em: Likewise.
	* ld/emultempl/beos.em: Likewise.
	* ld/emultempl/cr16elf.em: Likewise.
	* ld/emultempl/elf-generic.em: Likewise.
	* ld/emultempl/elf32.em: Likewise.
	* ld/emultempl/genelf.em: Likewise.
	* ld/emultempl/generic.em: Likewise.
	* ld/emultempl/gld960.em: Likewise.
	* ld/emultempl/gld960c.em: Likewise.
	* ld/emultempl/hppaelf.em: Likewise.
	* ld/emultempl/irix.em: Likewise.
	* ld/emultempl/linux.em: Likewise.
	* ld/emultempl/lnk960.em: Likewise.
	* ld/emultempl/m68hc1xelf.em: Likewise.
	* ld/emultempl/m68kcoff.em: Likewise.
	* ld/emultempl/m68kelf.em: Likewise.
	* ld/emultempl/metagelf.em: Likewise.
	* ld/emultempl/mipself.em: Likewise.
	* ld/emultempl/mmo.em: Likewise.
	* ld/emultempl/msp430.em: Likewise.
	* ld/emultempl/nds32elf.em: Likewise.
	* ld/emultempl/needrelax.em: Likewise.
	* ld/emultempl/nios2elf.em: Likewise.
	* ld/emultempl/pe.em: Likewise.
	* ld/emultempl/pep.em: Likewise.
	* ld/emultempl/ppc32elf.em: Likewise.
	* ld/emultempl/ppc64elf.em: Likewise.
	* ld/emultempl/sh64elf.em: Likewise.
	* ld/emultempl/solaris2.em: Likewise.
	* ld/emultempl/spuelf.em: Likewise.
	* ld/emultempl/sunos.em: Likewise.
	* ld/emultempl/tic6xdsbt.em: Likewise.
	* ld/emultempl/ticoff.em: Likewise.
	* ld/emultempl/v850elf.em: Likewise.
	* ld/emultempl/vms.em: Likewise.
	* ld/emultempl/vxworks.em: Likewise.
2015-08-18 05:51:19 -07:00
H.J. Lu 8efa2874ab Issue an error for read-only segment with dynamic IFUNC relocations
To load an ELF binary with DT_TEXTREL tag, the dynamic linker calls
__mprotect on the read-only segment with PROT_READ|PROT_WRITE before
applying dynamic relocation.  It leads to segfault when performing
IFUNC relocations since the read-only segment has no execute permission.
This patch changes x86 linker to issue an error for read-only segment
with dynamic IFUNC relocations.  Other backends with IFUNC support
may need a similar change.

bfd/

	PR ld/18801
	* elf32-i386.c (elf_i386_size_dynamic_sections): Issue an error
	for read-only segment with dynamic IFUNC relocations.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

	PR ld/18801
	* ld-i386/i386.exp: Run pr18801.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18801.d: New file.
	* ld-i386/pr18801.s: Likewise.
	* ld-x86-64/pr18801.d: Likewise.
	* ld-x86-64/pr18801.s: Likewise.
2015-08-13 04:31:38 -07:00
H.J. Lu 13a2df29c9 Set EI_OSABI to ELFOSABI_GNU for local IFUNC symbols
Since the backend elf_add_symbol_hook isn't called on local symbols,
the EI_OSABI field isn't to ELFOSABI_GNU where are local IFUNC symbols.
This patch changes the x86 backends to set has_gnu_symbols if there are
relocations against IFUNC symbols.  Other backends with IFUNC support
may need a similar change.

This patch also changes the type of has_gnu_symbols from bfd_boolean to
enum elf_gnu_symbols.

bfd/

	PR ld/18815
	* elf-bfd.h (elf_gnu_symbols): New enum.
	(elf_obj_tdata): Use elf_gnu_symbols on has_gnu_symbols.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Set
	has_gnu_symbols to elf_gnu_symbol_any.
	* elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* lfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf32-i386.c (elf_i386_check_relocs): Update has_gnu_symbols
	if there are relocations against IFUNC symbols.
	(elf_i386_add_symbol_hook): Don't check STT_GNU_IFUNC here.
	* elf64-x86-64. (elf_x86_64_check_relocs): Update has_gnu_symbols
	if there are relocations against IFUNC symbols.
	(elf_x86_64_add_symbol_hook): Don't check STT_GNU_IFUNC here.

ld/testsuite/

	PR ld/18815
	* ld-i386/i386.exp: Run pr18815.
	* ld-x86-64/x86-64.exp: Likewise.
	* ld-i386/pr18815.d: New file.
	* ld-i386/pr18815.s: Likewise.
	* ld-x86-64/pr18815.d: Likewise.
	* ld-x86-64/pr18815.s: Likewise.
2015-08-12 13:47:41 -07:00
H.J. Lu 0eace2105d Properly skip IFUNC relocations in debug sections
Use "continue" instead of "break" to skip IFUNC relocations in debug
sections.

	* elf32-i386.c (elf_i386_relocate_section): Properly skip IFUNC
	relocations in debug sections.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
2015-08-11 19:04:38 -07:00
H.J. Lu 97dc35c88d Skip IFUNC relocations in debug sections
Skip IFUNC relocations in debug sections ignored by ld.so.

bfd/

	PR ld/18808
	* elf32-i386.c (elf_i386_relocate_section): Skip IFUNC
	relocations in debug sections.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.

ld/testsuite/

	PR ld/18808
	* ld-ifunc/ifunc.exp: Add a test for PR ld/18808.
	* ld-ifunc/pr18808.out: New file.
	* ld-ifunc/pr18808a.c: Likewise.
	* ld-ifunc/pr18808b.c: Likewise.
2015-08-11 12:59:11 -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
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 fca6ae69c4 Skip extra relocations in .rel.plt/.rela.plt
Extra relocations may be added to the .rel.plt/.rela.plt section, which
are unrelated to PLT.  We should skip them when retrieving PLT entry
symbol values.

	PR binutils/18437
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip extra relocations
	in .rel.plt/.rela.plt.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-05-20 07:55:45 -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 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 bf64a9511f Add Intel MCU support to bfd
bfd/

	* Makefile.am (ALL_MACHINES): Add cpu-iamcu.lo.
	(ALL_MACHINES_CFILES): Likewise.
	* archures.c (bfd_mach_iamcu): New.
	(bfd_mach_i386_iamcu): Likewise.
	(bfd_mach_i386_iamcu_intel_syntax): Likewise.
	(bfd_iamcu_arch): Likewise.
	(bfd_archures_list): Add &bfd_iamcu_arch.
	* config.bfd (targ_selvecs): Add iamcu_elf32_vec to
	i386_elf32_vec.
	(targ_archs): Add bfd_iamcu_arch if needed.
	* configure.ac: Support iamcu_elf32_vec.
	* cpu-iamcu.c: New file.
	* elf32-i386.c (elf32_iamcu_elf_object_p): New function.
	Add support for iamcu_elf32_vec and elf32_iamcu_bed.
	* targets.c (iamcu_elf32_vec): New.
	(_bfd_target_vector): Add iamcu_elf32_vec.
	* Makefile.in: Regenerated.
	* bfd-in2.h: Likewise.
	* configure: Likewise.

binutils/testsuite/

	* binutils-all/objdump.exp (cpus_expected): Append iamcu.
2015-05-11 10:31:00 -07:00
H.J. Lu 4b71eec627 Replace input_bfd and output_bfd with abfd
The first argument to bfd_get_8/bfd_put_8 isn't used.  But we should
use something real.  Replace input_bfd and output_bfd with abfd.

	* elf32-i386.c (elf_i386_convert_mov_to_lea): Replace input_bfd
	and output_bfd with abfd.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2015-05-10 06:44:12 -07:00
H.J. Lu 914082d11b Undef elf_backend_post_process_headers for Solaris
* elf32-i386.c (elf_backend_post_process_headers): Undef for
	Solaris 2.
2015-04-30 06:52:34 -07:00
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 e3c0e32792 Replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL
When checking R_386_GOTOFF/R_X86_64_GOTOFF64 for building shared library,
we should check SYMBOL_REFERENCES_LOCAL instead of SYMBOLIC_BIND to cover
more cases.

bfd/

	* elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND
	with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against
	protected data symbol when building shared library.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Check
	R_X86_64_GOTOFF64 against undefined symbol and replace
	SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking
	R_X86_64_GOTOFF64 against protected data symbol when building
	shared library.

ld/testsuite/

	* ld-i386/i386.exp: Run protected6a.
	* ld-i386/protected6.d: Renamed to ...
	* ld-i386/protected6a.d: This.
	* ld-x86-64/hidden4.d: New file.
	* ld-x86-64/hidden4.s: Likewise.
	* ld-x86-64/hidden5.d: Likewise.
	* ld-x86-64/hidden5.s: Likewise.
	* ld-x86-64/protected6.d: Renamed to ...
	* ld-x86-64/protected6a.d: This.
	* ld-x86-64/x86-64.exp: Run hidden4, hidden5, protected6a,
	protected7a and protected7b.
2015-04-11 07:56:48 -07:00
H.J. Lu 3d9499950a Check GOTOFF reloc against protected data on x86
R_386_GOTOFF/R_X86_64_GOTOFF64 relocation shouldn't be used against
protected data symbol on x86 since with copy relocation, address of
protected data defined in the shared library may be external.

This patch will break building shared libraries with protected data
symbols using GCCs older than GCC 5 without the bug fix for

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

GCC backport request should be made in the GCC bug report above.

bfd/

	PR ld/pr17709
	* elf32-i386.c (elf_i386_relocate_section): Also check R_386_GOTOFF
	against protected data symbol when building shared library.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Also check
	R_X86_64_GOTOFF64 against protected data symbol when building
	shared library.

ld/testsuite/

	PR ld/pr17709
	* ld-i386/protected6.d: New file.
	* ld-i386/protected6.s: Likewise.
	* ld-x86-64/protected6.d: Likewise.
	* ld-x86-64/protected6.s: Likewise.
	* ld-x86-64/protected7.d: Likewise.
	* ld-x86-64/protected7.s: Likewise.
	* ld-x86-64/protected7a.d: Likewise.
	* ld-x86-64/protected7b.d: Likewise.
2015-04-10 14:02:23 -07:00
H.J. Lu f74839702e Add extern_protected_data and set it for x86
Re-apply: commit ca3fe95e46

With copy relocation, address of protected data defined in the shared
library may be external.  This patch adds extern_protected_data and
changes _bfd_elf_symbol_refs_local_p to return false for protected data
if extern_protected_data is true.

This patch will break building shared libraries with protected data
symbols using GCCs older than GCC 5 without the bug fix for

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

GCC backport request should be made in the GCC bug report above.

To get correct run-time behavior on Linux, glibc 2.22 or above are
required, which have the bug fix for

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

Backports for glibc 2.21, 2.20, 2.19 and 2.18 are on hjl/pr17711/2.21,
hjl/pr17711/2.20, hjl/pr17711/2.19 and hjl/pr17711/2.18 branches,
respectively, at

https://sourceware.org/git/?p=glibc.git;a=summary

bfd/

	PR ld/pr15228
	PR ld/pr17709
	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
	* elf32-i386.c (elf_backend_extern_protected_data): New.
	Defined to 1.
	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
	copy relocs against protected symbols if extern_protected_data
	is true.
	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
	non-function symbols if extern_protected_data is true.
	* elfxx-target.h (elf_backend_extern_protected_data): New.
	Default to 0.
	(elfNN_bed): Initialize extern_protected_data with
	elf_backend_extern_protected_data.

ld/testsuite/

	PR ld/pr15228
	PR ld/pr17709
	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
	* ld-i386/pr17709-nacl.rd: New file.
	* ld-i386/pr17709.rd: Likewise.
	* ld-i386/pr17709a.s: Likewise.
	* ld-i386/pr17709b.s: Likewise.
	* ld-i386/protected3.d: Updated.
	* ld-i386/protected3.s: Likewise.
	* ld-x86-64/pr17709-nacl.rd: New file.
	* ld-x86-64/pr17709.rd: Likewise.
	* ld-x86-64/pr17709a.s: Likewise.
	* ld-x86-64/pr17709b.s: Likewise.
	* ld-x86-64/protected3.d: Updated.
	* ld-x86-64/protected3.s: Likewise.
	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.
2015-04-10 11:06:34 -07:00
Alan Modra 8d2ea2a80a Revert "Add extern_protected_data and set it for x86"
This reverts commit ca3fe95e46.
2015-04-10 19:16:47 +09:30
H.J. Lu ca3fe95e46 Add extern_protected_data and set it for x86
With copy relocation, address of protected data defined in the shared
library may be external.  This patch adds extern_protected_data and
changes _bfd_elf_symbol_refs_local_p to return false for protected data
if extern_protected_data is true.

bfd/

	PR ld/pr15228
	PR ld/pr17709
	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
	* elf32-i386.c (elf_backend_extern_protected_data): New.
	Defined to 1.
	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
	copy relocs against protected symbols if extern_protected_data
	is true.
	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
	non-function symbols if extern_protected_data is true.
	* elfxx-target.h (elf_backend_extern_protected_data): New.
	Default to 0.
	(elfNN_bed): Initialize extern_protected_data with
	elf_backend_extern_protected_data.

ld/testsuite/

	PR ld/pr15228
	PR ld/pr17709
	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
	* ld-i386/pr17709-nacl.rd: New file.
	* ld-i386/pr17709.rd: Likewise.
	* ld-i386/pr17709a.s: Likewise.
	* ld-i386/pr17709b.s: Likewise.
	* ld-i386/protected3.d: Updated.
	* ld-i386/protected3.s: Likewise.
	* ld-x86-64/pr17709-nacl.rd: New file.
	* ld-x86-64/pr17709.rd: Likewise.
	* ld-x86-64/pr17709a.s: Likewise.
	* ld-x86-64/pr17709b.s: Likewise.
	* ld-x86-64/protected3.d: Updated.
	* ld-x86-64/protected3.s: Likewise.
	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.
2015-03-05 06:34:53 -08:00
H.J. Lu c1d11331c9 Convert mov to lea only if needed
We can convert mov to lea only if there are R_386_GOT32/R_X86_64_GOTPCREL
relocations against non IFUNC symbols.

	* elf32-i386.c (need_convert_mov_to_lea): New.
	(elf_i386_check_relocs): Set need_convert_mov_to_lea if needed.
	(elf_i386_convert_mov_to_lea): Return TRUE if
	need_convert_mov_to_lea is unset.
	* elf64-x86-64.c (need_convert_mov_to_lea): New.
	(elf_x86_64_check_relocs): Set need_convert_mov_to_lea if needed.
	(elf_x86_64_convert_mov_to_lea): Return TRUE if
	need_convert_mov_to_lea is unset.
2015-02-27 11:35:37 -08:00
H.J. Lu 576fa8831a Set root.linker_def on _TLS_MODULE_BASE_
* elf32-i386.c (elf_i386_always_size_sections): Set root.linker_def
	on _TLS_MODULE_BASE_.
	* elf64-x86-64.c (elf_x86_64_always_size_sections): Likewise.
2015-02-15 09:56:08 -08:00
Ed Maste 35181b3eaa Avoid incrementing uninitialized variable
* elf32-i386.c (elf_i386_get_plt_sym_val): Avoid incrementing
	uninitialized and unused variable.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-02-09 13:55:34 -08:00
H.J. Lu 1952c5cd7d Issue relocation in RO section warning for -z text
This patch changes linker to issue a warning for relocation in readonly
section for -z text.

bfd/

	PR ld/17935
	* elf32-i386.c (elf_i386_readonly_dynrelocs): Also issue a
	warning for relocation in readonly section for -z text.
	(elf_i386_size_dynamic_sections): Likewise.
	* elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.
	(elf_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

	PR ld/17935
	* ld-i386/i386.exp: Run pr17935-1 and pr17935-2.
	* ld-x86-64/x86-64.exp: Likewise.

	* ld-i386/pr17935-1.d: New file.
	* ld-i386/pr17935-1.s: Likewise.
	* ld-i386/pr17935-2.d: Likewise.
	* ld-i386/pr17935-2.s: Likewise.
	* ld-x86-64/pr17935-1.d: Likewise.
	* ld-x86-64/pr17935-1.s: Likewise.
	* ld-x86-64/pr17935-2.d: Likewise.
	* ld-x86-64/pr17935-2.s: Likewise.
2015-02-07 05:28:06 -08:00
Alan Modra 6346d5ca43 Fallout from recent bfd_reloc_outofrange changes
Commit ec93045b and cd21f5da introduced a large number of tic4x and
tic54x regressions, due to the new checks being wrong for targets
with octets_per_byte != 1.  To fix that I introduced a new
bfd_get_section_limit_octets and performed the check on octets rather
than byte adresses, reducing the number of bfd_octets_per_byte calls.
bfd_octets_per_byte is rather expensive..

I then wondered why the same bfd_reloc_outofrange check added to
bfd_perform_relocation wasn't also added to bfd_install_relocation.
The two functions are virtually identical and ought to remain that
way.  However, adding the same check to bfd_install_relocation
resulted in ld-elf "FAIL Link eh-group.o to eh-group" on many ELF
targets, including x64_64-linux.  The reason being that eh-group.o
has NONE relocs at the end of a section, and most targets give NONE
relocs a non-zero size.  So if we are to keep the new outofrange
check it appears that NONE relocs must have a zero size.

	* bfd-in.h (bfd_get_section_limit_octets): New define, extracted from..
	(bfd_get_section_limit): ..here.
	* reloc.c (bfd_perform_relocation): Correct bfd_reloc_outofrange check.
	(bfd_install_relocation, _bfd_final_link_relocate): Add same check here.
	* elf32-sh.c (sh_elf_reloc): Correct bfd_reloc_outofrange check.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Remove duplicated
	bfd_reloc_outofrange check.
	* bfd-in2.h: Regenerate.

	* cpu-ns32k.c (_bfd_do_ns32k_reloc_contents): Return bfd_reloc_ok
	on zero size relocs.
	* ecoff.c (ecoff_reloc_link_order): Likewise.
	* elf32-nds32.c (nds32_relocate_contents): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.

	* reloc.c (_bfd_relocate_contents): Don't bomb on zero size relocs.
	(_bfd_clear_contents): Likewise.
	* elfxx-mips.c (mips_elf_obtain_contents): Likewise.
	(mips_elf_perform_relocation): Likewise.

	* aoutx.h (aout_link_reloc_link_order): Allow for NULL return
	from malloc on zero size alloc.
	* cofflink.c (_bfd_coff_reloc_link_order): Likewise.
	* elflink.c (elf_reloc_link_order): Likewise.
	* linker.c (_bfd_generic_reloc_link_order): Likewise.
	* pdp11.c (aout_link_reloc_link_order): Likewise.
	* xcofflink.c (xcoff_reloc_link_order): Likewise.

	* aoutx.h (howto_table_ext): Ensure NONE relocs have size 3,
	bitsize 0, and complain_overflow_dont.
	* coff-sparc.c (coff_sparc_howto_table): Likewise.
	* elf-hppa.h (elf_hppa_howto_table): Likewise.
	* elf-m10200.c (elf_mn10200_howto_table): Likewise.
	* elf-m10300.c (elf_mn10300_howto_table): Likewise.
	* elf32-arc.c (elf_arc_howto_table): Likewise.
	* elf32-arm.c (elf32_arm_howto_table_1): Likewise.
	* elf32-avr.c (elf_avr_howto_table): Likewise.
	* elf32-bfin.c (bfin_howto_table): Likewise.
	* elf32-cr16.c (cr16_elf_howto_table): Likewise.
	* elf32-cris.c (cris_elf_howto_table): Likewise.
	* elf32-crx.c (crx_elf_howto_table): Likewise.
	* elf32-d10v.c (elf_d10v_howto_table): Likewise.
	* elf32-d30v.c (elf_d30v_howto_table): Likewise.
	* elf32-dlx.c (dlx_elf_howto_table): Likewise.
	* elf32-epiphany.c (epiphany_elf_howto_table): Likewise.
	* elf32-fr30.c (fr30_elf_howto_table): Likewise.
	* elf32-frv.c (elf32_frv_howto_table): Likewise.
	* elf32-h8300.c (h8_elf_howto_table): Likewise.
	* elf32-i370.c (i370_elf_howto_raw): Likewise.
	* elf32-i386.c (elf_howto_table): Likewise.
	* elf32-i860.c (elf32_i860_howto_table): Likewise.
	* elf32-i960.c (elf32_i960_relocate): Likewise.
	* elf32-ip2k.c (ip2k_elf_howto_table): Likewise.
	* elf32-iq2000.c (iq2000_elf_howto_table): Likewise.
	* elf32-lm32.c (lm32_elf_howto_table): Likewise.
	* elf32-m32c.c (m32c_elf_howto_table): Likewise.
	* elf32-m32r.c (m32r_elf_howto_table): Likewise.
	* elf32-m68hc11.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68hc12.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68k.c (howto_table): Likewise.
	* elf32-mcore.c (mcore_elf_howto_raw): Likewise.
	* elf32-mep.c (mep_elf_howto_table): Likewise.
	* elf32-metag.c (elf_metag_howto_table): Likewise.
	* elf32-microblaze.c (microblaze_elf_howto_raw): Likewise.
	* elf32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elf32-moxie.c (moxie_elf_howto_table): Likewise.
	* elf32-msp430.c (elf_msp430_howto_table): Likewise.
	* elf32-mt.c (mt_elf_howto_table): Likewise.
	* elf32-nds32.c (nds32_elf_howto_table): Likewise.
	* elf32-nios2.c (elf_nios2_howto_table_rel): Likewise.
	* elf32-or1k.c (or1k_elf_howto_table): Likewise.
	* elf32-pj.c (pj_elf_howto_table): Likewise.
	* elf32-ppc.c (ppc_elf_howto_raw): Likewise.
	* elf32-rl78.c (rl78_elf_howto_table): Likewise.
	* elf32-rx.c (rx_elf_howto_table): Likewise.
	* elf32-s390.c (elf_howto_table): Likewise.
	* elf32-score.c (elf32_score_howto_table): Likewise.
	* elf32-score7.c (elf32_score_howto_table): Likewise.
	* elf32-sh-relocs.h (R_SH_NONE): Likewise.
	* elf32-spu.c (elf_howto_table): Likewise.
	* elf32-tic6x.c (elf32_tic6x_howto_table): Likewise.
	* elf32-tilepro.c (tilepro_elf_howto_table): Likewise.
	* elf32-v850.c (v850_elf_howto_table): Likewise.
	* elf32-vax.c (howto_table): Likewise.
	* elf32-visium.c (visium_elf_howto_table): Likewise.
	* elf32-xc16x.c (xc16x_elf_howto_table): Likewise.
	* elf32-xgate.c (elf_xgate_howto_table): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_howto_table): Likewise.
	* elf32-xtensa.c (elf_howto_table): Likewise.
	* elf64-alpha.c (elf64_alpha_howto_table): Likewise.
	* elf64-mips.c (mips_elf64_howto_table_rel): Likewise.
	* elf64-mmix.c (elf_mmix_howto_table): Likewise.
	* elf64-ppc.c (ppc64_elf_howto_raw): Likewise.
	* elf64-s390.c (elf_howto_table): Likewise.
	* elf64-sh64.c (sh_elf64_howto_table): Likewise.
	* elf64-x86-64.c (x86_64_elf_howto_table): Likewise.
	* elfn32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_howto_table): Likewise.
	(elfNN_aarch64_howto_none): Likewise.
	* elfxx-ia64.c (ia64_howto_table): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_howto_table): Likewise.
	* elfxx-tilegx.c (tilegx_elf_howto_table): Likewise.
	* nlm32-sparc.c (nlm32_sparc_howto_table): Likewise.
2015-01-19 19:37:45 +10:30
H.J. Lu 6f25f22356 Skip unknown relocation
PR binutils/17512
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip unknown relocation.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-01-06 16:46:36 -08:00
H.J. Lu 533d0af0b8 Return NULL on corrupt input
PR binutils/17512
	* elf32-i386.c (elf_i386_get_plt_sym_val): Return NULL on corrupt
	input.
	* elf64-x86-64.c (elf_x86_64_get_plt_sym_val): Likewise.
2015-01-05 17:43:34 -08:00
Nick Clifton 896ca09813 More fixes for invalid memory accesses triggered by fuzzed binaries.
PR binutils/17512
	* nm.c (print_symbol): Add 'is_synthetic' parameter.  Use it to
	help initialize the info.elfinfo field.
	(print_size_symbols): Add 'synth_count' parameter.  Use it to set
	the is_synthetic parameter when calling print_symbol.
	(print_symbols): Likewise.
	(display_rel_file): Pass synth_count to printing function.
	(display_archive): Break loop if the last archive displayed
	matches the current archive.
	* size.c (display_archive): Likewise.

	* archive.c (do_slurp_bsd_armap): Make sure that the parsed sized
	is at least big enough for the header to be read.
	* elf32-i386.c (elf_i386_get_plt_sym_val): Skip unknown relocs.
	* mach-o.c (bfd_mach_o_get_synthetic_symtab): Add range checks.
	(bfd_mach_o_read_command): Prevetn duplicate error messages about
	unrecognized commands.
	* syms.c (_bfd_stab_section_find_nearest_line): Add range checks
	when indexing into the string table.
2015-01-05 23:13:50 +00:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Alan Modra 6cabe1ea46 Copy relocations against protected symbols
Copy relocs are used in a scheme to avoid dynamic text relocations in
non-PIC executables that refer to variables defined in shared
libraries.  The idea is to have the linker define any such variable in
the executable, with a copy reloc copying the initial value, then have
both the executable and shared library refer to the executable copy.
If the shared library defines the variable as protected then we have
two copies of the variable being used.

	PR 15228
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Add "info" param.
	Error on copy relocs against protected symbols.
	(elf_merge_st_other): Set h->protected_def.
	* elf-bfd.h (struct elf_link_hash_entry): Add "protected_def".
	(_bfd_elf_adjust_dynamic_copy): Update prototype.
	* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Update
	_bfd_elf_adjust_dynamic_copy call.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise.
	* elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise.
	* elf32-metag.c (elf_metag_adjust_dynamic_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise.
2014-12-12 23:35:50 +10:30
H.J. Lu 3972882e52 Add _bfd_elf_ifunc_get_synthetic_symtab
In i386 and x86-64 binaries with ifunc, relocations against .got.plt
section may not be in the same order as entries in PLT section.  This
patch adds _bfd_elf_ifunc_get_synthetic_symtab.  It takes a function
pointer which returns an array of PLT entry symbol values.  It calls
the function pointer to get the PLT entry symbol value array indexed
by relocation index, instead of calling plt_sym_val on each relocation
index.

	PR binutils/17677
	* elf-bfd.h (_bfd_elf_ifunc_get_synthetic_symtab): New prototype.
	* elf-ifunc.c (_bfd_elf_ifunc_get_synthetic_symtab): New
	function.
	* elf32-i386.c (elf_i386_plt_sym_val): Removed.
	(elf_backend_plt_sym_val): Likewise.
	(elf_i386_get_plt_sym_val): New.
	(elf_i386_get_synthetic_symtab): Likewise.
	(bfd_elf32_get_synthetic_symtab): Likewise.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Removed.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): Likewise.
	(elf_backend_plt_sym_val): Likewise.
	(elf_x86_64_get_plt_sym_val): New.
	(elf_x86_64_get_synthetic_symtab): Use
	_bfd_elf_ifunc_get_synthetic_symtab.
	(bfd_elf64_get_synthetic_symtab): Don't undefine for NaCl.
2014-12-04 16:55:39 -08:00
Nick Clifton 06614111d1 More fixes for memory access violations exposed by fuzzed binaries.
PR binutils/17512
	* dwarf.h (struct dwarf_section): Add user_data field.
	* dwarf.c (frame_need_space): Check for an over large register
	number.
	(display_debug_frames): Check the return value from
	frame_need_space.  Check for a CFA expression that is so long the
	start address wraps around.
	(debug_displays): Initialise the user_data field.
	* objdump.c (load_specific_debug_section): Save the BFD section
	pointer in the user_data field of the dwarf_section structure.
	(free_debug_section): Update BFD section data when freeing section
	contents.
	* readelf.c (load_specific_debug_section): Initialise the
	user_data field.

	* archive.c (do_slurp_coff_armap): Add range checks to prevent
	running off the end of the string table.
	* compress.c (bfd_get_full_section_contents): Return a NULL
	pointer for zero sized sections.  Do not attempt to copy a buffer
	onto itself.
	* elf-attrs.c (_bfd_elf_parse_attributes): Check for an empty
	header.  Add range checks to avoid running off the end of the
	section.
	* elf.c (bfd_elf_get_str_section): Seek before allocating so that
	if the seek fails, no memory is allocated.
	(bfd_elf_string_from_elf_section): Do not allocate a string from a
	non string section.  It only leads to trouble later on.
	(_bfd_elf_print_private_bfd_data): Check for there being too
	little external dynamic data.
	(bfd_section_from_shdr): Replace assertion with a failure mode.
	(bfd_section_from_shdr): When walking a loaded group section use
	the internal structure size, not the external size.  Check for the
	group section being empty.
	* elf32-i386.c (elf_i386_rtype_to_howto): Replace assertion with a
	failure mode.
	* elfcode.h (elf_slurp_reloc_table): Likewise.
	* reloc.c (bfd_perform_relocation): Avoid seg-fault if the howto
	parameter is NULL.
2014-12-01 16:43:46 +00:00
H.J. Lu dd7e64d45b Optimize out i386/x86-64 JUMP_SLOT relocation
When there are both PLT and GOT references to the same function symbol,
linker will create a GOTPLT slot for PLT entry and a GOT slot for GOT
reference.  A run-time JUMP_SLOT relocation is created to update the
GOTPLT slot and a run-time GLOB_DAT relocation is created to update the
GOT slot.  Both JUMP_SLOT and GLOB_DAT relocations will apply the same
symbol value to GOTPLT and GOT slots, respectively, at run-time.

This optimization combines GOTPLT and GOT slots into a single GOT slot
and removes the run-time JUMP_SLOT relocation.  It replaces the regular
PLT entry:

	indirect jump	[GOTPLT slot]
	push		relocation index
	jump		PLT0

with an GOT PLT entry with an indirect jump via the GOT slot:

	indirect jump	[GOT slot]
	nop

and resolves PLT reference to the GOT PLT entry.

We must avoid this optimization if pointer equality is needed since
we don't clear symbol value in this case and the dynamic linker won't
update the GOT slot.  Otherwise, the resulting binary will get into an
infinite loop at run-time.

bfd/

	* elf32-i386.c (elf_i386_got_plt_entry): New.
	(elf_i386_pic_got_plt_entry): Likewise.
	(elf_i386_link_hash_entry): Add plt_got.
	(elf_i386_link_hash_table): Likewise.
	(elf_i386_link_hash_newfunc): Initialize plt_got.offset to -1.
	(elf_i386_get_local_sym_hash): Likewise.
	(elf_i386_check_relocs): Create the GOT PLT if there are both
	PLT and GOT references when the regular PLT is used.
	(elf_i386_allocate_dynrelocs): Use the GOT PLT if there are
	both PLT and GOT references unless pointer equality is needed.
	(elf_i386_relocate_section): Also check the GOT PLT when
	resolving R_386_PLT32.
	(elf_i386_finish_dynamic_symbol): Use the GOT PLT if it is
	available.

	* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add plt_got.
	(elf_x86_64_link_hash_table): Likewise.
	(elf_x86_64_link_hash_newfunc): Initialize plt_got.offset to -1.
	(elf_x86_64_get_local_sym_hash): Likewise.
	(elf_x86_64_check_relocs): Create the GOT PLT if there are both
	PLT and GOT references when the regular PLT is used.
	(elf_x86_64_allocate_dynrelocs): Use the GOT PLT if there are
	both PLT and GOT references unless pointer equality is needed.
	(elf_x86_64_relocate_section): Also check the GOT PLT when
	resolving R_X86_64_PLT32.
	(elf_x86_64_finish_dynamic_symbol): Use the GOT PLT if it is
	available.

ld/

	* emulparams/elf_i386.sh (TINY_READONLY_SECTION): New.
	* emulparams/elf_x86_64.sh (TINY_READONLY_SECTION): Add .plt.got.

ld/testsuite/

	* ld-i386/i386.exp: Add run-time relocation tests for plt-main.
	* ld-i386/plt-main.rd: New file.
	* ld-x86-64/plt-main-bnd.dd: Likewise.
	* ld-x86-64/plt-main.rd: Likewise.
	* ld-x86-64/x86-64.exp: Add run-time relocation tests for
	plt-main.
2014-11-25 05:05:39 -08:00
Alan Modra f1885d1e59 Fix 17492, ld segfault with --oformat=binary
PR 17492
	* elf32-arm.c (elf32_arm_add_symbol_hook): Only set has_gnu_symbols
	on ELF output bfd.
	* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Likewise.  Handle
	STB_GNU_UNIQUE too.
2014-10-16 21:18:16 +10:30
H.J. Lu 5697705ac6 Convert mov to lea only if r_offset >= 2
* elf32-i386.c (elf_i386_convert_mov_to_lea): Skip if relocation
	offset is less than 2.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
2014-10-14 08:03:32 -07:00
H.J. Lu cf7363b42b Fix build for OLD_FREEBSD_ABI_LABEL
PR ld/17440
	* elf32-i386.c (elf_i386_fbsd_post_process_headers): Fix build
	for OLD_FREEBSD_ABI_LABEL.
2014-09-29 08:35:49 -07:00
H.J. Lu c8831961f9 Use bfd_is_abs_section to check discarded input section
bfd/

	PR ld/17306
	* elf32-i386.c (elf_i386_convert_mov_to_lea): Use bfd_is_abs_section
	to check discarded input section.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

	PR ld/17306
	* ld-i386/i386.exp (i386tests): Add tests for PR ld/17306.
	* ld-x86-64/x86-64.exp (x86_64tests): Likewise.

	* ld-i386/pr17306a.s: New file.
	* ld-i386/pr17306b.s: Likewise.
	* ld-x86-64/pr17306a.s: Likewise.
	* ld-x86-64/pr17306b.s: Likewise.
2014-08-27 07:59:48 -07:00
H.J. Lu cca5b8b64b Match PLT entry only for ELFOSABI_GNU input
* elf32-i386.c (elf_i386_plt_sym_val): Match PLT entry only for
	ELFOSABI_GNU input.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Likewise.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): Likewise.
2014-07-16 11:15:56 -07:00
H.J. Lu 144bed8d4d Properly match PLT entry against .got.plt relocation
Relocations against .got.plt section may not be in the same order as
entries in PLT section.  It is incorrect to assume that the Ith reloction
index against .got.plt section always maps to the (I + 1)th entry in PLT
section.  This patch matches the .got.plt relocation offset/index in PLT
entry against the index in .got.plt relocation table.  It only checks
R_*_JUMP_SLOT and R_*_IRELATIVE relocations.  It ignores R_*_TLS_DESC
and R_*_TLSDESC relocations since they have different PLT entries.

bfd/

	PR binutils/17154
	* elf32-i386.c (elf_i386_plt_sym_val): Only match R_*_JUMP_SLOT
	and R_*_IRELATIVE relocation offset with PLT entry.
	* elf64-x86-64.c (elf_x86_64_plt_sym_val): Likewise.
	(elf_x86_64_plt_sym_val_offset_plt_bnd): New.
	(elf_x86_64_get_synthetic_symtab): Use it.

ld/testsuite/

	PR binutils/17154
	* ld-ifunc/pr17154-i386.d: New file.
	* ld-ifunc/pr17154-x86-64.d: Likewise.
	* ld-ifunc/pr17154-x86.s: Likewise.
	* ld-x86-64/bnd-ifunc-2.d: Likewise.
	* ld-x86-64/bnd-ifunc-2.s: Likewise.
	* ld-x86-64/mpx.exp: Run bnd-ifunc-2.
	* ld-x86-64/tlsdesc-nacl.pd: Updated.
	* ld-x86-64/tlsdesc.pd: Likewise.
2014-07-16 10:57:49 -07:00
H.J. Lu 998d811a23 Update elf_i386_compute_jump_table_size
Commit e1f987424b changed how
next_tls_desc_index was set up.  This patch updates
elf_i386_compute_jump_table_size to use elf.srelplt->reloc_count
instead of next_tls_desc_index.

bfd/

	PR ld/17057
	* elf32-i386.c (elf_i386_compute_jump_table_size): Replace
	next_tls_desc_index with elf.srelplt->reloc_count.

ld/testsuite/

	PR ld/17057
	* ld-i386/i386.exp: Run pr17057.
	* ld-i386/pr17057.d: New file.
	* ld-i386/pr17057.s: Likewise.
2014-07-15 13:09:55 -07:00
Alan Modra d495ab0d84 Free linker hash table from bfd_close.
Also tidies numerous error exit paths in various link_hash_table_create
functions that failed to free memory.

include/
	* bfdlink.h (struct bfd_link_hash_table): Add hash_table_free field.
bfd/
	* archive.c: Include bfdlink.h.
	(_bfd_archive_close_and_cleanup): Call linker hash_table_free.
	* bfd.c (struct bfd): Add is_linker_output field.
	* elf-bfd.h (_bfd_elf_link_hash_table_free): Update prototype.
	* linker.c (_bfd_link_hash_table_init): Set up hash_table_free,
	link.hash and is_linker_output.
	(_bfd_generic_link_hash_table_free): Replace bfd_link_hash_table*
	param with bfd*.  Assert is_linker_output and link.hash, and
	clear them before exit.
	* elf-m10300.c (elf32_mn10300_link_hash_table_free): Replace
	bfd_link_hash_table* param with bfd*.  Hack is_linker_output
	and link.hash so we can free two linker hash tables.
	(elf32_mn10300_link_hash_table_create): Create static_hash_table
	first.  Clean up on errors.  Set hash_table_free pointer.
	* elf32-arm.c (elf32_arm_link_hash_table_free): Replace
	bfd_link_hash_table* param with bfd*.
	(elf32_arm_link_hash_table_create): Clean up on errors.  Set
	hash_table_free pointer.
	* elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc1x.c,
	* elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c, * elf32-xgate.c,
	* elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c, * elflink.c,
	* elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c,
	* xcofflink.c: Similarly.
	* simple.c (bfd_simple_get_relocated_section_contents): Save and
	clear link.next before creating linker hash table.  Clean up on
	errors, and restore link.next on exit.
	* elf32-m68hc1x.h (m68hc11_elf_bfd_link_hash_table_free): Delete.
	* elf32-xgate.h (xgate_elf_bfd_link_hash_table_free): Delete.
	* elfxx-sparc.h (_bfd_sparc_elf_link_hash_table_free): Delete.
	* libcoff-in.h (_bfd_xcoff_bfd_link_hash_table_free): Delete.
	* hash.c (bfd_hash_table_init_n): Free table on error.
	* libbfd-in.h (_bfd_generic_link_hash_table_free): Update proto.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* libcoff.h: Regenerate.
2014-06-13 19:11:39 +09:30
Alan Modra caa4096e84 Don't call bfd_link_hash_table_free
Freeing the linker hash table is a royal pain.  It can't be freed
before the _bfd_write_contents call in bfd_close, because some target
bfd_write_contents functions access the hash table.  It can't be freed
after bfd_close either, since bfd_alloc memory holding side data
structures disappears (PR17047).  Clearly the only place it can be freed
is actually in bfd_close.  This patch doesn't do that, but kills off
the existing means of freeing the hash table via a bfd target xvec call.

bfd/
	PR 17047
	* targets.c (BFD_JUMP_TABLE): Delete NAME##_bfd_link_hash_table_free.
	(struct bfd_target <_bfd_link_hash_table_free>): Delete.
	* bfd.c (bfd_link_hash_table_free): Don't define.
	* aout-adobe.c, * aout-target.h, * aout-tic30.c, * binary.c, * bout.c,
	* coff64-rs6000.c, * coffcode.h, * elf-m10300.c, * elf32-arm.c,
	* elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc11.c,
	* elf32-m68hc12.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c,
	* elf32-sparc.c, * elf32-xgate.c, * elf64-ia64-vms.c, * elf64-ppc.c,
	* elf64-sparc.c, * elf64-x86-64.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* elfxx-target.h, * i386msdos.c, * i386os9k.c, * ieee.c, * ihex.c,
	* libbfd-in.h, * libecoff.h, * mach-o-target.c, * mmo.c,
	* nlm-target.h, * oasys.c, * pef.c, * plugin.c, * ppcboot.c, * som.c,
	* srec.c, * tekhex.c, * verilog.c, * versados.c, * vms-alpha.c,
	* xsym.c: Don't define various link_hash_table_free defines, and
	remove from bfd_target vars.  Temporarily reference some of the
	target link_hash_table_free functions to avoid warnings.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	PR 17047
	* ldlang.c (output_bfd_hash_table_free_fn): Delete.
	(open_output): Don't set it..
	* ldmain.c (ld_cleanup): ..or call it.
2014-06-13 19:11:29 +09:30
Alan Modra 68faa6378d Move link_hash_table_free functions earlier
Move some code around, in preparation for a followup patch.

	* elf-m10300.c, * elf32-arm.c, * elf32-avr.c, * elf32-hppa.c,
	* elf32-i386.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-metag.c,
	* elf32-nios2.c, * elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c,
	* elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c, * xcofflink.c:
	Move link_hash_table_free functions before their corresponding
	link_hash_table_create functions.
2014-06-13 19:11:19 +09:30
Alan Modra c72f2fb2bb Make bfd.link_next field a union
This field of struct bfd is currently only used to chain together
linker input files.  This patch prepares to use the field to stash
the linker hash table, which is always created on the linker output
file.

bfd/
	* bfd.c (struct bfd): Replace link_next with a union.
	* aoutx.h, * bfd.c, * coff-ppc.c, * coff-rs6000.c, * cofflink.c,
	* ecoff.c, * elf-m10300.c, * elf32-arm.c, * elf32-avr.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-metag.c,
	* elf32-microblaze.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-or1k.c, * elf32-ppc.c, * elf32-rl78.c, * elf32-s390.c,
	* elf32-score.c, * elf32-score7.c, * elf32-sh.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilepro.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c,
	* elf64-mmix.c, * elf64-ppc.c, * elf64-s390.c, * elf64-x86-64.c,
	* elflink.c, * elfnn-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * linker.c, * pdp11.c, * peXXigen.c, * simple.c,
	* sunos.c, * vms-alpha.c, * xcofflink.c: Update for above.
	* bfd-in2.h: Regenerate.
include/
	* bfdlink.h: Update for bfd.link_next change.
ld/
	* emultempl/cr16elf.em, * emultempl/elf32.em, * emultempl/genelf.em,
	* emultempl/m68kcoff.em, * emultempl/m68kelf.em,
	* emultempl/nds32elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* ldlang.c, * ldmain.c, * pe-dll.c: Update for bfd.link_next change.
2014-06-13 19:10:57 +09:30
Alan Modra 6d00b59031 bfd target vector rationalisation
This renames the bfd targets to <cpu>_<format>_<other>_<endian>_vec.
So for example, bfd_elf32_ntradlittlemips_vec becomes
mips_elf32_ntrad_le_vec and hp300bsd_vec becomes m68k_aout_hp300bsd_vec.

bfd/
	* aix386-core.c, * aout-adobe.c, * aout-arm.c, * aout-ns32k.c,
	* aout-sparcle.c, * aout0.c, * aoutx.h, * armnetbsd.c, * bout.c,
	* cf-i386lynx.c, * cf-sparclynx.c, * cisco-core.c, * coff-alpha.c,
	* coff-apollo.c, * coff-arm.c, * coff-aux.c, * coff-go32.c,
	* coff-h8300.c, * coff-h8500.c, * coff-i386.c, * coff-i860.c,
	* coff-i960.c, * coff-m68k.c, * coff-m88k.c, * coff-mips.c,
	* coff-rs6000.c, * coff-sh.c, * coff-sparc.c, * coff-stgo32.c,
	* coff-svm68k.c, * coff-tic80.c, * coff-u68k.c, * coff-w65.c,
	* coff-we32k.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c,
	* coff64-rs6000.c, * config.bfd, * configure.com, * configure.in,
	* demo64.c, * elf-m10200.c, * elf-m10300.c, * elf32-am33lin.c,
	* elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-bfin.c,
	* elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c,
	* elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c,
	* elf32-fr30.c, * elf32-frv.c, * elf32-gen.c, * elf32-h8300.c,
	* elf32-hppa.c, * elf32-i370.c, * elf32-i386.c, * elf32-i860.c,
	* elf32-i960.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c,
	* elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c,
	* elf32-m68k.c, * elf32-m88k.c, * elf32-mcore.c, * elf32-mep.c,
	* elf32-metag.c, * elf32-microblaze.c, * elf32-mips.c, * elf32-moxie.c,
	* elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-sh-symbian.c,
	* elf32-sh.c, * elf32-sh64.c, * elf32-sparc.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilegx.c, * elf32-tilepro.c, * elf32-v850.c,
	* elf32-vax.c, * elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-gen.c, * elf64-hppa.c,
	* elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c, * elf64-ppc.c,
	* elf64-s390.c, * elf64-sh64.c, * elf64-sparc.c, * elf64-tilegx.c,
	* elf64-x86-64.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* epoc-pe-arm.c, * epoc-pei-arm.c, * hp300bsd.c, * hp300hpux.c,
	* hppabsd-core.c, * hpux-core.c, * i386aout.c, * i386bsd.c,
	* i386dynix.c, * i386freebsd.c, * i386linux.c, * i386lynx.c,
	* i386mach3.c, * i386msdos.c, * i386netbsd.c, * i386os9k.c,
	* irix-core.c, * m68k4knetbsd.c, * m68klinux.c, * m68knetbsd.c,
	* m88kmach3.c, * m88kopenbsd.c, * mach-o-i386.c, * mach-o-x86-64.c,
	* makefile.vms, * mipsbsd.c, * mmo.c, * netbsd-core.c, * newsos3.c,
	* nlm32-alpha.c, * nlm32-i386.c, * nlm32-ppc.c, * nlm32-sparc.c,
	* ns32knetbsd.c, * osf-core.c, * pc532-mach.c, * pe-arm-wince.c,
	* pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-mips.c, * pe-ppc.c,
	* pe-sh.c, * pe-x86_64.c, * pei-arm-wince.c, * pei-arm.c,
	* pei-i386.c, * pei-ia64.c, * pei-mcore.c, * pei-mips.c, * pei-ppc.c,
	* pei-sh.c, * pei-x86_64.c, * ppcboot.c, * ptrace-core.c, * riscix.c,
	* sco5-core.c, * som.c, * sparclinux.c, * sparclynx.c,
	* sparcnetbsd.c, * sunos.c, * targets.c, * trad-core.c,
	* vax1knetbsd.c, * vaxbsd.c, * vaxnetbsd.c, * versados.c,
	* vms-alpha.c, * vms-lib.c: Rename bfd targets to
	<cpu>_<format>_<other>_<endian>_vec.  Adjust associated MY macros
	on aout targets.
	* configure: Regenerate.
binutils/
	* emul_aix.c: Update bfd target vector naming.
	* testsuite/binutils-all/objcopy.exp: Likewise.
ld/
	* emultempl/metagelf.em: Update bfd target vector naming.
	* emultempl/nios2elf.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
2014-05-02 20:09:40 +09:30
Alan Modra 4b95cf5c0c Update copyright years 2014-03-05 22:16:15 +10:30
H.J. Lu c353e543fe Revert the last change
It has been fixed by

commit 4199e3b866
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jan 15 21:50:55 2014 +1030

    non-PIC references to __ehdr_start in pie and shared

    Rather than hacking every backend to not discard dynamic relocations
    against an undefined hidden __ehdr_start, make it appear to be defined
    early.  We want __ehdr_start hidden before size_dynamic_sections so
    that it isn't put in .dynsym, but we do need the dynamic relocations
    for a PIE or shared library with a non-PIC reference.  Defining it
    early is wrong if we don't actually define the symbol later to its
    proper value.  (In some cases we want to leave the symbol undefined,
    for example, when the ELF header isn't loaded, and we don't have this
    infomation available in before_allocation.)

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Revert the last
	change.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-15 03:59:42 -08:00
H.J. Lu 818d220a6f Don't discard relocs against __ehdr_start
__ehdr_start will be defined by assign_file_positions_for_non_load_sections
later.

	PR ld/16428
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't discard relocs
	against __ehdr_start.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 16:42:35 -08:00
H.J. Lu c3ce498cbd Revert the last change
* elf32-i386.c (elf_i386_allocate_dynrelocs): Revert the last
	change.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 16:40:51 -08:00
H.J. Lu d1ec1e40b5 Don't update reloc count if there are any non pc-relative relocs
PR ld/16428
	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't update reloc
	count if there are any non pc-relative relocs.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2014-01-14 10:48:39 -08:00
H.J. Lu 782450358d Default elf_backend_post_process_headers to set OSABI
* elf-bfd.h (_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf.c (_bfd_elf_compute_section_file_positions): Always
	call elf_backend_post_process_headers.
	(_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf32-hppa.c (elf_backend_post_process_headers): Removed.
	* elf32-i370.c (elf_backend_post_process_headers): Likewise.
	* elf32-msp430.c (elf_backend_post_process_headers): Likewise.
	* elf32-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf32-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-hppa.c (elf_backend_post_process_headers): Likewise.
	* elf64-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf64-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-x86-64.c (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	* elf32-i386.c (elf_backend_post_process_headers): Don't
	define as _bfd_elf_set_osabi.
	(elf_i386_fbsd_post_process_headers): Updated.
	* elf32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf32-tic6x.c (elf32_tic6x_set_osabi): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf64-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfn32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_post_process_headers): Updated.
	* elfxx-target.h (elf_backend_post_process_headers): Default
	to _bfd_elf_post_process_headers.
2013-12-17 13:41:17 -08:00
H.J. Lu bb81b736af Make room for PLT0 directly
* elf32-i386.c (elf_i386_allocate_dynrelocs): Make room for
	PLT0 directly.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
2013-11-15 09:32:24 -08:00
Roland McGrath 64b384e1e8 Set CPU type in BFD backend for x86_64-nacl* and i?86-nacl* targets
bfd/
	* archures.c (bfd_mach_i386_nacl): Fix definition so it doesn't
	collide with bfd_mach_l1om.
	* bfd-in2.h: Regenerate.

	* elf32-i386.c (elf32_i386_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf32-i386-nacl definition.
	* elf64-x86-64.c (elf64_x86_64_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf64-x86-64-nacl definition.
	(elf32_x86_64_nacl_elf_object_p): New function.
	(elf_backend_object_p): Use that in elf32-x86-64-nacl definition.

binutils/
	* objdump.c (dump_dwarf): Grok bfd_mach_x86_64_nacl and
	bfd_mach_x64_32_nacl as equivalent to bfd_mach_x86_64.

ld/testsuite/
	* ld-x86-64/x86-64.exp (mixed1, mixed2): Loosen error string match
	so it accepts "i386:nacl" in place of "i386".
	* ld-x86-64/ilp32-2.d: Likewise.
	* ld-x86-64/ilp32-3.d: Likewise.
	* ld-x86-64/lp64-2.d: Likewise.
	* ld-x86-64/lp64-3.d: Likewise.
2013-11-07 10:00:32 -08:00
H.J. Lu 62d887d406 Pass ignored unresolved relocations to ld backend
bfd/

	PR ld/4409
	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): Add an argument for
	error ignored.
	* elf-m10200.c (mn10200_elf_relocate_section): Updated.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-avr.c (elf32_avr_relocate_section): Likewise.
	* elf32-bfin.c (bfinfdpic_relocate_section): Likewise.
	(bfin_relocate_section): Likewise.
	* elf32-cr16.c (elf32_cr16_relocate_section): Likewise.
	* elf32-cr16c.c (elf32_cr16c_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-crx.c (elf32_crx_relocate_section): Likewise.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-epiphany.c (epiphany_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-h8300.c (elf32_h8_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-i860.c (elf32_i860_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_relocate_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-microblaze.c (microblaze_elf_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_relocate_section): Likewise.
	* elf32-moxie.c (moxie_elf_relocate_section): Likewise.
	* elf32-msp430.c (elf32_msp430_relocate_section): Likewise.
	* elf32-mt.c (mt_elf_relocate_section): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-openrisc.c (openrisc_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relocate_section): Likewise.
	* elf32-vax.c (elf_vax_relocate_section): Likewise.
	* elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
	* elf64-mmix.c (mmix_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.

	* elfnn-ia64.c (elfNN_ia64_relocate_section): Skip if error
	from RELOC_FOR_GLOBAL_SYMBOL in executable is ignored.

ld/testsuite/

	PR ld/4409
	* ld-ia64/error1.d: New file.
	* ld-ia64/error1.s: Likewise.
	* ld-ia64/error2.d: Likewise.
	* ld-ia64/error3.d: Likewise.
2013-11-05 10:29:44 -08:00
Roland McGrath 887badb310 bfd/
* elf-nacl.c (nacl_modify_segment_map): Fix logic reordering the
	elf_segment_map list.  If an executable segment is page-aligned
	but does not end with a full page, then append a fake section into
	the segment map entry that pads out the page.
	(nacl_final_write_processing): New function.  Write the code fill
	laid out in nacl_modify_segment_map.
	* elf-nacl.h: Declare it.
	* elf32-arm.c (elf32_arm_nacl_final_write_processing): New function.
	(elf_backend_final_write_processing): Define it for NaCl backend.
	* elf32-i386.c (elf_backend_final_write_processing): Likewise.
	* elf64-x86-64.c (elf_backend_final_write_processing): Likewise.

	* elf-nacl.c (segment_eligible_for_headers): Rename MAXPAGESIZE
	parameter to MINPAGESIZE.
	(nacl_modify_segment_map): Use minpagesize instead of maxpagesize.

	* elf32-arm.c (ELF_MINPAGESIZE, ELF_COMMONPAGESIZE): Set to
	0x10000	for NaCl targets.

ld/testsuite/
	* ld-x86-64/ilp32-4-nacl.d: Loosen .shstrtab line regexp to match
	any file offset.
	* ld-x86-64/tlsbin-nacl.rd: Update expected code segment PT_LOAD.
	* ld-x86-64/tlsbindesc-nacl.rd: Likewise.
	* ld-scripts/rgn-at3.d: XFAIL for *-*-nacl* targets.
	* ld-scripts/rgn-over8-ok.d: Likewise.
2013-08-26 19:27:25 +00:00
Will Newton 7b70956dc8 bfd/elf-ifunc.c: Add header size arg to _bfd_elf_allocate_ifunc_dyn_relocs.
bfd/ChangeLog:

2013-05-07  Will Newton  <will.newton@linaro.org>

	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Add a
	plt_header_size argument for ports where it differs from
	plt_entry_size.
	* elf-bfd.h: Likewise.
	* elf32-i386.c: Pass plt_header_size to
	_bfd_elf_allocate_ifunc_dyn_relocs.
	* elf64-x86-64.c: Likewise.
2013-05-07 17:03:52 +00:00
H.J. Lu 61315175ad Set non_ir_ref if a symbol is referenced by a non-shared object
bfd/

	PR ld/15323
	* elf32-i386.c (elf_i386_check_relocs): Set non_ir_ref if a
	symbol is referenced by a non-shared object.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.

ld/testsuite/

	PR ld/15323
	* ld-plugin/lto.exp (lto_link_tests): Add pr15323a-r.o.
	(lto_run_tests): Add a test for PR ld/15323.

	* ld-plugin/pr15323.out: New file.
	* ld-plugin/pr15323a.c: Likewise.
	* ld-plugin/pr15323b.c: Likewise.
2013-03-30 00:38:39 +00:00
Alan Modra 7e612e9848 * elf-bfd.h (enum elf_reloc_type_class): Add reloc_class_ifunc.
(struct elf_backend_data <elf_backed_reloc_type_class>): Add
	bfd_link_info* and asection* params.
	(_bfd_elf_reloc_type_class): Likewise.
	* elf.c (_bfd_elf_reloc_type_class): Likewise.
	* elflink.c (elf_link_sort_cmp2): Sort first on reloc class.
	(elf_link_sort_relocs): Update elf_backed_reloc_type_class call.
	* elf32-ppc.c (ppc_elf_reloc_type_class): Return reloc_class_ifunc
	for any reliplt reloc.  Don't return reloc_class_plt for
	R_PPC_REL24 and R_PPC_ADDR24.
	* elf64-ppc.c (allocate_got): Formatting.
	(ppc64_elf_reloc_type_class): Return reloc_class_ifunc for any
	reliplt reloc.
	* elf-m10300.c, * elf32-arm.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cris.c, * elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c,
	* elf32-m32r.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c,
	* elf32-s390.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilepro.c,
	* elf32-vax.c, * elf32-xtensa.c, * elf64-aarch64.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-s390.c, * elf64-sparc.c,
	* elf64-x86-64.c, * elfnn-ia64.c, * elfxx-tilegx.c, * elfxx-tilegx.h:
	Add extra params to the various reloc_type_class functions.
2013-03-27 13:37:51 +00:00
Alan Modra 228e534f16 * elf-bfd.h (struct core_elf_obj_tdata): New.
(struct elf_obj_tdata): Delete core_signal, core_pid, core_lwpid,
	core_program, and core_command.  Add "core".
	* elf.c (bfd_elf_mkcorefile): Allocate "core" struct.
	Update all refs to tdata core fields.
	* elf32-am33lin.c, * elf32-arm.c, * elf32-cris.c, * elf32-frv.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-m68k.c, * elf32-mips.c,
	* elf32-nios2.c, * elf32-ppc.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilegx.c,
	* elf32-tilepro.c, * elf32-xtensa.c, * elf64-aarch64.c,
	* elf64-hppa.c, * elf64-mips.c, * elf64-ppc.c, * elf64-tilegx.c,
	* elf64-x86-64.c, * elfcore.h, * elfn32-mips.c: Update all refs
	to tdata core fields.
2013-02-21 03:02:30 +00:00
Alan Modra 9f7c3e5e99 * elfcode.h (elf_checksum_contents): Free contents.
* elf-bfd.h (_bfd_elf_link_hash_table_free): Declare.
	* elflink.c (_bfd_elf_link_hash_table_free): New function.
	(elf_final_link_free): New function, extracted from..
	(bfd_elf_final_link): ..here.  Always call
	_bfd_elf_write_section_eh_frame_hdr.
	* elfxx-target.h (bfd_elfNN_bfd_link_hash_table_free): Default to
	_bfd_elf_link_hash_table_free.
	* libbfd-in.h (_bfd_merge_sections_free): Declare.
	* libbfd.h: Regenerate.
	* merge.c (_bfd_merge_sections_free): New function.
	* elf-eh-frame.c (_bfd_elf_write_section_eh_frame_hdr): Free
	hdr_info->array.
	* elf-m10300.c (elf32_mn10300_link_hash_table_free): Call
	_bfd_elf_link_hash_table_free.
	* elf32-arm.c (elf32_arm_link_hash_table_free): Likewise.
	* elf32-avr.c (elf32_avr_link_hash_table_free): Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_free): Likewise.
	* elf32-i386.c (elf_i386_link_hash_table_free): Likewise.
	* elf32-m68hc1x.c (m68hc11_elf_hash_table_free): Likewise.
	* elf32-m68k.c (elf_m68k_link_hash_table_free): Likewise.
	* elf32-metag.c (elf_metag_link_hash_table_free): Likewise.
	* elf32-xgate.c (xgate_elf_bfd_link_hash_table_free): Likewise.
	* elf64-aarch64.c (elf64_aarch64_link_hash_table_free): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_hash_table_free): Likewise.
	* elf64-ppc.c (ppc64_elf_link_hash_table_free): Likewise.
	* elf64-x86-64.c (elf_x86_64_link_hash_table_free): Likewise.
	* elfnn-ia64.c (elfNN_ia64_hash_table_free): Likewise.
	* elf32-cr16.c (elf32_cr16_link_hash_table_free): Delete.
	(bfd_elf32_bfd_link_hash_table_free): Don't define.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table_free): Delete.
	(bfd_elf32_bfd_link_hash_table_free): Dont' define.
2013-02-11 05:30:54 +00:00
Alan Modra 7bf52ea2ca * coff-arm.c (coff_arm_link_hash_table_create): Use bfd_zmalloc.
* coff-h8300.c (h8300_coff_link_hash_table_create): Likewise.
	* m68klinux.c (linux_link_hash_table_create): Likewise.
	* sparclinux.c (linux_link_hash_table_create): Likewise.
	* sunos.c (sunos_link_hash_table_create): Likewise.
	* xcofflink.c (_bfd_xcoff_bfd_link_hash_table_create): Likewise.
	* elf-m10300.c (elf32_mn10300_link_hash_table_create): Likewise.
	* elf32-arm.c (elf32_arm_link_hash_table_create): Likewise.
	* elf32-avr.c (elf32_avr_link_hash_table_create): Likewise.
	* elf32-cr16.c (elf32_cr16_link_hash_table_create): Likewise.
	* elf32-cris.c (elf_cris_link_hash_table_create): Likewise.
	* elf32-hppa.c (elf32_hppa_link_hash_table_create): Likewise.
	* elf32-i386.c (elf_i386_link_hash_table_create): Likewise.
	* elf32-lm32.c (lm32_elf_link_hash_table_create): Likewise.
	* elf32-m32r.c (m32r_elf_link_hash_table_create): Likewise.
	* elf32-m68hc1x.c (m68hc11_elf_hash_table_create): Likewise.
	* elf32-m68k.c (elf_m68k_link_hash_table_create): Likewise.
	* elf32-metag.c (elf_metag_link_hash_table_create): Likewise.
	* elf32-nios2.c (nios2_elf32_link_hash_table_create): Likewise.
	* elf32-s390.c (elf_s390_link_hash_table_create): Likewise.
	* elf32-score.c (elf32_score_link_hash_table_create): Likewise.
	* elf32-spu.c (spu_elf_link_hash_table_create): Likewise.
	* elf32-tic6x.c (elf32_tic6x_link_hash_table_create): Likewise.
	* elf32-vax.c (elf_vax_link_hash_table_create): Likewise.
	* elf32-xgate.c (xgate_elf_bfd_link_hash_table_create): Likewise.
	* elf32-xtensa.c (elf_xtensa_link_hash_table_create): Likewise.
	* elf64-aarch64.c (elf64_aarch64_link_hash_table_create): Likewise.
	* elf64-s390.c (elf_s390_link_hash_table_create): Likewise.
	* elf64-sh64.c (sh64_elf64_link_hash_table_create): Likewise.
	* elf64-x86-64.c (elf_x86_64_link_hash_table_create): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_link_hash_table_create): Likewise.
	* elflink.c (_bfd_elf_link_hash_table_create): Likewise.
	(_bfd_elf_link_hash_table_init): Assume zero fill table on entry.
2013-02-10 04:36:33 +00:00
H.J. Lu 20e52bd2b8 Don't resolve size relocation against non-zero TLS symbol
bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Don't clear pc_count
	for non-zero TLS symbol.
	(elf_i386_relocate_section): Don't resolve size relocation against
	non-zero TLS symbol.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Don't clear
	pc_count for non-zero TLS symbol.
	(elf_x86_64_relocate_section): Don't resolve size relocation
	against non-zero TLS symbol.

ld/testsuite/

	* ld-size/size-10.rd: Updated.
	* ld-size/size-8.rd: Likewise.
	* ld-size/size32-2-i386.d: Likewise.
	* ld-size/size32-2-x32.d: Likewise.
	* ld-size/size32-2-x86-64.d: Likewise.
	* ld-size/size64-2-x32.d: Likewise.
	* ld-size/size64-2-x86-64.d: Likewise.

	* ld-size/size.exp (run_time_tests): Pass --hash-styl=gnu to
	linker for size-8 test.
2013-02-07 02:15:30 +00:00
H.J. Lu 3bea1fcb8b Resolve size relocation against non-zero TLS symbol
bfd/

	* elf32-i386.c (elf_i386_allocate_dynrelocs): Clear pc_count for
	non-zero TLS symbol.
	(elf_i386_relocate_section): Resolve size relocation against
	non-zero TLS symbol.
	* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Clear pc_count
	for non-zero TLS symbol.
	(elf_x86_64_relocate_section): Resolve size relocation against
	non-zero TLS symbol.

ld/testsuite/

	* ld-size/size-10.rd: Updated.
	* ld-size/size-8.rd: Likewise.
	* ld-size/size32-2-i386.d: Likewise.
	* ld-size/size32-2-x32.d: Likewise.
	* ld-size/size32-2-x86-64.d: Likewise.
	* ld-size/size64-2-x32.d: Likewise.
	* ld-size/size64-2-x86-64.d: Likewise.
2013-01-18 22:50:30 +00:00
H.J. Lu 06a6a421f2 Count size relocation as PC-relative relocation
bfd/

	* elf32-i386.c (elf_i386_check_relocs): Count size relocation as
	PC-relative relocation.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Count size relocation
	as PC-relative relocation.

ld/testsuite/

	* ld-size/size32-3-i386.d: New file.
	* ld-size/size32-3-x32.d: Likewise.
	* ld-size/size32-3-x86-64.d: Likewise.
	* ld-size/size32-3.s: Likewise.
2013-01-17 23:36:10 +00:00
H.J. Lu 6a3e1baeae Update x86 size relocation check
* elf32-i386.c (elf_i386_check_relocs): Update R_386_SIZE32
	check.
	(elf_i386_relocate_section): Don't check TLS for R_386_SIZE32.

	* elf64-x86-64.c (elf_x86_64_check_relocs): Update R_X86_64_SIZE32
	and R_X86_64_SIZE64 check.
	(elf_x86_64_relocate_section): Don't check TLS for R_X86_64_SIZE32
	nor R_X86_64_SIZE64.
2013-01-16 22:41:03 +00:00
H.J. Lu 1788fc08f7 Add x86 size relocation support to bfd
* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

	* elf32-i386.c (elf_howto_table): Fill R_386_SIZE32 entry.
	(elf_i386_reloc_type_lookup): Support BFD_RELOC_SIZE32.
	(elf_i386_check_relocs): Handle R_386_SIZE32.
	(elf_i386_gc_sweep_hook): Likewise.
	(elf_i386_relocate_section): Likewise.

	* elf64-x86-64.c (x86_64_elf_howto_table): Fill R_X86_64_SIZE32
	and R_X86_64_SIZE64 entries.
	(x86_64_reloc_map): Add BFD_RELOC_SIZE32 and BFD_RELOC_SIZE64,
	(elf_x86_64_rtype_to_howto): Handle R_X86_64_SIZE32 for x32.
	(elf_x86_64_reloc_name_lookup): Likewise.
	(elf_x86_64_check_relocs): Handle R_X86_64_SIZE32 and
	R_X86_64_SIZE64.
	(elf_x86_64_gc_sweep_hook): Likewise.
	(elf_x86_64_relocate_section): Likewise.

	* reloc.c (bfd_reloc_code_type): Add BFD_RELOC_SIZE32 and
	BFD_RELOC_SIZE64.
2013-01-16 21:34:46 +00:00
H.J. Lu 68c4a57ee6 Set bfd errror for normal and TLS symbol access
* elf32-i386.c (elf_i386_check_relocs): Set bfd errror for
	normal and TLS symbol access.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2013-01-13 00:30:20 +00:00
H.J. Lu a5479e5ff4 Properly adjust h->plt.refcount
bfd/

	PR ld/14980
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Properly
	adjust h->plt.refcount.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.

ld/testsuite/

	PR ld/14980
	* ld-ifunc/ifunc-14c.s: New file.
	* ld-ifunc/ifunc-14e-i386.d: Likewise.
	* ld-ifunc/ifunc-14e-x86-64.d: Likewise.
	* ld-ifunc/ifunc-14f-i386.d: Likewise.
	* ld-ifunc/ifunc-14f-x86-64.d: Likewise.
2012-12-21 18:15:22 +00:00
H.J. Lu c3b0209786 Fix indentation in the last checkin 2012-12-19 19:50:40 +00:00
H.J. Lu 59d6ffb2c9 Fix and use elf_append_rel
* elf32-i386.c (elf_i386_relocate_section): Replace
	bfd_elf32_swap_reloc_out with elf_append_rel.
	(elf_i386_finish_dynamic_symbol): Likewise.

	* elflink.c (elf_append_rel): Call swap_reloc_out instead of
	swap_reloca_out.
2012-12-19 19:45:43 +00:00
H.J. Lu 13ca314985 Reindent elf_i386_finish_dynamic_symbol
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Reindent.
2012-12-19 19:41:18 +00:00
H.J. Lu ad1e85de41 Don't check IFUNC relocations in elf_*_check_relocs
* elf32-i386.c (elf_i386_check_relocs): Don't check IFUNC
	relocations here.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
2012-12-16 23:01:13 +00:00