Files
binutils-gdb/bfd
H.J. Lu 0ff2b86e7c Create the second PLT for BND relocations
Intel MPX introduces 4 bound registers, which will be used for parameter
passing in x86-64.  Bound registers are cleared by branch instructions.
Branch instructions with BND prefix will keep bound register contents.
This leads to 2 requirements to 64-bit MPX run-time:

1. Dynamic linker (ld.so) should save and restore bound registers during
symbol lookup.
2. Change the current 16-byte PLT0:

  ff 35 08 00 00 00	pushq  GOT+8(%rip)
  ff 25 00 10 00	jmpq  *GOT+16(%rip)
  0f 1f 40 00		nopl   0x0(%rax)

and 16-byte PLT1:

  ff 25 00 00 00 00    	jmpq   *name@GOTPCREL(%rip)
  68 00 00 00 00       	pushq  $index
  e9 00 00 00 00       	jmpq   PLT0

which clear bound registers, to preserve bound registers.

We use 2 new relocations:

to mark branch instructions with BND prefix.

When linker sees any R_X86_64_PC32_BND or R_X86_64_PLT32_BND relocations,
it switches to a different PLT0:

  ff 35 08 00 00 00	pushq  GOT+8(%rip)
  f2 ff 25 00 10 00	bnd jmpq *GOT+16(%rip)
  0f 1f 00		nopl   (%rax)

to preserve bound registers for symbol lookup and it also creates an
external PLT section, .pl.bnd.  Linker will create a BND PLT1 entry
in .plt:

  68 00 00 00 00       	pushq  $index
  f2 e9 00 00 00 00     bnd jmpq PLT0
  0f 1f 44 00 00        nopl 0(%rax,%rax,1)

and a 8-byte BND PLT entry in .plt.bnd:

  f2 ff 25 00 00 00 00  bnd jmpq *name@GOTPCREL(%rip)
  90			nop

Otherwise, linker will create a legacy PLT1 entry in .plt:

  68 00 00 00 00       	pushq  $index
  e9 00 00 00 00        jmpq PLT0
  66 0f 1f 44 00 00     nopw 0(%rax,%rax,1)

and a 8-byte legacy PLT in .plt.bnd:

  ff 25 00 00 00 00     jmpq  *name@GOTPCREL(%rip)
  66 90                 xchg  %ax,%ax

The initial value of the GOT entry for "name" will be set to the the
"pushq" instruction in the corresponding entry in .plt.  Linker will
resolve reference of symbol "name" to the entry in the second PLT,
.plt.bnd.

Prelink stores the offset of pushq of PLT1 (plt_base + 0x10) in GOT[1]
and GOT[1] is stored in GOT[3].  We can undo prelink in GOT by computing
the corresponding the pushq offset with

GOT[1] + (GOT offset - &GOT[3]) * 2

Since for each entry in .plt except for PLT0 we create a 8-byte entry in
.plt.bnd, there is extra 8-byte per PLT symbol.

We also investigated the 16-byte entry for .plt.bnd.  We compared the
8-byte entry vs the the 16-byte entry for .plt.bnd on Sandy Bridge.
There are no performance differences in SPEC CPU 2000/2006 as well as
micro benchmarks.

Pros:
	No change to undo prelink in dynamic linker.
	Only 8-byte memory overhead for each PLT symbol.
Cons:
	Extra .plt.bnd section is needed.
	Extra 8 byte for legacy branches to PLT.
	GDB is unware of the new layout of .plt and .plt.bnd.

bfd/

	* elf64-x86-64.c (elf_x86_64_bnd_plt0_entry): New.
	(elf_x86_64_legacy_plt_entry): Likewise.
	(elf_x86_64_bnd_plt_entry): Likewise.
	(elf_x86_64_legacy_plt2_entry): Likewise.
	(elf_x86_64_bnd_plt2_entry): Likewise.
	(elf_x86_64_bnd_arch_bed): Likewise.
	(elf_x86_64_link_hash_entry): Add has_bnd_reloc and plt_bnd.
	(elf_x86_64_link_hash_table): Add plt_bnd.
	(elf_x86_64_link_hash_newfunc): Initialize has_bnd_reloc and
	plt_bnd.
	(elf_x86_64_copy_indirect_symbol): Also copy has_bnd_reloc.
	(elf_x86_64_check_relocs): Create the second PLT for Intel MPX
	in 64-bit mode.
	(elf_x86_64_allocate_dynrelocs): Handle the second PLT for IFUNC
	symbols.  Resolve call to the second PLT if it is created.
	(elf_x86_64_size_dynamic_sections): Keep the second PLT section.
	(elf_x86_64_relocate_section): Resolve PLT references to the
	second PLT if it is created.
	(elf_x86_64_finish_dynamic_symbol): Use BND PLT0 and fill the
	second PLT entry for BND relocation.
	(elf_x86_64_finish_dynamic_sections): Use MPX backend data if
	the second PLT is created.
	(elf_x86_64_get_synthetic_symtab): New.
	(bfd_elf64_get_synthetic_symtab): Likewise.  Undefine for NaCl.

ld/

	* emulparams/elf_x86_64.sh (TINY_READONLY_SECTION): New.

ld/testsuite/

	* ld-x86-64/mpx.exp: Run bnd-ifunc-1 and bnd-plt-1.
	* ld-x86-64/bnd-ifunc-1.d: New file.
	* ld-x86-64/bnd-ifunc-1.s: Likewise.
	* ld-x86-64/bnd-plt-1.d: Likewise.
