From: Ard Biesheuvel <a...@kernel.org> On 64-bit, -mnop-mcount can be trivially enabled for -fPIC codegen as long as PLTs are being used, given that the instruction encodings are identical, only the target may resolve differently depending on how the linker decides to incorporate the object file.
So relax the option check, and add a test to ensure that 5-byte NOPs are emitted in the 64-bit case. On 32-bit, PLTs are never used so -mnop-mcount remains disallowed in combination with -fPIC. Signed-off-by: Ard Biesheuvel <a...@kernel.org> gcc/ChangeLog: PR target/119386 * config/i386/i386-options.cc: Permit -mnop-mcount on 64-bit when using -fpic with PLTs. gcc/testsuite/ChangeLog: PR target/119386 * gcc.target/i386/pr119386-3.c: New test. --- gcc/config/i386/i386-options.cc | 7 ++++++- gcc/testsuite/gcc.target/i386/pr119386-3.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr119386-3.c diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index fc4d2d2529e..8ecaff8d929 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -2819,7 +2819,12 @@ ix86_option_override_internal (bool main_args_p, error ("%<-mnop-mcount%> is not compatible with this target"); #endif if (flag_nop_mcount && flag_pic) - error ("%<-mnop-mcount%> is not implemented for %<-fPIC%>"); + { + if (!TARGET_64BIT) + error ("%<-mnop-mcount%> is not implemented for %<-fPIC%>"); + else if (!flag_plt) + error ("%<-mnop-mcount%> is not implemented for %<-fno-plt%>"); + } /* Accept -msseregparm only if at least SSE support is enabled. */ if (TARGET_SSEREGPARM_P (opts->x_target_flags) diff --git a/gcc/testsuite/gcc.target/i386/pr119386-3.c b/gcc/testsuite/gcc.target/i386/pr119386-3.c new file mode 100644 index 00000000000..b7999c34ce1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr119386-3.c @@ -0,0 +1,11 @@ +/* PR target/119386 */ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic -pg -mnop-mcount" } */ +/* { dg-final { scan-assembler ".byte\[ \t\]0x0f, 0x1f, 0x44, 0x00, 0x00" { target { ! ia32 } } } } */ +/* { dg-xfail-if "'-mnop-mcount' is not implemented for '-fPIC'" { ia32 } } */ + +int +main () +{ + return 0; +} -- 2.49.0.504.g3bcea36a83-goog