-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update framepointers tests to avoid false positive with inlined C functions #11594
Conversation
I like the idea, but I really don't think we should introduce My instinct on this is to move the processing of the stack trace from the shell script back into Equally, are we straying into over-thinking all this (@xavierleroy, what do you think??) |
Yes, at the moment, frame-pointers support is only for |
Quite possibly :-) My general impressions:
|
Xavier Leroy (2022/10/04 09:26 -0700):
- I still wish we'd standardize on Python for all the scripts of the
OCaml distribution. It's not a great language but at least all the
kids learn it in school these days, so we'll have maintainers when we
retire.
Would you use Python even for the scripts required to build the
compiler? In other words, would it be okay to have Python as a build
dependency?
In my understanding there are two reaons why we didn't do it so far.
First, it is reported to be easy to write scripts that are not portable
from one version of Python to another. I don't know to which extent this
is true. Second, I have the idea that the Python requirement is not as
easily satisfied on Windows that it is on Linux, that's why there is
resistance to depending on it.
What do you think about these reasons, @xavierleroy? Especially about
the second one?
- No way you'd change `ocamltest` to handle the postprocessing of the
- trace! If you want to do your postprocessing in OCaml, you can
write it in OCaml, have it compiled by `ocamltest`, and call it from
the `run` script. Leave `ocamltest` as generic as possible, please.
Yes, indeed. So far, the perhaps-not-explained-enough rule was that we
build something into ocamltest iff it's needed by more than one test.
|
This is off-topic for this PR, but:
This can't be worse than our current gawk vs mawk 1.3.3 vs mawk 1.3.4 situation, not to mention the odd non-GNU
I see Python in the Microsoft Store and as Cygwin packages. Nobody bothered to explain the Windows issues yet; I'm all ears. |
No issues that I am aware of. It is easy to install under Cygwin in any case. |
I'm not sure whether this is focussed at our "infrastructure" (testsuite, as here, support scripts like For the infrastructure, I personally anticipate that we swap one set of papercuts for another, but I don't have a strong objection. I think it is good, for example, that the installation instructions for For the actual Windows papercuts which may or may not happen. We've already mentioned two entirely different distributions of Python, both assuming different file system conventions. It's that kind of thing - I would anticipate that where occasionally now we hit a funny locale, an overly-stringent POSIX awk, we'll start hitting an unrecognised path format because the user provided us with a Python from something we (and possibly they) hadn't thought of. It doesn't mean it'd be a bad idea to switch to Python, but if we're going to switch to something, I'd prefer it to be utopia, that's all! Given that it's often been me doing it, I kinda prefer chasing down a GNU-ism on my aged Macbook, with the POSIX spec in the other hand, to trying to trace exactly which executable has invoked what in a cryptic CI run and why the Windows file path hasn't been accepted by it (which I have to do quite a lot where git is concerned in the opam project, where we hit exactly this kind of problem and annoyingly regularly). |
Another attempt to ignore potentially inlined C functions while still checking reasonable behavior
In frame-pointers tests, the backtrace post-processing is performed directly in fp_backtrace, and so, no longer depends on filter-locations.sh (that was using sed and awk scripts).
64ad832
to
9a7aeff
Compare
The last commit moves all the backtrace post-processing completely into Hopefully this commit also passes the INRIA CI with more exotic configurations! |
bc7d6b3
to
926c378
Compare
It looks fine on the Inria CI as well! |
I'm sorry but I can't review this PR myself. Has anything been decided? |
In #12588 I wrote logic in C to stop the printed backtrace at |
Did you actually have a look at the code of the present PR?
Because AFAIUI this PR does get rid of scripts by doing everything in C
already.
|
No I didn't, I had forgotten that the present PR existed.
Indeed. On the other hand, the change to the C code in the present PR adds 117 lines and removes 71, while my PR adds 22 lines and removes 6. Maybe we can still hope for faster review. |
This PR has evolved quite a bit from the very first implementation, to try and account for commenters opinion, especially on the delicate topic of
The bigger diff comes from that the all backtrace processing is now done in pure C, with POSIX regex, so it's obviously more C code but also removes the need for any of the |
|
||
if (!sigsetjmp(resume_buf, 1)) { | ||
*prev = fi->prev; | ||
*retaddr = fi->retaddr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I read correctly, that the signal mask and long jump business in safe_read
was here to handle the read to retaddr
, and this is why the present PR remove the function (and it auxiliary functions)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is absolutely correct.
Previously, fp_backtrace
tried to unwind the whole stack, but the linked list of 'saved rbp' was not always NULL
terminated, as I expected. safe_read
installed a temporary signal handler to gracefully handle an invalid pointer deference attempt.
Stopping the backtrace (and thus stack unwinding) at caml_program
means this dubious trick is no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing #12588 and this PR, I feel that #12588 is the simpler fix, whereas this PR ends up with the simpler code:
- all processing is in one place and one language
- the regexp matching code is as complex as before
- removing signal handling and longjumps from the test code feels like a clear win.
Now that I have reviewed both PRs, I am in favor of merging this version.
return 0; | ||
//regoff_t len = funcname->rm_eo - funcname->rm_so; | ||
//return strnstr(symbol + funcname->rm_so, CAML_ENTRY, len) == 0; | ||
return strstr(symbol + funcname->rm_so, CAML_ENTRY) != NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems slightly too lax, since we are testing that symbol
at offset funcname
contains CAML_ENTRY
somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right!
I don't know why I stopped using strncmp
like I did as in is_from_executable
... Fixed in 3dc39fe.
Squashed and merged, thanks for the simplification and sorry for the late review of the final version ! |
…ctions (ocaml#11594) Another attempt to ignore potentially inlined C functions while still checking reasonable behavior In frame-pointers tests, the backtrace post-processing is performed directly in fp_backtrace, and so, no longer depends on filter-locations.sh (that was using sed and awk scripts).
As explained correctly in 11582 we don't have much control over the backtrace look with C functions:
gcc
can choose to inline or not some of them.We probably still want to have minimal checks beyondcaml_program
(the starting point where our framepointers must be checked) while avoiding false positive on inlined function.This PR proposes adding an
awk
script to validate functions frommain..caml_start_program
are the expected ones and in correct order but discard them, so.reference
contains only the least likely to change.This PR stops the frame-pointers backtrace at
caml_program
to ignore the differences in case of a different inlining decision by the C compiler.It also does all of the previous "backtrace post-processing" in situ of the stack-walking-with-frame-pointers C code. So
awk
is not needed, and the previous dependency onsed
orsh
are also completely removed.