binutils-gdb/ld/emulparams
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
..
aarch64elf32.sh ld/ChangeLog: 2013-11-21 11:17:50 -08:00
aarch64elf32b.sh
aarch64elf.sh aarch64: Add support for GNU indirect functions. 2013-10-03 14:46:09 +00:00
aarch64elfb.sh
aarch64linux32.sh 2014-02-11 Andrew Pinski <apinski@cavium.com> 2014-02-11 11:16:30 -08:00
aarch64linux32b.sh 2014-02-11 Andrew Pinski <apinski@cavium.com> 2014-02-11 11:16:30 -08:00
aarch64linux.sh [AArch64] Define LP64 LE loader name. 2014-01-20 18:18:52 +00:00
aarch64linuxb.sh [AArch64] Define LP64 BE linker name. 2014-01-20 18:20:04 +00:00
aix5ppc.sh
aix5rs6.sh
aixppc.sh
aixrs6.sh
alpha.sh
alphavms.sh
arcelf.sh
arm_epoc_pe.sh
arm_wince_pe.sh
armaoutb.sh
armaoutl.sh
armcoff.sh
armelf_fbsd.sh
armelf_linux_eabi.sh
armelf_linux.sh
armelf_nacl.sh
armelf_nbsd.sh
armelf_vxworks.sh
armelf.sh
armelfb_linux_eabi.sh
armelfb_linux.sh
armelfb_nacl.sh
armelfb_nbsd.sh
armelfb.sh
armnbsd.sh
armnto.sh
armpe.sh
armsymbian.sh
avr1.sh
avr2.sh
avr3.sh
avr4.sh
avr5.sh
avr6.sh
avr25.sh
avr31.sh
avr35.sh
avr51.sh
avrxmega1.sh
avrxmega2.sh
avrxmega3.sh
avrxmega4.sh
avrxmega5.sh
avrxmega6.sh
avrxmega7.sh
bfin.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
coff_i860.sh
coff_sparc.sh
crisaout.sh
criself.sh
crislinux.sh * emulparams/crislinux.sh (COMMONPAGESIZE): Define. 2014-01-10 01:25:26 +01:00
d10velf.sh
d30v_e.sh
d30v_o.sh
d30velf.sh
delta68.sh
elf32_dlx.sh
elf32_i860.sh
elf32_i960.sh
elf32_sparc_sol2.sh
elf32_sparc_vxworks.sh
elf32_sparc.sh
elf32_spu.sh
elf32_tic6x_be.sh
elf32_tic6x_elf_be.sh
elf32_tic6x_elf_le.sh
elf32_tic6x_le.sh
elf32_tic6x_linux_be.sh
elf32_tic6x_linux_le.sh
elf32_x86_64_nacl.sh
elf32_x86_64.sh Skip directories with LIBPATH_SUFFIX_SKIP suffix 2014-01-15 20:09:09 -08:00
elf32am33lin.sh
elf32b4300.sh
elf32bfinfd.sh
elf32bmip.sh
elf32bmipn32-defs.sh
elf32bmipn32.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32bsmip.sh
elf32btsmip_fbsd.sh
elf32btsmip.sh
elf32btsmipn32_fbsd.sh
elf32btsmipn32.sh
elf32cr16.sh
elf32cr16c.sh
elf32crx.sh
elf32ebmip.sh
elf32ebmipvxworks.sh
elf32elmip.sh
elf32elmipvxworks.sh
elf32epiphany_4x4.sh
elf32epiphany.sh
elf32fr30.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32frv.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32frvfd.sh
elf32i370.sh
elf32ip2k.sh
elf32iq10.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32iq2000.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32l4300.sh
elf32lm32.sh
elf32lm32fd.sh
elf32lmip.sh
elf32lppc.sh
elf32lppclinux.sh
elf32lppcnto.sh
elf32lppcsim.sh
elf32lr5900.sh
elf32lr5900n32.sh
elf32lsmip.sh
elf32ltsmip_fbsd.sh
elf32ltsmip.sh
elf32ltsmipn32_fbsd.sh
elf32ltsmipn32.sh
elf32m32c.sh
elf32mb_linux.sh
elf32mbel_linux.sh
elf32mcore.sh
elf32mep.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32metag.sh
elf32microblaze.sh
elf32microblazeel.sh
elf32mipswindiss.sh
elf32moxie.sh
elf32mt.sh
elf32openrisc.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf32ppc_fbsd.sh
elf32ppc.sh
elf32ppccommon.sh * emulparams/elf32ppccommon.sh (LIBPATH_SUFFIX): Provide 32-bit 2013-09-24 06:29:39 +00:00
elf32ppclinux.sh
elf32ppcnto.sh
elf32ppcsim.sh
elf32ppcvxworks.sh
elf32ppcwindiss.sh
elf32rl78.sh
elf32rx.sh
elf32tilegx_be.sh
elf32tilegx.sh
elf32tilepro.sh
elf32vax.sh
elf32xc16x.sh
elf32xc16xl.sh
elf32xc16xs.sh
elf32xstormy16.sh
elf32xtensa.sh
elf64_aix.sh
elf64_ia64_fbsd.sh
elf64_ia64_vms.sh
elf64_ia64.sh
elf64_s390.sh
elf64_sparc_fbsd.sh
elf64_sparc_sol2.sh
elf64_sparc.sh
elf64alpha_fbsd.sh
elf64alpha_nbsd.sh
elf64alpha.sh
elf64bmip-defs.sh
elf64bmip.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf64btsmip_fbsd.sh
elf64btsmip.sh
elf64hppa.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
elf64lppc.sh
elf64ltsmip_fbsd.sh
elf64ltsmip.sh
elf64mmix.sh
elf64ppc_fbsd.sh
elf64ppc.sh * emulparams/elf32ppccommon.sh (LIBPATH_SUFFIX): Provide 32-bit 2013-09-24 06:29:39 +00:00
elf64rdos.sh
elf64tilegx_be.sh
elf64tilegx.sh
elf_fbsd.sh
elf_i386_be.sh
elf_i386_chaos.sh
elf_i386_fbsd.sh
elf_i386_ldso.sh
elf_i386_nacl.sh
elf_i386_sol2.sh
elf_i386_vxworks.sh
elf_i386.sh Skip directories with LIBPATH_SUFFIX_SKIP suffix 2014-01-15 20:09:09 -08:00
elf_k1om_fbsd.sh
elf_k1om.sh Define IREL_IN_PLT for elf_k1om.sh and elf_l1om.sh 2013-12-20 08:27:02 -08:00
elf_l1om_fbsd.sh
elf_l1om.sh Define IREL_IN_PLT for elf_k1om.sh and elf_l1om.sh 2013-12-20 08:27:02 -08:00
elf_nacl.sh
elf_s390.sh
elf_x86_64_fbsd.sh
elf_x86_64_nacl.sh
elf_x86_64_sol2.sh
elf_x86_64.sh Create the second PLT for BND relocations 2014-02-19 11:48:23 -08:00
gld960.sh
gld960coff.sh
h8300.sh
h8300elf.sh
h8300h.sh
h8300helf.sh
h8300hn.sh
h8300hnelf.sh
h8300s.sh
h8300self.sh
h8300sn.sh
h8300snelf.sh
h8300sx.sh
h8300sxelf.sh
h8300sxn.sh
h8300sxnelf.sh
h8500.sh
h8500b.sh
h8500c.sh
h8500m.sh
h8500s.sh
hp3hpux.sh
hp300bsd.sh
hppa64linux.sh
hppaelf.sh
hppalinux.sh
hppanbsd.sh
hppaobsd.sh
i386aout.sh
i386beos.sh strip off +x bits on non-executable/script files 2013-12-07 02:03:03 -05:00
i386bsd.sh
i386coff.sh
i386go32.sh
i386linux.sh
i386lynx.sh
i386mach.sh
i386moss.sh
i386msdos.sh
i386nbsd.sh
i386nto.sh
i386nw.sh
i386pe_posix.sh
i386pe.sh
i386pep.sh
lnk960.sh
m32relf_linux.sh
m32relf.sh
m32rlelf_linux.sh
m32rlelf.sh
m68hc11elf.sh
m68hc11elfb.sh
m68hc12elf.sh
m68hc12elfb.sh
m68k4knbsd.sh
m68kaout.sh
m68kaux.sh
m68kcoff.sh
m68kelf.sh
m68kelfnbsd.sh
m68klinux.sh
m68knbsd.sh
m68kpsos.sh
m88kbcs.sh
mcorepe.sh
mmo.sh
mn10200.sh
mn10300.sh
msp430all.sh The MSP430 linker contains emulations for old and obsolete MCU types. 2014-01-28 12:25:48 +00:00
nds32belf16m.sh Add support for Andes NDS32: 2013-12-13 11:52:32 +00:00
nds32belf_linux.sh Add support for Andes NDS32: 2013-12-13 11:52:32 +00:00
nds32belf.sh Add support for Andes NDS32: 2013-12-13 11:52:32 +00:00
nds32elf16m.sh Allow ld target customiser script to force on disk scripts. 2014-01-17 10:41:49 +10:30
nds32elf_linux.sh Allow ld target customiser script to force on disk scripts. 2014-01-17 10:41:49 +10:30
nds32elf.sh Allow ld target customiser script to force on disk scripts. 2014-01-17 10:41:49 +10:30
news.sh
nios2elf.sh Nios II CALL26 linker relaxation 2014-01-30 17:47:07 -08:00
nios2linux.sh Nios II CALL26 linker relaxation 2014-01-30 17:47:07 -08:00
ns32knbsd.sh
or32.sh
or32elf.sh
pc532macha.sh
pdp11.sh
pjelf.sh
pjlelf.sh
plt_unwind.sh
ppclynx.sh
ppcmacos.sh
ppcnw.sh
ppcpe.sh
README
riscix.sh
scoreelf.sh
sh.sh
shelf32_linux.sh
shelf32_nbsd.sh
shelf32.sh
shelf64_nbsd.sh
shelf64.sh
shelf_fd.sh
shelf_linux.sh
shelf_nbsd.sh
shelf_nto.sh
shelf_uclinux.sh
shelf_vxworks.sh
shelf.sh
shl.sh
shlelf32_linux.sh
shlelf32_nbsd.sh
shlelf32.sh
shlelf64_nbsd.sh
shlelf64.sh
shlelf_fd.sh
shlelf_linux.sh
shlelf_nbsd.sh
shlelf_nto.sh
shlelf_vxworks.sh
shlelf.sh
shlsymbian.sh
shpe.sh
solaris2.sh
sparcaout.sh
sparclinux.sh
sparcnbsd.sh
st2000.sh
sun3.sh
sun4.sh
tic3xcoff_onchip.sh
tic3xcoff.sh
tic4xcoff.sh
tic30aout.sh
tic30coff.sh
tic54xcoff.sh
tic80coff.sh
v850_rh850.sh
v850.sh
vanilla.sh
vax.sh
vaxnbsd.sh
vsta.sh
vxworks.sh
w65.sh
xgateelf.sh
z80.sh
z8001.sh
z8002.sh

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.

The files in this directory are read by genscripts.sh as shell commands.
They set parameters for the emulations.

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.