This is an archive of the discontinued LLVM Phabricator instance.

[libunwind] Ensure test/libunwind_01.pass is not completely inlined
ClosedPublic

Authored by arichardson on May 29 2022, 4:22 AM.

Details

Summary

By adding noinline and calling fprintf before returning we ensure that
every function will have a distinct call frame and that the return address
will always be saved instead of saving the target in main as the result.

Before this change all backtraces were always backtrace -> main -> _start,
i.e. always exactly three entries. This happenend because all calls were
inlined in main() and the test just happenend to pass because there is at
least _start before main.

I found this while fixing some bugs in libunwind for CHERI and noticed that
the test was passing even though the code was completely broken.

Obtained from: https://github.com/CTSRD-CHERI/llvm-project

Diff Detail

Event Timeline

arichardson created this revision.May 29 2022, 4:22 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 29 2022, 4:22 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
arichardson requested review of this revision.May 29 2022, 4:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 29 2022, 4:22 AM
arichardson added inline comments.May 29 2022, 4:23 AM
libunwind/test/libunwind_01.pass.cpp
11

@ldionne does the noinline fix the failure? I was originally testing on macOS and when I made this change (back in 2018) I believe it fixed the tests for me.

MaskRay accepted this revision as: MaskRay.May 29 2022, 10:55 AM
MaskRay added a subscriber: MaskRay.

I think it improves the robustness of the test. It'd be good to make tests at -O1 and above, not just -O0.

The test subject can mention [test] to make it clear this is a non-code change.

libunwind/test/libunwind_01.pass.cpp
167

The exit status is sufficient, no need for this log.

arichardson added inline comments.May 29 2022, 12:51 PM
libunwind/test/libunwind_01.pass.cpp
167

Indeed that was a debugging change to make it more obvious when the test passes. Will remove before committing.

ldionne accepted this revision.Jun 1 2022, 10:46 AM
ldionne added inline comments.
libunwind/test/libunwind_01.pass.cpp
11

It doesn't look like it does, otherwise we'd have seen some XPASS in the CI.

This revision is now accepted and ready to land.Jun 1 2022, 10:46 AM
This revision was landed with ongoing or failed builds.Jun 20 2022, 2:06 AM
This revision was automatically updated to reflect the committed changes.