https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119386
--- Comment #59 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Uros Bizjak <u...@gcc.gnu.org>: https://gcc.gnu.org/g:9b0ae0a8d70603960f3c578d261efd18c02b803f commit r15-9530-g9b0ae0a8d70603960f3c578d261efd18c02b803f Author: Ard Biesheuvel <a...@kernel.org> Date: Thu Apr 10 14:26:40 2025 +0200 i386: Prefer PLT indirection for __fentry__ calls under -fPIC [PR119386] Commit bde21de1205 ("i386: Honour -mdirect-extern-access when calling __fentry__") updated the logic that emits mcount() / __fentry__() calls into function prologues when profiling is enabled, to avoid GOT-based indirect calls when a direct call would suffice. There are two problems with that change: - it relies on -mdirect-extern-access rather than -fno-plt to decide whether or not a direct [PLT based] call is appropriate; - for the PLT case, it falls through to x86_print_call_or_nop(), which does not emit the @PLT suffix, resulting in the wrong relocation to be used (R_X86_64_PC32 instead of R_X86_64_PLT32) Fix this by testing flag_plt instead of ix86_direct_extern_access, and updating x86_print_call_or_nop() to take flag_pic and flag_plt into account. This also ensures that -mnop-mcount works as expected when emitting the PLT based profiling calls. While at it, fix the 32-bit logic as well, and issue a PLT call unless PLTs are explicitly disabled. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119386 Signed-off-by: Ard Biesheuvel <a...@kernel.org> gcc/ChangeLog: PR target/119386 * config/i386/i386.cc (x86_print_call_or_nop): Add @PLT suffix where appropriate. (x86_function_profiler): Fall through to x86_print_call_or_nop() for PIC codegen when flag_plt is set. gcc/testsuite/ChangeLog: PR target/119386 * gcc.target/i386/pr119386-1.c: New test. * gcc.target/i386/pr119386-2.c: New test. --- Comment #60 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Uros Bizjak <u...@gcc.gnu.org>: https://gcc.gnu.org/g:6b4569a3ebdd0df44d87d67a18272ec0b878f2ee commit r15-9531-g6b4569a3ebdd0df44d87d67a18272ec0b878f2ee Author: Ard Biesheuvel <a...@kernel.org> Date: Thu Apr 10 14:26:41 2025 +0200 i386: Enable -mnop-mcount for -fpic with PLTs [PR119386] -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 <a...@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.