[all-commits] [llvm/llvm-project] 3460f7: EntryExitInstrumenter: skip naked functions

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu May 4 09:21:31 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3460f727eaa3a4c81f031b1533f9ad28c64faa4a
      https://github.com/llvm/llvm-project/commit/3460f727eaa3a4c81f031b1533f9ad28c64faa4a
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-05-04 (Thu, 04 May 2023)

  Changed paths:
    M llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
    M llvm/test/Transforms/EntryExitInstrumenter/mcount.ll

  Log Message:
  -----------
  EntryExitInstrumenter: skip naked functions

The asm in a naked function may reasonably expect the argument registers and the
return address register (if present) to be live.

When using -pg and -finstrument-functions, functions are instrumented by adding
a function call to `_mcount/__cyg_profile_func_enter/__cyg_profile_func_enter_bare`/etc,
which will clobber these registers. If the return address register is clobbered,
the function will be unable to return to the caller, possibly causing an
infinite loop.

```
__attribute__((naked)) void g() {
#if defined(__arm__)
  __asm__("bx lr");
#else
  __asm__("ret");
#endif
}

int main() { g(); }
```

It seems that the only one reasonable way to handle the combination is to
disable instrumenting for naked functions.

GCC PR: https://gcc.gnu.org/PR109707
Close https://github.com/llvm/llvm-project/issues/62504

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D149721




More information about the All-commits mailing list