This is an archive of the discontinued LLVM Phabricator instance.

[llvm-jitlink] Add diagnostic output and port executor to getaddrinfo(3) as well
ClosedPublic

Authored by sgraenitz on Mar 13 2021, 7:12 AM.

Details

Summary

Add diagnostic output for TCP connections on both sides, llvm-jitlink and llvm-jitlink-executor.
Port the executor to use getaddrinfo(3) as well. This makes the code more symmetric and seems to be the recommended way for implementing the server side.

Diff Detail

Event Timeline

sgraenitz requested review of this revision.Mar 13 2021, 7:12 AM
sgraenitz created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2021, 7:12 AM

Follow-up patch that submits learnings from fixing D98579. The error it fixed would now print as:
Failed to connect TCP socket 'localhost:13921': Address resolution failed (Bad hints)

Some sample output for llvm-jitlink with various broken addresses:
Failed to connect TCP socket 'localhost:1': Connection refused (inactive)
Failed to connect TCP socket '8.8.8.8:1': Operation timed out (non-responding)
Failed to connect TCP socket '127.0.0.1:0': Can't assign requested address
Failed to connect TCP socket '127.0.0.1:-1': Address resolution failed (nodename nor servname provided, or not known)
Failed to connect TCP socket '127.0.0.1': Port for -oop-executor-connect can not be empty

Running llvm-jitlink-executor on a port that is busy:
Error on binding: Address already in use

In success case llvm-jitlink-executor dumps some convenient server'ish output:

> bin/llvm-jitlink-executor listen=localhost:13921
Listening at localhost:13921
Connection established. Running OrcRPCTPCServer...
sgraenitz updated this revision to Diff 330459.Mar 13 2021, 9:45 AM

Print 'Connection established' only when connecting via a TCP socket

rzurob added inline comments.Mar 15 2021, 9:05 PM
llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
94

This line fails compilation on AIX in 64-bit mode:

llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp:93:10: error: no matching function for call to 'accept'
  return accept(SockFD, AI->ai_addr, &AI->ai_addrlen);
         ^~~~~~
/usr/include/sys/socket.h:635:9: note: candidate function not viable: no known conversion from 'size_t *' (aka 'unsigned long *') to 'socklen_t *' (aka 'unsigned int *') for 3rd argument
int     accept(int, struct sockaddr *__restrict__, socklen_t *__restrict__);
        ^
1 error generated.
Error while processing llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp.

The size is always going to fit into an unsigned int. So perhaps we need to store AI->ai_addrlen into a socklen_t temp first?

sgraenitz updated this revision to Diff 331819.Mar 19 2021, 4:19 AM
sgraenitz marked an inline comment as done.

Add special-case for calling accept(2) on AIX. I cannot test it here, @rzurob does this work for you?

llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
94

Interesting, the ai_addrlen field should be of type socklen_t naturally:

struct addrinfo {
  int              ai_flags;
  int              ai_family;
  int              ai_socktype;
  int              ai_protocol;
  socklen_t        ai_addrlen;
  struct sockaddr *ai_addr;
  char            *ai_canonname;
  struct addrinfo *ai_next;
};

Do you think it's fine to keep this as a special-case for AIX? Does the connect call on the client side in D98579 suffer from the same issue?

rzurob accepted this revision.Mar 19 2021, 9:25 AM

LGTM

llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
94

You're right that the AIX header is not declaring ai_addrlen as what POSIX says. I've reported it to them.
In the meantime, I confirmed that the AIX workaround you added works. Thanks!

This revision is now accepted and ready to land.Mar 19 2021, 9:25 AM

Thanks for the confirmation. I will land this as soon as D98579 is done.

This revision was landed with ongoing or failed builds.Mar 22 2021, 3:21 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Mar 22 2021, 3:31 AM

This breaks the build on Windows: http://45.33.8.238/win/35472/step_4.txt

Please take a look, and please revert for now and fix async if it takes a while to fix.

@thakis Thanks for the note. I guess it's D98579. Fix will be quick.

thakis added inline comments.Mar 22 2021, 3:37 AM
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
680

No, I think it's this one (at least partially). This here used to be behind LLVM_ON_UNIX but now it isn't. Probably just needs to go back behind that check.

sgraenitz marked an inline comment as done.Mar 22 2021, 3:42 AM

Alright fixed with 9cdbdbea29ce

Thanks, bot is happy again :)