https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071

            Bug ID: 120071
           Summary: Add builtin to get the current PC/instruction counter
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

The linux kernel does this brokenness thing:
include/linux/instruction_pointer.h:#define _THIS_IP_  ({ __label__ __here;
__here: (unsigned long)&&__here; })


It works on x86_64 because they define it correctly:
arch/x86/include/asm/linkage.h:#define _THIS_IP_ ({ unsigned long __here; asm
("lea 0(%%rip), %0" : "=r" (__here)); __here; })

But really GCC should provide a builtin to the same thing.
For targets like ppc, it is harder to do it and requires a jump but that is ok.
This is used for tracing so ...

See also the LLVM bug report:
https://github.com/llvm/llvm-project/issues/138272

Reply via email to