2014-02-19 11:48:23 -08:00
..
2013-10-25 14:02:58 +00:00
2014-02-10 09:59:35 +10:30
2012-12-17 16:56:12 +00:00
2012-11-08 03:03:26 +00:00
2013-01-10 20:03:55 +00:00
2012-11-07 05:51:37 +00:00
2012-11-09 08:29:34 +00:00
2014-01-02 12:14:37 +00:00
2013-12-13 11:52:32 +00:00
2014-02-03 08:42:42 -08:00
2012-12-17 16:56:12 +00:00
2013-08-23 07:54:19 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2013-02-04 05:10:44 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2012-12-10 12:48:03 +00:00
2013-07-24 14:12:41 +00:00
2012-11-09 08:29:34 +00:00
2012-10-18 17:42:29 +00:00
2013-01-10 20:03:55 +00:00
2012-11-06 05:51:18 +00:00
2013-02-04 05:25:41 +00:00
2013-02-04 05:25:41 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-12-13 11:52:32 +00:00
2012-12-17 16:56:12 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-08-26 22:18:07 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 09:49:22 +00:00
2013-12-13 11:52:32 +00:00
2013-01-10 20:03:55 +00:00
2013-05-16 16:34:51 +00:00
2013-03-30 10:14:15 +00:00
2013-12-17 11:48:18 -08:00
2014-01-15 03:59:42 -08:00
2013-10-09 05:23:23 +00:00
2013-12-17 11:48:18 -08:00
2013-01-10 09:49:22 +00:00
2013-12-17 11:48:18 -08:00
2013-12-13 11:52:32 +00:00
2013-12-13 11:52:32 +00:00
2014-02-03 08:42:42 -08:00
2014-01-30 17:47:07 -08:00
2014-02-17 17:00:19 +10:30
2013-03-30 10:14:15 +00:00
2013-03-30 10:14:15 +00:00
2013-12-17 11:48:18 -08:00
2013-12-17 14:10:03 -08:00
2014-01-07 09:17:05 -07:00
2013-02-07 03:44:26 +00:00
2013-08-26 19:27:25 +00:00
2013-02-18 10:40:19 +00:00
2013-02-21 02:29:11 +00:00
2014-01-02 12:14:37 +00:00
2013-06-25 18:02:34 +00:00
2013-06-24 14:28:17 +00:00
2014-01-02 12:14:37 +00:00
2014-02-03 08:42:42 -08:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2014-01-02 12:14:37 +00:00
2013-01-10 20:03:55 +00:00
2012-12-17 16:56:12 +00:00
2013-12-13 11:52:32 +00:00
2013-12-13 11:52:32 +00:00
2014-01-02 12:14:37 +00:00
2014-01-02 12:14:37 +00:00
2012-10-18 17:42:29 +00:00
2012-10-18 17:42:29 +00:00
2014-01-02 14:30:18 +00:00
2013-01-10 20:03:55 +00:00
2012-12-17 16:56:12 +00:00
2012-12-17 16:56:12 +00:00
2014-02-03 08:42:42 -08:00
2013-01-10 20:03:55 +00:00
2014-02-03 20:24:20 +10:30
2014-02-17 08:32:22 +01:00
2013-04-08 20:08:21 +00:00
2013-04-08 20:08:21 +00:00
2013-05-22 06:13:59 +00:00
2013-12-13 11:52:32 +00:00
2013-01-10 20:03:55 +00:00
2013-01-10 20:03:55 +00:00
2012-12-17 16:56:12 +00:00
2013-01-10 20:03:55 +00:00
2014-02-19 09:30:43 +10:30
2014-01-02 12:14:37 +00:00
2012-12-17 16:56:12 +00:00
2013-10-09 18:02:48 +00:00

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

BFD is an object file library.  It permits applications to use the
same routines to process object files regardless of their format.

BFD is used by the GNU debugger, assembler, linker, and the binary
utilities.

The documentation on using BFD is scanty and may be occasionally
incorrect.  Pointers to documentation problems, or an entirely
rewritten manual, would be appreciated.

There is some BFD internals documentation in doc/bfdint.texi which may
help programmers who want to modify BFD.

BFD is normally built as part of another package.  See the build
instructions for that package, probably in a README file in the
appropriate directory.

BFD supports the following configure options:

  --target=TARGET
	The default target for which to build the library.  TARGET is
	a configuration target triplet, such as sparc-sun-solaris.
  --enable-targets=TARGET,TARGET,TARGET...
	Additional targets the library should support.  To include
	support for all known targets, use --enable-targets=all.
  --enable-64-bit-bfd
	Include support for 64 bit targets.  This is automatically
	turned on if you explicitly request a 64 bit target, but not
	for --enable-targets=all.  This requires a compiler with a 64
	bit integer type, such as gcc.
  --enable-shared
	Build BFD as a shared library.
  --with-mmap
	Use mmap when accessing files.  This is faster on some hosts,
	but slower on others.  It may not work on all hosts.

Report bugs with BFD to bug-binutils@gnu.org.

Patches are encouraged.  When sending patches, always send the output
of diff -u or diff -c from the original file to the new file.  Do not
send default diff output.  Do not make the diff from the new file to
the original file.  Remember that any patch must not break other
systems.  Remember that BFD must support cross compilation from any
host to any target, so patches which use ``#ifdef HOST'' are not
acceptable.  Please also read the ``Reporting Bugs'' section of the
gcc manual.

Bug reports without patches will be remembered, but they may never get
fixed until somebody volunteers to fix them.

Copyright (C) 2012 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.