Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame^] | 1 | From 8e0d9bf93e2e2ec03c544572aef4b03a8e7090f3 Mon Sep 17 00:00:00 2001 |
| 2 | From: "H.J. Lu" <hjl.tools@gmail.com> |
| 3 | Date: Sat, 13 Jan 2018 18:01:54 -0800 |
| 4 | Subject: [PATCH 08/12] x86: Disallow -mindirect-branch=/-mfunction-return= |
| 5 | with -mcmodel=large |
| 6 | |
| 7 | Since the thunk function may not be reachable in large code model, |
| 8 | -mcmodel=large is incompatible with -mindirect-branch=thunk, |
| 9 | -mindirect-branch=thunk-extern, -mfunction-return=thunk and |
| 10 | -mfunction-return=thunk-extern. Issue an error when they are used with |
| 11 | -mcmodel=large. |
| 12 | |
| 13 | gcc/ |
| 14 | |
| 15 | Backport from mainline |
| 16 | 2018-01-14 H.J. Lu <hongjiu.lu@intel.com> |
| 17 | |
| 18 | * config/i386/i386.c (ix86_set_indirect_branch_type): Disallow |
| 19 | -mcmodel=large with -mindirect-branch=thunk, |
| 20 | -mindirect-branch=thunk-extern, -mfunction-return=thunk and |
| 21 | -mfunction-return=thunk-extern. |
| 22 | * doc/invoke.texi: Document -mcmodel=large is incompatible with |
| 23 | -mindirect-branch=thunk, -mindirect-branch=thunk-extern, |
| 24 | -mfunction-return=thunk and -mfunction-return=thunk-extern. |
| 25 | |
| 26 | gcc/testsuite/ |
| 27 | |
| 28 | Backport from mainline |
| 29 | 2018-01-14 H.J. Lu <hongjiu.lu@intel.com> |
| 30 | |
| 31 | * gcc.target/i386/indirect-thunk-10.c: New test. |
| 32 | * gcc.target/i386/indirect-thunk-8.c: Likewise. |
| 33 | * gcc.target/i386/indirect-thunk-9.c: Likewise. |
| 34 | * gcc.target/i386/indirect-thunk-attr-10.c: Likewise. |
| 35 | * gcc.target/i386/indirect-thunk-attr-11.c: Likewise. |
| 36 | * gcc.target/i386/indirect-thunk-attr-9.c: Likewise. |
| 37 | * gcc.target/i386/ret-thunk-17.c: Likewise. |
| 38 | * gcc.target/i386/ret-thunk-18.c: Likewise. |
| 39 | * gcc.target/i386/ret-thunk-19.c: Likewise. |
| 40 | * gcc.target/i386/ret-thunk-20.c: Likewise. |
| 41 | * gcc.target/i386/ret-thunk-21.c: Likewise. |
| 42 | |
| 43 | Upstream-Status: Pending |
| 44 | |
| 45 | Signed-off-by: Juro Bystricky <juro.bystricky@intel.com> |
| 46 | |
| 47 | --- |
| 48 | gcc/config/i386/i386.c | 26 ++++++++++++++++++++++ |
| 49 | gcc/doc/invoke.texi | 11 +++++++++ |
| 50 | gcc/testsuite/gcc.target/i386/indirect-thunk-10.c | 7 ++++++ |
| 51 | gcc/testsuite/gcc.target/i386/indirect-thunk-8.c | 7 ++++++ |
| 52 | gcc/testsuite/gcc.target/i386/indirect-thunk-9.c | 7 ++++++ |
| 53 | .../gcc.target/i386/indirect-thunk-attr-10.c | 9 ++++++++ |
| 54 | .../gcc.target/i386/indirect-thunk-attr-11.c | 9 ++++++++ |
| 55 | .../gcc.target/i386/indirect-thunk-attr-9.c | 9 ++++++++ |
| 56 | gcc/testsuite/gcc.target/i386/ret-thunk-17.c | 7 ++++++ |
| 57 | gcc/testsuite/gcc.target/i386/ret-thunk-18.c | 8 +++++++ |
| 58 | gcc/testsuite/gcc.target/i386/ret-thunk-19.c | 8 +++++++ |
| 59 | gcc/testsuite/gcc.target/i386/ret-thunk-20.c | 9 ++++++++ |
| 60 | gcc/testsuite/gcc.target/i386/ret-thunk-21.c | 9 ++++++++ |
| 61 | 13 files changed, 126 insertions(+) |
| 62 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-10.c |
| 63 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-8.c |
| 64 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-9.c |
| 65 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c |
| 66 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c |
| 67 | create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c |
| 68 | create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-17.c |
| 69 | create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-18.c |
| 70 | create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-19.c |
| 71 | create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-20.c |
| 72 | create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-21.c |
| 73 | |
| 74 | diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c |
| 75 | index eeca7e5..9c038be 100644 |
| 76 | --- a/gcc/config/i386/i386.c |
| 77 | +++ b/gcc/config/i386/i386.c |
| 78 | @@ -6389,6 +6389,19 @@ ix86_set_indirect_branch_type (tree fndecl) |
| 79 | } |
| 80 | else |
| 81 | cfun->machine->indirect_branch_type = ix86_indirect_branch; |
| 82 | + |
| 83 | + /* -mcmodel=large is not compatible with -mindirect-branch=thunk |
| 84 | + nor -mindirect-branch=thunk-extern. */ |
| 85 | + if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) |
| 86 | + && ((cfun->machine->indirect_branch_type |
| 87 | + == indirect_branch_thunk_extern) |
| 88 | + || (cfun->machine->indirect_branch_type |
| 89 | + == indirect_branch_thunk))) |
| 90 | + error ("%<-mindirect-branch=%s%> and %<-mcmodel=large%> are not " |
| 91 | + "compatible", |
| 92 | + ((cfun->machine->indirect_branch_type |
| 93 | + == indirect_branch_thunk_extern) |
| 94 | + ? "thunk-extern" : "thunk")); |
| 95 | } |
| 96 | |
| 97 | if (cfun->machine->function_return_type == indirect_branch_unset) |
| 98 | @@ -6414,6 +6427,19 @@ ix86_set_indirect_branch_type (tree fndecl) |
| 99 | } |
| 100 | else |
| 101 | cfun->machine->function_return_type = ix86_function_return; |
| 102 | + |
| 103 | + /* -mcmodel=large is not compatible with -mfunction-return=thunk |
| 104 | + nor -mfunction-return=thunk-extern. */ |
| 105 | + if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) |
| 106 | + && ((cfun->machine->function_return_type |
| 107 | + == indirect_branch_thunk_extern) |
| 108 | + || (cfun->machine->function_return_type |
| 109 | + == indirect_branch_thunk))) |
| 110 | + error ("%<-mfunction-return=%s%> and %<-mcmodel=large%> are not " |
| 111 | + "compatible", |
| 112 | + ((cfun->machine->function_return_type |
| 113 | + == indirect_branch_thunk_extern) |
| 114 | + ? "thunk-extern" : "thunk")); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi |
| 119 | index ad9f295..48e827f 100644 |
| 120 | --- a/gcc/doc/invoke.texi |
| 121 | +++ b/gcc/doc/invoke.texi |
| 122 | @@ -24230,6 +24230,11 @@ to external call and return thunk provided in a separate object file. |
| 123 | You can control this behavior for a specific function by using the |
| 124 | function attribute @code{indirect_branch}. @xref{Function Attributes}. |
| 125 | |
| 126 | +Note that @option{-mcmodel=large} is incompatible with |
| 127 | +@option{-mindirect-branch=thunk} nor |
| 128 | +@option{-mindirect-branch=thunk-extern} since the thunk function may |
| 129 | +not be reachable in large code model. |
| 130 | + |
| 131 | @item -mfunction-return=@var{choice} |
| 132 | @opindex -mfunction-return |
| 133 | Convert function return with @var{choice}. The default is @samp{keep}, |
| 134 | @@ -24241,6 +24246,12 @@ object file. You can control this behavior for a specific function by |
| 135 | using the function attribute @code{function_return}. |
| 136 | @xref{Function Attributes}. |
| 137 | |
| 138 | +Note that @option{-mcmodel=large} is incompatible with |
| 139 | +@option{-mfunction-return=thunk} nor |
| 140 | +@option{-mfunction-return=thunk-extern} since the thunk function may |
| 141 | +not be reachable in large code model. |
| 142 | + |
| 143 | + |
| 144 | @item -mindirect-branch-register |
| 145 | @opindex -mindirect-branch-register |
| 146 | Force indirect call and jump via register. |
| 147 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c |
| 148 | new file mode 100644 |
| 149 | index 0000000..a0674bd |
| 150 | --- /dev/null |
| 151 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-10.c |
| 152 | @@ -0,0 +1,7 @@ |
| 153 | +/* { dg-do compile { target { lp64 } } } */ |
| 154 | +/* { dg-options "-O2 -mindirect-branch=thunk-inline -mfunction-return=keep -mcmodel=large" } */ |
| 155 | + |
| 156 | +void |
| 157 | +bar (void) |
| 158 | +{ |
| 159 | +} |
| 160 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c |
| 161 | new file mode 100644 |
| 162 | index 0000000..7a80a89 |
| 163 | --- /dev/null |
| 164 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-8.c |
| 165 | @@ -0,0 +1,7 @@ |
| 166 | +/* { dg-do compile { target { lp64 } } } */ |
| 167 | +/* { dg-options "-O2 -mindirect-branch=thunk -mfunction-return=keep -mcmodel=large" } */ |
| 168 | + |
| 169 | +void |
| 170 | +bar (void) |
| 171 | +{ /* { dg-error "'-mindirect-branch=thunk' and '-mcmodel=large' are not compatible" } */ |
| 172 | +} |
| 173 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c |
| 174 | new file mode 100644 |
| 175 | index 0000000..d4d45c5 |
| 176 | --- /dev/null |
| 177 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-9.c |
| 178 | @@ -0,0 +1,7 @@ |
| 179 | +/* { dg-do compile { target { lp64 } } } */ |
| 180 | +/* { dg-options "-O2 -mindirect-branch=thunk-extern -mfunction-return=keep -mcmodel=large" } */ |
| 181 | + |
| 182 | +void |
| 183 | +bar (void) |
| 184 | +{ /* { dg-error "'-mindirect-branch=thunk-extern' and '-mcmodel=large' are not compatible" } */ |
| 185 | +} |
| 186 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c |
| 187 | new file mode 100644 |
| 188 | index 0000000..3a2aead |
| 189 | --- /dev/null |
| 190 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c |
| 191 | @@ -0,0 +1,9 @@ |
| 192 | +/* { dg-do compile { target { lp64 } } } */ |
| 193 | +/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */ |
| 194 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 195 | + |
| 196 | +__attribute__ ((indirect_branch("thunk-extern"))) |
| 197 | +void |
| 198 | +bar (void) |
| 199 | +{ /* { dg-error "'-mindirect-branch=thunk-extern' and '-mcmodel=large' are not compatible" } */ |
| 200 | +} |
| 201 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c |
| 202 | new file mode 100644 |
| 203 | index 0000000..8e52f03 |
| 204 | --- /dev/null |
| 205 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c |
| 206 | @@ -0,0 +1,9 @@ |
| 207 | +/* { dg-do compile { target { lp64 } } } */ |
| 208 | +/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */ |
| 209 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 210 | + |
| 211 | +__attribute__ ((indirect_branch("thunk-inline"))) |
| 212 | +void |
| 213 | +bar (void) |
| 214 | +{ |
| 215 | +} |
| 216 | diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c |
| 217 | new file mode 100644 |
| 218 | index 0000000..bdaa4f6 |
| 219 | --- /dev/null |
| 220 | +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c |
| 221 | @@ -0,0 +1,9 @@ |
| 222 | +/* { dg-do compile { target { lp64 } } } */ |
| 223 | +/* { dg-options "-O2 -mindirect-branch=keep -mfunction-return=keep -mcmodel=large" } */ |
| 224 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 225 | + |
| 226 | +__attribute__ ((indirect_branch("thunk"))) |
| 227 | +void |
| 228 | +bar (void) |
| 229 | +{ /* { dg-error "'-mindirect-branch=thunk' and '-mcmodel=large' are not compatible" } */ |
| 230 | +} |
| 231 | diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-17.c b/gcc/testsuite/gcc.target/i386/ret-thunk-17.c |
| 232 | new file mode 100644 |
| 233 | index 0000000..0605e2c |
| 234 | --- /dev/null |
| 235 | +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-17.c |
| 236 | @@ -0,0 +1,7 @@ |
| 237 | +/* { dg-do compile { target { lp64 } } } */ |
| 238 | +/* { dg-options "-O2 -mfunction-return=thunk -mindirect-branch=keep -mcmodel=large" } */ |
| 239 | + |
| 240 | +void |
| 241 | +bar (void) |
| 242 | +{ /* { dg-error "'-mfunction-return=thunk' and '-mcmodel=large' are not compatible" } */ |
| 243 | +} |
| 244 | diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-18.c b/gcc/testsuite/gcc.target/i386/ret-thunk-18.c |
| 245 | new file mode 100644 |
| 246 | index 0000000..307019d |
| 247 | --- /dev/null |
| 248 | +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-18.c |
| 249 | @@ -0,0 +1,8 @@ |
| 250 | +/* { dg-do compile { target { lp64 } } } */ |
| 251 | +/* { dg-options "-O2 -mfunction-return=thunk-extern -mindirect-branch=keep -mcmodel=large" } */ |
| 252 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 253 | + |
| 254 | +void |
| 255 | +bar (void) |
| 256 | +{ /* { dg-error "'-mfunction-return=thunk-extern' and '-mcmodel=large' are not compatible" } */ |
| 257 | +} |
| 258 | diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-19.c b/gcc/testsuite/gcc.target/i386/ret-thunk-19.c |
| 259 | new file mode 100644 |
| 260 | index 0000000..772617f |
| 261 | --- /dev/null |
| 262 | +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-19.c |
| 263 | @@ -0,0 +1,8 @@ |
| 264 | +/* { dg-do compile { target { lp64 } } } */ |
| 265 | +/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */ |
| 266 | + |
| 267 | +__attribute__ ((function_return("thunk"))) |
| 268 | +void |
| 269 | +bar (void) |
| 270 | +{ /* { dg-error "'-mfunction-return=thunk' and '-mcmodel=large' are not compatible" } */ |
| 271 | +} |
| 272 | diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-20.c b/gcc/testsuite/gcc.target/i386/ret-thunk-20.c |
| 273 | new file mode 100644 |
| 274 | index 0000000..1e9f9bd |
| 275 | --- /dev/null |
| 276 | +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-20.c |
| 277 | @@ -0,0 +1,9 @@ |
| 278 | +/* { dg-do compile { target { lp64 } } } */ |
| 279 | +/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */ |
| 280 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 281 | + |
| 282 | +__attribute__ ((function_return("thunk-extern"))) |
| 283 | +void |
| 284 | +bar (void) |
| 285 | +{ /* { dg-error "'-mfunction-return=thunk-extern' and '-mcmodel=large' are not compatible" } */ |
| 286 | +} |
| 287 | diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-21.c b/gcc/testsuite/gcc.target/i386/ret-thunk-21.c |
| 288 | new file mode 100644 |
| 289 | index 0000000..eea07f7 |
| 290 | --- /dev/null |
| 291 | +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-21.c |
| 292 | @@ -0,0 +1,9 @@ |
| 293 | +/* { dg-do compile { target { lp64 } } } */ |
| 294 | +/* { dg-options "-O2 -mfunction-return=keep -mindirect-branch=keep -mcmodel=large" } */ |
| 295 | +/* { dg-additional-options "-fPIC" { target fpic } } */ |
| 296 | + |
| 297 | +__attribute__ ((function_return("thunk-inline"))) |
| 298 | +void |
| 299 | +bar (void) |
| 300 | +{ |
| 301 | +} |
| 302 | -- |
| 303 | 2.7.4 |
| 304 | |