<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57624>57624</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            sanitizer_internal_defs.h change breaks SPARC stacktraces
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            vitalybuka
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rorth
      </td>
    </tr>
</table>

<pre>
    A recent `sanitizer_internal_defs.h` change (4248f32b9ebe87c7af8ee53911efd47c2652f488) broke two tests on SPARC:
```
  UBSan-Standalone-sparc :: TestCases/Misc/missing_return.cpp
  UBSan-Standalone-sparcv9 :: TestCases/Misc/missing_return.cpp
```
The problem is that the sreported tacktrace changed: before, it was
```
    #0 0x58cf4 in f() /vol/llvm/src/llvm-project/dist/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp:8:35
    #1 0x58d00 in main /vol/llvm/src/llvm-project/dist/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp:13:10
    #2 0x2b8ac in _start (/var/llvm/dist-sparcv9-release-stage2-A.prev/tools/clang/stage2-bins/projects/compiler-rt/test/ubsan/Standalone-sparc/TestCases/Misc/Output/missing_return.cpp.tmp+0x2b8ac)
```
while now it's
```
    #0 0x58c4c in main /vol/llvm/src/llvm-project/local/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp:12
    #1 0x58c44 in f() /vol/llvm/src/llvm-project/local/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp:8:35
    #2 0x58c50 in main /vol/llvm/src/llvm-project/local/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp:13:10
    #3 0x2b9a4 in _start (/var/llvm/local-sparcv9-release-stage2-A/tools/clang/stage2-bins/projects/compiler-rt/test/ubsan/Standalone-sparc/TestCases/Misc/Output/missing_return.cpp.tmp+0x2b9a4)
```
i.e. a dummy internal frame #0 was introduced.  Recently, current `compiler-rt` was imported into GCC's `libsanitizer` which introduced more instances of the same issue.  Those failures don't show in LLVM since `clang` doesn't support `asan` on SPARC, unlike GCC.

I've tried to investigate the issue, but unfortunately the relevant code isn't compiled with debug info even in a `Debug` build.  Seems like I need to complete D91620 first.

The issue is multifold, I believe:

- The patch itself is correct: for the benefit of those targets where `__builtin_extract_return_addr` isn't a no-op, it's always necessary.  However, before the code coped with that situation, so that needs to be undone.
- Several targets that **do** need a non-default `__b_e_r_a` (cf. [D91607](https://reviews.llvm.org/D91607), but `clang` only implements this on SPARC.
- According to GCC, there are also ARM, MIPS, and S390.  The weird thing is that before the current patch, S390 had code to use `__b_e_r_a` (and would have needed it with GCC), however `clang` didn't implement that.
- It seems like some of the affected arches aren't even tested in `compiler-rt`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV9uO2zYQ_Rr5hbAg05IvD35wvEi7QBYN4k1fDYocWexSokFSdtyv7wwle3dTb5oUQVFgLYL3M2fOzHBLq86rNXMgoQ0smWVetDroP8HtdBvAtcLsFFQ-rXGOyVq0e2AJX-Q8X1RTXi6hhMVczkW1ACimy8kEKpXPJZ8VvMoXi4QvWensE7BwsiyAD57Zlm0_rj9tkuk6ye6SbI1HD3-xy9jnd1vRjrdBtEoY28LYH4STjDZM1-wRT9kIDz7h7x-0l9g02nvd7ncOQufaVB4O3z7quPwXh30F87EGdnC2NNAw7VmoRcAPMO_gYF0AxYKQT8EJCQNxii4sobIOEr5hOrCT8G9QwJDlacayL8VCVjnTLauQdqITER6twa8xxwYb7-TQGSOcP0AG7CrtqZG2OWgDbuyoR_Rj05XoZGy_z_TpeoG_afEK2CQCU1lGwBqBn_8c1WRKn9d8cYTFy4WQBGvng3CBRdbeH4V7xkYwLjoYOzCA141x9R74eJ0eHBwJlrWGMEiDriOD-vlStzQ62OT_yZqvhXfbwN-6cOjCTUvT0BwS_m6wC_1_Uy-nGhGw1p5QVAmff4-ocvljvjNWCvPTnMdvyEnmP67zn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