llvm.org GIT mirror llvm / 4e5fddc
Merging r324449: ------------------------------------------------------------------------ r324449 | chandlerc | 2018-02-06 22:16:24 -0800 (Tue, 06 Feb 2018) | 15 lines [x86/retpoline] Make the external thunk names exactly match the names that happened to end up in GCC. This is really unfortunate, as the names don't have much rhyme or reason to them. Originally in the discussions it seemed fine to rely on aliases to map different names to whatever external thunk code developers wished to use but there are practical problems with that in the kernel it turns out. And since we're discovering this practical problems late and since GCC has already shipped a release with one set of names, we are forced, yet again, to blindly match what is there. Somewhat rushing this patch out for the Linux kernel folks to test and so we can get it patched into our releases. Differential Revision: https://reviews.llvm.org/D42998 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@325088 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 1 year, 6 months ago
2 changed file(s) with 68 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
2624926249
2625026250 static const char *getRetpolineSymbol(const X86Subtarget &Subtarget,
2625126251 unsigned Reg) {
26252 if (Subtarget.useRetpolineExternalThunk()) {
26253 // When using an external thunk for retpolines, we pick names that match the
26254 // names GCC happens to use as well. This helps simplify the implementation
26255 // of the thunks for kernels where they have no easy ability to create
26256 // aliases and are doing non-trivial configuration of the thunk's body. For
26257 // example, the Linux kernel will do boot-time hot patching of the thunk
26258 // bodies and cannot easily export aliases of these to loaded modules.
26259 //
26260 // Note that at any point in the future, we may need to change the semantics
26261 // of how we implement retpolines and at that time will likely change the
26262 // name of the called thunk. Essentially, there is no hard guarantee that
26263 // LLVM will generate calls to specific thunks, we merely make a best-effort
26264 // attempt to help out kernels and other systems where duplicating the
26265 // thunks is costly.
26266 switch (Reg) {
26267 case 0:
26268 assert(!Subtarget.is64Bit() && "R11 should always be available on x64");
26269 return "__x86_indirect_thunk";
26270 case X86::EAX:
26271 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26272 return "__x86_indirect_thunk_eax";
26273 case X86::ECX:
26274 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26275 return "__x86_indirect_thunk_ecx";
26276 case X86::EDX:
26277 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26278 return "__x86_indirect_thunk_edx";
26279 case X86::R11:
26280 assert(Subtarget.is64Bit() && "Should not be using a 64-bit thunk!");
26281 return "__x86_indirect_thunk_r11";
26282 }
26283 llvm_unreachable("unexpected reg for retpoline");
26284 }
26285
26286 // When targeting an internal COMDAT thunk use an LLVM-specific name.
2625226287 switch (Reg) {
2625326288 case 0:
2625426289 assert(!Subtarget.is64Bit() && "R11 should always be available on x64");
26255 return Subtarget.useRetpolineExternalThunk()
26256 ? "__llvm_external_retpoline_push"
26257 : "__llvm_retpoline_push";
26290 return "__llvm_retpoline_push";
2625826291 case X86::EAX:
26259 return Subtarget.useRetpolineExternalThunk()
26260 ? "__llvm_external_retpoline_eax"
26261 : "__llvm_retpoline_eax";
26292 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26293 return "__llvm_retpoline_eax";
2626226294 case X86::ECX:
26263 return Subtarget.useRetpolineExternalThunk()
26264 ? "__llvm_external_retpoline_ecx"
26265 : "__llvm_retpoline_ecx";
26295 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26296 return "__llvm_retpoline_ecx";
2626626297 case X86::EDX:
26267 return Subtarget.useRetpolineExternalThunk()
26268 ? "__llvm_external_retpoline_edx"
26269 : "__llvm_retpoline_edx";
26298 assert(!Subtarget.is64Bit() && "Should not be using a 32-bit thunk!");
26299 return "__llvm_retpoline_edx";
2627026300 case X86::R11:
26271 return Subtarget.useRetpolineExternalThunk()
26272 ? "__llvm_external_retpoline_r11"
26273 : "__llvm_retpoline_r11";
26301 assert(Subtarget.is64Bit() && "Should not be using a 64-bit thunk!");
26302 return "__llvm_retpoline_r11";
2627426303 }
2627526304 llvm_unreachable("unexpected reg for retpoline");
2627626305 }
2222 ; X64: callq bar
2323 ; X64-DAG: movl %[[x]], %edi
2424 ; X64-DAG: movq %[[fp]], %r11
25 ; X64: callq __llvm_external_retpoline_r11
25 ; X64: callq __x86_indirect_thunk_r11
2626 ; X64: movl %[[x]], %edi
2727 ; X64: callq bar
2828 ; X64-DAG: movl %[[x]], %edi
2929 ; X64-DAG: movq %[[fp]], %r11
30 ; X64: jmp __llvm_external_retpoline_r11 # TAILCALL
30 ; X64: jmp __x86_indirect_thunk_r11 # TAILCALL
3131
3232 ; X64FAST-LABEL: icall_reg:
3333 ; X64FAST: callq bar
34 ; X64FAST: callq __llvm_external_retpoline_r11
34 ; X64FAST: callq __x86_indirect_thunk_r11
3535 ; X64FAST: callq bar
36 ; X64FAST: jmp __llvm_external_retpoline_r11 # TAILCALL
36 ; X64FAST: jmp __x86_indirect_thunk_r11 # TAILCALL
3737
3838 ; X86-LABEL: icall_reg:
3939 ; X86-DAG: movl 12(%esp), %[[fp:[^ ]*]]
4242 ; X86: calll bar
4343 ; X86: movl %[[fp]], %eax
4444 ; X86: pushl %[[x]]
45 ; X86: calll __llvm_external_retpoline_eax
45 ; X86: calll __x86_indirect_thunk_eax
4646 ; X86: pushl %[[x]]
4747 ; X86: calll bar
4848 ; X86: movl %[[fp]], %eax
4949 ; X86: pushl %[[x]]
50 ; X86: calll __llvm_external_retpoline_eax
50 ; X86: calll __x86_indirect_thunk_eax
5151 ; X86-NOT: # TAILCALL
5252
5353 ; X86FAST-LABEL: icall_reg:
5454 ; X86FAST: calll bar
55 ; X86FAST: calll __llvm_external_retpoline_eax
55 ; X86FAST: calll __x86_indirect_thunk_eax
5656 ; X86FAST: calll bar
57 ; X86FAST: calll __llvm_external_retpoline_eax
57 ; X86FAST: calll __x86_indirect_thunk_eax
5858
5959
6060 @global_fp = external global void (i32)*
7171 ; X64-LABEL: icall_global_fp:
7272 ; X64-DAG: movl %edi, %[[x:[^ ]*]]
7373 ; X64-DAG: movq global_fp(%rip), %r11
74 ; X64: callq __llvm_external_retpoline_r11
74 ; X64: callq __x86_indirect_thunk_r11
7575 ; X64-DAG: movl %[[x]], %edi
7676 ; X64-DAG: movq global_fp(%rip), %r11
77 ; X64: jmp __llvm_external_retpoline_r11 # TAILCALL
77 ; X64: jmp __x86_indirect_thunk_r11 # TAILCALL
7878
7979 ; X64FAST-LABEL: icall_global_fp:
8080 ; X64FAST: movq global_fp(%rip), %r11
81 ; X64FAST: callq __llvm_external_retpoline_r11
81 ; X64FAST: callq __x86_indirect_thunk_r11
8282 ; X64FAST: movq global_fp(%rip), %r11
83 ; X64FAST: jmp __llvm_external_retpoline_r11 # TAILCALL
83 ; X64FAST: jmp __x86_indirect_thunk_r11 # TAILCALL
8484
8585 ; X86-LABEL: icall_global_fp:
8686 ; X86: movl global_fp, %eax
8787 ; X86: pushl 4(%esp)
88 ; X86: calll __llvm_external_retpoline_eax
88 ; X86: calll __x86_indirect_thunk_eax
8989 ; X86: addl $4, %esp
9090 ; X86: movl global_fp, %eax
91 ; X86: jmp __llvm_external_retpoline_eax # TAILCALL
91 ; X86: jmp __x86_indirect_thunk_eax # TAILCALL
9292
9393 ; X86FAST-LABEL: icall_global_fp:
94 ; X86FAST: calll __llvm_external_retpoline_eax
95 ; X86FAST: jmp __llvm_external_retpoline_eax # TAILCALL
94 ; X86FAST: calll __x86_indirect_thunk_eax
95 ; X86FAST: jmp __x86_indirect_thunk_eax # TAILCALL
9696
9797
9898 %struct.Foo = type { void (%struct.Foo*)** }
113113 ; X64: movq (%[[obj]]), %[[vptr:[^ ]*]]
114114 ; X64: movq 8(%[[vptr]]), %[[fp:[^ ]*]]
115115 ; X64: movq %[[fp]], %r11
116 ; X64: callq __llvm_external_retpoline_r11
116 ; X64: callq __x86_indirect_thunk_r11
117117 ; X64-DAG: movq %[[obj]], %rdi
118118 ; X64-DAG: movq %[[fp]], %r11
119 ; X64: jmp __llvm_external_retpoline_r11 # TAILCALL
119 ; X64: jmp __x86_indirect_thunk_r11 # TAILCALL
120120
121121 ; X64FAST-LABEL: vcall:
122 ; X64FAST: callq __llvm_external_retpoline_r11
123 ; X64FAST: jmp __llvm_external_retpoline_r11 # TAILCALL
122 ; X64FAST: callq __x86_indirect_thunk_r11
123 ; X64FAST: jmp __x86_indirect_thunk_r11 # TAILCALL
124124
125125 ; X86-LABEL: vcall:
126126 ; X86: movl 8(%esp), %[[obj:[^ ]*]]
128128 ; X86: movl 4(%[[vptr]]), %[[fp:[^ ]*]]
129129 ; X86: movl %[[fp]], %eax
130130 ; X86: pushl %[[obj]]
131 ; X86: calll __llvm_external_retpoline_eax
131 ; X86: calll __x86_indirect_thunk_eax
132132 ; X86: addl $4, %esp
133133 ; X86: movl %[[fp]], %eax
134 ; X86: jmp __llvm_external_retpoline_eax # TAILCALL
134 ; X86: jmp __x86_indirect_thunk_eax # TAILCALL
135135
136136 ; X86FAST-LABEL: vcall:
137 ; X86FAST: calll __llvm_external_retpoline_eax
138 ; X86FAST: jmp __llvm_external_retpoline_eax # TAILCALL
137 ; X86FAST: calll __x86_indirect_thunk_eax
138 ; X86FAST: jmp __x86_indirect_thunk_eax # TAILCALL
139139
140140
141141 declare void @direct_callee()