summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/X86/empty-function.ll
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-04-21 20:58:12 +0000
committerHans Wennborg <hans@hanshq.net>2017-04-21 20:58:12 +0000
commitcb3e81071495dd2f63af38f6b50945a47939f9d7 (patch)
tree7826b28b7b5818fd416502e8c46a184c8188ce39 /llvm/test/CodeGen/X86/empty-function.ll
parent79873efcfb3ae8c4da5f8c6855105a9e496ce1f7 (diff)
downloadbcm5719-llvm-cb3e81071495dd2f63af38f6b50945a47939f9d7.tar.gz
bcm5719-llvm-cb3e81071495dd2f63af38f6b50945a47939f9d7.zip
X86: Don't emit zero-byte functions on Windows
Empty functions can lead to duplicate entries in the Guard CF Function Table of a binary due to multiple functions sharing the same RVA, causing the kernel to refuse to load that binary. We had a terrific bug due to this in Chromium. It turns out we were already doing this for Mach-O in certain situations. This patch expands the code for that in AsmPrinter::EmitFunctionBody() and renames TargetInstrInfo::getNoopForMachoTarget() to simply getNoop() since it seems it was used for not just Mach-O anyway. Differential Revision: https://reviews.llvm.org/D32330 llvm-svn: 301040
Diffstat (limited to 'llvm/test/CodeGen/X86/empty-function.ll')
-rw-r--r--llvm/test/CodeGen/X86/empty-function.ll22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/X86/empty-function.ll b/llvm/test/CodeGen/X86/empty-function.ll
new file mode 100644
index 00000000000..92bebd0ab1a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/empty-function.ll
@@ -0,0 +1,22 @@
+; RUN: llc < %s -mtriple=i686-pc-win32 | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
+; RUN: llc < %s -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=CHECK -check-prefix=WIN64 %s
+; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck -check-prefix=LINUX %s
+
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-pc-windows-msvc18.0.0"
+
+; Don't emit empty functions on Windows; it can lead to duplicate entries
+; (multiple functions sharing the same RVA) in the Guard CF Function Table which
+; the kernel refuses to load.
+
+define void @f() {
+entry:
+ unreachable
+
+; CHECK-LABEL: f:
+; WIN32: nop
+; WIN64: ud2
+; LINUX-NOT: nop
+; LINUX-NOT: ud2
+
+}
OpenPOWER on IntegriCloud