This is an archive of the discontinued LLVM Phabricator instance.

[Mips] Emit proper ABI for _mcount calls
ClosedPublic

Authored by mbrkusanin on Oct 3 2019, 6:32 AM.

Details

Summary

When -pg option is present than a call to _mcount is inserted into every
function. However since the proper ABI was not followed then the generated
gmon.out did not give proper results. By inserting needed instructions before
every _mcount we can fix this.

Diff Detail

Event Timeline

mbrkusanin created this revision.Oct 3 2019, 6:32 AM
mbrkusanin added a comment.EditedOct 3 2019, 6:41 AM

Simple use case if someone is unfamiliar with gpof and -pg options:

clang++ test.cpp -pg  ... # compile with _mcount calls
./a.out                   # generates gmon.out
gprof a.out               # shows report

For simple test.cpp:

int main() {
  return 0;
}

We now get proper results:

...
index % time    self  children    called     name
                0.00    0.00       1/1           __libc_start_main [620]
[1]      0.0    0.00    0.00       1         main [1]
...

Tested with following configurations:

mips -fpic -fast-isel=false         (used for _mcount: Mips::JALRPseudo)
mips -fpic                          (used for _mcount: Mips::JALR)
mips  -fast-isel=false              (used for _mcount: Mips::JAL)
mips                                (used for _mcount: Mips::JAL)
mips64 -fpic -fast-isel=false       (used for _mcount: Mips::JALR64Pseudo)
mips64 -fpic                        (used for _mcount: Mips::JALR64Pseudo)
mips64 -fast-isel=false             (used for _mcount: Mips::JALR64Pseudo)
mips64                              (used for _mcount: Mips::JALR64Pseudo)
micromips -fpic -fast-isel=false    (used for _mcount: Mips::JALR16_MM)
micromips -fpic                     (used for _mcount: Mips::JALR16_MM)
micromips -fast-isel=false          (used for _mcount: Mips::JAL_MM)
micromips                           (used for _mcount: Mips::JAL_MM)

Current _mcount implementation for Mips can be found here:
https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=blob;f=sysdeps/mips/machine-gmon.h;hb=HEAD

draganm added a subscriber: draganm.Oct 3 2019, 7:21 AM
This revision is now accepted and ready to land.Oct 4 2019, 1:31 PM
This revision was automatically updated to reflect the committed changes.

This is causing failures on EXPENSIVE_CHECKS builds, please can you take a look?

Thanks. I will look into it as soon as possible.

mbrkusanin added a comment.EditedOct 10 2019, 5:01 AM

Tests would fail when we add -verify-machineinstrs option.

I've added this option to my test and fixed the code in: r374320