binutils-gdb/ld/testsuite
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
..
config Ensure ld testsuite gcc -B options precede $CC -B options 2014-07-07 13:37:16 +09:30
ld-aarch64 [AArch64] Cortex-A53 erratum 835769 linker workaround 2014-10-24 11:39:35 +01:00
ld-alpha
ld-arm Calculate ARM arch attribute after relaxation 2014-11-21 11:54:39 +08:00
ld-auto-import
ld-avr When relaxing, update size of symbols. 2014-11-03 20:34:13 +00:00
ld-bootstrap Don't link FreeBSD tests with -ldl. 2014-05-19 08:49:55 +02:00
ld-cdtest
ld-checks
ld-cris
ld-crx
ld-cygwin
ld-d10v
ld-discard
ld-elf Discard zero address range eh_frame FDEs 2014-10-04 22:49:32 +09:30
ld-elfcomm
ld-elfvers ld/testsuite: Disable non-PIC shared library tests on ARM 2014-07-10 09:32:42 +01:00
ld-elfvsb
ld-elfweak
ld-fastcall
ld-frv
ld-gc
ld-h8300
ld-i386 Optimize out i386/x86-64 JUMP_SLOT relocation 2014-11-25 05:05:39 -08:00
ld-ia64
ld-ifunc Always load function pointer into a stack variable 2014-11-20 11:29:45 -08:00
ld-libs
ld-linkonce
ld-m68hc11
ld-m68k
ld-mep
ld-metag
ld-mips-elf Update .MIPS.abiflags to support MIPS R6 2014-11-05 10:48:38 +00:00
ld-misc
ld-mmix Move ELF section headers to end of object file 2014-09-11 00:15:51 +09:30
ld-mn10300
ld-nds32
ld-nios2
ld-pe
ld-pie
ld-plugin Find lto plugin when using gcc-5.0 2014-09-22 19:04:48 +09:30
ld-powerpc Power/GAS: Don't set VLE annotation for non-VLE processors/instructions 2014-08-22 16:52:20 +01:00
ld-s390
ld-scripts Fix ld tests with sysroot=/ and --enable-targets=all and test --print-sysroot 2014-10-17 13:11:42 +02:00
ld-selective
ld-sh Move ELF section headers to end of object file 2014-09-11 00:15:51 +09:30
ld-shared ld/aarch64: xfail non-PIC shared object tests on aarch64 2014-05-20 09:47:29 +01:00
ld-size
ld-sparc
ld-spu
ld-srec
ld-tic6x Move ELF section headers to end of object file 2014-09-11 00:15:51 +09:30
ld-tilegx
ld-tilepro
ld-undefined
ld-unique ld/testsuite/ld-unique: Fix running unique tests on ARM 2014-10-30 11:06:43 +00:00
ld-v850
ld-vax-elf
ld-versados
ld-vxworks
ld-x86-64 Optimize out i386/x86-64 JUMP_SLOT relocation 2014-11-25 05:05:39 -08:00
ld-xc16x
ld-xstormy16
ld-xtensa
lib Run IFUNC run-time tests only if IFUNC is supported 2014-11-20 08:59:42 -08:00
ChangeLog Optimize out i386/x86-64 JUMP_SLOT relocation 2014-11-25 05:05:39 -08:00
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-9303