56d343
commit 5315d05c7295fbb9345d85d6bf7cbe7c975a19c8
56d343
Author: hjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
56d343
Date:   Tue Jan 16 11:22:01 2018 +0000
56d343
56d343
    HJ patch #5
56d343
56d343
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
56d343
index e73389b..15cfe83 100644
56d343
--- a/gcc/config/i386/i386.c
56d343
+++ b/gcc/config/i386/i386.c
56d343
@@ -4634,6 +4634,19 @@ ix86_set_indirect_branch_type (tree fndecl)
56d343
 	}
56d343
       else
56d343
 	cfun->machine->indirect_branch_type = ix86_indirect_branch;
56d343
+
56d343
+      /* -mcmodel=large is not compatible with -mindirect-branch=thunk
56d343
+	 nor -mindirect-branch=thunk-extern.  */
56d343
+      if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
56d343
+	  && ((cfun->machine->indirect_branch_type
56d343
+	       == indirect_branch_thunk_extern)
56d343
+	      || (cfun->machine->indirect_branch_type
56d343
+		  == indirect_branch_thunk)))
56d343
+	error ("%<-mindirect-branch=%s%> and %<-mcmodel=large%> are not "
56d343
+	       "compatible",
56d343
+	       ((cfun->machine->indirect_branch_type
56d343
+		 == indirect_branch_thunk_extern)
56d343
+		? "thunk-extern" : "thunk"));
56d343
     }
56d343
 
56d343
   if (cfun->machine->function_return_type == indirect_branch_unset)
56d343
@@ -4659,6 +4672,19 @@ ix86_set_indirect_branch_type (tree fndecl)
56d343
 	}
56d343
       else
56d343
 	cfun->machine->function_return_type = ix86_function_return;
56d343
+
56d343
+      /* -mcmodel=large is not compatible with -mfunction-return=thunk
56d343
+	 nor -mfunction-return=thunk-extern.  */
56d343
+      if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
56d343
+	  && ((cfun->machine->function_return_type
56d343
+	       == indirect_branch_thunk_extern)
56d343
+	      || (cfun->machine->function_return_type
56d343
+		  == indirect_branch_thunk)))
56d343
+	error ("%<-mfunction-return=%s%> and %<-mcmodel=large%> are not "
56d343
+	       "compatible",
56d343
+	       ((cfun->machine->function_return_type
56d343
+		 == indirect_branch_thunk_extern)
56d343
+		? "thunk-extern" : "thunk"));
56d343
     }
56d343
 }
56d343
 
56d343
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
56d343
index 4a365c7..7b33803 100644
56d343
--- a/gcc/doc/invoke.texi
56d343
+++ b/gcc/doc/invoke.texi
56d343
@@ -14659,6 +14659,11 @@ to external call and return thunk provided in a separate object file.
56d343
 You can control this behavior for a specific function by using the
56d343
 function attribute @code{indirect_branch}.  @xref{Function Attributes}.
56d343
 
56d343
+Note that @option{-mcmodel=large} is incompatible with
56d343
+@option{-mindirect-branch=thunk} nor
56d343
+@option{-mindirect-branch=thunk-extern} since the thunk function may
56d343
+not be reachable in large code model.
56d343
+
56d343
 @item -mfunction-return=@var{choice}
56d343
 @opindex -mfunction-return
56d343
 Convert function return with @var{choice}.  The default is @samp{keep},
56d343
@@ -14670,6 +14675,11 @@ object file.  You can control this behavior for a specific function by
56d343
 using the function attribute @code{function_return}.
56d343
 @xref{Function Attributes}.
56d343
 
56d343
+Note that @option{-mcmodel=large} is incompatible with
56d343
+@option{-mfunction-return=thunk} nor
56d343
+@option{-mfunction-return=thunk-extern} since the thunk function may
56d343
+not be reachable in large code model.
56d343
+
56d343
 @item -mindirect-branch-register
56d343
 @opindex -mindirect-branch-register
56d343
 Force indirect call and jump via register.
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c
56d343
new file mode 100644
56d343
index 0000000..a0674bd
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c
56d343
@@ -0,0 +1,7 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=thunk-inline -mfunction-return=keep -mcmodel=large" } */
56d343
+
56d343
+void
56d343
+bar (void)
56d343
+{
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c
56d343
new file mode 100644
56d343
index 0000000..7a80a89
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c
56d343
@@ -0,0 +1,7 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=thunk -mfunction-return=keep -mcmodel=large" } */
56d343
+
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mindirect-branch=thunk' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c
56d343
new file mode 100644
56d343
index 0000000..d4d45c5
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c
56d343
@@ -0,0 +1,7 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=thunk-extern -mfunction-return=keep -mcmodel=large" } */
56d343
+
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mindirect-branch=thunk-extern' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c
56d343
new file mode 100644
56d343
index 0000000..3a2aead
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c
56d343
@@ -0,0 +1,9 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+__attribute__ ((indirect_branch("thunk-extern")))
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mindirect-branch=thunk-extern' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c
56d343
new file mode 100644
56d343
index 0000000..8e52f03
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c
56d343
@@ -0,0 +1,9 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+__attribute__ ((indirect_branch("thunk-inline")))
56d343
+void
56d343
+bar (void)
56d343
+{
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c
56d343
new file mode 100644
56d343
index 0000000..bdaa4f6
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c
56d343
@@ -0,0 +1,9 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+__attribute__ ((indirect_branch("thunk")))
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mindirect-branch=thunk' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-17.c b/gcc/testsuite/gcc.target/i386/ret-thunk-17.c
56d343
new file mode 100644
56d343
index 0000000..0605e2c
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-17.c
56d343
@@ -0,0 +1,7 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mfunction-return=thunk -mindirect-branch=keep -mcmodel=large" } */
56d343
+
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mfunction-return=thunk' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-18.c b/gcc/testsuite/gcc.target/i386/ret-thunk-18.c
56d343
new file mode 100644
56d343
index 0000000..307019d
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-18.c
56d343
@@ -0,0 +1,8 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mfunction-return=thunk-extern -mindirect-branch=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mfunction-return=thunk-extern' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-19.c b/gcc/testsuite/gcc.target/i386/ret-thunk-19.c
56d343
new file mode 100644
56d343
index 0000000..772617f
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-19.c
56d343
@@ -0,0 +1,8 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */
56d343
+
56d343
+__attribute__ ((function_return("thunk")))
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mfunction-return=thunk' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-20.c b/gcc/testsuite/gcc.target/i386/ret-thunk-20.c
56d343
new file mode 100644
56d343
index 0000000..1e9f9bd
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-20.c
56d343
@@ -0,0 +1,9 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+__attribute__ ((function_return("thunk-extern")))
56d343
+void
56d343
+bar (void)
56d343
+{ /* { dg-error "'-mfunction-return=thunk-extern' and '-mcmodel=large' are not compatible" } */
56d343
+}
56d343
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-21.c b/gcc/testsuite/gcc.target/i386/ret-thunk-21.c
56d343
new file mode 100644
56d343
index 0000000..eea07f7
56d343
--- /dev/null
56d343
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-21.c
56d343
@@ -0,0 +1,9 @@
56d343
+/* { dg-do compile { target { lp64 } } } */
56d343
+/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */
56d343
+/* { dg-additional-options "-fPIC" { target fpic } } */
56d343
+
56d343
+__attribute__ ((function_return("thunk-inline")))
56d343
+void
56d343
+bar (void)
56d343
+{
56d343
+}