Skip to content
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

The different xs_handshake() failures need distinct messages #19111

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

nwc10
Copy link
Contributor

@nwc10 nwc10 commented Sep 9, 2021

xs_handshake() makes two different comparisons that on failure are reported
as "got handshake key %p, needed %p", with opaque hexadecimal values.

The first is the "actual" key as generated by the HS_KEY() macro, which
encodes various values such as sizeof(PerlInterpreter) and the API version.
The second is the address of the current thread's PerlInterpreter struct.

Either can fail, and before this commit they would fail with identical text.
Hence it wasn't obvious what the problem was, causing "confusion and delay"
if one tried to decode the hexadecimal output as the wrong thing. (For
example when it's actually pointers mismatching, but one tries to decode the
values into API version and structure size, assuming that the values were
the packed output from HS_KEY().)

xs_handshake() makes two different comparisons that on failure are reported
as "got handshake key %p, needed %p", with opaque hexadecimal values.

The first is the "actual" key as generated by the HS_KEY() macro, which
encodes various values such as sizeof(PerlInterpreter) and the API version.
The second is the address of the current thread's PerlInterpreter struct.

Either can fail, and before this commit they would fail with identical text.
Hence it wasn't obvious what the problem was, causing "confusion and delay"
if one tried to decode the hexadecimal output as the wrong thing. (For
example when it's actually pointers mismatching, but one tries to decode the
values into API version and structure size, assuming that the values were
the packed output from HS_KEY().)
@iabyn
Copy link
Contributor

iabyn commented Sep 9, 2021 via email

@nwc10
Copy link
Contributor Author

nwc10 commented Sep 9, 2021

Personally I'd go further. ...

Agree. (with the reasoning and the detailed suggestions.)

Right now I have a TODO list of open things that I'm trying to put to bed, so I don't want to go sideways onto this. Also, I think that this commit is better than what we had, and doesn't get in the way of further improvement, so I'm going to merge it instead of putting it on hold until me (or someone else) takes up this plan.

@nwc10 nwc10 merged commit 7b6e25e into Perl:blead Sep 9, 2021
@nwc10 nwc10 deleted the explicit-handshake-failure-messages branch September 9, 2021 11:56
@jkeenan
Copy link
Contributor

jkeenan commented Sep 9, 2021

Is there any way we can in the test suite simulate the conditions which would generate this warning?

At present, it appears to be untested.

$ ack 'loadable library and perl binaries are mismatched' .
pod/perldiag.pod
3423:=item %s: loadable library and perl binaries are mismatched (got %s handshake key %p, needed %p)

util.c
5632:            noperl_die("%s: loadable library and perl binaries are mismatched"

@nwc10
Copy link
Contributor Author

nwc10 commented Sep 9, 2021

Is there any way we can in the test suite simulate the conditions which would generate this warning?

I can't think of any easy way. We can't rely on anything outside of the build tree, and we need a shared object that will load on the CPU and OS we're building on, so we can't pre-compile test files either. So I think we'd have to build a test shared object that we knew is "wrong", and then try to load it. So we'd

  1. need a specific extension just for this - sort of XS::API-Test::Handshake::Fail
  2. also have to add complexity to the core's macros so that we can compile this module with some "wrong" inputs so that the "handshake" fails

which seems like a lot of work to get to pass, and likely fragile and going to break quite often.

Unless I've missed a simpler way of deliberately getting this code to hit the error path...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants