gcc/gcc/config
H.J. Lu 7799a85590 x86: Add -mindirect-branch=
Add -mindirect-branch= option to convert indirect call and jump to call
and return thunks.  The default is 'keep', which keeps indirect call and
jump unmodified.  'thunk' converts indirect call and jump to call and
return thunk.  'thunk-inline' converts indirect call and jump to inlined
call and return thunk.  'thunk-extern' converts indirect call and jump to
external call and return thunk provided in a separate object file.  You
can control this behavior for a specific function by using the function
attribute indirect_branch.

2 kinds of thunks are geneated.  Memory thunk where the function address
is at the top of the stack:

__x86_indirect_thunk:
	call L2
L1:
	pause
	lfence
	jmp L1
L2:
	lea 8(%rsp), %rsp|lea 4(%esp), %esp
	ret

Indirect jmp via memory, "jmp mem", is converted to

	push memory
	jmp __x86_indirect_thunk

Indirect call via memory, "call mem", is converted to

	jmp L2
L1:
	push [mem]
	jmp __x86_indirect_thunk
L2:
	call L1

Register thunk where the function address is in a register, reg:

__x86_indirect_thunk_reg:
	call	L2
L1:
	pause
	lfence
	jmp	L1
L2:
	movq	%reg, (%rsp)|movl    %reg, (%esp)
	ret

where reg is one of (r|e)ax, (r|e)dx, (r|e)cx, (r|e)bx, (r|e)si, (r|e)di,
(r|e)bp, r8, r9, r10, r11, r12, r13, r14 and r15.

Indirect jmp via register, "jmp reg", is converted to

	jmp __x86_indirect_thunk_reg

Indirect call via register, "call reg", is converted to

	call __x86_indirect_thunk_reg

gcc/

	Backport from mainline
	* config/i386/i386-opts.h (indirect_branch): New.
	* config/i386/i386-protos.h (ix86_output_indirect_jmp): Likewise.
	* config/i386/i386.c (ix86_using_red_zone): Disallow red-zone
	with local indirect jump when converting indirect call and jump.
	(ix86_set_indirect_branch_type): New.
	(ix86_set_current_function): Call ix86_set_indirect_branch_type.
	(indirectlabelno): New.
	(indirect_thunk_needed): Likewise.
	(indirect_thunk_bnd_needed): Likewise.
	(indirect_thunks_used): Likewise.
	(indirect_thunks_bnd_used): Likewise.
	(INDIRECT_LABEL): Likewise.
	(indirect_thunk_name): Likewise.
	(output_indirect_thunk): Likewise.
	(output_indirect_thunk_function): Likewise.
	(ix86_output_indirect_branch_via_reg): Likewise.
	(ix86_output_indirect_branch_via_push): Likewise.
	(ix86_output_indirect_branch): Likewise.
	(ix86_output_indirect_jmp): Likewise.
	(ix86_code_end): Call output_indirect_thunk_function if needed.
	(ix86_output_call_insn): Call ix86_output_indirect_branch if
	needed.
	(ix86_handle_fndecl_attribute): Handle indirect_branch.
	(ix86_attribute_table): Add indirect_branch.
	* config/i386/i386.h (machine_function): Add indirect_branch_type
	and has_local_indirect_jump.
	* config/i386/i386.md (indirect_jump): Set has_local_indirect_jump
	to true.
	(tablejump): Likewise.
	(*indirect_jump): Use ix86_output_indirect_jmp.
	(*tablejump_1): Likewise.
	(simple_return_indirect_internal): Likewise.
	* config/i386/i386.opt (mindirect-branch=): New option.
	(indirect_branch): New.
	(keep): Likewise.
	(thunk): Likewise.
	(thunk-inline): Likewise.
	(thunk-extern): Likewise.
	* doc/extend.texi: Document indirect_branch function attribute.
	* doc/invoke.texi: Document -mindirect-branch= option.

gcc/testsuite/

	Backport from mainline
	* gcc.target/i386/indirect-thunk-1.c: New test.
	* gcc.target/i386/indirect-thunk-2.c: Likewise.
	* gcc.target/i386/indirect-thunk-3.c: Likewise.
	* gcc.target/i386/indirect-thunk-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-5.c: Likewise.
	* gcc.target/i386/indirect-thunk-6.c: Likewise.
	* gcc.target/i386/indirect-thunk-7.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-1.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-2.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-3.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-5.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-6.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-7.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-8.c: Likewise.
	* gcc.target/i386/indirect-thunk-bnd-1.c: Likewise.
	* gcc.target/i386/indirect-thunk-bnd-2.c: Likewise.
	* gcc.target/i386/indirect-thunk-bnd-3.c: Likewise.
	* gcc.target/i386/indirect-thunk-bnd-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-1.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-2.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-3.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-5.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-6.c: Likewise.
	* gcc.target/i386/indirect-thunk-extern-7.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-1.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-2.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-3.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-5.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-6.c: Likewise.
	* gcc.target/i386/indirect-thunk-inline-7.c: Likewise.

From-SVN: r256732
2018-01-16 02:59:42 -08:00
..
aarch64 PR60580: Fix frame pointer option magic 2017-11-03 15:01:10 +00:00
alpha backport: re PR rtl-optimization/83628 (performance regression when accessing arrays on alpha) 2018-01-14 16:45:38 +01:00
arc [ARC] Backport r254866. 2017-11-21 12:57:16 +01:00
arm [arm] PR target/82975: Guard against reg_renumber being NULL in arm.h 2018-01-08 18:42:50 +00:00
avr backport: re PR target/81910 ([avr] ICE with "address" attribute on type) 2017-08-22 07:55:34 +00:00
bfin [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
c6x c6x.c (hwloop_optimize): Handle case where the old iteration reg is used after the loop. 2017-03-15 13:36:50 +00:00
cr16 Fix numerous typos in comments 2017-04-03 23:30:56 +01:00
cris cris.md (cris_preferred_reload_class): Return GENNONACR_REGS rather than GENERAL_REGS. 2017-04-12 08:58:23 -06:00
epiphany RTEMS/EPIPHANY: Add RTEMS support 2018-01-08 13:39:11 +00:00
fr30 Update copyright years. 2017-01-01 13:07:43 +01:00
frv re PR tree-optimization/79256 (FAIL: gcc.dg/vect/pr25413a.c execution test) 2017-02-07 11:29:06 +00:00
ft32 Update copyright years. 2017-01-01 13:07:43 +01:00
h8300 Update copyright years. 2017-01-01 13:07:43 +01:00
i386 x86: Add -mindirect-branch= 2018-01-16 02:59:42 -08:00
ia64 Update copyright years. 2017-01-01 13:07:43 +01:00
iq2000 iq2000.c (final_prescan_insn): Do not separate a CALL and NOTE_INSN_CALL_ARG_LOCATION. 2017-04-07 08:26:05 -06:00
lm32 [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
m32c [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
m32r Update copyright years. 2017-01-01 13:07:43 +01:00
m68k [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
mcore Update copyright years. 2017-01-01 13:07:43 +01:00
microblaze [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
mips backport: re PR target/82880 (gcc --help=target --help=optimizers hangs on mips) 2017-12-15 22:52:06 +01:00
mmix Update copyright years. 2017-01-01 13:07:43 +01:00
mn10300 Update copyright years. 2017-01-01 13:07:43 +01:00
moxie [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
msp430 Remove trailing period from various diagnostic messages (PR translation/79923) 2017-03-11 01:43:48 +00:00
nds32 PR target/79928 - nds32: misspelled diagnostic: not support -fpic 2017-03-08 16:29:42 -07:00
nios2 [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
nvptx Backport "Insert diverging jump alap in nvptx_single" 2017-07-18 13:06:07 +00:00
pa backport: pa.c (pa_legitimate_address_p): For scaled indexing... 2017-12-17 17:02:10 +00:00
pdp11 pdp11.md (movmemhi): Adjust operand numbers to match_scratch operand is highest. 2017-03-13 11:43:19 -06:00
riscv RISC-V: Fix -msave-restore bug with sibcalls. 2018-01-08 17:01:45 -08:00
rl78 Update copyright years. 2017-01-01 13:07:43 +01:00
rs6000 backport: re PR target/83629 (ICE: in decompose_normal_address, at rtlanal.c:6329 with -O2 -fPIC -frename-registers --param=sched-autopref-queue-depth=nnn) 2018-01-15 23:08:12 +01:00
rx backport: re PR target/81819 ([RX] internal compiler error: in rx_is_restricted_memory_address, at config/rx/rx.c:311) 2018-01-12 12:12:38 +00:00
s390 [Committed] S/390: Support z14 as CPU name. 2017-07-31 11:33:18 +00:00
sh backport: re PR target/83111 ([sh] stack smashing detected in gen_udivsi3) 2017-11-23 14:08:12 +00:00
sparc SPARC: Make sure that jump is to a label in errata workaround 2017-12-19 08:07:22 +00:00
spu Update copyright years. 2017-01-01 13:07:43 +01:00
stormy16 Update copyright years. 2017-01-01 13:07:43 +01:00
tilegx re PR target/78862 (tile*: ICE with -fstack-protetor-strong) 2017-02-03 18:41:57 +00:00
tilepro re PR target/78862 (tile*: ICE with -fstack-protetor-strong) 2017-02-03 18:41:57 +00:00
v850 [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
vax Update copyright years. 2017-01-01 13:07:43 +01:00
visium visium.md (type): Add trap. 2017-02-23 23:04:00 +00:00
vms Update copyright years. 2017-01-01 13:07:43 +01:00
xtensa xtensa: enable address sanitizer 2017-12-05 14:31:41 +00:00
README
darwin-c.c Update copyright years. 2017-01-01 13:07:43 +01:00
darwin-driver.c darwin-driver.c (darwin_driver_init): Const-correctness fixes for first_period and second_period variables. 2017-01-02 22:36:40 -07:00
darwin-f.c Update copyright years. 2017-01-01 13:07:43 +01:00
darwin-ppc-ldouble-patch.def Update copyright years. 2017-01-01 13:07:43 +01:00
darwin-protos.h Update copyright years. 2017-01-01 13:07:43 +01:00
darwin-sections.def Update copyright years. 2017-01-01 13:07:43 +01:00
darwin.c Update copyright years. 2017-01-01 13:07:43 +01:00
darwin.h re PR driver/49726 (-g0 file.S -g does not produce debug info) 2017-01-16 22:33:07 +01:00
darwin.opt Update copyright years. 2017-01-01 13:07:43 +01:00
darwin9.h re PR driver/49726 (-g0 file.S -g does not produce debug info) 2017-01-16 22:33:07 +01:00
darwin10.h Update copyright years. 2017-01-01 13:07:43 +01:00
darwin12.h Update copyright years. 2017-01-01 13:07:43 +01:00
dbx.h Update copyright years. 2017-01-01 13:07:43 +01:00
dbxcoff.h Update copyright years. 2017-01-01 13:07:43 +01:00
dbxelf.h Update copyright years. 2017-01-01 13:07:43 +01:00
default-c.c Update copyright years. 2017-01-01 13:07:43 +01:00
dragonfly-stdint.h Update copyright years. 2017-01-01 13:07:43 +01:00
dragonfly.h Update copyright years. 2017-01-01 13:07:43 +01:00
dragonfly.opt Update copyright years. 2017-01-01 13:07:43 +01:00
elfos.h Update copyright years. 2017-01-01 13:07:43 +01:00
flat.h Update copyright years. 2017-01-01 13:07:43 +01:00
freebsd-nthr.h Update copyright years. 2017-01-01 13:07:43 +01:00
freebsd-spec.h Update copyright years. 2017-01-01 13:07:43 +01:00
freebsd-stdint.h Update copyright years. 2017-01-01 13:07:43 +01:00
freebsd.h Update copyright years. 2017-01-01 13:07:43 +01:00
freebsd.opt Update copyright years. 2017-01-01 13:07:43 +01:00
fuchsia.h fuchsia-elf.h: New file. 2017-01-10 18:00:43 +00:00
fused-madd.opt Update copyright years. 2017-01-01 13:07:43 +01:00
g.opt Update copyright years. 2017-01-01 13:07:43 +01:00
glibc-c.c Update copyright years. 2017-01-01 13:07:43 +01:00
glibc-stdint.h Update copyright years. 2017-01-01 13:07:43 +01:00
gnu-user.h PR driver/81523: Make -static override -pie 2017-08-29 17:52:44 +09:30
gnu-user.opt Update copyright years. 2017-01-01 13:07:43 +01:00
gnu.h Update copyright years. 2017-01-01 13:07:43 +01:00
host-darwin.c Update copyright years. 2017-01-01 13:07:43 +01:00
host-darwin.h Update copyright years. 2017-01-01 13:07:43 +01:00
host-hpux.c Update copyright years. 2017-01-01 13:07:43 +01:00
host-linux.c Update copyright years. 2017-01-01 13:07:43 +01:00
host-openbsd.c Update copyright years. 2017-01-01 13:07:43 +01:00
host-solaris.c Update copyright years. 2017-01-01 13:07:43 +01:00
hpux-stdint.h
hpux11.opt Update copyright years. 2017-01-01 13:07:43 +01:00
initfini-array.h Update copyright years. 2017-01-01 13:07:43 +01:00
kfreebsd-gnu.h Update copyright years. 2017-01-01 13:07:43 +01:00
kopensolaris-gnu.h Update copyright years. 2017-01-01 13:07:43 +01:00
linux-android.h Update copyright years. 2017-01-01 13:07:43 +01:00
linux-android.opt Update copyright years. 2017-01-01 13:07:43 +01:00
linux-protos.h Update copyright years. 2017-01-01 13:07:43 +01:00
linux.c Update copyright years. 2017-01-01 13:07:43 +01:00
linux.h Update copyright years. 2017-01-01 13:07:43 +01:00
linux.opt Update copyright years. 2017-01-01 13:07:43 +01:00
lynx.h Update copyright years. 2017-01-01 13:07:43 +01:00
lynx.opt Update copyright years. 2017-01-01 13:07:43 +01:00
netbsd-elf.h Update copyright years. 2017-01-01 13:07:43 +01:00
netbsd-elf.opt Update copyright years. 2017-01-01 13:07:43 +01:00
netbsd-protos.h backport: re PR target/39570 (cabs and cabsf are named differently on NetBSD 5) 2017-09-29 09:38:08 +00:00
netbsd-stdint.h Update copyright years. 2017-01-01 13:07:43 +01:00
netbsd.c backport: re PR target/39570 (cabs and cabsf are named differently on NetBSD 5) 2017-09-29 09:38:08 +00:00
netbsd.h backport: re PR target/77480 (netbsd specfile will not link against libc when building -shared (+patch)) 2017-09-29 21:34:00 +00:00
netbsd.opt Update copyright years. 2017-01-01 13:07:43 +01:00
newlib-stdint.h Update copyright years. 2017-01-01 13:07:43 +01:00
openbsd-libpthread.h Update copyright years. 2017-01-01 13:07:43 +01:00
openbsd-stdint.h
openbsd.h Update copyright years. 2017-01-01 13:07:43 +01:00
openbsd.opt Update copyright years. 2017-01-01 13:07:43 +01:00
phoenix.h Update copyright years. 2017-01-01 13:07:43 +01:00
print-sysroot-suffix.sh Update copyright years. 2017-01-01 13:07:43 +01:00
rpath.opt Update copyright years. 2017-01-01 13:07:43 +01:00
rtems.h [RTEMS] Add GCC Runtime Library Exception 2017-07-26 08:31:09 +00:00
rtems.opt Update copyright years. 2017-01-01 13:07:43 +01:00
sol2-c.c Update copyright years. 2017-01-01 13:07:43 +01:00
sol2-clearcap.map
sol2-clearcapv2.map
sol2-cxx.c Update copyright years. 2017-01-01 13:07:43 +01:00
sol2-protos.h Update copyright years. 2017-01-01 13:07:43 +01:00
sol2-stubs.c Update copyright years. 2017-01-01 13:07:43 +01:00
sol2.c Update copyright years. 2017-01-01 13:07:43 +01:00
sol2.h Adapt Solaris 12 references 2017-11-21 09:31:12 +00:00
sol2.opt Update copyright years. 2017-01-01 13:07:43 +01:00
t-darwin Update copyright years. 2017-01-01 13:07:43 +01:00
t-glibc Update copyright years. 2017-01-01 13:07:43 +01:00
t-libunwind Update copyright years. 2017-01-01 13:07:43 +01:00
t-linux Update copyright years. 2017-01-01 13:07:43 +01:00
t-lynx Update copyright years. 2017-01-01 13:07:43 +01:00
t-netbsd backport: re PR target/39570 (cabs and cabsf are named differently on NetBSD 5) 2017-09-29 09:38:08 +00:00
t-openbsd
t-pnt16-warn Update copyright years. 2017-01-01 13:07:43 +01:00
t-rtems
t-slibgcc
t-sol2 Update copyright years. 2017-01-01 13:07:43 +01:00
t-sysroot-suffix
t-vxworks Update copyright years. 2017-01-01 13:07:43 +01:00
t-winnt Update copyright years. 2017-01-01 13:07:43 +01:00
tm-dwarf2.h
usegas.h Update copyright years. 2017-01-01 13:07:43 +01:00
usegld.h
vx-common.h Update copyright years. 2017-01-01 13:07:43 +01:00
vxworks-dummy.h Update copyright years. 2017-01-01 13:07:43 +01:00
vxworks.c Update copyright years. 2017-01-01 13:07:43 +01:00
vxworks.h Update copyright years. 2017-01-01 13:07:43 +01:00
vxworks.opt Update copyright years. 2017-01-01 13:07:43 +01:00
vxworksae.h Update copyright years. 2017-01-01 13:07:43 +01:00
winnt-c.c Update copyright years. 2017-01-01 13:07:43 +01:00
x-cflags-O1
x-darwin
x-hpux
x-linux
x-openbsd
x-solaris

README

This directory contains machine-specific files for the GNU C compiler.
It has a subdirectory for each basic CPU type.
The only files in this directory itself
are some .h files that pertain to particular operating systems
and are used for more than one CPU type.