]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Enable -mnop-mcount for -fpic with PLTs [PR119386]
authorArd Biesheuvel <ardb@kernel.org>
Thu, 10 Apr 2025 12:26:41 +0000 (14:26 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Wed, 16 Apr 2025 18:38:20 +0000 (20:38 +0200)
-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 when -mnop-mcount is being used.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
gcc/ChangeLog:

PR target/119386
* config/i386/i386-options.cc: Permit -mnop-mcount 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
gcc/testsuite/gcc.target/i386/pr119386-3.c [new file with mode: 0644]

index a9fac011f3d2b1b0481fd6028bc62752c6fa4e1b..964449fa8cd7874d1627fc1fc67dd4c1ea85895a 100644 (file)
@@ -2828,8 +2828,8 @@ ix86_option_override_internal (bool main_args_p,
   if (flag_nop_mcount)
     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 (flag_nop_mcount && flag_pic && !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 (file)
index 0000000..287410b
--- /dev/null
@@ -0,0 +1,10 @@
+/* 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" } } */
+
+int
+main ()
+{
+  return 0;
+}